@7365admin1/core 3.52.18 → 3.52.19

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/dist/index.mjs CHANGED
@@ -11006,6 +11006,19 @@ function MOrg(value) {
11006
11006
 
11007
11007
  // src/repositories/organization.repo.ts
11008
11008
  import { ObjectId as ObjectId19 } from "mongodb";
11009
+ var DUPLICATE_FIELD_LABEL = {
11010
+ name: "name",
11011
+ email: "email address"
11012
+ };
11013
+ function duplicatedField(error) {
11014
+ if (error?.code !== 11e3 && !/duplicate/i.test(error?.message ?? "")) {
11015
+ return "";
11016
+ }
11017
+ const fromPattern = Object.keys(error?.keyPattern ?? {})[0];
11018
+ if (fromPattern)
11019
+ return fromPattern;
11020
+ return /index:\s*([A-Za-z0-9_]+?)_\d/.exec(error?.message ?? "")?.[1] ?? "";
11021
+ }
11009
11022
  function useOrgRepo() {
11010
11023
  const db2 = useAtlas12.getDb();
11011
11024
  if (!db2) {
@@ -11087,8 +11100,21 @@ function useOrgRepo() {
11087
11100
  await delNamespace();
11088
11101
  return id;
11089
11102
  } catch (error) {
11090
- logger9.log({ level: "error", message: error.message });
11091
- throw new InternalServerError9("Failed to update organization.");
11103
+ logger9.log({
11104
+ level: "error",
11105
+ message: `Organization update failed for ${id}: ${error?.name ?? "Error"}${error?.code !== void 0 ? ` code=${error.code}` : ""}${duplicatedField(error) ? ` key=${duplicatedField(error)}` : ""} fields=[${Object.keys(value ?? {}).join(",")}] ${error?.message ?? ""}`
11106
+ });
11107
+ if (error instanceof AppError3)
11108
+ throw error;
11109
+ const field = duplicatedField(error);
11110
+ if (field) {
11111
+ throw new BadRequestError19(
11112
+ `Another organization already uses this ${DUPLICATE_FIELD_LABEL[field] ?? field}. Please use a different one.`
11113
+ );
11114
+ }
11115
+ throw new InternalServerError9(
11116
+ `Failed to update organization${error?.code !== void 0 ? ` (${error.code})` : ""}.`
11117
+ );
11092
11118
  }
11093
11119
  }
11094
11120
  async function getAll({