@7365admin1/core 3.52.16-staging.267 → 3.52.16-staging.268
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.
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
"@7365admin1/core": patch
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Say what is wrong when an organisation cannot be saved.
|
|
6
|
+
|
|
7
|
+
`PUT /api/organizations/:id` — the write behind onboarding step 1 and the staff
|
|
8
|
+
Client List edit — collapsed every MongoDB write error into a 500 reading
|
|
9
|
+
"Failed to update organization.", with only `error.message` in the log. A
|
|
10
|
+
duplicate-key refusal (the `organizations` collection still carries a unique
|
|
11
|
+
index an earlier version of this file created and nothing ever dropped) is now
|
|
12
|
+
a 400 naming the field the caller has to change, a typed error raised
|
|
13
|
+
underneath is no longer turned into a 500, and the log line carries the error
|
|
14
|
+
name, code, key and the organisation id.
|
package/dist/index.js
CHANGED
|
@@ -11683,6 +11683,19 @@ function MOrg(value) {
|
|
|
11683
11683
|
|
|
11684
11684
|
// src/repositories/organization.repo.ts
|
|
11685
11685
|
var import_mongodb19 = require("mongodb");
|
|
11686
|
+
var DUPLICATE_FIELD_LABEL = {
|
|
11687
|
+
name: "name",
|
|
11688
|
+
email: "email address"
|
|
11689
|
+
};
|
|
11690
|
+
function duplicatedField(error) {
|
|
11691
|
+
if (error?.code !== 11e3 && !/duplicate/i.test(error?.message ?? "")) {
|
|
11692
|
+
return "";
|
|
11693
|
+
}
|
|
11694
|
+
const fromPattern = Object.keys(error?.keyPattern ?? {})[0];
|
|
11695
|
+
if (fromPattern)
|
|
11696
|
+
return fromPattern;
|
|
11697
|
+
return /index:\s*([A-Za-z0-9_]+?)_\d/.exec(error?.message ?? "")?.[1] ?? "";
|
|
11698
|
+
}
|
|
11686
11699
|
function useOrgRepo() {
|
|
11687
11700
|
const db2 = import_node_server_utils21.useAtlas.getDb();
|
|
11688
11701
|
if (!db2) {
|
|
@@ -11764,8 +11777,21 @@ function useOrgRepo() {
|
|
|
11764
11777
|
await delNamespace();
|
|
11765
11778
|
return id;
|
|
11766
11779
|
} catch (error) {
|
|
11767
|
-
import_node_server_utils21.logger.log({
|
|
11768
|
-
|
|
11780
|
+
import_node_server_utils21.logger.log({
|
|
11781
|
+
level: "error",
|
|
11782
|
+
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 ?? ""}`
|
|
11783
|
+
});
|
|
11784
|
+
if (error instanceof import_node_server_utils21.AppError)
|
|
11785
|
+
throw error;
|
|
11786
|
+
const field = duplicatedField(error);
|
|
11787
|
+
if (field) {
|
|
11788
|
+
throw new import_node_server_utils21.BadRequestError(
|
|
11789
|
+
`Another organization already uses this ${DUPLICATE_FIELD_LABEL[field] ?? field}. Please use a different one.`
|
|
11790
|
+
);
|
|
11791
|
+
}
|
|
11792
|
+
throw new import_node_server_utils21.InternalServerError(
|
|
11793
|
+
`Failed to update organization${error?.code !== void 0 ? ` (${error.code})` : ""}.`
|
|
11794
|
+
);
|
|
11769
11795
|
}
|
|
11770
11796
|
}
|
|
11771
11797
|
async function getAll({
|