@7365admin1/core 3.125.1-staging.420 → 3.125.1-staging.422

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,5 @@
1
+ ---
2
+ "@7365admin1/core": minor
3
+ ---
4
+
5
+ Console audit: `inventory.item-archived` / `inventory.item-restored` actions (target `inventory-item`) for the Seven365 staff archive of old inventory items.
@@ -0,0 +1,5 @@
1
+ ---
2
+ "@7365admin1/core": patch
3
+ ---
4
+
5
+ Create/rename role: a name already used in the organisation now says where (e.g. "already exists in this organisation at Winsland House II") and suggests a site-specific name, instead of the bare "Role already exists.". Role names stay unique per organisation and application.
package/dist/index.d.ts CHANGED
@@ -823,7 +823,9 @@ declare enum ConsoleAuditAction {
823
823
  * vs a service provider's own store) that was saved wrong. One row per store
824
824
  * changed, recorded by API-core's inventory repair endpoint.
825
825
  */
826
- INVENTORY_STORE_TYPE_REPAIRED = "inventory.store-type-repaired"
826
+ INVENTORY_STORE_TYPE_REPAIRED = "inventory.store-type-repaired",
827
+ INVENTORY_ITEM_ARCHIVED = "inventory.item-archived",
828
+ INVENTORY_ITEM_RESTORED = "inventory.item-restored"
827
829
  }
828
830
  /**
829
831
  * The three actions that live in `organization.controller.ts`.
@@ -849,6 +851,7 @@ declare enum ConsoleAuditTarget {
849
851
  ROBOT = "robot",
850
852
  ROBOT_MAP = "robot-map",
851
853
  INVENTORY_STORE = "inventory-store",
854
+ INVENTORY_ITEM = "inventory-item",
852
855
  MEMBER = "member"
853
856
  }
854
857
  /** A stored value is a primitive or it is not stored. */
package/dist/index.js CHANGED
@@ -11549,6 +11549,8 @@ var ConsoleAuditAction = /* @__PURE__ */ ((ConsoleAuditAction3) => {
11549
11549
  ConsoleAuditAction3["ROBOT_LIFT_REQUESTED"] = "robot.lift-requested";
11550
11550
  ConsoleAuditAction3["ROBOT_LIFT_RELEASED"] = "robot.lift-released";
11551
11551
  ConsoleAuditAction3["INVENTORY_STORE_TYPE_REPAIRED"] = "inventory.store-type-repaired";
11552
+ ConsoleAuditAction3["INVENTORY_ITEM_ARCHIVED"] = "inventory.item-archived";
11553
+ ConsoleAuditAction3["INVENTORY_ITEM_RESTORED"] = "inventory.item-restored";
11552
11554
  return ConsoleAuditAction3;
11553
11555
  })(ConsoleAuditAction || {});
11554
11556
  var CLIENT_ACTIONS = [
@@ -11588,7 +11590,9 @@ var CONSOLE_AUDIT_LABELS = {
11588
11590
  ["robot.map-removed" /* ROBOT_MAP_REMOVED */]: "Building map removed",
11589
11591
  ["robot.lift-requested" /* ROBOT_LIFT_REQUESTED */]: "Robot asked for a lift",
11590
11592
  ["robot.lift-released" /* ROBOT_LIFT_RELEASED */]: "Robot lift request released",
11591
- ["inventory.store-type-repaired" /* INVENTORY_STORE_TYPE_REPAIRED */]: "Inventory store type corrected"
11593
+ ["inventory.store-type-repaired" /* INVENTORY_STORE_TYPE_REPAIRED */]: "Inventory store type corrected",
11594
+ ["inventory.item-archived" /* INVENTORY_ITEM_ARCHIVED */]: "Old inventory item archived",
11595
+ ["inventory.item-restored" /* INVENTORY_ITEM_RESTORED */]: "Archived inventory item restored"
11592
11596
  };
11593
11597
  var ConsoleAuditTarget = /* @__PURE__ */ ((ConsoleAuditTarget2) => {
11594
11598
  ConsoleAuditTarget2["ORGANIZATION"] = "organization";
@@ -11601,6 +11605,7 @@ var ConsoleAuditTarget = /* @__PURE__ */ ((ConsoleAuditTarget2) => {
11601
11605
  ConsoleAuditTarget2["ROBOT"] = "robot";
11602
11606
  ConsoleAuditTarget2["ROBOT_MAP"] = "robot-map";
11603
11607
  ConsoleAuditTarget2["INVENTORY_STORE"] = "inventory-store";
11608
+ ConsoleAuditTarget2["INVENTORY_ITEM"] = "inventory-item";
11604
11609
  ConsoleAuditTarget2["MEMBER"] = "member";
11605
11610
  return ConsoleAuditTarget2;
11606
11611
  })(ConsoleAuditTarget || {});
@@ -11650,6 +11655,8 @@ var ROBOT_MAP_AUDIT_FIELDS = [
11650
11655
  var ROBOT_LIFT_AUDIT_FIELDS = ["name", "liftName", "fromFloor", "toFloor"];
11651
11656
  var AUDIT_FIELDS = {
11652
11657
  ["inventory.store-type-repaired" /* INVENTORY_STORE_TYPE_REPAIRED */]: ["ownerType", "name"],
11658
+ ["inventory.item-archived" /* INVENTORY_ITEM_ARCHIVED */]: ["status", "name", "store", "reason"],
11659
+ ["inventory.item-restored" /* INVENTORY_ITEM_RESTORED */]: ["status", "name", "store", "reason"],
11653
11660
  ["robot.map-saved" /* ROBOT_MAP_SAVED */]: ROBOT_MAP_AUDIT_FIELDS,
11654
11661
  ["robot.map-updated" /* ROBOT_MAP_UPDATED */]: ROBOT_MAP_AUDIT_FIELDS,
11655
11662
  ["robot.map-removed" /* ROBOT_MAP_REMOVED */]: ROBOT_MAP_AUDIT_FIELDS,
@@ -25613,6 +25620,43 @@ function useRoleRepo() {
25613
25620
  }
25614
25621
  const { delNamespace, setCache, getCache } = (0, import_node_server_utils61.useCache)(namespace_collection3);
25615
25622
  const { delNamespace: _delDashboardNameSpace } = (0, import_node_server_utils61.useCache)("dashboard");
25623
+ async function nameTakenMessage(value) {
25624
+ const name = String(value?.name ?? "");
25625
+ const fallback = `A role named "${name}" already exists in this organisation. Please choose a different name.`;
25626
+ try {
25627
+ const clash = await collection.findOne(
25628
+ {
25629
+ name,
25630
+ type: value.type,
25631
+ org: value.org,
25632
+ deletedAt: value.deletedAt ?? ""
25633
+ },
25634
+ { projection: { site: 1 } }
25635
+ );
25636
+ if (!clash)
25637
+ return fallback;
25638
+ if (!clash.site) {
25639
+ return `A role named "${name}" already exists for the whole organisation. Role names must be different across the organisation and all its sites - please choose a different name.`;
25640
+ }
25641
+ const siteName = async (id) => {
25642
+ if (!id)
25643
+ return "";
25644
+ const doc = await db2?.collection("sites").findOne(
25645
+ { _id: new import_mongodb57.ObjectId(String(id)) },
25646
+ { projection: { name: 1 } }
25647
+ ).catch(() => null);
25648
+ return doc?.name ?? "";
25649
+ };
25650
+ if (value.site && String(value.site) === String(clash.site)) {
25651
+ return `A role named "${name}" already exists at this site. Please choose a different name.`;
25652
+ }
25653
+ const [there, here] = await Promise.all([siteName(clash.site), siteName(value.site)]);
25654
+ const suggestion = here ? `, for example "${name} - ${here}"` : "";
25655
+ return `A role named "${name}" already exists in this organisation${there ? ` at ${there}` : " at another site"}. Role names must be different across all your sites - please choose a different name${suggestion}.`;
25656
+ } catch {
25657
+ return fallback;
25658
+ }
25659
+ }
25616
25660
  async function addRole(value, session) {
25617
25661
  value = new MRole({ ...value, type: serviceAppType(value.type) });
25618
25662
  try {
@@ -25630,7 +25674,7 @@ function useRoleRepo() {
25630
25674
  import_node_server_utils61.logger.log({ level: "error", message: `${error}` });
25631
25675
  const isDuplicated = error.message.includes("duplicate");
25632
25676
  if (isDuplicated) {
25633
- throw new import_node_server_utils61.BadRequestError("Role already exists.");
25677
+ throw new import_node_server_utils61.BadRequestError(await nameTakenMessage(value));
25634
25678
  }
25635
25679
  throw new import_node_server_utils61.InternalServerError("Failed to create role.");
25636
25680
  }
@@ -25859,7 +25903,10 @@ function useRoleRepo() {
25859
25903
  } catch (error) {
25860
25904
  const isDuplicated = error.message.includes("duplicate");
25861
25905
  if (isDuplicated) {
25862
- throw new import_node_server_utils61.BadRequestError("Role name already exists.");
25906
+ const current = await collection.findOne({ _id }, { projection: { type: 1, org: 1, site: 1, deletedAt: 1 } }).catch(() => null);
25907
+ throw new import_node_server_utils61.BadRequestError(
25908
+ await nameTakenMessage({ ...current ?? {}, name: value.name })
25909
+ );
25863
25910
  }
25864
25911
  throw new import_node_server_utils61.InternalServerError("Failed to update role.");
25865
25912
  }