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 () => {
|
it('empty', async () => {
|
||||||
const Test = await createCollection();
|
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();
|
await model.save();
|
||||||
|
|
||||||
const findOne = () =>
|
const findOne = () =>
|
||||||
|
@ -24,7 +24,8 @@ export class CircleField extends Field {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
set(value) {
|
set(value) {
|
||||||
if (isPg(context)) {
|
if (!value?.length) value = null
|
||||||
|
else if (isPg(context)) {
|
||||||
value = value.join(',')
|
value = value.join(',')
|
||||||
}
|
}
|
||||||
this.setDataValue(name, value)
|
this.setDataValue(name, value)
|
||||||
|
@ -22,13 +22,14 @@ export class LineStringField extends Field {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
set(value) {
|
set(value) {
|
||||||
if (isPg(context)) {
|
if (!value?.length) value = null
|
||||||
|
else if (isPg(context)) {
|
||||||
value = joinComma(value.map(joinComma))
|
value = joinComma(value.map(joinComma))
|
||||||
} else if (isMysql(context)) {
|
} else if (isMysql(context)) {
|
||||||
value = value?.length ? {
|
value = {
|
||||||
type: 'LineString',
|
type: 'LineString',
|
||||||
coordinates: value
|
coordinates: value
|
||||||
} : null
|
}
|
||||||
}
|
}
|
||||||
this.setDataValue(name, value)
|
this.setDataValue(name, value)
|
||||||
},
|
},
|
||||||
|
@ -25,13 +25,14 @@ export class PointField extends Field {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
set(value) {
|
set(value) {
|
||||||
if (isPg(context)) {
|
if (!value?.length) value = null
|
||||||
|
else if (isPg(context)) {
|
||||||
value = joinComma(value)
|
value = joinComma(value)
|
||||||
} else if (isMysql(context)) {
|
} else if (isMysql(context)) {
|
||||||
value = value?.length ? {
|
value = {
|
||||||
type: 'Point',
|
type: 'Point',
|
||||||
coordinates: value
|
coordinates: value
|
||||||
} : null
|
}
|
||||||
}
|
}
|
||||||
this.setDataValue(name, value)
|
this.setDataValue(name, value)
|
||||||
},
|
},
|
||||||
|
@ -22,13 +22,14 @@ export class PolygonField extends Field {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
set(value) {
|
set(value) {
|
||||||
if (isPg(context)) {
|
if (!value?.length) value = null
|
||||||
value = value ? joinComma(value.map((item: any) => joinComma(item))) : null
|
else if (isPg(context)) {
|
||||||
|
value = joinComma(value.map((item: any) => joinComma(item)))
|
||||||
} else if (isMysql(context)) {
|
} else if (isMysql(context)) {
|
||||||
value = value?.length ? {
|
value = {
|
||||||
type: 'Polygon',
|
type: 'Polygon',
|
||||||
coordinates: [value.concat([value[0]])]
|
coordinates: [value.concat([value[0]])]
|
||||||
} : null
|
}
|
||||||
}
|
}
|
||||||
this.setDataValue(name, value)
|
this.setDataValue(name, value)
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user