@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/dist/index.mjs
CHANGED
|
@@ -10442,6 +10442,8 @@ var ConsoleAuditAction = /* @__PURE__ */ ((ConsoleAuditAction3) => {
|
|
|
10442
10442
|
ConsoleAuditAction3["ROBOT_LIFT_REQUESTED"] = "robot.lift-requested";
|
|
10443
10443
|
ConsoleAuditAction3["ROBOT_LIFT_RELEASED"] = "robot.lift-released";
|
|
10444
10444
|
ConsoleAuditAction3["INVENTORY_STORE_TYPE_REPAIRED"] = "inventory.store-type-repaired";
|
|
10445
|
+
ConsoleAuditAction3["INVENTORY_ITEM_ARCHIVED"] = "inventory.item-archived";
|
|
10446
|
+
ConsoleAuditAction3["INVENTORY_ITEM_RESTORED"] = "inventory.item-restored";
|
|
10445
10447
|
return ConsoleAuditAction3;
|
|
10446
10448
|
})(ConsoleAuditAction || {});
|
|
10447
10449
|
var CLIENT_ACTIONS = [
|
|
@@ -10481,7 +10483,9 @@ var CONSOLE_AUDIT_LABELS = {
|
|
|
10481
10483
|
["robot.map-removed" /* ROBOT_MAP_REMOVED */]: "Building map removed",
|
|
10482
10484
|
["robot.lift-requested" /* ROBOT_LIFT_REQUESTED */]: "Robot asked for a lift",
|
|
10483
10485
|
["robot.lift-released" /* ROBOT_LIFT_RELEASED */]: "Robot lift request released",
|
|
10484
|
-
["inventory.store-type-repaired" /* INVENTORY_STORE_TYPE_REPAIRED */]: "Inventory store type corrected"
|
|
10486
|
+
["inventory.store-type-repaired" /* INVENTORY_STORE_TYPE_REPAIRED */]: "Inventory store type corrected",
|
|
10487
|
+
["inventory.item-archived" /* INVENTORY_ITEM_ARCHIVED */]: "Old inventory item archived",
|
|
10488
|
+
["inventory.item-restored" /* INVENTORY_ITEM_RESTORED */]: "Archived inventory item restored"
|
|
10485
10489
|
};
|
|
10486
10490
|
var ConsoleAuditTarget = /* @__PURE__ */ ((ConsoleAuditTarget2) => {
|
|
10487
10491
|
ConsoleAuditTarget2["ORGANIZATION"] = "organization";
|
|
@@ -10494,6 +10498,7 @@ var ConsoleAuditTarget = /* @__PURE__ */ ((ConsoleAuditTarget2) => {
|
|
|
10494
10498
|
ConsoleAuditTarget2["ROBOT"] = "robot";
|
|
10495
10499
|
ConsoleAuditTarget2["ROBOT_MAP"] = "robot-map";
|
|
10496
10500
|
ConsoleAuditTarget2["INVENTORY_STORE"] = "inventory-store";
|
|
10501
|
+
ConsoleAuditTarget2["INVENTORY_ITEM"] = "inventory-item";
|
|
10497
10502
|
ConsoleAuditTarget2["MEMBER"] = "member";
|
|
10498
10503
|
return ConsoleAuditTarget2;
|
|
10499
10504
|
})(ConsoleAuditTarget || {});
|
|
@@ -10543,6 +10548,8 @@ var ROBOT_MAP_AUDIT_FIELDS = [
|
|
|
10543
10548
|
var ROBOT_LIFT_AUDIT_FIELDS = ["name", "liftName", "fromFloor", "toFloor"];
|
|
10544
10549
|
var AUDIT_FIELDS = {
|
|
10545
10550
|
["inventory.store-type-repaired" /* INVENTORY_STORE_TYPE_REPAIRED */]: ["ownerType", "name"],
|
|
10551
|
+
["inventory.item-archived" /* INVENTORY_ITEM_ARCHIVED */]: ["status", "name", "store", "reason"],
|
|
10552
|
+
["inventory.item-restored" /* INVENTORY_ITEM_RESTORED */]: ["status", "name", "store", "reason"],
|
|
10546
10553
|
["robot.map-saved" /* ROBOT_MAP_SAVED */]: ROBOT_MAP_AUDIT_FIELDS,
|
|
10547
10554
|
["robot.map-updated" /* ROBOT_MAP_UPDATED */]: ROBOT_MAP_AUDIT_FIELDS,
|
|
10548
10555
|
["robot.map-removed" /* ROBOT_MAP_REMOVED */]: ROBOT_MAP_AUDIT_FIELDS,
|
|
@@ -15071,7 +15078,8 @@ function useVisitorTransactionRepo() {
|
|
|
15071
15078
|
throw new InternalServerError18("Unable to connect to server.");
|
|
15072
15079
|
}
|
|
15073
15080
|
const collection = db2.collection(visitors_namespace_collection);
|
|
15074
|
-
|
|
15081
|
+
const searchDb = db2;
|
|
15082
|
+
async function buildSearchStages(search, siteIds) {
|
|
15075
15083
|
const text2 = normaliseVisitorSearch(search);
|
|
15076
15084
|
if (!text2)
|
|
15077
15085
|
return [];
|
|
@@ -15085,98 +15093,78 @@ function useVisitorTransactionRepo() {
|
|
|
15085
15093
|
$regex: `(^|\\s)${escape(value)}$`,
|
|
15086
15094
|
$options: "i"
|
|
15087
15095
|
});
|
|
15088
|
-
const
|
|
15089
|
-
|
|
15090
|
-
|
|
15091
|
-
|
|
15092
|
-
foreignField: "_id",
|
|
15093
|
-
pipeline: [{ $project: { _id: 0, name: 1 } }],
|
|
15094
|
-
as
|
|
15095
|
-
}
|
|
15096
|
-
});
|
|
15097
|
-
const keyNameLookup = (localField, as) => ({
|
|
15098
|
-
$lookup: {
|
|
15099
|
-
from: "keys",
|
|
15100
|
-
localField,
|
|
15101
|
-
foreignField: "_id",
|
|
15102
|
-
pipeline: [
|
|
15103
|
-
{
|
|
15104
|
-
$lookup: {
|
|
15105
|
-
from: "qr-code-templates",
|
|
15106
|
-
localField: "template",
|
|
15107
|
-
foreignField: "_id",
|
|
15108
|
-
pipeline: [{ $project: { prefixPass: 1 } }],
|
|
15109
|
-
as: "template"
|
|
15110
|
-
}
|
|
15111
|
-
},
|
|
15112
|
-
{
|
|
15113
|
-
$project: {
|
|
15114
|
-
_id: 0,
|
|
15115
|
-
prefixAndName: {
|
|
15116
|
-
$concat: [
|
|
15117
|
-
{ $ifNull: [{ $arrayElemAt: ["$template.prefixPass", 0] }, ""] },
|
|
15118
|
-
{ $ifNull: ["$name", ""] }
|
|
15119
|
-
]
|
|
15120
|
-
}
|
|
15121
|
-
}
|
|
15122
|
-
}
|
|
15123
|
-
],
|
|
15124
|
-
as
|
|
15125
|
-
}
|
|
15126
|
-
});
|
|
15127
|
-
const locationLookups = [
|
|
15128
|
-
nameLookup("buildings", "block", "_searchBlock"),
|
|
15129
|
-
nameLookup("building-levels", "level", "_searchLevel"),
|
|
15130
|
-
nameLookup("building-units", "unit", "_searchUnit")
|
|
15131
|
-
];
|
|
15132
|
-
const cleanup = {
|
|
15133
|
-
$project: {
|
|
15134
|
-
_searchBlock: 0,
|
|
15135
|
-
_searchLevel: 0,
|
|
15136
|
-
_searchUnit: 0,
|
|
15137
|
-
_searchPass: 0,
|
|
15138
|
-
_searchKeys: 0
|
|
15139
|
-
}
|
|
15140
|
-
};
|
|
15141
|
-
const unitMatch = (value, match = like) => ({
|
|
15142
|
-
$or: [{ "_searchUnit.name": match(value) }, { unitName: match(value) }]
|
|
15143
|
-
});
|
|
15096
|
+
const onSites = siteIds ? { site: { $in: siteIds } } : {};
|
|
15097
|
+
const levelOnSites = siteIds ? { $or: [{ site: { $in: siteIds } }, { site: null }, { site: "" }] } : {};
|
|
15098
|
+
const idsOf = (from, filter) => searchDb.collection(from).distinct("_id", filter);
|
|
15099
|
+
const inIds = (field, ids2) => ids2.length ? [{ [field]: { $in: ids2 } }] : [];
|
|
15144
15100
|
const parts = text2.split("/").map((part) => part.trim());
|
|
15145
15101
|
if (parts.length >= 2 && parts.length <= 3 && parts.every(Boolean)) {
|
|
15146
15102
|
const [block, level2, unit] = parts;
|
|
15103
|
+
const [blockIds2, levelIds2, unitIds2] = await Promise.all([
|
|
15104
|
+
idsOf("buildings", { ...onSites, name: blockName(block) }),
|
|
15105
|
+
idsOf("building-levels", { ...levelOnSites, name: exact(level2) }),
|
|
15106
|
+
unit ? idsOf("building-units", { ...onSites, name: exact(unit) }) : []
|
|
15107
|
+
]);
|
|
15147
15108
|
return [
|
|
15148
|
-
...locationLookups,
|
|
15149
15109
|
{
|
|
15150
15110
|
$match: {
|
|
15151
|
-
|
|
15152
|
-
|
|
15153
|
-
...unit &&
|
|
15111
|
+
block: { $in: blockIds2 },
|
|
15112
|
+
level: { $in: levelIds2 },
|
|
15113
|
+
...unit && {
|
|
15114
|
+
$or: [...inIds("unit", unitIds2), { unitName: exact(unit) }]
|
|
15115
|
+
}
|
|
15154
15116
|
}
|
|
15155
|
-
}
|
|
15156
|
-
cleanup
|
|
15117
|
+
}
|
|
15157
15118
|
];
|
|
15158
15119
|
}
|
|
15159
15120
|
const compact = text2.replace(/\s+/g, "");
|
|
15121
|
+
const [blockIds, levelIds, unitIds, keyIds] = await Promise.all([
|
|
15122
|
+
idsOf("buildings", { ...onSites, name: like(text2) }),
|
|
15123
|
+
idsOf("building-levels", { ...levelOnSites, name: like(text2) }),
|
|
15124
|
+
idsOf("building-units", { ...onSites, name: like(text2) }),
|
|
15125
|
+
compact ? matchingKeyIds(compact) : []
|
|
15126
|
+
]);
|
|
15160
15127
|
return [
|
|
15161
|
-
...locationLookups,
|
|
15162
|
-
keyNameLookup("visitorPass.keyId", "_searchPass"),
|
|
15163
|
-
keyNameLookup("passKeys.keyId", "_searchKeys"),
|
|
15164
15128
|
{
|
|
15165
15129
|
$match: {
|
|
15166
15130
|
$or: [
|
|
15167
15131
|
// name, company, purpose, NRIC, types, members; plates ignoring
|
|
15168
15132
|
// spaces/hyphens/case; phones by digits - visitor-search.util.
|
|
15169
15133
|
...visitorRowSearchOr(text2),
|
|
15170
|
-
|
|
15171
|
-
|
|
15172
|
-
|
|
15173
|
-
{
|
|
15174
|
-
|
|
15134
|
+
...inIds("block", blockIds),
|
|
15135
|
+
...inIds("level", levelIds),
|
|
15136
|
+
...inIds("unit", unitIds),
|
|
15137
|
+
{ unitName: like(text2) },
|
|
15138
|
+
...inIds("visitorPass.keyId", keyIds),
|
|
15139
|
+
...inIds("passKeys.keyId", keyIds)
|
|
15175
15140
|
]
|
|
15176
15141
|
}
|
|
15177
|
-
}
|
|
15178
|
-
|
|
15142
|
+
}
|
|
15143
|
+
];
|
|
15144
|
+
}
|
|
15145
|
+
async function matchingKeyIds(compact) {
|
|
15146
|
+
const t = compact.toLowerCase();
|
|
15147
|
+
const templates = await searchDb.collection("qr-code-templates").find({ prefixPass: { $nin: [null, ""] } }, { projection: { prefixPass: 1 } }).toArray();
|
|
15148
|
+
const or = [
|
|
15149
|
+
{ name: { $regex: escapeRegex2(compact), $options: "i" } }
|
|
15179
15150
|
];
|
|
15151
|
+
for (const tpl of templates) {
|
|
15152
|
+
const prefix = String(tpl.prefixPass).toLowerCase();
|
|
15153
|
+
const template = { $in: [tpl._id, String(tpl._id)] };
|
|
15154
|
+
if (prefix.includes(t)) {
|
|
15155
|
+
or.push({ template });
|
|
15156
|
+
continue;
|
|
15157
|
+
}
|
|
15158
|
+
for (let i = 1; i < t.length; i++) {
|
|
15159
|
+
if (prefix.endsWith(t.slice(0, i))) {
|
|
15160
|
+
or.push({
|
|
15161
|
+
template,
|
|
15162
|
+
name: { $regex: `^${escapeRegex2(compact.slice(i))}`, $options: "i" }
|
|
15163
|
+
});
|
|
15164
|
+
}
|
|
15165
|
+
}
|
|
15166
|
+
}
|
|
15167
|
+
return await searchDb.collection("keys").distinct("_id", { $or: or });
|
|
15180
15168
|
}
|
|
15181
15169
|
async function createTextIndex() {
|
|
15182
15170
|
try {
|
|
@@ -15280,10 +15268,11 @@ function useVisitorTransactionRepo() {
|
|
|
15280
15268
|
...passOrKey?.type == "key" && { passKeys: { $elemMatch: { keyId: new ObjectId46(passOrKey.keyId) } } }
|
|
15281
15269
|
};
|
|
15282
15270
|
const finalSort = Object.keys(sort).length > 0 ? sort : { latestDate: -1 };
|
|
15271
|
+
const searchSiteIds = query2.site instanceof ObjectId46 ? [query2.site] : query2.site?.$in ?? null;
|
|
15283
15272
|
try {
|
|
15284
15273
|
const basePipeline = [
|
|
15285
15274
|
{ $match: query2 },
|
|
15286
|
-
...buildSearchStages(search),
|
|
15275
|
+
...await buildSearchStages(search, searchSiteIds),
|
|
15287
15276
|
{
|
|
15288
15277
|
$addFields: {
|
|
15289
15278
|
latestDate: { $max: ["$createdAt", "$updatedAt"] }
|