@7365admin1/core 3.128.0 → 3.129.1
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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +64 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -75
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/console-audit.test.mjs +13 -0
- package/test/e2e/visitor-search.e2e.test.mjs +27 -0
- package/test/visitor-search.test.mjs +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @iservice365/core
|
|
2
2
|
|
|
3
|
+
## 3.129.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6323620: Visitor list search is fast on large sites: block/level/unit and pass/key names are resolved to ids first instead of joining five collections onto every visitor row (staging 120k-row site: 20 s -> 0.2 s with the default one-month range, 84 s -> 0.7 s all-time). Same matches as before.
|
|
8
|
+
|
|
9
|
+
## 3.129.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- e24535d: Console audit: `inventory.item-archived` / `inventory.item-restored` actions (target `inventory-item`) for the Seven365 staff archive of old inventory items.
|
|
14
|
+
|
|
3
15
|
## 3.128.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -821,7 +821,9 @@ declare enum ConsoleAuditAction {
|
|
|
821
821
|
* vs a service provider's own store) that was saved wrong. One row per store
|
|
822
822
|
* changed, recorded by API-core's inventory repair endpoint.
|
|
823
823
|
*/
|
|
824
|
-
INVENTORY_STORE_TYPE_REPAIRED = "inventory.store-type-repaired"
|
|
824
|
+
INVENTORY_STORE_TYPE_REPAIRED = "inventory.store-type-repaired",
|
|
825
|
+
INVENTORY_ITEM_ARCHIVED = "inventory.item-archived",
|
|
826
|
+
INVENTORY_ITEM_RESTORED = "inventory.item-restored"
|
|
825
827
|
}
|
|
826
828
|
/**
|
|
827
829
|
* The three actions that live in `organization.controller.ts`.
|
|
@@ -847,6 +849,7 @@ declare enum ConsoleAuditTarget {
|
|
|
847
849
|
ROBOT = "robot",
|
|
848
850
|
ROBOT_MAP = "robot-map",
|
|
849
851
|
INVENTORY_STORE = "inventory-store",
|
|
852
|
+
INVENTORY_ITEM = "inventory-item",
|
|
850
853
|
MEMBER = "member"
|
|
851
854
|
}
|
|
852
855
|
/** A stored value is a primitive or it is not stored. */
|
package/dist/index.js
CHANGED
|
@@ -11484,6 +11484,8 @@ var ConsoleAuditAction = /* @__PURE__ */ ((ConsoleAuditAction3) => {
|
|
|
11484
11484
|
ConsoleAuditAction3["ROBOT_LIFT_REQUESTED"] = "robot.lift-requested";
|
|
11485
11485
|
ConsoleAuditAction3["ROBOT_LIFT_RELEASED"] = "robot.lift-released";
|
|
11486
11486
|
ConsoleAuditAction3["INVENTORY_STORE_TYPE_REPAIRED"] = "inventory.store-type-repaired";
|
|
11487
|
+
ConsoleAuditAction3["INVENTORY_ITEM_ARCHIVED"] = "inventory.item-archived";
|
|
11488
|
+
ConsoleAuditAction3["INVENTORY_ITEM_RESTORED"] = "inventory.item-restored";
|
|
11487
11489
|
return ConsoleAuditAction3;
|
|
11488
11490
|
})(ConsoleAuditAction || {});
|
|
11489
11491
|
var CLIENT_ACTIONS = [
|
|
@@ -11523,7 +11525,9 @@ var CONSOLE_AUDIT_LABELS = {
|
|
|
11523
11525
|
["robot.map-removed" /* ROBOT_MAP_REMOVED */]: "Building map removed",
|
|
11524
11526
|
["robot.lift-requested" /* ROBOT_LIFT_REQUESTED */]: "Robot asked for a lift",
|
|
11525
11527
|
["robot.lift-released" /* ROBOT_LIFT_RELEASED */]: "Robot lift request released",
|
|
11526
|
-
["inventory.store-type-repaired" /* INVENTORY_STORE_TYPE_REPAIRED */]: "Inventory store type corrected"
|
|
11528
|
+
["inventory.store-type-repaired" /* INVENTORY_STORE_TYPE_REPAIRED */]: "Inventory store type corrected",
|
|
11529
|
+
["inventory.item-archived" /* INVENTORY_ITEM_ARCHIVED */]: "Old inventory item archived",
|
|
11530
|
+
["inventory.item-restored" /* INVENTORY_ITEM_RESTORED */]: "Archived inventory item restored"
|
|
11527
11531
|
};
|
|
11528
11532
|
var ConsoleAuditTarget = /* @__PURE__ */ ((ConsoleAuditTarget2) => {
|
|
11529
11533
|
ConsoleAuditTarget2["ORGANIZATION"] = "organization";
|
|
@@ -11536,6 +11540,7 @@ var ConsoleAuditTarget = /* @__PURE__ */ ((ConsoleAuditTarget2) => {
|
|
|
11536
11540
|
ConsoleAuditTarget2["ROBOT"] = "robot";
|
|
11537
11541
|
ConsoleAuditTarget2["ROBOT_MAP"] = "robot-map";
|
|
11538
11542
|
ConsoleAuditTarget2["INVENTORY_STORE"] = "inventory-store";
|
|
11543
|
+
ConsoleAuditTarget2["INVENTORY_ITEM"] = "inventory-item";
|
|
11539
11544
|
ConsoleAuditTarget2["MEMBER"] = "member";
|
|
11540
11545
|
return ConsoleAuditTarget2;
|
|
11541
11546
|
})(ConsoleAuditTarget || {});
|
|
@@ -11585,6 +11590,8 @@ var ROBOT_MAP_AUDIT_FIELDS = [
|
|
|
11585
11590
|
var ROBOT_LIFT_AUDIT_FIELDS = ["name", "liftName", "fromFloor", "toFloor"];
|
|
11586
11591
|
var AUDIT_FIELDS = {
|
|
11587
11592
|
["inventory.store-type-repaired" /* INVENTORY_STORE_TYPE_REPAIRED */]: ["ownerType", "name"],
|
|
11593
|
+
["inventory.item-archived" /* INVENTORY_ITEM_ARCHIVED */]: ["status", "name", "store", "reason"],
|
|
11594
|
+
["inventory.item-restored" /* INVENTORY_ITEM_RESTORED */]: ["status", "name", "store", "reason"],
|
|
11588
11595
|
["robot.map-saved" /* ROBOT_MAP_SAVED */]: ROBOT_MAP_AUDIT_FIELDS,
|
|
11589
11596
|
["robot.map-updated" /* ROBOT_MAP_UPDATED */]: ROBOT_MAP_AUDIT_FIELDS,
|
|
11590
11597
|
["robot.map-removed" /* ROBOT_MAP_REMOVED */]: ROBOT_MAP_AUDIT_FIELDS,
|
|
@@ -16058,7 +16065,8 @@ function useVisitorTransactionRepo() {
|
|
|
16058
16065
|
throw new import_node_server_utils48.InternalServerError("Unable to connect to server.");
|
|
16059
16066
|
}
|
|
16060
16067
|
const collection = db2.collection(visitors_namespace_collection);
|
|
16061
|
-
|
|
16068
|
+
const searchDb = db2;
|
|
16069
|
+
async function buildSearchStages(search, siteIds) {
|
|
16062
16070
|
const text2 = normaliseVisitorSearch(search);
|
|
16063
16071
|
if (!text2)
|
|
16064
16072
|
return [];
|
|
@@ -16072,98 +16080,78 @@ function useVisitorTransactionRepo() {
|
|
|
16072
16080
|
$regex: `(^|\\s)${escape(value)}$`,
|
|
16073
16081
|
$options: "i"
|
|
16074
16082
|
});
|
|
16075
|
-
const
|
|
16076
|
-
|
|
16077
|
-
|
|
16078
|
-
|
|
16079
|
-
foreignField: "_id",
|
|
16080
|
-
pipeline: [{ $project: { _id: 0, name: 1 } }],
|
|
16081
|
-
as
|
|
16082
|
-
}
|
|
16083
|
-
});
|
|
16084
|
-
const keyNameLookup = (localField, as) => ({
|
|
16085
|
-
$lookup: {
|
|
16086
|
-
from: "keys",
|
|
16087
|
-
localField,
|
|
16088
|
-
foreignField: "_id",
|
|
16089
|
-
pipeline: [
|
|
16090
|
-
{
|
|
16091
|
-
$lookup: {
|
|
16092
|
-
from: "qr-code-templates",
|
|
16093
|
-
localField: "template",
|
|
16094
|
-
foreignField: "_id",
|
|
16095
|
-
pipeline: [{ $project: { prefixPass: 1 } }],
|
|
16096
|
-
as: "template"
|
|
16097
|
-
}
|
|
16098
|
-
},
|
|
16099
|
-
{
|
|
16100
|
-
$project: {
|
|
16101
|
-
_id: 0,
|
|
16102
|
-
prefixAndName: {
|
|
16103
|
-
$concat: [
|
|
16104
|
-
{ $ifNull: [{ $arrayElemAt: ["$template.prefixPass", 0] }, ""] },
|
|
16105
|
-
{ $ifNull: ["$name", ""] }
|
|
16106
|
-
]
|
|
16107
|
-
}
|
|
16108
|
-
}
|
|
16109
|
-
}
|
|
16110
|
-
],
|
|
16111
|
-
as
|
|
16112
|
-
}
|
|
16113
|
-
});
|
|
16114
|
-
const locationLookups = [
|
|
16115
|
-
nameLookup("buildings", "block", "_searchBlock"),
|
|
16116
|
-
nameLookup("building-levels", "level", "_searchLevel"),
|
|
16117
|
-
nameLookup("building-units", "unit", "_searchUnit")
|
|
16118
|
-
];
|
|
16119
|
-
const cleanup = {
|
|
16120
|
-
$project: {
|
|
16121
|
-
_searchBlock: 0,
|
|
16122
|
-
_searchLevel: 0,
|
|
16123
|
-
_searchUnit: 0,
|
|
16124
|
-
_searchPass: 0,
|
|
16125
|
-
_searchKeys: 0
|
|
16126
|
-
}
|
|
16127
|
-
};
|
|
16128
|
-
const unitMatch = (value, match = like) => ({
|
|
16129
|
-
$or: [{ "_searchUnit.name": match(value) }, { unitName: match(value) }]
|
|
16130
|
-
});
|
|
16083
|
+
const onSites = siteIds ? { site: { $in: siteIds } } : {};
|
|
16084
|
+
const levelOnSites = siteIds ? { $or: [{ site: { $in: siteIds } }, { site: null }, { site: "" }] } : {};
|
|
16085
|
+
const idsOf = (from, filter) => searchDb.collection(from).distinct("_id", filter);
|
|
16086
|
+
const inIds = (field, ids2) => ids2.length ? [{ [field]: { $in: ids2 } }] : [];
|
|
16131
16087
|
const parts = text2.split("/").map((part) => part.trim());
|
|
16132
16088
|
if (parts.length >= 2 && parts.length <= 3 && parts.every(Boolean)) {
|
|
16133
16089
|
const [block, level2, unit] = parts;
|
|
16090
|
+
const [blockIds2, levelIds2, unitIds2] = await Promise.all([
|
|
16091
|
+
idsOf("buildings", { ...onSites, name: blockName(block) }),
|
|
16092
|
+
idsOf("building-levels", { ...levelOnSites, name: exact(level2) }),
|
|
16093
|
+
unit ? idsOf("building-units", { ...onSites, name: exact(unit) }) : []
|
|
16094
|
+
]);
|
|
16134
16095
|
return [
|
|
16135
|
-
...locationLookups,
|
|
16136
16096
|
{
|
|
16137
16097
|
$match: {
|
|
16138
|
-
|
|
16139
|
-
|
|
16140
|
-
...unit &&
|
|
16098
|
+
block: { $in: blockIds2 },
|
|
16099
|
+
level: { $in: levelIds2 },
|
|
16100
|
+
...unit && {
|
|
16101
|
+
$or: [...inIds("unit", unitIds2), { unitName: exact(unit) }]
|
|
16102
|
+
}
|
|
16141
16103
|
}
|
|
16142
|
-
}
|
|
16143
|
-
cleanup
|
|
16104
|
+
}
|
|
16144
16105
|
];
|
|
16145
16106
|
}
|
|
16146
16107
|
const compact = text2.replace(/\s+/g, "");
|
|
16108
|
+
const [blockIds, levelIds, unitIds, keyIds] = await Promise.all([
|
|
16109
|
+
idsOf("buildings", { ...onSites, name: like(text2) }),
|
|
16110
|
+
idsOf("building-levels", { ...levelOnSites, name: like(text2) }),
|
|
16111
|
+
idsOf("building-units", { ...onSites, name: like(text2) }),
|
|
16112
|
+
compact ? matchingKeyIds(compact) : []
|
|
16113
|
+
]);
|
|
16147
16114
|
return [
|
|
16148
|
-
...locationLookups,
|
|
16149
|
-
keyNameLookup("visitorPass.keyId", "_searchPass"),
|
|
16150
|
-
keyNameLookup("passKeys.keyId", "_searchKeys"),
|
|
16151
16115
|
{
|
|
16152
16116
|
$match: {
|
|
16153
16117
|
$or: [
|
|
16154
16118
|
// name, company, purpose, NRIC, types, members; plates ignoring
|
|
16155
16119
|
// spaces/hyphens/case; phones by digits - visitor-search.util.
|
|
16156
16120
|
...visitorRowSearchOr(text2),
|
|
16157
|
-
|
|
16158
|
-
|
|
16159
|
-
|
|
16160
|
-
{
|
|
16161
|
-
|
|
16121
|
+
...inIds("block", blockIds),
|
|
16122
|
+
...inIds("level", levelIds),
|
|
16123
|
+
...inIds("unit", unitIds),
|
|
16124
|
+
{ unitName: like(text2) },
|
|
16125
|
+
...inIds("visitorPass.keyId", keyIds),
|
|
16126
|
+
...inIds("passKeys.keyId", keyIds)
|
|
16162
16127
|
]
|
|
16163
16128
|
}
|
|
16164
|
-
}
|
|
16165
|
-
|
|
16129
|
+
}
|
|
16130
|
+
];
|
|
16131
|
+
}
|
|
16132
|
+
async function matchingKeyIds(compact) {
|
|
16133
|
+
const t = compact.toLowerCase();
|
|
16134
|
+
const templates = await searchDb.collection("qr-code-templates").find({ prefixPass: { $nin: [null, ""] } }, { projection: { prefixPass: 1 } }).toArray();
|
|
16135
|
+
const or = [
|
|
16136
|
+
{ name: { $regex: escapeRegex2(compact), $options: "i" } }
|
|
16166
16137
|
];
|
|
16138
|
+
for (const tpl of templates) {
|
|
16139
|
+
const prefix = String(tpl.prefixPass).toLowerCase();
|
|
16140
|
+
const template = { $in: [tpl._id, String(tpl._id)] };
|
|
16141
|
+
if (prefix.includes(t)) {
|
|
16142
|
+
or.push({ template });
|
|
16143
|
+
continue;
|
|
16144
|
+
}
|
|
16145
|
+
for (let i = 1; i < t.length; i++) {
|
|
16146
|
+
if (prefix.endsWith(t.slice(0, i))) {
|
|
16147
|
+
or.push({
|
|
16148
|
+
template,
|
|
16149
|
+
name: { $regex: `^${escapeRegex2(compact.slice(i))}`, $options: "i" }
|
|
16150
|
+
});
|
|
16151
|
+
}
|
|
16152
|
+
}
|
|
16153
|
+
}
|
|
16154
|
+
return await searchDb.collection("keys").distinct("_id", { $or: or });
|
|
16167
16155
|
}
|
|
16168
16156
|
async function createTextIndex() {
|
|
16169
16157
|
try {
|
|
@@ -16267,10 +16255,11 @@ function useVisitorTransactionRepo() {
|
|
|
16267
16255
|
...passOrKey?.type == "key" && { passKeys: { $elemMatch: { keyId: new import_mongodb46.ObjectId(passOrKey.keyId) } } }
|
|
16268
16256
|
};
|
|
16269
16257
|
const finalSort = Object.keys(sort).length > 0 ? sort : { latestDate: -1 };
|
|
16258
|
+
const searchSiteIds = query2.site instanceof import_mongodb46.ObjectId ? [query2.site] : query2.site?.$in ?? null;
|
|
16270
16259
|
try {
|
|
16271
16260
|
const basePipeline = [
|
|
16272
16261
|
{ $match: query2 },
|
|
16273
|
-
...buildSearchStages(search),
|
|
16262
|
+
...await buildSearchStages(search, searchSiteIds),
|
|
16274
16263
|
{
|
|
16275
16264
|
$addFields: {
|
|
16276
16265
|
latestDate: { $max: ["$createdAt", "$updatedAt"] }
|