@7365admin1/core 2.42.0 → 2.44.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 +49 -7
- package/dist/index.js +438 -217
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +433 -217
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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, ""),
|
|
@@ -4813,7 +4824,10 @@ function useSiteRepo() {
|
|
|
4813
4824
|
throw error;
|
|
4814
4825
|
}
|
|
4815
4826
|
}
|
|
4816
|
-
async function siteInformation({
|
|
4827
|
+
async function siteInformation({
|
|
4828
|
+
id,
|
|
4829
|
+
payload
|
|
4830
|
+
}) {
|
|
4817
4831
|
try {
|
|
4818
4832
|
const siteId = new ObjectId17(id);
|
|
4819
4833
|
const res = await collection.updateOne(
|
|
@@ -4833,6 +4847,48 @@ function useSiteRepo() {
|
|
|
4833
4847
|
throw error;
|
|
4834
4848
|
}
|
|
4835
4849
|
}
|
|
4850
|
+
async function getAllSitesForResidentCreation({
|
|
4851
|
+
search = "",
|
|
4852
|
+
page = 1,
|
|
4853
|
+
limit = 10
|
|
4854
|
+
}) {
|
|
4855
|
+
page = page > 0 ? page - 1 : 0;
|
|
4856
|
+
const query = {
|
|
4857
|
+
status: { $ne: "deleted" }
|
|
4858
|
+
};
|
|
4859
|
+
const cacheOptions = {
|
|
4860
|
+
status: { $ne: "deleted" },
|
|
4861
|
+
page,
|
|
4862
|
+
limit
|
|
4863
|
+
};
|
|
4864
|
+
if (search) {
|
|
4865
|
+
query.$or = [{ name: { $regex: search, $options: "i" } }];
|
|
4866
|
+
cacheOptions.search = search;
|
|
4867
|
+
}
|
|
4868
|
+
const cacheKey = makeCacheKey9(namespace_collection, cacheOptions);
|
|
4869
|
+
const cachedData = await getCache(cacheKey);
|
|
4870
|
+
if (cachedData) {
|
|
4871
|
+
logger12.info(`Cache hit for key: ${cacheKey}`);
|
|
4872
|
+
return cachedData;
|
|
4873
|
+
}
|
|
4874
|
+
try {
|
|
4875
|
+
const items = await collection.aggregate([
|
|
4876
|
+
{ $match: query },
|
|
4877
|
+
{ $skip: page * limit },
|
|
4878
|
+
{ $limit: limit }
|
|
4879
|
+
]).toArray();
|
|
4880
|
+
const length = await collection.countDocuments(query);
|
|
4881
|
+
const data = paginate8(items, page, limit, length);
|
|
4882
|
+
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
4883
|
+
logger12.info(`Cache set for key: ${cacheKey}`);
|
|
4884
|
+
}).catch((err) => {
|
|
4885
|
+
logger12.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
4886
|
+
});
|
|
4887
|
+
return data;
|
|
4888
|
+
} catch (error) {
|
|
4889
|
+
throw error;
|
|
4890
|
+
}
|
|
4891
|
+
}
|
|
4836
4892
|
return {
|
|
4837
4893
|
createIndexes,
|
|
4838
4894
|
createSite,
|
|
@@ -4847,7 +4903,8 @@ function useSiteRepo() {
|
|
|
4847
4903
|
updateSiteIncidentCounter,
|
|
4848
4904
|
updateSiteById,
|
|
4849
4905
|
getAllSitesUnpaginated,
|
|
4850
|
-
siteInformation
|
|
4906
|
+
siteInformation,
|
|
4907
|
+
getAllSitesForResidentCreation
|
|
4851
4908
|
};
|
|
4852
4909
|
}
|
|
4853
4910
|
|
|
@@ -12063,7 +12120,7 @@ function useServiceProviderController() {
|
|
|
12063
12120
|
const validation = Joi30.object({
|
|
12064
12121
|
search: Joi30.string().optional().allow("", null),
|
|
12065
12122
|
page: Joi30.number().integer().min(1).allow("", null).default(1),
|
|
12066
|
-
limit: Joi30.number().integer().min(1).max(
|
|
12123
|
+
limit: Joi30.number().integer().min(1).max(1e3).allow("", null).default(10),
|
|
12067
12124
|
orgId: Joi30.string().hex().optional().allow("", null),
|
|
12068
12125
|
siteId: Joi30.string().hex().optional().allow("", null),
|
|
12069
12126
|
serviceProviderOrgId: Joi30.string().hex().optional().allow("", null),
|
|
@@ -13273,6 +13330,10 @@ var schemaFiles = Joi35.object({
|
|
|
13273
13330
|
id: Joi35.string().hex().required(),
|
|
13274
13331
|
name: Joi35.string().optional().allow(null, "")
|
|
13275
13332
|
});
|
|
13333
|
+
var schemaApprover = Joi35.object({
|
|
13334
|
+
id: Joi35.string().hex().required(),
|
|
13335
|
+
name: Joi35.string().optional().allow(null, "")
|
|
13336
|
+
});
|
|
13276
13337
|
var schemaPerson = Joi35.object({
|
|
13277
13338
|
_id: Joi35.string().hex().optional().allow("", null),
|
|
13278
13339
|
user: Joi35.string().hex().length(24).optional().allow(null, ""),
|
|
@@ -13296,7 +13357,9 @@ var schemaPerson = Joi35.object({
|
|
|
13296
13357
|
isOwner: Joi35.boolean().required(),
|
|
13297
13358
|
files: Joi35.array().items(schemaFiles).optional().allow(null),
|
|
13298
13359
|
password: Joi35.string().optional().allow(null, ""),
|
|
13299
|
-
plateNumber: Joi35.string().optional().allow(null, "")
|
|
13360
|
+
plateNumber: Joi35.string().optional().allow(null, ""),
|
|
13361
|
+
platform: Joi35.string().valid("web", "mobile").optional().allow(null, ""),
|
|
13362
|
+
approvedBy: schemaApprover.optional().allow(null, "")
|
|
13300
13363
|
});
|
|
13301
13364
|
var schemaUpdatePerson = Joi35.object({
|
|
13302
13365
|
_id: Joi35.string().hex().required(),
|
|
@@ -13317,12 +13380,14 @@ var schemaUpdatePerson = Joi35.object({
|
|
|
13317
13380
|
isOwner: Joi35.boolean().optional().allow(null, ""),
|
|
13318
13381
|
files: Joi35.array().items(schemaFiles).optional().allow(null),
|
|
13319
13382
|
password: Joi35.string().optional().allow(null, ""),
|
|
13320
|
-
plateNumber: Joi35.string().optional().allow(null, "")
|
|
13383
|
+
plateNumber: Joi35.string().optional().allow(null, ""),
|
|
13384
|
+
platform: Joi35.string().valid("web", "mobile").optional().allow(null, ""),
|
|
13385
|
+
approvedBy: schemaApprover.optional().allow(null, "")
|
|
13321
13386
|
});
|
|
13322
13387
|
function MPerson(value) {
|
|
13323
13388
|
const { error } = schemaPerson.validate(value);
|
|
13324
13389
|
if (error) {
|
|
13325
|
-
throw new
|
|
13390
|
+
throw new BadRequestError66(error.details[0].message);
|
|
13326
13391
|
}
|
|
13327
13392
|
if (value._id && typeof value._id === "string") {
|
|
13328
13393
|
try {
|
|
@@ -13388,6 +13453,8 @@ function MPerson(value) {
|
|
|
13388
13453
|
isOwner: value.isOwner ?? false,
|
|
13389
13454
|
files: value.files ?? [],
|
|
13390
13455
|
plateNumber: value.plateNumber ?? "",
|
|
13456
|
+
platForm: value.platform ?? "",
|
|
13457
|
+
approvedBy: value.approvedBy ?? { id: "", name: "" },
|
|
13391
13458
|
createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
13392
13459
|
updatedAt: value.updatedAt,
|
|
13393
13460
|
deletedAt: value.deletedAt
|
|
@@ -13426,8 +13493,8 @@ var schemaVisitorTransaction = Joi36.object({
|
|
|
13426
13493
|
contact: Joi36.string().optional().allow(null, ""),
|
|
13427
13494
|
plateNumber: Joi36.string().optional().allow(null, ""),
|
|
13428
13495
|
recNo: Joi36.string().optional().allow(null, ""),
|
|
13429
|
-
checkIn: Joi36.date().optional().allow(null
|
|
13430
|
-
checkOut: Joi36.date().optional().allow(null
|
|
13496
|
+
checkIn: Joi36.date().iso().optional().allow(null),
|
|
13497
|
+
checkOut: Joi36.date().iso().optional().allow(null),
|
|
13431
13498
|
deliveryType: Joi36.string().optional().allow(null, ""),
|
|
13432
13499
|
status: Joi36.string().optional().valid(...Object.values(VisitorStatus)).default("registered" /* REGISTERED */),
|
|
13433
13500
|
remarks: Joi36.string().optional().allow(null, ""),
|
|
@@ -13491,8 +13558,8 @@ var schemaUpdateVisTrans = Joi36.object({
|
|
|
13491
13558
|
contact: Joi36.string().optional().allow(null, ""),
|
|
13492
13559
|
plateNumber: Joi36.string().optional().allow(null, ""),
|
|
13493
13560
|
recNo: Joi36.string().optional().allow(null, ""),
|
|
13494
|
-
checkIn: Joi36.date().optional().allow(null
|
|
13495
|
-
checkOut: Joi36.date().optional().allow(null
|
|
13561
|
+
checkIn: Joi36.date().iso().optional().allow(null),
|
|
13562
|
+
checkOut: Joi36.date().iso().optional().allow(null),
|
|
13496
13563
|
deliveryType: Joi36.string().optional().allow(null, ""),
|
|
13497
13564
|
status: Joi36.string().optional().allow(null, ""),
|
|
13498
13565
|
remarks: Joi36.string().optional().allow(null, ""),
|
|
@@ -15092,7 +15159,7 @@ function usePersonRepo() {
|
|
|
15092
15159
|
]
|
|
15093
15160
|
} : void 0;
|
|
15094
15161
|
const query = {
|
|
15095
|
-
status,
|
|
15162
|
+
...status && status !== "all" ? { status } : { status: { $nin: ["deleted", "rejected"] } },
|
|
15096
15163
|
...start && { start },
|
|
15097
15164
|
...end,
|
|
15098
15165
|
...search && {
|
|
@@ -15130,12 +15197,29 @@ function usePersonRepo() {
|
|
|
15130
15197
|
return cachedData;
|
|
15131
15198
|
}
|
|
15132
15199
|
try {
|
|
15133
|
-
const basePipeline = [
|
|
15134
|
-
|
|
15135
|
-
|
|
15136
|
-
|
|
15137
|
-
|
|
15138
|
-
|
|
15200
|
+
const basePipeline = [{ $match: query }];
|
|
15201
|
+
if (status && status == "all") {
|
|
15202
|
+
basePipeline.push(
|
|
15203
|
+
{
|
|
15204
|
+
$addFields: {
|
|
15205
|
+
sortPriority: {
|
|
15206
|
+
$cond: [{ $eq: ["$status", "pending"] }, 1, 2]
|
|
15207
|
+
}
|
|
15208
|
+
}
|
|
15209
|
+
},
|
|
15210
|
+
{
|
|
15211
|
+
$sort: {
|
|
15212
|
+
sortPriority: 1,
|
|
15213
|
+
...sort
|
|
15214
|
+
}
|
|
15215
|
+
}
|
|
15216
|
+
);
|
|
15217
|
+
} else {
|
|
15218
|
+
basePipeline.push({
|
|
15219
|
+
$sort: sort
|
|
15220
|
+
});
|
|
15221
|
+
}
|
|
15222
|
+
basePipeline.push({ $skip: page * limit }, { $limit: limit });
|
|
15139
15223
|
const [items, countResult] = await Promise.all([
|
|
15140
15224
|
collection.aggregate(basePipeline, { session }).toArray(),
|
|
15141
15225
|
collection.aggregate([{ $match: query }, { $count: "total" }], { session }).toArray()
|
|
@@ -15584,6 +15668,37 @@ function usePersonRepo() {
|
|
|
15584
15668
|
}
|
|
15585
15669
|
}
|
|
15586
15670
|
}
|
|
15671
|
+
async function reviewResidentPerson(_id, value, session) {
|
|
15672
|
+
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
15673
|
+
try {
|
|
15674
|
+
_id = new ObjectId44(_id);
|
|
15675
|
+
} catch (error) {
|
|
15676
|
+
throw new BadRequestError70("Invalid ID format.");
|
|
15677
|
+
}
|
|
15678
|
+
try {
|
|
15679
|
+
const res = await collection.updateOne(
|
|
15680
|
+
{ _id },
|
|
15681
|
+
{ $set: value },
|
|
15682
|
+
{ session }
|
|
15683
|
+
);
|
|
15684
|
+
if (res.modifiedCount === 0) {
|
|
15685
|
+
throw new InternalServerError26(`Unable to ${value.status} person.`);
|
|
15686
|
+
}
|
|
15687
|
+
delNamespace().then(() => {
|
|
15688
|
+
logger51.info(
|
|
15689
|
+
`Cache cleared for namespace: ${site_people_namespace_collection}`
|
|
15690
|
+
);
|
|
15691
|
+
}).catch((err) => {
|
|
15692
|
+
logger51.error(
|
|
15693
|
+
`Failed to clear cache for namespace: ${site_people_namespace_collection}`,
|
|
15694
|
+
err
|
|
15695
|
+
);
|
|
15696
|
+
});
|
|
15697
|
+
return res;
|
|
15698
|
+
} catch (error) {
|
|
15699
|
+
throw error;
|
|
15700
|
+
}
|
|
15701
|
+
}
|
|
15587
15702
|
return {
|
|
15588
15703
|
add,
|
|
15589
15704
|
getAll,
|
|
@@ -15601,7 +15716,8 @@ function usePersonRepo() {
|
|
|
15601
15716
|
getPeopleByNRIC,
|
|
15602
15717
|
pushVehicleById,
|
|
15603
15718
|
pullVehicleByRecNo,
|
|
15604
|
-
getByUserId
|
|
15719
|
+
getByUserId,
|
|
15720
|
+
reviewResidentPerson
|
|
15605
15721
|
};
|
|
15606
15722
|
}
|
|
15607
15723
|
|
|
@@ -17915,7 +18031,8 @@ function useSiteController() {
|
|
|
17915
18031
|
getSites: _getSites,
|
|
17916
18032
|
getSiteById: _getSiteById,
|
|
17917
18033
|
updateSiteBlock: _updateSiteBlock,
|
|
17918
|
-
deleteSite: _deleteSite
|
|
18034
|
+
deleteSite: _deleteSite,
|
|
18035
|
+
getAllSitesForResidentCreation: _getAllSitesForResidentCreation
|
|
17919
18036
|
} = useSiteRepo();
|
|
17920
18037
|
const { updateGuardPostById, siteInformation: _siteInformation } = useSiteService();
|
|
17921
18038
|
async function createSite(req, res, next) {
|
|
@@ -18100,14 +18217,13 @@ function useSiteController() {
|
|
|
18100
18217
|
id: Joi42.string().hex().required(),
|
|
18101
18218
|
bgImage: Joi42.string().optional().allow("", null),
|
|
18102
18219
|
description: Joi42.string().optional().allow("", null),
|
|
18103
|
-
docs: Joi42.array().items(
|
|
18104
|
-
|
|
18105
|
-
|
|
18106
|
-
|
|
18107
|
-
|
|
18108
|
-
|
|
18109
|
-
|
|
18110
|
-
);
|
|
18220
|
+
docs: Joi42.array().items(
|
|
18221
|
+
Joi42.object({
|
|
18222
|
+
id: Joi42.string().hex().optional().allow("", null),
|
|
18223
|
+
name: Joi42.string().optional().allow("", null)
|
|
18224
|
+
})
|
|
18225
|
+
).optional().allow("", null)
|
|
18226
|
+
}).validate({ id, ...payload }, { abortEarly: false });
|
|
18111
18227
|
if (error) {
|
|
18112
18228
|
logger57.log({ level: "error", message: error.message });
|
|
18113
18229
|
next(new BadRequestError76(error.message));
|
|
@@ -18123,6 +18239,36 @@ function useSiteController() {
|
|
|
18123
18239
|
return;
|
|
18124
18240
|
}
|
|
18125
18241
|
}
|
|
18242
|
+
async function getAllSitesForResidentCreation(req, res, next) {
|
|
18243
|
+
const validation = Joi42.object({
|
|
18244
|
+
search: Joi42.string().optional().allow("", null),
|
|
18245
|
+
page: Joi42.number().integer().min(1).allow("", null).default(1),
|
|
18246
|
+
limit: Joi42.number().integer().min(1).max(100).allow("", null).default(10)
|
|
18247
|
+
});
|
|
18248
|
+
const query = { ...req.query };
|
|
18249
|
+
const { error } = validation.validate(query);
|
|
18250
|
+
if (error) {
|
|
18251
|
+
logger57.log({ level: "error", message: error.message });
|
|
18252
|
+
next(new BadRequestError76(error.message));
|
|
18253
|
+
return;
|
|
18254
|
+
}
|
|
18255
|
+
const search = req.query.search ?? "";
|
|
18256
|
+
const page = parseInt(req.query.page ?? "1");
|
|
18257
|
+
const limit = parseInt(req.query.limit ?? "10");
|
|
18258
|
+
try {
|
|
18259
|
+
const data = await _getAllSitesForResidentCreation({
|
|
18260
|
+
search,
|
|
18261
|
+
page,
|
|
18262
|
+
limit
|
|
18263
|
+
});
|
|
18264
|
+
res.json(data);
|
|
18265
|
+
return;
|
|
18266
|
+
} catch (error2) {
|
|
18267
|
+
logger57.log({ level: "error", message: error2.message });
|
|
18268
|
+
next(error2);
|
|
18269
|
+
return;
|
|
18270
|
+
}
|
|
18271
|
+
}
|
|
18126
18272
|
return {
|
|
18127
18273
|
createSite,
|
|
18128
18274
|
getSites,
|
|
@@ -18131,7 +18277,8 @@ function useSiteController() {
|
|
|
18131
18277
|
deleteSite,
|
|
18132
18278
|
updateById,
|
|
18133
18279
|
updateGuardPostsById,
|
|
18134
|
-
siteInformation
|
|
18280
|
+
siteInformation,
|
|
18281
|
+
getAllSitesForResidentCreation
|
|
18135
18282
|
};
|
|
18136
18283
|
}
|
|
18137
18284
|
|
|
@@ -22474,6 +22621,7 @@ function useVisitorTransactionService() {
|
|
|
22474
22621
|
const { getAllSites: _getAllSites } = useSiteRepo();
|
|
22475
22622
|
const { getByUserId: _getByUserId } = usePersonRepo();
|
|
22476
22623
|
const { add: addVehicle } = useVehicleRepo();
|
|
22624
|
+
const { getById: _getUnitById } = useBuildingUnitRepo();
|
|
22477
22625
|
function extractKeyId(item) {
|
|
22478
22626
|
if (!item)
|
|
22479
22627
|
return null;
|
|
@@ -22558,6 +22706,10 @@ function useVisitorTransactionService() {
|
|
|
22558
22706
|
_getSiteById(value.site)
|
|
22559
22707
|
]);
|
|
22560
22708
|
}
|
|
22709
|
+
if (!value.unitName && value.unit) {
|
|
22710
|
+
const unit = await _getUnitById(value.unit);
|
|
22711
|
+
value.unitName = unit?.name;
|
|
22712
|
+
}
|
|
22561
22713
|
const hourExpiration = site?.dahuaTimeExpiration ? site?.dahuaTimeExpiration : 24 * 60;
|
|
22562
22714
|
const end = value.checkOut ? new Date(value.checkOut) : new Date(start.getTime() + hourExpiration * 60 * 1e3);
|
|
22563
22715
|
const startDahuaDate = formatDahuaDate(start);
|
|
@@ -22852,6 +23004,14 @@ function useVisitorTransactionService() {
|
|
|
22852
23004
|
}
|
|
22853
23005
|
value.passKeys = keptPassKeys;
|
|
22854
23006
|
}
|
|
23007
|
+
if (value.checkIn) {
|
|
23008
|
+
const parsed = new Date(value.checkIn);
|
|
23009
|
+
value.checkIn = isNaN(parsed.getTime()) ? null : parsed;
|
|
23010
|
+
}
|
|
23011
|
+
if (value.checkOut) {
|
|
23012
|
+
const parsed = new Date(value.checkOut);
|
|
23013
|
+
value.checkOut = isNaN(parsed.getTime()) ? null : parsed;
|
|
23014
|
+
}
|
|
22855
23015
|
await _updateVisitorTansactionById(id, value, session);
|
|
22856
23016
|
await session?.commitTransaction();
|
|
22857
23017
|
return "Successfully updated visitor transaction.";
|
|
@@ -23818,13 +23978,15 @@ function usePersonService() {
|
|
|
23818
23978
|
add: _add,
|
|
23819
23979
|
getById: _getById,
|
|
23820
23980
|
updateById: _updateById,
|
|
23821
|
-
getByUserId: _getByUserId
|
|
23981
|
+
getByUserId: _getByUserId,
|
|
23982
|
+
reviewResidentPerson: _reviewResidentPerson
|
|
23822
23983
|
} = usePersonRepo();
|
|
23823
23984
|
const { addPlateNumber: _addPlateNumber } = useDahuaService();
|
|
23824
23985
|
const {
|
|
23825
23986
|
createUser: addUser,
|
|
23826
23987
|
getUserByEmail,
|
|
23827
|
-
updateUserFieldById: _updateUserFieldById
|
|
23988
|
+
updateUserFieldById: _updateUserFieldById,
|
|
23989
|
+
getUserById
|
|
23828
23990
|
} = useUserRepo();
|
|
23829
23991
|
const { add: addMember } = useMemberRepo();
|
|
23830
23992
|
const { getById: _getUnitById, updateById: updateUnitById } = useBuildingUnitRepo();
|
|
@@ -23865,10 +24027,11 @@ function usePersonService() {
|
|
|
23865
24027
|
email: value.email,
|
|
23866
24028
|
password: hashedPassword,
|
|
23867
24029
|
name: value.name,
|
|
24030
|
+
status: value.platform == "mobile" ? "deleted" : "active",
|
|
23868
24031
|
defaultOrg: value.org?.toString() || ""
|
|
23869
24032
|
};
|
|
23870
24033
|
const userId = await addUser(user, session);
|
|
23871
|
-
value.user = userId;
|
|
24034
|
+
value.user = userId.toString();
|
|
23872
24035
|
let org = null;
|
|
23873
24036
|
if (userId) {
|
|
23874
24037
|
if (value?.org) {
|
|
@@ -23981,9 +24144,31 @@ function usePersonService() {
|
|
|
23981
24144
|
}
|
|
23982
24145
|
return { start: "", end: "" };
|
|
23983
24146
|
}
|
|
24147
|
+
async function reviewResidentPerson(id, value) {
|
|
24148
|
+
const session = useAtlas52.getClient()?.startSession();
|
|
24149
|
+
session?.startTransaction();
|
|
24150
|
+
try {
|
|
24151
|
+
if (value.approvedBy) {
|
|
24152
|
+
const approvedBy = await getUserById(value.approvedBy.id);
|
|
24153
|
+
if (!approvedBy || !approvedBy.name)
|
|
24154
|
+
throw new BadRequestError101("Created by not found.");
|
|
24155
|
+
value.approvedBy.name = approvedBy.name;
|
|
24156
|
+
value.approvedBy.id = approvedBy._id;
|
|
24157
|
+
}
|
|
24158
|
+
await _reviewResidentPerson(id, value, session);
|
|
24159
|
+
await session?.commitTransaction();
|
|
24160
|
+
return `Successfully ${value.status} person`;
|
|
24161
|
+
} catch (error) {
|
|
24162
|
+
await session?.abortTransaction();
|
|
24163
|
+
throw error;
|
|
24164
|
+
} finally {
|
|
24165
|
+
session?.endSession();
|
|
24166
|
+
}
|
|
24167
|
+
}
|
|
23984
24168
|
return {
|
|
23985
24169
|
add,
|
|
23986
|
-
updateById
|
|
24170
|
+
updateById,
|
|
24171
|
+
reviewResidentPerson
|
|
23987
24172
|
};
|
|
23988
24173
|
}
|
|
23989
24174
|
|
|
@@ -24000,7 +24185,11 @@ function usePersonController() {
|
|
|
24000
24185
|
getPeopleByNRIC: _getPeopleByNRIC,
|
|
24001
24186
|
getByUserId: _getByUserId
|
|
24002
24187
|
} = usePersonRepo();
|
|
24003
|
-
const {
|
|
24188
|
+
const {
|
|
24189
|
+
add: _add,
|
|
24190
|
+
updateById: _updateById,
|
|
24191
|
+
reviewResidentPerson: _reviewResidentPerson
|
|
24192
|
+
} = usePersonService();
|
|
24004
24193
|
async function add(req, res, next) {
|
|
24005
24194
|
const payload = { ...req.body };
|
|
24006
24195
|
const { error } = schemaPerson.validate(payload, {
|
|
@@ -24315,6 +24504,38 @@ function usePersonController() {
|
|
|
24315
24504
|
return;
|
|
24316
24505
|
}
|
|
24317
24506
|
}
|
|
24507
|
+
async function reviewResidentPerson(req, res, next) {
|
|
24508
|
+
const cookies = req.headers.cookie?.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
24509
|
+
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
24510
|
+
{}
|
|
24511
|
+
);
|
|
24512
|
+
req.body.approvedBy = cookies?.["user"] ? cookies["user"].toString() : req.body.approvedBy;
|
|
24513
|
+
const _id = req.params.id;
|
|
24514
|
+
const payload = { _id, ...req.body };
|
|
24515
|
+
const schema2 = Joi58.object({
|
|
24516
|
+
_id: Joi58.string().hex().required(),
|
|
24517
|
+
status: Joi58.string().valid("approved", "rejected", "resubmit").required(),
|
|
24518
|
+
approvedBy: Joi58.string().required(),
|
|
24519
|
+
remarks: Joi58.string().optional().allow("", null)
|
|
24520
|
+
});
|
|
24521
|
+
const { error } = schema2.validate(payload);
|
|
24522
|
+
if (error) {
|
|
24523
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
24524
|
+
logger83.log({ level: "error", message: messages });
|
|
24525
|
+
next(new BadRequestError102(messages));
|
|
24526
|
+
return;
|
|
24527
|
+
}
|
|
24528
|
+
try {
|
|
24529
|
+
req.body.approvedBy = { id: req.body.approvedBy, name: "" };
|
|
24530
|
+
const result = await _reviewResidentPerson(_id, req.body);
|
|
24531
|
+
res.status(200).json({ message: result });
|
|
24532
|
+
return;
|
|
24533
|
+
} catch (error2) {
|
|
24534
|
+
logger83.log({ level: "error", message: error2.message });
|
|
24535
|
+
next(error2);
|
|
24536
|
+
return;
|
|
24537
|
+
}
|
|
24538
|
+
}
|
|
24318
24539
|
return {
|
|
24319
24540
|
add,
|
|
24320
24541
|
getAll,
|
|
@@ -24326,7 +24547,8 @@ function usePersonController() {
|
|
|
24326
24547
|
getCompany,
|
|
24327
24548
|
getPeopleByPlateNumber,
|
|
24328
24549
|
getPeopleByNRIC,
|
|
24329
|
-
getPersonByUserId
|
|
24550
|
+
getPersonByUserId,
|
|
24551
|
+
reviewResidentPerson
|
|
24330
24552
|
};
|
|
24331
24553
|
}
|
|
24332
24554
|
|
|
@@ -29539,7 +29761,7 @@ function useBulletinBoardController() {
|
|
|
29539
29761
|
page: Joi76.number().integer().min(1).allow("", null).default(1),
|
|
29540
29762
|
limit: Joi76.number().integer().min(1).max(100).allow("", null).default(10),
|
|
29541
29763
|
sort: Joi76.string().valid(...Object.values(BulletinSort)).default("_id" /* ID */),
|
|
29542
|
-
order: Joi76.string().valid(...Object.values(SortOrder)).default("
|
|
29764
|
+
order: Joi76.string().valid(...Object.values(SortOrder)).default("desc" /* DESC */),
|
|
29543
29765
|
site: Joi76.string().hex().length(24).required(),
|
|
29544
29766
|
status: Joi76.string().valid(...Object.values(BuildingStatus)).optional().default("active" /* ACTIVE */),
|
|
29545
29767
|
recipients: Joi76.alternatives().try(
|
|
@@ -32754,7 +32976,7 @@ var MAccessCard = class {
|
|
|
32754
32976
|
accessType = "Normal" /* NORMAL */,
|
|
32755
32977
|
cardNo,
|
|
32756
32978
|
pin,
|
|
32757
|
-
qrData,
|
|
32979
|
+
qrData = null,
|
|
32758
32980
|
startDate,
|
|
32759
32981
|
endDate,
|
|
32760
32982
|
isActivated,
|
|
@@ -33091,10 +33313,6 @@ function UseAccessManagementRepo() {
|
|
|
33091
33313
|
payload.updatedAt = new Date(payload.updatedAt);
|
|
33092
33314
|
payload.assignedUnit = payload.unit?.map((id) => new ObjectId90(id));
|
|
33093
33315
|
delete payload.unit;
|
|
33094
|
-
payload.qrData = await createQrData({
|
|
33095
|
-
cardNumber: payload.cardNo,
|
|
33096
|
-
facilityCode: parseInt(payload.cardNo.slice(0, 4), 10)
|
|
33097
|
-
});
|
|
33098
33316
|
const accessCardObj = new MAccessCard(payload);
|
|
33099
33317
|
const result = await collection().insertOne(accessCardObj);
|
|
33100
33318
|
return result.insertedId;
|
|
@@ -33156,10 +33374,6 @@ function UseAccessManagementRepo() {
|
|
|
33156
33374
|
cardNo,
|
|
33157
33375
|
accessType: "Normal" /* NORMAL */,
|
|
33158
33376
|
pin: "123456",
|
|
33159
|
-
qrData: await createQrData({
|
|
33160
|
-
cardNumber: cardNo,
|
|
33161
|
-
facilityCode: parseInt(cardNo.slice(0, 4), 10)
|
|
33162
|
-
}),
|
|
33163
33377
|
startDate: /* @__PURE__ */ new Date(),
|
|
33164
33378
|
endDate,
|
|
33165
33379
|
isActivated: true,
|
|
@@ -33209,10 +33423,6 @@ function UseAccessManagementRepo() {
|
|
|
33209
33423
|
cardNo,
|
|
33210
33424
|
accessType: "Normal" /* NORMAL */,
|
|
33211
33425
|
pin: "123456",
|
|
33212
|
-
qrData: await createQrData({
|
|
33213
|
-
cardNumber: cardNo,
|
|
33214
|
-
facilityCode: parseInt(cardNo.slice(0, 4), 10)
|
|
33215
|
-
}),
|
|
33216
33426
|
startDate: /* @__PURE__ */ new Date(),
|
|
33217
33427
|
endDate,
|
|
33218
33428
|
isActivated: true,
|
|
@@ -34354,7 +34564,6 @@ function UseAccessManagementRepo() {
|
|
|
34354
34564
|
accessType: "Normal" /* NORMAL */,
|
|
34355
34565
|
cardNo: `${facilityCode}${cardNumber}`,
|
|
34356
34566
|
pin,
|
|
34357
|
-
qrData: await createQrData({ cardNumber: `${facilityCode}${cardNumber}` }),
|
|
34358
34567
|
startDate: new Date(item["startDate (format MM/DD/YYYY)"]),
|
|
34359
34568
|
endDate: new Date(item["endDate (format MM/DD/YYYY)"] || endDate),
|
|
34360
34569
|
isActivated: true,
|
|
@@ -41583,6 +41792,17 @@ import {
|
|
|
41583
41792
|
// src/models/occurrence-subject.model.ts
|
|
41584
41793
|
import { ObjectId as ObjectId108 } from "mongodb";
|
|
41585
41794
|
import Joi103 from "joi";
|
|
41795
|
+
var SubjectSort = /* @__PURE__ */ ((SubjectSort2) => {
|
|
41796
|
+
SubjectSort2["CREATED_AT"] = "createdAt";
|
|
41797
|
+
SubjectSort2["NAME"] = "name";
|
|
41798
|
+
SubjectSort2["ID"] = "_id";
|
|
41799
|
+
return SubjectSort2;
|
|
41800
|
+
})(SubjectSort || {});
|
|
41801
|
+
var SubjectOrder = /* @__PURE__ */ ((SubjectOrder2) => {
|
|
41802
|
+
SubjectOrder2["ASC"] = "asc";
|
|
41803
|
+
SubjectOrder2["DESC"] = "desc";
|
|
41804
|
+
return SubjectOrder2;
|
|
41805
|
+
})(SubjectOrder || {});
|
|
41586
41806
|
var schemaOccurrenceSubject = Joi103.object({
|
|
41587
41807
|
site: Joi103.string().hex().required(),
|
|
41588
41808
|
subject: Joi103.string().required(),
|
|
@@ -41691,7 +41911,8 @@ function useOccurrenceSubjectRepo() {
|
|
|
41691
41911
|
}
|
|
41692
41912
|
const baseQuery = {
|
|
41693
41913
|
site,
|
|
41694
|
-
status: { $ne: "deleted" }
|
|
41914
|
+
status: { $ne: "deleted" },
|
|
41915
|
+
...search && { $text: { $search: search } }
|
|
41695
41916
|
};
|
|
41696
41917
|
let query = { ...baseQuery };
|
|
41697
41918
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
@@ -41700,12 +41921,9 @@ function useOccurrenceSubjectRepo() {
|
|
|
41700
41921
|
sort: JSON.stringify(sort),
|
|
41701
41922
|
page,
|
|
41702
41923
|
limit,
|
|
41703
|
-
status: { $ne: "deleted" }
|
|
41924
|
+
status: { $ne: "deleted" },
|
|
41925
|
+
...search && { search }
|
|
41704
41926
|
};
|
|
41705
|
-
if (search) {
|
|
41706
|
-
query.$text = { $search: search };
|
|
41707
|
-
cacheOptions.search = search;
|
|
41708
|
-
}
|
|
41709
41927
|
const cacheKey = makeCacheKey54(namespace_collection, cacheOptions);
|
|
41710
41928
|
const cachedData = await getCache(cacheKey);
|
|
41711
41929
|
if (cachedData) {
|
|
@@ -41784,11 +42002,22 @@ function useOccurrenceSubjectRepo() {
|
|
|
41784
42002
|
} catch (error) {
|
|
41785
42003
|
throw new BadRequestError170("Invalid occurrence subject ID format.");
|
|
41786
42004
|
}
|
|
42005
|
+
const cacheKey = makeCacheKey54(namespace_collection, { _id });
|
|
42006
|
+
const cachedData = await getCache(cacheKey);
|
|
42007
|
+
if (cachedData) {
|
|
42008
|
+
logger147.info(`Cache hit for key: ${cacheKey}`);
|
|
42009
|
+
return cachedData;
|
|
42010
|
+
}
|
|
41787
42011
|
try {
|
|
41788
42012
|
const data = await collection.findOne({ _id }, { session });
|
|
41789
42013
|
if (!data) {
|
|
41790
42014
|
throw new NotFoundError46("Occurrence subject not found.");
|
|
41791
42015
|
}
|
|
42016
|
+
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
42017
|
+
logger147.info(`Cache set for key: ${cacheKey}`);
|
|
42018
|
+
}).catch((err) => {
|
|
42019
|
+
logger147.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
42020
|
+
});
|
|
41792
42021
|
return data;
|
|
41793
42022
|
} catch (error) {
|
|
41794
42023
|
throw error;
|
|
@@ -41975,62 +42204,49 @@ function useOccurrenceEntryController() {
|
|
|
41975
42204
|
getLatestSerialNumber: _getLatestSerialNumber
|
|
41976
42205
|
} = useOccurrenceEntryRepo();
|
|
41977
42206
|
async function add(req, res, next) {
|
|
41978
|
-
const { error, value } = schemaOccurrenceEntry.validate(req.body, {
|
|
41979
|
-
abortEarly: false
|
|
41980
|
-
});
|
|
41981
|
-
if (error) {
|
|
41982
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
41983
|
-
logger148.log({ level: "error", message: messages });
|
|
41984
|
-
next(new BadRequestError171(messages));
|
|
41985
|
-
return;
|
|
41986
|
-
}
|
|
41987
42207
|
try {
|
|
42208
|
+
const { error, value } = schemaOccurrenceEntry.validate(req.body, {
|
|
42209
|
+
abortEarly: false
|
|
42210
|
+
});
|
|
42211
|
+
if (error) {
|
|
42212
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
42213
|
+
logger148.log({ level: "error", message: messages });
|
|
42214
|
+
next(new BadRequestError171(messages));
|
|
42215
|
+
return;
|
|
42216
|
+
}
|
|
41988
42217
|
const data = await _add(value);
|
|
41989
42218
|
res.status(201).json(data);
|
|
41990
42219
|
return;
|
|
41991
|
-
} catch (
|
|
41992
|
-
logger148.log({ level: "error", message:
|
|
41993
|
-
next(
|
|
42220
|
+
} catch (error) {
|
|
42221
|
+
logger148.log({ level: "error", message: error.message });
|
|
42222
|
+
next(error);
|
|
41994
42223
|
return;
|
|
41995
42224
|
}
|
|
41996
42225
|
}
|
|
41997
42226
|
async function getAll(req, res, next) {
|
|
41998
|
-
const allowedFields = ["createdAt", "name"];
|
|
41999
|
-
const allowedOrder = ["asc", "desc"];
|
|
42000
|
-
const validation = Joi104.object({
|
|
42001
|
-
search: Joi104.string().optional().allow("", null),
|
|
42002
|
-
page: Joi104.number().integer().min(1).allow("", null).default(1),
|
|
42003
|
-
limit: Joi104.number().integer().min(1).max(100).allow("", null).default(10),
|
|
42004
|
-
sort: Joi104.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("", ...allowedFields),
|
|
42005
|
-
order: Joi104.string().pattern(/^(asc|desc)(,(asc|desc))*$/).optional().allow("", ...allowedOrder),
|
|
42006
|
-
site: Joi104.string().hex().required(),
|
|
42007
|
-
dailyOccurrenceBookId: Joi104.string().optional().allow("", null)
|
|
42008
|
-
});
|
|
42009
|
-
const query = { ...req.query };
|
|
42010
|
-
const { error } = validation.validate(query, {
|
|
42011
|
-
abortEarly: false
|
|
42012
|
-
});
|
|
42013
|
-
if (error) {
|
|
42014
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
42015
|
-
logger148.log({ level: "error", message: messages });
|
|
42016
|
-
next(new BadRequestError171(messages));
|
|
42017
|
-
return;
|
|
42018
|
-
}
|
|
42019
|
-
const search = req.query.search ?? "";
|
|
42020
|
-
const page = parseInt(req.query.page ?? "1");
|
|
42021
|
-
const limit = parseInt(req.query.limit ?? "10");
|
|
42022
|
-
const site = req.query.site ?? "";
|
|
42023
|
-
const dailyOccurrenceBookId = req.query.dailyOccurrenceBookId ?? "";
|
|
42024
|
-
const sortObj = {};
|
|
42025
|
-
const sortFields = String(req.query.sort).split(",");
|
|
42026
|
-
const sortOrders = String(req.query.order).split(",");
|
|
42027
|
-
sortFields.forEach((field, index) => {
|
|
42028
|
-
if (allowedFields.includes(field)) {
|
|
42029
|
-
const order = sortOrders[index] === "asc" ? 1 : -1;
|
|
42030
|
-
sortObj[field] = order;
|
|
42031
|
-
}
|
|
42032
|
-
});
|
|
42033
42227
|
try {
|
|
42228
|
+
const schema2 = Joi104.object({
|
|
42229
|
+
search: Joi104.string().optional().allow("", null),
|
|
42230
|
+
page: Joi104.number().integer().min(1).allow("", null).default(1),
|
|
42231
|
+
limit: Joi104.number().integer().min(1).max(100).allow("", null).default(10),
|
|
42232
|
+
sort: Joi104.string().valid(...Object.values(EntrySort)).default("_id" /* ID */),
|
|
42233
|
+
order: Joi104.string().valid(...Object.values(EntryOrder)).default("desc" /* DESC */),
|
|
42234
|
+
site: Joi104.string().hex().required(),
|
|
42235
|
+
dailyOccurrenceBookId: Joi104.string().hex().length(24).optional().allow("", null)
|
|
42236
|
+
});
|
|
42237
|
+
const { error, value } = schema2.validate(req.query, {
|
|
42238
|
+
abortEarly: false
|
|
42239
|
+
});
|
|
42240
|
+
if (error) {
|
|
42241
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
42242
|
+
logger148.log({ level: "error", message: messages });
|
|
42243
|
+
next(new BadRequestError171(messages));
|
|
42244
|
+
return;
|
|
42245
|
+
}
|
|
42246
|
+
const { search, page, limit, site, dailyOccurrenceBookId, sort, order } = value;
|
|
42247
|
+
const sortObj = {
|
|
42248
|
+
[sort ? sort : "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
|
|
42249
|
+
};
|
|
42034
42250
|
const data = await _getAll({
|
|
42035
42251
|
search,
|
|
42036
42252
|
page,
|
|
@@ -42041,69 +42257,73 @@ function useOccurrenceEntryController() {
|
|
|
42041
42257
|
});
|
|
42042
42258
|
res.status(200).json(data);
|
|
42043
42259
|
return;
|
|
42044
|
-
} catch (
|
|
42045
|
-
logger148.log({ level: "error", message:
|
|
42046
|
-
next(
|
|
42260
|
+
} catch (error) {
|
|
42261
|
+
logger148.log({ level: "error", message: error.message });
|
|
42262
|
+
next(error);
|
|
42047
42263
|
return;
|
|
42048
42264
|
}
|
|
42049
42265
|
}
|
|
42050
42266
|
async function getOccurrenceEntryById(req, res, next) {
|
|
42051
|
-
const validation = Joi104.string().hex().required();
|
|
42052
|
-
const _id = req.params.id;
|
|
42053
|
-
const { error } = validation.validate(_id);
|
|
42054
|
-
if (error) {
|
|
42055
|
-
logger148.log({ level: "error", message: error.message });
|
|
42056
|
-
next(new BadRequestError171(error.message));
|
|
42057
|
-
return;
|
|
42058
|
-
}
|
|
42059
42267
|
try {
|
|
42268
|
+
const schema2 = Joi104.object({
|
|
42269
|
+
_id: Joi104.string().hex().length(24).required()
|
|
42270
|
+
});
|
|
42271
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
42272
|
+
if (error) {
|
|
42273
|
+
logger148.log({ level: "error", message: error.message });
|
|
42274
|
+
next(new BadRequestError171(error.message));
|
|
42275
|
+
return;
|
|
42276
|
+
}
|
|
42277
|
+
const { _id } = value;
|
|
42060
42278
|
const data = await _getOccurrenceEntryById(_id);
|
|
42061
42279
|
res.status(200).json(data);
|
|
42062
42280
|
return;
|
|
42063
|
-
} catch (
|
|
42064
|
-
logger148.log({ level: "error", message:
|
|
42065
|
-
next(
|
|
42281
|
+
} catch (error) {
|
|
42282
|
+
logger148.log({ level: "error", message: error.message });
|
|
42283
|
+
next(error);
|
|
42066
42284
|
return;
|
|
42067
42285
|
}
|
|
42068
42286
|
}
|
|
42069
42287
|
async function updateOccurrenceEntryById(req, res, next) {
|
|
42070
|
-
const payload = { _id: req.params.id, ...req.body };
|
|
42071
|
-
const { error, value } = schemaUpdateOccurrenceEntry.validate(payload, {
|
|
42072
|
-
abortEarly: false
|
|
42073
|
-
});
|
|
42074
|
-
if (error) {
|
|
42075
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
42076
|
-
logger148.log({ level: "error", message: messages });
|
|
42077
|
-
next(new BadRequestError171(messages));
|
|
42078
|
-
return;
|
|
42079
|
-
}
|
|
42080
|
-
const { _id, ...rest } = value;
|
|
42081
42288
|
try {
|
|
42289
|
+
const payload = { _id: req.params.id, ...req.body };
|
|
42290
|
+
const { error, value } = schemaUpdateOccurrenceEntry.validate(payload, {
|
|
42291
|
+
abortEarly: false
|
|
42292
|
+
});
|
|
42293
|
+
if (error) {
|
|
42294
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
42295
|
+
logger148.log({ level: "error", message: messages });
|
|
42296
|
+
next(new BadRequestError171(messages));
|
|
42297
|
+
return;
|
|
42298
|
+
}
|
|
42299
|
+
const { _id, ...rest } = value;
|
|
42082
42300
|
const result = await _updateOccurrenceEntryById(_id, rest);
|
|
42083
42301
|
res.status(200).json({ message: result });
|
|
42084
42302
|
return;
|
|
42085
|
-
} catch (
|
|
42086
|
-
logger148.log({ level: "error", message:
|
|
42087
|
-
next(
|
|
42303
|
+
} catch (error) {
|
|
42304
|
+
logger148.log({ level: "error", message: error.message });
|
|
42305
|
+
next(error);
|
|
42088
42306
|
return;
|
|
42089
42307
|
}
|
|
42090
42308
|
}
|
|
42091
42309
|
async function deleteOccurrenceEntryById(req, res, next) {
|
|
42092
|
-
const validation = Joi104.string().hex().required();
|
|
42093
|
-
const _id = req.params.id;
|
|
42094
|
-
const { error } = validation.validate(_id);
|
|
42095
|
-
if (error) {
|
|
42096
|
-
logger148.log({ level: "error", message: error.message });
|
|
42097
|
-
next(new BadRequestError171(error.message));
|
|
42098
|
-
return;
|
|
42099
|
-
}
|
|
42100
42310
|
try {
|
|
42311
|
+
const schema2 = Joi104.object({
|
|
42312
|
+
_id: Joi104.string().hex().length(24).required()
|
|
42313
|
+
});
|
|
42314
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
42315
|
+
if (error) {
|
|
42316
|
+
logger148.log({ level: "error", message: error.message });
|
|
42317
|
+
next(new BadRequestError171(error.message));
|
|
42318
|
+
return;
|
|
42319
|
+
}
|
|
42320
|
+
const { _id } = value;
|
|
42101
42321
|
await _deleteOccurrenceEntryById(_id);
|
|
42102
42322
|
res.status(200).json({ message: "Successfully deleted occurrence entry." });
|
|
42103
42323
|
return;
|
|
42104
|
-
} catch (
|
|
42105
|
-
logger148.log({ level: "error", message:
|
|
42106
|
-
next(
|
|
42324
|
+
} catch (error) {
|
|
42325
|
+
logger148.log({ level: "error", message: error.message });
|
|
42326
|
+
next(error);
|
|
42107
42327
|
return;
|
|
42108
42328
|
}
|
|
42109
42329
|
}
|
|
@@ -42749,61 +42969,48 @@ function useOccurrenceSubjectController() {
|
|
|
42749
42969
|
deleteOccurrenceSubjectById: _deleteOccurrenceSubjectById
|
|
42750
42970
|
} = useOccurrenceSubjectRepo();
|
|
42751
42971
|
async function add(req, res, next) {
|
|
42752
|
-
const payload = { ...req.body };
|
|
42753
|
-
const { error } = schemaOccurrenceSubject.validate(payload, {
|
|
42754
|
-
abortEarly: false
|
|
42755
|
-
});
|
|
42756
|
-
if (error) {
|
|
42757
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
42758
|
-
logger151.log({ level: "error", message: messages });
|
|
42759
|
-
next(new BadRequestError174(messages));
|
|
42760
|
-
return;
|
|
42761
|
-
}
|
|
42762
42972
|
try {
|
|
42763
|
-
const
|
|
42973
|
+
const { error, value } = schemaOccurrenceSubject.validate(req.body, {
|
|
42974
|
+
abortEarly: false
|
|
42975
|
+
});
|
|
42976
|
+
if (error) {
|
|
42977
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
42978
|
+
logger151.log({ level: "error", message: messages });
|
|
42979
|
+
next(new BadRequestError174(messages));
|
|
42980
|
+
return;
|
|
42981
|
+
}
|
|
42982
|
+
const data = await _add(value);
|
|
42764
42983
|
res.status(201).json(data);
|
|
42765
42984
|
return;
|
|
42766
|
-
} catch (
|
|
42767
|
-
logger151.log({ level: "error", message:
|
|
42768
|
-
next(
|
|
42985
|
+
} catch (error) {
|
|
42986
|
+
logger151.log({ level: "error", message: error.message });
|
|
42987
|
+
next(error);
|
|
42769
42988
|
return;
|
|
42770
42989
|
}
|
|
42771
42990
|
}
|
|
42772
42991
|
async function getAll(req, res, next) {
|
|
42773
|
-
const allowedFields = ["createdAt", "name"];
|
|
42774
|
-
const allowedOrder = ["asc", "desc"];
|
|
42775
|
-
const validation = Joi107.object({
|
|
42776
|
-
search: Joi107.string().optional().allow("", null),
|
|
42777
|
-
page: Joi107.number().integer().min(1).allow("", null).default(1),
|
|
42778
|
-
limit: Joi107.number().integer().min(1).max(100).allow("", null).default(10),
|
|
42779
|
-
sort: Joi107.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("", ...allowedFields),
|
|
42780
|
-
order: Joi107.string().pattern(/^(asc|desc)(,(asc|desc))*$/).optional().allow("", ...allowedOrder),
|
|
42781
|
-
site: Joi107.string().hex().required()
|
|
42782
|
-
});
|
|
42783
|
-
const query = { ...req.query };
|
|
42784
|
-
const { error } = validation.validate(query, {
|
|
42785
|
-
abortEarly: false
|
|
42786
|
-
});
|
|
42787
|
-
if (error) {
|
|
42788
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
42789
|
-
logger151.log({ level: "error", message: messages });
|
|
42790
|
-
next(new BadRequestError174(messages));
|
|
42791
|
-
return;
|
|
42792
|
-
}
|
|
42793
|
-
const search = req.query.search ?? "";
|
|
42794
|
-
const page = parseInt(req.query.page ?? "1");
|
|
42795
|
-
const limit = parseInt(req.query.limit ?? "10");
|
|
42796
|
-
const site = req.query.site ?? "";
|
|
42797
|
-
const sortObj = {};
|
|
42798
|
-
const sortFields = String(req.query.sort).split(",");
|
|
42799
|
-
const sortOrders = String(req.query.order).split(",");
|
|
42800
|
-
sortFields.forEach((field, index) => {
|
|
42801
|
-
if (allowedFields.includes(field)) {
|
|
42802
|
-
const order = sortOrders[index] === "asc" ? 1 : -1;
|
|
42803
|
-
sortObj[field] = order;
|
|
42804
|
-
}
|
|
42805
|
-
});
|
|
42806
42992
|
try {
|
|
42993
|
+
const validation = Joi107.object({
|
|
42994
|
+
search: Joi107.string().optional().allow("", null),
|
|
42995
|
+
page: Joi107.number().integer().min(1).allow("", null).default(1),
|
|
42996
|
+
limit: Joi107.number().integer().min(1).max(100).allow("", null).default(10),
|
|
42997
|
+
sort: Joi107.string().valid(...Object.values(SubjectSort)).default("_id" /* ID */),
|
|
42998
|
+
order: Joi107.string().valid(...Object.values(SubjectOrder)).default("desc" /* DESC */),
|
|
42999
|
+
site: Joi107.string().hex().length(24).required()
|
|
43000
|
+
});
|
|
43001
|
+
const { error, value } = validation.validate(req.query, {
|
|
43002
|
+
abortEarly: false
|
|
43003
|
+
});
|
|
43004
|
+
if (error) {
|
|
43005
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
43006
|
+
logger151.log({ level: "error", message: messages });
|
|
43007
|
+
next(new BadRequestError174(messages));
|
|
43008
|
+
return;
|
|
43009
|
+
}
|
|
43010
|
+
const { search, page, limit, site, sort, order } = value;
|
|
43011
|
+
const sortObj = {
|
|
43012
|
+
[sort ? sort : "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
|
|
43013
|
+
};
|
|
42807
43014
|
const data = await _getAll({
|
|
42808
43015
|
search,
|
|
42809
43016
|
page,
|
|
@@ -42813,50 +43020,54 @@ function useOccurrenceSubjectController() {
|
|
|
42813
43020
|
});
|
|
42814
43021
|
res.status(200).json(data);
|
|
42815
43022
|
return;
|
|
42816
|
-
} catch (
|
|
42817
|
-
logger151.log({ level: "error", message:
|
|
42818
|
-
next(
|
|
43023
|
+
} catch (error) {
|
|
43024
|
+
logger151.log({ level: "error", message: error.message });
|
|
43025
|
+
next(error);
|
|
42819
43026
|
return;
|
|
42820
43027
|
}
|
|
42821
43028
|
}
|
|
42822
43029
|
async function getOccurrenceSubjectById(req, res, next) {
|
|
42823
|
-
const validation = Joi107.string().hex().required();
|
|
42824
|
-
const _id = req.params.id;
|
|
42825
|
-
const { error } = validation.validate(_id);
|
|
42826
|
-
if (error) {
|
|
42827
|
-
logger151.log({ level: "error", message: error.message });
|
|
42828
|
-
next(new BadRequestError174(error.message));
|
|
42829
|
-
return;
|
|
42830
|
-
}
|
|
42831
43030
|
try {
|
|
43031
|
+
const schema2 = Joi107.object({
|
|
43032
|
+
_id: Joi107.string().hex().length(24).required()
|
|
43033
|
+
});
|
|
43034
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
43035
|
+
if (error) {
|
|
43036
|
+
logger151.log({ level: "error", message: error.message });
|
|
43037
|
+
next(new BadRequestError174(error.message));
|
|
43038
|
+
return;
|
|
43039
|
+
}
|
|
43040
|
+
const { _id } = value;
|
|
42832
43041
|
const data = await _getOccurrenceSubjectById(_id);
|
|
42833
43042
|
res.status(200).json(data);
|
|
42834
43043
|
return;
|
|
42835
|
-
} catch (
|
|
42836
|
-
logger151.log({ level: "error", message:
|
|
42837
|
-
next(
|
|
43044
|
+
} catch (error) {
|
|
43045
|
+
logger151.log({ level: "error", message: error.message });
|
|
43046
|
+
next(error);
|
|
42838
43047
|
return;
|
|
42839
43048
|
}
|
|
42840
43049
|
}
|
|
42841
43050
|
async function updateOccurrenceSubjectById(req, res, next) {
|
|
42842
|
-
const _id = req.params.id;
|
|
42843
|
-
const payload = { _id, ...req.body };
|
|
42844
|
-
const { error } = schemaUpdateOccurrenceSubject.validate(payload, {
|
|
42845
|
-
abortEarly: false
|
|
42846
|
-
});
|
|
42847
|
-
if (error) {
|
|
42848
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
42849
|
-
logger151.log({ level: "error", message: messages });
|
|
42850
|
-
next(new BadRequestError174(messages));
|
|
42851
|
-
return;
|
|
42852
|
-
}
|
|
42853
43051
|
try {
|
|
42854
|
-
const
|
|
43052
|
+
const { error, value } = schemaUpdateOccurrenceSubject.validate(
|
|
43053
|
+
{ _id: req.params.id, ...req.body },
|
|
43054
|
+
{
|
|
43055
|
+
abortEarly: false
|
|
43056
|
+
}
|
|
43057
|
+
);
|
|
43058
|
+
if (error) {
|
|
43059
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
43060
|
+
logger151.log({ level: "error", message: messages });
|
|
43061
|
+
next(new BadRequestError174(messages));
|
|
43062
|
+
return;
|
|
43063
|
+
}
|
|
43064
|
+
const { _id, ...rest } = value;
|
|
43065
|
+
const result = await _updateOccurrenceSubjectById(_id, rest);
|
|
42855
43066
|
res.status(200).json({ message: result });
|
|
42856
43067
|
return;
|
|
42857
|
-
} catch (
|
|
42858
|
-
logger151.log({ level: "error", message:
|
|
42859
|
-
next(
|
|
43068
|
+
} catch (error) {
|
|
43069
|
+
logger151.log({ level: "error", message: error.message });
|
|
43070
|
+
next(error);
|
|
42860
43071
|
return;
|
|
42861
43072
|
}
|
|
42862
43073
|
}
|
|
@@ -50182,6 +50393,8 @@ export {
|
|
|
50182
50393
|
EAccessCardTypes,
|
|
50183
50394
|
EAccessCardUserTypes,
|
|
50184
50395
|
EmailSender,
|
|
50396
|
+
EntryOrder,
|
|
50397
|
+
EntrySort,
|
|
50185
50398
|
FacilitySort,
|
|
50186
50399
|
FacilityStatus,
|
|
50187
50400
|
GuestSort,
|
|
@@ -50263,6 +50476,8 @@ export {
|
|
|
50263
50476
|
SortFields,
|
|
50264
50477
|
SortOrder,
|
|
50265
50478
|
Status,
|
|
50479
|
+
SubjectOrder,
|
|
50480
|
+
SubjectSort,
|
|
50266
50481
|
SubscriptionType,
|
|
50267
50482
|
UseAccessManagementRepo,
|
|
50268
50483
|
UserStatus,
|
|
@@ -50318,6 +50533,7 @@ export {
|
|
|
50318
50533
|
robotSchema,
|
|
50319
50534
|
schema,
|
|
50320
50535
|
schemaApprovedBy,
|
|
50536
|
+
schemaApprover,
|
|
50321
50537
|
schemaBilling,
|
|
50322
50538
|
schemaBillingConfiguration,
|
|
50323
50539
|
schemaBillingItem,
|