@fonderie/customers 6.1.2 → 6.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/brain/signatures.md +1 -1
- package/dist/index.cjs +9 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.cts
CHANGED
|
@@ -196,7 +196,8 @@ declare class CustomerAddressModel {
|
|
|
196
196
|
}): Promise<ICustomerAddress>;
|
|
197
197
|
updateLabel(addrId: string, customerId: string, labelId: string): Promise<ICustomerAddress>;
|
|
198
198
|
setPrimary(addrId: string, customerId: string): Promise<void>;
|
|
199
|
-
|
|
199
|
+
/** Returns false when the address is not linked to THIS customer (no-op). */
|
|
200
|
+
remove(addrId: string, customerId: string): Promise<boolean>;
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
declare class CustomerEmailModel {
|
package/dist/index.d.ts
CHANGED
|
@@ -196,7 +196,8 @@ declare class CustomerAddressModel {
|
|
|
196
196
|
}): Promise<ICustomerAddress>;
|
|
197
197
|
updateLabel(addrId: string, customerId: string, labelId: string): Promise<ICustomerAddress>;
|
|
198
198
|
setPrimary(addrId: string, customerId: string): Promise<void>;
|
|
199
|
-
|
|
199
|
+
/** Returns false when the address is not linked to THIS customer (no-op). */
|
|
200
|
+
remove(addrId: string, customerId: string): Promise<boolean>;
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
declare class CustomerEmailModel {
|
package/dist/index.js
CHANGED
|
@@ -908,16 +908,18 @@ var CustomerAddressModel = class {
|
|
|
908
908
|
);
|
|
909
909
|
});
|
|
910
910
|
}
|
|
911
|
+
/** Returns false when the address is not linked to THIS customer (no-op). */
|
|
911
912
|
async remove(addrId, customerId) {
|
|
912
|
-
|
|
913
|
+
return this.store.transaction(async (tx) => {
|
|
913
914
|
const [deleted] = await tx.query(
|
|
914
915
|
`DELETE FROM fonderie_customer_addresses
|
|
915
916
|
WHERE addr_id = $1 AND customer_id = $2
|
|
916
917
|
RETURNING is_primary AS "isPrimary"`,
|
|
917
918
|
[addrId, customerId]
|
|
918
919
|
);
|
|
920
|
+
if (!deleted) return false;
|
|
919
921
|
await tx.query(`DELETE FROM fonderie_addresses WHERE id = $1`, [addrId]);
|
|
920
|
-
if (deleted
|
|
922
|
+
if (deleted.isPrimary) {
|
|
921
923
|
await tx.query(
|
|
922
924
|
`UPDATE fonderie_customer_addresses
|
|
923
925
|
SET is_primary = true
|
|
@@ -930,6 +932,7 @@ var CustomerAddressModel = class {
|
|
|
930
932
|
[customerId]
|
|
931
933
|
);
|
|
932
934
|
}
|
|
935
|
+
return true;
|
|
933
936
|
});
|
|
934
937
|
}
|
|
935
938
|
};
|
|
@@ -1733,7 +1736,10 @@ function customerAddressController(store) {
|
|
|
1733
1736
|
if (!isUuid(addrId)) {
|
|
1734
1737
|
return setApiResponse2(HTTP2.UNPROCESSABLE, "INVALID_PARAMETER", "addrId must be a valid UUID");
|
|
1735
1738
|
}
|
|
1736
|
-
await addresses.remove(addrId, r.customer.id);
|
|
1739
|
+
const removed = await addresses.remove(addrId, r.customer.id);
|
|
1740
|
+
if (!removed) {
|
|
1741
|
+
return setApiResponse2(HTTP2.NOT_FOUND, "NOT_FOUND", "Address not found");
|
|
1742
|
+
}
|
|
1737
1743
|
return setApiResponse2(HTTP2.OK, "ADDRESS_REMOVED", "Address removed successfully.");
|
|
1738
1744
|
}
|
|
1739
1745
|
};
|