@7365admin1/core 3.34.4-staging.18 → 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 +6 -3
- package/dist/index.js +87 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2625,7 +2625,7 @@ type TGetAttendancesQuery = {
|
|
|
2625
2625
|
startDate?: string | Date;
|
|
2626
2626
|
endDate?: string | Date;
|
|
2627
2627
|
} & Pick<TAttendance, "site" | "serviceType">;
|
|
2628
|
-
type TGetAttendancesByUserQuery = Pick<TGetAttendancesQuery, "page" | "limit" | "search" | "site" | "serviceType"> & Pick<TAttendance, "user">;
|
|
2628
|
+
type TGetAttendancesByUserQuery = Pick<TGetAttendancesQuery, "page" | "limit" | "search" | "site" | "serviceType" | "startDate" | "endDate"> & Pick<TAttendance, "user">;
|
|
2629
2629
|
declare const attendanceSchema: Joi.ObjectSchema<any>;
|
|
2630
2630
|
declare function MAttendance(value: TAttendance): {
|
|
2631
2631
|
site: string | ObjectId;
|
|
@@ -2685,7 +2685,7 @@ declare function useAttendanceRepository(): {
|
|
|
2685
2685
|
createIndex: () => Promise<void>;
|
|
2686
2686
|
checkInAttendance: (value: TAttendanceCheckIn, session?: ClientSession) => Promise<ObjectId>;
|
|
2687
2687
|
getAllAttendances: ({ page, limit, search, site, startDate, endDate, serviceType, }: TGetAttendancesQuery) => Promise<{}>;
|
|
2688
|
-
getAttendanceByUser: ({ page, limit, search, site, serviceType, user, }: TGetAttendancesByUserQuery) => Promise<{}>;
|
|
2688
|
+
getAttendanceByUser: ({ page, limit, search, site, startDate, endDate, serviceType, user, }: TGetAttendancesByUserQuery) => Promise<{}>;
|
|
2689
2689
|
getAttendanceById: (_id: string | ObjectId, session?: ClientSession) => Promise<{}>;
|
|
2690
2690
|
getRawAttendanceById: (_id: string | ObjectId, session?: ClientSession) => Promise<TAttendance>;
|
|
2691
2691
|
checkOutAttendance: (_id: string | ObjectId, value: TAttendanceCheckOut, session?: ClientSession) => Promise<number>;
|
|
@@ -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 {
|
|
@@ -33211,6 +33240,8 @@ function useAttendanceRepository() {
|
|
|
33211
33240
|
limit = 10,
|
|
33212
33241
|
search = "",
|
|
33213
33242
|
site,
|
|
33243
|
+
startDate = "",
|
|
33244
|
+
endDate = "",
|
|
33214
33245
|
serviceType,
|
|
33215
33246
|
user
|
|
33216
33247
|
}) {
|
|
@@ -33238,6 +33269,37 @@ function useAttendanceRepository() {
|
|
|
33238
33269
|
if (search) {
|
|
33239
33270
|
cacheOptions.search = search;
|
|
33240
33271
|
}
|
|
33272
|
+
const singaporeTz = "Asia/Singapore";
|
|
33273
|
+
const normalizedStartDate = typeof startDate === "string" ? startDate : (0, import_moment.default)(startDate).tz(singaporeTz).format("YYYY-MM-DD");
|
|
33274
|
+
const normalizedEndDate = typeof endDate === "string" ? endDate : (0, import_moment.default)(endDate).tz(singaporeTz).format("YYYY-MM-DD");
|
|
33275
|
+
if (startDate && endDate) {
|
|
33276
|
+
const startOfDay = import_moment.default.tz(normalizedStartDate, "YYYY-MM-DD", singaporeTz).startOf("day").toDate();
|
|
33277
|
+
const endOfDay = import_moment.default.tz(normalizedEndDate, "YYYY-MM-DD", singaporeTz).endOf("day").toDate();
|
|
33278
|
+
query.$expr = {
|
|
33279
|
+
$and: [
|
|
33280
|
+
{ $gte: [{ $toDate: "$checkIn.timestamp" }, startOfDay] },
|
|
33281
|
+
{ $lte: [{ $toDate: "$checkIn.timestamp" }, endOfDay] }
|
|
33282
|
+
]
|
|
33283
|
+
};
|
|
33284
|
+
cacheOptions.startDate = normalizedStartDate;
|
|
33285
|
+
cacheOptions.endDate = normalizedEndDate;
|
|
33286
|
+
} else if (startDate) {
|
|
33287
|
+
query.$expr = {
|
|
33288
|
+
$gte: [
|
|
33289
|
+
{ $toDate: "$checkIn.timestamp" },
|
|
33290
|
+
import_moment.default.tz(normalizedStartDate, "YYYY-MM-DD", singaporeTz).startOf("day").toDate()
|
|
33291
|
+
]
|
|
33292
|
+
};
|
|
33293
|
+
cacheOptions.startDate = normalizedStartDate;
|
|
33294
|
+
} else if (endDate) {
|
|
33295
|
+
query.$expr = {
|
|
33296
|
+
$lte: [
|
|
33297
|
+
{ $toDate: "$checkIn.timestamp" },
|
|
33298
|
+
import_moment.default.tz(normalizedEndDate, "YYYY-MM-DD", singaporeTz).endOf("day").toDate()
|
|
33299
|
+
]
|
|
33300
|
+
};
|
|
33301
|
+
cacheOptions.endDate = normalizedEndDate;
|
|
33302
|
+
}
|
|
33241
33303
|
const cacheKey = (0, import_node_server_utils103.makeCacheKey)(namespace_collection, cacheOptions);
|
|
33242
33304
|
const cachedData = await getCache(cacheKey);
|
|
33243
33305
|
if (cachedData) {
|
|
@@ -33683,6 +33745,8 @@ function useAttendanceController() {
|
|
|
33683
33745
|
search: import_joi56.default.string().optional().allow("", null),
|
|
33684
33746
|
site: import_joi56.default.string().hex().required(),
|
|
33685
33747
|
serviceType: import_joi56.default.string().valid(...Object.values(AppServiceType)).required(),
|
|
33748
|
+
dateFrom: import_joi56.default.alternatives().try(import_joi56.default.date(), import_joi56.default.string()).optional().allow("", null),
|
|
33749
|
+
dateTo: import_joi56.default.alternatives().try(import_joi56.default.date(), import_joi56.default.string()).optional().allow("", null),
|
|
33686
33750
|
user: import_joi56.default.string().hex().required()
|
|
33687
33751
|
});
|
|
33688
33752
|
const { error } = validation.validate(query);
|
|
@@ -33696,6 +33760,8 @@ function useAttendanceController() {
|
|
|
33696
33760
|
const search = req.query.search ?? "";
|
|
33697
33761
|
const site = req.params.site ?? "";
|
|
33698
33762
|
const serviceType = req.query.serviceType ?? "";
|
|
33763
|
+
const startDate = req.query.dateFrom ?? "";
|
|
33764
|
+
const endDate = req.query.dateTo ?? "";
|
|
33699
33765
|
try {
|
|
33700
33766
|
const data = await _getAttendanceByUser({
|
|
33701
33767
|
page,
|
|
@@ -33703,7 +33769,9 @@ function useAttendanceController() {
|
|
|
33703
33769
|
search,
|
|
33704
33770
|
site,
|
|
33705
33771
|
serviceType,
|
|
33706
|
-
user
|
|
33772
|
+
user,
|
|
33773
|
+
startDate,
|
|
33774
|
+
endDate
|
|
33707
33775
|
});
|
|
33708
33776
|
res.json(data);
|
|
33709
33777
|
return;
|
|
@@ -37026,17 +37094,21 @@ function usePersonController() {
|
|
|
37026
37094
|
const validation = import_joi60.default.object({
|
|
37027
37095
|
page: import_joi60.default.number().integer().min(1).allow("", null).default(1),
|
|
37028
37096
|
limit: import_joi60.default.number().integer().min(1).max(100).allow("", null).default(10),
|
|
37029
|
-
sort: import_joi60.default.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("",
|
|
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),
|
|
37030
37099
|
status: import_joi60.default.string().optional().allow(null, ""),
|
|
37031
37100
|
search: import_joi60.default.string().optional().allow(null, ""),
|
|
37032
37101
|
dateFrom: import_joi60.default.date().iso().optional().allow(null, ""),
|
|
37033
37102
|
dateTo: import_joi60.default.date().iso().optional().allow(null, ""),
|
|
37034
|
-
org: import_joi60.default.string().optional().allow(null, ""),
|
|
37035
|
-
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, ""),
|
|
37036
37105
|
type: import_joi60.default.alternatives().try(
|
|
37037
37106
|
import_joi60.default.string().valid(...PERSON_TYPES),
|
|
37038
37107
|
import_joi60.default.array().items(import_joi60.default.string().valid(...PERSON_TYPES))
|
|
37039
|
-
).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, "")
|
|
37040
37112
|
});
|
|
37041
37113
|
const query = { ...req.query };
|
|
37042
37114
|
const { error } = validation.validate(query, {
|
|
@@ -37057,6 +37129,9 @@ function usePersonController() {
|
|
|
37057
37129
|
const org = req.query.org;
|
|
37058
37130
|
const site = req.query.site;
|
|
37059
37131
|
const type = req.query.type;
|
|
37132
|
+
const nric = req.query.nric;
|
|
37133
|
+
const contact = req.query.contact;
|
|
37134
|
+
const plateNumber = req.query.plateNumber;
|
|
37060
37135
|
const sortObj = {};
|
|
37061
37136
|
const sortFields = String(req.query.sort).split(",");
|
|
37062
37137
|
const sortOrders = String(req.query.order).split(",");
|
|
@@ -37077,7 +37152,10 @@ function usePersonController() {
|
|
|
37077
37152
|
dateTo,
|
|
37078
37153
|
org,
|
|
37079
37154
|
site,
|
|
37080
|
-
type
|
|
37155
|
+
type,
|
|
37156
|
+
nric,
|
|
37157
|
+
contact,
|
|
37158
|
+
plateNumber
|
|
37081
37159
|
});
|
|
37082
37160
|
res.status(200).json(data);
|
|
37083
37161
|
return;
|