mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-03 08:03:22 +00:00
fix(vendors): support sparse updates on current target
This commit is contained in:
parent
e6a3899f4c
commit
4fe9319d7a
2 changed files with 20 additions and 8 deletions
19
src/domain/vendors/mappers/vendor-mapper.ts
vendored
19
src/domain/vendors/mappers/vendor-mapper.ts
vendored
|
|
@ -191,16 +191,25 @@ export function mapVendorUpdateToBackend(vendor: unknown): Record<string, unknow
|
|||
] as const;
|
||||
|
||||
fieldMappings.forEach(([target, source]) => {
|
||||
if (Object.hasOwn(item, target)) payload[target] = item[target];
|
||||
if (Object.hasOwn(item, source)) payload[target] = item[source];
|
||||
if (Object.prototype.hasOwnProperty.call(item, target)) payload[target] = item[target];
|
||||
if (Object.prototype.hasOwnProperty.call(item, source)) payload[target] = item[source];
|
||||
});
|
||||
if (Object.hasOwn(item, "companyId") || Object.hasOwn(item, "CompanyId")) {
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(item, "companyId") ||
|
||||
Object.prototype.hasOwnProperty.call(item, "CompanyId")
|
||||
) {
|
||||
payload.companyId = readNumericCompanyId(item);
|
||||
}
|
||||
if (Object.hasOwn(item, "phone") || Object.hasOwn(item, "Phone")) {
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(item, "phone") ||
|
||||
Object.prototype.hasOwnProperty.call(item, "Phone")
|
||||
) {
|
||||
payload.phone = toCanonicalPhone(item.phone ?? item.Phone);
|
||||
}
|
||||
if (Object.hasOwn(item, "companyPhone") || Object.hasOwn(item, "CompanyPhone")) {
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(item, "companyPhone") ||
|
||||
Object.prototype.hasOwnProperty.call(item, "CompanyPhone")
|
||||
) {
|
||||
payload.companyPhone = toCanonicalPhone(item.companyPhone ?? item.CompanyPhone);
|
||||
}
|
||||
return payload;
|
||||
|
|
|
|||
9
src/domain/vendors/schemas/vendor-schema.ts
vendored
9
src/domain/vendors/schemas/vendor-schema.ts
vendored
|
|
@ -64,14 +64,17 @@ const VENDOR_UPDATE_FIELDS = [
|
|||
] as const satisfies readonly (keyof VendorFormValues)[];
|
||||
|
||||
export function getChangedVendorValues(
|
||||
values: VendorFormValues,
|
||||
values: Partial<VendorFormValues>,
|
||||
original: VendorFormValues | null,
|
||||
): VendorUpdateValues {
|
||||
if (!original) return {};
|
||||
|
||||
return VENDOR_UPDATE_FIELDS.reduce<VendorUpdateValues>((changed, field) => {
|
||||
if (!Object.is(values[field], original[field])) {
|
||||
changed[field] = values[field];
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(values, field) &&
|
||||
!Object.is(values[field], original[field])
|
||||
) {
|
||||
Object.assign(changed, { [field]: values[field] });
|
||||
}
|
||||
return changed;
|
||||
}, {});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue