@7365admin1/core 3.47.1-staging.141 → 3.47.1-staging.142

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,26 @@
1
+ ---
2
+ "@7365admin1/core": patch
3
+ ---
4
+
5
+ Make the people search filters narrow each other instead of overwriting each
6
+ other.
7
+
8
+ `person.repo.getAll` built its Mongo filter as one object literal in which four
9
+ different filters each wrote a `$or` key — the date range (`dateTo`), the
10
+ free-text `search`, `contact` and `plateNumber`. An object literal can only
11
+ carry one `$or`, so the last one written silently replaced every earlier one.
12
+ In practice:
13
+
14
+ - searching by name **and** contact number searched only the contact number,
15
+ - searching by name **and** plate number searched only the plate number,
16
+ - and a **date range was dropped entirely** the moment any of the three was
17
+ used — which is the live case, because `layer-common`
18
+ `composables/usePeople.ts:2-30` sends `search`, `dateFrom` and `dateTo`
19
+ together from the visitor/people list.
20
+
21
+ No error was raised; the endpoint simply answered a narrower question than it
22
+ was asked, with rows that should not have matched.
23
+
24
+ The four groups are now collected and combined with `$and`, so each one narrows
25
+ the result. A single filter behaves exactly as before, and a request with no
26
+ filters is unchanged.
package/dist/index.js CHANGED
@@ -17370,46 +17370,47 @@ function usePersonRepo() {
17370
17370
  }, session) {
17371
17371
  page = page > 0 ? page - 1 : 0;
17372
17372
  const start = dateFrom ? { $gte: new Date(dateFrom).toISOString() } : void 0;
17373
- const end = dateTo ? {
17374
- $or: [
17373
+ const anyOf = [];
17374
+ if (dateTo) {
17375
+ anyOf.push([
17375
17376
  { end: { $lte: new Date(dateTo).toISOString() } },
17376
17377
  { end: null }
17377
- ]
17378
- } : void 0;
17378
+ ]);
17379
+ }
17380
+ if (search) {
17381
+ anyOf.push([
17382
+ { name: { $regex: search, $options: "i" } },
17383
+ { email: { $regex: search, $options: "i" } },
17384
+ { nric: { $regex: search, $options: "i" } },
17385
+ { "plates.plateNumber": { $regex: search, $options: "i" } },
17386
+ { contact: { $regex: makeContainsRegex(search) } },
17387
+ { contacts: { $regex: makeContainsRegex(search) } },
17388
+ { plateNumbers: { $regex: makeContainsRegex(search) } }
17389
+ ]);
17390
+ }
17391
+ if (contact) {
17392
+ anyOf.push([
17393
+ { contact: { $regex: makeContainsRegex(contact) } },
17394
+ { contacts: { $regex: makeContainsRegex(contact) } }
17395
+ ]);
17396
+ }
17397
+ if (plateNumber) {
17398
+ anyOf.push([
17399
+ { "plates.plateNumber": { $regex: makeContainsRegex(plateNumber) } },
17400
+ { plateNumbers: { $regex: makeContainsRegex(plateNumber) } }
17401
+ ]);
17402
+ }
17379
17403
  const query2 = {
17380
17404
  ...status && status !== "all" ? { status } : { status: { $nin: ["deleted", "rejected"] } },
17381
17405
  ...start && { start },
17382
- ...end,
17383
- ...search && {
17384
- $or: [
17385
- { name: { $regex: search, $options: "i" } },
17386
- { email: { $regex: search, $options: "i" } },
17387
- { nric: { $regex: search, $options: "i" } },
17388
- { "plates.plateNumber": { $regex: search, $options: "i" } },
17389
- { contact: { $regex: makeContainsRegex(search) } },
17390
- { contacts: { $regex: makeContainsRegex(search) } },
17391
- { plateNumbers: { $regex: makeContainsRegex(search) } }
17392
- ]
17393
- },
17406
+ ...anyOf.length > 0 && { $and: anyOf.map(($or) => ({ $or })) },
17394
17407
  ...import_mongodb36.ObjectId.isValid(org) && { org: new import_mongodb36.ObjectId(org) },
17395
17408
  ...!import_mongodb36.ObjectId.isValid(org) && orgs && {
17396
17409
  org: { $in: orgs.filter(import_mongodb36.ObjectId.isValid).map((o) => new import_mongodb36.ObjectId(o)) }
17397
17410
  },
17398
17411
  ...import_mongodb36.ObjectId.isValid(site) && { site: new import_mongodb36.ObjectId(site) },
17399
17412
  ...PERSON_TYPES.includes(type) && { type },
17400
- ...nric && { nric: { $regex: makeContainsRegex(nric), $options: "i" } },
17401
- ...contact && {
17402
- $or: [
17403
- { contact: { $regex: makeContainsRegex(contact) } },
17404
- { contacts: { $regex: makeContainsRegex(contact) } }
17405
- ]
17406
- },
17407
- ...plateNumber && {
17408
- $or: [
17409
- { "plates.plateNumber": { $regex: makeContainsRegex(plateNumber) } },
17410
- { plateNumbers: { $regex: makeContainsRegex(plateNumber) } }
17411
- ]
17412
- }
17413
+ ...nric && { nric: { $regex: makeContainsRegex(nric), $options: "i" } }
17413
17414
  };
17414
17415
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
17415
17416
  try {