Skip to content

Commit dad579f

Browse files
committed
Fix triggering update for multiple linked objects
1 parent ab1d757 commit dad579f

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

src/server/sendDataToGeoserver.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async function updateObject(object, currentObject) {
5757
const configuration = getPluginConfiguration();
5858
const authorizationString = getAuthorizationString(configuration);
5959

60-
addDataFromCurrentObject(object, currentObject);
60+
if (currentObject) addDataFromCurrentObject(object, currentObject);
6161
addToObjectCache(object);
6262

6363
const linkedObjectConfiguration = getLinkedObjectConfiguration(object._objecttype, configuration);
@@ -72,8 +72,8 @@ async function updateObject(object, currentObject) {
7272
return throwErrorToFrontend('Eine oder mehrere Geometrien sind bereits mit anderen Objekten verknüpft.', undefined, 'multipleGeometryLinking');
7373
}
7474

75-
await editGeometries(object, currentObject, fieldConfiguration, geometryIds, authorizationString);
76-
await deleteGeometries(fieldConfiguration, geometryIds, currentObject, authorizationString);
75+
await editGeometries(object, fieldConfiguration, geometryIds, authorizationString);
76+
if (currentObject) await deleteGeometries(fieldConfiguration, geometryIds, currentObject, authorizationString);
7777
}
7878
}
7979

@@ -83,9 +83,9 @@ function getLinkedObjectConfiguration(objectType, configuration) {
8383

8484
async function updateLinkedObjects(object, linkedObjectConfiguration) {
8585
const linkedObjects = await getFieldValues(object, linkedObjectConfiguration.link_field_name.split('.'));
86-
86+
8787
for (let linkedObject of linkedObjects) {
88-
await updateObject(linkedObject, linkedObject);
88+
await updateObject(linkedObject, undefined);
8989
}
9090
}
9191

@@ -145,7 +145,7 @@ function getGeometryFieldPaths(configuration) {
145145
return fieldPaths;
146146
}
147147

148-
async function editGeometries(object, currentObject, fieldConfiguration, geometryIds, authorizationString) {
148+
async function editGeometries(object, fieldConfiguration, geometryIds, authorizationString) {
149149
if (isSendingDataToGeoserverActivated(fieldConfiguration, geometryIds)) {
150150
const changeMap = await getChangeMap(object, fieldConfiguration);
151151
if (Object.keys(changeMap).length) {
@@ -177,7 +177,7 @@ function addDataFromCurrentObject(object, currentObject) {
177177
if (Array.isArray(object[fieldName])) {
178178
for (let i = 0; i < object[fieldName].length; i++) {
179179
if (!hasLinkedObjectData(object[fieldName][i])) {
180-
object[fieldName][i] = currentObject[fieldName].find(entry => entry._id = object[fieldName][i]._id);
180+
object[fieldName][i] = currentObject[fieldName].find(entry => entry._id === object[fieldName][i]._id);
181181
}
182182
}
183183
} else if (!hasLinkedObjectData(object[fieldName])) {
@@ -224,7 +224,7 @@ async function getFieldValues(object, pathSegments) {
224224
if (pathSegments.length === 0) {
225225
return [field];
226226
} else if (Array.isArray(field)) {
227-
let fieldValues = [];
227+
const fieldValues = [];
228228
for (let entry of field) {
229229
fieldValues.push(await getFieldValues(entry, pathSegments.slice()));
230230
}

0 commit comments

Comments
 (0)