@fonderie/customers 6.1.3 → 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.
@@ -117,7 +117,7 @@ new CustomerAddressModel(store: IStoreAdapter): CustomerAddressModel
117
117
  .add(opts: { customerId: string; countryIso: string; subdivision1Iso?: string | null; subdivision2Iso?: string | null; zipPostalCode: string; unit?: string | null; line1?: string | null; line2?: string | null; labelId: string; isPrimary?: boolean; }): Promise<...>
118
118
  .updateLabel(addrId: string, customerId: string, labelId: string): Promise<ICustomerAddress>
119
119
  .setPrimary(addrId: string, customerId: string): Promise<void>
120
- .remove(addrId: string, customerId: string): Promise<void>
120
+ .remove(addrId: string, customerId: string): Promise<boolean>
121
121
 
122
122
  new CustomerEmailModel(store: IStoreAdapter): CustomerEmailModel
123
123
  .list(customerId: string): Promise<ICustomerEmail[]>
package/dist/index.cjs CHANGED
@@ -944,16 +944,18 @@ var CustomerAddressModel = class {
944
944
  );
945
945
  });
946
946
  }
947
+ /** Returns false when the address is not linked to THIS customer (no-op). */
947
948
  async remove(addrId, customerId) {
948
- await this.store.transaction(async (tx) => {
949
+ return this.store.transaction(async (tx) => {
949
950
  const [deleted] = await tx.query(
950
951
  `DELETE FROM fonderie_customer_addresses
951
952
  WHERE addr_id = $1 AND customer_id = $2
952
953
  RETURNING is_primary AS "isPrimary"`,
953
954
  [addrId, customerId]
954
955
  );
956
+ if (!deleted) return false;
955
957
  await tx.query(`DELETE FROM fonderie_addresses WHERE id = $1`, [addrId]);
956
- if (deleted?.isPrimary) {
958
+ if (deleted.isPrimary) {
957
959
  await tx.query(
958
960
  `UPDATE fonderie_customer_addresses
959
961
  SET is_primary = true
@@ -966,6 +968,7 @@ var CustomerAddressModel = class {
966
968
  [customerId]
967
969
  );
968
970
  }
971
+ return true;
969
972
  });
970
973
  }
971
974
  };
@@ -1769,7 +1772,10 @@ function customerAddressController(store) {
1769
1772
  if (!isUuid(addrId)) {
1770
1773
  return (0, import_core3.setApiResponse)(import_core3.HTTP.UNPROCESSABLE, "INVALID_PARAMETER", "addrId must be a valid UUID");
1771
1774
  }
1772
- await addresses.remove(addrId, r.customer.id);
1775
+ const removed = await addresses.remove(addrId, r.customer.id);
1776
+ if (!removed) {
1777
+ return (0, import_core3.setApiResponse)(import_core3.HTTP.NOT_FOUND, "NOT_FOUND", "Address not found");
1778
+ }
1773
1779
  return (0, import_core3.setApiResponse)(import_core3.HTTP.OK, "ADDRESS_REMOVED", "Address removed successfully.");
1774
1780
  }
1775
1781
  };