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:
parent
d0c7a1e39b
commit
a98c9e03ce
@ -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 = () =>
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
},
|
||||
|
@ -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)
|
||||
},
|
||||
|
@ -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)
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user