Skip to content

Commit 996a2c2

Browse files
author
Andrea Cosentino
committed
fix: partial delete with json objects
1 parent e3d7096 commit 996a2c2

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/utils/plugin.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,14 +431,20 @@ async function handlingApiFsRequest(logger: ILogger, fullUrl: URL, request: Univ
431431
JSON.stringify(dataFile.originalData[key]) === JSON.stringify(dataFile.data[key]) && delete (newData as Record<string, any>)[key];
432432
})
433433
}
434-
// INFO partial delete allowed allowed in json file with array
435434
if (Array.isArray(newData) && newData.length > 0) {
436435
removeFile = false;
437436
await Utils.files.writingFile(file, fileFound, newData, MimeType[".json"], true);
438437
result.headers.push({
439438
name: Constants.DELETED_ELEMENTS_HEADER,
440439
value: dataFile.originalData.length - newData.length
441440
});
441+
} else if (!Array.isArray(newData) && Object.keys(newData).length > 0) {
442+
removeFile = false;
443+
await Utils.files.writingFile(file, fileFound, newData, MimeType[".json"], true);
444+
result.headers.push({
445+
name: Constants.DELETED_ELEMENTS_HEADER,
446+
value: 0
447+
});
442448
}
443449
}
444450
if (removeFile) {

0 commit comments

Comments
 (0)