@7365admin1/core 3.34.4-staging.19 → 3.34.4-staging.20

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/dist/index.d.ts CHANGED
@@ -3108,7 +3108,7 @@ declare function useGuestManagementController(): {
3108
3108
  declare const site_people_namespace_collection = "site.people";
3109
3109
  declare function usePersonRepo(): {
3110
3110
  add: (value: TPerson, session?: ClientSession) => Promise<ObjectId>;
3111
- getAll: ({ search, page, limit, sort, status, dateFrom, dateTo, org, site, type, }: {
3111
+ getAll: ({ search, page, limit, sort, status, dateFrom, dateTo, org, site, type, nric, contact, plateNumber, }: {
3112
3112
  search?: string | undefined;
3113
3113
  page?: number | undefined;
3114
3114
  limit?: number | undefined;
@@ -3119,6 +3119,9 @@ declare function usePersonRepo(): {
3119
3119
  org?: string | undefined;
3120
3120
  site?: string | undefined;
3121
3121
  type?: string | undefined;
3122
+ nric?: string | undefined;
3123
+ contact?: string | undefined;
3124
+ plateNumber: string;
3122
3125
  }, session?: ClientSession) => Promise<{
3123
3126
  items: any[];
3124
3127
  pages: number;
package/dist/index.js CHANGED
@@ -25185,6 +25185,16 @@ var import_node_server_utils78 = require("@7365admin1/node-server-utils");
25185
25185
  // src/repositories/person.repo.ts
25186
25186
  var import_node_server_utils74 = require("@7365admin1/node-server-utils");
25187
25187
  var import_mongodb45 = require("mongodb");
25188
+
25189
+ // src/utils/sanitizer.ts
25190
+ var makeContainsRegex = (input) => {
25191
+ if (!input)
25192
+ return "";
25193
+ const sanitized = input.replace(/\s+/g, "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
25194
+ return sanitized;
25195
+ };
25196
+
25197
+ // src/repositories/person.repo.ts
25188
25198
  var site_people_namespace_collection = "site.people";
25189
25199
  function usePersonRepo() {
25190
25200
  const db = import_node_server_utils74.useAtlas.getDb();
@@ -25257,7 +25267,10 @@ function usePersonRepo() {
25257
25267
  dateTo,
25258
25268
  org = "",
25259
25269
  site = "",
25260
- type = ""
25270
+ type = "",
25271
+ nric = "",
25272
+ contact = "",
25273
+ plateNumber = ""
25261
25274
  }, session) {
25262
25275
  page = page > 0 ? page - 1 : 0;
25263
25276
  const start = dateFrom ? { $gte: new Date(dateFrom).toISOString() } : void 0;
@@ -25276,12 +25289,28 @@ function usePersonRepo() {
25276
25289
  { name: { $regex: search, $options: "i" } },
25277
25290
  { email: { $regex: search, $options: "i" } },
25278
25291
  { nric: { $regex: search, $options: "i" } },
25279
- { "plates.plateNumber": { $regex: search, $options: "i" } }
25292
+ { "plates.plateNumber": { $regex: search, $options: "i" } },
25293
+ { contact: { $regex: makeContainsRegex(contact) } },
25294
+ { contacts: { $regex: makeContainsRegex(contact) } },
25295
+ { plateNumbers: { $regex: makeContainsRegex(plateNumber) } }
25280
25296
  ]
25281
25297
  },
25282
25298
  ...import_mongodb45.ObjectId.isValid(org) && { org: new import_mongodb45.ObjectId(org) },
25283
25299
  ...import_mongodb45.ObjectId.isValid(site) && { site: new import_mongodb45.ObjectId(site) },
25284
- ...PERSON_TYPES.includes(type) && { type }
25300
+ ...PERSON_TYPES.includes(type) && { type },
25301
+ ...nric && { nric: { $regex: makeContainsRegex(nric), $options: "i" } },
25302
+ ...contact && {
25303
+ $or: [
25304
+ { contact: { $regex: makeContainsRegex(contact) } },
25305
+ { contacts: { $regex: makeContainsRegex(contact) } }
25306
+ ]
25307
+ },
25308
+ ...plateNumber && {
25309
+ $or: [
25310
+ { "plates.plateNumber": { $regex: makeContainsRegex(plateNumber) } },
25311
+ { plateNumbers: { $regex: makeContainsRegex(plateNumber) } }
25312
+ ]
25313
+ }
25285
25314
  };
25286
25315
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
25287
25316
  try {
@@ -37065,17 +37094,21 @@ function usePersonController() {
37065
37094
  const validation = import_joi60.default.object({
37066
37095
  page: import_joi60.default.number().integer().min(1).allow("", null).default(1),
37067
37096
  limit: import_joi60.default.number().integer().min(1).max(100).allow("", null).default(10),
37068
- sort: import_joi60.default.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("", ...allowedFields),
37097
+ sort: import_joi60.default.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("", null),
37098
+ order: import_joi60.default.string().pattern(/^(asc|desc)(,(asc|desc))*$/i).optional().allow("", null),
37069
37099
  status: import_joi60.default.string().optional().allow(null, ""),
37070
37100
  search: import_joi60.default.string().optional().allow(null, ""),
37071
37101
  dateFrom: import_joi60.default.date().iso().optional().allow(null, ""),
37072
37102
  dateTo: import_joi60.default.date().iso().optional().allow(null, ""),
37073
- org: import_joi60.default.string().optional().allow(null, ""),
37074
- site: import_joi60.default.string().optional().allow(null, ""),
37103
+ org: import_joi60.default.string().hex().length(24).optional().allow(null, ""),
37104
+ site: import_joi60.default.string().hex().length(24).optional().allow(null, ""),
37075
37105
  type: import_joi60.default.alternatives().try(
37076
37106
  import_joi60.default.string().valid(...PERSON_TYPES),
37077
37107
  import_joi60.default.array().items(import_joi60.default.string().valid(...PERSON_TYPES))
37078
- ).optional().allow(null, "")
37108
+ ).optional().allow(null, ""),
37109
+ nric: import_joi60.default.string().optional().allow(null, ""),
37110
+ contact: import_joi60.default.string().optional().allow(null, ""),
37111
+ plateNumber: import_joi60.default.string().optional().allow(null, "")
37079
37112
  });
37080
37113
  const query = { ...req.query };
37081
37114
  const { error } = validation.validate(query, {
@@ -37096,6 +37129,9 @@ function usePersonController() {
37096
37129
  const org = req.query.org;
37097
37130
  const site = req.query.site;
37098
37131
  const type = req.query.type;
37132
+ const nric = req.query.nric;
37133
+ const contact = req.query.contact;
37134
+ const plateNumber = req.query.plateNumber;
37099
37135
  const sortObj = {};
37100
37136
  const sortFields = String(req.query.sort).split(",");
37101
37137
  const sortOrders = String(req.query.order).split(",");
@@ -37116,7 +37152,10 @@ function usePersonController() {
37116
37152
  dateTo,
37117
37153
  org,
37118
37154
  site,
37119
- type
37155
+ type,
37156
+ nric,
37157
+ contact,
37158
+ plateNumber
37120
37159
  });
37121
37160
  res.status(200).json(data);
37122
37161
  return;