@7365admin1/core 2.8.0 → 2.10.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 +12 -0
- package/dist/index.d.ts +98 -8
- package/dist/index.js +758 -82
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +830 -151
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -372,7 +372,8 @@ function useFeedbackRepo() {
|
|
|
372
372
|
query.$or = [
|
|
373
373
|
{ subject: { $regex: search, $options: "i" } },
|
|
374
374
|
{ description: { $regex: search, $options: "i" } },
|
|
375
|
-
{ createdByName: { $regex: search, $options: "i" } }
|
|
375
|
+
{ createdByName: { $regex: search, $options: "i" } },
|
|
376
|
+
{ category: { $regex: search, $options: "i" } }
|
|
376
377
|
];
|
|
377
378
|
cacheOptions.search = search;
|
|
378
379
|
}
|
|
@@ -993,7 +994,9 @@ function useWorkOrderRepo() {
|
|
|
993
994
|
if (search) {
|
|
994
995
|
query.$or = [
|
|
995
996
|
{ subject: { $regex: search, $options: "i" } },
|
|
996
|
-
{ createdByName: { $regex: search, $options: "i" } }
|
|
997
|
+
{ createdByName: { $regex: search, $options: "i" } },
|
|
998
|
+
{ description: { $regex: search, $options: "i" } },
|
|
999
|
+
{ category: { $regex: search, $options: "i" } }
|
|
997
1000
|
];
|
|
998
1001
|
cacheOptions.search = search;
|
|
999
1002
|
}
|
|
@@ -1805,6 +1808,14 @@ function useOccurrenceEntryRepo() {
|
|
|
1805
1808
|
throw new Error("Invalid signature ID.");
|
|
1806
1809
|
}
|
|
1807
1810
|
}
|
|
1811
|
+
if (value.incidentReportId && typeof value.incidentReportId === "string") {
|
|
1812
|
+
try {
|
|
1813
|
+
value.incidentReportId = new ObjectId7(value.incidentReportId);
|
|
1814
|
+
} catch {
|
|
1815
|
+
throw new Error("Invalid incident report ID.");
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
console.log("Updating occurrence entry:", _id, value);
|
|
1808
1819
|
try {
|
|
1809
1820
|
const res = await collection.updateOne(
|
|
1810
1821
|
{ _id },
|
|
@@ -3218,7 +3229,8 @@ var allowedFieldsSite = [
|
|
|
3218
3229
|
"metadata.block",
|
|
3219
3230
|
"metadata.guardPosts",
|
|
3220
3231
|
"metadata.gracePeriod",
|
|
3221
|
-
"metadata.incidentCounter"
|
|
3232
|
+
"metadata.incidentCounter",
|
|
3233
|
+
"metadata.incidentLogo"
|
|
3222
3234
|
];
|
|
3223
3235
|
var siteSchema = Joi8.object({
|
|
3224
3236
|
name: Joi8.string().required(),
|
|
@@ -10794,7 +10806,8 @@ function useFeedbackController() {
|
|
|
10794
10806
|
}
|
|
10795
10807
|
async function deleteFeedback(req, res, next) {
|
|
10796
10808
|
const validation = Joi28.string().hex().required();
|
|
10797
|
-
const _id = req.
|
|
10809
|
+
const _id = req.query.id;
|
|
10810
|
+
console.log(_id);
|
|
10798
10811
|
const { error } = validation.validate(_id);
|
|
10799
10812
|
if (error) {
|
|
10800
10813
|
logger39.log({ level: "error", message: error.message });
|
|
@@ -11158,7 +11171,8 @@ function useWorkOrderController() {
|
|
|
11158
11171
|
}
|
|
11159
11172
|
async function deleteWorkOrder(req, res, next) {
|
|
11160
11173
|
const validation = Joi29.string().hex().required();
|
|
11161
|
-
const _id = req.
|
|
11174
|
+
const _id = req.query.id;
|
|
11175
|
+
console.log(_id);
|
|
11162
11176
|
const { error } = validation.validate(_id);
|
|
11163
11177
|
if (error) {
|
|
11164
11178
|
logger40.log({ level: "error", message: error.message });
|
|
@@ -12698,7 +12712,7 @@ function useSiteController() {
|
|
|
12698
12712
|
const validation = Joi36.object({
|
|
12699
12713
|
_id: Joi36.string().hex().required(),
|
|
12700
12714
|
field: Joi36.string().valid(...allowedFieldsSite).required(),
|
|
12701
|
-
value: Joi36.number().integer().min(0).required()
|
|
12715
|
+
value: Joi36.alternatives().try(Joi36.number().integer().min(0), Joi36.string().hex().length(24)).required()
|
|
12702
12716
|
});
|
|
12703
12717
|
const _id = req.params.id ?? "";
|
|
12704
12718
|
const field = req.body.field ?? "";
|
|
@@ -12905,8 +12919,8 @@ var schemaBuildingUnit = Joi38.object({
|
|
|
12905
12919
|
buildingUnitFiles: Joi38.array().items(Joi38.string()).optional().allow("", null),
|
|
12906
12920
|
companyName: Joi38.string().optional().allow("", null),
|
|
12907
12921
|
companyRegistrationNumber: Joi38.string().optional().allow("", null),
|
|
12908
|
-
leaseStart: Joi38.date().
|
|
12909
|
-
leaseEnd: Joi38.date().
|
|
12922
|
+
leaseStart: Joi38.date().optional(),
|
|
12923
|
+
leaseEnd: Joi38.date().optional(),
|
|
12910
12924
|
owner: Joi38.string().hex().optional().allow("", null),
|
|
12911
12925
|
ownerName: Joi38.string().optional().allow("", null),
|
|
12912
12926
|
billing: Joi38.array().items(schemaBilling).optional().allow("", null)
|
|
@@ -14276,8 +14290,8 @@ function useBuildingUnitController() {
|
|
|
14276
14290
|
buildingUnitFiles: Joi40.array().items(Joi40.string()).optional(),
|
|
14277
14291
|
companyName: Joi40.string().optional().allow("", null),
|
|
14278
14292
|
companyRegistrationNumber: Joi40.string().optional().allow("", null),
|
|
14279
|
-
leaseStart: Joi40.date().
|
|
14280
|
-
leaseEnd: Joi40.date().
|
|
14293
|
+
leaseStart: Joi40.date().optional(),
|
|
14294
|
+
leaseEnd: Joi40.date().optional()
|
|
14281
14295
|
}),
|
|
14282
14296
|
qty: Joi40.number().integer().min(1).max(20).optional().default(1)
|
|
14283
14297
|
});
|
|
@@ -17514,7 +17528,11 @@ function useAttendanceSettingsRepository() {
|
|
|
17514
17528
|
isLocationEnabled: 1,
|
|
17515
17529
|
location: 1,
|
|
17516
17530
|
isGeofencingEnabled: 1,
|
|
17517
|
-
mile: 1
|
|
17531
|
+
mile: 1,
|
|
17532
|
+
postalCode: 1,
|
|
17533
|
+
country: 1,
|
|
17534
|
+
city: 1,
|
|
17535
|
+
address: 1
|
|
17518
17536
|
}
|
|
17519
17537
|
}
|
|
17520
17538
|
]).toArray();
|
|
@@ -27195,11 +27213,11 @@ var EAccessCardTypes = /* @__PURE__ */ ((EAccessCardTypes2) => {
|
|
|
27195
27213
|
EAccessCardTypes2["QR"] = "QRCODE";
|
|
27196
27214
|
return EAccessCardTypes2;
|
|
27197
27215
|
})(EAccessCardTypes || {});
|
|
27198
|
-
var EAccessCardUserTypes = /* @__PURE__ */ ((
|
|
27199
|
-
|
|
27200
|
-
|
|
27201
|
-
|
|
27202
|
-
return
|
|
27216
|
+
var EAccessCardUserTypes = /* @__PURE__ */ ((EAccessCardUserTypes4) => {
|
|
27217
|
+
EAccessCardUserTypes4["RESIDENT"] = "Resident/Tenant";
|
|
27218
|
+
EAccessCardUserTypes4["CONTRACTOR"] = "Contractor";
|
|
27219
|
+
EAccessCardUserTypes4["VISITOR"] = "Visitor";
|
|
27220
|
+
return EAccessCardUserTypes4;
|
|
27203
27221
|
})(EAccessCardUserTypes || {});
|
|
27204
27222
|
var AccessTypeProps = /* @__PURE__ */ ((AccessTypeProps2) => {
|
|
27205
27223
|
AccessTypeProps2["NORMAL"] = "Normal";
|
|
@@ -27261,7 +27279,8 @@ var MAccessCard = class {
|
|
|
27261
27279
|
doorName,
|
|
27262
27280
|
liftName,
|
|
27263
27281
|
replacementStatus,
|
|
27264
|
-
vmsRemarks
|
|
27282
|
+
vmsRemarks,
|
|
27283
|
+
isWinsland = false
|
|
27265
27284
|
} = {}) {
|
|
27266
27285
|
this._id = _id;
|
|
27267
27286
|
this.userId = userId;
|
|
@@ -27288,12 +27307,14 @@ var MAccessCard = class {
|
|
|
27288
27307
|
this.liftName = liftName;
|
|
27289
27308
|
this.replacementStatus = replacementStatus;
|
|
27290
27309
|
this.vmsRemarks = vmsRemarks;
|
|
27310
|
+
this.isWinsland = isWinsland;
|
|
27291
27311
|
}
|
|
27292
27312
|
};
|
|
27293
27313
|
|
|
27294
27314
|
// src/repositories/access-management.repo.ts
|
|
27295
27315
|
import {
|
|
27296
27316
|
InternalServerError as InternalServerError47,
|
|
27317
|
+
paginate as paginate38,
|
|
27297
27318
|
useAtlas as useAtlas74
|
|
27298
27319
|
} from "@7365admin1/node-server-utils";
|
|
27299
27320
|
import { ObjectId as ObjectId83 } from "mongodb";
|
|
@@ -27340,6 +27361,15 @@ function UseAccessManagementRepo() {
|
|
|
27340
27361
|
return Promise.reject("Failed to create Access cards indexes.");
|
|
27341
27362
|
}
|
|
27342
27363
|
}
|
|
27364
|
+
async function createIndexForEntrypass() {
|
|
27365
|
+
try {
|
|
27366
|
+
const entrypass = collectionName("entrypass-settings");
|
|
27367
|
+
await Promise.all([entrypass.createIndex({ site: 1 })]);
|
|
27368
|
+
return Promise.resolve("Access cards indexes created.");
|
|
27369
|
+
} catch (error) {
|
|
27370
|
+
return Promise.reject("Failed to create Access cards indexes.");
|
|
27371
|
+
}
|
|
27372
|
+
}
|
|
27343
27373
|
async function addPhysicalCardRepo({
|
|
27344
27374
|
payload
|
|
27345
27375
|
}) {
|
|
@@ -27430,7 +27460,8 @@ function UseAccessManagementRepo() {
|
|
|
27430
27460
|
liftName: params.liftName,
|
|
27431
27461
|
assignedUnit: new ObjectId83(units[i]),
|
|
27432
27462
|
createdAt: new Date(params.createdAt),
|
|
27433
|
-
updatedAt: new Date(params.updatedAt)
|
|
27463
|
+
updatedAt: new Date(params.updatedAt),
|
|
27464
|
+
isWinsland: params.isWinsland
|
|
27434
27465
|
});
|
|
27435
27466
|
try {
|
|
27436
27467
|
const result = await collection().insertOne(newCard);
|
|
@@ -27482,7 +27513,8 @@ function UseAccessManagementRepo() {
|
|
|
27482
27513
|
liftName: params.liftName,
|
|
27483
27514
|
assignedUnit: null,
|
|
27484
27515
|
createdAt: new Date(params.createdAt),
|
|
27485
|
-
updatedAt: new Date(params.updatedAt)
|
|
27516
|
+
updatedAt: new Date(params.updatedAt),
|
|
27517
|
+
isWinsland: params.isWinsland
|
|
27486
27518
|
});
|
|
27487
27519
|
try {
|
|
27488
27520
|
const result = await collection().insertOne(newCard);
|
|
@@ -27514,10 +27546,362 @@ function UseAccessManagementRepo() {
|
|
|
27514
27546
|
throw new Error(error.message);
|
|
27515
27547
|
}
|
|
27516
27548
|
}
|
|
27549
|
+
async function accessManagementSettingsRepo(params) {
|
|
27550
|
+
try {
|
|
27551
|
+
params.site = new ObjectId83(params.site);
|
|
27552
|
+
const result = collectionName("entrypass-settings").updateOne(
|
|
27553
|
+
{ site: params.site },
|
|
27554
|
+
{
|
|
27555
|
+
$set: {
|
|
27556
|
+
...params,
|
|
27557
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
27558
|
+
},
|
|
27559
|
+
$setOnInsert: {
|
|
27560
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
27561
|
+
}
|
|
27562
|
+
},
|
|
27563
|
+
{ upsert: true }
|
|
27564
|
+
);
|
|
27565
|
+
await createIndexForEntrypass();
|
|
27566
|
+
return result;
|
|
27567
|
+
} catch (error) {
|
|
27568
|
+
throw new Error(error.message);
|
|
27569
|
+
}
|
|
27570
|
+
}
|
|
27571
|
+
async function allAccessCardsCountsRepo(params) {
|
|
27572
|
+
try {
|
|
27573
|
+
const site = new ObjectId83(params.site);
|
|
27574
|
+
const userType = params.userType;
|
|
27575
|
+
const result = await collection().aggregate([
|
|
27576
|
+
{
|
|
27577
|
+
$match: { site, userType }
|
|
27578
|
+
},
|
|
27579
|
+
{
|
|
27580
|
+
$facet: {
|
|
27581
|
+
available_physical: [{ $match: { assignedUnit: { $eq: null }, type: "NFC" /* NFC */ } }, { $count: "count" }],
|
|
27582
|
+
available_non_physical: [{ $match: { assignedUnit: { $eq: null }, type: "QRCODE" /* QR */ } }, { $count: "count" }],
|
|
27583
|
+
assigned_physical: [{ $match: { assignedUnit: { $ne: null }, type: "NFC" /* NFC */ } }, { $count: "count" }],
|
|
27584
|
+
assigned_non_physical: [{ $match: { assignedUnit: { $ne: null }, type: "QRCODE" /* QR */ } }, { $count: "count" }]
|
|
27585
|
+
}
|
|
27586
|
+
}
|
|
27587
|
+
]).toArray();
|
|
27588
|
+
const totalCardCount = {
|
|
27589
|
+
available_physical: result[0].available_physical[0] ? result[0].available_physical[0].count : 0,
|
|
27590
|
+
available_non_physical: result[0].available_non_physical[0] ? result[0].available_non_physical[0].count : 0,
|
|
27591
|
+
assigned_physical: result[0].assigned_physical[0] ? result[0].assigned_physical[0].count : 0,
|
|
27592
|
+
assigned_non_physical: result[0].assigned_non_physical[0] ? result[0].assigned_non_physical[0].count : 0
|
|
27593
|
+
};
|
|
27594
|
+
return totalCardCount;
|
|
27595
|
+
} catch (error) {
|
|
27596
|
+
throw new Error(error.message);
|
|
27597
|
+
}
|
|
27598
|
+
}
|
|
27599
|
+
async function availableAccessCardsRepo(params) {
|
|
27600
|
+
try {
|
|
27601
|
+
const site = new ObjectId83(params.site);
|
|
27602
|
+
const userType = params.userType;
|
|
27603
|
+
const type = params.type;
|
|
27604
|
+
const query = {
|
|
27605
|
+
site: { $in: [site] },
|
|
27606
|
+
userType,
|
|
27607
|
+
assignedUnit: null,
|
|
27608
|
+
type,
|
|
27609
|
+
isActivated: true
|
|
27610
|
+
};
|
|
27611
|
+
const result = await collection().aggregate([
|
|
27612
|
+
{
|
|
27613
|
+
$match: { ...query }
|
|
27614
|
+
},
|
|
27615
|
+
{
|
|
27616
|
+
$project: {
|
|
27617
|
+
accessLevel: 1,
|
|
27618
|
+
liftAccessLevel: 1,
|
|
27619
|
+
doorName: 1,
|
|
27620
|
+
liftName: 1
|
|
27621
|
+
}
|
|
27622
|
+
},
|
|
27623
|
+
{
|
|
27624
|
+
$group: {
|
|
27625
|
+
_id: {
|
|
27626
|
+
accessLevel: "$accessLevel",
|
|
27627
|
+
liftAccessLevel: "$liftAccessLevel",
|
|
27628
|
+
doorName: "$doorName",
|
|
27629
|
+
liftName: "$liftName"
|
|
27630
|
+
},
|
|
27631
|
+
count: { $sum: 1 }
|
|
27632
|
+
}
|
|
27633
|
+
},
|
|
27634
|
+
{
|
|
27635
|
+
$project: {
|
|
27636
|
+
_id: 0,
|
|
27637
|
+
accessLevel: "$_id.accessLevel",
|
|
27638
|
+
liftAccessLevel: "$_id.liftAccessLevel",
|
|
27639
|
+
doorName: "$_id.doorName",
|
|
27640
|
+
liftName: "$_id.liftName",
|
|
27641
|
+
count: 1
|
|
27642
|
+
}
|
|
27643
|
+
}
|
|
27644
|
+
]).toArray();
|
|
27645
|
+
return result;
|
|
27646
|
+
} catch (error) {
|
|
27647
|
+
throw new Error(error.message);
|
|
27648
|
+
}
|
|
27649
|
+
}
|
|
27650
|
+
function buildSearchQuery(search) {
|
|
27651
|
+
if (!search) {
|
|
27652
|
+
return {};
|
|
27653
|
+
}
|
|
27654
|
+
const terms = search.split("/").map((s) => s.trim()).filter(Boolean);
|
|
27655
|
+
if (search.includes("/") && terms.length <= 3) {
|
|
27656
|
+
switch (terms.length) {
|
|
27657
|
+
case 3:
|
|
27658
|
+
return {
|
|
27659
|
+
$and: [
|
|
27660
|
+
{ $expr: { $eq: [{ $toLower: "$name" }, terms[0].toLowerCase()] } },
|
|
27661
|
+
{ $expr: { $eq: [{ $toLower: "$level.level" }, terms[1].toLowerCase()] } },
|
|
27662
|
+
{ $expr: { $eq: [{ $toLower: "$level.units.name" }, terms[2].toLowerCase()] } }
|
|
27663
|
+
]
|
|
27664
|
+
};
|
|
27665
|
+
case 2:
|
|
27666
|
+
return {
|
|
27667
|
+
$and: [
|
|
27668
|
+
{ $expr: { $eq: [{ $toLower: "$name" }, terms[0].toLowerCase()] } },
|
|
27669
|
+
{ $expr: { $eq: [{ $toLower: "$level.level" }, terms[1].toLowerCase()] } }
|
|
27670
|
+
]
|
|
27671
|
+
};
|
|
27672
|
+
default:
|
|
27673
|
+
return {
|
|
27674
|
+
$expr: { $eq: [{ $toLower: "$name" }, terms[0].toLowerCase()] }
|
|
27675
|
+
};
|
|
27676
|
+
}
|
|
27677
|
+
}
|
|
27678
|
+
return {
|
|
27679
|
+
$or: [
|
|
27680
|
+
{ name: { $regex: search.trim(), $options: "i" } },
|
|
27681
|
+
{ "level.level": { $regex: search.trim(), $options: "i" } },
|
|
27682
|
+
{ "level.units.name": { $regex: search.trim(), $options: "i" } }
|
|
27683
|
+
]
|
|
27684
|
+
};
|
|
27685
|
+
}
|
|
27686
|
+
async function userTypeAccessCardsRepo(params) {
|
|
27687
|
+
try {
|
|
27688
|
+
const site = new ObjectId83(params.site);
|
|
27689
|
+
const userType = params.userType;
|
|
27690
|
+
const page = params.page ? Number(params.page) - 1 : 0;
|
|
27691
|
+
const limit = Number(params.limit) || 10;
|
|
27692
|
+
const search = params.search;
|
|
27693
|
+
const defaultQuery = {
|
|
27694
|
+
site
|
|
27695
|
+
};
|
|
27696
|
+
const searchQuery = buildSearchQuery(search);
|
|
27697
|
+
const result = await collectionName("buildings").aggregate([
|
|
27698
|
+
// ✅ Match early with index-friendly query
|
|
27699
|
+
{
|
|
27700
|
+
$match: {
|
|
27701
|
+
...defaultQuery,
|
|
27702
|
+
status: { $ne: "deleted" }
|
|
27703
|
+
}
|
|
27704
|
+
},
|
|
27705
|
+
// ✅ Only project needed fields before heavy lookups
|
|
27706
|
+
{
|
|
27707
|
+
$project: {
|
|
27708
|
+
_id: 1,
|
|
27709
|
+
name: 1,
|
|
27710
|
+
site: 1
|
|
27711
|
+
}
|
|
27712
|
+
},
|
|
27713
|
+
// ✅ Use localField/foreignField for better index usage
|
|
27714
|
+
{
|
|
27715
|
+
$lookup: {
|
|
27716
|
+
from: "building-levels",
|
|
27717
|
+
localField: "_id",
|
|
27718
|
+
foreignField: "block",
|
|
27719
|
+
pipeline: [
|
|
27720
|
+
{ $match: { status: { $ne: "deleted" } } },
|
|
27721
|
+
{
|
|
27722
|
+
$lookup: {
|
|
27723
|
+
from: "building-units",
|
|
27724
|
+
localField: "_id",
|
|
27725
|
+
foreignField: "level",
|
|
27726
|
+
pipeline: [
|
|
27727
|
+
{ $match: { status: { $ne: "deleted" } } },
|
|
27728
|
+
{ $project: { _id: 1, name: 1 } }
|
|
27729
|
+
],
|
|
27730
|
+
as: "units"
|
|
27731
|
+
}
|
|
27732
|
+
},
|
|
27733
|
+
{
|
|
27734
|
+
$match: { "units.0": { $exists: true } }
|
|
27735
|
+
},
|
|
27736
|
+
{
|
|
27737
|
+
$project: {
|
|
27738
|
+
_id: 1,
|
|
27739
|
+
level: 1,
|
|
27740
|
+
units: 1
|
|
27741
|
+
}
|
|
27742
|
+
}
|
|
27743
|
+
],
|
|
27744
|
+
as: "level"
|
|
27745
|
+
}
|
|
27746
|
+
},
|
|
27747
|
+
// ✅ Filter out buildings with no levels early
|
|
27748
|
+
{
|
|
27749
|
+
$match: { "level.0": { $exists: true } }
|
|
27750
|
+
},
|
|
27751
|
+
// ✅ Unwind to flatten the hierarchy
|
|
27752
|
+
{
|
|
27753
|
+
$unwind: {
|
|
27754
|
+
path: "$level",
|
|
27755
|
+
preserveNullAndEmptyArrays: false
|
|
27756
|
+
}
|
|
27757
|
+
},
|
|
27758
|
+
{
|
|
27759
|
+
$unwind: {
|
|
27760
|
+
path: "$level.units",
|
|
27761
|
+
preserveNullAndEmptyArrays: false
|
|
27762
|
+
}
|
|
27763
|
+
},
|
|
27764
|
+
// Groups by unit _id and keeps only the first occurrence
|
|
27765
|
+
{
|
|
27766
|
+
$group: {
|
|
27767
|
+
_id: "$level.units._id",
|
|
27768
|
+
doc: { $first: "$$ROOT" }
|
|
27769
|
+
}
|
|
27770
|
+
},
|
|
27771
|
+
{
|
|
27772
|
+
$replaceRoot: { newRoot: "$doc" }
|
|
27773
|
+
},
|
|
27774
|
+
// ✅ Apply search filter
|
|
27775
|
+
{
|
|
27776
|
+
$match: {
|
|
27777
|
+
...searchQuery
|
|
27778
|
+
}
|
|
27779
|
+
},
|
|
27780
|
+
{
|
|
27781
|
+
$facet: {
|
|
27782
|
+
totalCount: [{ $count: "count" }],
|
|
27783
|
+
items: [
|
|
27784
|
+
// ✅ Sort BEFORE skip/limit for correct pagination
|
|
27785
|
+
{ $sort: { _id: -1 } },
|
|
27786
|
+
{ $skip: page * limit },
|
|
27787
|
+
{ $limit: limit },
|
|
27788
|
+
// ✅ Users lookup - optimized with index hint
|
|
27789
|
+
{
|
|
27790
|
+
$lookup: {
|
|
27791
|
+
from: "users",
|
|
27792
|
+
let: { unit: "$level.units._id" },
|
|
27793
|
+
pipeline: [
|
|
27794
|
+
{
|
|
27795
|
+
$match: {
|
|
27796
|
+
$expr: { $eq: ["$unitNumber", "$$unit"] },
|
|
27797
|
+
residentType: "House/Unit Owner"
|
|
27798
|
+
}
|
|
27799
|
+
},
|
|
27800
|
+
{ $limit: 1 },
|
|
27801
|
+
{ $project: { _id: 1, givenName: 1, surname: 1 } }
|
|
27802
|
+
],
|
|
27803
|
+
as: "unitOwner"
|
|
27804
|
+
}
|
|
27805
|
+
},
|
|
27806
|
+
// ✅ Access card lookup - optimized query
|
|
27807
|
+
{
|
|
27808
|
+
$lookup: {
|
|
27809
|
+
from: "access-cards",
|
|
27810
|
+
let: { unit: "$level.units._id" },
|
|
27811
|
+
pipeline: [
|
|
27812
|
+
{
|
|
27813
|
+
$match: {
|
|
27814
|
+
$expr: {
|
|
27815
|
+
$in: [
|
|
27816
|
+
"$$unit",
|
|
27817
|
+
{ $cond: [{ $isArray: "$assignedUnit" }, "$assignedUnit", ["$assignedUnit"]] }
|
|
27818
|
+
]
|
|
27819
|
+
},
|
|
27820
|
+
userType
|
|
27821
|
+
}
|
|
27822
|
+
},
|
|
27823
|
+
{ $project: { _id: 1, userId: 1, type: 1, cardNo: 1, isActivated: 1 } }
|
|
27824
|
+
],
|
|
27825
|
+
as: "accessCards"
|
|
27826
|
+
}
|
|
27827
|
+
},
|
|
27828
|
+
// ✅ Compute all card categorization and counts in ONE stage
|
|
27829
|
+
{
|
|
27830
|
+
$addFields: {
|
|
27831
|
+
f_Available: {
|
|
27832
|
+
$filter: {
|
|
27833
|
+
input: "$accessCards",
|
|
27834
|
+
as: "card",
|
|
27835
|
+
cond: { $and: [{ $eq: ["$$card.userId", null] }, { $eq: ["$$card.isActivated", true] }] }
|
|
27836
|
+
}
|
|
27837
|
+
},
|
|
27838
|
+
f_Assigned: {
|
|
27839
|
+
$filter: {
|
|
27840
|
+
input: "$accessCards",
|
|
27841
|
+
as: "card",
|
|
27842
|
+
cond: { $ne: ["$$card.userId", null] }
|
|
27843
|
+
}
|
|
27844
|
+
}
|
|
27845
|
+
}
|
|
27846
|
+
},
|
|
27847
|
+
// ✅ Final projection with all computed fields
|
|
27848
|
+
{
|
|
27849
|
+
$project: {
|
|
27850
|
+
_id: "$level.units._id",
|
|
27851
|
+
name: "$level.units.name",
|
|
27852
|
+
level: { _id: "$level._id", level: "$level.level" },
|
|
27853
|
+
block: { _id: "$_id", name: "$name" },
|
|
27854
|
+
site: "$site",
|
|
27855
|
+
unit_owner: { $arrayElemAt: ["$unitOwner", 0] },
|
|
27856
|
+
available: {
|
|
27857
|
+
physical: { $filter: { input: "$f_Available", as: "c", cond: { $eq: ["$$c.type", "NFC" /* NFC */] } } },
|
|
27858
|
+
non_physical: { $filter: { input: "$f_Available", as: "c", cond: { $eq: ["$$c.type", "QRCODE" /* QR */] } } }
|
|
27859
|
+
},
|
|
27860
|
+
assigned: {
|
|
27861
|
+
physical: { $filter: { input: "$f_Assigned", as: "c", cond: { $eq: ["$$c.type", "NFC" /* NFC */] } } },
|
|
27862
|
+
non_physical: { $filter: { input: "$f_Assigned", as: "c", cond: { $eq: ["$$c.type", "QRCODE" /* QR */] } } }
|
|
27863
|
+
},
|
|
27864
|
+
cardCounts: {
|
|
27865
|
+
available: {
|
|
27866
|
+
physical: { $size: { $filter: { input: { $ifNull: ["$f_Available", []] }, as: "c", cond: { $eq: ["$$c.type", "NFC" /* NFC */] } } } },
|
|
27867
|
+
non_physical: { $size: { $filter: { input: { $ifNull: ["$f_Available", []] }, as: "c", cond: { $eq: ["$$c.type", "QRCODE" /* QR */] } } } }
|
|
27868
|
+
},
|
|
27869
|
+
assigned: {
|
|
27870
|
+
physical: { $size: { $filter: { input: { $ifNull: ["$f_Assigned", []] }, as: "c", cond: { $eq: ["$$c.type", "NFC" /* NFC */] } } } },
|
|
27871
|
+
non_physical: { $size: { $filter: { input: { $ifNull: ["$f_Assigned", []] }, as: "c", cond: { $eq: ["$$c.type", "QRCODE" /* QR */] } } } }
|
|
27872
|
+
}
|
|
27873
|
+
},
|
|
27874
|
+
totalCardCount: {
|
|
27875
|
+
$add: [
|
|
27876
|
+
{ $size: { $filter: { input: { $ifNull: ["$f_Available", []] }, as: "c", cond: { $eq: ["$$c.type", "NFC" /* NFC */] } } } },
|
|
27877
|
+
{ $size: { $filter: { input: { $ifNull: ["$f_Available", []] }, as: "c", cond: { $eq: ["$$c.type", "QRCODE" /* QR */] } } } },
|
|
27878
|
+
{ $size: { $filter: { input: { $ifNull: ["$f_Assigned", []] }, as: "c", cond: { $eq: ["$$c.type", "NFC" /* NFC */] } } } },
|
|
27879
|
+
{ $size: { $filter: { input: { $ifNull: ["$f_Assigned", []] }, as: "c", cond: { $eq: ["$$c.type", "QRCODE" /* QR */] } } } }
|
|
27880
|
+
]
|
|
27881
|
+
}
|
|
27882
|
+
}
|
|
27883
|
+
}
|
|
27884
|
+
]
|
|
27885
|
+
}
|
|
27886
|
+
}
|
|
27887
|
+
], { allowDiskUse: true }).toArray();
|
|
27888
|
+
const totalCount = result[0]?.totalCount?.[0]?.count ?? 0;
|
|
27889
|
+
const items = result[0]?.items ?? [];
|
|
27890
|
+
const paginatedResult = paginate38(items, page, limit, totalCount);
|
|
27891
|
+
return paginatedResult;
|
|
27892
|
+
} catch (error) {
|
|
27893
|
+
throw new Error(error.message);
|
|
27894
|
+
}
|
|
27895
|
+
}
|
|
27517
27896
|
return {
|
|
27518
27897
|
createIndexes,
|
|
27898
|
+
createIndexForEntrypass,
|
|
27519
27899
|
addPhysicalCardRepo,
|
|
27520
|
-
addNonPhysicalCardRepo
|
|
27900
|
+
addNonPhysicalCardRepo,
|
|
27901
|
+
accessManagementSettingsRepo,
|
|
27902
|
+
allAccessCardsCountsRepo,
|
|
27903
|
+
availableAccessCardsRepo,
|
|
27904
|
+
userTypeAccessCardsRepo
|
|
27521
27905
|
};
|
|
27522
27906
|
}
|
|
27523
27907
|
|
|
@@ -27623,7 +28007,14 @@ var formatAccessGroup = (data, search) => {
|
|
|
27623
28007
|
// src/services/access-management.service.ts
|
|
27624
28008
|
import { parseStringPromise } from "xml2js";
|
|
27625
28009
|
function useAccessManagementSvc() {
|
|
27626
|
-
const {
|
|
28010
|
+
const {
|
|
28011
|
+
addPhysicalCardRepo,
|
|
28012
|
+
addNonPhysicalCardRepo,
|
|
28013
|
+
accessManagementSettingsRepo,
|
|
28014
|
+
allAccessCardsCountsRepo,
|
|
28015
|
+
availableAccessCardsRepo,
|
|
28016
|
+
userTypeAccessCardsRepo
|
|
28017
|
+
} = UseAccessManagementRepo();
|
|
27627
28018
|
const addPhysicalCardSvc = async (payload) => {
|
|
27628
28019
|
try {
|
|
27629
28020
|
const response = await addPhysicalCardRepo({ payload });
|
|
@@ -27670,7 +28061,39 @@ function useAccessManagementSvc() {
|
|
|
27670
28061
|
const format = await formatAccessGroup(res);
|
|
27671
28062
|
return format;
|
|
27672
28063
|
} catch (err) {
|
|
27673
|
-
|
|
28064
|
+
throw new Error(err.message);
|
|
28065
|
+
}
|
|
28066
|
+
};
|
|
28067
|
+
const accessManagementSettingsSvc = async (settings) => {
|
|
28068
|
+
try {
|
|
28069
|
+
const response = await accessManagementSettingsRepo({ ...settings });
|
|
28070
|
+
return response;
|
|
28071
|
+
} catch (err) {
|
|
28072
|
+
throw new Error(err.message);
|
|
28073
|
+
}
|
|
28074
|
+
};
|
|
28075
|
+
const allAccessCardsCountsSvc = async (params) => {
|
|
28076
|
+
try {
|
|
28077
|
+
const response = await allAccessCardsCountsRepo({ ...params });
|
|
28078
|
+
return response;
|
|
28079
|
+
} catch (err) {
|
|
28080
|
+
throw new Error(err.message);
|
|
28081
|
+
}
|
|
28082
|
+
};
|
|
28083
|
+
const availableAccessCardsSvc = async (params) => {
|
|
28084
|
+
try {
|
|
28085
|
+
const response = await availableAccessCardsRepo({ ...params });
|
|
28086
|
+
return response;
|
|
28087
|
+
} catch (err) {
|
|
28088
|
+
throw new Error(err.message);
|
|
28089
|
+
}
|
|
28090
|
+
};
|
|
28091
|
+
const userTypeAccessCardsSvc = async (params) => {
|
|
28092
|
+
try {
|
|
28093
|
+
const response = await userTypeAccessCardsRepo({ ...params });
|
|
28094
|
+
return response;
|
|
28095
|
+
} catch (err) {
|
|
28096
|
+
throw new Error(err.message);
|
|
27674
28097
|
}
|
|
27675
28098
|
};
|
|
27676
28099
|
return {
|
|
@@ -27678,7 +28101,11 @@ function useAccessManagementSvc() {
|
|
|
27678
28101
|
addNonPhysicalCardSvc,
|
|
27679
28102
|
doorAccessLevelsSvc,
|
|
27680
28103
|
liftAccessLevelsSvc,
|
|
27681
|
-
accessGroupsSvc
|
|
28104
|
+
accessGroupsSvc,
|
|
28105
|
+
accessManagementSettingsSvc,
|
|
28106
|
+
allAccessCardsCountsSvc,
|
|
28107
|
+
availableAccessCardsSvc,
|
|
28108
|
+
userTypeAccessCardsSvc
|
|
27682
28109
|
};
|
|
27683
28110
|
}
|
|
27684
28111
|
|
|
@@ -27689,7 +28116,11 @@ function useAccessManagementController() {
|
|
|
27689
28116
|
addNonPhysicalCardSvc,
|
|
27690
28117
|
doorAccessLevelsSvc,
|
|
27691
28118
|
liftAccessLevelsSvc,
|
|
27692
|
-
accessGroupsSvc
|
|
28119
|
+
accessGroupsSvc,
|
|
28120
|
+
accessManagementSettingsSvc,
|
|
28121
|
+
allAccessCardsCountsSvc,
|
|
28122
|
+
availableAccessCardsSvc,
|
|
28123
|
+
userTypeAccessCardsSvc
|
|
27693
28124
|
} = useAccessManagementSvc();
|
|
27694
28125
|
const addPhysicalCard = async (req, res) => {
|
|
27695
28126
|
try {
|
|
@@ -27749,7 +28180,8 @@ function useAccessManagementController() {
|
|
|
27749
28180
|
createdAt,
|
|
27750
28181
|
updatedAt,
|
|
27751
28182
|
startDate,
|
|
27752
|
-
endDate
|
|
28183
|
+
endDate,
|
|
28184
|
+
isWinsland
|
|
27753
28185
|
} = req.body;
|
|
27754
28186
|
const schema2 = Joi85.object({
|
|
27755
28187
|
site: Joi85.string().hex().required(),
|
|
@@ -27765,7 +28197,8 @@ function useAccessManagementController() {
|
|
|
27765
28197
|
startDate: Joi85.date().required(),
|
|
27766
28198
|
endDate: Joi85.date().required(),
|
|
27767
28199
|
createdAt: Joi85.date().required(),
|
|
27768
|
-
updatedAt: Joi85.date().required()
|
|
28200
|
+
updatedAt: Joi85.date().required(),
|
|
28201
|
+
isWinsland: Joi85.boolean().optional().allow(null)
|
|
27769
28202
|
});
|
|
27770
28203
|
const { error } = schema2.validate({
|
|
27771
28204
|
site,
|
|
@@ -27781,7 +28214,8 @@ function useAccessManagementController() {
|
|
|
27781
28214
|
startDate,
|
|
27782
28215
|
endDate,
|
|
27783
28216
|
createdAt,
|
|
27784
|
-
updatedAt
|
|
28217
|
+
updatedAt,
|
|
28218
|
+
isWinsland
|
|
27785
28219
|
});
|
|
27786
28220
|
if (error) {
|
|
27787
28221
|
throw new Error(`${error.message}`);
|
|
@@ -27800,7 +28234,8 @@ function useAccessManagementController() {
|
|
|
27800
28234
|
startDate,
|
|
27801
28235
|
endDate,
|
|
27802
28236
|
createdAt,
|
|
27803
|
-
updatedAt
|
|
28237
|
+
updatedAt,
|
|
28238
|
+
isWinsland
|
|
27804
28239
|
});
|
|
27805
28240
|
return res.status(201).json({
|
|
27806
28241
|
data: result,
|
|
@@ -27858,12 +28293,100 @@ function useAccessManagementController() {
|
|
|
27858
28293
|
});
|
|
27859
28294
|
}
|
|
27860
28295
|
};
|
|
28296
|
+
const accessManagementSettings = async (req, res) => {
|
|
28297
|
+
try {
|
|
28298
|
+
const settings = req.body;
|
|
28299
|
+
const result = await accessManagementSettingsSvc(settings);
|
|
28300
|
+
return res.status(201).json({ message: "Success", data: result });
|
|
28301
|
+
} catch (error) {
|
|
28302
|
+
return res.status(400).json({
|
|
28303
|
+
data: null,
|
|
28304
|
+
message: error.message
|
|
28305
|
+
});
|
|
28306
|
+
}
|
|
28307
|
+
};
|
|
28308
|
+
const allAccessCardsCounts = async (req, res) => {
|
|
28309
|
+
try {
|
|
28310
|
+
const { site, userType } = req.query;
|
|
28311
|
+
const schema2 = Joi85.object({
|
|
28312
|
+
site: Joi85.string().hex().required(),
|
|
28313
|
+
userType: Joi85.string().required()
|
|
28314
|
+
});
|
|
28315
|
+
const { error } = schema2.validate({ site, userType });
|
|
28316
|
+
if (error) {
|
|
28317
|
+
throw new Error(`${error.message}`);
|
|
28318
|
+
}
|
|
28319
|
+
const result = await allAccessCardsCountsSvc({ site, userType });
|
|
28320
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
28321
|
+
} catch (error) {
|
|
28322
|
+
return res.status(400).json({
|
|
28323
|
+
data: null,
|
|
28324
|
+
message: error.message
|
|
28325
|
+
});
|
|
28326
|
+
}
|
|
28327
|
+
};
|
|
28328
|
+
const availableAccessCards = async (req, res) => {
|
|
28329
|
+
try {
|
|
28330
|
+
const { site, userType, type } = req.query;
|
|
28331
|
+
const schema2 = Joi85.object({
|
|
28332
|
+
site: Joi85.string().hex().required(),
|
|
28333
|
+
userType: Joi85.string().optional().allow("", null),
|
|
28334
|
+
type: Joi85.string().optional().allow("", null)
|
|
28335
|
+
});
|
|
28336
|
+
const { error } = schema2.validate({ site, userType, type });
|
|
28337
|
+
if (error) {
|
|
28338
|
+
return res.status(400).json({ message: error.message });
|
|
28339
|
+
}
|
|
28340
|
+
const result = await availableAccessCardsSvc({ site, userType, type });
|
|
28341
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
28342
|
+
} catch (error) {
|
|
28343
|
+
return res.status(400).json({
|
|
28344
|
+
data: null,
|
|
28345
|
+
message: error.message
|
|
28346
|
+
});
|
|
28347
|
+
}
|
|
28348
|
+
};
|
|
28349
|
+
const userTypeAccessCards = async (req, res) => {
|
|
28350
|
+
try {
|
|
28351
|
+
const {
|
|
28352
|
+
page = 1,
|
|
28353
|
+
limit = 10,
|
|
28354
|
+
search = "",
|
|
28355
|
+
site,
|
|
28356
|
+
organization,
|
|
28357
|
+
userType
|
|
28358
|
+
} = req.query;
|
|
28359
|
+
const schema2 = Joi85.object({
|
|
28360
|
+
page: Joi85.number().required(),
|
|
28361
|
+
limit: Joi85.number().optional().default(10),
|
|
28362
|
+
site: Joi85.string().hex().required(),
|
|
28363
|
+
organization: Joi85.string().hex().optional().allow("", null),
|
|
28364
|
+
search: Joi85.string().optional().allow("", null),
|
|
28365
|
+
userType: Joi85.string().required()
|
|
28366
|
+
});
|
|
28367
|
+
const { error } = schema2.validate({ page, limit, site, organization, search, userType });
|
|
28368
|
+
if (error) {
|
|
28369
|
+
return res.status(400).json({ message: error.message });
|
|
28370
|
+
}
|
|
28371
|
+
const result = await userTypeAccessCardsSvc({ page, limit, search, site, organization, userType });
|
|
28372
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
28373
|
+
} catch (error) {
|
|
28374
|
+
return res.status(500).json({
|
|
28375
|
+
data: null,
|
|
28376
|
+
message: error.message
|
|
28377
|
+
});
|
|
28378
|
+
}
|
|
28379
|
+
};
|
|
27861
28380
|
return {
|
|
27862
28381
|
addPhysicalCard,
|
|
27863
28382
|
addNonPhysicalCard,
|
|
27864
28383
|
doorAccessLevels,
|
|
27865
28384
|
liftAccessLevels,
|
|
27866
|
-
accessGroups
|
|
28385
|
+
accessGroups,
|
|
28386
|
+
accessManagementSettings,
|
|
28387
|
+
allAccessCardsCounts,
|
|
28388
|
+
availableAccessCards,
|
|
28389
|
+
userTypeAccessCards
|
|
27867
28390
|
};
|
|
27868
28391
|
}
|
|
27869
28392
|
|
|
@@ -29896,6 +30419,7 @@ function useStatementOfAccountService() {
|
|
|
29896
30419
|
try {
|
|
29897
30420
|
const browser = await launch({
|
|
29898
30421
|
headless: true,
|
|
30422
|
+
executablePath: process.env.CHROME_BINARY,
|
|
29899
30423
|
args: [`--no-sandbox`, `--disable-gpu`, `--disable-dev-shm-usage`]
|
|
29900
30424
|
});
|
|
29901
30425
|
const page = await browser.newPage();
|
|
@@ -31552,6 +32076,27 @@ var actionStatusSchema = Joi99.object({
|
|
|
31552
32076
|
status: Joi99.string().optional(),
|
|
31553
32077
|
time: Joi99.string().optional()
|
|
31554
32078
|
});
|
|
32079
|
+
var affectedInjuredStatusSchema = Joi99.object({
|
|
32080
|
+
name: Joi99.string().required(),
|
|
32081
|
+
contact: Joi99.string().optional().allow(null, ""),
|
|
32082
|
+
nric: Joi99.string().optional().allow(null, "")
|
|
32083
|
+
});
|
|
32084
|
+
var anyoneDamageToPropertyStatusSchema = Joi99.object({
|
|
32085
|
+
description: Joi99.string().optional().allow(null, ""),
|
|
32086
|
+
block: Joi99.number().optional().allow(null, ""),
|
|
32087
|
+
level: Joi99.string().optional().allow(null, ""),
|
|
32088
|
+
unit: Joi99.string().optional().allow(null, ""),
|
|
32089
|
+
blkLevelUnit: Joi99.string().optional().allow(null, ""),
|
|
32090
|
+
name: Joi99.string().optional().allow(null, ""),
|
|
32091
|
+
contact: Joi99.string().optional().allow(null, "")
|
|
32092
|
+
});
|
|
32093
|
+
var authoritiesCalledStatusSchema = Joi99.object({
|
|
32094
|
+
type: Joi99.string().optional().allow(null, ""),
|
|
32095
|
+
vehicleNumber: Joi99.string().optional().allow(null, ""),
|
|
32096
|
+
personInCharge: Joi99.string().optional().allow(null, ""),
|
|
32097
|
+
caseReportReference: Joi99.string().optional().allow(null, ""),
|
|
32098
|
+
description: Joi99.string().optional().allow(null, "")
|
|
32099
|
+
});
|
|
31555
32100
|
var schemaIncidentReport = Joi99.object({
|
|
31556
32101
|
reportId: Joi99.string().required(),
|
|
31557
32102
|
incidentInformation: Joi99.object({
|
|
@@ -31564,7 +32109,7 @@ var schemaIncidentReport = Joi99.object({
|
|
|
31564
32109
|
placeOfIncident: Joi99.object({
|
|
31565
32110
|
block: Joi99.number().optional().allow(null, ""),
|
|
31566
32111
|
level: Joi99.string().optional().allow(null, ""),
|
|
31567
|
-
unit: Joi99.string().
|
|
32112
|
+
unit: Joi99.string().optional().allow(null, ""),
|
|
31568
32113
|
other: Joi99.string().allow(null, "").optional().allow(null, ""),
|
|
31569
32114
|
isOther: Joi99.boolean().required(),
|
|
31570
32115
|
incidentLocation: Joi99.string().optional().allow(null, "")
|
|
@@ -31601,13 +32146,13 @@ var schemaIncidentReport = Joi99.object({
|
|
|
31601
32146
|
anyUnitAffectedValue: Joi99.string().valid("yes", "no").required(),
|
|
31602
32147
|
affectedUnit: Joi99.any().optional(),
|
|
31603
32148
|
anyoneAffectedValue: Joi99.string().valid("yes", "no").required(),
|
|
31604
|
-
affectedInjured: Joi99.array().items(
|
|
32149
|
+
affectedInjured: Joi99.array().items(affectedInjuredStatusSchema).optional().allow(null, ""),
|
|
31605
32150
|
anyPropertyAffectedValue: Joi99.string().valid("yes", "no").required(),
|
|
31606
|
-
anyoneDamageToProperty: Joi99.array().items(
|
|
31607
|
-
}).
|
|
32151
|
+
anyoneDamageToProperty: Joi99.array().items(anyoneDamageToPropertyStatusSchema).optional()
|
|
32152
|
+
}).optional().allow(null, ""),
|
|
31608
32153
|
authorities: Joi99.object({
|
|
31609
32154
|
authoritiesValue: Joi99.string().valid("yes", "no").required(),
|
|
31610
|
-
authoritiesCalled: Joi99.array().items(
|
|
32155
|
+
authoritiesCalled: Joi99.array().items(authoritiesCalledStatusSchema).optional().allow(null, ""),
|
|
31611
32156
|
incidentThereAfter: Joi99.string().optional().allow("", null),
|
|
31612
32157
|
managementNotified: actionStatusSchema.optional(),
|
|
31613
32158
|
incidentResolved: Joi99.string().optional().allow("", null),
|
|
@@ -31631,7 +32176,7 @@ var schemaIncidentReport = Joi99.object({
|
|
|
31631
32176
|
photos: Joi99.array().items(Joi99.string()).optional(),
|
|
31632
32177
|
approvedBy: Joi99.string().hex().allow(null, "").optional(),
|
|
31633
32178
|
approvedByName: Joi99.string().optional().allow("", null),
|
|
31634
|
-
|
|
32179
|
+
remarks: Joi99.string().optional().allow("", null),
|
|
31635
32180
|
status: Joi99.string().valid("pending", "approved", "rejected").default("pending")
|
|
31636
32181
|
});
|
|
31637
32182
|
var schemaUpdateIncidentReport = Joi99.object({
|
|
@@ -31646,7 +32191,7 @@ var schemaUpdateIncidentReport = Joi99.object({
|
|
|
31646
32191
|
placeOfIncident: Joi99.object({
|
|
31647
32192
|
block: Joi99.number().optional().allow(null, ""),
|
|
31648
32193
|
level: Joi99.string().optional().allow(null, ""),
|
|
31649
|
-
unit: Joi99.string().
|
|
32194
|
+
unit: Joi99.string().optional().allow(null, ""),
|
|
31650
32195
|
other: Joi99.string().allow(null, "").optional().allow(null, ""),
|
|
31651
32196
|
isOther: Joi99.boolean().allow(null, ""),
|
|
31652
32197
|
incidentLocation: Joi99.string().optional().allow(null, "")
|
|
@@ -31683,13 +32228,13 @@ var schemaUpdateIncidentReport = Joi99.object({
|
|
|
31683
32228
|
anyUnitAffectedValue: Joi99.string().valid("yes", "no").allow(null, ""),
|
|
31684
32229
|
affectedUnit: Joi99.any().optional(),
|
|
31685
32230
|
anyoneAffectedValue: Joi99.string().valid("yes", "no").allow(null, ""),
|
|
31686
|
-
affectedInjured: Joi99.array().items(
|
|
32231
|
+
affectedInjured: Joi99.array().items(affectedInjuredStatusSchema).optional().allow(null, ""),
|
|
31687
32232
|
anyPropertyAffectedValue: Joi99.string().valid("yes", "no").allow(null, ""),
|
|
31688
|
-
anyoneDamageToProperty: Joi99.array().items(
|
|
31689
|
-
}).allow(null, ""),
|
|
32233
|
+
anyoneDamageToProperty: Joi99.array().items(anyoneDamageToPropertyStatusSchema).optional().allow(null, "")
|
|
32234
|
+
}).optional().allow(null, ""),
|
|
31690
32235
|
authorities: Joi99.object({
|
|
31691
32236
|
authoritiesValue: Joi99.string().valid("yes", "no").allow(null, ""),
|
|
31692
|
-
authoritiesCalled: Joi99.array().items(
|
|
32237
|
+
authoritiesCalled: Joi99.array().items(authoritiesCalledStatusSchema).optional().allow(null, ""),
|
|
31693
32238
|
incidentThereAfter: Joi99.string().optional().allow("", null),
|
|
31694
32239
|
managementNotified: actionStatusSchema.optional(),
|
|
31695
32240
|
incidentResolved: Joi99.string().optional().allow("", null),
|
|
@@ -31713,7 +32258,7 @@ var schemaUpdateIncidentReport = Joi99.object({
|
|
|
31713
32258
|
photos: Joi99.array().items(Joi99.string()).optional(),
|
|
31714
32259
|
approvedBy: Joi99.string().hex().allow(null, "").optional(),
|
|
31715
32260
|
approvedByName: Joi99.string().optional().allow("", null),
|
|
31716
|
-
|
|
32261
|
+
remarks: Joi99.string().optional().allow("", null),
|
|
31717
32262
|
status: Joi99.string().valid("pending", "approved", "rejected").default("pending")
|
|
31718
32263
|
});
|
|
31719
32264
|
function MIncidentReport(value) {
|
|
@@ -31755,14 +32300,6 @@ function MIncidentReport(value) {
|
|
|
31755
32300
|
throw new Error("Invalid siteInfo.site ID.");
|
|
31756
32301
|
}
|
|
31757
32302
|
}
|
|
31758
|
-
const place = incidentInformation?.placeOfIncident;
|
|
31759
|
-
if (place?.unit && typeof place.unit === "string") {
|
|
31760
|
-
try {
|
|
31761
|
-
place.unit = new ObjectId96(place.unit);
|
|
31762
|
-
} catch {
|
|
31763
|
-
throw new Error("Invalid unit ID.");
|
|
31764
|
-
}
|
|
31765
|
-
}
|
|
31766
32303
|
if (incidentInformation?.incidentTypeAndTime?.dateOfIncident && typeof incidentInformation.incidentTypeAndTime.dateOfIncident !== "string") {
|
|
31767
32304
|
incidentInformation.incidentTypeAndTime.dateOfIncident = incidentInformation.incidentTypeAndTime.dateOfIncident.toISOString();
|
|
31768
32305
|
}
|
|
@@ -31784,7 +32321,7 @@ function MIncidentReport(value) {
|
|
|
31784
32321
|
photos: value.photos ?? [],
|
|
31785
32322
|
approvedBy: value.approvedBy ?? null,
|
|
31786
32323
|
approvedByName: value.approvedByName ?? "",
|
|
31787
|
-
|
|
32324
|
+
remarks: value.remarks ?? null,
|
|
31788
32325
|
status: value.status ?? "pending",
|
|
31789
32326
|
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
31790
32327
|
updatedAt: value.updatedAt,
|
|
@@ -31793,7 +32330,11 @@ function MIncidentReport(value) {
|
|
|
31793
32330
|
}
|
|
31794
32331
|
|
|
31795
32332
|
// src/services/incident-report.service.ts
|
|
31796
|
-
import {
|
|
32333
|
+
import {
|
|
32334
|
+
useAtlas as useAtlas88,
|
|
32335
|
+
BadRequestError as BadRequestError160,
|
|
32336
|
+
NotFoundError as NotFoundError44
|
|
32337
|
+
} from "@7365admin1/node-server-utils";
|
|
31797
32338
|
|
|
31798
32339
|
// src/repositories/incident-report.repo.ts
|
|
31799
32340
|
import {
|
|
@@ -31992,6 +32533,37 @@ function useIncidentReportRepo() {
|
|
|
31992
32533
|
} catch (error) {
|
|
31993
32534
|
throw new BadRequestError159("Invalid ID format.");
|
|
31994
32535
|
}
|
|
32536
|
+
if (value.organization && typeof value.organization === "string") {
|
|
32537
|
+
try {
|
|
32538
|
+
value.organization = new ObjectId97(value.organization);
|
|
32539
|
+
} catch {
|
|
32540
|
+
throw new Error("Invalid organization ID.");
|
|
32541
|
+
}
|
|
32542
|
+
}
|
|
32543
|
+
if (value.site && typeof value.site === "string") {
|
|
32544
|
+
try {
|
|
32545
|
+
value.site = new ObjectId97(value.site);
|
|
32546
|
+
} catch {
|
|
32547
|
+
throw new Error("Invalid site ID.");
|
|
32548
|
+
}
|
|
32549
|
+
}
|
|
32550
|
+
if (value.approvedBy && typeof value.approvedBy === "string") {
|
|
32551
|
+
try {
|
|
32552
|
+
value.approvedBy = new ObjectId97(value.approvedBy);
|
|
32553
|
+
} catch {
|
|
32554
|
+
throw new Error("Invalid approvedBy ID.");
|
|
32555
|
+
}
|
|
32556
|
+
}
|
|
32557
|
+
const { incidentInformation } = value;
|
|
32558
|
+
if (incidentInformation?.siteInfo?.site && typeof incidentInformation.siteInfo.site === "string") {
|
|
32559
|
+
try {
|
|
32560
|
+
incidentInformation.siteInfo.site = new ObjectId97(
|
|
32561
|
+
incidentInformation.siteInfo.site
|
|
32562
|
+
);
|
|
32563
|
+
} catch {
|
|
32564
|
+
throw new Error("Invalid siteInfo.site ID.");
|
|
32565
|
+
}
|
|
32566
|
+
}
|
|
31995
32567
|
try {
|
|
31996
32568
|
const res = await collection.updateOne(
|
|
31997
32569
|
{ _id },
|
|
@@ -32045,6 +32617,37 @@ function useIncidentReportRepo() {
|
|
|
32045
32617
|
throw error;
|
|
32046
32618
|
}
|
|
32047
32619
|
}
|
|
32620
|
+
async function reviewIncidentReport(_id, value, session) {
|
|
32621
|
+
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
32622
|
+
try {
|
|
32623
|
+
_id = new ObjectId97(_id);
|
|
32624
|
+
} catch (error) {
|
|
32625
|
+
throw new BadRequestError159("Invalid ID format.");
|
|
32626
|
+
}
|
|
32627
|
+
try {
|
|
32628
|
+
const res = await collection.updateOne(
|
|
32629
|
+
{ _id },
|
|
32630
|
+
{ $set: value },
|
|
32631
|
+
{ session }
|
|
32632
|
+
);
|
|
32633
|
+
if (res.modifiedCount === 0) {
|
|
32634
|
+
throw new InternalServerError55(
|
|
32635
|
+
`Unable to ${value.status} incident report.`
|
|
32636
|
+
);
|
|
32637
|
+
}
|
|
32638
|
+
delNamespace().then(() => {
|
|
32639
|
+
logger139.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
32640
|
+
}).catch((err) => {
|
|
32641
|
+
logger139.error(
|
|
32642
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
32643
|
+
err
|
|
32644
|
+
);
|
|
32645
|
+
});
|
|
32646
|
+
return res;
|
|
32647
|
+
} catch (error) {
|
|
32648
|
+
throw error;
|
|
32649
|
+
}
|
|
32650
|
+
}
|
|
32048
32651
|
return {
|
|
32049
32652
|
add,
|
|
32050
32653
|
getAll,
|
|
@@ -32052,20 +32655,29 @@ function useIncidentReportRepo() {
|
|
|
32052
32655
|
updateIncidentReportById,
|
|
32053
32656
|
deleteIncidentReportById,
|
|
32054
32657
|
createIndexes,
|
|
32055
|
-
createTextIndex
|
|
32658
|
+
createTextIndex,
|
|
32659
|
+
reviewIncidentReport
|
|
32056
32660
|
};
|
|
32057
32661
|
}
|
|
32058
32662
|
|
|
32059
32663
|
// src/services/incident-report.service.ts
|
|
32060
32664
|
import OpenAI from "openai";
|
|
32061
32665
|
function useIncidentReportService() {
|
|
32062
|
-
const {
|
|
32666
|
+
const {
|
|
32667
|
+
add: _add,
|
|
32668
|
+
updateIncidentReportById: _updateIncidentReportById,
|
|
32669
|
+
reviewIncidentReport: _reviewIncidentReport,
|
|
32670
|
+
getIncidentReportById: _getIncidentReportById
|
|
32671
|
+
} = useIncidentReportRepo();
|
|
32063
32672
|
const {
|
|
32064
32673
|
updateSiteIncidentCounter: _updateSiteIncidentCounter,
|
|
32065
32674
|
getSiteById: _getSiteById
|
|
32066
32675
|
} = useSiteRepo();
|
|
32676
|
+
const { updateStatusById } = useFileRepo();
|
|
32677
|
+
const { getUserById } = useUserRepo();
|
|
32067
32678
|
const { getById: _getUnitById } = useBuildingUnitRepo();
|
|
32068
32679
|
const { getById: _getOrganizationById } = useOrgRepo();
|
|
32680
|
+
const { deleteFile } = useFileService();
|
|
32069
32681
|
async function add(value) {
|
|
32070
32682
|
const session = useAtlas88.getClient()?.startSession();
|
|
32071
32683
|
session?.startTransaction();
|
|
@@ -32083,23 +32695,22 @@ function useIncidentReportService() {
|
|
|
32083
32695
|
);
|
|
32084
32696
|
}
|
|
32085
32697
|
}
|
|
32086
|
-
|
|
32087
|
-
|
|
32088
|
-
|
|
32089
|
-
|
|
32090
|
-
|
|
32091
|
-
|
|
32092
|
-
|
|
32093
|
-
"Building unit not found for the provided place of incident."
|
|
32698
|
+
const incidentAttachments = value?.photos ?? [];
|
|
32699
|
+
if (incidentAttachments.length > 0) {
|
|
32700
|
+
for (const attachment of incidentAttachments) {
|
|
32701
|
+
const file = await updateStatusById(
|
|
32702
|
+
attachment,
|
|
32703
|
+
{ status: "active" },
|
|
32704
|
+
session
|
|
32094
32705
|
);
|
|
32706
|
+
if (!file) {
|
|
32707
|
+
throw new NotFoundError44("File not found.");
|
|
32708
|
+
}
|
|
32095
32709
|
}
|
|
32096
|
-
value.incidentInformation.placeOfIncident.incidentLocation = value.incidentInformation.placeOfIncident.block?.toString() + "-" + value.incidentInformation.placeOfIncident.level + "-" + unit?.name;
|
|
32097
|
-
} else {
|
|
32098
|
-
value.incidentInformation.placeOfIncident.incidentLocation = value.incidentInformation.placeOfIncident.other;
|
|
32099
32710
|
}
|
|
32100
|
-
await _add(value, session);
|
|
32711
|
+
const result = await _add(value, session);
|
|
32101
32712
|
await session?.commitTransaction();
|
|
32102
|
-
return
|
|
32713
|
+
return result;
|
|
32103
32714
|
} catch (error) {
|
|
32104
32715
|
await session?.abortTransaction();
|
|
32105
32716
|
throw error;
|
|
@@ -32111,6 +32722,26 @@ function useIncidentReportService() {
|
|
|
32111
32722
|
const session = useAtlas88.getClient()?.startSession();
|
|
32112
32723
|
session?.startTransaction();
|
|
32113
32724
|
try {
|
|
32725
|
+
const incidentReport = await _getIncidentReportById(id);
|
|
32726
|
+
const dataAttchments = value?.photos || [];
|
|
32727
|
+
const incidentAttachments = incidentReport?.photos || [];
|
|
32728
|
+
const deletedFiles = [];
|
|
32729
|
+
incidentAttachments.forEach((id2) => {
|
|
32730
|
+
if (!dataAttchments.includes(id2)) {
|
|
32731
|
+
deletedFiles.push(id2);
|
|
32732
|
+
}
|
|
32733
|
+
});
|
|
32734
|
+
if (deletedFiles.length > 0) {
|
|
32735
|
+
await Promise.all(
|
|
32736
|
+
deletedFiles.map(async (id2) => {
|
|
32737
|
+
try {
|
|
32738
|
+
await deleteFile(id2);
|
|
32739
|
+
} catch (error) {
|
|
32740
|
+
throw error;
|
|
32741
|
+
}
|
|
32742
|
+
})
|
|
32743
|
+
);
|
|
32744
|
+
}
|
|
32114
32745
|
await _updateIncidentReportById(id, value, session);
|
|
32115
32746
|
await session?.commitTransaction();
|
|
32116
32747
|
return "Successfully updated incident report.";
|
|
@@ -32146,19 +32777,10 @@ function useIncidentReportService() {
|
|
|
32146
32777
|
value.site = site.name;
|
|
32147
32778
|
}
|
|
32148
32779
|
}
|
|
32149
|
-
if (value?.
|
|
32150
|
-
const
|
|
32151
|
-
|
|
32152
|
-
|
|
32153
|
-
);
|
|
32154
|
-
if (unit) {
|
|
32155
|
-
value.incidentInformation.placeOfIncident.unit = unit.name;
|
|
32156
|
-
}
|
|
32157
|
-
if (value?.organization) {
|
|
32158
|
-
const org = await _getOrganizationById(value.organization);
|
|
32159
|
-
if (org) {
|
|
32160
|
-
value.organization = org.name;
|
|
32161
|
-
}
|
|
32780
|
+
if (value?.organization) {
|
|
32781
|
+
const org = await _getOrganizationById(value.organization);
|
|
32782
|
+
if (org) {
|
|
32783
|
+
value.organization = org.name;
|
|
32162
32784
|
}
|
|
32163
32785
|
}
|
|
32164
32786
|
const completion = await openai.chat.completions.create({
|
|
@@ -32181,21 +32803,44 @@ function useIncidentReportService() {
|
|
|
32181
32803
|
throw error;
|
|
32182
32804
|
}
|
|
32183
32805
|
}
|
|
32806
|
+
async function reviewIncidentReport(id, value) {
|
|
32807
|
+
const session = useAtlas88.getClient()?.startSession();
|
|
32808
|
+
session?.startTransaction();
|
|
32809
|
+
try {
|
|
32810
|
+
if (value.approvedBy) {
|
|
32811
|
+
const approvedBy = await getUserById(value.approvedBy);
|
|
32812
|
+
if (!approvedBy || !approvedBy.name)
|
|
32813
|
+
throw new BadRequestError160("Created by not found.");
|
|
32814
|
+
value.approvedByName = approvedBy.name;
|
|
32815
|
+
value.approvedBy = approvedBy._id;
|
|
32816
|
+
}
|
|
32817
|
+
await _reviewIncidentReport(id, value, session);
|
|
32818
|
+
await session?.commitTransaction();
|
|
32819
|
+
return `Successfully ${value.status} incident report.`;
|
|
32820
|
+
} catch (error) {
|
|
32821
|
+
await session?.abortTransaction();
|
|
32822
|
+
throw error;
|
|
32823
|
+
} finally {
|
|
32824
|
+
session?.endSession();
|
|
32825
|
+
}
|
|
32826
|
+
}
|
|
32184
32827
|
return {
|
|
32185
32828
|
add,
|
|
32186
32829
|
updateIncidentReportById,
|
|
32187
|
-
createIncidentSummary
|
|
32830
|
+
createIncidentSummary,
|
|
32831
|
+
reviewIncidentReport
|
|
32188
32832
|
};
|
|
32189
32833
|
}
|
|
32190
32834
|
|
|
32191
32835
|
// src/controllers/incident-report.controller.ts
|
|
32192
|
-
import { BadRequestError as
|
|
32836
|
+
import { BadRequestError as BadRequestError161, logger as logger140 } from "@7365admin1/node-server-utils";
|
|
32193
32837
|
import Joi100 from "joi";
|
|
32194
32838
|
function useIncidentReportController() {
|
|
32195
32839
|
const {
|
|
32196
32840
|
add: _add,
|
|
32197
32841
|
updateIncidentReportById: _updateIncidentReportById,
|
|
32198
|
-
createIncidentSummary: _createIncidentSummary
|
|
32842
|
+
createIncidentSummary: _createIncidentSummary,
|
|
32843
|
+
reviewIncidentReport: _reviewIncidentReport
|
|
32199
32844
|
} = useIncidentReportService();
|
|
32200
32845
|
const {
|
|
32201
32846
|
getAll: _getAll,
|
|
@@ -32210,12 +32855,12 @@ function useIncidentReportController() {
|
|
|
32210
32855
|
if (error) {
|
|
32211
32856
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
32212
32857
|
logger140.log({ level: "error", message: messages });
|
|
32213
|
-
next(new
|
|
32858
|
+
next(new BadRequestError161(messages));
|
|
32214
32859
|
return;
|
|
32215
32860
|
}
|
|
32216
32861
|
try {
|
|
32217
32862
|
const data = await _add(payload);
|
|
32218
|
-
res.status(201).json(data);
|
|
32863
|
+
res.status(201).json({ data });
|
|
32219
32864
|
return;
|
|
32220
32865
|
} catch (error2) {
|
|
32221
32866
|
logger140.log({ level: "error", message: error2.message });
|
|
@@ -32243,7 +32888,7 @@ function useIncidentReportController() {
|
|
|
32243
32888
|
if (error) {
|
|
32244
32889
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
32245
32890
|
logger140.log({ level: "error", message: messages });
|
|
32246
|
-
next(new
|
|
32891
|
+
next(new BadRequestError161(messages));
|
|
32247
32892
|
return;
|
|
32248
32893
|
}
|
|
32249
32894
|
const search = req.query.search ?? "";
|
|
@@ -32285,7 +32930,7 @@ function useIncidentReportController() {
|
|
|
32285
32930
|
const { error } = validation.validate(_id);
|
|
32286
32931
|
if (error) {
|
|
32287
32932
|
logger140.log({ level: "error", message: error.message });
|
|
32288
|
-
next(new
|
|
32933
|
+
next(new BadRequestError161(error.message));
|
|
32289
32934
|
return;
|
|
32290
32935
|
}
|
|
32291
32936
|
try {
|
|
@@ -32307,7 +32952,7 @@ function useIncidentReportController() {
|
|
|
32307
32952
|
if (error) {
|
|
32308
32953
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
32309
32954
|
logger140.log({ level: "error", message: messages });
|
|
32310
|
-
next(new
|
|
32955
|
+
next(new BadRequestError161(messages));
|
|
32311
32956
|
return;
|
|
32312
32957
|
}
|
|
32313
32958
|
try {
|
|
@@ -32326,7 +32971,7 @@ function useIncidentReportController() {
|
|
|
32326
32971
|
const { error } = validation.validate(_id);
|
|
32327
32972
|
if (error) {
|
|
32328
32973
|
logger140.log({ level: "error", message: error.message });
|
|
32329
|
-
next(new
|
|
32974
|
+
next(new BadRequestError161(error.message));
|
|
32330
32975
|
return;
|
|
32331
32976
|
}
|
|
32332
32977
|
try {
|
|
@@ -32347,7 +32992,7 @@ function useIncidentReportController() {
|
|
|
32347
32992
|
if (error) {
|
|
32348
32993
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
32349
32994
|
logger140.log({ level: "error", message: messages });
|
|
32350
|
-
next(new
|
|
32995
|
+
next(new BadRequestError161(messages));
|
|
32351
32996
|
return;
|
|
32352
32997
|
}
|
|
32353
32998
|
try {
|
|
@@ -32363,20 +33008,52 @@ function useIncidentReportController() {
|
|
|
32363
33008
|
return;
|
|
32364
33009
|
}
|
|
32365
33010
|
}
|
|
33011
|
+
async function reviewIncidentReport(req, res, next) {
|
|
33012
|
+
const cookies = req.headers.cookie?.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
33013
|
+
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
33014
|
+
{}
|
|
33015
|
+
);
|
|
33016
|
+
req.body.approvedBy = cookies?.["user"].toString() ?? "";
|
|
33017
|
+
const _id = req.params.id;
|
|
33018
|
+
const payload = { _id, ...req.body };
|
|
33019
|
+
const schema2 = Joi100.object({
|
|
33020
|
+
_id: Joi100.string().hex().required(),
|
|
33021
|
+
status: Joi100.string().valid("approved", "rejected").required(),
|
|
33022
|
+
approvedBy: Joi100.string().required(),
|
|
33023
|
+
remarks: Joi100.string().optional().allow("", null)
|
|
33024
|
+
});
|
|
33025
|
+
const { error } = schema2.validate(payload);
|
|
33026
|
+
if (error) {
|
|
33027
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
33028
|
+
logger140.log({ level: "error", message: messages });
|
|
33029
|
+
next(new BadRequestError161(messages));
|
|
33030
|
+
return;
|
|
33031
|
+
}
|
|
33032
|
+
try {
|
|
33033
|
+
const result = await _reviewIncidentReport(_id, req.body);
|
|
33034
|
+
res.status(200).json({ message: result });
|
|
33035
|
+
return;
|
|
33036
|
+
} catch (error2) {
|
|
33037
|
+
logger140.log({ level: "error", message: error2.message });
|
|
33038
|
+
next(error2);
|
|
33039
|
+
return;
|
|
33040
|
+
}
|
|
33041
|
+
}
|
|
32366
33042
|
return {
|
|
32367
33043
|
add,
|
|
32368
33044
|
getAll,
|
|
32369
33045
|
getIncidentReportById,
|
|
32370
33046
|
updateIncidentReportById,
|
|
32371
33047
|
deleteIncidentReportById,
|
|
32372
|
-
createIncidentSummary
|
|
33048
|
+
createIncidentSummary,
|
|
33049
|
+
reviewIncidentReport
|
|
32373
33050
|
};
|
|
32374
33051
|
}
|
|
32375
33052
|
|
|
32376
33053
|
// src/models/nfc-patrol-settings.model.ts
|
|
32377
33054
|
import { ObjectId as ObjectId98 } from "mongodb";
|
|
32378
33055
|
import Joi101 from "joi";
|
|
32379
|
-
import { BadRequestError as
|
|
33056
|
+
import { BadRequestError as BadRequestError162, logger as logger141 } from "@7365admin1/node-server-utils";
|
|
32380
33057
|
var objectId = Joi101.string().hex().length(24);
|
|
32381
33058
|
var nfcPatrolSettingsSchema = Joi101.object({
|
|
32382
33059
|
site: objectId.required(),
|
|
@@ -32396,13 +33073,13 @@ function MNfcPatrolSettings(value) {
|
|
|
32396
33073
|
const { error } = nfcPatrolSettingsSchema.validate(value);
|
|
32397
33074
|
if (error) {
|
|
32398
33075
|
logger141.info(`NFC Patrol Settings Model: ${error.message}`);
|
|
32399
|
-
throw new
|
|
33076
|
+
throw new BadRequestError162(error.message);
|
|
32400
33077
|
}
|
|
32401
33078
|
if (value.site) {
|
|
32402
33079
|
try {
|
|
32403
33080
|
value.site = new ObjectId98(value.site);
|
|
32404
33081
|
} catch (error2) {
|
|
32405
|
-
throw new
|
|
33082
|
+
throw new BadRequestError162("Invalid site ID format.");
|
|
32406
33083
|
}
|
|
32407
33084
|
}
|
|
32408
33085
|
return {
|
|
@@ -32416,13 +33093,13 @@ function MNfcPatrolSettingsUpdate(value) {
|
|
|
32416
33093
|
const { error } = nfcPatrolSettingsSchemaUpdate.validate(value);
|
|
32417
33094
|
if (error) {
|
|
32418
33095
|
logger141.info(`NFC Patrol Settings Model: ${error.message}`);
|
|
32419
|
-
throw new
|
|
33096
|
+
throw new BadRequestError162(error.message);
|
|
32420
33097
|
}
|
|
32421
33098
|
if (value.updatedBy) {
|
|
32422
33099
|
try {
|
|
32423
33100
|
value.updatedBy = new ObjectId98(value.updatedBy);
|
|
32424
33101
|
} catch (error2) {
|
|
32425
|
-
throw new
|
|
33102
|
+
throw new BadRequestError162("Invalid updatedBy ID format.");
|
|
32426
33103
|
}
|
|
32427
33104
|
}
|
|
32428
33105
|
return {
|
|
@@ -32434,11 +33111,11 @@ function MNfcPatrolSettingsUpdate(value) {
|
|
|
32434
33111
|
|
|
32435
33112
|
// src/repositories/nfc-patrol-settings.repository.ts
|
|
32436
33113
|
import {
|
|
32437
|
-
BadRequestError as
|
|
33114
|
+
BadRequestError as BadRequestError163,
|
|
32438
33115
|
InternalServerError as InternalServerError56,
|
|
32439
33116
|
logger as logger142,
|
|
32440
33117
|
makeCacheKey as makeCacheKey53,
|
|
32441
|
-
NotFoundError as
|
|
33118
|
+
NotFoundError as NotFoundError45,
|
|
32442
33119
|
useAtlas as useAtlas89,
|
|
32443
33120
|
useCache as useCache55
|
|
32444
33121
|
} from "@7365admin1/node-server-utils";
|
|
@@ -32474,7 +33151,7 @@ function useNfcPatrolSettingsRepository() {
|
|
|
32474
33151
|
try {
|
|
32475
33152
|
site = new ObjectId99(site);
|
|
32476
33153
|
} catch (error) {
|
|
32477
|
-
throw new
|
|
33154
|
+
throw new BadRequestError163("Invalid nfc patrol settings site ID format.");
|
|
32478
33155
|
}
|
|
32479
33156
|
const query = { site };
|
|
32480
33157
|
const cacheKey = makeCacheKey53(namespace_collection, {
|
|
@@ -32518,7 +33195,7 @@ function useNfcPatrolSettingsRepository() {
|
|
|
32518
33195
|
try {
|
|
32519
33196
|
site = new ObjectId99(site);
|
|
32520
33197
|
} catch (error) {
|
|
32521
|
-
throw new
|
|
33198
|
+
throw new BadRequestError163("Invalid attendance settings ID format.");
|
|
32522
33199
|
}
|
|
32523
33200
|
try {
|
|
32524
33201
|
value = MNfcPatrolSettingsUpdate(value);
|
|
@@ -32528,7 +33205,7 @@ function useNfcPatrolSettingsRepository() {
|
|
|
32528
33205
|
{ session }
|
|
32529
33206
|
);
|
|
32530
33207
|
if (res.matchedCount === 0) {
|
|
32531
|
-
throw new
|
|
33208
|
+
throw new NotFoundError45("NFC patrol settings not found for this site.");
|
|
32532
33209
|
}
|
|
32533
33210
|
delNamespace().then(() => {
|
|
32534
33211
|
logger142.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
@@ -32566,7 +33243,7 @@ function useNfcPatrolSettingsRepository() {
|
|
|
32566
33243
|
|
|
32567
33244
|
// src/services/nfc-patrol-settings.service.ts
|
|
32568
33245
|
import {
|
|
32569
|
-
BadRequestError as
|
|
33246
|
+
BadRequestError as BadRequestError164,
|
|
32570
33247
|
logger as logger143,
|
|
32571
33248
|
useAtlas as useAtlas90
|
|
32572
33249
|
} from "@7365admin1/node-server-utils";
|
|
@@ -32612,7 +33289,7 @@ function useNfcPatrolSettingsService() {
|
|
|
32612
33289
|
async function updateNfcPatrolSettings(site, value) {
|
|
32613
33290
|
const session = useAtlas90.getClient()?.startSession();
|
|
32614
33291
|
if (!session) {
|
|
32615
|
-
throw new
|
|
33292
|
+
throw new BadRequestError164("Database session not available.");
|
|
32616
33293
|
}
|
|
32617
33294
|
try {
|
|
32618
33295
|
await session.startTransaction();
|
|
@@ -32635,7 +33312,7 @@ function useNfcPatrolSettingsService() {
|
|
|
32635
33312
|
|
|
32636
33313
|
// src/controllers/nfc-patrol-settings.controller.ts
|
|
32637
33314
|
import Joi102 from "joi";
|
|
32638
|
-
import { BadRequestError as
|
|
33315
|
+
import { BadRequestError as BadRequestError165, logger as logger144 } from "@7365admin1/node-server-utils";
|
|
32639
33316
|
function useNfcPatrolSettingsController() {
|
|
32640
33317
|
const { getNfcPatrolSettingsBySite: _getNfcPatrolSettingsBySite } = useNfcPatrolSettingsService();
|
|
32641
33318
|
const { updateNfcPatrolSettings: _updateNfcPatrolSettings } = useNfcPatrolSettingsService();
|
|
@@ -32645,7 +33322,7 @@ function useNfcPatrolSettingsController() {
|
|
|
32645
33322
|
const { error } = validation.validate(site);
|
|
32646
33323
|
if (error) {
|
|
32647
33324
|
logger144.log({ level: "error", message: error.message });
|
|
32648
|
-
next(new
|
|
33325
|
+
next(new BadRequestError165(error.message));
|
|
32649
33326
|
return;
|
|
32650
33327
|
}
|
|
32651
33328
|
try {
|
|
@@ -32688,11 +33365,11 @@ import { useAtlas as useAtlas92 } from "@7365admin1/node-server-utils";
|
|
|
32688
33365
|
|
|
32689
33366
|
// src/repositories/occurrence-subject.repo.ts
|
|
32690
33367
|
import {
|
|
32691
|
-
BadRequestError as
|
|
33368
|
+
BadRequestError as BadRequestError166,
|
|
32692
33369
|
InternalServerError as InternalServerError57,
|
|
32693
33370
|
logger as logger145,
|
|
32694
33371
|
makeCacheKey as makeCacheKey54,
|
|
32695
|
-
NotFoundError as
|
|
33372
|
+
NotFoundError as NotFoundError46,
|
|
32696
33373
|
paginate as paginate46,
|
|
32697
33374
|
useAtlas as useAtlas91,
|
|
32698
33375
|
useCache as useCache56
|
|
@@ -32789,7 +33466,7 @@ function useOccurrenceSubjectRepo() {
|
|
|
32789
33466
|
} catch (error) {
|
|
32790
33467
|
const isDuplicated = error.message.includes("duplicate");
|
|
32791
33468
|
if (isDuplicated) {
|
|
32792
|
-
throw new
|
|
33469
|
+
throw new BadRequestError166("Occurrence subject already exists.");
|
|
32793
33470
|
}
|
|
32794
33471
|
throw error;
|
|
32795
33472
|
}
|
|
@@ -32805,7 +33482,7 @@ function useOccurrenceSubjectRepo() {
|
|
|
32805
33482
|
try {
|
|
32806
33483
|
site = new ObjectId101(site);
|
|
32807
33484
|
} catch (error) {
|
|
32808
|
-
throw new
|
|
33485
|
+
throw new BadRequestError166("Invalid site ID format.");
|
|
32809
33486
|
}
|
|
32810
33487
|
const baseQuery = {
|
|
32811
33488
|
site,
|
|
@@ -32900,7 +33577,7 @@ function useOccurrenceSubjectRepo() {
|
|
|
32900
33577
|
try {
|
|
32901
33578
|
_id = new ObjectId101(_id);
|
|
32902
33579
|
} catch (error) {
|
|
32903
|
-
throw new
|
|
33580
|
+
throw new BadRequestError166("Invalid occurrence subject ID format.");
|
|
32904
33581
|
}
|
|
32905
33582
|
const cacheKey = makeCacheKey54(namespace_collection, { _id });
|
|
32906
33583
|
const cachedData = await getCache(cacheKey);
|
|
@@ -32911,7 +33588,7 @@ function useOccurrenceSubjectRepo() {
|
|
|
32911
33588
|
try {
|
|
32912
33589
|
const data = await collection.findOne({ _id }, { session });
|
|
32913
33590
|
if (!data) {
|
|
32914
|
-
throw new
|
|
33591
|
+
throw new NotFoundError46("Occurrence subject not found.");
|
|
32915
33592
|
}
|
|
32916
33593
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
32917
33594
|
logger145.info(`Cache set for key: ${cacheKey}`);
|
|
@@ -32928,7 +33605,7 @@ function useOccurrenceSubjectRepo() {
|
|
|
32928
33605
|
try {
|
|
32929
33606
|
_id = new ObjectId101(_id);
|
|
32930
33607
|
} catch (error) {
|
|
32931
|
-
throw new
|
|
33608
|
+
throw new BadRequestError166("Invalid ID format.");
|
|
32932
33609
|
}
|
|
32933
33610
|
try {
|
|
32934
33611
|
const res = await collection.updateOne(
|
|
@@ -32958,7 +33635,7 @@ function useOccurrenceSubjectRepo() {
|
|
|
32958
33635
|
try {
|
|
32959
33636
|
_id = new ObjectId101(_id);
|
|
32960
33637
|
} catch (error) {
|
|
32961
|
-
throw new
|
|
33638
|
+
throw new BadRequestError166("Invalid occurrence subject ID format.");
|
|
32962
33639
|
}
|
|
32963
33640
|
try {
|
|
32964
33641
|
const updateValue = {
|
|
@@ -33073,7 +33750,7 @@ function useOccurrenceEntryService() {
|
|
|
33073
33750
|
}
|
|
33074
33751
|
|
|
33075
33752
|
// src/controllers/occurrence-entry.controller.ts
|
|
33076
|
-
import { BadRequestError as
|
|
33753
|
+
import { BadRequestError as BadRequestError167, logger as logger146 } from "@7365admin1/node-server-utils";
|
|
33077
33754
|
import Joi104 from "joi";
|
|
33078
33755
|
function useOccurrenceEntryController() {
|
|
33079
33756
|
const { add: _add, updateOccurrenceEntryById: _updateOccurrenceEntryById } = useOccurrenceEntryService();
|
|
@@ -33091,7 +33768,7 @@ function useOccurrenceEntryController() {
|
|
|
33091
33768
|
if (error) {
|
|
33092
33769
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
33093
33770
|
logger146.log({ level: "error", message: messages });
|
|
33094
|
-
next(new
|
|
33771
|
+
next(new BadRequestError167(messages));
|
|
33095
33772
|
return;
|
|
33096
33773
|
}
|
|
33097
33774
|
try {
|
|
@@ -33123,7 +33800,7 @@ function useOccurrenceEntryController() {
|
|
|
33123
33800
|
if (error) {
|
|
33124
33801
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
33125
33802
|
logger146.log({ level: "error", message: messages });
|
|
33126
|
-
next(new
|
|
33803
|
+
next(new BadRequestError167(messages));
|
|
33127
33804
|
return;
|
|
33128
33805
|
}
|
|
33129
33806
|
const search = req.query.search ?? "";
|
|
@@ -33163,7 +33840,7 @@ function useOccurrenceEntryController() {
|
|
|
33163
33840
|
const { error } = validation.validate(_id);
|
|
33164
33841
|
if (error) {
|
|
33165
33842
|
logger146.log({ level: "error", message: error.message });
|
|
33166
|
-
next(new
|
|
33843
|
+
next(new BadRequestError167(error.message));
|
|
33167
33844
|
return;
|
|
33168
33845
|
}
|
|
33169
33846
|
try {
|
|
@@ -33185,7 +33862,7 @@ function useOccurrenceEntryController() {
|
|
|
33185
33862
|
if (error) {
|
|
33186
33863
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
33187
33864
|
logger146.log({ level: "error", message: messages });
|
|
33188
|
-
next(new
|
|
33865
|
+
next(new BadRequestError167(messages));
|
|
33189
33866
|
return;
|
|
33190
33867
|
}
|
|
33191
33868
|
try {
|
|
@@ -33204,7 +33881,7 @@ function useOccurrenceEntryController() {
|
|
|
33204
33881
|
const { error } = validation.validate(_id);
|
|
33205
33882
|
if (error) {
|
|
33206
33883
|
logger146.log({ level: "error", message: error.message });
|
|
33207
|
-
next(new
|
|
33884
|
+
next(new BadRequestError167(error.message));
|
|
33208
33885
|
return;
|
|
33209
33886
|
}
|
|
33210
33887
|
try {
|
|
@@ -33223,7 +33900,7 @@ function useOccurrenceEntryController() {
|
|
|
33223
33900
|
const { error } = validation.validate(_id);
|
|
33224
33901
|
if (error) {
|
|
33225
33902
|
logger146.log({ level: "error", message: error.message });
|
|
33226
|
-
next(new
|
|
33903
|
+
next(new BadRequestError167(error.message));
|
|
33227
33904
|
return;
|
|
33228
33905
|
}
|
|
33229
33906
|
try {
|
|
@@ -33333,11 +34010,11 @@ function MOnlineForm(value) {
|
|
|
33333
34010
|
|
|
33334
34011
|
// src/repositories/online-form.repo.ts
|
|
33335
34012
|
import {
|
|
33336
|
-
BadRequestError as
|
|
34013
|
+
BadRequestError as BadRequestError168,
|
|
33337
34014
|
InternalServerError as InternalServerError58,
|
|
33338
34015
|
logger as logger147,
|
|
33339
34016
|
makeCacheKey as makeCacheKey55,
|
|
33340
|
-
NotFoundError as
|
|
34017
|
+
NotFoundError as NotFoundError47,
|
|
33341
34018
|
paginate as paginate47,
|
|
33342
34019
|
useAtlas as useAtlas93,
|
|
33343
34020
|
useCache as useCache57
|
|
@@ -33378,7 +34055,7 @@ function useOnlineFormRepo() {
|
|
|
33378
34055
|
} catch (error) {
|
|
33379
34056
|
const isDuplicated = error.message.includes("duplicate");
|
|
33380
34057
|
if (isDuplicated) {
|
|
33381
|
-
throw new
|
|
34058
|
+
throw new BadRequestError168("Online Form already exists.");
|
|
33382
34059
|
}
|
|
33383
34060
|
throw error;
|
|
33384
34061
|
}
|
|
@@ -33446,7 +34123,7 @@ function useOnlineFormRepo() {
|
|
|
33446
34123
|
try {
|
|
33447
34124
|
_id = new ObjectId103(_id);
|
|
33448
34125
|
} catch (error) {
|
|
33449
|
-
throw new
|
|
34126
|
+
throw new BadRequestError168("Invalid online form ID format.");
|
|
33450
34127
|
}
|
|
33451
34128
|
const cacheKey = makeCacheKey55(namespace_collection, { _id });
|
|
33452
34129
|
const cachedData = await getCache(cacheKey);
|
|
@@ -33473,7 +34150,7 @@ function useOnlineFormRepo() {
|
|
|
33473
34150
|
}
|
|
33474
34151
|
]).toArray();
|
|
33475
34152
|
if (!data || !data.length) {
|
|
33476
|
-
throw new
|
|
34153
|
+
throw new NotFoundError47("Document not found.");
|
|
33477
34154
|
}
|
|
33478
34155
|
setCache(cacheKey, data[0], 15 * 60).then(() => {
|
|
33479
34156
|
logger147.info(`Cache set for key: ${cacheKey}`);
|
|
@@ -33489,7 +34166,7 @@ function useOnlineFormRepo() {
|
|
|
33489
34166
|
try {
|
|
33490
34167
|
_id = new ObjectId103(_id);
|
|
33491
34168
|
} catch (error) {
|
|
33492
|
-
throw new
|
|
34169
|
+
throw new BadRequestError168("Invalid online form ID format.");
|
|
33493
34170
|
}
|
|
33494
34171
|
try {
|
|
33495
34172
|
const updateValue = {
|
|
@@ -33517,7 +34194,7 @@ function useOnlineFormRepo() {
|
|
|
33517
34194
|
try {
|
|
33518
34195
|
_id = new ObjectId103(_id);
|
|
33519
34196
|
} catch (error) {
|
|
33520
|
-
throw new
|
|
34197
|
+
throw new BadRequestError168("Invalid online form ID format.");
|
|
33521
34198
|
}
|
|
33522
34199
|
try {
|
|
33523
34200
|
const updateValue = {
|
|
@@ -33550,7 +34227,7 @@ function useOnlineFormRepo() {
|
|
|
33550
34227
|
try {
|
|
33551
34228
|
site = new ObjectId103(site);
|
|
33552
34229
|
} catch (error) {
|
|
33553
|
-
throw new
|
|
34230
|
+
throw new BadRequestError168(
|
|
33554
34231
|
"Invalid online form configuration site ID format."
|
|
33555
34232
|
);
|
|
33556
34233
|
}
|
|
@@ -33614,7 +34291,7 @@ function useOnlineFormRepo() {
|
|
|
33614
34291
|
}
|
|
33615
34292
|
|
|
33616
34293
|
// src/controllers/online-form.controller.ts
|
|
33617
|
-
import { BadRequestError as
|
|
34294
|
+
import { BadRequestError as BadRequestError169, logger as logger148 } from "@7365admin1/node-server-utils";
|
|
33618
34295
|
import Joi106 from "joi";
|
|
33619
34296
|
function useOnlineFormController() {
|
|
33620
34297
|
const {
|
|
@@ -33638,7 +34315,7 @@ function useOnlineFormController() {
|
|
|
33638
34315
|
if (error) {
|
|
33639
34316
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
33640
34317
|
logger148.log({ level: "error", message: messages });
|
|
33641
|
-
next(new
|
|
34318
|
+
next(new BadRequestError169(messages));
|
|
33642
34319
|
return;
|
|
33643
34320
|
}
|
|
33644
34321
|
try {
|
|
@@ -33665,7 +34342,7 @@ function useOnlineFormController() {
|
|
|
33665
34342
|
const { error } = validation.validate(query);
|
|
33666
34343
|
if (error) {
|
|
33667
34344
|
logger148.log({ level: "error", message: error.message });
|
|
33668
|
-
next(new
|
|
34345
|
+
next(new BadRequestError169(error.message));
|
|
33669
34346
|
return;
|
|
33670
34347
|
}
|
|
33671
34348
|
const search = req.query.search ?? "";
|
|
@@ -33690,7 +34367,7 @@ function useOnlineFormController() {
|
|
|
33690
34367
|
const { error } = validation.validate(_id);
|
|
33691
34368
|
if (error) {
|
|
33692
34369
|
logger148.log({ level: "error", message: error.message });
|
|
33693
|
-
next(new
|
|
34370
|
+
next(new BadRequestError169(error.message));
|
|
33694
34371
|
return;
|
|
33695
34372
|
}
|
|
33696
34373
|
try {
|
|
@@ -33731,7 +34408,7 @@ function useOnlineFormController() {
|
|
|
33731
34408
|
const { error } = validation.validate({ _id, ...payload });
|
|
33732
34409
|
if (error) {
|
|
33733
34410
|
logger148.log({ level: "error", message: error.message });
|
|
33734
|
-
next(new
|
|
34411
|
+
next(new BadRequestError169(error.message));
|
|
33735
34412
|
return;
|
|
33736
34413
|
}
|
|
33737
34414
|
try {
|
|
@@ -33750,7 +34427,7 @@ function useOnlineFormController() {
|
|
|
33750
34427
|
const { error } = validation.validate(_id);
|
|
33751
34428
|
if (error) {
|
|
33752
34429
|
logger148.log({ level: "error", message: error.message });
|
|
33753
|
-
next(new
|
|
34430
|
+
next(new BadRequestError169(error.message));
|
|
33754
34431
|
return;
|
|
33755
34432
|
}
|
|
33756
34433
|
try {
|
|
@@ -33771,7 +34448,7 @@ function useOnlineFormController() {
|
|
|
33771
34448
|
const { error } = validation.validate(_id);
|
|
33772
34449
|
if (error) {
|
|
33773
34450
|
logger148.log({ level: "error", message: error.message });
|
|
33774
|
-
next(new
|
|
34451
|
+
next(new BadRequestError169(error.message));
|
|
33775
34452
|
return;
|
|
33776
34453
|
}
|
|
33777
34454
|
try {
|
|
@@ -33836,7 +34513,7 @@ function useOccurrenceSubjectService() {
|
|
|
33836
34513
|
}
|
|
33837
34514
|
|
|
33838
34515
|
// src/controllers/occurrence-subject.controller.ts
|
|
33839
|
-
import { BadRequestError as
|
|
34516
|
+
import { BadRequestError as BadRequestError170, logger as logger149 } from "@7365admin1/node-server-utils";
|
|
33840
34517
|
import Joi107 from "joi";
|
|
33841
34518
|
function useOccurrenceSubjectController() {
|
|
33842
34519
|
const {
|
|
@@ -33856,7 +34533,7 @@ function useOccurrenceSubjectController() {
|
|
|
33856
34533
|
if (error) {
|
|
33857
34534
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
33858
34535
|
logger149.log({ level: "error", message: messages });
|
|
33859
|
-
next(new
|
|
34536
|
+
next(new BadRequestError170(messages));
|
|
33860
34537
|
return;
|
|
33861
34538
|
}
|
|
33862
34539
|
try {
|
|
@@ -33887,7 +34564,7 @@ function useOccurrenceSubjectController() {
|
|
|
33887
34564
|
if (error) {
|
|
33888
34565
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
33889
34566
|
logger149.log({ level: "error", message: messages });
|
|
33890
|
-
next(new
|
|
34567
|
+
next(new BadRequestError170(messages));
|
|
33891
34568
|
return;
|
|
33892
34569
|
}
|
|
33893
34570
|
const search = req.query.search ?? "";
|
|
@@ -33925,7 +34602,7 @@ function useOccurrenceSubjectController() {
|
|
|
33925
34602
|
const { error } = validation.validate(_id);
|
|
33926
34603
|
if (error) {
|
|
33927
34604
|
logger149.log({ level: "error", message: error.message });
|
|
33928
|
-
next(new
|
|
34605
|
+
next(new BadRequestError170(error.message));
|
|
33929
34606
|
return;
|
|
33930
34607
|
}
|
|
33931
34608
|
try {
|
|
@@ -33947,7 +34624,7 @@ function useOccurrenceSubjectController() {
|
|
|
33947
34624
|
if (error) {
|
|
33948
34625
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
33949
34626
|
logger149.log({ level: "error", message: messages });
|
|
33950
|
-
next(new
|
|
34627
|
+
next(new BadRequestError170(messages));
|
|
33951
34628
|
return;
|
|
33952
34629
|
}
|
|
33953
34630
|
try {
|
|
@@ -33966,7 +34643,7 @@ function useOccurrenceSubjectController() {
|
|
|
33966
34643
|
const { error } = validation.validate(_id);
|
|
33967
34644
|
if (error) {
|
|
33968
34645
|
logger149.log({ level: "error", message: error.message });
|
|
33969
|
-
next(new
|
|
34646
|
+
next(new BadRequestError170(error.message));
|
|
33970
34647
|
return;
|
|
33971
34648
|
}
|
|
33972
34649
|
try {
|
|
@@ -33991,7 +34668,7 @@ function useOccurrenceSubjectController() {
|
|
|
33991
34668
|
// src/models/nfc-patrol-log.model.ts
|
|
33992
34669
|
import { ObjectId as ObjectId104 } from "mongodb";
|
|
33993
34670
|
import Joi108 from "joi";
|
|
33994
|
-
import { BadRequestError as
|
|
34671
|
+
import { BadRequestError as BadRequestError171, logger as logger150 } from "@7365admin1/node-server-utils";
|
|
33995
34672
|
var schemaNfcPatrolLog = Joi108.object({
|
|
33996
34673
|
_id: Joi108.string().length(24).hex().optional().allow(null, ""),
|
|
33997
34674
|
site: Joi108.string().length(24).hex().required(),
|
|
@@ -34037,32 +34714,32 @@ function MNfcPatrolLog(valueArg) {
|
|
|
34037
34714
|
const { error, value } = schemaNfcPatrolLog.validate(valueArg);
|
|
34038
34715
|
if (error) {
|
|
34039
34716
|
logger150.info(`NFC Patrol Log Model: ${error.message}`);
|
|
34040
|
-
throw new
|
|
34717
|
+
throw new BadRequestError171(error.message);
|
|
34041
34718
|
}
|
|
34042
34719
|
if (value._id && typeof value._id === "string") {
|
|
34043
34720
|
try {
|
|
34044
34721
|
value._id = new ObjectId104(value._id);
|
|
34045
34722
|
} catch (error2) {
|
|
34046
|
-
throw new
|
|
34723
|
+
throw new BadRequestError171("Invalid _id format");
|
|
34047
34724
|
}
|
|
34048
34725
|
}
|
|
34049
34726
|
try {
|
|
34050
34727
|
value.site = new ObjectId104(value.site);
|
|
34051
34728
|
} catch (error2) {
|
|
34052
|
-
throw new
|
|
34729
|
+
throw new BadRequestError171("Invalid site format");
|
|
34053
34730
|
}
|
|
34054
34731
|
if (value?.createdBy) {
|
|
34055
34732
|
try {
|
|
34056
34733
|
value.createdBy = new ObjectId104(value.createdBy);
|
|
34057
34734
|
} catch (error2) {
|
|
34058
|
-
throw new
|
|
34735
|
+
throw new BadRequestError171("Invalid createdBy format");
|
|
34059
34736
|
}
|
|
34060
34737
|
}
|
|
34061
34738
|
if (value?.route?._id) {
|
|
34062
34739
|
try {
|
|
34063
34740
|
value.route._id = new ObjectId104(value.route._id);
|
|
34064
34741
|
} catch (error2) {
|
|
34065
|
-
throw new
|
|
34742
|
+
throw new BadRequestError171("Invalid route _id format");
|
|
34066
34743
|
}
|
|
34067
34744
|
}
|
|
34068
34745
|
return {
|
|
@@ -34080,7 +34757,7 @@ function MNfcPatrolLog(valueArg) {
|
|
|
34080
34757
|
|
|
34081
34758
|
// src/repositories/nfc-patrol-log.repository.ts
|
|
34082
34759
|
import {
|
|
34083
|
-
BadRequestError as
|
|
34760
|
+
BadRequestError as BadRequestError172,
|
|
34084
34761
|
InternalServerError as InternalServerError59,
|
|
34085
34762
|
logger as logger151,
|
|
34086
34763
|
makeCacheKey as makeCacheKey56,
|
|
@@ -34126,7 +34803,7 @@ function useNfcPatrolLogRepo() {
|
|
|
34126
34803
|
} catch (error) {
|
|
34127
34804
|
const isDuplicated = error.message.includes("duplicate");
|
|
34128
34805
|
if (isDuplicated) {
|
|
34129
|
-
throw new
|
|
34806
|
+
throw new BadRequestError172("NFC Patrol Log already exists.");
|
|
34130
34807
|
}
|
|
34131
34808
|
throw error;
|
|
34132
34809
|
}
|
|
@@ -34143,7 +34820,7 @@ function useNfcPatrolLogRepo() {
|
|
|
34143
34820
|
try {
|
|
34144
34821
|
siteId = typeof site === "string" ? new ObjectId105(site) : site;
|
|
34145
34822
|
} catch {
|
|
34146
|
-
throw new
|
|
34823
|
+
throw new BadRequestError172("Invalid site ID format.");
|
|
34147
34824
|
}
|
|
34148
34825
|
const query = {
|
|
34149
34826
|
site: siteId
|
|
@@ -34245,7 +34922,7 @@ function useNfcPatrolLogService() {
|
|
|
34245
34922
|
|
|
34246
34923
|
// src/controllers/nfc-patrol-log.controller.ts
|
|
34247
34924
|
import {
|
|
34248
|
-
BadRequestError as
|
|
34925
|
+
BadRequestError as BadRequestError174,
|
|
34249
34926
|
logger as logger153
|
|
34250
34927
|
} from "@7365admin1/node-server-utils";
|
|
34251
34928
|
import Joi109 from "joi";
|
|
@@ -34293,7 +34970,7 @@ function useNfcPatrolLogController() {
|
|
|
34293
34970
|
if (error) {
|
|
34294
34971
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
34295
34972
|
logger153.log({ level: "error", message: messages });
|
|
34296
|
-
next(new
|
|
34973
|
+
next(new BadRequestError174(messages));
|
|
34297
34974
|
return;
|
|
34298
34975
|
}
|
|
34299
34976
|
const { page, limit, site, date, route } = value;
|
|
@@ -34325,6 +35002,7 @@ export {
|
|
|
34325
35002
|
EAccessCardUserTypes,
|
|
34326
35003
|
MAccessCard,
|
|
34327
35004
|
MAccessCardTransaction,
|
|
35005
|
+
MAddress,
|
|
34328
35006
|
MAttendance,
|
|
34329
35007
|
MAttendanceSettings,
|
|
34330
35008
|
MBillingConfiguration,
|
|
@@ -34459,6 +35137,7 @@ export {
|
|
|
34459
35137
|
siteSchema,
|
|
34460
35138
|
tokenSchema,
|
|
34461
35139
|
useAccessManagementController,
|
|
35140
|
+
useAddressRepo,
|
|
34462
35141
|
useAttendanceController,
|
|
34463
35142
|
useAttendanceRepository,
|
|
34464
35143
|
useAttendanceSettingsController,
|