@7365admin1/core 2.43.0 → 2.45.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 +42 -6
- package/dist/index.js +460 -275
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +453 -275
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1431,6 +1431,17 @@ import {
|
|
|
1431
1431
|
// src/models/occurrence-entry.model.ts
|
|
1432
1432
|
import { ObjectId as ObjectId6 } from "mongodb";
|
|
1433
1433
|
import Joi5 from "joi";
|
|
1434
|
+
var EntrySort = /* @__PURE__ */ ((EntrySort2) => {
|
|
1435
|
+
EntrySort2["CREATED_AT"] = "createdAt";
|
|
1436
|
+
EntrySort2["NAME"] = "name";
|
|
1437
|
+
EntrySort2["ID"] = "_id";
|
|
1438
|
+
return EntrySort2;
|
|
1439
|
+
})(EntrySort || {});
|
|
1440
|
+
var EntryOrder = /* @__PURE__ */ ((EntryOrder2) => {
|
|
1441
|
+
EntryOrder2["ASC"] = "asc";
|
|
1442
|
+
EntryOrder2["DESC"] = "desc";
|
|
1443
|
+
return EntryOrder2;
|
|
1444
|
+
})(EntryOrder || {});
|
|
1434
1445
|
var schemaOccurrenceEntry = Joi5.object({
|
|
1435
1446
|
site: Joi5.string().hex().length(24).required(),
|
|
1436
1447
|
dailyOccurrenceBookId: Joi5.string().hex().optional().allow(null, ""),
|
|
@@ -2595,7 +2606,8 @@ function useUserRepo() {
|
|
|
2595
2606
|
"dateOfBirth",
|
|
2596
2607
|
"profile",
|
|
2597
2608
|
"gender",
|
|
2598
|
-
"defaultOrg"
|
|
2609
|
+
"defaultOrg",
|
|
2610
|
+
"status"
|
|
2599
2611
|
];
|
|
2600
2612
|
if (!allowedFields.includes(field)) {
|
|
2601
2613
|
throw new BadRequestError9(
|
|
@@ -13319,6 +13331,10 @@ var schemaFiles = Joi35.object({
|
|
|
13319
13331
|
id: Joi35.string().hex().required(),
|
|
13320
13332
|
name: Joi35.string().optional().allow(null, "")
|
|
13321
13333
|
});
|
|
13334
|
+
var schemaApprover = Joi35.object({
|
|
13335
|
+
id: Joi35.string().hex().required(),
|
|
13336
|
+
name: Joi35.string().optional().allow(null, "")
|
|
13337
|
+
});
|
|
13322
13338
|
var schemaPerson = Joi35.object({
|
|
13323
13339
|
_id: Joi35.string().hex().optional().allow("", null),
|
|
13324
13340
|
user: Joi35.string().hex().length(24).optional().allow(null, ""),
|
|
@@ -13343,7 +13359,8 @@ var schemaPerson = Joi35.object({
|
|
|
13343
13359
|
files: Joi35.array().items(schemaFiles).optional().allow(null),
|
|
13344
13360
|
password: Joi35.string().optional().allow(null, ""),
|
|
13345
13361
|
plateNumber: Joi35.string().optional().allow(null, ""),
|
|
13346
|
-
platform: Joi35.string().valid("web", "mobile").optional().allow(null, "")
|
|
13362
|
+
platform: Joi35.string().valid("web", "mobile").optional().allow(null, ""),
|
|
13363
|
+
approvedBy: schemaApprover.optional().allow(null, "")
|
|
13347
13364
|
});
|
|
13348
13365
|
var schemaUpdatePerson = Joi35.object({
|
|
13349
13366
|
_id: Joi35.string().hex().required(),
|
|
@@ -13365,7 +13382,8 @@ var schemaUpdatePerson = Joi35.object({
|
|
|
13365
13382
|
files: Joi35.array().items(schemaFiles).optional().allow(null),
|
|
13366
13383
|
password: Joi35.string().optional().allow(null, ""),
|
|
13367
13384
|
plateNumber: Joi35.string().optional().allow(null, ""),
|
|
13368
|
-
platform: Joi35.string().valid("web", "mobile").optional().allow(null, "")
|
|
13385
|
+
platform: Joi35.string().valid("web", "mobile").optional().allow(null, ""),
|
|
13386
|
+
approvedBy: schemaApprover.optional().allow(null, "")
|
|
13369
13387
|
});
|
|
13370
13388
|
function MPerson(value) {
|
|
13371
13389
|
const { error } = schemaPerson.validate(value);
|
|
@@ -13437,6 +13455,7 @@ function MPerson(value) {
|
|
|
13437
13455
|
files: value.files ?? [],
|
|
13438
13456
|
plateNumber: value.plateNumber ?? "",
|
|
13439
13457
|
platForm: value.platform ?? "",
|
|
13458
|
+
approvedBy: value.approvedBy ?? { id: "", name: "" },
|
|
13440
13459
|
createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
13441
13460
|
updatedAt: value.updatedAt,
|
|
13442
13461
|
deletedAt: value.deletedAt
|
|
@@ -15650,6 +15669,37 @@ function usePersonRepo() {
|
|
|
15650
15669
|
}
|
|
15651
15670
|
}
|
|
15652
15671
|
}
|
|
15672
|
+
async function reviewResidentPerson(_id, value, session) {
|
|
15673
|
+
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
15674
|
+
try {
|
|
15675
|
+
_id = new ObjectId44(_id);
|
|
15676
|
+
} catch (error) {
|
|
15677
|
+
throw new BadRequestError70("Invalid ID format.");
|
|
15678
|
+
}
|
|
15679
|
+
try {
|
|
15680
|
+
const res = await collection.updateOne(
|
|
15681
|
+
{ _id },
|
|
15682
|
+
{ $set: value },
|
|
15683
|
+
{ session }
|
|
15684
|
+
);
|
|
15685
|
+
if (res.modifiedCount === 0) {
|
|
15686
|
+
throw new InternalServerError26(`Unable to ${value.status} person.`);
|
|
15687
|
+
}
|
|
15688
|
+
delNamespace().then(() => {
|
|
15689
|
+
logger51.info(
|
|
15690
|
+
`Cache cleared for namespace: ${site_people_namespace_collection}`
|
|
15691
|
+
);
|
|
15692
|
+
}).catch((err) => {
|
|
15693
|
+
logger51.error(
|
|
15694
|
+
`Failed to clear cache for namespace: ${site_people_namespace_collection}`,
|
|
15695
|
+
err
|
|
15696
|
+
);
|
|
15697
|
+
});
|
|
15698
|
+
return res;
|
|
15699
|
+
} catch (error) {
|
|
15700
|
+
throw error;
|
|
15701
|
+
}
|
|
15702
|
+
}
|
|
15653
15703
|
return {
|
|
15654
15704
|
add,
|
|
15655
15705
|
getAll,
|
|
@@ -15667,7 +15717,8 @@ function usePersonRepo() {
|
|
|
15667
15717
|
getPeopleByNRIC,
|
|
15668
15718
|
pushVehicleById,
|
|
15669
15719
|
pullVehicleByRecNo,
|
|
15670
|
-
getByUserId
|
|
15720
|
+
getByUserId,
|
|
15721
|
+
reviewResidentPerson
|
|
15671
15722
|
};
|
|
15672
15723
|
}
|
|
15673
15724
|
|
|
@@ -16508,10 +16559,13 @@ function useVehicleService() {
|
|
|
16508
16559
|
pullVehicleByRecNo: _pullVehicleByRecNo
|
|
16509
16560
|
} = usePersonRepo();
|
|
16510
16561
|
const { getUnitByBlockLevelUnitNumber: _getUnitByBlockLevelUnitNumber } = useBuildingUnitRepo();
|
|
16511
|
-
async function add(value) {
|
|
16512
|
-
const
|
|
16562
|
+
async function add(value, session) {
|
|
16563
|
+
const isExternalSession = !!session;
|
|
16513
16564
|
if (!session) {
|
|
16514
|
-
|
|
16565
|
+
session = await useAtlas35.getClient()?.startSession();
|
|
16566
|
+
if (!session) {
|
|
16567
|
+
throw new Error("Unable to start session for vehicle service.");
|
|
16568
|
+
}
|
|
16515
16569
|
}
|
|
16516
16570
|
const [_vehiclePlateNumber] = value.plateNumber;
|
|
16517
16571
|
const [existingPlateNumber, org] = await Promise.all([
|
|
@@ -16568,7 +16622,9 @@ function useVehicleService() {
|
|
|
16568
16622
|
const owner = value.name;
|
|
16569
16623
|
const plateNumbers = value.plateNumber;
|
|
16570
16624
|
try {
|
|
16571
|
-
|
|
16625
|
+
if (!isExternalSession) {
|
|
16626
|
+
session.startTransaction();
|
|
16627
|
+
}
|
|
16572
16628
|
let message = "Vehicle plate number needs approval from property management.";
|
|
16573
16629
|
let siteCameras = [];
|
|
16574
16630
|
if (value.status && value.status !== "pending" /* PENDING */) {
|
|
@@ -16666,14 +16722,20 @@ function useVehicleService() {
|
|
|
16666
16722
|
}
|
|
16667
16723
|
await _add(vehicleValue, session);
|
|
16668
16724
|
}
|
|
16669
|
-
|
|
16725
|
+
if (!isExternalSession) {
|
|
16726
|
+
await session.commitTransaction();
|
|
16727
|
+
}
|
|
16670
16728
|
return message;
|
|
16671
16729
|
} catch (error) {
|
|
16672
16730
|
logger54.error("Error in vehicle service add:", error);
|
|
16673
|
-
|
|
16731
|
+
if (!isExternalSession) {
|
|
16732
|
+
await session.abortTransaction();
|
|
16733
|
+
}
|
|
16674
16734
|
throw error;
|
|
16675
16735
|
} finally {
|
|
16676
|
-
|
|
16736
|
+
if (!isExternalSession) {
|
|
16737
|
+
session.endSession();
|
|
16738
|
+
}
|
|
16677
16739
|
}
|
|
16678
16740
|
}
|
|
16679
16741
|
async function deleteVehicle(_id, recno, site, type, bypass = false) {
|
|
@@ -22571,6 +22633,7 @@ function useVisitorTransactionService() {
|
|
|
22571
22633
|
const { getAllSites: _getAllSites } = useSiteRepo();
|
|
22572
22634
|
const { getByUserId: _getByUserId } = usePersonRepo();
|
|
22573
22635
|
const { add: addVehicle } = useVehicleRepo();
|
|
22636
|
+
const { getById: _getUnitById } = useBuildingUnitRepo();
|
|
22574
22637
|
function extractKeyId(item) {
|
|
22575
22638
|
if (!item)
|
|
22576
22639
|
return null;
|
|
@@ -22655,6 +22718,10 @@ function useVisitorTransactionService() {
|
|
|
22655
22718
|
_getSiteById(value.site)
|
|
22656
22719
|
]);
|
|
22657
22720
|
}
|
|
22721
|
+
if (!value.unitName && value.unit) {
|
|
22722
|
+
const unit = await _getUnitById(value.unit);
|
|
22723
|
+
value.unitName = unit?.name;
|
|
22724
|
+
}
|
|
22658
22725
|
const hourExpiration = site?.dahuaTimeExpiration ? site?.dahuaTimeExpiration : 24 * 60;
|
|
22659
22726
|
const end = value.checkOut ? new Date(value.checkOut) : new Date(start.getTime() + hourExpiration * 60 * 1e3);
|
|
22660
22727
|
const startDahuaDate = formatDahuaDate(start);
|
|
@@ -23923,13 +23990,15 @@ function usePersonService() {
|
|
|
23923
23990
|
add: _add,
|
|
23924
23991
|
getById: _getById,
|
|
23925
23992
|
updateById: _updateById,
|
|
23926
|
-
getByUserId: _getByUserId
|
|
23993
|
+
getByUserId: _getByUserId,
|
|
23994
|
+
reviewResidentPerson: _reviewResidentPerson
|
|
23927
23995
|
} = usePersonRepo();
|
|
23928
23996
|
const { addPlateNumber: _addPlateNumber } = useDahuaService();
|
|
23929
23997
|
const {
|
|
23930
23998
|
createUser: addUser,
|
|
23931
23999
|
getUserByEmail,
|
|
23932
|
-
updateUserFieldById: _updateUserFieldById
|
|
24000
|
+
updateUserFieldById: _updateUserFieldById,
|
|
24001
|
+
getUserById
|
|
23933
24002
|
} = useUserRepo();
|
|
23934
24003
|
const { add: addMember } = useMemberRepo();
|
|
23935
24004
|
const { getById: _getUnitById, updateById: updateUnitById } = useBuildingUnitRepo();
|
|
@@ -23937,6 +24006,7 @@ function usePersonService() {
|
|
|
23937
24006
|
const { updateStatusById } = useFileRepo();
|
|
23938
24007
|
const { getById: getOrgById } = useOrgRepo();
|
|
23939
24008
|
const { getSiteById } = useSiteRepo();
|
|
24009
|
+
const { add: addVehicle } = useVehicleService();
|
|
23940
24010
|
async function add(value) {
|
|
23941
24011
|
const session = useAtlas52.getClient()?.startSession();
|
|
23942
24012
|
if (!session) {
|
|
@@ -23970,7 +24040,7 @@ function usePersonService() {
|
|
|
23970
24040
|
email: value.email,
|
|
23971
24041
|
password: hashedPassword,
|
|
23972
24042
|
name: value.name,
|
|
23973
|
-
status: value.platform == "mobile" ? "
|
|
24043
|
+
status: value.platform == "mobile" ? "pending" : "active",
|
|
23974
24044
|
defaultOrg: value.org?.toString() || ""
|
|
23975
24045
|
};
|
|
23976
24046
|
const userId = await addUser(user, session);
|
|
@@ -24087,9 +24157,76 @@ function usePersonService() {
|
|
|
24087
24157
|
}
|
|
24088
24158
|
return { start: "", end: "" };
|
|
24089
24159
|
}
|
|
24160
|
+
async function reviewResidentPerson(id, value) {
|
|
24161
|
+
const session = useAtlas52.getClient()?.startSession();
|
|
24162
|
+
session?.startTransaction();
|
|
24163
|
+
try {
|
|
24164
|
+
const person = await _getById(id.toString());
|
|
24165
|
+
if (!person)
|
|
24166
|
+
throw new BadRequestError101("Person not found.");
|
|
24167
|
+
if (value.approvedBy) {
|
|
24168
|
+
const approvedBy = await getUserById(value.approvedBy.id);
|
|
24169
|
+
if (!approvedBy || !approvedBy.name)
|
|
24170
|
+
throw new BadRequestError101("Created by not found.");
|
|
24171
|
+
value.approvedBy.name = approvedBy.name;
|
|
24172
|
+
value.approvedBy.id = approvedBy._id;
|
|
24173
|
+
}
|
|
24174
|
+
const vehicle = {
|
|
24175
|
+
plateNumber: person.plateNumber || "",
|
|
24176
|
+
type: "whitelist",
|
|
24177
|
+
category: person.type || "",
|
|
24178
|
+
name: person.name,
|
|
24179
|
+
phoneNumber: person.contact,
|
|
24180
|
+
org: person.org.toString(),
|
|
24181
|
+
site: person.site.toString(),
|
|
24182
|
+
block: person.block,
|
|
24183
|
+
level: person.level,
|
|
24184
|
+
unit: person.unit.toString(),
|
|
24185
|
+
nric: person.nric,
|
|
24186
|
+
status: "active",
|
|
24187
|
+
peopleId: person._id?.toString()
|
|
24188
|
+
};
|
|
24189
|
+
const reviewStatus = value.status;
|
|
24190
|
+
if (reviewStatus === "approved") {
|
|
24191
|
+
value.status = "active";
|
|
24192
|
+
}
|
|
24193
|
+
await _reviewResidentPerson(id, value, session);
|
|
24194
|
+
if (person.user) {
|
|
24195
|
+
let userStatus;
|
|
24196
|
+
switch (reviewStatus) {
|
|
24197
|
+
case "approved":
|
|
24198
|
+
userStatus = "active";
|
|
24199
|
+
if (person.plateNumber && person.plateNumber.trim() !== "") {
|
|
24200
|
+
await addVehicle(vehicle, session);
|
|
24201
|
+
}
|
|
24202
|
+
break;
|
|
24203
|
+
case "resubmit":
|
|
24204
|
+
userStatus = "resubmit";
|
|
24205
|
+
break;
|
|
24206
|
+
case "rejected":
|
|
24207
|
+
userStatus = "rejected";
|
|
24208
|
+
break;
|
|
24209
|
+
default:
|
|
24210
|
+
throw new Error("Invalid review status");
|
|
24211
|
+
}
|
|
24212
|
+
await _updateUserFieldById(
|
|
24213
|
+
{ _id: person.user.toString(), field: "status", value: userStatus },
|
|
24214
|
+
session
|
|
24215
|
+
);
|
|
24216
|
+
}
|
|
24217
|
+
await session?.commitTransaction();
|
|
24218
|
+
return `Successfully ${reviewStatus} person`;
|
|
24219
|
+
} catch (error) {
|
|
24220
|
+
await session?.abortTransaction();
|
|
24221
|
+
throw error;
|
|
24222
|
+
} finally {
|
|
24223
|
+
session?.endSession();
|
|
24224
|
+
}
|
|
24225
|
+
}
|
|
24090
24226
|
return {
|
|
24091
24227
|
add,
|
|
24092
|
-
updateById
|
|
24228
|
+
updateById,
|
|
24229
|
+
reviewResidentPerson
|
|
24093
24230
|
};
|
|
24094
24231
|
}
|
|
24095
24232
|
|
|
@@ -24106,7 +24243,11 @@ function usePersonController() {
|
|
|
24106
24243
|
getPeopleByNRIC: _getPeopleByNRIC,
|
|
24107
24244
|
getByUserId: _getByUserId
|
|
24108
24245
|
} = usePersonRepo();
|
|
24109
|
-
const {
|
|
24246
|
+
const {
|
|
24247
|
+
add: _add,
|
|
24248
|
+
updateById: _updateById,
|
|
24249
|
+
reviewResidentPerson: _reviewResidentPerson
|
|
24250
|
+
} = usePersonService();
|
|
24110
24251
|
async function add(req, res, next) {
|
|
24111
24252
|
const payload = { ...req.body };
|
|
24112
24253
|
const { error } = schemaPerson.validate(payload, {
|
|
@@ -24421,6 +24562,38 @@ function usePersonController() {
|
|
|
24421
24562
|
return;
|
|
24422
24563
|
}
|
|
24423
24564
|
}
|
|
24565
|
+
async function reviewResidentPerson(req, res, next) {
|
|
24566
|
+
const cookies = req.headers.cookie?.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
24567
|
+
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
24568
|
+
{}
|
|
24569
|
+
);
|
|
24570
|
+
req.body.approvedBy = cookies?.["user"] ? cookies["user"].toString() : req.body.approvedBy;
|
|
24571
|
+
const _id = req.params.id;
|
|
24572
|
+
const payload = { _id, ...req.body };
|
|
24573
|
+
const schema2 = Joi58.object({
|
|
24574
|
+
_id: Joi58.string().hex().required(),
|
|
24575
|
+
status: Joi58.string().valid("approved", "rejected", "resubmit").required(),
|
|
24576
|
+
approvedBy: Joi58.string().required(),
|
|
24577
|
+
remarks: Joi58.string().optional().allow("", null)
|
|
24578
|
+
});
|
|
24579
|
+
const { error } = schema2.validate(payload);
|
|
24580
|
+
if (error) {
|
|
24581
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
24582
|
+
logger83.log({ level: "error", message: messages });
|
|
24583
|
+
next(new BadRequestError102(messages));
|
|
24584
|
+
return;
|
|
24585
|
+
}
|
|
24586
|
+
try {
|
|
24587
|
+
req.body.approvedBy = { id: req.body.approvedBy, name: "" };
|
|
24588
|
+
const result = await _reviewResidentPerson(_id, req.body);
|
|
24589
|
+
res.status(200).json({ message: result });
|
|
24590
|
+
return;
|
|
24591
|
+
} catch (error2) {
|
|
24592
|
+
logger83.log({ level: "error", message: error2.message });
|
|
24593
|
+
next(error2);
|
|
24594
|
+
return;
|
|
24595
|
+
}
|
|
24596
|
+
}
|
|
24424
24597
|
return {
|
|
24425
24598
|
add,
|
|
24426
24599
|
getAll,
|
|
@@ -24432,7 +24605,8 @@ function usePersonController() {
|
|
|
24432
24605
|
getCompany,
|
|
24433
24606
|
getPeopleByPlateNumber,
|
|
24434
24607
|
getPeopleByNRIC,
|
|
24435
|
-
getPersonByUserId
|
|
24608
|
+
getPersonByUserId,
|
|
24609
|
+
reviewResidentPerson
|
|
24436
24610
|
};
|
|
24437
24611
|
}
|
|
24438
24612
|
|
|
@@ -29707,21 +29881,23 @@ function useBulletinBoardController() {
|
|
|
29707
29881
|
}
|
|
29708
29882
|
}
|
|
29709
29883
|
async function getBulletinBoardById(req, res, next) {
|
|
29710
|
-
const validation = Joi76.string().hex().required();
|
|
29711
|
-
const _id = req.params.id;
|
|
29712
|
-
const { error } = validation.validate(_id);
|
|
29713
|
-
if (error) {
|
|
29714
|
-
logger106.log({ level: "error", message: error.message });
|
|
29715
|
-
next(new BadRequestError127(error.message));
|
|
29716
|
-
return;
|
|
29717
|
-
}
|
|
29718
29884
|
try {
|
|
29885
|
+
const schema2 = Joi76.object({
|
|
29886
|
+
_id: Joi76.string().hex().length(24).required()
|
|
29887
|
+
});
|
|
29888
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
29889
|
+
if (error) {
|
|
29890
|
+
logger106.log({ level: "error", message: error.message });
|
|
29891
|
+
next(new BadRequestError127(error.message));
|
|
29892
|
+
return;
|
|
29893
|
+
}
|
|
29894
|
+
const { _id } = value;
|
|
29719
29895
|
const data = await _getBulletinBoardById(_id);
|
|
29720
29896
|
res.status(200).json(data);
|
|
29721
29897
|
return;
|
|
29722
|
-
} catch (
|
|
29723
|
-
logger106.log({ level: "error", message:
|
|
29724
|
-
next(
|
|
29898
|
+
} catch (error) {
|
|
29899
|
+
logger106.log({ level: "error", message: error.message });
|
|
29900
|
+
next(error);
|
|
29725
29901
|
return;
|
|
29726
29902
|
}
|
|
29727
29903
|
}
|
|
@@ -31055,7 +31231,7 @@ var schemaEventManagement = Joi81.object({
|
|
|
31055
31231
|
site: Joi81.string().required(),
|
|
31056
31232
|
title: Joi81.string().required(),
|
|
31057
31233
|
description: Joi81.string().optional().allow(""),
|
|
31058
|
-
dateTime: Joi81.
|
|
31234
|
+
dateTime: Joi81.date().iso().required(),
|
|
31059
31235
|
status: Joi81.string().optional().default("planned"),
|
|
31060
31236
|
type: Joi81.string().optional().default("TASK")
|
|
31061
31237
|
});
|
|
@@ -31063,7 +31239,7 @@ var schemaUpdateEventManagement = Joi81.object({
|
|
|
31063
31239
|
_id: Joi81.string().hex().required(),
|
|
31064
31240
|
title: Joi81.string().optional().allow(null, ""),
|
|
31065
31241
|
description: Joi81.string().optional().allow(null, ""),
|
|
31066
|
-
dateTime: Joi81.
|
|
31242
|
+
dateTime: Joi81.date().iso().optional().allow(null, ""),
|
|
31067
31243
|
status: Joi81.string().optional().allow(null, ""),
|
|
31068
31244
|
type: Joi81.string().optional().allow(null, "")
|
|
31069
31245
|
});
|
|
@@ -31087,10 +31263,10 @@ function MEventManagement(value) {
|
|
|
31087
31263
|
site: value.site,
|
|
31088
31264
|
title: value.title,
|
|
31089
31265
|
description: value.description ?? "",
|
|
31090
|
-
dateTime: value.dateTime,
|
|
31266
|
+
dateTime: new Date(value.dateTime),
|
|
31091
31267
|
status: value.status ?? "planned",
|
|
31092
31268
|
type: value.type ?? "TASK",
|
|
31093
|
-
createdAt: value.createdAt ??
|
|
31269
|
+
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
31094
31270
|
updatedAt: value.updatedAt,
|
|
31095
31271
|
deletedAt: value.deletedAt
|
|
31096
31272
|
};
|
|
@@ -31277,7 +31453,7 @@ function useEventManagementRepo() {
|
|
|
31277
31453
|
}
|
|
31278
31454
|
}
|
|
31279
31455
|
async function updateEventManagementById(_id, value, session) {
|
|
31280
|
-
value.updatedAt =
|
|
31456
|
+
value.updatedAt = /* @__PURE__ */ new Date();
|
|
31281
31457
|
try {
|
|
31282
31458
|
_id = new ObjectId85(_id);
|
|
31283
31459
|
} catch (error) {
|
|
@@ -31323,8 +31499,7 @@ function useEventManagementRepo() {
|
|
|
31323
31499
|
try {
|
|
31324
31500
|
const updateValue = {
|
|
31325
31501
|
status: "deleted",
|
|
31326
|
-
|
|
31327
|
-
deletedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
31502
|
+
deletedAt: /* @__PURE__ */ new Date()
|
|
31328
31503
|
};
|
|
31329
31504
|
const res = await collection.updateOne({ _id }, { $set: updateValue });
|
|
31330
31505
|
if (res.modifiedCount === 0) {
|
|
@@ -31417,7 +31592,12 @@ function useEventManagementService() {
|
|
|
31417
31592
|
const session = useAtlas73.getClient()?.startSession();
|
|
31418
31593
|
session?.startTransaction();
|
|
31419
31594
|
try {
|
|
31420
|
-
|
|
31595
|
+
const updatedValue = {
|
|
31596
|
+
...value.dateTime && { dateTime: new Date(value.dateTime) },
|
|
31597
|
+
...value.title && { title: value.title },
|
|
31598
|
+
...value.description && { description: value.description }
|
|
31599
|
+
};
|
|
31600
|
+
await _updateEventManagementById(id, updatedValue, session);
|
|
31421
31601
|
await session?.commitTransaction();
|
|
31422
31602
|
return "Successfully updated event.";
|
|
31423
31603
|
} catch (error) {
|
|
@@ -32860,7 +33040,7 @@ var MAccessCard = class {
|
|
|
32860
33040
|
accessType = "Normal" /* NORMAL */,
|
|
32861
33041
|
cardNo,
|
|
32862
33042
|
pin,
|
|
32863
|
-
qrData,
|
|
33043
|
+
qrData = null,
|
|
32864
33044
|
startDate,
|
|
32865
33045
|
endDate,
|
|
32866
33046
|
isActivated,
|
|
@@ -32946,7 +33126,7 @@ var minifyXml = (xml) => {
|
|
|
32946
33126
|
};
|
|
32947
33127
|
var readTemplate = (name, params) => {
|
|
32948
33128
|
const template = fs2.readFileSync(
|
|
32949
|
-
path2.join(__dirname, `../
|
|
33129
|
+
path2.join(__dirname, `../dist/public/xml-templates/${name}.xml`),
|
|
32950
33130
|
"utf-8"
|
|
32951
33131
|
);
|
|
32952
33132
|
if (!params)
|
|
@@ -33197,10 +33377,6 @@ function UseAccessManagementRepo() {
|
|
|
33197
33377
|
payload.updatedAt = new Date(payload.updatedAt);
|
|
33198
33378
|
payload.assignedUnit = payload.unit?.map((id) => new ObjectId90(id));
|
|
33199
33379
|
delete payload.unit;
|
|
33200
|
-
payload.qrData = await createQrData({
|
|
33201
|
-
cardNumber: payload.cardNo,
|
|
33202
|
-
facilityCode: parseInt(payload.cardNo.slice(0, 4), 10)
|
|
33203
|
-
});
|
|
33204
33380
|
const accessCardObj = new MAccessCard(payload);
|
|
33205
33381
|
const result = await collection().insertOne(accessCardObj);
|
|
33206
33382
|
return result.insertedId;
|
|
@@ -33262,10 +33438,6 @@ function UseAccessManagementRepo() {
|
|
|
33262
33438
|
cardNo,
|
|
33263
33439
|
accessType: "Normal" /* NORMAL */,
|
|
33264
33440
|
pin: "123456",
|
|
33265
|
-
qrData: await createQrData({
|
|
33266
|
-
cardNumber: cardNo,
|
|
33267
|
-
facilityCode: parseInt(cardNo.slice(0, 4), 10)
|
|
33268
|
-
}),
|
|
33269
33441
|
startDate: /* @__PURE__ */ new Date(),
|
|
33270
33442
|
endDate,
|
|
33271
33443
|
isActivated: true,
|
|
@@ -33315,10 +33487,6 @@ function UseAccessManagementRepo() {
|
|
|
33315
33487
|
cardNo,
|
|
33316
33488
|
accessType: "Normal" /* NORMAL */,
|
|
33317
33489
|
pin: "123456",
|
|
33318
|
-
qrData: await createQrData({
|
|
33319
|
-
cardNumber: cardNo,
|
|
33320
|
-
facilityCode: parseInt(cardNo.slice(0, 4), 10)
|
|
33321
|
-
}),
|
|
33322
33490
|
startDate: /* @__PURE__ */ new Date(),
|
|
33323
33491
|
endDate,
|
|
33324
33492
|
isActivated: true,
|
|
@@ -34460,7 +34628,6 @@ function UseAccessManagementRepo() {
|
|
|
34460
34628
|
accessType: "Normal" /* NORMAL */,
|
|
34461
34629
|
cardNo: `${facilityCode}${cardNumber}`,
|
|
34462
34630
|
pin,
|
|
34463
|
-
qrData: await createQrData({ cardNumber: `${facilityCode}${cardNumber}` }),
|
|
34464
34631
|
startDate: new Date(item["startDate (format MM/DD/YYYY)"]),
|
|
34465
34632
|
endDate: new Date(item["endDate (format MM/DD/YYYY)"] || endDate),
|
|
34466
34633
|
isActivated: true,
|
|
@@ -37397,6 +37564,17 @@ function useOccurrenceBookController() {
|
|
|
37397
37564
|
// src/models/bulletin-video.model.ts
|
|
37398
37565
|
import { ObjectId as ObjectId95 } from "mongodb";
|
|
37399
37566
|
import Joi90 from "joi";
|
|
37567
|
+
var BulletinVideoSort = /* @__PURE__ */ ((BulletinVideoSort2) => {
|
|
37568
|
+
BulletinVideoSort2["CREATED_AT"] = "createdAt";
|
|
37569
|
+
BulletinVideoSort2["NAME"] = "name";
|
|
37570
|
+
BulletinVideoSort2["ID"] = "_id";
|
|
37571
|
+
return BulletinVideoSort2;
|
|
37572
|
+
})(BulletinVideoSort || {});
|
|
37573
|
+
var BulletinVideoOrder = /* @__PURE__ */ ((BulletinVideoOrder2) => {
|
|
37574
|
+
BulletinVideoOrder2["ASC"] = "asc";
|
|
37575
|
+
BulletinVideoOrder2["DESC"] = "desc";
|
|
37576
|
+
return BulletinVideoOrder2;
|
|
37577
|
+
})(BulletinVideoOrder || {});
|
|
37400
37578
|
var schemaBulletinVideo = Joi90.object({
|
|
37401
37579
|
site: Joi90.string().hex().required(),
|
|
37402
37580
|
title: Joi90.string().optional().allow(null, ""),
|
|
@@ -37734,39 +37912,35 @@ function useBulletinVideoController() {
|
|
|
37734
37912
|
deleteBulletinVideoById: _deleteBulletinVideoById
|
|
37735
37913
|
} = useBulletinVideoRepo();
|
|
37736
37914
|
async function add(req, res, next) {
|
|
37737
|
-
const payload = { ...req.body };
|
|
37738
|
-
const { error } = schemaBulletinVideo.validate(payload, {
|
|
37739
|
-
abortEarly: false
|
|
37740
|
-
});
|
|
37741
|
-
if (error) {
|
|
37742
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
37743
|
-
logger127.log({ level: "error", message: messages });
|
|
37744
|
-
next(new BadRequestError150(messages));
|
|
37745
|
-
return;
|
|
37746
|
-
}
|
|
37747
37915
|
try {
|
|
37748
|
-
const
|
|
37916
|
+
const { error, value } = schemaBulletinVideo.validate(req.body, {
|
|
37917
|
+
abortEarly: false
|
|
37918
|
+
});
|
|
37919
|
+
if (error) {
|
|
37920
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
37921
|
+
logger127.log({ level: "error", message: messages });
|
|
37922
|
+
next(new BadRequestError150(messages));
|
|
37923
|
+
return;
|
|
37924
|
+
}
|
|
37925
|
+
const data = await _add(value);
|
|
37749
37926
|
res.status(201).json(data);
|
|
37750
37927
|
return;
|
|
37751
|
-
} catch (
|
|
37752
|
-
logger127.log({ level: "error", message:
|
|
37753
|
-
next(
|
|
37928
|
+
} catch (error) {
|
|
37929
|
+
logger127.log({ level: "error", message: error.message });
|
|
37930
|
+
next(error);
|
|
37754
37931
|
return;
|
|
37755
37932
|
}
|
|
37756
37933
|
}
|
|
37757
37934
|
async function getAll(req, res, next) {
|
|
37758
|
-
const allowedFields = ["createdAt", "name"];
|
|
37759
|
-
const allowedOrder = ["asc", "desc"];
|
|
37760
37935
|
const validation = Joi91.object({
|
|
37761
37936
|
search: Joi91.string().optional().allow("", null),
|
|
37762
37937
|
page: Joi91.number().integer().min(1).allow("", null).default(1),
|
|
37763
37938
|
limit: Joi91.number().integer().min(1).max(100).allow("", null).default(10),
|
|
37764
|
-
sort: Joi91.string().
|
|
37765
|
-
order: Joi91.string().
|
|
37766
|
-
site: Joi91.string().hex().required()
|
|
37939
|
+
sort: Joi91.string().valid(...Object.values(BulletinVideoSort)).default("_id" /* ID */),
|
|
37940
|
+
order: Joi91.string().valid(...Object.values(BulletinVideoOrder)).default("desc" /* DESC */),
|
|
37941
|
+
site: Joi91.string().hex().length(24).required()
|
|
37767
37942
|
});
|
|
37768
|
-
const
|
|
37769
|
-
const { error } = validation.validate(query, {
|
|
37943
|
+
const { error, value } = validation.validate(req.query, {
|
|
37770
37944
|
abortEarly: false
|
|
37771
37945
|
});
|
|
37772
37946
|
if (error) {
|
|
@@ -37775,19 +37949,10 @@ function useBulletinVideoController() {
|
|
|
37775
37949
|
next(new BadRequestError150(messages));
|
|
37776
37950
|
return;
|
|
37777
37951
|
}
|
|
37778
|
-
const search
|
|
37779
|
-
const
|
|
37780
|
-
|
|
37781
|
-
|
|
37782
|
-
const sortObj = {};
|
|
37783
|
-
const sortFields = String(req.query.sort).split(",");
|
|
37784
|
-
const sortOrders = String(req.query.order).split(",");
|
|
37785
|
-
sortFields.forEach((field, index) => {
|
|
37786
|
-
if (allowedFields.includes(field)) {
|
|
37787
|
-
const order = sortOrders[index] === "asc" ? 1 : -1;
|
|
37788
|
-
sortObj[field] = order;
|
|
37789
|
-
}
|
|
37790
|
-
});
|
|
37952
|
+
const { search, page, limit, site, sort, order } = value;
|
|
37953
|
+
const sortObj = {
|
|
37954
|
+
[sort ?? "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
|
|
37955
|
+
};
|
|
37791
37956
|
try {
|
|
37792
37957
|
const data = await _getAll({
|
|
37793
37958
|
search,
|
|
@@ -37805,21 +37970,23 @@ function useBulletinVideoController() {
|
|
|
37805
37970
|
}
|
|
37806
37971
|
}
|
|
37807
37972
|
async function getBulletinVideoById(req, res, next) {
|
|
37808
|
-
const validation = Joi91.string().hex().required();
|
|
37809
|
-
const _id = req.params.id;
|
|
37810
|
-
const { error } = validation.validate(_id);
|
|
37811
|
-
if (error) {
|
|
37812
|
-
logger127.log({ level: "error", message: error.message });
|
|
37813
|
-
next(new BadRequestError150(error.message));
|
|
37814
|
-
return;
|
|
37815
|
-
}
|
|
37816
37973
|
try {
|
|
37974
|
+
const schema2 = Joi91.object({
|
|
37975
|
+
_id: Joi91.string().hex().length(24).required()
|
|
37976
|
+
});
|
|
37977
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
37978
|
+
if (error) {
|
|
37979
|
+
logger127.log({ level: "error", message: error.message });
|
|
37980
|
+
next(new BadRequestError150(error.message));
|
|
37981
|
+
return;
|
|
37982
|
+
}
|
|
37983
|
+
const { _id } = value;
|
|
37817
37984
|
const data = await _getBulletinVideoById(_id);
|
|
37818
37985
|
res.status(200).json(data);
|
|
37819
37986
|
return;
|
|
37820
|
-
} catch (
|
|
37821
|
-
logger127.log({ level: "error", message:
|
|
37822
|
-
next(
|
|
37987
|
+
} catch (error) {
|
|
37988
|
+
logger127.log({ level: "error", message: error.message });
|
|
37989
|
+
next(error);
|
|
37823
37990
|
return;
|
|
37824
37991
|
}
|
|
37825
37992
|
}
|
|
@@ -37846,21 +38013,23 @@ function useBulletinVideoController() {
|
|
|
37846
38013
|
}
|
|
37847
38014
|
}
|
|
37848
38015
|
async function deleteBulletinVideoById(req, res, next) {
|
|
37849
|
-
const validation = Joi91.string().hex().required();
|
|
37850
|
-
const _id = req.params.id;
|
|
37851
|
-
const { error } = validation.validate(_id);
|
|
37852
|
-
if (error) {
|
|
37853
|
-
logger127.log({ level: "error", message: error.message });
|
|
37854
|
-
next(new BadRequestError150(error.message));
|
|
37855
|
-
return;
|
|
37856
|
-
}
|
|
37857
38016
|
try {
|
|
38017
|
+
const schema2 = Joi91.object({
|
|
38018
|
+
_id: Joi91.string().hex().length(24).required()
|
|
38019
|
+
});
|
|
38020
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
38021
|
+
if (error) {
|
|
38022
|
+
logger127.log({ level: "error", message: error.message });
|
|
38023
|
+
next(new BadRequestError150(error.message));
|
|
38024
|
+
return;
|
|
38025
|
+
}
|
|
38026
|
+
const { _id } = value;
|
|
37858
38027
|
await _deleteBulletinVideoById(_id);
|
|
37859
38028
|
res.status(200).json({ message: "Successfully deleted bulletin video." });
|
|
37860
38029
|
return;
|
|
37861
|
-
} catch (
|
|
37862
|
-
logger127.log({ level: "error", message:
|
|
37863
|
-
next(
|
|
38030
|
+
} catch (error) {
|
|
38031
|
+
logger127.log({ level: "error", message: error.message });
|
|
38032
|
+
next(error);
|
|
37864
38033
|
return;
|
|
37865
38034
|
}
|
|
37866
38035
|
}
|
|
@@ -41689,6 +41858,17 @@ import {
|
|
|
41689
41858
|
// src/models/occurrence-subject.model.ts
|
|
41690
41859
|
import { ObjectId as ObjectId108 } from "mongodb";
|
|
41691
41860
|
import Joi103 from "joi";
|
|
41861
|
+
var SubjectSort = /* @__PURE__ */ ((SubjectSort2) => {
|
|
41862
|
+
SubjectSort2["CREATED_AT"] = "createdAt";
|
|
41863
|
+
SubjectSort2["NAME"] = "name";
|
|
41864
|
+
SubjectSort2["ID"] = "_id";
|
|
41865
|
+
return SubjectSort2;
|
|
41866
|
+
})(SubjectSort || {});
|
|
41867
|
+
var SubjectOrder = /* @__PURE__ */ ((SubjectOrder2) => {
|
|
41868
|
+
SubjectOrder2["ASC"] = "asc";
|
|
41869
|
+
SubjectOrder2["DESC"] = "desc";
|
|
41870
|
+
return SubjectOrder2;
|
|
41871
|
+
})(SubjectOrder || {});
|
|
41692
41872
|
var schemaOccurrenceSubject = Joi103.object({
|
|
41693
41873
|
site: Joi103.string().hex().required(),
|
|
41694
41874
|
subject: Joi103.string().required(),
|
|
@@ -41797,7 +41977,8 @@ function useOccurrenceSubjectRepo() {
|
|
|
41797
41977
|
}
|
|
41798
41978
|
const baseQuery = {
|
|
41799
41979
|
site,
|
|
41800
|
-
status: { $ne: "deleted" }
|
|
41980
|
+
status: { $ne: "deleted" },
|
|
41981
|
+
...search && { $text: { $search: search } }
|
|
41801
41982
|
};
|
|
41802
41983
|
let query = { ...baseQuery };
|
|
41803
41984
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
@@ -41806,12 +41987,9 @@ function useOccurrenceSubjectRepo() {
|
|
|
41806
41987
|
sort: JSON.stringify(sort),
|
|
41807
41988
|
page,
|
|
41808
41989
|
limit,
|
|
41809
|
-
status: { $ne: "deleted" }
|
|
41990
|
+
status: { $ne: "deleted" },
|
|
41991
|
+
...search && { search }
|
|
41810
41992
|
};
|
|
41811
|
-
if (search) {
|
|
41812
|
-
query.$text = { $search: search };
|
|
41813
|
-
cacheOptions.search = search;
|
|
41814
|
-
}
|
|
41815
41993
|
const cacheKey = makeCacheKey54(namespace_collection, cacheOptions);
|
|
41816
41994
|
const cachedData = await getCache(cacheKey);
|
|
41817
41995
|
if (cachedData) {
|
|
@@ -41890,11 +42068,22 @@ function useOccurrenceSubjectRepo() {
|
|
|
41890
42068
|
} catch (error) {
|
|
41891
42069
|
throw new BadRequestError170("Invalid occurrence subject ID format.");
|
|
41892
42070
|
}
|
|
42071
|
+
const cacheKey = makeCacheKey54(namespace_collection, { _id });
|
|
42072
|
+
const cachedData = await getCache(cacheKey);
|
|
42073
|
+
if (cachedData) {
|
|
42074
|
+
logger147.info(`Cache hit for key: ${cacheKey}`);
|
|
42075
|
+
return cachedData;
|
|
42076
|
+
}
|
|
41893
42077
|
try {
|
|
41894
42078
|
const data = await collection.findOne({ _id }, { session });
|
|
41895
42079
|
if (!data) {
|
|
41896
42080
|
throw new NotFoundError46("Occurrence subject not found.");
|
|
41897
42081
|
}
|
|
42082
|
+
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
42083
|
+
logger147.info(`Cache set for key: ${cacheKey}`);
|
|
42084
|
+
}).catch((err) => {
|
|
42085
|
+
logger147.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
42086
|
+
});
|
|
41898
42087
|
return data;
|
|
41899
42088
|
} catch (error) {
|
|
41900
42089
|
throw error;
|
|
@@ -42081,62 +42270,49 @@ function useOccurrenceEntryController() {
|
|
|
42081
42270
|
getLatestSerialNumber: _getLatestSerialNumber
|
|
42082
42271
|
} = useOccurrenceEntryRepo();
|
|
42083
42272
|
async function add(req, res, next) {
|
|
42084
|
-
const { error, value } = schemaOccurrenceEntry.validate(req.body, {
|
|
42085
|
-
abortEarly: false
|
|
42086
|
-
});
|
|
42087
|
-
if (error) {
|
|
42088
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
42089
|
-
logger148.log({ level: "error", message: messages });
|
|
42090
|
-
next(new BadRequestError171(messages));
|
|
42091
|
-
return;
|
|
42092
|
-
}
|
|
42093
42273
|
try {
|
|
42274
|
+
const { error, value } = schemaOccurrenceEntry.validate(req.body, {
|
|
42275
|
+
abortEarly: false
|
|
42276
|
+
});
|
|
42277
|
+
if (error) {
|
|
42278
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
42279
|
+
logger148.log({ level: "error", message: messages });
|
|
42280
|
+
next(new BadRequestError171(messages));
|
|
42281
|
+
return;
|
|
42282
|
+
}
|
|
42094
42283
|
const data = await _add(value);
|
|
42095
42284
|
res.status(201).json(data);
|
|
42096
42285
|
return;
|
|
42097
|
-
} catch (
|
|
42098
|
-
logger148.log({ level: "error", message:
|
|
42099
|
-
next(
|
|
42286
|
+
} catch (error) {
|
|
42287
|
+
logger148.log({ level: "error", message: error.message });
|
|
42288
|
+
next(error);
|
|
42100
42289
|
return;
|
|
42101
42290
|
}
|
|
42102
42291
|
}
|
|
42103
42292
|
async function getAll(req, res, next) {
|
|
42104
|
-
const allowedFields = ["createdAt", "name"];
|
|
42105
|
-
const allowedOrder = ["asc", "desc"];
|
|
42106
|
-
const validation = Joi104.object({
|
|
42107
|
-
search: Joi104.string().optional().allow("", null),
|
|
42108
|
-
page: Joi104.number().integer().min(1).allow("", null).default(1),
|
|
42109
|
-
limit: Joi104.number().integer().min(1).max(100).allow("", null).default(10),
|
|
42110
|
-
sort: Joi104.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("", ...allowedFields),
|
|
42111
|
-
order: Joi104.string().pattern(/^(asc|desc)(,(asc|desc))*$/).optional().allow("", ...allowedOrder),
|
|
42112
|
-
site: Joi104.string().hex().required(),
|
|
42113
|
-
dailyOccurrenceBookId: Joi104.string().optional().allow("", null)
|
|
42114
|
-
});
|
|
42115
|
-
const query = { ...req.query };
|
|
42116
|
-
const { error } = validation.validate(query, {
|
|
42117
|
-
abortEarly: false
|
|
42118
|
-
});
|
|
42119
|
-
if (error) {
|
|
42120
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
42121
|
-
logger148.log({ level: "error", message: messages });
|
|
42122
|
-
next(new BadRequestError171(messages));
|
|
42123
|
-
return;
|
|
42124
|
-
}
|
|
42125
|
-
const search = req.query.search ?? "";
|
|
42126
|
-
const page = parseInt(req.query.page ?? "1");
|
|
42127
|
-
const limit = parseInt(req.query.limit ?? "10");
|
|
42128
|
-
const site = req.query.site ?? "";
|
|
42129
|
-
const dailyOccurrenceBookId = req.query.dailyOccurrenceBookId ?? "";
|
|
42130
|
-
const sortObj = {};
|
|
42131
|
-
const sortFields = String(req.query.sort).split(",");
|
|
42132
|
-
const sortOrders = String(req.query.order).split(",");
|
|
42133
|
-
sortFields.forEach((field, index) => {
|
|
42134
|
-
if (allowedFields.includes(field)) {
|
|
42135
|
-
const order = sortOrders[index] === "asc" ? 1 : -1;
|
|
42136
|
-
sortObj[field] = order;
|
|
42137
|
-
}
|
|
42138
|
-
});
|
|
42139
42293
|
try {
|
|
42294
|
+
const schema2 = Joi104.object({
|
|
42295
|
+
search: Joi104.string().optional().allow("", null),
|
|
42296
|
+
page: Joi104.number().integer().min(1).allow("", null).default(1),
|
|
42297
|
+
limit: Joi104.number().integer().min(1).max(100).allow("", null).default(10),
|
|
42298
|
+
sort: Joi104.string().valid(...Object.values(EntrySort)).default("_id" /* ID */),
|
|
42299
|
+
order: Joi104.string().valid(...Object.values(EntryOrder)).default("desc" /* DESC */),
|
|
42300
|
+
site: Joi104.string().hex().required(),
|
|
42301
|
+
dailyOccurrenceBookId: Joi104.string().hex().length(24).optional().allow("", null)
|
|
42302
|
+
});
|
|
42303
|
+
const { error, value } = schema2.validate(req.query, {
|
|
42304
|
+
abortEarly: false
|
|
42305
|
+
});
|
|
42306
|
+
if (error) {
|
|
42307
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
42308
|
+
logger148.log({ level: "error", message: messages });
|
|
42309
|
+
next(new BadRequestError171(messages));
|
|
42310
|
+
return;
|
|
42311
|
+
}
|
|
42312
|
+
const { search, page, limit, site, dailyOccurrenceBookId, sort, order } = value;
|
|
42313
|
+
const sortObj = {
|
|
42314
|
+
[sort ? sort : "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
|
|
42315
|
+
};
|
|
42140
42316
|
const data = await _getAll({
|
|
42141
42317
|
search,
|
|
42142
42318
|
page,
|
|
@@ -42147,69 +42323,73 @@ function useOccurrenceEntryController() {
|
|
|
42147
42323
|
});
|
|
42148
42324
|
res.status(200).json(data);
|
|
42149
42325
|
return;
|
|
42150
|
-
} catch (
|
|
42151
|
-
logger148.log({ level: "error", message:
|
|
42152
|
-
next(
|
|
42326
|
+
} catch (error) {
|
|
42327
|
+
logger148.log({ level: "error", message: error.message });
|
|
42328
|
+
next(error);
|
|
42153
42329
|
return;
|
|
42154
42330
|
}
|
|
42155
42331
|
}
|
|
42156
42332
|
async function getOccurrenceEntryById(req, res, next) {
|
|
42157
|
-
const validation = Joi104.string().hex().required();
|
|
42158
|
-
const _id = req.params.id;
|
|
42159
|
-
const { error } = validation.validate(_id);
|
|
42160
|
-
if (error) {
|
|
42161
|
-
logger148.log({ level: "error", message: error.message });
|
|
42162
|
-
next(new BadRequestError171(error.message));
|
|
42163
|
-
return;
|
|
42164
|
-
}
|
|
42165
42333
|
try {
|
|
42334
|
+
const schema2 = Joi104.object({
|
|
42335
|
+
_id: Joi104.string().hex().length(24).required()
|
|
42336
|
+
});
|
|
42337
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
42338
|
+
if (error) {
|
|
42339
|
+
logger148.log({ level: "error", message: error.message });
|
|
42340
|
+
next(new BadRequestError171(error.message));
|
|
42341
|
+
return;
|
|
42342
|
+
}
|
|
42343
|
+
const { _id } = value;
|
|
42166
42344
|
const data = await _getOccurrenceEntryById(_id);
|
|
42167
42345
|
res.status(200).json(data);
|
|
42168
42346
|
return;
|
|
42169
|
-
} catch (
|
|
42170
|
-
logger148.log({ level: "error", message:
|
|
42171
|
-
next(
|
|
42347
|
+
} catch (error) {
|
|
42348
|
+
logger148.log({ level: "error", message: error.message });
|
|
42349
|
+
next(error);
|
|
42172
42350
|
return;
|
|
42173
42351
|
}
|
|
42174
42352
|
}
|
|
42175
42353
|
async function updateOccurrenceEntryById(req, res, next) {
|
|
42176
|
-
const payload = { _id: req.params.id, ...req.body };
|
|
42177
|
-
const { error, value } = schemaUpdateOccurrenceEntry.validate(payload, {
|
|
42178
|
-
abortEarly: false
|
|
42179
|
-
});
|
|
42180
|
-
if (error) {
|
|
42181
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
42182
|
-
logger148.log({ level: "error", message: messages });
|
|
42183
|
-
next(new BadRequestError171(messages));
|
|
42184
|
-
return;
|
|
42185
|
-
}
|
|
42186
|
-
const { _id, ...rest } = value;
|
|
42187
42354
|
try {
|
|
42355
|
+
const payload = { _id: req.params.id, ...req.body };
|
|
42356
|
+
const { error, value } = schemaUpdateOccurrenceEntry.validate(payload, {
|
|
42357
|
+
abortEarly: false
|
|
42358
|
+
});
|
|
42359
|
+
if (error) {
|
|
42360
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
42361
|
+
logger148.log({ level: "error", message: messages });
|
|
42362
|
+
next(new BadRequestError171(messages));
|
|
42363
|
+
return;
|
|
42364
|
+
}
|
|
42365
|
+
const { _id, ...rest } = value;
|
|
42188
42366
|
const result = await _updateOccurrenceEntryById(_id, rest);
|
|
42189
42367
|
res.status(200).json({ message: result });
|
|
42190
42368
|
return;
|
|
42191
|
-
} catch (
|
|
42192
|
-
logger148.log({ level: "error", message:
|
|
42193
|
-
next(
|
|
42369
|
+
} catch (error) {
|
|
42370
|
+
logger148.log({ level: "error", message: error.message });
|
|
42371
|
+
next(error);
|
|
42194
42372
|
return;
|
|
42195
42373
|
}
|
|
42196
42374
|
}
|
|
42197
42375
|
async function deleteOccurrenceEntryById(req, res, next) {
|
|
42198
|
-
const validation = Joi104.string().hex().required();
|
|
42199
|
-
const _id = req.params.id;
|
|
42200
|
-
const { error } = validation.validate(_id);
|
|
42201
|
-
if (error) {
|
|
42202
|
-
logger148.log({ level: "error", message: error.message });
|
|
42203
|
-
next(new BadRequestError171(error.message));
|
|
42204
|
-
return;
|
|
42205
|
-
}
|
|
42206
42376
|
try {
|
|
42377
|
+
const schema2 = Joi104.object({
|
|
42378
|
+
_id: Joi104.string().hex().length(24).required()
|
|
42379
|
+
});
|
|
42380
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
42381
|
+
if (error) {
|
|
42382
|
+
logger148.log({ level: "error", message: error.message });
|
|
42383
|
+
next(new BadRequestError171(error.message));
|
|
42384
|
+
return;
|
|
42385
|
+
}
|
|
42386
|
+
const { _id } = value;
|
|
42207
42387
|
await _deleteOccurrenceEntryById(_id);
|
|
42208
42388
|
res.status(200).json({ message: "Successfully deleted occurrence entry." });
|
|
42209
42389
|
return;
|
|
42210
|
-
} catch (
|
|
42211
|
-
logger148.log({ level: "error", message:
|
|
42212
|
-
next(
|
|
42390
|
+
} catch (error) {
|
|
42391
|
+
logger148.log({ level: "error", message: error.message });
|
|
42392
|
+
next(error);
|
|
42213
42393
|
return;
|
|
42214
42394
|
}
|
|
42215
42395
|
}
|
|
@@ -42855,61 +43035,48 @@ function useOccurrenceSubjectController() {
|
|
|
42855
43035
|
deleteOccurrenceSubjectById: _deleteOccurrenceSubjectById
|
|
42856
43036
|
} = useOccurrenceSubjectRepo();
|
|
42857
43037
|
async function add(req, res, next) {
|
|
42858
|
-
const payload = { ...req.body };
|
|
42859
|
-
const { error } = schemaOccurrenceSubject.validate(payload, {
|
|
42860
|
-
abortEarly: false
|
|
42861
|
-
});
|
|
42862
|
-
if (error) {
|
|
42863
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
42864
|
-
logger151.log({ level: "error", message: messages });
|
|
42865
|
-
next(new BadRequestError174(messages));
|
|
42866
|
-
return;
|
|
42867
|
-
}
|
|
42868
43038
|
try {
|
|
42869
|
-
const
|
|
43039
|
+
const { error, value } = schemaOccurrenceSubject.validate(req.body, {
|
|
43040
|
+
abortEarly: false
|
|
43041
|
+
});
|
|
43042
|
+
if (error) {
|
|
43043
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
43044
|
+
logger151.log({ level: "error", message: messages });
|
|
43045
|
+
next(new BadRequestError174(messages));
|
|
43046
|
+
return;
|
|
43047
|
+
}
|
|
43048
|
+
const data = await _add(value);
|
|
42870
43049
|
res.status(201).json(data);
|
|
42871
43050
|
return;
|
|
42872
|
-
} catch (
|
|
42873
|
-
logger151.log({ level: "error", message:
|
|
42874
|
-
next(
|
|
43051
|
+
} catch (error) {
|
|
43052
|
+
logger151.log({ level: "error", message: error.message });
|
|
43053
|
+
next(error);
|
|
42875
43054
|
return;
|
|
42876
43055
|
}
|
|
42877
43056
|
}
|
|
42878
43057
|
async function getAll(req, res, next) {
|
|
42879
|
-
const allowedFields = ["createdAt", "name"];
|
|
42880
|
-
const allowedOrder = ["asc", "desc"];
|
|
42881
|
-
const validation = Joi107.object({
|
|
42882
|
-
search: Joi107.string().optional().allow("", null),
|
|
42883
|
-
page: Joi107.number().integer().min(1).allow("", null).default(1),
|
|
42884
|
-
limit: Joi107.number().integer().min(1).max(100).allow("", null).default(10),
|
|
42885
|
-
sort: Joi107.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("", ...allowedFields),
|
|
42886
|
-
order: Joi107.string().pattern(/^(asc|desc)(,(asc|desc))*$/).optional().allow("", ...allowedOrder),
|
|
42887
|
-
site: Joi107.string().hex().required()
|
|
42888
|
-
});
|
|
42889
|
-
const query = { ...req.query };
|
|
42890
|
-
const { error } = validation.validate(query, {
|
|
42891
|
-
abortEarly: false
|
|
42892
|
-
});
|
|
42893
|
-
if (error) {
|
|
42894
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
42895
|
-
logger151.log({ level: "error", message: messages });
|
|
42896
|
-
next(new BadRequestError174(messages));
|
|
42897
|
-
return;
|
|
42898
|
-
}
|
|
42899
|
-
const search = req.query.search ?? "";
|
|
42900
|
-
const page = parseInt(req.query.page ?? "1");
|
|
42901
|
-
const limit = parseInt(req.query.limit ?? "10");
|
|
42902
|
-
const site = req.query.site ?? "";
|
|
42903
|
-
const sortObj = {};
|
|
42904
|
-
const sortFields = String(req.query.sort).split(",");
|
|
42905
|
-
const sortOrders = String(req.query.order).split(",");
|
|
42906
|
-
sortFields.forEach((field, index) => {
|
|
42907
|
-
if (allowedFields.includes(field)) {
|
|
42908
|
-
const order = sortOrders[index] === "asc" ? 1 : -1;
|
|
42909
|
-
sortObj[field] = order;
|
|
42910
|
-
}
|
|
42911
|
-
});
|
|
42912
43058
|
try {
|
|
43059
|
+
const validation = Joi107.object({
|
|
43060
|
+
search: Joi107.string().optional().allow("", null),
|
|
43061
|
+
page: Joi107.number().integer().min(1).allow("", null).default(1),
|
|
43062
|
+
limit: Joi107.number().integer().min(1).max(100).allow("", null).default(10),
|
|
43063
|
+
sort: Joi107.string().valid(...Object.values(SubjectSort)).default("_id" /* ID */),
|
|
43064
|
+
order: Joi107.string().valid(...Object.values(SubjectOrder)).default("desc" /* DESC */),
|
|
43065
|
+
site: Joi107.string().hex().length(24).required()
|
|
43066
|
+
});
|
|
43067
|
+
const { error, value } = validation.validate(req.query, {
|
|
43068
|
+
abortEarly: false
|
|
43069
|
+
});
|
|
43070
|
+
if (error) {
|
|
43071
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
43072
|
+
logger151.log({ level: "error", message: messages });
|
|
43073
|
+
next(new BadRequestError174(messages));
|
|
43074
|
+
return;
|
|
43075
|
+
}
|
|
43076
|
+
const { search, page, limit, site, sort, order } = value;
|
|
43077
|
+
const sortObj = {
|
|
43078
|
+
[sort ? sort : "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
|
|
43079
|
+
};
|
|
42913
43080
|
const data = await _getAll({
|
|
42914
43081
|
search,
|
|
42915
43082
|
page,
|
|
@@ -42919,50 +43086,54 @@ function useOccurrenceSubjectController() {
|
|
|
42919
43086
|
});
|
|
42920
43087
|
res.status(200).json(data);
|
|
42921
43088
|
return;
|
|
42922
|
-
} catch (
|
|
42923
|
-
logger151.log({ level: "error", message:
|
|
42924
|
-
next(
|
|
43089
|
+
} catch (error) {
|
|
43090
|
+
logger151.log({ level: "error", message: error.message });
|
|
43091
|
+
next(error);
|
|
42925
43092
|
return;
|
|
42926
43093
|
}
|
|
42927
43094
|
}
|
|
42928
43095
|
async function getOccurrenceSubjectById(req, res, next) {
|
|
42929
|
-
const validation = Joi107.string().hex().required();
|
|
42930
|
-
const _id = req.params.id;
|
|
42931
|
-
const { error } = validation.validate(_id);
|
|
42932
|
-
if (error) {
|
|
42933
|
-
logger151.log({ level: "error", message: error.message });
|
|
42934
|
-
next(new BadRequestError174(error.message));
|
|
42935
|
-
return;
|
|
42936
|
-
}
|
|
42937
43096
|
try {
|
|
43097
|
+
const schema2 = Joi107.object({
|
|
43098
|
+
_id: Joi107.string().hex().length(24).required()
|
|
43099
|
+
});
|
|
43100
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
43101
|
+
if (error) {
|
|
43102
|
+
logger151.log({ level: "error", message: error.message });
|
|
43103
|
+
next(new BadRequestError174(error.message));
|
|
43104
|
+
return;
|
|
43105
|
+
}
|
|
43106
|
+
const { _id } = value;
|
|
42938
43107
|
const data = await _getOccurrenceSubjectById(_id);
|
|
42939
43108
|
res.status(200).json(data);
|
|
42940
43109
|
return;
|
|
42941
|
-
} catch (
|
|
42942
|
-
logger151.log({ level: "error", message:
|
|
42943
|
-
next(
|
|
43110
|
+
} catch (error) {
|
|
43111
|
+
logger151.log({ level: "error", message: error.message });
|
|
43112
|
+
next(error);
|
|
42944
43113
|
return;
|
|
42945
43114
|
}
|
|
42946
43115
|
}
|
|
42947
43116
|
async function updateOccurrenceSubjectById(req, res, next) {
|
|
42948
|
-
const _id = req.params.id;
|
|
42949
|
-
const payload = { _id, ...req.body };
|
|
42950
|
-
const { error } = schemaUpdateOccurrenceSubject.validate(payload, {
|
|
42951
|
-
abortEarly: false
|
|
42952
|
-
});
|
|
42953
|
-
if (error) {
|
|
42954
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
42955
|
-
logger151.log({ level: "error", message: messages });
|
|
42956
|
-
next(new BadRequestError174(messages));
|
|
42957
|
-
return;
|
|
42958
|
-
}
|
|
42959
43117
|
try {
|
|
42960
|
-
const
|
|
43118
|
+
const { error, value } = schemaUpdateOccurrenceSubject.validate(
|
|
43119
|
+
{ _id: req.params.id, ...req.body },
|
|
43120
|
+
{
|
|
43121
|
+
abortEarly: false
|
|
43122
|
+
}
|
|
43123
|
+
);
|
|
43124
|
+
if (error) {
|
|
43125
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
43126
|
+
logger151.log({ level: "error", message: messages });
|
|
43127
|
+
next(new BadRequestError174(messages));
|
|
43128
|
+
return;
|
|
43129
|
+
}
|
|
43130
|
+
const { _id, ...rest } = value;
|
|
43131
|
+
const result = await _updateOccurrenceSubjectById(_id, rest);
|
|
42961
43132
|
res.status(200).json({ message: result });
|
|
42962
43133
|
return;
|
|
42963
|
-
} catch (
|
|
42964
|
-
logger151.log({ level: "error", message:
|
|
42965
|
-
next(
|
|
43134
|
+
} catch (error) {
|
|
43135
|
+
logger151.log({ level: "error", message: error.message });
|
|
43136
|
+
next(error);
|
|
42966
43137
|
return;
|
|
42967
43138
|
}
|
|
42968
43139
|
}
|
|
@@ -50281,6 +50452,8 @@ export {
|
|
|
50281
50452
|
BulletinRecipient,
|
|
50282
50453
|
BulletinSort,
|
|
50283
50454
|
BulletinStatus,
|
|
50455
|
+
BulletinVideoOrder,
|
|
50456
|
+
BulletinVideoSort,
|
|
50284
50457
|
CameraType,
|
|
50285
50458
|
DEVICE_STATUS,
|
|
50286
50459
|
DOBStatus,
|
|
@@ -50288,6 +50461,8 @@ export {
|
|
|
50288
50461
|
EAccessCardTypes,
|
|
50289
50462
|
EAccessCardUserTypes,
|
|
50290
50463
|
EmailSender,
|
|
50464
|
+
EntryOrder,
|
|
50465
|
+
EntrySort,
|
|
50291
50466
|
FacilitySort,
|
|
50292
50467
|
FacilityStatus,
|
|
50293
50468
|
GuestSort,
|
|
@@ -50369,6 +50544,8 @@ export {
|
|
|
50369
50544
|
SortFields,
|
|
50370
50545
|
SortOrder,
|
|
50371
50546
|
Status,
|
|
50547
|
+
SubjectOrder,
|
|
50548
|
+
SubjectSort,
|
|
50372
50549
|
SubscriptionType,
|
|
50373
50550
|
UseAccessManagementRepo,
|
|
50374
50551
|
UserStatus,
|
|
@@ -50424,6 +50601,7 @@ export {
|
|
|
50424
50601
|
robotSchema,
|
|
50425
50602
|
schema,
|
|
50426
50603
|
schemaApprovedBy,
|
|
50604
|
+
schemaApprover,
|
|
50427
50605
|
schemaBilling,
|
|
50428
50606
|
schemaBillingConfiguration,
|
|
50429
50607
|
schemaBillingItem,
|