@7365admin1/core 3.124.3-staging.415 → 3.124.3-staging.416
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/.changeset/visitor-search-all-fields.md +5 -0
- package/dist/index.js +66 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/test/e2e/visitor-search.e2e.test.mjs +107 -0
- package/test/visitor-search.test.mjs +122 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
---
|
|
2
|
+
"@7365admin1/core": patch
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Visitor Management search (GET /api/visitor-transactions, every tab) finds visitors by name, plate number (ignoring spaces, hyphens and case), phone number (by digits), NRIC, company, purpose, delivery/contractor type, block, level, unit ("151/1/02"), pass/key held, and group members. The typed text is matched literally, so characters like "(" no longer cause a server error. Search stays inside the site(s) the caller may see and combines with the existing date, status and type filters.
|
package/dist/index.js
CHANGED
|
@@ -15369,6 +15369,50 @@ function isPreCheckInStatusOnly(status) {
|
|
|
15369
15369
|
return requested.length > 0 && requested.every((s) => PRE_CHECK_IN_STATUSES.includes(s));
|
|
15370
15370
|
}
|
|
15371
15371
|
|
|
15372
|
+
// src/utils/visitor-search.util.ts
|
|
15373
|
+
var VISITOR_SEARCH_MAX_LENGTH = 100;
|
|
15374
|
+
var MIN_PHONE_DIGITS = 3;
|
|
15375
|
+
var MIN_PLATE_CHARS = 2;
|
|
15376
|
+
function escapeRegex3(value) {
|
|
15377
|
+
return String(value ?? "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
15378
|
+
}
|
|
15379
|
+
function normaliseVisitorSearch(raw) {
|
|
15380
|
+
if (typeof raw !== "string")
|
|
15381
|
+
return "";
|
|
15382
|
+
return raw.replace(/\s+/g, " ").trim().slice(0, VISITOR_SEARCH_MAX_LENGTH);
|
|
15383
|
+
}
|
|
15384
|
+
function looseSequence(chars, gap) {
|
|
15385
|
+
return chars.map(escapeRegex3).join(gap);
|
|
15386
|
+
}
|
|
15387
|
+
function visitorRowSearchOr(raw) {
|
|
15388
|
+
const q = normaliseVisitorSearch(raw);
|
|
15389
|
+
if (!q)
|
|
15390
|
+
return [];
|
|
15391
|
+
const contains = { $regex: escapeRegex3(q), $options: "i" };
|
|
15392
|
+
const or = [
|
|
15393
|
+
{ name: contains },
|
|
15394
|
+
{ company: contains },
|
|
15395
|
+
{ purpose: contains },
|
|
15396
|
+
{ nric: contains },
|
|
15397
|
+
{ contractorType: contains },
|
|
15398
|
+
{ deliveryType: contains },
|
|
15399
|
+
{ unitName: contains },
|
|
15400
|
+
{ "members.name": contains },
|
|
15401
|
+
{ "members.nric": contains }
|
|
15402
|
+
];
|
|
15403
|
+
const plateChars = q.replace(/[^A-Za-z0-9]/g, "").split("");
|
|
15404
|
+
if (plateChars.length >= MIN_PLATE_CHARS) {
|
|
15405
|
+
const plate = { $regex: looseSequence(plateChars, "[\\s-]*"), $options: "i" };
|
|
15406
|
+
or.push({ plateNumber: plate }, { "members.plateNumber": plate });
|
|
15407
|
+
}
|
|
15408
|
+
const digits = q.replace(/\D/g, "").split("");
|
|
15409
|
+
if (/^[+\d\s()-]+$/.test(q) && digits.length >= MIN_PHONE_DIGITS) {
|
|
15410
|
+
const phone = { $regex: looseSequence(digits, "\\D*") };
|
|
15411
|
+
or.push({ contact: phone }, { "members.contact": phone });
|
|
15412
|
+
}
|
|
15413
|
+
return or;
|
|
15414
|
+
}
|
|
15415
|
+
|
|
15372
15416
|
// src/repositories/visitor-transaction.repo.ts
|
|
15373
15417
|
var visitors_namespace_collection = "visitor.transactions";
|
|
15374
15418
|
function useVisitorTransactionRepo() {
|
|
@@ -15378,10 +15422,10 @@ function useVisitorTransactionRepo() {
|
|
|
15378
15422
|
}
|
|
15379
15423
|
const collection = db2.collection(visitors_namespace_collection);
|
|
15380
15424
|
function buildSearchStages(search) {
|
|
15381
|
-
const text2 = (search
|
|
15425
|
+
const text2 = normaliseVisitorSearch(search);
|
|
15382
15426
|
if (!text2)
|
|
15383
15427
|
return [];
|
|
15384
|
-
const escape =
|
|
15428
|
+
const escape = escapeRegex3;
|
|
15385
15429
|
const like = (value) => ({ $regex: escape(value), $options: "i" });
|
|
15386
15430
|
const exact = (value) => ({
|
|
15387
15431
|
$regex: `^${escape(value)}$`,
|
|
@@ -15470,10 +15514,9 @@ function useVisitorTransactionRepo() {
|
|
|
15470
15514
|
{
|
|
15471
15515
|
$match: {
|
|
15472
15516
|
$or: [
|
|
15473
|
-
|
|
15474
|
-
|
|
15475
|
-
|
|
15476
|
-
{ company: like(text2) },
|
|
15517
|
+
// name, company, purpose, NRIC, types, members; plates ignoring
|
|
15518
|
+
// spaces/hyphens/case; phones by digits - visitor-search.util.
|
|
15519
|
+
...visitorRowSearchOr(text2),
|
|
15477
15520
|
{ "_searchBlock.name": like(text2) },
|
|
15478
15521
|
{ "_searchLevel.name": like(text2) },
|
|
15479
15522
|
unitMatch(text2),
|
|
@@ -16931,7 +16974,7 @@ function useVehicleRepo() {
|
|
|
16931
16974
|
let query2 = { ...baseQuery };
|
|
16932
16975
|
if (search)
|
|
16933
16976
|
query2.$text = { $search: search };
|
|
16934
|
-
const
|
|
16977
|
+
const escapeRegex5 = (input) => input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
16935
16978
|
const buildGroupedPipeline = (matchQuery) => [
|
|
16936
16979
|
{ $match: matchQuery },
|
|
16937
16980
|
{
|
|
@@ -17115,7 +17158,7 @@ function useVehicleRepo() {
|
|
|
17115
17158
|
const countResult = await collection.aggregate(buildGroupedCountPipeline(query2)).toArray();
|
|
17116
17159
|
length = countResult[0]?.total || 0;
|
|
17117
17160
|
if ((!items || items.length === 0) && search) {
|
|
17118
|
-
const escaped =
|
|
17161
|
+
const escaped = escapeRegex5(search);
|
|
17119
17162
|
const regexQuery = {
|
|
17120
17163
|
...baseQuery,
|
|
17121
17164
|
$or: [
|
|
@@ -17904,7 +17947,7 @@ function useVehicleRepo() {
|
|
|
17904
17947
|
...baseQuery,
|
|
17905
17948
|
...search && { $text: { $search: search } }
|
|
17906
17949
|
};
|
|
17907
|
-
const
|
|
17950
|
+
const escapeRegex5 = (input) => input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
17908
17951
|
const buildPipeline = (matchQuery) => [
|
|
17909
17952
|
{ $match: matchQuery },
|
|
17910
17953
|
{
|
|
@@ -17932,7 +17975,7 @@ function useVehicleRepo() {
|
|
|
17932
17975
|
const countResult = await collection.aggregate(buildCountPipeline(query2)).toArray();
|
|
17933
17976
|
length = countResult[0]?.total || 0;
|
|
17934
17977
|
if ((!items || items.length === 0) && search) {
|
|
17935
|
-
const escaped =
|
|
17978
|
+
const escaped = escapeRegex5(search);
|
|
17936
17979
|
const regexQuery = {
|
|
17937
17980
|
...baseQuery,
|
|
17938
17981
|
$or: [
|
|
@@ -47558,7 +47601,7 @@ function usePersonService() {
|
|
|
47558
47601
|
let set = {};
|
|
47559
47602
|
const cleanInput = (str2) => str2.replace(/\s+/g, "");
|
|
47560
47603
|
const cleanPhone = (str2) => str2.replace(/\D/g, "");
|
|
47561
|
-
const
|
|
47604
|
+
const escapeRegex5 = (str2) => str2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
47562
47605
|
const nric = value.nric ? cleanInput(value.nric) : "";
|
|
47563
47606
|
const name = value.name?.trim();
|
|
47564
47607
|
const contact = value.contact?.trim();
|
|
@@ -47566,8 +47609,8 @@ function usePersonService() {
|
|
|
47566
47609
|
const email = value.email?.trim();
|
|
47567
47610
|
const type = value.type?.trim();
|
|
47568
47611
|
const company = value.company?.trim();
|
|
47569
|
-
const nricQuery = nric ? { nric: { $regex: `^${
|
|
47570
|
-
const nameQuery = name ? { name: { $regex: `^${
|
|
47612
|
+
const nricQuery = nric ? { nric: { $regex: `^${escapeRegex5(nric)}$`, $options: "i" } } : null;
|
|
47613
|
+
const nameQuery = name ? { name: { $regex: `^${escapeRegex5(name)}$`, $options: "i" } } : null;
|
|
47571
47614
|
let nricCondition = null;
|
|
47572
47615
|
if (nric) {
|
|
47573
47616
|
if (nric.length < 9) {
|
|
@@ -47580,8 +47623,8 @@ function usePersonService() {
|
|
|
47580
47623
|
}
|
|
47581
47624
|
const orConditions = [
|
|
47582
47625
|
...nricCondition ? [nricCondition] : [],
|
|
47583
|
-
...contact ? [{ contacts: { $regex: `^\\+?${cleanPhone(
|
|
47584
|
-
...plateNumber ? [{ plateNumbers: { $regex: `^${
|
|
47626
|
+
...contact ? [{ contacts: { $regex: `^\\+?${cleanPhone(escapeRegex5(contact))}$`, $options: "i" } }] : [],
|
|
47627
|
+
...plateNumber ? [{ plateNumbers: { $regex: `^${escapeRegex5(plateNumber)}$`, $options: "i" } }] : []
|
|
47585
47628
|
];
|
|
47586
47629
|
const existingPerson2 = await findFirstTen(
|
|
47587
47630
|
{
|
|
@@ -49576,7 +49619,7 @@ function useHidAmicoRepo() {
|
|
|
49576
49619
|
passwordSet: Boolean(password)
|
|
49577
49620
|
};
|
|
49578
49621
|
}
|
|
49579
|
-
function
|
|
49622
|
+
function escapeRegex5(value) {
|
|
49580
49623
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
49581
49624
|
}
|
|
49582
49625
|
function buildIdentityKeyQuery(value) {
|
|
@@ -49805,7 +49848,7 @@ function useHidAmicoRepo() {
|
|
|
49805
49848
|
{ serviceProvider: { $in: subjectIds } },
|
|
49806
49849
|
{ user: { $in: subjectIds } }
|
|
49807
49850
|
] : null;
|
|
49808
|
-
const search = value.search ?
|
|
49851
|
+
const search = value.search ? escapeRegex5(value.search) : "";
|
|
49809
49852
|
const searchOr = search ? [
|
|
49810
49853
|
{ hidUserId: { $regex: search, $options: "i" } },
|
|
49811
49854
|
{ registration: { $regex: search, $options: "i" } },
|
|
@@ -50217,7 +50260,7 @@ function useHidAmicoRepo() {
|
|
|
50217
50260
|
const text2 = search.trim();
|
|
50218
50261
|
if (!text2)
|
|
50219
50262
|
return {};
|
|
50220
|
-
const pattern = { $regex:
|
|
50263
|
+
const pattern = { $regex: escapeRegex5(text2), $options: "i" };
|
|
50221
50264
|
return {
|
|
50222
50265
|
$or: [
|
|
50223
50266
|
{ name: pattern },
|
|
@@ -63487,7 +63530,7 @@ var NETWORK_SORTS = {
|
|
|
63487
63530
|
};
|
|
63488
63531
|
var NETWORK_OFFLINE_CODE = "OFFLINE";
|
|
63489
63532
|
var ROBOT_FAULTS_COLLECTION = "robot-faults";
|
|
63490
|
-
function
|
|
63533
|
+
function escapeRegex4(value) {
|
|
63491
63534
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
63492
63535
|
}
|
|
63493
63536
|
function matchDefaulted(field, value, fallback) {
|
|
@@ -63591,7 +63634,7 @@ function networkListPipeline(q) {
|
|
|
63591
63634
|
pipeline.push({ $match: { offline: true } });
|
|
63592
63635
|
const search = (q.search ?? "").trim();
|
|
63593
63636
|
if (search) {
|
|
63594
|
-
const rx = { $regex:
|
|
63637
|
+
const rx = { $regex: escapeRegex4(search), $options: "i" };
|
|
63595
63638
|
pipeline.push({
|
|
63596
63639
|
$match: { $or: [{ name: rx }, { robotSn: rx }, { "client.name": rx }, { "site.name": rx }] }
|
|
63597
63640
|
});
|
|
@@ -75382,7 +75425,7 @@ function usePatrolEmailRepo() {
|
|
|
75382
75425
|
throw new import_node_server_utils186.BadRequestError(`Invalid ${label2} format.`);
|
|
75383
75426
|
}
|
|
75384
75427
|
}
|
|
75385
|
-
function
|
|
75428
|
+
function escapeRegex5(value) {
|
|
75386
75429
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
75387
75430
|
}
|
|
75388
75431
|
async function createIndexes() {
|
|
@@ -75519,8 +75562,8 @@ function usePatrolEmailRepo() {
|
|
|
75519
75562
|
...status ? { status } : { status: { $ne: "deleted" } },
|
|
75520
75563
|
...search && {
|
|
75521
75564
|
$or: [
|
|
75522
|
-
{ subject: { $regex:
|
|
75523
|
-
{ recipients: { $regex:
|
|
75565
|
+
{ subject: { $regex: escapeRegex5(search), $options: "i" } },
|
|
75566
|
+
{ recipients: { $regex: escapeRegex5(search), $options: "i" } }
|
|
75524
75567
|
]
|
|
75525
75568
|
}
|
|
75526
75569
|
};
|