fix(map-plugin): cannot save because the value is null (#1309)

* fix: cannot save because the value is null

* test: update
This commit is contained in:
Dunqing 2022-12-31 22:30:26 +08:00 committed by GitHub
parent d0c7a1e39b
commit a98c9e03ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 12 deletions

View File

@ -143,7 +143,12 @@ describe('fields', () => {
it('empty', async () => {
const Test = await createCollection();
const model = await Test.model.create();
const model = await Test.model.create({
circle: null,
lineString: null,
point: null,
polygon: null,
});
await model.save();
const findOne = () =>

View File

@ -24,7 +24,8 @@ export class CircleField extends Field {
}
},
set(value) {
if (isPg(context)) {
if (!value?.length) value = null
else if (isPg(context)) {
value = value.join(',')
}
this.setDataValue(name, value)

View File

@ -22,13 +22,14 @@ export class LineStringField extends Field {
}
},
set(value) {
if (isPg(context)) {
if (!value?.length) value = null
else if (isPg(context)) {
value = joinComma(value.map(joinComma))
} else if (isMysql(context)) {
value = value?.length ? {
value = {
type: 'LineString',
coordinates: value
} : null
}
}
this.setDataValue(name, value)
},

View File

@ -25,13 +25,14 @@ export class PointField extends Field {
}
},
set(value) {
if (isPg(context)) {
if (!value?.length) value = null
else if (isPg(context)) {
value = joinComma(value)
} else if (isMysql(context)) {
value = value?.length ? {
value = {
type: 'Point',
coordinates: value
} : null
}
}
this.setDataValue(name, value)
},

View File

@ -22,13 +22,14 @@ export class PolygonField extends Field {
}
},
set(value) {
if (isPg(context)) {
value = value ? joinComma(value.map((item: any) => joinComma(item))) : null
if (!value?.length) value = null
else if (isPg(context)) {
value = joinComma(value.map((item: any) => joinComma(item)))
} else if (isMysql(context)) {
value = value?.length ? {
value = {
type: 'Polygon',
coordinates: [value.concat([value[0]])]
} : null
}
}
this.setDataValue(name, value)
},