Update
This commit is contained in:
1 parent
cfb96f03c0
commit
b7f7d7e793
3 files changed
+58
-6
No files matched your search
+29
-3
@@ -1868,12 +1868,38 @@ function syncComparableValue(value: unknown) {
|
||||
return value ?? null;
|
||||
}
|
||||
|
||||
function syncValueChanged(left: unknown, right: unknown) {
|
||||
return JSON.stringify(syncComparableValue(left)) !== JSON.stringify(syncComparableValue(right));
|
||||
function syncIdComparableValue(value: unknown) {
|
||||
const comparable = syncComparableValue(value);
|
||||
|
||||
if (typeof comparable === "number" && Number.isInteger(comparable)) {
|
||||
return String(comparable);
|
||||
}
|
||||
|
||||
if (typeof comparable === "bigint") {
|
||||
return comparable.toString();
|
||||
}
|
||||
|
||||
if (typeof comparable === "string" && /^\d+$/.test(comparable.trim())) {
|
||||
return comparable.trim().replace(/^0+(?=\d)/, "");
|
||||
}
|
||||
|
||||
return comparable;
|
||||
}
|
||||
|
||||
function syncComparableValueForField(field: string, value: unknown) {
|
||||
if (field === "Organisation") {
|
||||
return syncIdComparableValue(value);
|
||||
}
|
||||
|
||||
return syncComparableValue(value);
|
||||
}
|
||||
|
||||
function syncValueChanged(field: string, left: unknown, right: unknown) {
|
||||
return JSON.stringify(syncComparableValueForField(field, left)) !== JSON.stringify(syncComparableValueForField(field, right));
|
||||
}
|
||||
|
||||
function addSyncChange(changes: ZammadSyncChange[], field: string, from: unknown, to: unknown) {
|
||||
if (syncValueChanged(from, to)) {
|
||||
if (syncValueChanged(field, from, to)) {
|
||||
changes.push({ field, from: syncComparableValue(from), to: syncComparableValue(to) });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user