@7365admin1/core 3.34.4-staging.14 → 3.34.4-staging.16
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 +8 -1
- package/dist/index.js +67 -128
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -128
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -6181,7 +6181,14 @@ declare function useNewDashboardRepo(): {
|
|
|
6181
6181
|
missed: any;
|
|
6182
6182
|
percentage: number;
|
|
6183
6183
|
};
|
|
6184
|
-
activePatrolItems:
|
|
6184
|
+
activePatrolItems: {
|
|
6185
|
+
id: string;
|
|
6186
|
+
title: any;
|
|
6187
|
+
subtitle: string;
|
|
6188
|
+
person: any;
|
|
6189
|
+
status: any;
|
|
6190
|
+
time: string;
|
|
6191
|
+
}[];
|
|
6185
6192
|
}>;
|
|
6186
6193
|
getPropertyManagementDashboard: (siteId: string, period?: Period, type?: string, facility?: string) => Promise<{
|
|
6187
6194
|
openWorkOrder: {
|
package/dist/index.js
CHANGED
|
@@ -33135,7 +33135,7 @@ function useAttendanceRepository() {
|
|
|
33135
33135
|
localField: "user",
|
|
33136
33136
|
foreignField: "_id",
|
|
33137
33137
|
as: "user",
|
|
33138
|
-
pipeline: [{ $project: { name: 1 } }]
|
|
33138
|
+
pipeline: [{ $project: { name: 1, profile: 1 } }]
|
|
33139
33139
|
}
|
|
33140
33140
|
},
|
|
33141
33141
|
{ $unwind: { path: "$user", preserveNullAndEmptyArrays: true } }
|
|
@@ -33149,6 +33149,7 @@ function useAttendanceRepository() {
|
|
|
33149
33149
|
{
|
|
33150
33150
|
$project: {
|
|
33151
33151
|
userName: "$user.name",
|
|
33152
|
+
userProfile: "$user.profile",
|
|
33152
33153
|
checkInTimestamp: "$checkIn.timestamp",
|
|
33153
33154
|
checkOutTimestamp: "$checkOut.timestamp",
|
|
33154
33155
|
createdAt: 1
|
|
@@ -58989,6 +58990,17 @@ function useNewDashboardRepo() {
|
|
|
58989
58990
|
$lte: now.clone().endOf("day").toDate()
|
|
58990
58991
|
};
|
|
58991
58992
|
}
|
|
58993
|
+
function getActivePatrolDateRange(period) {
|
|
58994
|
+
switch (period) {
|
|
58995
|
+
case "thisWeek" /* THIS_WEEK */:
|
|
58996
|
+
return getDateRange("thisWeek" /* THIS_WEEK */);
|
|
58997
|
+
case "thisMonth" /* THIS_MONTH */:
|
|
58998
|
+
return getDateRange("thisMonth" /* THIS_MONTH */);
|
|
58999
|
+
case "today" /* TODAY */:
|
|
59000
|
+
default:
|
|
59001
|
+
return getDateRange("today" /* TODAY */);
|
|
59002
|
+
}
|
|
59003
|
+
}
|
|
58992
59004
|
function getSiteDayRange(date = import_moment2.default.tz("Asia/Singapore")) {
|
|
58993
59005
|
return {
|
|
58994
59006
|
$gte: date.clone().startOf("day").toDate(),
|
|
@@ -59001,6 +59013,33 @@ function useNewDashboardRepo() {
|
|
|
59001
59013
|
}
|
|
59002
59014
|
return Math.round((currentCount - previousCount) / previousCount * 100 * 100) / 100;
|
|
59003
59015
|
};
|
|
59016
|
+
async function getPatrolLogPerson(log) {
|
|
59017
|
+
if (!log) {
|
|
59018
|
+
return "Unassigned";
|
|
59019
|
+
}
|
|
59020
|
+
if (log.assignee && log.assignee.length > 0) {
|
|
59021
|
+
const userIds = log.assignee.map((id) => (0, import_node_server_utils201.toObjectId)(id));
|
|
59022
|
+
const userDocs = await db.collection("members").find({ _id: { $in: userIds } }).toArray();
|
|
59023
|
+
if (userDocs && userDocs.length > 0) {
|
|
59024
|
+
return userDocs.map((u) => u.name || u.email || "").filter(Boolean).join(", ");
|
|
59025
|
+
}
|
|
59026
|
+
}
|
|
59027
|
+
if (log.createdBy) {
|
|
59028
|
+
const userDoc = await db.collection("members").findOne({
|
|
59029
|
+
_id: (0, import_node_server_utils201.toObjectId)(log.createdBy)
|
|
59030
|
+
});
|
|
59031
|
+
if (userDoc && userDoc.name) {
|
|
59032
|
+
return userDoc.name;
|
|
59033
|
+
}
|
|
59034
|
+
}
|
|
59035
|
+
return "Unassigned";
|
|
59036
|
+
}
|
|
59037
|
+
function getPatrolLogStatus(log, defaultStatus = "completed") {
|
|
59038
|
+
if (!log?.status) {
|
|
59039
|
+
return defaultStatus;
|
|
59040
|
+
}
|
|
59041
|
+
return Array.isArray(log.status) ? log.status.join(", ") : log.status;
|
|
59042
|
+
}
|
|
59004
59043
|
async function getSecurityDashboard({
|
|
59005
59044
|
siteId = "",
|
|
59006
59045
|
period = "today" /* TODAY */,
|
|
@@ -59175,11 +59214,11 @@ function useNewDashboardRepo() {
|
|
|
59175
59214
|
$facet: {
|
|
59176
59215
|
total: [{ $count: "count" }],
|
|
59177
59216
|
completed: [
|
|
59178
|
-
{ $match: {
|
|
59217
|
+
{ $match: { status: "complete" } },
|
|
59179
59218
|
{ $count: "count" }
|
|
59180
59219
|
],
|
|
59181
59220
|
skipped: [
|
|
59182
|
-
{ $match: {
|
|
59221
|
+
{ $match: { status: "incomplete" } },
|
|
59183
59222
|
{ $count: "count" }
|
|
59184
59223
|
]
|
|
59185
59224
|
}
|
|
@@ -59199,11 +59238,11 @@ function useNewDashboardRepo() {
|
|
|
59199
59238
|
$facet: {
|
|
59200
59239
|
total: [{ $count: "count" }],
|
|
59201
59240
|
completed: [
|
|
59202
|
-
{ $match: {
|
|
59241
|
+
{ $match: { status: "complete" } },
|
|
59203
59242
|
{ $count: "count" }
|
|
59204
59243
|
],
|
|
59205
59244
|
skipped: [
|
|
59206
|
-
{ $match: {
|
|
59245
|
+
{ $match: { status: "incomplete" } },
|
|
59207
59246
|
{ $count: "count" }
|
|
59208
59247
|
]
|
|
59209
59248
|
}
|
|
@@ -59223,11 +59262,11 @@ function useNewDashboardRepo() {
|
|
|
59223
59262
|
$facet: {
|
|
59224
59263
|
total: [{ $count: "count" }],
|
|
59225
59264
|
completed: [
|
|
59226
|
-
{ $match: {
|
|
59265
|
+
{ $match: { status: "complete" } },
|
|
59227
59266
|
{ $count: "count" }
|
|
59228
59267
|
],
|
|
59229
59268
|
skipped: [
|
|
59230
|
-
{ $match: {
|
|
59269
|
+
{ $match: { status: "incomplete" } },
|
|
59231
59270
|
{ $count: "count" }
|
|
59232
59271
|
]
|
|
59233
59272
|
}
|
|
@@ -59258,127 +59297,27 @@ function useNewDashboardRepo() {
|
|
|
59258
59297
|
const tTotal = tPatrolFacet.total[0]?.count ?? 0;
|
|
59259
59298
|
const tCompleted = tPatrolFacet.completed[0]?.count ?? 0;
|
|
59260
59299
|
const todayCompliance = tTotal > 0 ? tCompleted / tTotal * 100 : 0;
|
|
59261
|
-
|
|
59262
|
-
|
|
59263
|
-
|
|
59264
|
-
|
|
59265
|
-
|
|
59266
|
-
|
|
59267
|
-
|
|
59268
|
-
|
|
59269
|
-
status
|
|
59270
|
-
|
|
59271
|
-
|
|
59272
|
-
|
|
59273
|
-
|
|
59274
|
-
|
|
59275
|
-
|
|
59276
|
-
|
|
59277
|
-
|
|
59278
|
-
|
|
59279
|
-
}
|
|
59280
|
-
}
|
|
59281
|
-
|
|
59282
|
-
const limitedRoutes = expandedRoutes.slice(0, 4);
|
|
59283
|
-
limitedRoutes.forEach((item, idx) => {
|
|
59284
|
-
item.itemIndex = idx + 1;
|
|
59285
|
-
});
|
|
59286
|
-
activePatrolItems = await Promise.all(
|
|
59287
|
-
limitedRoutes.map(async ({ route, startTime, itemIndex }) => {
|
|
59288
|
-
const log = await db.collection("patrol.logs").findOne({
|
|
59289
|
-
site: { $in: [siteIdObj, siteId] },
|
|
59290
|
-
route: { $in: [route._id, route._id.toString()] },
|
|
59291
|
-
createdAt: { $gte: today, $lte: todayEnd }
|
|
59292
|
-
});
|
|
59293
|
-
let person = "Unassigned";
|
|
59294
|
-
if (log && log.assignee && log.assignee.length > 0) {
|
|
59295
|
-
const userIds = log.assignee.map((id) => (0, import_node_server_utils201.toObjectId)(id));
|
|
59296
|
-
const userDocs = await db.collection("members").find({ _id: { $in: userIds } }).toArray();
|
|
59297
|
-
if (userDocs && userDocs.length > 0) {
|
|
59298
|
-
person = userDocs.map((u) => u.name || u.email || "").filter(Boolean).join(", ");
|
|
59299
|
-
}
|
|
59300
|
-
} else if (log && log.createdBy) {
|
|
59301
|
-
const userDoc = await db.collection("members").findOne({
|
|
59302
|
-
_id: (0, import_node_server_utils201.toObjectId)(log.createdBy)
|
|
59303
|
-
});
|
|
59304
|
-
if (userDoc && userDoc.name) {
|
|
59305
|
-
person = userDoc.name;
|
|
59306
|
-
}
|
|
59307
|
-
}
|
|
59308
|
-
let status = "pending";
|
|
59309
|
-
if (log) {
|
|
59310
|
-
if (log.status) {
|
|
59311
|
-
status = Array.isArray(log.status) ? log.status.join(", ") : log.status;
|
|
59312
|
-
} else {
|
|
59313
|
-
status = "completed";
|
|
59314
|
-
}
|
|
59315
|
-
} else {
|
|
59316
|
-
const routeTime = import_moment2.default.tz(
|
|
59317
|
-
`${todayString} ${startTime}`,
|
|
59318
|
-
"YYYY-MM-DD HH:mm",
|
|
59319
|
-
"Asia/Singapore"
|
|
59320
|
-
);
|
|
59321
|
-
const nowSg = import_moment2.default.tz("Asia/Singapore");
|
|
59322
|
-
const diffMinutes = nowSg.diff(routeTime, "minutes");
|
|
59323
|
-
if (diffMinutes >= 0) {
|
|
59324
|
-
if (diffMinutes <= 120) {
|
|
59325
|
-
status = "on paused";
|
|
59326
|
-
} else {
|
|
59327
|
-
status = "incomplete";
|
|
59328
|
-
}
|
|
59329
|
-
} else {
|
|
59330
|
-
status = "pending";
|
|
59331
|
-
}
|
|
59332
|
-
}
|
|
59333
|
-
return {
|
|
59334
|
-
id: `${route._id.toString()}_${startTime}`,
|
|
59335
|
-
title: route.name,
|
|
59336
|
-
subtitle: `ID${String(itemIndex).padStart(3, "0")}`,
|
|
59337
|
-
person,
|
|
59338
|
-
status,
|
|
59339
|
-
time: startTime
|
|
59340
|
-
};
|
|
59341
|
-
})
|
|
59342
|
-
);
|
|
59343
|
-
} else {
|
|
59344
|
-
const logs = await db.collection("patrol.logs").find({
|
|
59345
|
-
site: { $in: [siteIdObj, siteId] },
|
|
59346
|
-
createdAt: periodRange
|
|
59347
|
-
}).sort({ createdAt: -1 }).limit(4).toArray();
|
|
59348
|
-
activePatrolItems = await Promise.all(
|
|
59349
|
-
logs.map(async (log) => {
|
|
59350
|
-
let person = "Unassigned";
|
|
59351
|
-
if (log.assignee && log.assignee.length > 0) {
|
|
59352
|
-
const userIds = log.assignee.map((id) => (0, import_node_server_utils201.toObjectId)(id));
|
|
59353
|
-
const userDocs = await db.collection("members").find({ _id: { $in: userIds } }).toArray();
|
|
59354
|
-
if (userDocs && userDocs.length > 0) {
|
|
59355
|
-
person = userDocs.map((u) => u.name || u.email || "").filter(Boolean).join(", ");
|
|
59356
|
-
}
|
|
59357
|
-
} else if (log.createdBy) {
|
|
59358
|
-
const userDoc = await db.collection("members").findOne({
|
|
59359
|
-
_id: (0, import_node_server_utils201.toObjectId)(log.createdBy)
|
|
59360
|
-
});
|
|
59361
|
-
if (userDoc && userDoc.name) {
|
|
59362
|
-
person = userDoc.name;
|
|
59363
|
-
}
|
|
59364
|
-
}
|
|
59365
|
-
let status = "completed";
|
|
59366
|
-
if (log.status) {
|
|
59367
|
-
status = Array.isArray(log.status) ? log.status.join(", ") : log.status;
|
|
59368
|
-
}
|
|
59369
|
-
const logTime = (0, import_moment2.default)(log.createdAt).tz("Asia/Singapore").format("HH:mm");
|
|
59370
|
-
const logDate = (0, import_moment2.default)(log.createdAt).tz("Asia/Singapore").format("DD/MM/YYYY");
|
|
59371
|
-
return {
|
|
59372
|
-
id: log._id.toString(),
|
|
59373
|
-
title: log.name,
|
|
59374
|
-
subtitle: logDate,
|
|
59375
|
-
person,
|
|
59376
|
-
status,
|
|
59377
|
-
time: logTime
|
|
59378
|
-
};
|
|
59379
|
-
})
|
|
59380
|
-
);
|
|
59381
|
-
}
|
|
59300
|
+
const activePatrolDateRange = getActivePatrolDateRange(period);
|
|
59301
|
+
const activePatrolLogs = await db.collection("patrol.logs").find({
|
|
59302
|
+
site: { $in: [siteIdObj, siteId] },
|
|
59303
|
+
createdAt: activePatrolDateRange
|
|
59304
|
+
}).sort({ createdAt: -1 }).limit(4).toArray();
|
|
59305
|
+
const activePatrolItems = await Promise.all(
|
|
59306
|
+
activePatrolLogs.map(async (log) => {
|
|
59307
|
+
const person = await getPatrolLogPerson(log);
|
|
59308
|
+
const status = getPatrolLogStatus(log);
|
|
59309
|
+
const logTime = (0, import_moment2.default)(log.createdAt).tz("Asia/Singapore").format("HH:mm");
|
|
59310
|
+
const logDate = (0, import_moment2.default)(log.createdAt).tz("Asia/Singapore").format("DD/MM/YYYY");
|
|
59311
|
+
return {
|
|
59312
|
+
id: log._id.toString(),
|
|
59313
|
+
title: log.name,
|
|
59314
|
+
subtitle: logDate,
|
|
59315
|
+
person,
|
|
59316
|
+
status,
|
|
59317
|
+
time: logTime
|
|
59318
|
+
};
|
|
59319
|
+
})
|
|
59320
|
+
);
|
|
59382
59321
|
const data = {
|
|
59383
59322
|
openWorkOrder: {
|
|
59384
59323
|
count: wFacet.total[0]?.count ?? 0,
|