@7365admin1/core 3.5.0 → 3.6.0
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/CHANGELOG.md +6 -0
- package/dist/index.d.ts +194 -35
- package/dist/index.js +1679 -635
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1994 -948
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -536,13 +536,13 @@ var require_logger = __commonJS({
|
|
|
536
536
|
"use strict";
|
|
537
537
|
exports.__esModule = true;
|
|
538
538
|
var _utils = require_utils();
|
|
539
|
-
var
|
|
539
|
+
var logger197 = {
|
|
540
540
|
methodMap: ["debug", "info", "warn", "error"],
|
|
541
541
|
level: "info",
|
|
542
542
|
// Maps a given level value to the `methodMap` indexes above.
|
|
543
543
|
lookupLevel: function lookupLevel(level) {
|
|
544
544
|
if (typeof level === "string") {
|
|
545
|
-
var levelMap = _utils.indexOf(
|
|
545
|
+
var levelMap = _utils.indexOf(logger197.methodMap, level.toLowerCase());
|
|
546
546
|
if (levelMap >= 0) {
|
|
547
547
|
level = levelMap;
|
|
548
548
|
} else {
|
|
@@ -553,9 +553,9 @@ var require_logger = __commonJS({
|
|
|
553
553
|
},
|
|
554
554
|
// Can be overridden in the host environment
|
|
555
555
|
log: function log(level) {
|
|
556
|
-
level =
|
|
557
|
-
if (typeof console !== "undefined" &&
|
|
558
|
-
var method =
|
|
556
|
+
level = logger197.lookupLevel(level);
|
|
557
|
+
if (typeof console !== "undefined" && logger197.lookupLevel(logger197.level) <= level) {
|
|
558
|
+
var method = logger197.methodMap[level];
|
|
559
559
|
if (!console[method]) {
|
|
560
560
|
method = "log";
|
|
561
561
|
}
|
|
@@ -566,7 +566,7 @@ var require_logger = __commonJS({
|
|
|
566
566
|
}
|
|
567
567
|
}
|
|
568
568
|
};
|
|
569
|
-
exports["default"] =
|
|
569
|
+
exports["default"] = logger197;
|
|
570
570
|
module2.exports = exports["default"];
|
|
571
571
|
}
|
|
572
572
|
});
|
|
@@ -5993,7 +5993,6 @@ __export(src_exports, {
|
|
|
5993
5993
|
OvernightParkingRequestSort: () => OvernightParkingRequestSort,
|
|
5994
5994
|
OvernightParkingRequestStatus: () => OvernightParkingRequestStatus,
|
|
5995
5995
|
PERSON_TYPES: () => PERSON_TYPES,
|
|
5996
|
-
PMDashboardCollection: () => PMDashboardCollection,
|
|
5997
5996
|
PStatus: () => PStatus,
|
|
5998
5997
|
Period: () => Period,
|
|
5999
5998
|
PersonStatus: () => PersonStatus,
|
|
@@ -6046,8 +6045,6 @@ __export(src_exports, {
|
|
|
6046
6045
|
guests_namespace_collection: () => guests_namespace_collection,
|
|
6047
6046
|
incidentReportLog: () => incidentReportLog,
|
|
6048
6047
|
incidents_namespace_collection: () => incidents_namespace_collection,
|
|
6049
|
-
landscapeDashboardCollection: () => landscapeDashboardCollection,
|
|
6050
|
-
mAndEDashboardCollection: () => mAndEDashboardCollection,
|
|
6051
6048
|
manpowerDesignationsSchema: () => manpowerDesignationsSchema,
|
|
6052
6049
|
manpowerEvents: () => manpowerEvents,
|
|
6053
6050
|
manpowerMonitoringSchema: () => manpowerMonitoringSchema,
|
|
@@ -6060,8 +6057,6 @@ __export(src_exports, {
|
|
|
6060
6057
|
orgSchema: () => orgSchema,
|
|
6061
6058
|
overnight_parking_requests_namespace_collection: () => overnight_parking_requests_namespace_collection,
|
|
6062
6059
|
parseDahuaFind: () => parseDahuaFind,
|
|
6063
|
-
pestDashboardCollection: () => pestDashboardCollection,
|
|
6064
|
-
poolDashboardCollection: () => poolDashboardCollection,
|
|
6065
6060
|
promoCodeSchema: () => promoCodeSchema,
|
|
6066
6061
|
remarksSchema: () => remarksSchema,
|
|
6067
6062
|
residentFormEntry: () => residentFormEntry,
|
|
@@ -6152,7 +6147,6 @@ __export(src_exports, {
|
|
|
6152
6147
|
schemaVisitorTransaction: () => schemaVisitorTransaction,
|
|
6153
6148
|
schemeCamera: () => schemeCamera,
|
|
6154
6149
|
schemeLogCamera: () => schemeLogCamera,
|
|
6155
|
-
securityDashboardCollection: () => securityDashboardCollection,
|
|
6156
6150
|
shiftSchema: () => shiftSchema,
|
|
6157
6151
|
siteSchema: () => siteSchema,
|
|
6158
6152
|
site_people_namespace_collection: () => site_people_namespace_collection,
|
|
@@ -21343,11 +21337,22 @@ function useVisitorTransactionRepo() {
|
|
|
21343
21337
|
return res.insertedId;
|
|
21344
21338
|
}
|
|
21345
21339
|
} catch (error) {
|
|
21346
|
-
console.log("Error in add visitor transaction:", error);
|
|
21347
21340
|
const isDuplicated = error.message.includes("duplicate");
|
|
21348
21341
|
if (isDuplicated) {
|
|
21342
|
+
import_node_server_utils69.logger.warn({
|
|
21343
|
+
operation: "addVisitorTransaction",
|
|
21344
|
+
reason: "Duplicate entry",
|
|
21345
|
+
site: value.site,
|
|
21346
|
+
error: error.message
|
|
21347
|
+
});
|
|
21349
21348
|
throw new import_node_server_utils69.BadRequestError("Visitor already exists.");
|
|
21350
21349
|
}
|
|
21350
|
+
import_node_server_utils69.logger.error({
|
|
21351
|
+
operation: "addVisitorTransaction",
|
|
21352
|
+
site: value.site,
|
|
21353
|
+
error: error.message,
|
|
21354
|
+
stack: error.stack
|
|
21355
|
+
});
|
|
21351
21356
|
throw error;
|
|
21352
21357
|
}
|
|
21353
21358
|
}
|
|
@@ -26001,30 +26006,28 @@ function useBuildingUnitRepo() {
|
|
|
26001
26006
|
}
|
|
26002
26007
|
const query = {
|
|
26003
26008
|
site,
|
|
26004
|
-
owner: { $nin: [null, ""] }
|
|
26009
|
+
owner: { $nin: [null, ""] },
|
|
26010
|
+
status: "active"
|
|
26005
26011
|
};
|
|
26006
26012
|
if (unitIds && unitIds.length > 0) {
|
|
26007
26013
|
query._id = { $in: unitIds };
|
|
26008
26014
|
}
|
|
26009
|
-
const cacheOptions = {
|
|
26010
|
-
site: site.toString()
|
|
26011
|
-
};
|
|
26012
|
-
const cacheKey = (0, import_node_server_utils76.makeCacheKey)(
|
|
26013
|
-
building_units_namespace_collection,
|
|
26014
|
-
cacheOptions
|
|
26015
|
-
);
|
|
26016
|
-
const cachedData = await getCache(cacheKey);
|
|
26017
|
-
if (cachedData) {
|
|
26018
|
-
import_node_server_utils76.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
26019
|
-
return cachedData;
|
|
26020
|
-
}
|
|
26021
26015
|
try {
|
|
26022
|
-
const data = await collection.aggregate([
|
|
26023
|
-
|
|
26024
|
-
|
|
26025
|
-
|
|
26026
|
-
|
|
26027
|
-
|
|
26016
|
+
const data = await collection.aggregate([
|
|
26017
|
+
{ $match: query },
|
|
26018
|
+
{
|
|
26019
|
+
$lookup: {
|
|
26020
|
+
from: "building-levels",
|
|
26021
|
+
localField: "level",
|
|
26022
|
+
foreignField: "_id",
|
|
26023
|
+
pipeline: [{ $project: { _id: 0, name: 1 } }],
|
|
26024
|
+
as: "_levelData"
|
|
26025
|
+
}
|
|
26026
|
+
},
|
|
26027
|
+
{ $unwind: { path: "$_levelData", preserveNullAndEmptyArrays: true } },
|
|
26028
|
+
{ $addFields: { levelName: { $ifNull: ["$_levelData.name", ""] } } },
|
|
26029
|
+
{ $unset: "_levelData" }
|
|
26030
|
+
]).toArray();
|
|
26028
26031
|
return data;
|
|
26029
26032
|
} catch (error) {
|
|
26030
26033
|
if (error instanceof import_node_server_utils76.AppError) {
|
|
@@ -40965,7 +40968,7 @@ var NotificationService = class {
|
|
|
40965
40968
|
await send(
|
|
40966
40969
|
toStringArray(payload.to),
|
|
40967
40970
|
"Preloved Marketplace",
|
|
40968
|
-
`
|
|
40971
|
+
`New preloved marketplace post added.`,
|
|
40969
40972
|
{
|
|
40970
40973
|
prelovedId: payload.prelovedId.toString(),
|
|
40971
40974
|
status: payload.status,
|
|
@@ -56325,18 +56328,14 @@ function useNfcPatrolLogController() {
|
|
|
56325
56328
|
|
|
56326
56329
|
// src/repositories/new-dashboard.repo.ts
|
|
56327
56330
|
var import_node_server_utils199 = require("@7365admin1/node-server-utils");
|
|
56331
|
+
var import_mongodb121 = require("mongodb");
|
|
56332
|
+
var import_moment = __toESM(require("moment"));
|
|
56328
56333
|
var Period = /* @__PURE__ */ ((Period2) => {
|
|
56329
56334
|
Period2["TODAY"] = "today";
|
|
56330
56335
|
Period2["THIS_WEEK"] = "thisWeek";
|
|
56331
56336
|
Period2["THIS_MONTH"] = "thisMonth";
|
|
56332
56337
|
return Period2;
|
|
56333
56338
|
})(Period || {});
|
|
56334
|
-
var securityDashboardCollection = "security-dashboard";
|
|
56335
|
-
var PMDashboardCollection = "PM-dashboard";
|
|
56336
|
-
var pestDashboardCollection = "pest-dashboard";
|
|
56337
|
-
var poolDashboardCollection = "pool-dashboard";
|
|
56338
|
-
var mAndEDashboardCollection = "M&E-dashboard";
|
|
56339
|
-
var landscapeDashboardCollection = "landscape-dashboard";
|
|
56340
56339
|
function getPeriodRangeWithPrevious(period) {
|
|
56341
56340
|
const now = /* @__PURE__ */ new Date();
|
|
56342
56341
|
let currentStart = /* @__PURE__ */ new Date();
|
|
@@ -56409,26 +56408,62 @@ function useNewDashboardRepo() {
|
|
|
56409
56408
|
if (!db) {
|
|
56410
56409
|
throw new import_node_server_utils199.InternalServerError("Unable to connect to server.");
|
|
56411
56410
|
}
|
|
56412
|
-
const
|
|
56413
|
-
|
|
56411
|
+
const cleaning_schedule_namespace_collection = "site.cleaning.schedules";
|
|
56412
|
+
const area_checklist_namespace_collection = "site.cleaning.schedule.areas";
|
|
56413
|
+
const supply_namespace_collection = "site.supplies";
|
|
56414
|
+
const work_order_namespace_collection = "work-orders2";
|
|
56415
|
+
const areaChecklistCollection = db.collection(
|
|
56416
|
+
area_checklist_namespace_collection
|
|
56414
56417
|
);
|
|
56418
|
+
const supplyCollection = db.collection(supply_namespace_collection);
|
|
56419
|
+
const workOrderCollection = db.collection(work_order_namespace_collection);
|
|
56420
|
+
const attendanceCollection = db.collection("site.attendances");
|
|
56421
|
+
const feedbackCollection = db.collection("feedbacks2");
|
|
56422
|
+
const workOrderServiceMap = {
|
|
56423
|
+
security_agency: "Security",
|
|
56424
|
+
cleaning_services: "Cleaning",
|
|
56425
|
+
mechanical_electrical_services: "M&E",
|
|
56426
|
+
landscaping_services: "Landscape",
|
|
56427
|
+
pest_control_services: "Pest Control",
|
|
56428
|
+
pool_maintenance_services: "Pool Maintenance"
|
|
56429
|
+
};
|
|
56415
56430
|
async function getMetric(collectionString, siteId, period) {
|
|
56416
56431
|
const site = (0, import_node_server_utils199.toObjectId)(siteId);
|
|
56417
56432
|
const range = getPeriodRangeWithPrevious(period);
|
|
56418
56433
|
const collection = db.collection(collectionString);
|
|
56419
56434
|
const current = await collection.countDocuments({
|
|
56420
56435
|
site,
|
|
56421
|
-
|
|
56422
|
-
|
|
56423
|
-
|
|
56424
|
-
|
|
56436
|
+
$or: [
|
|
56437
|
+
{
|
|
56438
|
+
createdAt: {
|
|
56439
|
+
$gte: range.current.start,
|
|
56440
|
+
$lte: range.current.end
|
|
56441
|
+
}
|
|
56442
|
+
},
|
|
56443
|
+
{
|
|
56444
|
+
createdAt: {
|
|
56445
|
+
$gte: new Date(range.current.start),
|
|
56446
|
+
$lte: new Date(range.current.end)
|
|
56447
|
+
}
|
|
56448
|
+
}
|
|
56449
|
+
]
|
|
56425
56450
|
});
|
|
56426
56451
|
const previous = await collection.countDocuments({
|
|
56427
56452
|
site,
|
|
56428
|
-
|
|
56429
|
-
|
|
56430
|
-
|
|
56431
|
-
|
|
56453
|
+
$or: [
|
|
56454
|
+
{
|
|
56455
|
+
createdAt: {
|
|
56456
|
+
$gte: range.previous.start,
|
|
56457
|
+
$lte: range.previous.end
|
|
56458
|
+
}
|
|
56459
|
+
},
|
|
56460
|
+
{
|
|
56461
|
+
createdAt: {
|
|
56462
|
+
$gte: new Date(range.previous.start),
|
|
56463
|
+
$lte: new Date(range.previous.end)
|
|
56464
|
+
}
|
|
56465
|
+
}
|
|
56466
|
+
]
|
|
56432
56467
|
});
|
|
56433
56468
|
return {
|
|
56434
56469
|
count: current,
|
|
@@ -56445,21 +56480,6 @@ function useNewDashboardRepo() {
|
|
|
56445
56480
|
incident = "today" /* TODAY */,
|
|
56446
56481
|
guest = "today" /* TODAY */
|
|
56447
56482
|
}) {
|
|
56448
|
-
const cacheOptions = {
|
|
56449
|
-
siteId,
|
|
56450
|
-
feedback,
|
|
56451
|
-
workOrder,
|
|
56452
|
-
vehicle,
|
|
56453
|
-
building,
|
|
56454
|
-
visitor,
|
|
56455
|
-
incident
|
|
56456
|
-
};
|
|
56457
|
-
const cacheKey = (0, import_node_server_utils199.makeCacheKey)(securityDashboardCollection, cacheOptions);
|
|
56458
|
-
const cachedData = await getCache(cacheKey);
|
|
56459
|
-
if (cachedData) {
|
|
56460
|
-
import_node_server_utils199.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
56461
|
-
return cachedData;
|
|
56462
|
-
}
|
|
56463
56483
|
const feedbacks = await getMetric(
|
|
56464
56484
|
feedbacks_namespace_collection,
|
|
56465
56485
|
siteId,
|
|
@@ -56500,11 +56520,6 @@ function useNewDashboardRepo() {
|
|
|
56500
56520
|
incidents,
|
|
56501
56521
|
guests
|
|
56502
56522
|
};
|
|
56503
|
-
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
56504
|
-
import_node_server_utils199.logger.info(`Cache set for key: ${cacheKey}`);
|
|
56505
|
-
}).catch((err) => {
|
|
56506
|
-
import_node_server_utils199.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
56507
|
-
});
|
|
56508
56523
|
return data;
|
|
56509
56524
|
}
|
|
56510
56525
|
async function getPropertyManagementDashboard({
|
|
@@ -56520,25 +56535,6 @@ function useNewDashboardRepo() {
|
|
|
56520
56535
|
visitor = "today" /* TODAY */,
|
|
56521
56536
|
incident = "today" /* TODAY */
|
|
56522
56537
|
}) {
|
|
56523
|
-
const cacheOptions = {
|
|
56524
|
-
siteId,
|
|
56525
|
-
feedback,
|
|
56526
|
-
workOrder,
|
|
56527
|
-
sitePeople,
|
|
56528
|
-
facilityBooking,
|
|
56529
|
-
bulletinBoard,
|
|
56530
|
-
event,
|
|
56531
|
-
vehicle,
|
|
56532
|
-
building,
|
|
56533
|
-
visitor,
|
|
56534
|
-
incident
|
|
56535
|
-
};
|
|
56536
|
-
const cacheKey = (0, import_node_server_utils199.makeCacheKey)(PMDashboardCollection, cacheOptions);
|
|
56537
|
-
const cachedData = await getCache(cacheKey);
|
|
56538
|
-
if (cachedData) {
|
|
56539
|
-
import_node_server_utils199.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
56540
|
-
return cachedData;
|
|
56541
|
-
}
|
|
56542
56538
|
const feedbacks = await getMetric(
|
|
56543
56539
|
feedbacks_namespace_collection,
|
|
56544
56540
|
siteId,
|
|
@@ -56597,168 +56593,1108 @@ function useNewDashboardRepo() {
|
|
|
56597
56593
|
events,
|
|
56598
56594
|
facilityBookings
|
|
56599
56595
|
};
|
|
56600
|
-
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
56601
|
-
import_node_server_utils199.logger.info(`Cache set for key: ${cacheKey}`);
|
|
56602
|
-
}).catch((err) => {
|
|
56603
|
-
import_node_server_utils199.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
56604
|
-
});
|
|
56605
56596
|
return data;
|
|
56606
56597
|
}
|
|
56607
|
-
|
|
56608
|
-
|
|
56609
|
-
|
|
56610
|
-
|
|
56598
|
+
function areaChecklistScheduleLookup(site, serviceType, createdAtRange) {
|
|
56599
|
+
return [
|
|
56600
|
+
{ $match: { serviceType } },
|
|
56601
|
+
{
|
|
56602
|
+
$lookup: {
|
|
56603
|
+
from: cleaning_schedule_namespace_collection,
|
|
56604
|
+
localField: "schedule",
|
|
56605
|
+
foreignField: "_id",
|
|
56606
|
+
as: "scheduleDoc",
|
|
56607
|
+
pipeline: [
|
|
56608
|
+
{
|
|
56609
|
+
$match: {
|
|
56610
|
+
site,
|
|
56611
|
+
serviceType,
|
|
56612
|
+
createdAt: createdAtRange
|
|
56613
|
+
}
|
|
56614
|
+
}
|
|
56615
|
+
]
|
|
56616
|
+
}
|
|
56617
|
+
},
|
|
56618
|
+
{ $unwind: { path: "$scheduleDoc", preserveNullAndEmptyArrays: false } }
|
|
56619
|
+
];
|
|
56620
|
+
}
|
|
56621
|
+
async function getServiceDashboard({
|
|
56622
|
+
site,
|
|
56623
|
+
serviceType,
|
|
56624
|
+
period = "today" /* TODAY */,
|
|
56625
|
+
type,
|
|
56626
|
+
facility
|
|
56611
56627
|
}) {
|
|
56612
|
-
|
|
56613
|
-
|
|
56614
|
-
|
|
56615
|
-
|
|
56616
|
-
};
|
|
56617
|
-
const cacheKey = (0, import_node_server_utils199.makeCacheKey)(pestDashboardCollection, cacheOptions);
|
|
56618
|
-
const cachedData = await getCache(cacheKey);
|
|
56619
|
-
if (cachedData) {
|
|
56620
|
-
import_node_server_utils199.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
56621
|
-
return cachedData;
|
|
56628
|
+
try {
|
|
56629
|
+
site = new import_mongodb121.ObjectId(site);
|
|
56630
|
+
} catch (error) {
|
|
56631
|
+
throw new import_node_server_utils199.BadRequestError("Invalid site ID format.");
|
|
56622
56632
|
}
|
|
56623
|
-
const
|
|
56624
|
-
|
|
56625
|
-
|
|
56626
|
-
|
|
56627
|
-
|
|
56628
|
-
|
|
56629
|
-
|
|
56630
|
-
|
|
56631
|
-
|
|
56632
|
-
|
|
56633
|
-
|
|
56634
|
-
|
|
56635
|
-
|
|
56633
|
+
const visitorMatchObj = {};
|
|
56634
|
+
if (type) {
|
|
56635
|
+
visitorMatchObj.type = type;
|
|
56636
|
+
}
|
|
56637
|
+
const facilityMatchObj = {};
|
|
56638
|
+
if (facility) {
|
|
56639
|
+
try {
|
|
56640
|
+
facilityMatchObj.facility = { $in: [facility, new import_mongodb121.ObjectId(facility)] };
|
|
56641
|
+
} catch (e) {
|
|
56642
|
+
facilityMatchObj.facility = facility;
|
|
56643
|
+
}
|
|
56644
|
+
}
|
|
56645
|
+
function formatEndDate(date) {
|
|
56646
|
+
if (typeof date === "string") {
|
|
56647
|
+
const dateWithoutTimezone = date.replace(/\s*\+\d{2}:\d{2}$/, "");
|
|
56648
|
+
date = new Date(dateWithoutTimezone);
|
|
56649
|
+
}
|
|
56650
|
+
const singaporeMoment = import_moment.default.tz(date, "Asia/Singapore");
|
|
56651
|
+
singaporeMoment.set({
|
|
56652
|
+
hour: 23,
|
|
56653
|
+
minute: 59,
|
|
56654
|
+
second: 59,
|
|
56655
|
+
millisecond: 999
|
|
56656
|
+
});
|
|
56657
|
+
return singaporeMoment.toDate();
|
|
56658
|
+
}
|
|
56659
|
+
function getDateRange(p) {
|
|
56660
|
+
const start = /* @__PURE__ */ new Date();
|
|
56661
|
+
start.setHours(0, 0, 0, 0);
|
|
56662
|
+
if (p === "today") {
|
|
56663
|
+
return { $gte: start, $lte: formatEndDate(start) };
|
|
56664
|
+
}
|
|
56665
|
+
const days = p === "thisWeek" ? 7 : 30;
|
|
56666
|
+
const rangeStart = /* @__PURE__ */ new Date();
|
|
56667
|
+
rangeStart.setDate(start.getDate() - days);
|
|
56668
|
+
rangeStart.setHours(0, 0, 0, 0);
|
|
56669
|
+
return { $gte: rangeStart, $lte: formatEndDate(/* @__PURE__ */ new Date()) };
|
|
56670
|
+
}
|
|
56671
|
+
const calculatePercentageChange = (currentCount, previousCount) => {
|
|
56672
|
+
if (previousCount === 0) {
|
|
56673
|
+
return currentCount > 0 ? 100 : 0;
|
|
56674
|
+
}
|
|
56675
|
+
return Math.round(
|
|
56676
|
+
(currentCount - previousCount) / previousCount * 100 * 100
|
|
56677
|
+
) / 100;
|
|
56636
56678
|
};
|
|
56637
|
-
|
|
56638
|
-
|
|
56639
|
-
|
|
56640
|
-
|
|
56641
|
-
|
|
56642
|
-
|
|
56679
|
+
const today = /* @__PURE__ */ new Date();
|
|
56680
|
+
today.setHours(0, 0, 0, 0);
|
|
56681
|
+
const yesterday = /* @__PURE__ */ new Date();
|
|
56682
|
+
yesterday.setDate(today.getDate() - 1);
|
|
56683
|
+
yesterday.setHours(0, 0, 0, 0);
|
|
56684
|
+
const yesterdayEnd = new Date(yesterday);
|
|
56685
|
+
yesterdayEnd.setHours(23, 59, 59, 999);
|
|
56686
|
+
const todayEnd = formatEndDate(/* @__PURE__ */ new Date());
|
|
56687
|
+
const periodRange = getDateRange(period);
|
|
56688
|
+
try {
|
|
56689
|
+
if (serviceType === "property_management_agency" /* PROPERTY_MANAGEMENT_AGENCY */) {
|
|
56690
|
+
const incidentCollection = db.collection(
|
|
56691
|
+
incidents_namespace_collection
|
|
56692
|
+
);
|
|
56693
|
+
const visitorCollection = db.collection(visitors_namespace_collection);
|
|
56694
|
+
const facilityCollection = db.collection(
|
|
56695
|
+
facility_bookings_namespace_collection
|
|
56696
|
+
);
|
|
56697
|
+
const [
|
|
56698
|
+
workOrderReport2,
|
|
56699
|
+
yesterdayWorkOrderReport2,
|
|
56700
|
+
todayWorkOrderReport2,
|
|
56701
|
+
incidentReport,
|
|
56702
|
+
yesterdayIncidentReport,
|
|
56703
|
+
todayIncidentReport,
|
|
56704
|
+
visitorReport,
|
|
56705
|
+
yesterdayVisitorReport,
|
|
56706
|
+
todayVisitorReport,
|
|
56707
|
+
currentlyOnSiteCount,
|
|
56708
|
+
facilityReport,
|
|
56709
|
+
yesterdayFacilityReport,
|
|
56710
|
+
todayFacilityReport
|
|
56711
|
+
] = await Promise.all([
|
|
56712
|
+
workOrderCollection.aggregate([
|
|
56713
|
+
{
|
|
56714
|
+
$match: {
|
|
56715
|
+
site,
|
|
56716
|
+
createdAt: periodRange,
|
|
56717
|
+
status: { $nin: ["completed"] }
|
|
56718
|
+
}
|
|
56719
|
+
},
|
|
56720
|
+
{
|
|
56721
|
+
$facet: {
|
|
56722
|
+
total: [{ $count: "count" }],
|
|
56723
|
+
inProgress: [
|
|
56724
|
+
{ $match: { status: "in-progress" } },
|
|
56725
|
+
{ $count: "count" }
|
|
56726
|
+
]
|
|
56727
|
+
}
|
|
56728
|
+
}
|
|
56729
|
+
]).toArray(),
|
|
56730
|
+
workOrderCollection.aggregate([
|
|
56731
|
+
{
|
|
56732
|
+
$match: {
|
|
56733
|
+
site,
|
|
56734
|
+
createdAt: { $gte: yesterday, $lte: yesterdayEnd },
|
|
56735
|
+
status: { $nin: ["completed"] }
|
|
56736
|
+
}
|
|
56737
|
+
},
|
|
56738
|
+
{ $count: "count" }
|
|
56739
|
+
]).toArray(),
|
|
56740
|
+
workOrderCollection.aggregate([
|
|
56741
|
+
{
|
|
56742
|
+
$match: {
|
|
56743
|
+
site,
|
|
56744
|
+
createdAt: { $gte: today, $lte: todayEnd },
|
|
56745
|
+
status: { $nin: ["completed"] }
|
|
56746
|
+
}
|
|
56747
|
+
},
|
|
56748
|
+
{ $count: "count" }
|
|
56749
|
+
]).toArray(),
|
|
56750
|
+
incidentCollection.aggregate([
|
|
56751
|
+
{
|
|
56752
|
+
$match: {
|
|
56753
|
+
site,
|
|
56754
|
+
status: "pending",
|
|
56755
|
+
createdAt: periodRange
|
|
56756
|
+
}
|
|
56757
|
+
},
|
|
56758
|
+
{ $count: "count" }
|
|
56759
|
+
]).toArray(),
|
|
56760
|
+
incidentCollection.aggregate([
|
|
56761
|
+
{
|
|
56762
|
+
$match: {
|
|
56763
|
+
site,
|
|
56764
|
+
status: "pending",
|
|
56765
|
+
createdAt: { $gte: yesterday, $lte: yesterdayEnd }
|
|
56766
|
+
}
|
|
56767
|
+
},
|
|
56768
|
+
{ $count: "count" }
|
|
56769
|
+
]).toArray(),
|
|
56770
|
+
incidentCollection.aggregate([
|
|
56771
|
+
{
|
|
56772
|
+
$match: {
|
|
56773
|
+
site,
|
|
56774
|
+
status: "pending",
|
|
56775
|
+
createdAt: { $gte: today, $lte: todayEnd }
|
|
56776
|
+
}
|
|
56777
|
+
},
|
|
56778
|
+
{ $count: "count" }
|
|
56779
|
+
]).toArray(),
|
|
56780
|
+
visitorCollection.aggregate([
|
|
56781
|
+
{
|
|
56782
|
+
$match: {
|
|
56783
|
+
site,
|
|
56784
|
+
...visitorMatchObj,
|
|
56785
|
+
createdAt: periodRange,
|
|
56786
|
+
status: { $ne: "deleted" }
|
|
56787
|
+
}
|
|
56788
|
+
},
|
|
56789
|
+
{ $count: "count" }
|
|
56790
|
+
]).toArray(),
|
|
56791
|
+
visitorCollection.aggregate([
|
|
56792
|
+
{
|
|
56793
|
+
$match: {
|
|
56794
|
+
site,
|
|
56795
|
+
...visitorMatchObj,
|
|
56796
|
+
createdAt: { $gte: yesterday, $lte: yesterdayEnd },
|
|
56797
|
+
status: { $ne: "deleted" }
|
|
56798
|
+
}
|
|
56799
|
+
},
|
|
56800
|
+
{ $count: "count" }
|
|
56801
|
+
]).toArray(),
|
|
56802
|
+
visitorCollection.aggregate([
|
|
56803
|
+
{
|
|
56804
|
+
$match: {
|
|
56805
|
+
site,
|
|
56806
|
+
...visitorMatchObj,
|
|
56807
|
+
createdAt: { $gte: today, $lte: todayEnd },
|
|
56808
|
+
status: { $ne: "deleted" }
|
|
56809
|
+
}
|
|
56810
|
+
},
|
|
56811
|
+
{ $count: "count" }
|
|
56812
|
+
]).toArray(),
|
|
56813
|
+
visitorCollection.countDocuments({
|
|
56814
|
+
site,
|
|
56815
|
+
...visitorMatchObj,
|
|
56816
|
+
checkIn: { $ne: null },
|
|
56817
|
+
checkOut: null,
|
|
56818
|
+
status: { $ne: "deleted" }
|
|
56819
|
+
}),
|
|
56820
|
+
facilityCollection.aggregate([
|
|
56821
|
+
{
|
|
56822
|
+
$match: {
|
|
56823
|
+
site,
|
|
56824
|
+
...facilityMatchObj,
|
|
56825
|
+
$or: [
|
|
56826
|
+
{ createdAt: periodRange },
|
|
56827
|
+
{
|
|
56828
|
+
createdAt: {
|
|
56829
|
+
$gte: periodRange.$gte.toISOString(),
|
|
56830
|
+
$lte: periodRange.$lte.toISOString()
|
|
56831
|
+
}
|
|
56832
|
+
}
|
|
56833
|
+
],
|
|
56834
|
+
status: { $nin: ["deleted", "Deleted"] }
|
|
56835
|
+
}
|
|
56836
|
+
},
|
|
56837
|
+
{
|
|
56838
|
+
$facet: {
|
|
56839
|
+
total: [{ $count: "count" }],
|
|
56840
|
+
ongoing: [
|
|
56841
|
+
{
|
|
56842
|
+
$match: {
|
|
56843
|
+
status: {
|
|
56844
|
+
$in: ["Approved", "Ongoing"]
|
|
56845
|
+
}
|
|
56846
|
+
}
|
|
56847
|
+
},
|
|
56848
|
+
{ $count: "count" }
|
|
56849
|
+
],
|
|
56850
|
+
waitingApproval: [
|
|
56851
|
+
{
|
|
56852
|
+
$match: {
|
|
56853
|
+
status: {
|
|
56854
|
+
$in: ["Pending", "For Review"]
|
|
56855
|
+
}
|
|
56856
|
+
}
|
|
56857
|
+
},
|
|
56858
|
+
{ $count: "count" }
|
|
56859
|
+
]
|
|
56860
|
+
}
|
|
56861
|
+
}
|
|
56862
|
+
]).toArray(),
|
|
56863
|
+
facilityCollection.aggregate([
|
|
56864
|
+
{
|
|
56865
|
+
$match: {
|
|
56866
|
+
site,
|
|
56867
|
+
...facilityMatchObj,
|
|
56868
|
+
$or: [
|
|
56869
|
+
{ createdAt: { $gte: yesterday, $lte: yesterdayEnd } },
|
|
56870
|
+
{
|
|
56871
|
+
createdAt: {
|
|
56872
|
+
$gte: yesterday.toISOString(),
|
|
56873
|
+
$lte: yesterdayEnd.toISOString()
|
|
56874
|
+
}
|
|
56875
|
+
}
|
|
56876
|
+
],
|
|
56877
|
+
status: { $nin: ["deleted", "Deleted"] }
|
|
56878
|
+
}
|
|
56879
|
+
},
|
|
56880
|
+
{ $count: "count" }
|
|
56881
|
+
]).toArray(),
|
|
56882
|
+
facilityCollection.aggregate([
|
|
56883
|
+
{
|
|
56884
|
+
$match: {
|
|
56885
|
+
site,
|
|
56886
|
+
...facilityMatchObj,
|
|
56887
|
+
$or: [
|
|
56888
|
+
{ createdAt: { $gte: today, $lte: todayEnd } },
|
|
56889
|
+
{
|
|
56890
|
+
createdAt: {
|
|
56891
|
+
$gte: today.toISOString(),
|
|
56892
|
+
$lte: todayEnd.toISOString()
|
|
56893
|
+
}
|
|
56894
|
+
}
|
|
56895
|
+
],
|
|
56896
|
+
status: { $nin: ["deleted", "Deleted"] }
|
|
56897
|
+
}
|
|
56898
|
+
},
|
|
56899
|
+
{ $count: "count" }
|
|
56900
|
+
]).toArray()
|
|
56901
|
+
]);
|
|
56902
|
+
const wFacet2 = workOrderReport2[0] ?? { total: [], inProgress: [] };
|
|
56903
|
+
const fFacet = facilityReport[0] ?? {
|
|
56904
|
+
total: [],
|
|
56905
|
+
ongoing: [],
|
|
56906
|
+
waitingApproval: []
|
|
56907
|
+
};
|
|
56908
|
+
const result2 = {
|
|
56909
|
+
openWorkOrder: {
|
|
56910
|
+
count: wFacet2.total[0]?.count ?? 0,
|
|
56911
|
+
inProgress: wFacet2.inProgress[0]?.count ?? 0,
|
|
56912
|
+
percentage: calculatePercentageChange(
|
|
56913
|
+
todayWorkOrderReport2[0]?.count ?? 0,
|
|
56914
|
+
yesterdayWorkOrderReport2[0]?.count ?? 0
|
|
56915
|
+
)
|
|
56916
|
+
},
|
|
56917
|
+
openIncidents: {
|
|
56918
|
+
count: incidentReport[0]?.count ?? 0,
|
|
56919
|
+
highSeverity: 0,
|
|
56920
|
+
percentage: calculatePercentageChange(
|
|
56921
|
+
todayIncidentReport[0]?.count ?? 0,
|
|
56922
|
+
yesterdayIncidentReport[0]?.count ?? 0
|
|
56923
|
+
)
|
|
56924
|
+
},
|
|
56925
|
+
visitors: {
|
|
56926
|
+
count: visitorReport[0]?.count ?? 0,
|
|
56927
|
+
currentlyOnSite: currentlyOnSiteCount,
|
|
56928
|
+
percentage: calculatePercentageChange(
|
|
56929
|
+
todayVisitorReport[0]?.count ?? 0,
|
|
56930
|
+
yesterdayVisitorReport[0]?.count ?? 0
|
|
56931
|
+
)
|
|
56932
|
+
},
|
|
56933
|
+
facilityBooking: {
|
|
56934
|
+
count: fFacet.total[0]?.count ?? 0,
|
|
56935
|
+
ongoing: fFacet.ongoing[0]?.count ?? 0,
|
|
56936
|
+
waitingApproval: fFacet.waitingApproval[0]?.count ?? 0,
|
|
56937
|
+
percentage: calculatePercentageChange(
|
|
56938
|
+
todayFacilityReport[0]?.count ?? 0,
|
|
56939
|
+
yesterdayFacilityReport[0]?.count ?? 0
|
|
56940
|
+
)
|
|
56941
|
+
}
|
|
56942
|
+
};
|
|
56943
|
+
return result2;
|
|
56944
|
+
}
|
|
56945
|
+
if (serviceType === "security_agency" /* SECURITY_AGENCY */) {
|
|
56946
|
+
const incidentCollection = db.collection(
|
|
56947
|
+
incidents_namespace_collection
|
|
56948
|
+
);
|
|
56949
|
+
const visitorCollection = db.collection(visitors_namespace_collection);
|
|
56950
|
+
const nfcPatrolLogCollection = db.collection("nfc-patrol-logs");
|
|
56951
|
+
const [
|
|
56952
|
+
workOrderReport2,
|
|
56953
|
+
yesterdayWorkOrderReport2,
|
|
56954
|
+
todayWorkOrderReport2,
|
|
56955
|
+
incidentReport,
|
|
56956
|
+
yesterdayIncidentReport,
|
|
56957
|
+
todayIncidentReport,
|
|
56958
|
+
visitorReport,
|
|
56959
|
+
yesterdayVisitorReport,
|
|
56960
|
+
todayVisitorReport,
|
|
56961
|
+
currentlyOnSiteCount,
|
|
56962
|
+
patrolReport,
|
|
56963
|
+
yesterdayPatrolReport,
|
|
56964
|
+
todayPatrolReport
|
|
56965
|
+
] = await Promise.all([
|
|
56966
|
+
workOrderCollection.aggregate([
|
|
56967
|
+
{
|
|
56968
|
+
$match: {
|
|
56969
|
+
site,
|
|
56970
|
+
service: "Security",
|
|
56971
|
+
createdAt: periodRange,
|
|
56972
|
+
status: { $nin: ["completed"] }
|
|
56973
|
+
}
|
|
56974
|
+
},
|
|
56975
|
+
{
|
|
56976
|
+
$facet: {
|
|
56977
|
+
total: [{ $count: "count" }],
|
|
56978
|
+
inProgress: [
|
|
56979
|
+
{ $match: { status: "in-progress" } },
|
|
56980
|
+
{ $count: "count" }
|
|
56981
|
+
]
|
|
56982
|
+
}
|
|
56983
|
+
}
|
|
56984
|
+
]).toArray(),
|
|
56985
|
+
workOrderCollection.aggregate([
|
|
56986
|
+
{
|
|
56987
|
+
$match: {
|
|
56988
|
+
site,
|
|
56989
|
+
service: "Security",
|
|
56990
|
+
createdAt: { $gte: yesterday, $lte: yesterdayEnd },
|
|
56991
|
+
status: { $nin: ["completed"] }
|
|
56992
|
+
}
|
|
56993
|
+
},
|
|
56994
|
+
{ $count: "count" }
|
|
56995
|
+
]).toArray(),
|
|
56996
|
+
workOrderCollection.aggregate([
|
|
56997
|
+
{
|
|
56998
|
+
$match: {
|
|
56999
|
+
site,
|
|
57000
|
+
service: "Security",
|
|
57001
|
+
createdAt: { $gte: today, $lte: todayEnd },
|
|
57002
|
+
status: { $nin: ["completed"] }
|
|
57003
|
+
}
|
|
57004
|
+
},
|
|
57005
|
+
{ $count: "count" }
|
|
57006
|
+
]).toArray(),
|
|
57007
|
+
incidentCollection.aggregate([
|
|
57008
|
+
{
|
|
57009
|
+
$match: {
|
|
57010
|
+
site,
|
|
57011
|
+
status: "pending",
|
|
57012
|
+
createdAt: periodRange
|
|
57013
|
+
}
|
|
57014
|
+
},
|
|
57015
|
+
{ $count: "count" }
|
|
57016
|
+
]).toArray(),
|
|
57017
|
+
incidentCollection.aggregate([
|
|
57018
|
+
{
|
|
57019
|
+
$match: {
|
|
57020
|
+
site,
|
|
57021
|
+
status: "pending",
|
|
57022
|
+
createdAt: { $gte: yesterday, $lte: yesterdayEnd }
|
|
57023
|
+
}
|
|
57024
|
+
},
|
|
57025
|
+
{ $count: "count" }
|
|
57026
|
+
]).toArray(),
|
|
57027
|
+
incidentCollection.aggregate([
|
|
57028
|
+
{
|
|
57029
|
+
$match: {
|
|
57030
|
+
site,
|
|
57031
|
+
status: "pending",
|
|
57032
|
+
createdAt: { $gte: today, $lte: todayEnd }
|
|
57033
|
+
}
|
|
57034
|
+
},
|
|
57035
|
+
{ $count: "count" }
|
|
57036
|
+
]).toArray(),
|
|
57037
|
+
visitorCollection.aggregate([
|
|
57038
|
+
{
|
|
57039
|
+
$match: {
|
|
57040
|
+
site,
|
|
57041
|
+
...visitorMatchObj,
|
|
57042
|
+
createdAt: periodRange,
|
|
57043
|
+
status: { $ne: "deleted" }
|
|
57044
|
+
}
|
|
57045
|
+
},
|
|
57046
|
+
{ $count: "count" }
|
|
57047
|
+
]).toArray(),
|
|
57048
|
+
visitorCollection.aggregate([
|
|
57049
|
+
{
|
|
57050
|
+
$match: {
|
|
57051
|
+
site,
|
|
57052
|
+
...visitorMatchObj,
|
|
57053
|
+
createdAt: { $gte: yesterday, $lte: yesterdayEnd },
|
|
57054
|
+
status: { $ne: "deleted" }
|
|
57055
|
+
}
|
|
57056
|
+
},
|
|
57057
|
+
{ $count: "count" }
|
|
57058
|
+
]).toArray(),
|
|
57059
|
+
visitorCollection.aggregate([
|
|
57060
|
+
{
|
|
57061
|
+
$match: {
|
|
57062
|
+
site,
|
|
57063
|
+
...visitorMatchObj,
|
|
57064
|
+
createdAt: { $gte: today, $lte: todayEnd },
|
|
57065
|
+
status: { $ne: "deleted" }
|
|
57066
|
+
}
|
|
57067
|
+
},
|
|
57068
|
+
{ $count: "count" }
|
|
57069
|
+
]).toArray(),
|
|
57070
|
+
visitorCollection.countDocuments({
|
|
57071
|
+
site,
|
|
57072
|
+
...visitorMatchObj,
|
|
57073
|
+
checkIn: { $ne: null },
|
|
57074
|
+
checkOut: null,
|
|
57075
|
+
status: { $ne: "deleted" }
|
|
57076
|
+
}),
|
|
57077
|
+
nfcPatrolLogCollection.aggregate([
|
|
57078
|
+
{
|
|
57079
|
+
$match: {
|
|
57080
|
+
site,
|
|
57081
|
+
createdAt: periodRange
|
|
57082
|
+
}
|
|
57083
|
+
},
|
|
57084
|
+
{
|
|
57085
|
+
$unwind: "$checkPoints"
|
|
57086
|
+
},
|
|
57087
|
+
{
|
|
57088
|
+
$facet: {
|
|
57089
|
+
total: [{ $count: "count" }],
|
|
57090
|
+
completed: [
|
|
57091
|
+
{ $match: { "checkPoints.status": "Completed" } },
|
|
57092
|
+
{ $count: "count" }
|
|
57093
|
+
],
|
|
57094
|
+
skipped: [
|
|
57095
|
+
{ $match: { "checkPoints.status": "Skipped" } },
|
|
57096
|
+
{ $count: "count" }
|
|
57097
|
+
]
|
|
57098
|
+
}
|
|
57099
|
+
}
|
|
57100
|
+
]).toArray(),
|
|
57101
|
+
nfcPatrolLogCollection.aggregate([
|
|
57102
|
+
{
|
|
57103
|
+
$match: {
|
|
57104
|
+
site,
|
|
57105
|
+
createdAt: { $gte: yesterday, $lte: yesterdayEnd }
|
|
57106
|
+
}
|
|
57107
|
+
},
|
|
57108
|
+
{
|
|
57109
|
+
$unwind: "$checkPoints"
|
|
57110
|
+
},
|
|
57111
|
+
{
|
|
57112
|
+
$facet: {
|
|
57113
|
+
total: [{ $count: "count" }],
|
|
57114
|
+
completed: [
|
|
57115
|
+
{ $match: { "checkPoints.status": "Completed" } },
|
|
57116
|
+
{ $count: "count" }
|
|
57117
|
+
],
|
|
57118
|
+
skipped: [
|
|
57119
|
+
{ $match: { "checkPoints.status": "Skipped" } },
|
|
57120
|
+
{ $count: "count" }
|
|
57121
|
+
]
|
|
57122
|
+
}
|
|
57123
|
+
}
|
|
57124
|
+
]).toArray(),
|
|
57125
|
+
nfcPatrolLogCollection.aggregate([
|
|
57126
|
+
{
|
|
57127
|
+
$match: {
|
|
57128
|
+
site,
|
|
57129
|
+
createdAt: { $gte: today, $lte: todayEnd }
|
|
57130
|
+
}
|
|
57131
|
+
},
|
|
57132
|
+
{
|
|
57133
|
+
$unwind: "$checkPoints"
|
|
57134
|
+
},
|
|
57135
|
+
{
|
|
57136
|
+
$facet: {
|
|
57137
|
+
total: [{ $count: "count" }],
|
|
57138
|
+
completed: [
|
|
57139
|
+
{ $match: { "checkPoints.status": "Completed" } },
|
|
57140
|
+
{ $count: "count" }
|
|
57141
|
+
],
|
|
57142
|
+
skipped: [
|
|
57143
|
+
{ $match: { "checkPoints.status": "Skipped" } },
|
|
57144
|
+
{ $count: "count" }
|
|
57145
|
+
]
|
|
57146
|
+
}
|
|
57147
|
+
}
|
|
57148
|
+
]).toArray()
|
|
57149
|
+
]);
|
|
57150
|
+
const wFacet2 = workOrderReport2[0] ?? { total: [], inProgress: [] };
|
|
57151
|
+
const pFacet = patrolReport[0] ?? {
|
|
57152
|
+
total: [],
|
|
57153
|
+
completed: [],
|
|
57154
|
+
skipped: []
|
|
57155
|
+
};
|
|
57156
|
+
const totalCheckpoints = pFacet.total[0]?.count ?? 0;
|
|
57157
|
+
const completedCheckpoints = pFacet.completed[0]?.count ?? 0;
|
|
57158
|
+
const skippedCheckpoints = pFacet.skipped[0]?.count ?? 0;
|
|
57159
|
+
const complianceRate = totalCheckpoints > 0 ? Math.round(
|
|
57160
|
+
completedCheckpoints / totalCheckpoints * 100 * 100
|
|
57161
|
+
) / 100 : 100;
|
|
57162
|
+
const yPatrolFacet = yesterdayPatrolReport[0] ?? {
|
|
57163
|
+
total: [],
|
|
57164
|
+
completed: []
|
|
57165
|
+
};
|
|
57166
|
+
const yTotal = yPatrolFacet.total[0]?.count ?? 0;
|
|
57167
|
+
const yCompleted = yPatrolFacet.completed[0]?.count ?? 0;
|
|
57168
|
+
const yesterdayCompliance = yTotal > 0 ? yCompleted / yTotal * 100 : 0;
|
|
57169
|
+
const tPatrolFacet = todayPatrolReport[0] ?? {
|
|
57170
|
+
total: [],
|
|
57171
|
+
completed: []
|
|
57172
|
+
};
|
|
57173
|
+
const tTotal = tPatrolFacet.total[0]?.count ?? 0;
|
|
57174
|
+
const tCompleted = tPatrolFacet.completed[0]?.count ?? 0;
|
|
57175
|
+
const todayCompliance = tTotal > 0 ? tCompleted / tTotal * 100 : 0;
|
|
57176
|
+
const result2 = {
|
|
57177
|
+
openWorkOrder: {
|
|
57178
|
+
count: wFacet2.total[0]?.count ?? 0,
|
|
57179
|
+
inProgress: wFacet2.inProgress[0]?.count ?? 0,
|
|
57180
|
+
percentage: calculatePercentageChange(
|
|
57181
|
+
todayWorkOrderReport2[0]?.count ?? 0,
|
|
57182
|
+
yesterdayWorkOrderReport2[0]?.count ?? 0
|
|
57183
|
+
)
|
|
57184
|
+
},
|
|
57185
|
+
openIncidents: {
|
|
57186
|
+
count: incidentReport[0]?.count ?? 0,
|
|
57187
|
+
highSeverity: 0,
|
|
57188
|
+
percentage: calculatePercentageChange(
|
|
57189
|
+
todayIncidentReport[0]?.count ?? 0,
|
|
57190
|
+
yesterdayIncidentReport[0]?.count ?? 0
|
|
57191
|
+
)
|
|
57192
|
+
},
|
|
57193
|
+
visitors: {
|
|
57194
|
+
count: visitorReport[0]?.count ?? 0,
|
|
57195
|
+
currentlyOnSite: currentlyOnSiteCount,
|
|
57196
|
+
percentage: calculatePercentageChange(
|
|
57197
|
+
todayVisitorReport[0]?.count ?? 0,
|
|
57198
|
+
yesterdayVisitorReport[0]?.count ?? 0
|
|
57199
|
+
)
|
|
57200
|
+
},
|
|
57201
|
+
patrolCompliance: {
|
|
57202
|
+
count: complianceRate,
|
|
57203
|
+
missedCheckpoints: skippedCheckpoints,
|
|
57204
|
+
missed: skippedCheckpoints,
|
|
57205
|
+
percentage: calculatePercentageChange(
|
|
57206
|
+
todayCompliance,
|
|
57207
|
+
yesterdayCompliance
|
|
57208
|
+
)
|
|
57209
|
+
}
|
|
57210
|
+
};
|
|
57211
|
+
return result2;
|
|
57212
|
+
}
|
|
57213
|
+
const workOrderService = workOrderServiceMap[serviceType] ?? serviceType;
|
|
57214
|
+
const [
|
|
57215
|
+
workOrderReport,
|
|
57216
|
+
supplyAlertReport,
|
|
57217
|
+
taskCompletedReport,
|
|
57218
|
+
yesterdayWorkOrderReport,
|
|
57219
|
+
todayWorkOrderReport,
|
|
57220
|
+
yesterdayTaskCompletedReport,
|
|
57221
|
+
todayTaskCompletedReport
|
|
57222
|
+
] = await Promise.all([
|
|
57223
|
+
workOrderCollection.aggregate([
|
|
57224
|
+
{
|
|
57225
|
+
$match: {
|
|
57226
|
+
site,
|
|
57227
|
+
service: workOrderService,
|
|
57228
|
+
createdAt: periodRange,
|
|
57229
|
+
status: { $nin: ["completed"] }
|
|
57230
|
+
}
|
|
57231
|
+
},
|
|
57232
|
+
{
|
|
57233
|
+
$facet: {
|
|
57234
|
+
total: [{ $count: "count" }],
|
|
57235
|
+
inProgress: [
|
|
57236
|
+
{ $match: { status: "in-progress" } },
|
|
57237
|
+
{ $count: "count" }
|
|
57238
|
+
]
|
|
57239
|
+
}
|
|
57240
|
+
}
|
|
57241
|
+
]).toArray(),
|
|
57242
|
+
supplyCollection.aggregate([
|
|
57243
|
+
{ $match: { site, serviceType, status: "active" } },
|
|
57244
|
+
{ $sort: { qty: 1 } },
|
|
57245
|
+
{ $limit: 3 },
|
|
57246
|
+
{ $project: { _id: 1, name: 1, qty: 1 } }
|
|
57247
|
+
]).toArray(),
|
|
57248
|
+
areaChecklistCollection.aggregate([
|
|
57249
|
+
...areaChecklistScheduleLookup(site, serviceType, periodRange),
|
|
57250
|
+
{
|
|
57251
|
+
$facet: {
|
|
57252
|
+
total: [{ $count: "count" }],
|
|
57253
|
+
completed: [
|
|
57254
|
+
{ $match: { status: "completed" } },
|
|
57255
|
+
{ $count: "count" }
|
|
57256
|
+
],
|
|
57257
|
+
inProgress: [
|
|
57258
|
+
{ $match: { status: { $in: ["open", "ongoing"] } } },
|
|
57259
|
+
{ $count: "count" }
|
|
57260
|
+
]
|
|
57261
|
+
}
|
|
57262
|
+
}
|
|
57263
|
+
]).toArray(),
|
|
57264
|
+
workOrderCollection.aggregate([
|
|
57265
|
+
{
|
|
57266
|
+
$match: {
|
|
57267
|
+
site,
|
|
57268
|
+
service: workOrderService,
|
|
57269
|
+
createdAt: { $gte: yesterday, $lte: yesterdayEnd },
|
|
57270
|
+
status: { $nin: ["completed"] }
|
|
57271
|
+
}
|
|
57272
|
+
},
|
|
57273
|
+
{ $count: "count" }
|
|
57274
|
+
]).toArray(),
|
|
57275
|
+
workOrderCollection.aggregate([
|
|
57276
|
+
{
|
|
57277
|
+
$match: {
|
|
57278
|
+
site,
|
|
57279
|
+
service: workOrderService,
|
|
57280
|
+
createdAt: { $gte: today, $lte: todayEnd },
|
|
57281
|
+
status: { $nin: ["completed"] }
|
|
57282
|
+
}
|
|
57283
|
+
},
|
|
57284
|
+
{ $count: "count" }
|
|
57285
|
+
]).toArray(),
|
|
57286
|
+
areaChecklistCollection.aggregate([
|
|
57287
|
+
...areaChecklistScheduleLookup(site, serviceType, {
|
|
57288
|
+
$gte: yesterday,
|
|
57289
|
+
$lte: yesterdayEnd
|
|
57290
|
+
}),
|
|
57291
|
+
{ $match: { status: "completed" } },
|
|
57292
|
+
{ $count: "count" }
|
|
57293
|
+
]).toArray(),
|
|
57294
|
+
areaChecklistCollection.aggregate([
|
|
57295
|
+
...areaChecklistScheduleLookup(site, serviceType, {
|
|
57296
|
+
$gte: today,
|
|
57297
|
+
$lte: todayEnd
|
|
57298
|
+
}),
|
|
57299
|
+
{ $match: { status: "completed" } },
|
|
57300
|
+
{ $count: "count" }
|
|
57301
|
+
]).toArray()
|
|
57302
|
+
]);
|
|
57303
|
+
const wFacet = workOrderReport[0] ?? { total: [], inProgress: [] };
|
|
57304
|
+
const tFacet = taskCompletedReport[0] ?? {
|
|
57305
|
+
total: [],
|
|
57306
|
+
completed: [],
|
|
57307
|
+
inProgress: []
|
|
57308
|
+
};
|
|
57309
|
+
const result = {
|
|
57310
|
+
openWorkOrder: {
|
|
57311
|
+
count: wFacet.total[0]?.count ?? 0,
|
|
57312
|
+
inProgress: wFacet.inProgress[0]?.count ?? 0,
|
|
57313
|
+
percentage: calculatePercentageChange(
|
|
57314
|
+
todayWorkOrderReport[0]?.count ?? 0,
|
|
57315
|
+
yesterdayWorkOrderReport[0]?.count ?? 0
|
|
57316
|
+
)
|
|
57317
|
+
},
|
|
57318
|
+
supplyAlert: {
|
|
57319
|
+
items: supplyAlertReport.map((item) => ({
|
|
57320
|
+
name: item.name,
|
|
57321
|
+
qty: item.qty
|
|
57322
|
+
}))
|
|
57323
|
+
},
|
|
57324
|
+
taskCompleted: {
|
|
57325
|
+
completed: tFacet.completed[0]?.count ?? 0,
|
|
57326
|
+
total: tFacet.total[0]?.count ?? 0,
|
|
57327
|
+
inProgress: tFacet.inProgress[0]?.count ?? 0,
|
|
57328
|
+
percentage: calculatePercentageChange(
|
|
57329
|
+
todayTaskCompletedReport[0]?.count ?? 0,
|
|
57330
|
+
yesterdayTaskCompletedReport[0]?.count ?? 0
|
|
57331
|
+
)
|
|
57332
|
+
}
|
|
57333
|
+
};
|
|
57334
|
+
return result;
|
|
57335
|
+
} catch (error) {
|
|
57336
|
+
throw error;
|
|
57337
|
+
}
|
|
56643
57338
|
}
|
|
56644
|
-
async function
|
|
56645
|
-
|
|
56646
|
-
|
|
56647
|
-
|
|
57339
|
+
async function getServiceWeeklyActivity({
|
|
57340
|
+
site,
|
|
57341
|
+
serviceType,
|
|
57342
|
+
period = "today" /* TODAY */
|
|
56648
57343
|
}) {
|
|
56649
|
-
const cacheOptions = {
|
|
56650
|
-
|
|
56651
|
-
|
|
56652
|
-
|
|
56653
|
-
}
|
|
56654
|
-
|
|
56655
|
-
|
|
56656
|
-
|
|
56657
|
-
|
|
56658
|
-
|
|
57344
|
+
const cacheOptions = { serviceType, period };
|
|
57345
|
+
try {
|
|
57346
|
+
site = new import_mongodb121.ObjectId(site);
|
|
57347
|
+
cacheOptions.site = site.toString();
|
|
57348
|
+
} catch {
|
|
57349
|
+
throw new import_node_server_utils199.BadRequestError("Invalid site ID format.");
|
|
57350
|
+
}
|
|
57351
|
+
const workOrderService = workOrderServiceMap[serviceType] ?? serviceType;
|
|
57352
|
+
let rangeStart;
|
|
57353
|
+
let rangeEnd;
|
|
57354
|
+
let labels = [];
|
|
57355
|
+
let getIntervalIndex;
|
|
57356
|
+
if (period === "today" /* TODAY */) {
|
|
57357
|
+
rangeStart = import_moment.default.tz("Asia/Singapore").startOf("day").toDate();
|
|
57358
|
+
rangeEnd = import_moment.default.tz("Asia/Singapore").endOf("day").toDate();
|
|
57359
|
+
labels = ["12 AM", "4 AM", "8 AM", "12 PM", "4 PM", "8 PM"];
|
|
57360
|
+
getIntervalIndex = (date) => {
|
|
57361
|
+
const hour = (0, import_moment.default)(date).tz("Asia/Singapore").hour();
|
|
57362
|
+
return Math.floor(hour / 4);
|
|
57363
|
+
};
|
|
57364
|
+
} else if (period === "thisWeek" /* THIS_WEEK */) {
|
|
57365
|
+
rangeStart = import_moment.default.tz("Asia/Singapore").startOf("isoWeek").toDate();
|
|
57366
|
+
rangeEnd = import_moment.default.tz("Asia/Singapore").endOf("isoWeek").toDate();
|
|
57367
|
+
labels = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
|
|
57368
|
+
getIntervalIndex = (date) => {
|
|
57369
|
+
const day = (0, import_moment.default)(date).tz("Asia/Singapore").isoWeekday();
|
|
57370
|
+
return day - 1;
|
|
57371
|
+
};
|
|
57372
|
+
} else if (period === "thisMonth" /* THIS_MONTH */) {
|
|
57373
|
+
rangeStart = import_moment.default.tz("Asia/Singapore").startOf("month").toDate();
|
|
57374
|
+
rangeEnd = import_moment.default.tz("Asia/Singapore").endOf("month").toDate();
|
|
57375
|
+
const daysInMonth = import_moment.default.tz("Asia/Singapore").daysInMonth();
|
|
57376
|
+
labels = Array.from({ length: daysInMonth }, (_, i) => String(i + 1));
|
|
57377
|
+
getIntervalIndex = (date) => {
|
|
57378
|
+
return (0, import_moment.default)(date).tz("Asia/Singapore").date() - 1;
|
|
57379
|
+
};
|
|
57380
|
+
} else {
|
|
57381
|
+
throw new import_node_server_utils199.BadRequestError("Invalid period.");
|
|
57382
|
+
}
|
|
57383
|
+
try {
|
|
57384
|
+
const workOrders = await workOrderCollection.find({
|
|
57385
|
+
site,
|
|
57386
|
+
service: workOrderService,
|
|
57387
|
+
status: { $nin: ["deleted", "Deleted"] },
|
|
57388
|
+
$or: [
|
|
57389
|
+
{ createdAt: { $gte: rangeStart, $lte: rangeEnd } },
|
|
57390
|
+
{
|
|
57391
|
+
createdAt: {
|
|
57392
|
+
$gte: rangeStart.toISOString(),
|
|
57393
|
+
$lte: rangeEnd.toISOString()
|
|
57394
|
+
}
|
|
57395
|
+
}
|
|
57396
|
+
]
|
|
57397
|
+
}).project({ status: 1, createdAt: 1 }).toArray();
|
|
57398
|
+
const chartData = labels.map((label) => ({
|
|
57399
|
+
day: label,
|
|
57400
|
+
label,
|
|
57401
|
+
openWorkOrder: 0,
|
|
57402
|
+
closedWorkOrder: 0,
|
|
57403
|
+
workOrder: 0,
|
|
57404
|
+
taskCompleted: 0
|
|
57405
|
+
}));
|
|
57406
|
+
for (const wo of workOrders) {
|
|
57407
|
+
const dateVal = wo.createdAt instanceof Date ? wo.createdAt : new Date(wo.createdAt);
|
|
57408
|
+
const index = getIntervalIndex(dateVal);
|
|
57409
|
+
if (index >= 0 && index < chartData.length) {
|
|
57410
|
+
const isCompleted = wo.status === "completed" || wo.status === "Completed";
|
|
57411
|
+
if (isCompleted) {
|
|
57412
|
+
chartData[index].closedWorkOrder++;
|
|
57413
|
+
chartData[index].taskCompleted++;
|
|
57414
|
+
} else {
|
|
57415
|
+
chartData[index].openWorkOrder++;
|
|
57416
|
+
chartData[index].workOrder++;
|
|
57417
|
+
}
|
|
57418
|
+
}
|
|
57419
|
+
}
|
|
57420
|
+
return chartData;
|
|
57421
|
+
} catch (error) {
|
|
57422
|
+
throw error;
|
|
56659
57423
|
}
|
|
56660
|
-
const feedbacks = await getMetric(
|
|
56661
|
-
feedbacks_namespace_collection,
|
|
56662
|
-
siteId,
|
|
56663
|
-
feedback
|
|
56664
|
-
);
|
|
56665
|
-
const workOrders = await getMetric(
|
|
56666
|
-
work_orders_namespace_collection,
|
|
56667
|
-
siteId,
|
|
56668
|
-
workOrder
|
|
56669
|
-
);
|
|
56670
|
-
const data = {
|
|
56671
|
-
feedbacks,
|
|
56672
|
-
workOrders
|
|
56673
|
-
};
|
|
56674
|
-
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
56675
|
-
import_node_server_utils199.logger.info(`Cache set for key: ${cacheKey}`);
|
|
56676
|
-
}).catch((err) => {
|
|
56677
|
-
import_node_server_utils199.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
56678
|
-
});
|
|
56679
|
-
return data;
|
|
56680
57424
|
}
|
|
56681
|
-
async function
|
|
56682
|
-
|
|
56683
|
-
|
|
56684
|
-
|
|
57425
|
+
async function getServiceTodayTaskSchedule({
|
|
57426
|
+
site,
|
|
57427
|
+
serviceType,
|
|
57428
|
+
page = 1,
|
|
57429
|
+
limit = 10
|
|
56685
57430
|
}) {
|
|
56686
|
-
|
|
56687
|
-
|
|
56688
|
-
|
|
56689
|
-
|
|
56690
|
-
|
|
56691
|
-
|
|
56692
|
-
|
|
56693
|
-
|
|
56694
|
-
|
|
56695
|
-
|
|
57431
|
+
page = page > 0 ? page - 1 : 0;
|
|
57432
|
+
const cacheOptions = { serviceType, page, limit };
|
|
57433
|
+
try {
|
|
57434
|
+
site = new import_mongodb121.ObjectId(site);
|
|
57435
|
+
cacheOptions.site = site.toString();
|
|
57436
|
+
} catch {
|
|
57437
|
+
throw new import_node_server_utils199.BadRequestError("Invalid site ID format.");
|
|
57438
|
+
}
|
|
57439
|
+
const todayStart = import_moment.default.tz("Asia/Singapore").startOf("day").toDate();
|
|
57440
|
+
const todayEnd = import_moment.default.tz("Asia/Singapore").endOf("day").toDate();
|
|
57441
|
+
const todayRange = { $gte: todayStart, $lte: todayEnd };
|
|
57442
|
+
try {
|
|
57443
|
+
const [items, countResult] = await Promise.all([
|
|
57444
|
+
areaChecklistCollection.aggregate([
|
|
57445
|
+
...areaChecklistScheduleLookup(site, serviceType, todayRange),
|
|
57446
|
+
{
|
|
57447
|
+
$addFields: {
|
|
57448
|
+
_assigneeId: {
|
|
57449
|
+
$reduce: {
|
|
57450
|
+
input: { $ifNull: ["$checklist", []] },
|
|
57451
|
+
initialValue: null,
|
|
57452
|
+
in: {
|
|
57453
|
+
$cond: {
|
|
57454
|
+
if: { $ne: ["$$value", null] },
|
|
57455
|
+
then: "$$value",
|
|
57456
|
+
else: {
|
|
57457
|
+
$reduce: {
|
|
57458
|
+
input: { $ifNull: ["$$this.units", []] },
|
|
57459
|
+
initialValue: null,
|
|
57460
|
+
in: {
|
|
57461
|
+
$cond: {
|
|
57462
|
+
if: { $ne: ["$$value", null] },
|
|
57463
|
+
then: "$$value",
|
|
57464
|
+
else: {
|
|
57465
|
+
$cond: {
|
|
57466
|
+
if: { $gt: ["$$this.completedBy", null] },
|
|
57467
|
+
then: "$$this.completedBy",
|
|
57468
|
+
else: null
|
|
57469
|
+
}
|
|
57470
|
+
}
|
|
57471
|
+
}
|
|
57472
|
+
}
|
|
57473
|
+
}
|
|
57474
|
+
}
|
|
57475
|
+
}
|
|
57476
|
+
}
|
|
57477
|
+
}
|
|
57478
|
+
}
|
|
57479
|
+
}
|
|
57480
|
+
},
|
|
57481
|
+
{
|
|
57482
|
+
$lookup: {
|
|
57483
|
+
from: "users",
|
|
57484
|
+
localField: "_assigneeId",
|
|
57485
|
+
foreignField: "_id",
|
|
57486
|
+
as: "_assigneeDoc"
|
|
57487
|
+
}
|
|
57488
|
+
},
|
|
57489
|
+
{ $sort: { createdAt: -1, _id: -1 } },
|
|
57490
|
+
{
|
|
57491
|
+
$project: {
|
|
57492
|
+
name: 1,
|
|
57493
|
+
type: 1,
|
|
57494
|
+
status: 1,
|
|
57495
|
+
assigneeName: { $arrayElemAt: ["$_assigneeDoc.name", 0] }
|
|
57496
|
+
}
|
|
57497
|
+
},
|
|
57498
|
+
{ $skip: page * limit },
|
|
57499
|
+
{ $limit: limit }
|
|
57500
|
+
]).toArray(),
|
|
57501
|
+
areaChecklistCollection.aggregate([
|
|
57502
|
+
...areaChecklistScheduleLookup(site, serviceType, todayRange),
|
|
57503
|
+
{ $count: "count" }
|
|
57504
|
+
]).toArray()
|
|
57505
|
+
]);
|
|
57506
|
+
const length = countResult[0]?.count ?? 0;
|
|
57507
|
+
const data = (0, import_node_server_utils199.paginate)(items, page, limit, length);
|
|
57508
|
+
return data;
|
|
57509
|
+
} catch (error) {
|
|
57510
|
+
throw error;
|
|
56696
57511
|
}
|
|
56697
|
-
const feedbacks = await getMetric(
|
|
56698
|
-
feedbacks_namespace_collection,
|
|
56699
|
-
siteId,
|
|
56700
|
-
feedback
|
|
56701
|
-
);
|
|
56702
|
-
const workOrders = await getMetric(
|
|
56703
|
-
work_orders_namespace_collection,
|
|
56704
|
-
siteId,
|
|
56705
|
-
workOrder
|
|
56706
|
-
);
|
|
56707
|
-
const data = {
|
|
56708
|
-
feedbacks,
|
|
56709
|
-
workOrders
|
|
56710
|
-
};
|
|
56711
|
-
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
56712
|
-
import_node_server_utils199.logger.info(`Cache set for key: ${cacheKey}`);
|
|
56713
|
-
}).catch((err) => {
|
|
56714
|
-
import_node_server_utils199.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
56715
|
-
});
|
|
56716
|
-
return data;
|
|
56717
57512
|
}
|
|
56718
|
-
async function
|
|
56719
|
-
|
|
56720
|
-
|
|
56721
|
-
|
|
57513
|
+
async function getServiceStaffAttendance({
|
|
57514
|
+
site,
|
|
57515
|
+
serviceType,
|
|
57516
|
+
page = 1,
|
|
57517
|
+
limit = 10
|
|
56722
57518
|
}) {
|
|
56723
|
-
|
|
56724
|
-
|
|
56725
|
-
|
|
56726
|
-
|
|
56727
|
-
|
|
56728
|
-
|
|
56729
|
-
|
|
56730
|
-
|
|
56731
|
-
|
|
56732
|
-
|
|
57519
|
+
page = page > 0 ? page - 1 : 0;
|
|
57520
|
+
const cacheOptions = { serviceType, page, limit };
|
|
57521
|
+
try {
|
|
57522
|
+
site = new import_mongodb121.ObjectId(site);
|
|
57523
|
+
cacheOptions.site = site.toString();
|
|
57524
|
+
} catch {
|
|
57525
|
+
throw new import_node_server_utils199.BadRequestError("Invalid site ID format.");
|
|
57526
|
+
}
|
|
57527
|
+
const todayStart = import_moment.default.tz("Asia/Singapore").startOf("day").toDate();
|
|
57528
|
+
const todayEnd = import_moment.default.tz("Asia/Singapore").endOf("day").toDate();
|
|
57529
|
+
const todayStartStr = todayStart.toISOString();
|
|
57530
|
+
const todayEndStr = todayEnd.toISOString();
|
|
57531
|
+
try {
|
|
57532
|
+
const [items, length] = await Promise.all([
|
|
57533
|
+
attendanceCollection.aggregate([
|
|
57534
|
+
{
|
|
57535
|
+
$match: {
|
|
57536
|
+
site,
|
|
57537
|
+
serviceType,
|
|
57538
|
+
$or: [
|
|
57539
|
+
{ createdAt: { $gte: todayStart, $lte: todayEnd } },
|
|
57540
|
+
{ createdAt: { $gte: todayStartStr, $lte: todayEndStr } }
|
|
57541
|
+
]
|
|
57542
|
+
}
|
|
57543
|
+
},
|
|
57544
|
+
{
|
|
57545
|
+
$lookup: {
|
|
57546
|
+
from: "users",
|
|
57547
|
+
localField: "user",
|
|
57548
|
+
foreignField: "_id",
|
|
57549
|
+
as: "_userDoc"
|
|
57550
|
+
}
|
|
57551
|
+
},
|
|
57552
|
+
{
|
|
57553
|
+
$lookup: {
|
|
57554
|
+
from: "members",
|
|
57555
|
+
let: { userId: "$user", siteId: "$site", type: "$serviceType" },
|
|
57556
|
+
pipeline: [
|
|
57557
|
+
{
|
|
57558
|
+
$match: {
|
|
57559
|
+
$expr: {
|
|
57560
|
+
$and: [
|
|
57561
|
+
{ $eq: ["$user", "$$userId"] },
|
|
57562
|
+
{ $eq: ["$siteId", "$$siteId"] },
|
|
57563
|
+
{ $eq: ["$type", "$$type"] },
|
|
57564
|
+
{ $ne: ["$status", "deleted"] }
|
|
57565
|
+
]
|
|
57566
|
+
}
|
|
57567
|
+
}
|
|
57568
|
+
}
|
|
57569
|
+
],
|
|
57570
|
+
as: "_memberDoc"
|
|
57571
|
+
}
|
|
57572
|
+
},
|
|
57573
|
+
{
|
|
57574
|
+
$unwind: {
|
|
57575
|
+
path: "$_memberDoc",
|
|
57576
|
+
preserveNullAndEmptyArrays: true
|
|
57577
|
+
}
|
|
57578
|
+
},
|
|
57579
|
+
{
|
|
57580
|
+
$lookup: {
|
|
57581
|
+
from: "roles",
|
|
57582
|
+
localField: "_memberDoc.role",
|
|
57583
|
+
foreignField: "_id",
|
|
57584
|
+
as: "_roleDoc"
|
|
57585
|
+
}
|
|
57586
|
+
},
|
|
57587
|
+
{
|
|
57588
|
+
$unwind: {
|
|
57589
|
+
path: "$_roleDoc",
|
|
57590
|
+
preserveNullAndEmptyArrays: true
|
|
57591
|
+
}
|
|
57592
|
+
},
|
|
57593
|
+
{ $sort: { createdAt: -1, _id: -1 } },
|
|
57594
|
+
{
|
|
57595
|
+
$project: {
|
|
57596
|
+
checkIn: 1,
|
|
57597
|
+
checkOut: 1,
|
|
57598
|
+
createdAt: 1,
|
|
57599
|
+
userName: { $arrayElemAt: ["$_userDoc.name", 0] },
|
|
57600
|
+
userRole: { $ifNull: ["$_roleDoc.name", ""] },
|
|
57601
|
+
totalHours: {
|
|
57602
|
+
$round: [
|
|
57603
|
+
{
|
|
57604
|
+
$divide: [
|
|
57605
|
+
{
|
|
57606
|
+
$subtract: [
|
|
57607
|
+
{
|
|
57608
|
+
$toDate: {
|
|
57609
|
+
$ifNull: ["$checkOut.timestamp", "$$NOW"]
|
|
57610
|
+
}
|
|
57611
|
+
},
|
|
57612
|
+
{ $toDate: "$checkIn.timestamp" }
|
|
57613
|
+
]
|
|
57614
|
+
},
|
|
57615
|
+
36e5
|
|
57616
|
+
]
|
|
57617
|
+
},
|
|
57618
|
+
2
|
|
57619
|
+
]
|
|
57620
|
+
}
|
|
57621
|
+
}
|
|
57622
|
+
},
|
|
57623
|
+
{ $skip: page * limit },
|
|
57624
|
+
{ $limit: limit }
|
|
57625
|
+
]).toArray(),
|
|
57626
|
+
attendanceCollection.countDocuments({
|
|
57627
|
+
site,
|
|
57628
|
+
serviceType,
|
|
57629
|
+
$or: [
|
|
57630
|
+
{ createdAt: { $gte: todayStart, $lte: todayEnd } },
|
|
57631
|
+
{ createdAt: { $gte: todayStartStr, $lte: todayEndStr } }
|
|
57632
|
+
]
|
|
57633
|
+
})
|
|
57634
|
+
]);
|
|
57635
|
+
const data = (0, import_node_server_utils199.paginate)(items, page, limit, length);
|
|
57636
|
+
return data;
|
|
57637
|
+
} catch (error) {
|
|
57638
|
+
throw error;
|
|
57639
|
+
}
|
|
57640
|
+
}
|
|
57641
|
+
async function getServiceRecentFeedbacks({
|
|
57642
|
+
site,
|
|
57643
|
+
serviceType,
|
|
57644
|
+
page = 1,
|
|
57645
|
+
limit = 10
|
|
57646
|
+
}) {
|
|
57647
|
+
page = page > 0 ? page - 1 : 0;
|
|
57648
|
+
const cacheOptions = { serviceType, page, limit };
|
|
57649
|
+
try {
|
|
57650
|
+
site = new import_mongodb121.ObjectId(site);
|
|
57651
|
+
cacheOptions.site = site.toString();
|
|
57652
|
+
} catch {
|
|
57653
|
+
throw new import_node_server_utils199.BadRequestError("Invalid site ID format.");
|
|
57654
|
+
}
|
|
57655
|
+
const workOrderService = workOrderServiceMap[serviceType] ?? serviceType;
|
|
57656
|
+
try {
|
|
57657
|
+
const [items, length] = await Promise.all([
|
|
57658
|
+
feedbackCollection.aggregate([
|
|
57659
|
+
{ $match: { site, service: workOrderService } },
|
|
57660
|
+
{ $sort: { createdAt: -1, _id: -1 } },
|
|
57661
|
+
{
|
|
57662
|
+
$lookup: {
|
|
57663
|
+
from: "users",
|
|
57664
|
+
localField: "createdBy",
|
|
57665
|
+
foreignField: "_id",
|
|
57666
|
+
as: "_createdByDoc"
|
|
57667
|
+
}
|
|
57668
|
+
},
|
|
57669
|
+
{
|
|
57670
|
+
$project: {
|
|
57671
|
+
description: 1,
|
|
57672
|
+
subject: 1,
|
|
57673
|
+
app: 1,
|
|
57674
|
+
status: 1,
|
|
57675
|
+
createdAt: 1,
|
|
57676
|
+
createdByName: { $arrayElemAt: ["$_createdByDoc.name", 0] }
|
|
57677
|
+
}
|
|
57678
|
+
},
|
|
57679
|
+
{ $skip: page * limit },
|
|
57680
|
+
{ $limit: limit }
|
|
57681
|
+
]).toArray(),
|
|
57682
|
+
feedbackCollection.countDocuments({ site, service: workOrderService })
|
|
57683
|
+
]);
|
|
57684
|
+
const data = (0, import_node_server_utils199.paginate)(items, page, limit, length);
|
|
57685
|
+
return data;
|
|
57686
|
+
} catch (error) {
|
|
57687
|
+
throw error;
|
|
56733
57688
|
}
|
|
56734
|
-
const feedbacks = await getMetric(
|
|
56735
|
-
feedbacks_namespace_collection,
|
|
56736
|
-
siteId,
|
|
56737
|
-
feedback
|
|
56738
|
-
);
|
|
56739
|
-
const workOrders = await getMetric(
|
|
56740
|
-
work_orders_namespace_collection,
|
|
56741
|
-
siteId,
|
|
56742
|
-
workOrder
|
|
56743
|
-
);
|
|
56744
|
-
const data = {
|
|
56745
|
-
feedbacks,
|
|
56746
|
-
workOrders
|
|
56747
|
-
};
|
|
56748
|
-
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
56749
|
-
import_node_server_utils199.logger.info(`Cache set for key: ${cacheKey}`);
|
|
56750
|
-
}).catch((err) => {
|
|
56751
|
-
import_node_server_utils199.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
56752
|
-
});
|
|
56753
|
-
return data;
|
|
56754
57689
|
}
|
|
56755
57690
|
return {
|
|
56756
57691
|
getSecurityDashboard,
|
|
56757
57692
|
getPropertyManagementDashboard,
|
|
56758
|
-
|
|
56759
|
-
|
|
56760
|
-
|
|
56761
|
-
|
|
57693
|
+
getServiceDashboard,
|
|
57694
|
+
getServiceWeeklyActivity,
|
|
57695
|
+
getServiceTodayTaskSchedule,
|
|
57696
|
+
getServiceStaffAttendance,
|
|
57697
|
+
getServiceRecentFeedbacks
|
|
56762
57698
|
};
|
|
56763
57699
|
}
|
|
56764
57700
|
|
|
@@ -56769,10 +57705,11 @@ function useNewDashboardController() {
|
|
|
56769
57705
|
const {
|
|
56770
57706
|
getSecurityDashboard: _getSecurityDashboard,
|
|
56771
57707
|
getPropertyManagementDashboard: _getPropertyManagementDashboard,
|
|
56772
|
-
|
|
56773
|
-
|
|
56774
|
-
|
|
56775
|
-
|
|
57708
|
+
getServiceDashboard: _getServiceDashboard,
|
|
57709
|
+
getServiceWeeklyActivity: _getServiceWeeklyActivity,
|
|
57710
|
+
getServiceTodayTaskSchedule: _getServiceTodayTaskSchedule,
|
|
57711
|
+
getServiceStaffAttendance: _getServiceStaffAttendance,
|
|
57712
|
+
getServiceRecentFeedbacks: _getServiceRecentFeedbacks
|
|
56776
57713
|
} = useNewDashboardRepo();
|
|
56777
57714
|
const periodField = import_joi112.default.string().valid(...Object.values(Period)).default("today" /* TODAY */);
|
|
56778
57715
|
async function getSecurityDashboard(req, res, next) {
|
|
@@ -56884,143 +57821,179 @@ function useNewDashboardController() {
|
|
|
56884
57821
|
return;
|
|
56885
57822
|
}
|
|
56886
57823
|
}
|
|
56887
|
-
async function
|
|
57824
|
+
async function getServiceDashboard(req, res, next) {
|
|
57825
|
+
const query = { ...req.query, ...req.params };
|
|
57826
|
+
const validation = import_joi112.default.object({
|
|
57827
|
+
site: import_joi112.default.string().hex().required(),
|
|
57828
|
+
serviceType: import_joi112.default.string().valid(...Object.values(AppServiceType)).required(),
|
|
57829
|
+
period: import_joi112.default.string().valid(...Object.values(Period)).default("today" /* TODAY */),
|
|
57830
|
+
type: import_joi112.default.string().optional().allow("", null),
|
|
57831
|
+
facility: import_joi112.default.string().hex().optional().allow("", null)
|
|
57832
|
+
});
|
|
57833
|
+
const { error } = validation.validate(query);
|
|
57834
|
+
if (error) {
|
|
57835
|
+
import_node_server_utils200.logger.log({ level: "error", message: error.message });
|
|
57836
|
+
next(new import_node_server_utils200.BadRequestError(error.message));
|
|
57837
|
+
return;
|
|
57838
|
+
}
|
|
57839
|
+
const site = req.params.site ?? "";
|
|
57840
|
+
const serviceType = req.params.serviceType;
|
|
57841
|
+
const period = req.query.period;
|
|
57842
|
+
const type = req.query.type;
|
|
57843
|
+
const facility = req.query.facility;
|
|
56888
57844
|
try {
|
|
56889
|
-
const
|
|
56890
|
-
site
|
|
56891
|
-
|
|
56892
|
-
|
|
56893
|
-
|
|
56894
|
-
|
|
56895
|
-
site: req.params.site,
|
|
56896
|
-
...req.query
|
|
56897
|
-
});
|
|
56898
|
-
if (error) {
|
|
56899
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
56900
|
-
import_node_server_utils200.logger.log({ level: "error", message: messages });
|
|
56901
|
-
next(new import_node_server_utils200.BadRequestError(messages));
|
|
56902
|
-
return;
|
|
56903
|
-
}
|
|
56904
|
-
const { site, feedbackPeriod, workOrderPeriod } = value;
|
|
56905
|
-
const data = await _getPestManagementDashboard({
|
|
56906
|
-
siteId: site,
|
|
56907
|
-
feedback: feedbackPeriod,
|
|
56908
|
-
workOrder: workOrderPeriod
|
|
57845
|
+
const data = await _getServiceDashboard({
|
|
57846
|
+
site,
|
|
57847
|
+
period,
|
|
57848
|
+
serviceType,
|
|
57849
|
+
type,
|
|
57850
|
+
facility
|
|
56909
57851
|
});
|
|
56910
|
-
res.
|
|
57852
|
+
res.json(data);
|
|
56911
57853
|
return;
|
|
56912
|
-
} catch (
|
|
57854
|
+
} catch (error2) {
|
|
57855
|
+
import_node_server_utils200.logger.log({ level: "error", message: error2.message });
|
|
57856
|
+
next(error2);
|
|
57857
|
+
return;
|
|
57858
|
+
}
|
|
57859
|
+
}
|
|
57860
|
+
async function getServiceWeeklyActivity(req, res, next) {
|
|
57861
|
+
const query = { ...req.params, ...req.query };
|
|
57862
|
+
const validation = import_joi112.default.object({
|
|
57863
|
+
site: import_joi112.default.string().hex().required(),
|
|
57864
|
+
serviceType: import_joi112.default.string().valid(...Object.values(AppServiceType)).required(),
|
|
57865
|
+
period: import_joi112.default.string().valid(...Object.values(Period)).default("today" /* TODAY */)
|
|
57866
|
+
});
|
|
57867
|
+
const { error, value } = validation.validate(query);
|
|
57868
|
+
if (error) {
|
|
56913
57869
|
import_node_server_utils200.logger.log({ level: "error", message: error.message });
|
|
56914
|
-
next(error);
|
|
57870
|
+
next(new import_node_server_utils200.BadRequestError(error.message));
|
|
57871
|
+
return;
|
|
57872
|
+
}
|
|
57873
|
+
const { site, serviceType, period } = value;
|
|
57874
|
+
try {
|
|
57875
|
+
const data = await _getServiceWeeklyActivity({ site, serviceType, period });
|
|
57876
|
+
res.json(data);
|
|
57877
|
+
return;
|
|
57878
|
+
} catch (error2) {
|
|
57879
|
+
import_node_server_utils200.logger.log({ level: "error", message: error2.message });
|
|
57880
|
+
next(error2);
|
|
56915
57881
|
return;
|
|
56916
57882
|
}
|
|
56917
57883
|
}
|
|
56918
|
-
async function
|
|
57884
|
+
async function getServiceTodayTaskSchedule(req, res, next) {
|
|
57885
|
+
const query = { ...req.query, ...req.params };
|
|
57886
|
+
const validation = import_joi112.default.object({
|
|
57887
|
+
site: import_joi112.default.string().hex().required(),
|
|
57888
|
+
serviceType: import_joi112.default.string().valid(...Object.values(AppServiceType)).required(),
|
|
57889
|
+
page: import_joi112.default.number().min(1).optional().allow("", null),
|
|
57890
|
+
limit: import_joi112.default.number().min(1).optional().allow("", null)
|
|
57891
|
+
});
|
|
57892
|
+
const { error } = validation.validate(query);
|
|
57893
|
+
if (error) {
|
|
57894
|
+
import_node_server_utils200.logger.log({ level: "error", message: error.message });
|
|
57895
|
+
next(new import_node_server_utils200.BadRequestError(error.message));
|
|
57896
|
+
return;
|
|
57897
|
+
}
|
|
57898
|
+
const site = req.params.site;
|
|
57899
|
+
const serviceType = req.params.serviceType;
|
|
57900
|
+
const page = parseInt(req.query.page) ?? 1;
|
|
57901
|
+
const limit = parseInt(req.query.limit) ?? 10;
|
|
56919
57902
|
try {
|
|
56920
|
-
const
|
|
56921
|
-
site
|
|
56922
|
-
|
|
56923
|
-
|
|
56924
|
-
|
|
56925
|
-
const { error, value } = schema2.validate({
|
|
56926
|
-
site: req.params.site,
|
|
56927
|
-
...req.query
|
|
56928
|
-
});
|
|
56929
|
-
if (error) {
|
|
56930
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
56931
|
-
import_node_server_utils200.logger.log({ level: "error", message: messages });
|
|
56932
|
-
next(new import_node_server_utils200.BadRequestError(messages));
|
|
56933
|
-
return;
|
|
56934
|
-
}
|
|
56935
|
-
const { site, feedbackPeriod, workOrderPeriod } = value;
|
|
56936
|
-
const data = await _getPestManagementDashboard({
|
|
56937
|
-
siteId: site,
|
|
56938
|
-
feedback: feedbackPeriod,
|
|
56939
|
-
workOrder: workOrderPeriod
|
|
57903
|
+
const data = await _getServiceTodayTaskSchedule({
|
|
57904
|
+
site,
|
|
57905
|
+
serviceType,
|
|
57906
|
+
page,
|
|
57907
|
+
limit
|
|
56940
57908
|
});
|
|
56941
|
-
res.
|
|
57909
|
+
res.json(data);
|
|
56942
57910
|
return;
|
|
56943
|
-
} catch (
|
|
56944
|
-
import_node_server_utils200.logger.log({ level: "error", message:
|
|
56945
|
-
next(
|
|
57911
|
+
} catch (error2) {
|
|
57912
|
+
import_node_server_utils200.logger.log({ level: "error", message: error2.message });
|
|
57913
|
+
next(error2);
|
|
56946
57914
|
return;
|
|
56947
57915
|
}
|
|
56948
57916
|
}
|
|
56949
|
-
async function
|
|
57917
|
+
async function getServiceStaffAttendance(req, res, next) {
|
|
57918
|
+
const query = { ...req.query, ...req.params };
|
|
57919
|
+
const validation = import_joi112.default.object({
|
|
57920
|
+
site: import_joi112.default.string().hex().required(),
|
|
57921
|
+
serviceType: import_joi112.default.string().valid(...Object.values(AppServiceType)).required(),
|
|
57922
|
+
page: import_joi112.default.number().min(1).optional().allow("", null),
|
|
57923
|
+
limit: import_joi112.default.number().min(1).optional().allow("", null)
|
|
57924
|
+
});
|
|
57925
|
+
const { error } = validation.validate(query);
|
|
57926
|
+
if (error) {
|
|
57927
|
+
import_node_server_utils200.logger.log({ level: "error", message: error.message });
|
|
57928
|
+
next(new import_node_server_utils200.BadRequestError(error.message));
|
|
57929
|
+
return;
|
|
57930
|
+
}
|
|
57931
|
+
const site = req.params.site;
|
|
57932
|
+
const serviceType = req.params.serviceType;
|
|
57933
|
+
const page = parseInt(req.query.page) ?? 1;
|
|
57934
|
+
const limit = parseInt(req.query.limit) ?? 10;
|
|
56950
57935
|
try {
|
|
56951
|
-
const
|
|
56952
|
-
site
|
|
56953
|
-
|
|
56954
|
-
|
|
56955
|
-
|
|
56956
|
-
const { error, value } = schema2.validate({
|
|
56957
|
-
site: req.params.site,
|
|
56958
|
-
...req.query
|
|
56959
|
-
});
|
|
56960
|
-
if (error) {
|
|
56961
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
56962
|
-
import_node_server_utils200.logger.log({ level: "error", message: messages });
|
|
56963
|
-
next(new import_node_server_utils200.BadRequestError(messages));
|
|
56964
|
-
return;
|
|
56965
|
-
}
|
|
56966
|
-
const { site, feedbackPeriod, workOrderPeriod } = value;
|
|
56967
|
-
const data = await _getMAndEManagementDashboard({
|
|
56968
|
-
siteId: site,
|
|
56969
|
-
feedback: feedbackPeriod,
|
|
56970
|
-
workOrder: workOrderPeriod
|
|
57936
|
+
const data = await _getServiceStaffAttendance({
|
|
57937
|
+
site,
|
|
57938
|
+
serviceType,
|
|
57939
|
+
page,
|
|
57940
|
+
limit
|
|
56971
57941
|
});
|
|
56972
|
-
res.
|
|
57942
|
+
res.json(data);
|
|
56973
57943
|
return;
|
|
56974
|
-
} catch (
|
|
56975
|
-
import_node_server_utils200.logger.log({ level: "error", message:
|
|
56976
|
-
next(
|
|
57944
|
+
} catch (error2) {
|
|
57945
|
+
import_node_server_utils200.logger.log({ level: "error", message: error2.message });
|
|
57946
|
+
next(error2);
|
|
56977
57947
|
return;
|
|
56978
57948
|
}
|
|
56979
57949
|
}
|
|
56980
|
-
async function
|
|
57950
|
+
async function getServiceRecentFeedbacks(req, res, next) {
|
|
57951
|
+
const query = { ...req.query, ...req.params };
|
|
57952
|
+
const validation = import_joi112.default.object({
|
|
57953
|
+
site: import_joi112.default.string().hex().required(),
|
|
57954
|
+
serviceType: import_joi112.default.string().valid(...Object.values(AppServiceType)).required(),
|
|
57955
|
+
page: import_joi112.default.number().min(1).optional().allow("", null),
|
|
57956
|
+
limit: import_joi112.default.number().min(1).optional().allow("", null)
|
|
57957
|
+
});
|
|
57958
|
+
const { error } = validation.validate(query);
|
|
57959
|
+
if (error) {
|
|
57960
|
+
import_node_server_utils200.logger.log({ level: "error", message: error.message });
|
|
57961
|
+
next(new import_node_server_utils200.BadRequestError(error.message));
|
|
57962
|
+
return;
|
|
57963
|
+
}
|
|
57964
|
+
const site = req.params.site;
|
|
57965
|
+
const serviceType = req.params.serviceType;
|
|
57966
|
+
const page = parseInt(req.query.page) ?? 1;
|
|
57967
|
+
const limit = parseInt(req.query.limit) ?? 10;
|
|
56981
57968
|
try {
|
|
56982
|
-
const
|
|
56983
|
-
site
|
|
56984
|
-
|
|
56985
|
-
|
|
56986
|
-
|
|
56987
|
-
const { error, value } = schema2.validate({
|
|
56988
|
-
site: req.params.site,
|
|
56989
|
-
...req.query
|
|
56990
|
-
});
|
|
56991
|
-
if (error) {
|
|
56992
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
56993
|
-
import_node_server_utils200.logger.log({ level: "error", message: messages });
|
|
56994
|
-
next(new import_node_server_utils200.BadRequestError(messages));
|
|
56995
|
-
return;
|
|
56996
|
-
}
|
|
56997
|
-
const { site, feedbackPeriod, workOrderPeriod } = value;
|
|
56998
|
-
const data = await _getLandscapeDashboard({
|
|
56999
|
-
siteId: site,
|
|
57000
|
-
feedback: feedbackPeriod,
|
|
57001
|
-
workOrder: workOrderPeriod
|
|
57969
|
+
const data = await _getServiceRecentFeedbacks({
|
|
57970
|
+
site,
|
|
57971
|
+
serviceType,
|
|
57972
|
+
page,
|
|
57973
|
+
limit
|
|
57002
57974
|
});
|
|
57003
|
-
res.
|
|
57975
|
+
res.json(data);
|
|
57004
57976
|
return;
|
|
57005
|
-
} catch (
|
|
57006
|
-
import_node_server_utils200.logger.log({ level: "error", message:
|
|
57007
|
-
next(
|
|
57977
|
+
} catch (error2) {
|
|
57978
|
+
import_node_server_utils200.logger.log({ level: "error", message: error2.message });
|
|
57979
|
+
next(error2);
|
|
57008
57980
|
return;
|
|
57009
57981
|
}
|
|
57010
57982
|
}
|
|
57011
57983
|
return {
|
|
57012
57984
|
getSecurityDashboard,
|
|
57013
57985
|
getPropertyManagementDashboard,
|
|
57014
|
-
|
|
57015
|
-
|
|
57016
|
-
|
|
57017
|
-
|
|
57986
|
+
getServiceDashboard,
|
|
57987
|
+
getServiceWeeklyActivity,
|
|
57988
|
+
getServiceTodayTaskSchedule,
|
|
57989
|
+
getServiceStaffAttendance,
|
|
57990
|
+
getServiceRecentFeedbacks
|
|
57018
57991
|
};
|
|
57019
57992
|
}
|
|
57020
57993
|
|
|
57021
57994
|
// src/models/manpower-monitoring.model.ts
|
|
57022
57995
|
var import_joi113 = __toESM(require("joi"));
|
|
57023
|
-
var
|
|
57996
|
+
var import_mongodb122 = require("mongodb");
|
|
57024
57997
|
var shiftSchema = import_joi113.default.object({
|
|
57025
57998
|
name: import_joi113.default.string().required(),
|
|
57026
57999
|
checkIn: import_joi113.default.string().optional().allow("", null),
|
|
@@ -57045,7 +58018,7 @@ var manpowerMonitoringSchema = import_joi113.default.object({
|
|
|
57045
58018
|
});
|
|
57046
58019
|
var MManpowerMonitoring = class {
|
|
57047
58020
|
constructor(data) {
|
|
57048
|
-
this._id = new
|
|
58021
|
+
this._id = new import_mongodb122.ObjectId();
|
|
57049
58022
|
this.serviceProviderId = data.serviceProviderId || "";
|
|
57050
58023
|
this.siteId = data.siteId || "";
|
|
57051
58024
|
this.siteName = data.siteName;
|
|
@@ -57154,7 +58127,7 @@ function filterByShiftTime(attendance, shiftData, timezone, format2) {
|
|
|
57154
58127
|
return checkInLocal.isBetween(shiftStart, shiftEnd, null, "[]");
|
|
57155
58128
|
});
|
|
57156
58129
|
}
|
|
57157
|
-
function
|
|
58130
|
+
function paginate52(data, page, limit) {
|
|
57158
58131
|
const length = data.length;
|
|
57159
58132
|
const startIndex = (page - 1) * limit;
|
|
57160
58133
|
const endIndex = startIndex + limit;
|
|
@@ -57502,7 +58475,7 @@ var hrmlabs_attendance_util_default = {
|
|
|
57502
58475
|
hrmLabsAuthentication,
|
|
57503
58476
|
fetchAttendanceData,
|
|
57504
58477
|
filterByShiftTime,
|
|
57505
|
-
paginate:
|
|
58478
|
+
paginate: paginate52,
|
|
57506
58479
|
designationCount,
|
|
57507
58480
|
totalCountPerShift,
|
|
57508
58481
|
filterByStatus,
|
|
@@ -57512,7 +58485,7 @@ var hrmlabs_attendance_util_default = {
|
|
|
57512
58485
|
};
|
|
57513
58486
|
|
|
57514
58487
|
// src/repositories/manpower-monitoring.repo.ts
|
|
57515
|
-
var
|
|
58488
|
+
var import_mongodb123 = require("mongodb");
|
|
57516
58489
|
var { hrmLabsAuthentication: hrmLabsAuthentication2, fetchSites: fetchSites2 } = hrmlabs_attendance_util_default;
|
|
57517
58490
|
function useManpowerMonitoringRepo() {
|
|
57518
58491
|
const db = import_node_server_utils201.useAtlas.getDb();
|
|
@@ -57547,11 +58520,11 @@ function useManpowerMonitoringRepo() {
|
|
|
57547
58520
|
try {
|
|
57548
58521
|
value = new MManpowerMonitoring(value);
|
|
57549
58522
|
if (value.createdBy)
|
|
57550
|
-
value.createdBy = new
|
|
58523
|
+
value.createdBy = new import_mongodb123.ObjectId(value.createdBy);
|
|
57551
58524
|
if (value.siteId)
|
|
57552
|
-
value.siteId = new
|
|
58525
|
+
value.siteId = new import_mongodb123.ObjectId(value.siteId);
|
|
57553
58526
|
if (value.serviceProviderId)
|
|
57554
|
-
value.serviceProviderId = new
|
|
58527
|
+
value.serviceProviderId = new import_mongodb123.ObjectId(value.serviceProviderId);
|
|
57555
58528
|
const result = await collection.insertOne(value, { session });
|
|
57556
58529
|
return result;
|
|
57557
58530
|
} catch (error) {
|
|
@@ -57592,8 +58565,8 @@ function useManpowerMonitoringRepo() {
|
|
|
57592
58565
|
}
|
|
57593
58566
|
async function getManpowerSettingsBySiteId(_id, serviceProviderId) {
|
|
57594
58567
|
try {
|
|
57595
|
-
_id = new
|
|
57596
|
-
serviceProviderId = new
|
|
58568
|
+
_id = new import_mongodb123.ObjectId(_id);
|
|
58569
|
+
serviceProviderId = new import_mongodb123.ObjectId(serviceProviderId);
|
|
57597
58570
|
} catch (error) {
|
|
57598
58571
|
throw new Error("Invalid Site ID format.");
|
|
57599
58572
|
}
|
|
@@ -57609,7 +58582,7 @@ function useManpowerMonitoringRepo() {
|
|
|
57609
58582
|
}
|
|
57610
58583
|
async function updateManpowerMonitoringSettings(_id, value) {
|
|
57611
58584
|
try {
|
|
57612
|
-
_id = new
|
|
58585
|
+
_id = new import_mongodb123.ObjectId(_id);
|
|
57613
58586
|
} catch (error) {
|
|
57614
58587
|
throw new import_node_server_utils201.BadRequestError("Invalid ID format.");
|
|
57615
58588
|
}
|
|
@@ -57636,7 +58609,7 @@ function useManpowerMonitoringRepo() {
|
|
|
57636
58609
|
for (let item of value) {
|
|
57637
58610
|
item = new MManpowerMonitoring(item);
|
|
57638
58611
|
const data = await collection.findOne({
|
|
57639
|
-
siteId: new
|
|
58612
|
+
siteId: new import_mongodb123.ObjectId(item.siteId)
|
|
57640
58613
|
});
|
|
57641
58614
|
if (data) {
|
|
57642
58615
|
let updateValue;
|
|
@@ -57661,11 +58634,11 @@ function useManpowerMonitoringRepo() {
|
|
|
57661
58634
|
}
|
|
57662
58635
|
} else {
|
|
57663
58636
|
if (item.createdBy)
|
|
57664
|
-
item.createdBy = new
|
|
58637
|
+
item.createdBy = new import_mongodb123.ObjectId(item.createdBy);
|
|
57665
58638
|
if (item.siteId)
|
|
57666
|
-
item.siteId = new
|
|
58639
|
+
item.siteId = new import_mongodb123.ObjectId(item.siteId);
|
|
57667
58640
|
if (item.serviceProviderId)
|
|
57668
|
-
item.serviceProviderId = new
|
|
58641
|
+
item.serviceProviderId = new import_mongodb123.ObjectId(item.serviceProviderId);
|
|
57669
58642
|
const result = await collection.insertOne(item);
|
|
57670
58643
|
if (result.insertedId) {
|
|
57671
58644
|
results.inserted++;
|
|
@@ -57689,7 +58662,7 @@ function useManpowerMonitoringRepo() {
|
|
|
57689
58662
|
const siteUrl = process.env.HRMLABS_SITE_URL;
|
|
57690
58663
|
try {
|
|
57691
58664
|
const serviceProvider = await serviceProviderCollection.findOne({
|
|
57692
|
-
_id: new
|
|
58665
|
+
_id: new import_mongodb123.ObjectId(serviceProviderId)
|
|
57693
58666
|
});
|
|
57694
58667
|
if (!serviceProvider) {
|
|
57695
58668
|
throw new Error("Service Provider not found.");
|
|
@@ -57732,7 +58705,7 @@ var import_node_server_utils202 = require("@7365admin1/node-server-utils");
|
|
|
57732
58705
|
|
|
57733
58706
|
// src/models/manpower-remarks.model.ts
|
|
57734
58707
|
var import_joi114 = __toESM(require("joi"));
|
|
57735
|
-
var
|
|
58708
|
+
var import_mongodb124 = require("mongodb");
|
|
57736
58709
|
var remarksSchema = import_joi114.default.object({
|
|
57737
58710
|
name: import_joi114.default.string().required(),
|
|
57738
58711
|
remark: import_joi114.default.object({
|
|
@@ -57756,7 +58729,7 @@ var manpowerRemarksSchema = import_joi114.default.object({
|
|
|
57756
58729
|
});
|
|
57757
58730
|
var MManpowerRemarks = class {
|
|
57758
58731
|
constructor(data) {
|
|
57759
|
-
this._id = new
|
|
58732
|
+
this._id = new import_mongodb124.ObjectId();
|
|
57760
58733
|
this.serviceProviderId = data.serviceProviderId || "";
|
|
57761
58734
|
this.siteId = data.siteId || "";
|
|
57762
58735
|
this.siteName = data.siteName || "";
|
|
@@ -57774,7 +58747,7 @@ var MManpowerRemarks = class {
|
|
|
57774
58747
|
};
|
|
57775
58748
|
|
|
57776
58749
|
// src/repositories/manpower-remarks.repo.ts
|
|
57777
|
-
var
|
|
58750
|
+
var import_mongodb125 = require("mongodb");
|
|
57778
58751
|
var import_moment_timezone3 = __toESM(require("moment-timezone"));
|
|
57779
58752
|
function useManpowerRemarksRepo() {
|
|
57780
58753
|
const db = import_node_server_utils202.useAtlas.getDb();
|
|
@@ -57808,9 +58781,9 @@ function useManpowerRemarksRepo() {
|
|
|
57808
58781
|
try {
|
|
57809
58782
|
value = new MManpowerRemarks(value);
|
|
57810
58783
|
if (value.siteId)
|
|
57811
|
-
value.siteId = new
|
|
58784
|
+
value.siteId = new import_mongodb125.ObjectId(value.siteId);
|
|
57812
58785
|
if (value.serviceProviderId)
|
|
57813
|
-
value.serviceProviderId = new
|
|
58786
|
+
value.serviceProviderId = new import_mongodb125.ObjectId(value.serviceProviderId);
|
|
57814
58787
|
const result = await collection.insertOne(value, { session });
|
|
57815
58788
|
return result;
|
|
57816
58789
|
} catch (error) {
|
|
@@ -57830,7 +58803,7 @@ function useManpowerRemarksRepo() {
|
|
|
57830
58803
|
limit = limit || 10;
|
|
57831
58804
|
const searchQuery = {};
|
|
57832
58805
|
const nowSGT = (0, import_moment_timezone3.default)().tz("Asia/Singapore");
|
|
57833
|
-
searchQuery.serviceProviderId = new
|
|
58806
|
+
searchQuery.serviceProviderId = new import_mongodb125.ObjectId(serviceProviderId);
|
|
57834
58807
|
if (search != "") {
|
|
57835
58808
|
searchQuery.siteName = { $regex: search, $options: "i" };
|
|
57836
58809
|
}
|
|
@@ -57862,8 +58835,8 @@ function useManpowerRemarksRepo() {
|
|
|
57862
58835
|
}
|
|
57863
58836
|
async function getManpowerRemarksBySiteId(_id, date, serviceProviderId) {
|
|
57864
58837
|
try {
|
|
57865
|
-
_id = new
|
|
57866
|
-
serviceProviderId = new
|
|
58838
|
+
_id = new import_mongodb125.ObjectId(_id);
|
|
58839
|
+
serviceProviderId = new import_mongodb125.ObjectId(serviceProviderId);
|
|
57867
58840
|
} catch (error) {
|
|
57868
58841
|
throw new Error("Invalid Site ID format.");
|
|
57869
58842
|
}
|
|
@@ -57880,13 +58853,13 @@ function useManpowerRemarksRepo() {
|
|
|
57880
58853
|
}
|
|
57881
58854
|
async function updateManpowerRemarks(_id, value) {
|
|
57882
58855
|
try {
|
|
57883
|
-
_id = new
|
|
58856
|
+
_id = new import_mongodb125.ObjectId(_id);
|
|
57884
58857
|
} catch (error) {
|
|
57885
58858
|
throw new import_node_server_utils202.BadRequestError("Invalid ID format.");
|
|
57886
58859
|
}
|
|
57887
58860
|
try {
|
|
57888
58861
|
if (value.createdBy) {
|
|
57889
|
-
value.createdBy = new
|
|
58862
|
+
value.createdBy = new import_mongodb125.ObjectId(value.createdBy);
|
|
57890
58863
|
}
|
|
57891
58864
|
const updateValue = {
|
|
57892
58865
|
...value,
|
|
@@ -57903,7 +58876,7 @@ function useManpowerRemarksRepo() {
|
|
|
57903
58876
|
}
|
|
57904
58877
|
async function updateRemarksStatus(_id, value) {
|
|
57905
58878
|
try {
|
|
57906
|
-
_id = new
|
|
58879
|
+
_id = new import_mongodb125.ObjectId(_id);
|
|
57907
58880
|
} catch (error) {
|
|
57908
58881
|
throw new import_node_server_utils202.BadRequestError("Invalid ID format.");
|
|
57909
58882
|
}
|
|
@@ -58173,7 +59146,7 @@ function useManpowerMonitoringCtrl() {
|
|
|
58173
59146
|
|
|
58174
59147
|
// src/models/manpower-designations.model.ts
|
|
58175
59148
|
var import_joi116 = __toESM(require("joi"));
|
|
58176
|
-
var
|
|
59149
|
+
var import_mongodb126 = require("mongodb");
|
|
58177
59150
|
var designationsSchema = import_joi116.default.object({
|
|
58178
59151
|
title: import_joi116.default.string().required(),
|
|
58179
59152
|
shifts: import_joi116.default.object({
|
|
@@ -58192,7 +59165,7 @@ var manpowerDesignationsSchema = import_joi116.default.object({
|
|
|
58192
59165
|
});
|
|
58193
59166
|
var MManpowerDesignations = class {
|
|
58194
59167
|
constructor(data) {
|
|
58195
|
-
this._id = new
|
|
59168
|
+
this._id = new import_mongodb126.ObjectId();
|
|
58196
59169
|
this.siteId = data.siteId || "";
|
|
58197
59170
|
this.siteName = data.siteName || "";
|
|
58198
59171
|
this.serviceProviderId = data.serviceProviderId || "";
|
|
@@ -58206,7 +59179,7 @@ var MManpowerDesignations = class {
|
|
|
58206
59179
|
|
|
58207
59180
|
// src/repositories/manpower-designations.repo.ts
|
|
58208
59181
|
var import_node_server_utils205 = require("@7365admin1/node-server-utils");
|
|
58209
|
-
var
|
|
59182
|
+
var import_mongodb127 = require("mongodb");
|
|
58210
59183
|
function useManpowerDesignationRepo() {
|
|
58211
59184
|
const db = import_node_server_utils205.useAtlas.getDb();
|
|
58212
59185
|
if (!db) {
|
|
@@ -58238,11 +59211,11 @@ function useManpowerDesignationRepo() {
|
|
|
58238
59211
|
try {
|
|
58239
59212
|
value = new MManpowerDesignations(value);
|
|
58240
59213
|
if (value.createdBy)
|
|
58241
|
-
value.createdBy = new
|
|
59214
|
+
value.createdBy = new import_mongodb127.ObjectId(value.createdBy);
|
|
58242
59215
|
if (value.siteId)
|
|
58243
|
-
value.siteId = new
|
|
59216
|
+
value.siteId = new import_mongodb127.ObjectId(value.siteId);
|
|
58244
59217
|
if (value.serviceProviderId)
|
|
58245
|
-
value.serviceProviderId = new
|
|
59218
|
+
value.serviceProviderId = new import_mongodb127.ObjectId(value.serviceProviderId);
|
|
58246
59219
|
const result = await collection.insertOne(value);
|
|
58247
59220
|
return result;
|
|
58248
59221
|
} catch (error) {
|
|
@@ -58251,8 +59224,8 @@ function useManpowerDesignationRepo() {
|
|
|
58251
59224
|
}
|
|
58252
59225
|
async function getManpowerDesignationsBySiteId(_id, serviceProviderId) {
|
|
58253
59226
|
try {
|
|
58254
|
-
_id = new
|
|
58255
|
-
serviceProviderId = new
|
|
59227
|
+
_id = new import_mongodb127.ObjectId(_id);
|
|
59228
|
+
serviceProviderId = new import_mongodb127.ObjectId(serviceProviderId);
|
|
58256
59229
|
} catch (error) {
|
|
58257
59230
|
throw new Error("Invalid Site ID format.");
|
|
58258
59231
|
}
|
|
@@ -58268,7 +59241,7 @@ function useManpowerDesignationRepo() {
|
|
|
58268
59241
|
}
|
|
58269
59242
|
async function updateManpowerDesignations(_id, value) {
|
|
58270
59243
|
try {
|
|
58271
|
-
_id = new
|
|
59244
|
+
_id = new import_mongodb127.ObjectId(_id);
|
|
58272
59245
|
} catch (error) {
|
|
58273
59246
|
throw new Error("Invalid ID format.");
|
|
58274
59247
|
}
|
|
@@ -58372,7 +59345,7 @@ function useManpowerDesignationCtrl() {
|
|
|
58372
59345
|
|
|
58373
59346
|
// src/models/overnight-parking.model.ts
|
|
58374
59347
|
var import_joi118 = __toESM(require("joi"));
|
|
58375
|
-
var
|
|
59348
|
+
var import_mongodb128 = require("mongodb");
|
|
58376
59349
|
var dayScheduleSchema = import_joi118.default.object({
|
|
58377
59350
|
isEnabled: import_joi118.default.boolean().required(),
|
|
58378
59351
|
startTime: import_joi118.default.string().pattern(/^([01]\d|2[0-3]):([0-5]\d)$/).optional().allow(null, "").messages({
|
|
@@ -58414,7 +59387,7 @@ function MOvernightParkingApprovalHours(value) {
|
|
|
58414
59387
|
}
|
|
58415
59388
|
if (value.site && typeof value.site === "string") {
|
|
58416
59389
|
try {
|
|
58417
|
-
value.site = new
|
|
59390
|
+
value.site = new import_mongodb128.ObjectId(value.site);
|
|
58418
59391
|
} catch {
|
|
58419
59392
|
throw new Error("Invalid site ID.");
|
|
58420
59393
|
}
|
|
@@ -59177,7 +60150,7 @@ var {
|
|
|
59177
60150
|
hrmLabsAuthentication: hrmLabsAuthentication3,
|
|
59178
60151
|
fetchAttendanceData: fetchAttendanceData2,
|
|
59179
60152
|
filterByShiftTime: filterByShiftTime2,
|
|
59180
|
-
paginate:
|
|
60153
|
+
paginate: paginate58,
|
|
59181
60154
|
designationCount: designationCount2,
|
|
59182
60155
|
totalCountPerShift: totalCountPerShift2,
|
|
59183
60156
|
filterByStatus: filterByStatus2,
|
|
@@ -59278,7 +60251,7 @@ function useHrmLabsAttendanceSrvc() {
|
|
|
59278
60251
|
status
|
|
59279
60252
|
);
|
|
59280
60253
|
}
|
|
59281
|
-
const paginatedItems =
|
|
60254
|
+
const paginatedItems = paginate58(filteredAttendance, page, limit);
|
|
59282
60255
|
return {
|
|
59283
60256
|
items: paginatedItems.items,
|
|
59284
60257
|
pages: paginatedItems.pages,
|
|
@@ -60019,7 +60992,7 @@ function useManpowerRemarkCtrl() {
|
|
|
60019
60992
|
|
|
60020
60993
|
// src/models/manpower-sites.model.ts
|
|
60021
60994
|
var import_joi124 = __toESM(require("joi"));
|
|
60022
|
-
var
|
|
60995
|
+
var import_mongodb129 = require("mongodb");
|
|
60023
60996
|
var manpowerSitesSchema = import_joi124.default.object({
|
|
60024
60997
|
id: import_joi124.default.string().hex().required(),
|
|
60025
60998
|
text: import_joi124.default.string().hex().optional().allow("", null),
|
|
@@ -60030,7 +61003,7 @@ var manpowerSitesSchema = import_joi124.default.object({
|
|
|
60030
61003
|
});
|
|
60031
61004
|
var MManpowerSites = class {
|
|
60032
61005
|
constructor(data) {
|
|
60033
|
-
this._id = new
|
|
61006
|
+
this._id = new import_mongodb129.ObjectId();
|
|
60034
61007
|
this.id = data.id || "";
|
|
60035
61008
|
this.text = data.text || "";
|
|
60036
61009
|
this.contractID = data.contractID || "";
|
|
@@ -60240,7 +61213,7 @@ function useManpowerSitesCtrl() {
|
|
|
60240
61213
|
|
|
60241
61214
|
// src/utils/cron.util.ts
|
|
60242
61215
|
var import_node_server_utils219 = require("@7365admin1/node-server-utils");
|
|
60243
|
-
var
|
|
61216
|
+
var import_mongodb130 = require("mongodb");
|
|
60244
61217
|
var import_moment_timezone5 = __toESM(require("moment-timezone"));
|
|
60245
61218
|
var createManpowerRemarksDaily = async () => {
|
|
60246
61219
|
const db = import_node_server_utils219.useAtlas.getDb();
|
|
@@ -60400,7 +61373,7 @@ var updateRemarksisAcknowledged = async () => {
|
|
|
60400
61373
|
for (const id of updatedIds) {
|
|
60401
61374
|
const doc = await remarks.findOne({ _id: id });
|
|
60402
61375
|
const setting = await settings.findOne(
|
|
60403
|
-
{ siteId: new
|
|
61376
|
+
{ siteId: new import_mongodb130.ObjectId(doc?.siteId) },
|
|
60404
61377
|
{ projection: { emails: 1 } }
|
|
60405
61378
|
);
|
|
60406
61379
|
const payload = {
|
|
@@ -60486,7 +61459,7 @@ var updateRemarksStatusEod = async () => {
|
|
|
60486
61459
|
for (const doc of docs) {
|
|
60487
61460
|
let shiftsToCheck = [];
|
|
60488
61461
|
const endShiftTime = await settings.findOne(
|
|
60489
|
-
{ siteId: new
|
|
61462
|
+
{ siteId: new import_mongodb130.ObjectId(doc.siteId) },
|
|
60490
61463
|
{ projection: { shifts: 1, shiftType: 1 } }
|
|
60491
61464
|
);
|
|
60492
61465
|
if (doc.createdAtSGT === nowSGT) {
|
|
@@ -60592,7 +61565,7 @@ var isWithinHour = (alertTime, timeNow) => {
|
|
|
60592
61565
|
|
|
60593
61566
|
// src/events/manpower.event.ts
|
|
60594
61567
|
var import_node_server_utils220 = require("@7365admin1/node-server-utils");
|
|
60595
|
-
var
|
|
61568
|
+
var import_mongodb131 = require("mongodb");
|
|
60596
61569
|
var import_moment_timezone6 = __toESM(require("moment-timezone"));
|
|
60597
61570
|
async function manpowerEvents(io) {
|
|
60598
61571
|
let intervalId = null;
|
|
@@ -60618,7 +61591,7 @@ async function manpowerEvents(io) {
|
|
|
60618
61591
|
}).toArray();
|
|
60619
61592
|
for (const doc of docs) {
|
|
60620
61593
|
const siteSettings = await settings.findOne(
|
|
60621
|
-
{ siteId: new
|
|
61594
|
+
{ siteId: new import_mongodb131.ObjectId(doc.siteId), enabled: true },
|
|
60622
61595
|
{ projection: { shifts: 1, shiftType: 1 } }
|
|
60623
61596
|
);
|
|
60624
61597
|
const shiftType = siteSettings?.shiftType || "2-shifts";
|
|
@@ -60737,11 +61710,11 @@ function genericSignature(params, secretKey) {
|
|
|
60737
61710
|
}
|
|
60738
61711
|
|
|
60739
61712
|
// src/repositories/reddot-payment.repository.ts
|
|
60740
|
-
var
|
|
61713
|
+
var import_mongodb133 = require("mongodb");
|
|
60741
61714
|
|
|
60742
61715
|
// src/models/billing-payments.model.ts
|
|
60743
61716
|
var import_node_server_utils221 = require("@7365admin1/node-server-utils");
|
|
60744
|
-
var
|
|
61717
|
+
var import_mongodb132 = require("mongodb");
|
|
60745
61718
|
var import_joi126 = __toESM(require("joi"));
|
|
60746
61719
|
var schemaBillingItems = import_joi126.default.object({
|
|
60747
61720
|
_id: import_joi126.default.string().hex().optional(),
|
|
@@ -60775,21 +61748,21 @@ function MBillingItems(value) {
|
|
|
60775
61748
|
}
|
|
60776
61749
|
if (value._id && typeof value._id === "string") {
|
|
60777
61750
|
try {
|
|
60778
|
-
value._id = new
|
|
61751
|
+
value._id = new import_mongodb132.ObjectId(value._id);
|
|
60779
61752
|
} catch {
|
|
60780
61753
|
throw new import_node_server_utils221.BadRequestError("Invalid _id format");
|
|
60781
61754
|
}
|
|
60782
61755
|
}
|
|
60783
61756
|
if (value.unitId && typeof value.unitId === "string") {
|
|
60784
61757
|
try {
|
|
60785
|
-
value.unitId = new
|
|
61758
|
+
value.unitId = new import_mongodb132.ObjectId(value.unitId);
|
|
60786
61759
|
} catch {
|
|
60787
61760
|
throw new import_node_server_utils221.BadRequestError("Invalid unitId id format");
|
|
60788
61761
|
}
|
|
60789
61762
|
}
|
|
60790
61763
|
if (value.paidBy && typeof value.paidBy === "string") {
|
|
60791
61764
|
try {
|
|
60792
|
-
value.paidBy = new
|
|
61765
|
+
value.paidBy = new import_mongodb132.ObjectId(value.paidBy);
|
|
60793
61766
|
} catch {
|
|
60794
61767
|
throw new import_node_server_utils221.BadRequestError("Invalid paidBy id format");
|
|
60795
61768
|
}
|
|
@@ -60799,7 +61772,7 @@ function MBillingItems(value) {
|
|
|
60799
61772
|
value.unitBillingItems = value.unitBillingItems.map((unitBillingItem) => {
|
|
60800
61773
|
if (typeof unitBillingItem._id === "string") {
|
|
60801
61774
|
try {
|
|
60802
|
-
unitBillingItem._id = new
|
|
61775
|
+
unitBillingItem._id = new import_mongodb132.ObjectId(unitBillingItem._id);
|
|
60803
61776
|
} catch {
|
|
60804
61777
|
throw new import_node_server_utils221.BadRequestError("Invalid unit billing id format");
|
|
60805
61778
|
}
|
|
@@ -60811,7 +61784,7 @@ function MBillingItems(value) {
|
|
|
60811
61784
|
}
|
|
60812
61785
|
}
|
|
60813
61786
|
return {
|
|
60814
|
-
_id: value._id ?? new
|
|
61787
|
+
_id: value._id ?? new import_mongodb132.ObjectId(),
|
|
60815
61788
|
unitBillingItems: value.unitBillingItems ?? [],
|
|
60816
61789
|
unitId: value.unitId ?? "",
|
|
60817
61790
|
unitOwner: value.unitOwner ?? "",
|
|
@@ -60879,7 +61852,7 @@ var useRedDotPaymentRepo = () => {
|
|
|
60879
61852
|
const res = await paymentCollection().insertOne(payload, { session });
|
|
60880
61853
|
const unit = payload.unitId?.toString().slice(-4);
|
|
60881
61854
|
const dateFormatted = formatDateString(/* @__PURE__ */ new Date());
|
|
60882
|
-
const newId = new
|
|
61855
|
+
const newId = new import_mongodb133.ObjectId(res.insertedId).toString().slice(-6);
|
|
60883
61856
|
const referenceNumber = `${unit}${newId}${dateFormatted}`;
|
|
60884
61857
|
await paymentCollection().updateOne(
|
|
60885
61858
|
{ _id: res.insertedId },
|
|
@@ -61979,7 +62952,7 @@ var import_node_server_utils228 = require("@7365admin1/node-server-utils");
|
|
|
61979
62952
|
var import_uuid2 = require("uuid");
|
|
61980
62953
|
|
|
61981
62954
|
// src/repositories/user-v2.repo.ts
|
|
61982
|
-
var
|
|
62955
|
+
var import_mongodb134 = require("mongodb");
|
|
61983
62956
|
var import_node_server_utils227 = require("@7365admin1/node-server-utils");
|
|
61984
62957
|
function useUserRepoV2() {
|
|
61985
62958
|
const { updateFeedbackCreatedByName } = useFeedbackRepo();
|
|
@@ -62180,7 +63153,7 @@ function useUserRepoV2() {
|
|
|
62180
63153
|
}
|
|
62181
63154
|
if (organization) {
|
|
62182
63155
|
try {
|
|
62183
|
-
query.defaultOrg = new
|
|
63156
|
+
query.defaultOrg = new import_mongodb134.ObjectId(organization);
|
|
62184
63157
|
cacheOptions.organization = organization.toString();
|
|
62185
63158
|
} catch (error) {
|
|
62186
63159
|
throw new import_node_server_utils227.BadRequestError("Invalid organization ID format.");
|
|
@@ -62319,13 +63292,13 @@ function useUserRepoV2() {
|
|
|
62319
63292
|
);
|
|
62320
63293
|
}
|
|
62321
63294
|
try {
|
|
62322
|
-
_id = new
|
|
63295
|
+
_id = new import_mongodb134.ObjectId(_id);
|
|
62323
63296
|
} catch (error) {
|
|
62324
63297
|
throw new import_node_server_utils227.BadRequestError("Invalid ID.");
|
|
62325
63298
|
}
|
|
62326
63299
|
if (field === "defaultOrg") {
|
|
62327
63300
|
try {
|
|
62328
|
-
value = new
|
|
63301
|
+
value = new import_mongodb134.ObjectId(value);
|
|
62329
63302
|
} catch (error) {
|
|
62330
63303
|
throw new import_node_server_utils227.BadRequestError("Invalid organization ID.");
|
|
62331
63304
|
}
|
|
@@ -62366,7 +63339,7 @@ function useUserRepoV2() {
|
|
|
62366
63339
|
year
|
|
62367
63340
|
}, session) {
|
|
62368
63341
|
try {
|
|
62369
|
-
_id = new
|
|
63342
|
+
_id = new import_mongodb134.ObjectId(_id);
|
|
62370
63343
|
} catch (error) {
|
|
62371
63344
|
throw new import_node_server_utils227.BadRequestError("Invalid user ID format.");
|
|
62372
63345
|
}
|
|
@@ -62396,7 +63369,7 @@ function useUserRepoV2() {
|
|
|
62396
63369
|
}
|
|
62397
63370
|
async function updatePassword({ _id, password }, session) {
|
|
62398
63371
|
try {
|
|
62399
|
-
_id = new
|
|
63372
|
+
_id = new import_mongodb134.ObjectId(_id);
|
|
62400
63373
|
} catch (error) {
|
|
62401
63374
|
throw new import_node_server_utils227.BadRequestError("Invalid user ID format.");
|
|
62402
63375
|
}
|
|
@@ -63151,38 +64124,38 @@ function useUserControllerV2() {
|
|
|
63151
64124
|
|
|
63152
64125
|
// src/models/role-v2.model.ts
|
|
63153
64126
|
var import_node_server_utils232 = require("@7365admin1/node-server-utils");
|
|
63154
|
-
var
|
|
64127
|
+
var import_mongodb135 = require("mongodb");
|
|
63155
64128
|
var MRoleV2 = class {
|
|
63156
64129
|
constructor(value) {
|
|
63157
64130
|
if (typeof value._id === "string") {
|
|
63158
64131
|
try {
|
|
63159
|
-
value._id = new
|
|
64132
|
+
value._id = new import_mongodb135.ObjectId(value._id);
|
|
63160
64133
|
} catch (error) {
|
|
63161
64134
|
throw new import_node_server_utils232.BadRequestError("Invalid role-v2 ID format.");
|
|
63162
64135
|
}
|
|
63163
64136
|
}
|
|
63164
64137
|
if (typeof value.site === "string" && value.site.length === 24) {
|
|
63165
64138
|
try {
|
|
63166
|
-
value.site = new
|
|
64139
|
+
value.site = new import_mongodb135.ObjectId(value.site);
|
|
63167
64140
|
} catch (error) {
|
|
63168
64141
|
throw new import_node_server_utils232.BadRequestError("Invalid site ID format.");
|
|
63169
64142
|
}
|
|
63170
64143
|
}
|
|
63171
64144
|
if (typeof value.org === "string" && value.org.length === 24) {
|
|
63172
64145
|
try {
|
|
63173
|
-
value.org = new
|
|
64146
|
+
value.org = new import_mongodb135.ObjectId(value.org);
|
|
63174
64147
|
} catch (error) {
|
|
63175
64148
|
throw new import_node_server_utils232.BadRequestError("Invalid org ID format.");
|
|
63176
64149
|
}
|
|
63177
64150
|
}
|
|
63178
64151
|
if (value.createdBy) {
|
|
63179
64152
|
try {
|
|
63180
|
-
value.createdBy = new
|
|
64153
|
+
value.createdBy = new import_mongodb135.ObjectId(value.createdBy);
|
|
63181
64154
|
} catch (error) {
|
|
63182
64155
|
throw new import_node_server_utils232.BadRequestError("Invalid created by ID format.");
|
|
63183
64156
|
}
|
|
63184
64157
|
}
|
|
63185
|
-
this._id = value._id ?? new
|
|
64158
|
+
this._id = value._id ?? new import_mongodb135.ObjectId();
|
|
63186
64159
|
this.name = value.name ?? "";
|
|
63187
64160
|
this.permissions = value.permissions ?? [];
|
|
63188
64161
|
this.site = value.site ?? "";
|
|
@@ -63317,7 +64290,7 @@ function useRoleControllerV2() {
|
|
|
63317
64290
|
|
|
63318
64291
|
// src/models/post-preloved.model.ts
|
|
63319
64292
|
var import_joi133 = __toESM(require("joi"));
|
|
63320
|
-
var
|
|
64293
|
+
var import_mongodb136 = require("mongodb");
|
|
63321
64294
|
var PostStatus = /* @__PURE__ */ ((PostStatus2) => {
|
|
63322
64295
|
PostStatus2["PUBLISHED"] = "published";
|
|
63323
64296
|
PostStatus2["RESERVED"] = "reserved";
|
|
@@ -63373,28 +64346,28 @@ function MPost(value) {
|
|
|
63373
64346
|
}
|
|
63374
64347
|
if (value._id && typeof value._id === "string") {
|
|
63375
64348
|
try {
|
|
63376
|
-
value._id = new
|
|
64349
|
+
value._id = new import_mongodb136.ObjectId(value._id);
|
|
63377
64350
|
} catch {
|
|
63378
64351
|
throw new Error("Invalid ID.");
|
|
63379
64352
|
}
|
|
63380
64353
|
}
|
|
63381
64354
|
if (value.site && typeof value.site === "string") {
|
|
63382
64355
|
try {
|
|
63383
|
-
value.site = new
|
|
64356
|
+
value.site = new import_mongodb136.ObjectId(value.site);
|
|
63384
64357
|
} catch {
|
|
63385
64358
|
throw new Error("Invalid site ID.");
|
|
63386
64359
|
}
|
|
63387
64360
|
}
|
|
63388
64361
|
if (value.createdBy && typeof value.createdBy === "string") {
|
|
63389
64362
|
try {
|
|
63390
|
-
value.createdBy = new
|
|
64363
|
+
value.createdBy = new import_mongodb136.ObjectId(value.createdBy);
|
|
63391
64364
|
} catch {
|
|
63392
64365
|
throw new Error("Invalid createdBy ID.");
|
|
63393
64366
|
}
|
|
63394
64367
|
}
|
|
63395
64368
|
if (value.reserverId && typeof value.reserverId === "string") {
|
|
63396
64369
|
try {
|
|
63397
|
-
value.reserverId = new
|
|
64370
|
+
value.reserverId = new import_mongodb136.ObjectId(value.reserverId);
|
|
63398
64371
|
} catch {
|
|
63399
64372
|
throw new Error("Invalid reserver ID.");
|
|
63400
64373
|
}
|
|
@@ -63403,7 +64376,7 @@ function MPost(value) {
|
|
|
63403
64376
|
value.attachments = value.attachments.map((id) => {
|
|
63404
64377
|
if (typeof id === "string") {
|
|
63405
64378
|
try {
|
|
63406
|
-
return new
|
|
64379
|
+
return new import_mongodb136.ObjectId(id);
|
|
63407
64380
|
} catch {
|
|
63408
64381
|
throw new Error("Invalid attachment ID.");
|
|
63409
64382
|
}
|
|
@@ -63413,20 +64386,20 @@ function MPost(value) {
|
|
|
63413
64386
|
}
|
|
63414
64387
|
if (value.category && typeof value.category === "string") {
|
|
63415
64388
|
try {
|
|
63416
|
-
value.category = new
|
|
64389
|
+
value.category = new import_mongodb136.ObjectId(value.category);
|
|
63417
64390
|
} catch {
|
|
63418
64391
|
throw new Error("Invalid category ID.");
|
|
63419
64392
|
}
|
|
63420
64393
|
}
|
|
63421
64394
|
if (value.subcategory && typeof value.subcategory === "string") {
|
|
63422
64395
|
try {
|
|
63423
|
-
value.subcategory = new
|
|
64396
|
+
value.subcategory = new import_mongodb136.ObjectId(value.subcategory);
|
|
63424
64397
|
} catch {
|
|
63425
64398
|
throw new Error("Invalid subcategory ID.");
|
|
63426
64399
|
}
|
|
63427
64400
|
}
|
|
63428
64401
|
return {
|
|
63429
|
-
_id: value._id ?? new
|
|
64402
|
+
_id: value._id ?? new import_mongodb136.ObjectId(),
|
|
63430
64403
|
title: value.title ?? "",
|
|
63431
64404
|
description: value.description ?? "",
|
|
63432
64405
|
attachments: value.attachments ?? [],
|
|
@@ -63446,7 +64419,7 @@ function MPost(value) {
|
|
|
63446
64419
|
|
|
63447
64420
|
// src/repositories/post-preloved.repo.ts
|
|
63448
64421
|
var import_node_server_utils235 = require("@7365admin1/node-server-utils");
|
|
63449
|
-
var
|
|
64422
|
+
var import_mongodb137 = require("mongodb");
|
|
63450
64423
|
function usePostPrelovedRepo() {
|
|
63451
64424
|
const db = import_node_server_utils235.useAtlas.getDb();
|
|
63452
64425
|
if (!db) {
|
|
@@ -63510,14 +64483,14 @@ function usePostPrelovedRepo() {
|
|
|
63510
64483
|
}
|
|
63511
64484
|
async function getById(_id, userId) {
|
|
63512
64485
|
try {
|
|
63513
|
-
_id = new
|
|
64486
|
+
_id = new import_mongodb137.ObjectId(_id);
|
|
63514
64487
|
} catch {
|
|
63515
64488
|
throw new import_node_server_utils235.BadRequestError("Invalid post ID format.");
|
|
63516
64489
|
}
|
|
63517
64490
|
let userObjectId = null;
|
|
63518
64491
|
if (userId) {
|
|
63519
64492
|
try {
|
|
63520
|
-
userObjectId = new
|
|
64493
|
+
userObjectId = new import_mongodb137.ObjectId(userId);
|
|
63521
64494
|
} catch {
|
|
63522
64495
|
throw new import_node_server_utils235.BadRequestError("Invalid user ID format.");
|
|
63523
64496
|
}
|
|
@@ -63587,7 +64560,7 @@ function usePostPrelovedRepo() {
|
|
|
63587
64560
|
page = page > 0 ? page - 1 : 0;
|
|
63588
64561
|
if (site) {
|
|
63589
64562
|
try {
|
|
63590
|
-
site = new
|
|
64563
|
+
site = new import_mongodb137.ObjectId(site);
|
|
63591
64564
|
} catch {
|
|
63592
64565
|
throw new import_node_server_utils235.BadRequestError("Invalid site ID format.");
|
|
63593
64566
|
}
|
|
@@ -63596,14 +64569,14 @@ function usePostPrelovedRepo() {
|
|
|
63596
64569
|
let subcategoryIds = null;
|
|
63597
64570
|
if (category && subcategory) {
|
|
63598
64571
|
try {
|
|
63599
|
-
categoryId = new
|
|
64572
|
+
categoryId = new import_mongodb137.ObjectId(category);
|
|
63600
64573
|
} catch {
|
|
63601
64574
|
throw new import_node_server_utils235.BadRequestError("Invalid category ID format.");
|
|
63602
64575
|
}
|
|
63603
64576
|
if (subcategory.length > 0) {
|
|
63604
64577
|
subcategoryIds = subcategory.map((id) => {
|
|
63605
64578
|
try {
|
|
63606
|
-
return new
|
|
64579
|
+
return new import_mongodb137.ObjectId(id);
|
|
63607
64580
|
} catch {
|
|
63608
64581
|
throw new import_node_server_utils235.BadRequestError("Invalid subcategory ID format.");
|
|
63609
64582
|
}
|
|
@@ -63628,7 +64601,7 @@ function usePostPrelovedRepo() {
|
|
|
63628
64601
|
let userObjectId = null;
|
|
63629
64602
|
if (userId) {
|
|
63630
64603
|
try {
|
|
63631
|
-
userObjectId = new
|
|
64604
|
+
userObjectId = new import_mongodb137.ObjectId(userId);
|
|
63632
64605
|
} catch {
|
|
63633
64606
|
throw new import_node_server_utils235.BadRequestError("Invalid user ID format.");
|
|
63634
64607
|
}
|
|
@@ -63677,7 +64650,7 @@ function usePostPrelovedRepo() {
|
|
|
63677
64650
|
}
|
|
63678
64651
|
async function updateById(_id, value, session) {
|
|
63679
64652
|
try {
|
|
63680
|
-
_id = new
|
|
64653
|
+
_id = new import_mongodb137.ObjectId(_id);
|
|
63681
64654
|
} catch {
|
|
63682
64655
|
throw new import_node_server_utils235.BadRequestError("Invalid post ID format.");
|
|
63683
64656
|
}
|
|
@@ -63698,7 +64671,7 @@ function usePostPrelovedRepo() {
|
|
|
63698
64671
|
}
|
|
63699
64672
|
async function deleteById(_id, session) {
|
|
63700
64673
|
try {
|
|
63701
|
-
_id = new
|
|
64674
|
+
_id = new import_mongodb137.ObjectId(_id);
|
|
63702
64675
|
} catch {
|
|
63703
64676
|
throw new import_node_server_utils235.BadRequestError("Invalid post ID format.");
|
|
63704
64677
|
}
|
|
@@ -63724,7 +64697,7 @@ function usePostPrelovedRepo() {
|
|
|
63724
64697
|
}
|
|
63725
64698
|
async function updateStatus(_id, status, session) {
|
|
63726
64699
|
try {
|
|
63727
|
-
_id = new
|
|
64700
|
+
_id = new import_mongodb137.ObjectId(_id);
|
|
63728
64701
|
} catch {
|
|
63729
64702
|
throw new import_node_server_utils235.BadRequestError("Invalid post ID format.");
|
|
63730
64703
|
}
|
|
@@ -63760,11 +64733,11 @@ var import_node_server_utils237 = require("@7365admin1/node-server-utils");
|
|
|
63760
64733
|
|
|
63761
64734
|
// src/repositories/post-favorite.repo.ts
|
|
63762
64735
|
var import_node_server_utils236 = require("@7365admin1/node-server-utils");
|
|
63763
|
-
var
|
|
64736
|
+
var import_mongodb139 = require("mongodb");
|
|
63764
64737
|
|
|
63765
64738
|
// src/models/post-favorite.model.ts
|
|
63766
64739
|
var import_joi134 = __toESM(require("joi"));
|
|
63767
|
-
var
|
|
64740
|
+
var import_mongodb138 = require("mongodb");
|
|
63768
64741
|
var schemaUpdatePostFavorite = import_joi134.default.object({
|
|
63769
64742
|
userId: import_joi134.default.string().hex().length(24).required()
|
|
63770
64743
|
});
|
|
@@ -63782,14 +64755,14 @@ function MPostFavorite(value) {
|
|
|
63782
64755
|
}
|
|
63783
64756
|
if (value._id && typeof value._id === "string") {
|
|
63784
64757
|
try {
|
|
63785
|
-
value._id = new
|
|
64758
|
+
value._id = new import_mongodb138.ObjectId(value._id);
|
|
63786
64759
|
} catch {
|
|
63787
64760
|
throw new Error("Invalid ID.");
|
|
63788
64761
|
}
|
|
63789
64762
|
}
|
|
63790
64763
|
if (value.postId && typeof value.postId === "string") {
|
|
63791
64764
|
try {
|
|
63792
|
-
value.postId = new
|
|
64765
|
+
value.postId = new import_mongodb138.ObjectId(value.postId);
|
|
63793
64766
|
} catch {
|
|
63794
64767
|
throw new Error("Invalid post ID.");
|
|
63795
64768
|
}
|
|
@@ -63798,7 +64771,7 @@ function MPostFavorite(value) {
|
|
|
63798
64771
|
value.userIds = value.userIds.map((id) => {
|
|
63799
64772
|
if (typeof id === "string") {
|
|
63800
64773
|
try {
|
|
63801
|
-
return new
|
|
64774
|
+
return new import_mongodb138.ObjectId(id);
|
|
63802
64775
|
} catch {
|
|
63803
64776
|
throw new Error("Invalid user ID.");
|
|
63804
64777
|
}
|
|
@@ -63807,7 +64780,7 @@ function MPostFavorite(value) {
|
|
|
63807
64780
|
});
|
|
63808
64781
|
}
|
|
63809
64782
|
return {
|
|
63810
|
-
_id: value._id ?? new
|
|
64783
|
+
_id: value._id ?? new import_mongodb138.ObjectId(),
|
|
63811
64784
|
postId: value.postId ?? "",
|
|
63812
64785
|
userIds: value.userIds ?? [],
|
|
63813
64786
|
createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -63837,7 +64810,7 @@ function usePostFavoriteRepo() {
|
|
|
63837
64810
|
}
|
|
63838
64811
|
async function getById(_id) {
|
|
63839
64812
|
try {
|
|
63840
|
-
_id = new
|
|
64813
|
+
_id = new import_mongodb139.ObjectId(_id);
|
|
63841
64814
|
} catch {
|
|
63842
64815
|
throw new import_node_server_utils236.BadRequestError("Invalid favorite ID format.");
|
|
63843
64816
|
}
|
|
@@ -63848,7 +64821,7 @@ function usePostFavoriteRepo() {
|
|
|
63848
64821
|
}
|
|
63849
64822
|
async function getByPostId(postId) {
|
|
63850
64823
|
try {
|
|
63851
|
-
postId = new
|
|
64824
|
+
postId = new import_mongodb139.ObjectId(postId);
|
|
63852
64825
|
} catch {
|
|
63853
64826
|
throw new import_node_server_utils236.BadRequestError("Invalid post ID format.");
|
|
63854
64827
|
}
|
|
@@ -63859,13 +64832,13 @@ function usePostFavoriteRepo() {
|
|
|
63859
64832
|
}
|
|
63860
64833
|
async function updateById(_id, userId, session) {
|
|
63861
64834
|
try {
|
|
63862
|
-
_id = new
|
|
64835
|
+
_id = new import_mongodb139.ObjectId(_id);
|
|
63863
64836
|
} catch {
|
|
63864
64837
|
throw new import_node_server_utils236.BadRequestError("Invalid favorite ID format.");
|
|
63865
64838
|
}
|
|
63866
64839
|
let userObjectId;
|
|
63867
64840
|
try {
|
|
63868
|
-
userObjectId = new
|
|
64841
|
+
userObjectId = new import_mongodb139.ObjectId(userId);
|
|
63869
64842
|
} catch {
|
|
63870
64843
|
throw new import_node_server_utils236.BadRequestError("Invalid user ID format.");
|
|
63871
64844
|
}
|
|
@@ -63896,7 +64869,7 @@ function usePostFavoriteRepo() {
|
|
|
63896
64869
|
}
|
|
63897
64870
|
|
|
63898
64871
|
// src/services/post-preloved.service.ts
|
|
63899
|
-
var
|
|
64872
|
+
var import_mongodb140 = require("mongodb");
|
|
63900
64873
|
function usePostFavoriteService() {
|
|
63901
64874
|
const { add: _addPost } = usePostPrelovedRepo();
|
|
63902
64875
|
const { addFavorite: _addFavorite } = usePostFavoriteRepo();
|
|
@@ -63914,7 +64887,7 @@ function usePostFavoriteService() {
|
|
|
63914
64887
|
let siteId = value.site;
|
|
63915
64888
|
let postId = post.toString();
|
|
63916
64889
|
if (value.site) {
|
|
63917
|
-
siteId = new
|
|
64890
|
+
siteId = new import_mongodb140.ObjectId(value.site);
|
|
63918
64891
|
}
|
|
63919
64892
|
if (post) {
|
|
63920
64893
|
postId = post.toString();
|
|
@@ -64273,7 +65246,7 @@ function usePostFavoriteController() {
|
|
|
64273
65246
|
|
|
64274
65247
|
// src/models/category-preloved.model.ts
|
|
64275
65248
|
var import_joi137 = __toESM(require("joi"));
|
|
64276
|
-
var
|
|
65249
|
+
var import_mongodb141 = require("mongodb");
|
|
64277
65250
|
var schemaCategoryPreloved = import_joi137.default.object({
|
|
64278
65251
|
name: import_joi137.default.string().required(),
|
|
64279
65252
|
createdBy: import_joi137.default.string().hex().optional().allow("", null),
|
|
@@ -64290,14 +65263,14 @@ function MCategoryPreloved(value) {
|
|
|
64290
65263
|
}
|
|
64291
65264
|
if (value.createdBy && typeof value.createdBy === "string") {
|
|
64292
65265
|
try {
|
|
64293
|
-
value.createdBy = new
|
|
65266
|
+
value.createdBy = new import_mongodb141.ObjectId(value.createdBy);
|
|
64294
65267
|
} catch {
|
|
64295
65268
|
throw new Error("Invalid createdBy ID.");
|
|
64296
65269
|
}
|
|
64297
65270
|
}
|
|
64298
65271
|
if (value.site && typeof value.site === "string") {
|
|
64299
65272
|
try {
|
|
64300
|
-
value.site = new
|
|
65273
|
+
value.site = new import_mongodb141.ObjectId(value.site);
|
|
64301
65274
|
} catch {
|
|
64302
65275
|
throw new Error("Invalid site ID.");
|
|
64303
65276
|
}
|
|
@@ -64313,7 +65286,7 @@ function MCategoryPreloved(value) {
|
|
|
64313
65286
|
|
|
64314
65287
|
// src/repositories/category-preloved.repo.ts
|
|
64315
65288
|
var import_node_server_utils241 = require("@7365admin1/node-server-utils");
|
|
64316
|
-
var
|
|
65289
|
+
var import_mongodb142 = require("mongodb");
|
|
64317
65290
|
function useCategoryPrelovedRepo() {
|
|
64318
65291
|
const db = import_node_server_utils241.useAtlas.getDb();
|
|
64319
65292
|
if (!db) {
|
|
@@ -64327,7 +65300,7 @@ function useCategoryPrelovedRepo() {
|
|
|
64327
65300
|
} = {}) {
|
|
64328
65301
|
if (site) {
|
|
64329
65302
|
try {
|
|
64330
|
-
site = new
|
|
65303
|
+
site = new import_mongodb142.ObjectId(site);
|
|
64331
65304
|
} catch {
|
|
64332
65305
|
throw new import_node_server_utils241.BadRequestError("Invalid site ID format.");
|
|
64333
65306
|
}
|
|
@@ -64346,7 +65319,7 @@ function useCategoryPrelovedRepo() {
|
|
|
64346
65319
|
async function getById(_id) {
|
|
64347
65320
|
let objectId2;
|
|
64348
65321
|
try {
|
|
64349
|
-
objectId2 = new
|
|
65322
|
+
objectId2 = new import_mongodb142.ObjectId(_id);
|
|
64350
65323
|
} catch {
|
|
64351
65324
|
throw new import_node_server_utils241.BadRequestError("Invalid category-preloved ID format.");
|
|
64352
65325
|
}
|
|
@@ -64376,7 +65349,7 @@ function useCategoryPrelovedRepo() {
|
|
|
64376
65349
|
async function updateById(_id, value) {
|
|
64377
65350
|
let objectId2;
|
|
64378
65351
|
try {
|
|
64379
|
-
objectId2 = new
|
|
65352
|
+
objectId2 = new import_mongodb142.ObjectId(_id);
|
|
64380
65353
|
} catch {
|
|
64381
65354
|
throw new import_node_server_utils241.BadRequestError("Invalid category ID format.");
|
|
64382
65355
|
}
|
|
@@ -64394,7 +65367,7 @@ function useCategoryPrelovedRepo() {
|
|
|
64394
65367
|
async function deleteById(_id) {
|
|
64395
65368
|
let objectId2;
|
|
64396
65369
|
try {
|
|
64397
|
-
objectId2 = new
|
|
65370
|
+
objectId2 = new import_mongodb142.ObjectId(_id);
|
|
64398
65371
|
} catch {
|
|
64399
65372
|
throw new import_node_server_utils241.BadRequestError("Invalid category ID format.");
|
|
64400
65373
|
}
|
|
@@ -64515,7 +65488,7 @@ function useCategoryPrelovedController() {
|
|
|
64515
65488
|
|
|
64516
65489
|
// src/models/subcategory-preloved.model.ts
|
|
64517
65490
|
var import_joi139 = __toESM(require("joi"));
|
|
64518
|
-
var
|
|
65491
|
+
var import_mongodb143 = require("mongodb");
|
|
64519
65492
|
var schemaSubcategoryPreloved = import_joi139.default.object({
|
|
64520
65493
|
name: import_joi139.default.string().required(),
|
|
64521
65494
|
createdBy: import_joi139.default.string().hex().optional().allow("", null),
|
|
@@ -64534,21 +65507,21 @@ function MSubcategoryPreloved(value) {
|
|
|
64534
65507
|
}
|
|
64535
65508
|
if (value.createdBy && typeof value.createdBy === "string") {
|
|
64536
65509
|
try {
|
|
64537
|
-
value.createdBy = new
|
|
65510
|
+
value.createdBy = new import_mongodb143.ObjectId(value.createdBy);
|
|
64538
65511
|
} catch {
|
|
64539
65512
|
throw new Error("Invalid createdBy ID.");
|
|
64540
65513
|
}
|
|
64541
65514
|
}
|
|
64542
65515
|
if (value.site && typeof value.site === "string") {
|
|
64543
65516
|
try {
|
|
64544
|
-
value.site = new
|
|
65517
|
+
value.site = new import_mongodb143.ObjectId(value.site);
|
|
64545
65518
|
} catch {
|
|
64546
65519
|
throw new Error("Invalid site ID.");
|
|
64547
65520
|
}
|
|
64548
65521
|
}
|
|
64549
65522
|
if (value.category_id && typeof value.category_id === "string") {
|
|
64550
65523
|
try {
|
|
64551
|
-
value.category_id = new
|
|
65524
|
+
value.category_id = new import_mongodb143.ObjectId(value.category_id);
|
|
64552
65525
|
} catch {
|
|
64553
65526
|
throw new Error("Invalid category ID.");
|
|
64554
65527
|
}
|
|
@@ -64565,7 +65538,7 @@ function MSubcategoryPreloved(value) {
|
|
|
64565
65538
|
|
|
64566
65539
|
// src/repositories/subcategory-preloved.repo.ts
|
|
64567
65540
|
var import_node_server_utils243 = require("@7365admin1/node-server-utils");
|
|
64568
|
-
var
|
|
65541
|
+
var import_mongodb144 = require("mongodb");
|
|
64569
65542
|
function useSubcategoryPrelovedRepo() {
|
|
64570
65543
|
const db = import_node_server_utils243.useAtlas.getDb();
|
|
64571
65544
|
if (!db) {
|
|
@@ -64580,14 +65553,14 @@ function useSubcategoryPrelovedRepo() {
|
|
|
64580
65553
|
} = {}) {
|
|
64581
65554
|
if (site) {
|
|
64582
65555
|
try {
|
|
64583
|
-
site = new
|
|
65556
|
+
site = new import_mongodb144.ObjectId(site);
|
|
64584
65557
|
} catch {
|
|
64585
65558
|
throw new import_node_server_utils243.BadRequestError("Invalid site ID format.");
|
|
64586
65559
|
}
|
|
64587
65560
|
}
|
|
64588
65561
|
if (category_id) {
|
|
64589
65562
|
try {
|
|
64590
|
-
category_id = new
|
|
65563
|
+
category_id = new import_mongodb144.ObjectId(category_id);
|
|
64591
65564
|
} catch {
|
|
64592
65565
|
throw new import_node_server_utils243.BadRequestError("Invalid category ID format.");
|
|
64593
65566
|
}
|
|
@@ -64606,7 +65579,7 @@ function useSubcategoryPrelovedRepo() {
|
|
|
64606
65579
|
async function getById(_id) {
|
|
64607
65580
|
let objectId2;
|
|
64608
65581
|
try {
|
|
64609
|
-
objectId2 = new
|
|
65582
|
+
objectId2 = new import_mongodb144.ObjectId(_id);
|
|
64610
65583
|
} catch {
|
|
64611
65584
|
throw new import_node_server_utils243.BadRequestError("Invalid subcategory-preloved ID format.");
|
|
64612
65585
|
}
|
|
@@ -64635,20 +65608,20 @@ function useSubcategoryPrelovedRepo() {
|
|
|
64635
65608
|
async function updateById(_id, value, session) {
|
|
64636
65609
|
let objectId2;
|
|
64637
65610
|
try {
|
|
64638
|
-
objectId2 = new
|
|
65611
|
+
objectId2 = new import_mongodb144.ObjectId(_id);
|
|
64639
65612
|
} catch {
|
|
64640
65613
|
throw new import_node_server_utils243.BadRequestError("Invalid subcategory ID format.");
|
|
64641
65614
|
}
|
|
64642
65615
|
if (value.category_id && typeof value.category_id === "string") {
|
|
64643
65616
|
try {
|
|
64644
|
-
value.category_id = new
|
|
65617
|
+
value.category_id = new import_mongodb144.ObjectId(value.category_id);
|
|
64645
65618
|
} catch {
|
|
64646
65619
|
throw new import_node_server_utils243.BadRequestError("Invalid category ID format.");
|
|
64647
65620
|
}
|
|
64648
65621
|
}
|
|
64649
65622
|
if (value.site && typeof value.site === "string") {
|
|
64650
65623
|
try {
|
|
64651
|
-
value.site = new
|
|
65624
|
+
value.site = new import_mongodb144.ObjectId(value.site);
|
|
64652
65625
|
} catch {
|
|
64653
65626
|
throw new import_node_server_utils243.BadRequestError("Invalid site ID format.");
|
|
64654
65627
|
}
|
|
@@ -64666,7 +65639,7 @@ function useSubcategoryPrelovedRepo() {
|
|
|
64666
65639
|
async function deleteById(_id, session) {
|
|
64667
65640
|
let objectId2;
|
|
64668
65641
|
try {
|
|
64669
|
-
objectId2 = new
|
|
65642
|
+
objectId2 = new import_mongodb144.ObjectId(_id);
|
|
64670
65643
|
} catch {
|
|
64671
65644
|
throw new import_node_server_utils243.BadRequestError("Invalid subcategory ID format.");
|
|
64672
65645
|
}
|
|
@@ -64798,7 +65771,7 @@ function useSubcategoryPrelovedController() {
|
|
|
64798
65771
|
|
|
64799
65772
|
// src/models/chat-preloved.model.ts
|
|
64800
65773
|
var import_joi141 = __toESM(require("joi"));
|
|
64801
|
-
var
|
|
65774
|
+
var import_mongodb145 = require("mongodb");
|
|
64802
65775
|
var schemaMessage = import_joi141.default.object({
|
|
64803
65776
|
text: import_joi141.default.string().required(),
|
|
64804
65777
|
date: import_joi141.default.date().optional().allow(null),
|
|
@@ -64829,7 +65802,7 @@ var schemaChatPreloved = import_joi141.default.object({
|
|
|
64829
65802
|
function toObjectId21(value, label) {
|
|
64830
65803
|
if (typeof value === "string") {
|
|
64831
65804
|
try {
|
|
64832
|
-
return new
|
|
65805
|
+
return new import_mongodb145.ObjectId(value);
|
|
64833
65806
|
} catch {
|
|
64834
65807
|
throw new Error(`Invalid ${label}.`);
|
|
64835
65808
|
}
|
|
@@ -64861,7 +65834,7 @@ function MChatPreloved(value) {
|
|
|
64861
65834
|
value.attachments = value.attachments.map((id) => toObjectId21(id, "attachment ID"));
|
|
64862
65835
|
}
|
|
64863
65836
|
return {
|
|
64864
|
-
_id: new
|
|
65837
|
+
_id: new import_mongodb145.ObjectId(),
|
|
64865
65838
|
channelId: value.channelId ?? "",
|
|
64866
65839
|
senderId: value.senderId ?? "",
|
|
64867
65840
|
postId: value.postId ?? null,
|
|
@@ -64885,7 +65858,7 @@ function MChatPreloved(value) {
|
|
|
64885
65858
|
|
|
64886
65859
|
// src/repositories/chat-preloved.repo.ts
|
|
64887
65860
|
var import_node_server_utils245 = require("@7365admin1/node-server-utils");
|
|
64888
|
-
var
|
|
65861
|
+
var import_mongodb146 = require("mongodb");
|
|
64889
65862
|
function useChatPrelovedRepo() {
|
|
64890
65863
|
const db = import_node_server_utils245.useAtlas.getDb();
|
|
64891
65864
|
if (!db)
|
|
@@ -64904,7 +65877,7 @@ function useChatPrelovedRepo() {
|
|
|
64904
65877
|
async function updateById(_id, value) {
|
|
64905
65878
|
let objectId2;
|
|
64906
65879
|
try {
|
|
64907
|
-
objectId2 = new
|
|
65880
|
+
objectId2 = new import_mongodb146.ObjectId(_id);
|
|
64908
65881
|
} catch {
|
|
64909
65882
|
throw new import_node_server_utils245.BadRequestError("Invalid chat ID format.");
|
|
64910
65883
|
}
|
|
@@ -64921,7 +65894,7 @@ function useChatPrelovedRepo() {
|
|
|
64921
65894
|
async function deleteById(_id) {
|
|
64922
65895
|
let objectId2;
|
|
64923
65896
|
try {
|
|
64924
|
-
objectId2 = new
|
|
65897
|
+
objectId2 = new import_mongodb146.ObjectId(_id);
|
|
64925
65898
|
} catch {
|
|
64926
65899
|
throw new import_node_server_utils245.BadRequestError("Invalid chat ID format.");
|
|
64927
65900
|
}
|
|
@@ -64940,79 +65913,28 @@ function useChatPrelovedRepo() {
|
|
|
64940
65913
|
}
|
|
64941
65914
|
|
|
64942
65915
|
// src/controllers/chat-preloved.controller.ts
|
|
65916
|
+
var import_node_server_utils248 = require("@7365admin1/node-server-utils");
|
|
65917
|
+
var import_joi143 = __toESM(require("joi"));
|
|
65918
|
+
|
|
65919
|
+
// src/services/chat-preloved.service.ts
|
|
65920
|
+
var import_node_server_utils247 = require("@7365admin1/node-server-utils");
|
|
65921
|
+
|
|
65922
|
+
// src/repositories/channel-preloved.repo.ts
|
|
64943
65923
|
var import_node_server_utils246 = require("@7365admin1/node-server-utils");
|
|
64944
|
-
var
|
|
64945
|
-
function useChatPrelovedController() {
|
|
64946
|
-
const { add: _add, updateById: _updateById, deleteById: _deleteById } = useChatPrelovedRepo();
|
|
64947
|
-
async function add(req, res, next) {
|
|
64948
|
-
const { error, value } = schemaChatPreloved.validate(req.body, {
|
|
64949
|
-
abortEarly: false
|
|
64950
|
-
});
|
|
64951
|
-
if (error) {
|
|
64952
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
64953
|
-
import_node_server_utils246.logger.log({ level: "error", message: messages });
|
|
64954
|
-
next(new import_node_server_utils246.BadRequestError(messages));
|
|
64955
|
-
return;
|
|
64956
|
-
}
|
|
64957
|
-
try {
|
|
64958
|
-
const data = await _add(value);
|
|
64959
|
-
res.status(201).json(data);
|
|
64960
|
-
} catch (error2) {
|
|
64961
|
-
import_node_server_utils246.logger.log({ level: "error", message: error2.message });
|
|
64962
|
-
next(error2);
|
|
64963
|
-
}
|
|
64964
|
-
}
|
|
64965
|
-
async function updateById(req, res, next) {
|
|
64966
|
-
const { error, value } = schemaUpdateChatPreloved.validate(req.body, {
|
|
64967
|
-
abortEarly: false
|
|
64968
|
-
});
|
|
64969
|
-
if (error) {
|
|
64970
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
64971
|
-
import_node_server_utils246.logger.log({ level: "error", message: messages });
|
|
64972
|
-
next(new import_node_server_utils246.BadRequestError(messages));
|
|
64973
|
-
return;
|
|
64974
|
-
}
|
|
64975
|
-
try {
|
|
64976
|
-
const data = await _updateById(req.params.id, value);
|
|
64977
|
-
res.status(200).json(data);
|
|
64978
|
-
} catch (error2) {
|
|
64979
|
-
import_node_server_utils246.logger.log({ level: "error", message: error2.message });
|
|
64980
|
-
next(error2);
|
|
64981
|
-
}
|
|
64982
|
-
}
|
|
64983
|
-
async function deleteById(req, res, next) {
|
|
64984
|
-
const schema2 = import_joi142.default.object({
|
|
64985
|
-
_id: import_joi142.default.string().hex().length(24).required()
|
|
64986
|
-
});
|
|
64987
|
-
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
64988
|
-
if (error) {
|
|
64989
|
-
import_node_server_utils246.logger.log({ level: "error", message: error.message });
|
|
64990
|
-
next(new import_node_server_utils246.BadRequestError(error.message));
|
|
64991
|
-
return;
|
|
64992
|
-
}
|
|
64993
|
-
try {
|
|
64994
|
-
const data = await _deleteById(value._id);
|
|
64995
|
-
res.status(200).json(data);
|
|
64996
|
-
} catch (error2) {
|
|
64997
|
-
import_node_server_utils246.logger.log({ level: "error", message: error2.message });
|
|
64998
|
-
next(error2);
|
|
64999
|
-
}
|
|
65000
|
-
}
|
|
65001
|
-
return { add, updateById, deleteById };
|
|
65002
|
-
}
|
|
65924
|
+
var import_mongodb148 = require("mongodb");
|
|
65003
65925
|
|
|
65004
65926
|
// src/models/channel-preloved.model.ts
|
|
65005
|
-
var
|
|
65006
|
-
var
|
|
65007
|
-
var schemaChannelPreloved =
|
|
65008
|
-
receiverId:
|
|
65009
|
-
senderId:
|
|
65010
|
-
postId:
|
|
65927
|
+
var import_joi142 = __toESM(require("joi"));
|
|
65928
|
+
var import_mongodb147 = require("mongodb");
|
|
65929
|
+
var schemaChannelPreloved = import_joi142.default.object({
|
|
65930
|
+
receiverId: import_joi142.default.string().hex().length(24).required(),
|
|
65931
|
+
senderId: import_joi142.default.string().hex().length(24).required(),
|
|
65932
|
+
postId: import_joi142.default.string().hex().length(24).required()
|
|
65011
65933
|
});
|
|
65012
65934
|
function toObjectId22(value, label) {
|
|
65013
65935
|
if (typeof value === "string") {
|
|
65014
65936
|
try {
|
|
65015
|
-
return new
|
|
65937
|
+
return new import_mongodb147.ObjectId(value);
|
|
65016
65938
|
} catch {
|
|
65017
65939
|
throw new Error(`Invalid ${label}.`);
|
|
65018
65940
|
}
|
|
@@ -65030,7 +65952,7 @@ function MChannelPreloved(value) {
|
|
|
65030
65952
|
if (value.postId)
|
|
65031
65953
|
value.postId = toObjectId22(value.postId, "post ID");
|
|
65032
65954
|
return {
|
|
65033
|
-
_id: new
|
|
65955
|
+
_id: new import_mongodb147.ObjectId(),
|
|
65034
65956
|
name: `seven365-${(/* @__PURE__ */ new Date()).getTime()}`,
|
|
65035
65957
|
receiverId: value.receiverId,
|
|
65036
65958
|
senderId: value.senderId,
|
|
@@ -65041,11 +65963,10 @@ function MChannelPreloved(value) {
|
|
|
65041
65963
|
}
|
|
65042
65964
|
|
|
65043
65965
|
// src/repositories/channel-preloved.repo.ts
|
|
65044
|
-
var import_node_server_utils247 = require("@7365admin1/node-server-utils");
|
|
65045
65966
|
function useChannelPrelovedRepo() {
|
|
65046
|
-
const db =
|
|
65967
|
+
const db = import_node_server_utils246.useAtlas.getDb();
|
|
65047
65968
|
if (!db)
|
|
65048
|
-
throw new
|
|
65969
|
+
throw new import_node_server_utils246.InternalServerError("Unable to connect to server.");
|
|
65049
65970
|
const CHANNEL_COLLECTION = "channel-preloved";
|
|
65050
65971
|
const collection = db.collection(CHANNEL_COLLECTION);
|
|
65051
65972
|
async function add(value, session) {
|
|
@@ -65057,11 +65978,130 @@ function useChannelPrelovedRepo() {
|
|
|
65057
65978
|
throw error;
|
|
65058
65979
|
}
|
|
65059
65980
|
}
|
|
65981
|
+
async function getByParticipants(senderId, receiverId, postId, session) {
|
|
65982
|
+
const query = {
|
|
65983
|
+
senderId: new import_mongodb148.ObjectId(senderId),
|
|
65984
|
+
receiverId: new import_mongodb148.ObjectId(receiverId),
|
|
65985
|
+
postId: new import_mongodb148.ObjectId(postId)
|
|
65986
|
+
};
|
|
65987
|
+
return collection.findOne(query, { session });
|
|
65988
|
+
}
|
|
65989
|
+
return { add, getByParticipants };
|
|
65990
|
+
}
|
|
65991
|
+
|
|
65992
|
+
// src/services/chat-preloved.service.ts
|
|
65993
|
+
function useChatPrelovedService() {
|
|
65994
|
+
const { add: _addChat } = useChatPrelovedRepo();
|
|
65995
|
+
const { add: _addChannel, getByParticipants: _getByParticipants } = useChannelPrelovedRepo();
|
|
65996
|
+
async function add(value) {
|
|
65997
|
+
const client = import_node_server_utils247.useAtlas.getClient();
|
|
65998
|
+
if (!client)
|
|
65999
|
+
throw new import_node_server_utils247.InternalServerError("Unable to connect to server.");
|
|
66000
|
+
const session = client.startSession();
|
|
66001
|
+
session.startTransaction();
|
|
66002
|
+
try {
|
|
66003
|
+
let channelId = value.channelId;
|
|
66004
|
+
if (!channelId) {
|
|
66005
|
+
if (!value.postId) {
|
|
66006
|
+
throw new import_node_server_utils247.BadRequestError("postId is required when creating a new channel.");
|
|
66007
|
+
}
|
|
66008
|
+
const existing = await _getByParticipants(
|
|
66009
|
+
value.senderId,
|
|
66010
|
+
value.receiverId,
|
|
66011
|
+
value.postId,
|
|
66012
|
+
session
|
|
66013
|
+
);
|
|
66014
|
+
if (existing) {
|
|
66015
|
+
channelId = existing._id.toString();
|
|
66016
|
+
} else {
|
|
66017
|
+
const newChannelId = await _addChannel(
|
|
66018
|
+
{
|
|
66019
|
+
receiverId: value.receiverId,
|
|
66020
|
+
senderId: value.senderId,
|
|
66021
|
+
postId: value.postId
|
|
66022
|
+
},
|
|
66023
|
+
session
|
|
66024
|
+
);
|
|
66025
|
+
channelId = newChannelId.toString();
|
|
66026
|
+
}
|
|
66027
|
+
}
|
|
66028
|
+
const { receiverId, ...chatPayload } = value;
|
|
66029
|
+
const insertedId = await _addChat({ ...chatPayload, channelId }, session);
|
|
66030
|
+
await session.commitTransaction();
|
|
66031
|
+
return { insertedId, channelId };
|
|
66032
|
+
} catch (error) {
|
|
66033
|
+
await session.abortTransaction();
|
|
66034
|
+
throw error;
|
|
66035
|
+
} finally {
|
|
66036
|
+
session.endSession();
|
|
66037
|
+
}
|
|
66038
|
+
}
|
|
65060
66039
|
return { add };
|
|
65061
66040
|
}
|
|
65062
66041
|
|
|
66042
|
+
// src/controllers/chat-preloved.controller.ts
|
|
66043
|
+
function useChatPrelovedController() {
|
|
66044
|
+
const { add: _add } = useChatPrelovedService();
|
|
66045
|
+
const { updateById: _updateById, deleteById: _deleteById } = useChatPrelovedRepo();
|
|
66046
|
+
async function add(req, res, next) {
|
|
66047
|
+
const { error, value } = schemaChatPreloved.validate(req.body, {
|
|
66048
|
+
abortEarly: false
|
|
66049
|
+
});
|
|
66050
|
+
if (error) {
|
|
66051
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
66052
|
+
import_node_server_utils248.logger.log({ level: "error", message: messages });
|
|
66053
|
+
next(new import_node_server_utils248.BadRequestError(messages));
|
|
66054
|
+
return;
|
|
66055
|
+
}
|
|
66056
|
+
try {
|
|
66057
|
+
const data = await _add(value);
|
|
66058
|
+
res.status(201).json(data);
|
|
66059
|
+
} catch (error2) {
|
|
66060
|
+
import_node_server_utils248.logger.log({ level: "error", message: error2.message });
|
|
66061
|
+
next(error2);
|
|
66062
|
+
}
|
|
66063
|
+
}
|
|
66064
|
+
async function updateById(req, res, next) {
|
|
66065
|
+
const { error, value } = schemaUpdateChatPreloved.validate(req.body, {
|
|
66066
|
+
abortEarly: false
|
|
66067
|
+
});
|
|
66068
|
+
if (error) {
|
|
66069
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
66070
|
+
import_node_server_utils248.logger.log({ level: "error", message: messages });
|
|
66071
|
+
next(new import_node_server_utils248.BadRequestError(messages));
|
|
66072
|
+
return;
|
|
66073
|
+
}
|
|
66074
|
+
try {
|
|
66075
|
+
const data = await _updateById(req.params.id, value);
|
|
66076
|
+
res.status(200).json(data);
|
|
66077
|
+
} catch (error2) {
|
|
66078
|
+
import_node_server_utils248.logger.log({ level: "error", message: error2.message });
|
|
66079
|
+
next(error2);
|
|
66080
|
+
}
|
|
66081
|
+
}
|
|
66082
|
+
async function deleteById(req, res, next) {
|
|
66083
|
+
const schema2 = import_joi143.default.object({
|
|
66084
|
+
_id: import_joi143.default.string().hex().length(24).required()
|
|
66085
|
+
});
|
|
66086
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
66087
|
+
if (error) {
|
|
66088
|
+
import_node_server_utils248.logger.log({ level: "error", message: error.message });
|
|
66089
|
+
next(new import_node_server_utils248.BadRequestError(error.message));
|
|
66090
|
+
return;
|
|
66091
|
+
}
|
|
66092
|
+
try {
|
|
66093
|
+
const data = await _deleteById(value._id);
|
|
66094
|
+
res.status(200).json(data);
|
|
66095
|
+
} catch (error2) {
|
|
66096
|
+
import_node_server_utils248.logger.log({ level: "error", message: error2.message });
|
|
66097
|
+
next(error2);
|
|
66098
|
+
}
|
|
66099
|
+
}
|
|
66100
|
+
return { add, updateById, deleteById };
|
|
66101
|
+
}
|
|
66102
|
+
|
|
65063
66103
|
// src/controllers/channel-preloved.controller.ts
|
|
65064
|
-
var
|
|
66104
|
+
var import_node_server_utils249 = require("@7365admin1/node-server-utils");
|
|
65065
66105
|
function useChannelPrelovedController() {
|
|
65066
66106
|
const { add: _add } = useChannelPrelovedRepo();
|
|
65067
66107
|
async function add(req, res, next) {
|
|
@@ -65070,15 +66110,15 @@ function useChannelPrelovedController() {
|
|
|
65070
66110
|
});
|
|
65071
66111
|
if (error) {
|
|
65072
66112
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
65073
|
-
|
|
65074
|
-
next(new
|
|
66113
|
+
import_node_server_utils249.logger.log({ level: "error", message: messages });
|
|
66114
|
+
next(new import_node_server_utils249.BadRequestError(messages));
|
|
65075
66115
|
return;
|
|
65076
66116
|
}
|
|
65077
66117
|
try {
|
|
65078
66118
|
const data = await _add(value);
|
|
65079
66119
|
res.status(201).json(data);
|
|
65080
66120
|
} catch (error2) {
|
|
65081
|
-
|
|
66121
|
+
import_node_server_utils249.logger.log({ level: "error", message: error2.message });
|
|
65082
66122
|
next(error2);
|
|
65083
66123
|
}
|
|
65084
66124
|
}
|
|
@@ -65087,7 +66127,7 @@ function useChannelPrelovedController() {
|
|
|
65087
66127
|
|
|
65088
66128
|
// src/models/online-forms-v2.model.ts
|
|
65089
66129
|
var import_joi144 = __toESM(require("joi"));
|
|
65090
|
-
var
|
|
66130
|
+
var import_mongodb149 = require("mongodb");
|
|
65091
66131
|
var FormEntryStatus = /* @__PURE__ */ ((FormEntryStatus2) => {
|
|
65092
66132
|
FormEntryStatus2["ACTIVE"] = "active";
|
|
65093
66133
|
FormEntryStatus2["INACTIVE"] = "inactive";
|
|
@@ -65145,21 +66185,21 @@ function MFormEntry(value) {
|
|
|
65145
66185
|
}
|
|
65146
66186
|
if (value._id && typeof value._id === "string") {
|
|
65147
66187
|
try {
|
|
65148
|
-
value._id = new
|
|
66188
|
+
value._id = new import_mongodb149.ObjectId(value._id);
|
|
65149
66189
|
} catch {
|
|
65150
66190
|
throw new Error("Invalid ID.");
|
|
65151
66191
|
}
|
|
65152
66192
|
}
|
|
65153
66193
|
if (value.org && typeof value.org === "string") {
|
|
65154
66194
|
try {
|
|
65155
|
-
value.org = new
|
|
66195
|
+
value.org = new import_mongodb149.ObjectId(value.org);
|
|
65156
66196
|
} catch {
|
|
65157
66197
|
throw new Error("Invalid org ID.");
|
|
65158
66198
|
}
|
|
65159
66199
|
}
|
|
65160
66200
|
if (value.site && typeof value.site === "string") {
|
|
65161
66201
|
try {
|
|
65162
|
-
value.site = new
|
|
66202
|
+
value.site = new import_mongodb149.ObjectId(value.site);
|
|
65163
66203
|
} catch {
|
|
65164
66204
|
throw new Error("Invalid site ID.");
|
|
65165
66205
|
}
|
|
@@ -65200,20 +66240,30 @@ var residentFormEntry = import_joi144.default.object({
|
|
|
65200
66240
|
userId: import_joi144.default.string().hex().optional().allow("", null),
|
|
65201
66241
|
createdAt: import_joi144.default.date().optional().allow("", null),
|
|
65202
66242
|
updatedAt: import_joi144.default.date().optional().allow("", null),
|
|
65203
|
-
deletedAt: import_joi144.default.date().optional().allow("", null)
|
|
66243
|
+
deletedAt: import_joi144.default.date().optional().allow("", null),
|
|
66244
|
+
remarks: import_joi144.default.string().optional().allow("", null),
|
|
66245
|
+
managementValues: import_joi144.default.object().pattern(
|
|
66246
|
+
import_joi144.default.string(),
|
|
66247
|
+
import_joi144.default.alternatives().try(
|
|
66248
|
+
import_joi144.default.string(),
|
|
66249
|
+
import_joi144.default.number(),
|
|
66250
|
+
import_joi144.default.boolean(),
|
|
66251
|
+
import_joi144.default.valid(null)
|
|
66252
|
+
)
|
|
66253
|
+
).optional().allow(null, "")
|
|
65204
66254
|
});
|
|
65205
66255
|
|
|
65206
66256
|
// src/repositories/online-forms-v2.repository.ts
|
|
65207
|
-
var
|
|
65208
|
-
var
|
|
66257
|
+
var import_node_server_utils250 = require("@7365admin1/node-server-utils");
|
|
66258
|
+
var import_mongodb150 = require("mongodb");
|
|
65209
66259
|
var online_forms_namespace_collection = "online-forms";
|
|
65210
66260
|
function useFormEntryRepo() {
|
|
65211
|
-
const db =
|
|
66261
|
+
const db = import_node_server_utils250.useAtlas.getDb();
|
|
65212
66262
|
if (!db) {
|
|
65213
|
-
throw new
|
|
66263
|
+
throw new import_node_server_utils250.InternalServerError("Unable to connect to server.");
|
|
65214
66264
|
}
|
|
65215
66265
|
const collection = db.collection(online_forms_namespace_collection);
|
|
65216
|
-
const { delNamespace, getCache, setCache } = (0,
|
|
66266
|
+
const { delNamespace, getCache, setCache } = (0, import_node_server_utils250.useCache)(
|
|
65217
66267
|
online_forms_namespace_collection
|
|
65218
66268
|
);
|
|
65219
66269
|
async function createTextIndex() {
|
|
@@ -65222,7 +66272,7 @@ function useFormEntryRepo() {
|
|
|
65222
66272
|
name: "text"
|
|
65223
66273
|
});
|
|
65224
66274
|
} catch (error) {
|
|
65225
|
-
throw new
|
|
66275
|
+
throw new import_node_server_utils250.InternalServerError(
|
|
65226
66276
|
"Failed to create text index on online form."
|
|
65227
66277
|
);
|
|
65228
66278
|
}
|
|
@@ -65232,11 +66282,11 @@ function useFormEntryRepo() {
|
|
|
65232
66282
|
value = MFormEntry(value);
|
|
65233
66283
|
const res = await collection.insertOne(value, { session });
|
|
65234
66284
|
delNamespace().then(() => {
|
|
65235
|
-
|
|
66285
|
+
import_node_server_utils250.logger.info(
|
|
65236
66286
|
`Cache cleared for namespace: ${online_forms_namespace_collection}`
|
|
65237
66287
|
);
|
|
65238
66288
|
}).catch((err) => {
|
|
65239
|
-
|
|
66289
|
+
import_node_server_utils250.logger.error(
|
|
65240
66290
|
`Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
|
|
65241
66291
|
err
|
|
65242
66292
|
);
|
|
@@ -65245,7 +66295,7 @@ function useFormEntryRepo() {
|
|
|
65245
66295
|
} catch (error) {
|
|
65246
66296
|
const isDuplicated = error.message.includes("duplicate");
|
|
65247
66297
|
if (isDuplicated) {
|
|
65248
|
-
throw new
|
|
66298
|
+
throw new import_node_server_utils250.BadRequestError("Online Form already exists.");
|
|
65249
66299
|
}
|
|
65250
66300
|
throw error;
|
|
65251
66301
|
}
|
|
@@ -65261,8 +66311,8 @@ function useFormEntryRepo() {
|
|
|
65261
66311
|
}) {
|
|
65262
66312
|
page = page > 0 ? page - 1 : 0;
|
|
65263
66313
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
65264
|
-
site = new
|
|
65265
|
-
org = new
|
|
66314
|
+
site = new import_mongodb150.ObjectId(site);
|
|
66315
|
+
org = new import_mongodb150.ObjectId(org);
|
|
65266
66316
|
const cacheOptions = {
|
|
65267
66317
|
page,
|
|
65268
66318
|
limit,
|
|
@@ -65282,13 +66332,13 @@ function useFormEntryRepo() {
|
|
|
65282
66332
|
{ unitNumber: { $regex: search, $options: "i" } }
|
|
65283
66333
|
];
|
|
65284
66334
|
}
|
|
65285
|
-
const cacheKey = (0,
|
|
66335
|
+
const cacheKey = (0, import_node_server_utils250.makeCacheKey)(
|
|
65286
66336
|
online_forms_namespace_collection,
|
|
65287
66337
|
cacheOptions
|
|
65288
66338
|
);
|
|
65289
66339
|
const cachedData = await getCache(cacheKey);
|
|
65290
66340
|
if (cachedData) {
|
|
65291
|
-
|
|
66341
|
+
import_node_server_utils250.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
65292
66342
|
return cachedData;
|
|
65293
66343
|
}
|
|
65294
66344
|
try {
|
|
@@ -65299,11 +66349,11 @@ function useFormEntryRepo() {
|
|
|
65299
66349
|
{ $limit: limit }
|
|
65300
66350
|
]).toArray();
|
|
65301
66351
|
const length = await collection.countDocuments(query);
|
|
65302
|
-
const data = (0,
|
|
66352
|
+
const data = (0, import_node_server_utils250.paginate)(items, page, limit, length);
|
|
65303
66353
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
65304
|
-
|
|
66354
|
+
import_node_server_utils250.logger.info(`Cache set for key: ${cacheKey}`);
|
|
65305
66355
|
}).catch((err) => {
|
|
65306
|
-
|
|
66356
|
+
import_node_server_utils250.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
65307
66357
|
});
|
|
65308
66358
|
return data;
|
|
65309
66359
|
} catch (error) {
|
|
@@ -65311,27 +66361,27 @@ function useFormEntryRepo() {
|
|
|
65311
66361
|
}
|
|
65312
66362
|
}
|
|
65313
66363
|
async function getFormEntryById(_id) {
|
|
65314
|
-
const cacheKey = (0,
|
|
66364
|
+
const cacheKey = (0, import_node_server_utils250.makeCacheKey)(online_forms_namespace_collection, { _id });
|
|
65315
66365
|
const cachedData = await getCache(cacheKey);
|
|
65316
66366
|
if (cachedData) {
|
|
65317
|
-
|
|
66367
|
+
import_node_server_utils250.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
65318
66368
|
return cachedData;
|
|
65319
66369
|
}
|
|
65320
66370
|
try {
|
|
65321
|
-
_id = new
|
|
66371
|
+
_id = new import_mongodb150.ObjectId(_id);
|
|
65322
66372
|
} catch (error) {
|
|
65323
|
-
throw new
|
|
66373
|
+
throw new import_node_server_utils250.BadRequestError("Invalid online form ID format.");
|
|
65324
66374
|
}
|
|
65325
66375
|
const query = { _id, status: { $ne: "deleted" } };
|
|
65326
66376
|
try {
|
|
65327
66377
|
const [data] = await collection.aggregate([{ $match: query }]).toArray();
|
|
65328
66378
|
if (!data) {
|
|
65329
|
-
throw new
|
|
66379
|
+
throw new import_node_server_utils250.NotFoundError("Document not found.");
|
|
65330
66380
|
}
|
|
65331
66381
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
65332
|
-
|
|
66382
|
+
import_node_server_utils250.logger.info(`Cache set for key: ${cacheKey}`);
|
|
65333
66383
|
}).catch((err) => {
|
|
65334
|
-
|
|
66384
|
+
import_node_server_utils250.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
65335
66385
|
});
|
|
65336
66386
|
return data;
|
|
65337
66387
|
} catch (error) {
|
|
@@ -65340,9 +66390,9 @@ function useFormEntryRepo() {
|
|
|
65340
66390
|
}
|
|
65341
66391
|
async function updateFormEntryById(_id, value) {
|
|
65342
66392
|
try {
|
|
65343
|
-
_id = new
|
|
66393
|
+
_id = new import_mongodb150.ObjectId(_id);
|
|
65344
66394
|
} catch (error) {
|
|
65345
|
-
throw new
|
|
66395
|
+
throw new import_node_server_utils250.BadRequestError("Invalid online form ID format.");
|
|
65346
66396
|
}
|
|
65347
66397
|
try {
|
|
65348
66398
|
const updateValue = {
|
|
@@ -65351,14 +66401,14 @@ function useFormEntryRepo() {
|
|
|
65351
66401
|
};
|
|
65352
66402
|
const res = await collection.updateOne({ _id }, { $set: updateValue });
|
|
65353
66403
|
if (res.modifiedCount === 0) {
|
|
65354
|
-
throw new
|
|
66404
|
+
throw new import_node_server_utils250.InternalServerError("Unable to update online form.");
|
|
65355
66405
|
}
|
|
65356
66406
|
delNamespace().then(() => {
|
|
65357
|
-
|
|
66407
|
+
import_node_server_utils250.logger.info(
|
|
65358
66408
|
`Cache cleared for namespace: ${online_forms_namespace_collection}`
|
|
65359
66409
|
);
|
|
65360
66410
|
}).catch((err) => {
|
|
65361
|
-
|
|
66411
|
+
import_node_server_utils250.logger.error(
|
|
65362
66412
|
`Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
|
|
65363
66413
|
err
|
|
65364
66414
|
);
|
|
@@ -65370,9 +66420,9 @@ function useFormEntryRepo() {
|
|
|
65370
66420
|
}
|
|
65371
66421
|
async function deleteOnlineFormById(_id, session) {
|
|
65372
66422
|
try {
|
|
65373
|
-
_id = new
|
|
66423
|
+
_id = new import_mongodb150.ObjectId(_id);
|
|
65374
66424
|
} catch (error) {
|
|
65375
|
-
throw new
|
|
66425
|
+
throw new import_node_server_utils250.BadRequestError("Invalid online form ID format.");
|
|
65376
66426
|
}
|
|
65377
66427
|
try {
|
|
65378
66428
|
const updateValue = {
|
|
@@ -65386,12 +66436,12 @@ function useFormEntryRepo() {
|
|
|
65386
66436
|
{ session }
|
|
65387
66437
|
);
|
|
65388
66438
|
if (res.modifiedCount === 0) {
|
|
65389
|
-
throw new
|
|
66439
|
+
throw new import_node_server_utils250.InternalServerError("Unable to delete online form.");
|
|
65390
66440
|
}
|
|
65391
66441
|
delNamespace().then(() => {
|
|
65392
|
-
|
|
66442
|
+
import_node_server_utils250.logger.info(`Cache cleared for namespace: ${online_forms_namespace_collection}`);
|
|
65393
66443
|
}).catch((err) => {
|
|
65394
|
-
|
|
66444
|
+
import_node_server_utils250.logger.error(
|
|
65395
66445
|
`Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
|
|
65396
66446
|
err
|
|
65397
66447
|
);
|
|
@@ -65403,16 +66453,16 @@ function useFormEntryRepo() {
|
|
|
65403
66453
|
}
|
|
65404
66454
|
async function addResidentForm(value, session) {
|
|
65405
66455
|
try {
|
|
65406
|
-
value.site = new
|
|
65407
|
-
value.org = new
|
|
65408
|
-
value.userId = new
|
|
66456
|
+
value.site = new import_mongodb150.ObjectId(value.site);
|
|
66457
|
+
value.org = new import_mongodb150.ObjectId(value.org);
|
|
66458
|
+
value.userId = new import_mongodb150.ObjectId(value.userId);
|
|
65409
66459
|
const res = await collection.insertOne(value, { session });
|
|
65410
66460
|
delNamespace().then(() => {
|
|
65411
|
-
|
|
66461
|
+
import_node_server_utils250.logger.info(
|
|
65412
66462
|
`Cache cleared for namespace: ${online_forms_namespace_collection}`
|
|
65413
66463
|
);
|
|
65414
66464
|
}).catch((err) => {
|
|
65415
|
-
|
|
66465
|
+
import_node_server_utils250.logger.error(
|
|
65416
66466
|
`Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
|
|
65417
66467
|
err
|
|
65418
66468
|
);
|
|
@@ -65421,16 +66471,16 @@ function useFormEntryRepo() {
|
|
|
65421
66471
|
} catch (error) {
|
|
65422
66472
|
const isDuplicated = error.message.includes("duplicate");
|
|
65423
66473
|
if (isDuplicated) {
|
|
65424
|
-
throw new
|
|
66474
|
+
throw new import_node_server_utils250.BadRequestError("Online Form already exists.");
|
|
65425
66475
|
}
|
|
65426
66476
|
throw error;
|
|
65427
66477
|
}
|
|
65428
66478
|
}
|
|
65429
66479
|
async function residentForm({ userId, site, org }) {
|
|
65430
66480
|
try {
|
|
65431
|
-
const user = new
|
|
65432
|
-
const siteId = new
|
|
65433
|
-
const orgId = new
|
|
66481
|
+
const user = new import_mongodb150.ObjectId(userId);
|
|
66482
|
+
const siteId = new import_mongodb150.ObjectId(site);
|
|
66483
|
+
const orgId = new import_mongodb150.ObjectId(org);
|
|
65434
66484
|
const res = await collection.aggregate([
|
|
65435
66485
|
{
|
|
65436
66486
|
$match: {
|
|
@@ -65458,7 +66508,7 @@ function useFormEntryRepo() {
|
|
|
65458
66508
|
}
|
|
65459
66509
|
|
|
65460
66510
|
// src/controllers/online-forms-v2.controller.ts
|
|
65461
|
-
var
|
|
66511
|
+
var import_node_server_utils251 = require("@7365admin1/node-server-utils");
|
|
65462
66512
|
var import_joi145 = __toESM(require("joi"));
|
|
65463
66513
|
var import_exceljs3 = __toESM(require("exceljs"));
|
|
65464
66514
|
var import_fs7 = __toESM(require("fs"));
|
|
@@ -65485,14 +66535,14 @@ function useFormEntryController() {
|
|
|
65485
66535
|
async function uploadFormEntrys(req, res, next) {
|
|
65486
66536
|
try {
|
|
65487
66537
|
if (!req.file) {
|
|
65488
|
-
next(new
|
|
66538
|
+
next(new import_node_server_utils251.BadRequestError("Excel file is required."));
|
|
65489
66539
|
return;
|
|
65490
66540
|
}
|
|
65491
66541
|
const workbook = new import_exceljs3.default.Workbook();
|
|
65492
66542
|
await workbook.xlsx.readFile(req.file.path);
|
|
65493
66543
|
const worksheet = workbook.worksheets[0];
|
|
65494
66544
|
if (!worksheet) {
|
|
65495
|
-
next(new
|
|
66545
|
+
next(new import_node_server_utils251.BadRequestError("No worksheet found in uploaded Excel file."));
|
|
65496
66546
|
return;
|
|
65497
66547
|
}
|
|
65498
66548
|
const headerRow = worksheet.getRow(1);
|
|
@@ -65520,8 +66570,8 @@ function useFormEntryController() {
|
|
|
65520
66570
|
});
|
|
65521
66571
|
if (error) {
|
|
65522
66572
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
65523
|
-
|
|
65524
|
-
next(new
|
|
66573
|
+
import_node_server_utils251.logger.log({ level: "error", message: messages });
|
|
66574
|
+
next(new import_node_server_utils251.BadRequestError(messages));
|
|
65525
66575
|
return;
|
|
65526
66576
|
}
|
|
65527
66577
|
const result = await _add(value);
|
|
@@ -65529,7 +66579,7 @@ function useFormEntryController() {
|
|
|
65529
66579
|
import_fs7.default.unlink(req.file.path, () => {
|
|
65530
66580
|
});
|
|
65531
66581
|
} catch (error) {
|
|
65532
|
-
|
|
66582
|
+
import_node_server_utils251.logger.log({ level: "error", message: error.message });
|
|
65533
66583
|
next(error);
|
|
65534
66584
|
}
|
|
65535
66585
|
}
|
|
@@ -65546,8 +66596,8 @@ function useFormEntryController() {
|
|
|
65546
66596
|
const { error, value } = schema2.validate(req.query);
|
|
65547
66597
|
if (error) {
|
|
65548
66598
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
65549
|
-
|
|
65550
|
-
next(new
|
|
66599
|
+
import_node_server_utils251.logger.log({ level: "error", message: messages });
|
|
66600
|
+
next(new import_node_server_utils251.BadRequestError(messages));
|
|
65551
66601
|
return;
|
|
65552
66602
|
}
|
|
65553
66603
|
const { search, page, limit, status, org, site } = value;
|
|
@@ -65555,7 +66605,7 @@ function useFormEntryController() {
|
|
|
65555
66605
|
res.json(data);
|
|
65556
66606
|
return;
|
|
65557
66607
|
} catch (error) {
|
|
65558
|
-
|
|
66608
|
+
import_node_server_utils251.logger.log({ level: "error", message: error.message });
|
|
65559
66609
|
next(error);
|
|
65560
66610
|
return;
|
|
65561
66611
|
}
|
|
@@ -65568,8 +66618,8 @@ function useFormEntryController() {
|
|
|
65568
66618
|
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
65569
66619
|
if (error) {
|
|
65570
66620
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
65571
|
-
|
|
65572
|
-
next(new
|
|
66621
|
+
import_node_server_utils251.logger.log({ level: "error", message: messages });
|
|
66622
|
+
next(new import_node_server_utils251.BadRequestError(messages));
|
|
65573
66623
|
return;
|
|
65574
66624
|
}
|
|
65575
66625
|
const { _id } = value;
|
|
@@ -65577,7 +66627,7 @@ function useFormEntryController() {
|
|
|
65577
66627
|
res.json(data);
|
|
65578
66628
|
return;
|
|
65579
66629
|
} catch (error) {
|
|
65580
|
-
|
|
66630
|
+
import_node_server_utils251.logger.log({ level: "error", message: error.message });
|
|
65581
66631
|
next(error);
|
|
65582
66632
|
return;
|
|
65583
66633
|
}
|
|
@@ -65590,8 +66640,8 @@ function useFormEntryController() {
|
|
|
65590
66640
|
});
|
|
65591
66641
|
if (error) {
|
|
65592
66642
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
65593
|
-
|
|
65594
|
-
next(new
|
|
66643
|
+
import_node_server_utils251.logger.log({ level: "error", message: messages });
|
|
66644
|
+
next(new import_node_server_utils251.BadRequestError(messages));
|
|
65595
66645
|
return;
|
|
65596
66646
|
}
|
|
65597
66647
|
const { _id, ...rest } = value;
|
|
@@ -65599,7 +66649,7 @@ function useFormEntryController() {
|
|
|
65599
66649
|
res.json({ message: "Successfully updated online form." });
|
|
65600
66650
|
return;
|
|
65601
66651
|
} catch (error) {
|
|
65602
|
-
|
|
66652
|
+
import_node_server_utils251.logger.log({ level: "error", message: error.message });
|
|
65603
66653
|
next(error);
|
|
65604
66654
|
return;
|
|
65605
66655
|
}
|
|
@@ -65610,15 +66660,15 @@ function useFormEntryController() {
|
|
|
65610
66660
|
const _id = req.params.id;
|
|
65611
66661
|
const { error } = validation.validate(_id);
|
|
65612
66662
|
if (error) {
|
|
65613
|
-
|
|
65614
|
-
next(new
|
|
66663
|
+
import_node_server_utils251.logger.log({ level: "error", message: error.message });
|
|
66664
|
+
next(new import_node_server_utils251.BadRequestError(error.message));
|
|
65615
66665
|
return;
|
|
65616
66666
|
}
|
|
65617
66667
|
await _deleteOnlineFormById(_id);
|
|
65618
66668
|
res.json({ message: "Successfully deleted online form." });
|
|
65619
66669
|
return;
|
|
65620
66670
|
} catch (error) {
|
|
65621
|
-
|
|
66671
|
+
import_node_server_utils251.logger.log({ level: "error", message: error.message });
|
|
65622
66672
|
next(error);
|
|
65623
66673
|
return;
|
|
65624
66674
|
}
|
|
@@ -65635,8 +66685,8 @@ function useFormEntryController() {
|
|
|
65635
66685
|
});
|
|
65636
66686
|
if (error) {
|
|
65637
66687
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
65638
|
-
|
|
65639
|
-
next(new
|
|
66688
|
+
import_node_server_utils251.logger.log({ level: "error", message: messages });
|
|
66689
|
+
next(new import_node_server_utils251.BadRequestError(messages));
|
|
65640
66690
|
return;
|
|
65641
66691
|
}
|
|
65642
66692
|
try {
|
|
@@ -65644,7 +66694,7 @@ function useFormEntryController() {
|
|
|
65644
66694
|
res.status(201).json({ message: data });
|
|
65645
66695
|
return;
|
|
65646
66696
|
} catch (error2) {
|
|
65647
|
-
|
|
66697
|
+
import_node_server_utils251.logger.log({ level: "error", message: error2.message });
|
|
65648
66698
|
next(error2);
|
|
65649
66699
|
return;
|
|
65650
66700
|
}
|
|
@@ -65656,8 +66706,8 @@ function useFormEntryController() {
|
|
|
65656
66706
|
});
|
|
65657
66707
|
if (error) {
|
|
65658
66708
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
65659
|
-
|
|
65660
|
-
next(new
|
|
66709
|
+
import_node_server_utils251.logger.log({ level: "error", message: messages });
|
|
66710
|
+
next(new import_node_server_utils251.BadRequestError(messages));
|
|
65661
66711
|
return;
|
|
65662
66712
|
}
|
|
65663
66713
|
try {
|
|
@@ -65665,7 +66715,7 @@ function useFormEntryController() {
|
|
|
65665
66715
|
res.status(201).json({ message: data });
|
|
65666
66716
|
return;
|
|
65667
66717
|
} catch (error2) {
|
|
65668
|
-
|
|
66718
|
+
import_node_server_utils251.logger.log({ level: "error", message: error2.message });
|
|
65669
66719
|
next(error2);
|
|
65670
66720
|
return;
|
|
65671
66721
|
}
|
|
@@ -65681,14 +66731,14 @@ function useFormEntryController() {
|
|
|
65681
66731
|
const { error } = residentFormPayload.validate({ site, userId, org }, { abortEarly: true });
|
|
65682
66732
|
if (error) {
|
|
65683
66733
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
65684
|
-
|
|
65685
|
-
next(new
|
|
66734
|
+
import_node_server_utils251.logger.log({ level: "error", message: messages });
|
|
66735
|
+
next(new import_node_server_utils251.BadRequestError(messages));
|
|
65686
66736
|
return;
|
|
65687
66737
|
}
|
|
65688
66738
|
const result = await _residentForm({ userId, site, org });
|
|
65689
66739
|
res.json(result);
|
|
65690
66740
|
} catch (error) {
|
|
65691
|
-
|
|
66741
|
+
import_node_server_utils251.logger.log({ level: "error", message: error.message });
|
|
65692
66742
|
next(error);
|
|
65693
66743
|
return;
|
|
65694
66744
|
}
|
|
@@ -65706,11 +66756,11 @@ function useFormEntryController() {
|
|
|
65706
66756
|
}
|
|
65707
66757
|
|
|
65708
66758
|
// src/services/building-level.service.ts
|
|
65709
|
-
var
|
|
66759
|
+
var import_node_server_utils252 = require("@7365admin1/node-server-utils");
|
|
65710
66760
|
function useBuildingLevelService() {
|
|
65711
66761
|
const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelRepo();
|
|
65712
66762
|
async function add(value) {
|
|
65713
|
-
const session =
|
|
66763
|
+
const session = import_node_server_utils252.useAtlas.getClient()?.startSession();
|
|
65714
66764
|
try {
|
|
65715
66765
|
session?.startTransaction();
|
|
65716
66766
|
await _add(value, session);
|
|
@@ -65724,7 +66774,7 @@ function useBuildingLevelService() {
|
|
|
65724
66774
|
}
|
|
65725
66775
|
}
|
|
65726
66776
|
async function updateLevelById(_id, value) {
|
|
65727
|
-
const session =
|
|
66777
|
+
const session = import_node_server_utils252.useAtlas.getClient()?.startSession();
|
|
65728
66778
|
try {
|
|
65729
66779
|
session?.startTransaction();
|
|
65730
66780
|
await _updateLevelById(_id, value, session);
|
|
@@ -65744,7 +66794,7 @@ function useBuildingLevelService() {
|
|
|
65744
66794
|
}
|
|
65745
66795
|
|
|
65746
66796
|
// src/controllers/building-level.controller.ts
|
|
65747
|
-
var
|
|
66797
|
+
var import_node_server_utils253 = require("@7365admin1/node-server-utils");
|
|
65748
66798
|
var import_joi146 = __toESM(require("joi"));
|
|
65749
66799
|
function useBuildingLevelController() {
|
|
65750
66800
|
const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelService();
|
|
@@ -65762,8 +66812,8 @@ function useBuildingLevelController() {
|
|
|
65762
66812
|
});
|
|
65763
66813
|
if (error) {
|
|
65764
66814
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
65765
|
-
|
|
65766
|
-
next(new
|
|
66815
|
+
import_node_server_utils253.logger.log({ level: "error", message: messages });
|
|
66816
|
+
next(new import_node_server_utils253.BadRequestError(messages));
|
|
65767
66817
|
return;
|
|
65768
66818
|
}
|
|
65769
66819
|
const result = await _add(value);
|
|
@@ -65786,8 +66836,8 @@ function useBuildingLevelController() {
|
|
|
65786
66836
|
});
|
|
65787
66837
|
if (error) {
|
|
65788
66838
|
const messages = error.details.map((d) => d.message);
|
|
65789
|
-
|
|
65790
|
-
next(new
|
|
66839
|
+
import_node_server_utils253.logger.log({ level: "error", message: messages.join(", ") });
|
|
66840
|
+
next(new import_node_server_utils253.BadRequestError(messages.join(", ")));
|
|
65791
66841
|
return;
|
|
65792
66842
|
}
|
|
65793
66843
|
const { page, limit, status, site, search } = value;
|
|
@@ -65812,8 +66862,8 @@ function useBuildingLevelController() {
|
|
|
65812
66862
|
const { error, value } = schema2.validate({ id: req.params.id });
|
|
65813
66863
|
if (error) {
|
|
65814
66864
|
const messages = error.details.map((d) => d.message);
|
|
65815
|
-
|
|
65816
|
-
next(new
|
|
66865
|
+
import_node_server_utils253.logger.log({ level: "error", message: messages.join(", ") });
|
|
66866
|
+
next(new import_node_server_utils253.BadRequestError(messages.join(", ")));
|
|
65817
66867
|
return;
|
|
65818
66868
|
}
|
|
65819
66869
|
const { id } = value;
|
|
@@ -65832,8 +66882,8 @@ function useBuildingLevelController() {
|
|
|
65832
66882
|
});
|
|
65833
66883
|
if (error) {
|
|
65834
66884
|
const messages = error.details.map((d) => d.message);
|
|
65835
|
-
|
|
65836
|
-
next(new
|
|
66885
|
+
import_node_server_utils253.logger.log({ level: "error", message: messages.join(", ") });
|
|
66886
|
+
next(new import_node_server_utils253.BadRequestError(messages.join(", ")));
|
|
65837
66887
|
return;
|
|
65838
66888
|
}
|
|
65839
66889
|
const { _id, ...rest } = value;
|
|
@@ -65851,8 +66901,8 @@ function useBuildingLevelController() {
|
|
|
65851
66901
|
const { error, value } = schema2.validate({ id: req.params.id });
|
|
65852
66902
|
if (error) {
|
|
65853
66903
|
const messages = error.details.map((d) => d.message);
|
|
65854
|
-
|
|
65855
|
-
next(new
|
|
66904
|
+
import_node_server_utils253.logger.log({ level: "error", message: messages.join(", ") });
|
|
66905
|
+
next(new import_node_server_utils253.BadRequestError(messages.join(", ")));
|
|
65856
66906
|
return;
|
|
65857
66907
|
}
|
|
65858
66908
|
const { id } = value;
|
|
@@ -65876,8 +66926,8 @@ function useBuildingLevelController() {
|
|
|
65876
66926
|
const { error, value } = schema2.validate(req.body);
|
|
65877
66927
|
if (error) {
|
|
65878
66928
|
const messages = error.details.map((d) => d.message);
|
|
65879
|
-
|
|
65880
|
-
next(new
|
|
66929
|
+
import_node_server_utils253.logger.log({ level: "error", message: messages.join(", ") });
|
|
66930
|
+
next(new import_node_server_utils253.BadRequestError(messages.join(", ")));
|
|
65881
66931
|
return;
|
|
65882
66932
|
}
|
|
65883
66933
|
const updates = value.map((item) => ({
|
|
@@ -65902,8 +66952,8 @@ function useBuildingLevelController() {
|
|
|
65902
66952
|
});
|
|
65903
66953
|
if (error) {
|
|
65904
66954
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
65905
|
-
|
|
65906
|
-
next(new
|
|
66955
|
+
import_node_server_utils253.logger.log({ level: "error", message: messages });
|
|
66956
|
+
next(new import_node_server_utils253.BadRequestError(messages));
|
|
65907
66957
|
return;
|
|
65908
66958
|
}
|
|
65909
66959
|
const { site, block } = value;
|
|
@@ -66030,7 +67080,6 @@ function useBuildingLevelController() {
|
|
|
66030
67080
|
OvernightParkingRequestSort,
|
|
66031
67081
|
OvernightParkingRequestStatus,
|
|
66032
67082
|
PERSON_TYPES,
|
|
66033
|
-
PMDashboardCollection,
|
|
66034
67083
|
PStatus,
|
|
66035
67084
|
Period,
|
|
66036
67085
|
PersonStatus,
|
|
@@ -66083,8 +67132,6 @@ function useBuildingLevelController() {
|
|
|
66083
67132
|
guests_namespace_collection,
|
|
66084
67133
|
incidentReportLog,
|
|
66085
67134
|
incidents_namespace_collection,
|
|
66086
|
-
landscapeDashboardCollection,
|
|
66087
|
-
mAndEDashboardCollection,
|
|
66088
67135
|
manpowerDesignationsSchema,
|
|
66089
67136
|
manpowerEvents,
|
|
66090
67137
|
manpowerMonitoringSchema,
|
|
@@ -66097,8 +67144,6 @@ function useBuildingLevelController() {
|
|
|
66097
67144
|
orgSchema,
|
|
66098
67145
|
overnight_parking_requests_namespace_collection,
|
|
66099
67146
|
parseDahuaFind,
|
|
66100
|
-
pestDashboardCollection,
|
|
66101
|
-
poolDashboardCollection,
|
|
66102
67147
|
promoCodeSchema,
|
|
66103
67148
|
remarksSchema,
|
|
66104
67149
|
residentFormEntry,
|
|
@@ -66189,7 +67234,6 @@ function useBuildingLevelController() {
|
|
|
66189
67234
|
schemaVisitorTransaction,
|
|
66190
67235
|
schemeCamera,
|
|
66191
67236
|
schemeLogCamera,
|
|
66192
|
-
securityDashboardCollection,
|
|
66193
67237
|
shiftSchema,
|
|
66194
67238
|
siteSchema,
|
|
66195
67239
|
site_people_namespace_collection,
|