@7365admin1/core 3.34.4-staging.15 → 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 +65 -127
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -127
- 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
|
@@ -58990,6 +58990,17 @@ function useNewDashboardRepo() {
|
|
|
58990
58990
|
$lte: now.clone().endOf("day").toDate()
|
|
58991
58991
|
};
|
|
58992
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
|
+
}
|
|
58993
59004
|
function getSiteDayRange(date = import_moment2.default.tz("Asia/Singapore")) {
|
|
58994
59005
|
return {
|
|
58995
59006
|
$gte: date.clone().startOf("day").toDate(),
|
|
@@ -59002,6 +59013,33 @@ function useNewDashboardRepo() {
|
|
|
59002
59013
|
}
|
|
59003
59014
|
return Math.round((currentCount - previousCount) / previousCount * 100 * 100) / 100;
|
|
59004
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
|
+
}
|
|
59005
59043
|
async function getSecurityDashboard({
|
|
59006
59044
|
siteId = "",
|
|
59007
59045
|
period = "today" /* TODAY */,
|
|
@@ -59176,11 +59214,11 @@ function useNewDashboardRepo() {
|
|
|
59176
59214
|
$facet: {
|
|
59177
59215
|
total: [{ $count: "count" }],
|
|
59178
59216
|
completed: [
|
|
59179
|
-
{ $match: {
|
|
59217
|
+
{ $match: { status: "complete" } },
|
|
59180
59218
|
{ $count: "count" }
|
|
59181
59219
|
],
|
|
59182
59220
|
skipped: [
|
|
59183
|
-
{ $match: {
|
|
59221
|
+
{ $match: { status: "incomplete" } },
|
|
59184
59222
|
{ $count: "count" }
|
|
59185
59223
|
]
|
|
59186
59224
|
}
|
|
@@ -59200,11 +59238,11 @@ function useNewDashboardRepo() {
|
|
|
59200
59238
|
$facet: {
|
|
59201
59239
|
total: [{ $count: "count" }],
|
|
59202
59240
|
completed: [
|
|
59203
|
-
{ $match: {
|
|
59241
|
+
{ $match: { status: "complete" } },
|
|
59204
59242
|
{ $count: "count" }
|
|
59205
59243
|
],
|
|
59206
59244
|
skipped: [
|
|
59207
|
-
{ $match: {
|
|
59245
|
+
{ $match: { status: "incomplete" } },
|
|
59208
59246
|
{ $count: "count" }
|
|
59209
59247
|
]
|
|
59210
59248
|
}
|
|
@@ -59224,11 +59262,11 @@ function useNewDashboardRepo() {
|
|
|
59224
59262
|
$facet: {
|
|
59225
59263
|
total: [{ $count: "count" }],
|
|
59226
59264
|
completed: [
|
|
59227
|
-
{ $match: {
|
|
59265
|
+
{ $match: { status: "complete" } },
|
|
59228
59266
|
{ $count: "count" }
|
|
59229
59267
|
],
|
|
59230
59268
|
skipped: [
|
|
59231
|
-
{ $match: {
|
|
59269
|
+
{ $match: { status: "incomplete" } },
|
|
59232
59270
|
{ $count: "count" }
|
|
59233
59271
|
]
|
|
59234
59272
|
}
|
|
@@ -59259,127 +59297,27 @@ function useNewDashboardRepo() {
|
|
|
59259
59297
|
const tTotal = tPatrolFacet.total[0]?.count ?? 0;
|
|
59260
59298
|
const tCompleted = tPatrolFacet.completed[0]?.count ?? 0;
|
|
59261
59299
|
const todayCompliance = tTotal > 0 ? tCompleted / tTotal * 100 : 0;
|
|
59262
|
-
|
|
59263
|
-
|
|
59264
|
-
|
|
59265
|
-
|
|
59266
|
-
|
|
59267
|
-
|
|
59268
|
-
|
|
59269
|
-
|
|
59270
|
-
status
|
|
59271
|
-
|
|
59272
|
-
|
|
59273
|
-
|
|
59274
|
-
|
|
59275
|
-
|
|
59276
|
-
|
|
59277
|
-
|
|
59278
|
-
|
|
59279
|
-
|
|
59280
|
-
}
|
|
59281
|
-
}
|
|
59282
|
-
|
|
59283
|
-
const limitedRoutes = expandedRoutes.slice(0, 4);
|
|
59284
|
-
limitedRoutes.forEach((item, idx) => {
|
|
59285
|
-
item.itemIndex = idx + 1;
|
|
59286
|
-
});
|
|
59287
|
-
activePatrolItems = await Promise.all(
|
|
59288
|
-
limitedRoutes.map(async ({ route, startTime, itemIndex }) => {
|
|
59289
|
-
const log = await db.collection("patrol.logs").findOne({
|
|
59290
|
-
site: { $in: [siteIdObj, siteId] },
|
|
59291
|
-
route: { $in: [route._id, route._id.toString()] },
|
|
59292
|
-
createdAt: { $gte: today, $lte: todayEnd }
|
|
59293
|
-
});
|
|
59294
|
-
let person = "Unassigned";
|
|
59295
|
-
if (log && log.assignee && log.assignee.length > 0) {
|
|
59296
|
-
const userIds = log.assignee.map((id) => (0, import_node_server_utils201.toObjectId)(id));
|
|
59297
|
-
const userDocs = await db.collection("members").find({ _id: { $in: userIds } }).toArray();
|
|
59298
|
-
if (userDocs && userDocs.length > 0) {
|
|
59299
|
-
person = userDocs.map((u) => u.name || u.email || "").filter(Boolean).join(", ");
|
|
59300
|
-
}
|
|
59301
|
-
} else if (log && log.createdBy) {
|
|
59302
|
-
const userDoc = await db.collection("members").findOne({
|
|
59303
|
-
_id: (0, import_node_server_utils201.toObjectId)(log.createdBy)
|
|
59304
|
-
});
|
|
59305
|
-
if (userDoc && userDoc.name) {
|
|
59306
|
-
person = userDoc.name;
|
|
59307
|
-
}
|
|
59308
|
-
}
|
|
59309
|
-
let status = "pending";
|
|
59310
|
-
if (log) {
|
|
59311
|
-
if (log.status) {
|
|
59312
|
-
status = Array.isArray(log.status) ? log.status.join(", ") : log.status;
|
|
59313
|
-
} else {
|
|
59314
|
-
status = "completed";
|
|
59315
|
-
}
|
|
59316
|
-
} else {
|
|
59317
|
-
const routeTime = import_moment2.default.tz(
|
|
59318
|
-
`${todayString} ${startTime}`,
|
|
59319
|
-
"YYYY-MM-DD HH:mm",
|
|
59320
|
-
"Asia/Singapore"
|
|
59321
|
-
);
|
|
59322
|
-
const nowSg = import_moment2.default.tz("Asia/Singapore");
|
|
59323
|
-
const diffMinutes = nowSg.diff(routeTime, "minutes");
|
|
59324
|
-
if (diffMinutes >= 0) {
|
|
59325
|
-
if (diffMinutes <= 120) {
|
|
59326
|
-
status = "on paused";
|
|
59327
|
-
} else {
|
|
59328
|
-
status = "incomplete";
|
|
59329
|
-
}
|
|
59330
|
-
} else {
|
|
59331
|
-
status = "pending";
|
|
59332
|
-
}
|
|
59333
|
-
}
|
|
59334
|
-
return {
|
|
59335
|
-
id: `${route._id.toString()}_${startTime}`,
|
|
59336
|
-
title: route.name,
|
|
59337
|
-
subtitle: `ID${String(itemIndex).padStart(3, "0")}`,
|
|
59338
|
-
person,
|
|
59339
|
-
status,
|
|
59340
|
-
time: startTime
|
|
59341
|
-
};
|
|
59342
|
-
})
|
|
59343
|
-
);
|
|
59344
|
-
} else {
|
|
59345
|
-
const logs = await db.collection("patrol.logs").find({
|
|
59346
|
-
site: { $in: [siteIdObj, siteId] },
|
|
59347
|
-
createdAt: periodRange
|
|
59348
|
-
}).sort({ createdAt: -1 }).limit(4).toArray();
|
|
59349
|
-
activePatrolItems = await Promise.all(
|
|
59350
|
-
logs.map(async (log) => {
|
|
59351
|
-
let person = "Unassigned";
|
|
59352
|
-
if (log.assignee && log.assignee.length > 0) {
|
|
59353
|
-
const userIds = log.assignee.map((id) => (0, import_node_server_utils201.toObjectId)(id));
|
|
59354
|
-
const userDocs = await db.collection("members").find({ _id: { $in: userIds } }).toArray();
|
|
59355
|
-
if (userDocs && userDocs.length > 0) {
|
|
59356
|
-
person = userDocs.map((u) => u.name || u.email || "").filter(Boolean).join(", ");
|
|
59357
|
-
}
|
|
59358
|
-
} else if (log.createdBy) {
|
|
59359
|
-
const userDoc = await db.collection("members").findOne({
|
|
59360
|
-
_id: (0, import_node_server_utils201.toObjectId)(log.createdBy)
|
|
59361
|
-
});
|
|
59362
|
-
if (userDoc && userDoc.name) {
|
|
59363
|
-
person = userDoc.name;
|
|
59364
|
-
}
|
|
59365
|
-
}
|
|
59366
|
-
let status = "completed";
|
|
59367
|
-
if (log.status) {
|
|
59368
|
-
status = Array.isArray(log.status) ? log.status.join(", ") : log.status;
|
|
59369
|
-
}
|
|
59370
|
-
const logTime = (0, import_moment2.default)(log.createdAt).tz("Asia/Singapore").format("HH:mm");
|
|
59371
|
-
const logDate = (0, import_moment2.default)(log.createdAt).tz("Asia/Singapore").format("DD/MM/YYYY");
|
|
59372
|
-
return {
|
|
59373
|
-
id: log._id.toString(),
|
|
59374
|
-
title: log.name,
|
|
59375
|
-
subtitle: logDate,
|
|
59376
|
-
person,
|
|
59377
|
-
status,
|
|
59378
|
-
time: logTime
|
|
59379
|
-
};
|
|
59380
|
-
})
|
|
59381
|
-
);
|
|
59382
|
-
}
|
|
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
|
+
);
|
|
59383
59321
|
const data = {
|
|
59384
59322
|
openWorkOrder: {
|
|
59385
59323
|
count: wFacet.total[0]?.count ?? 0,
|