@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.js
CHANGED
|
@@ -44,6 +44,8 @@ __export(src_exports, {
|
|
|
44
44
|
EAccessCardTypes: () => EAccessCardTypes,
|
|
45
45
|
EAccessCardUserTypes: () => EAccessCardUserTypes,
|
|
46
46
|
EmailSender: () => EmailSender,
|
|
47
|
+
EntryOrder: () => EntryOrder,
|
|
48
|
+
EntrySort: () => EntrySort,
|
|
47
49
|
FacilitySort: () => FacilitySort,
|
|
48
50
|
FacilityStatus: () => FacilityStatus,
|
|
49
51
|
GuestSort: () => GuestSort,
|
|
@@ -125,6 +127,8 @@ __export(src_exports, {
|
|
|
125
127
|
SortFields: () => SortFields,
|
|
126
128
|
SortOrder: () => SortOrder,
|
|
127
129
|
Status: () => Status,
|
|
130
|
+
SubjectOrder: () => SubjectOrder,
|
|
131
|
+
SubjectSort: () => SubjectSort,
|
|
128
132
|
SubscriptionType: () => SubscriptionType,
|
|
129
133
|
UseAccessManagementRepo: () => UseAccessManagementRepo,
|
|
130
134
|
UserStatus: () => UserStatus,
|
|
@@ -180,6 +184,7 @@ __export(src_exports, {
|
|
|
180
184
|
robotSchema: () => robotSchema,
|
|
181
185
|
schema: () => schema,
|
|
182
186
|
schemaApprovedBy: () => schemaApprovedBy,
|
|
187
|
+
schemaApprover: () => schemaApprover,
|
|
183
188
|
schemaBilling: () => schemaBilling,
|
|
184
189
|
schemaBillingConfiguration: () => schemaBillingConfiguration,
|
|
185
190
|
schemaBillingItem: () => schemaBillingItem,
|
|
@@ -1832,6 +1837,17 @@ var import_node_server_utils8 = require("@7365admin1/node-server-utils");
|
|
|
1832
1837
|
// src/models/occurrence-entry.model.ts
|
|
1833
1838
|
var import_mongodb6 = require("mongodb");
|
|
1834
1839
|
var import_joi5 = __toESM(require("joi"));
|
|
1840
|
+
var EntrySort = /* @__PURE__ */ ((EntrySort2) => {
|
|
1841
|
+
EntrySort2["CREATED_AT"] = "createdAt";
|
|
1842
|
+
EntrySort2["NAME"] = "name";
|
|
1843
|
+
EntrySort2["ID"] = "_id";
|
|
1844
|
+
return EntrySort2;
|
|
1845
|
+
})(EntrySort || {});
|
|
1846
|
+
var EntryOrder = /* @__PURE__ */ ((EntryOrder2) => {
|
|
1847
|
+
EntryOrder2["ASC"] = "asc";
|
|
1848
|
+
EntryOrder2["DESC"] = "desc";
|
|
1849
|
+
return EntryOrder2;
|
|
1850
|
+
})(EntryOrder || {});
|
|
1835
1851
|
var schemaOccurrenceEntry = import_joi5.default.object({
|
|
1836
1852
|
site: import_joi5.default.string().hex().length(24).required(),
|
|
1837
1853
|
dailyOccurrenceBookId: import_joi5.default.string().hex().optional().allow(null, ""),
|
|
@@ -5156,7 +5172,10 @@ function useSiteRepo() {
|
|
|
5156
5172
|
throw error;
|
|
5157
5173
|
}
|
|
5158
5174
|
}
|
|
5159
|
-
async function siteInformation({
|
|
5175
|
+
async function siteInformation({
|
|
5176
|
+
id,
|
|
5177
|
+
payload
|
|
5178
|
+
}) {
|
|
5160
5179
|
try {
|
|
5161
5180
|
const siteId = new import_mongodb17.ObjectId(id);
|
|
5162
5181
|
const res = await collection.updateOne(
|
|
@@ -5176,6 +5195,48 @@ function useSiteRepo() {
|
|
|
5176
5195
|
throw error;
|
|
5177
5196
|
}
|
|
5178
5197
|
}
|
|
5198
|
+
async function getAllSitesForResidentCreation({
|
|
5199
|
+
search = "",
|
|
5200
|
+
page = 1,
|
|
5201
|
+
limit = 10
|
|
5202
|
+
}) {
|
|
5203
|
+
page = page > 0 ? page - 1 : 0;
|
|
5204
|
+
const query = {
|
|
5205
|
+
status: { $ne: "deleted" }
|
|
5206
|
+
};
|
|
5207
|
+
const cacheOptions = {
|
|
5208
|
+
status: { $ne: "deleted" },
|
|
5209
|
+
page,
|
|
5210
|
+
limit
|
|
5211
|
+
};
|
|
5212
|
+
if (search) {
|
|
5213
|
+
query.$or = [{ name: { $regex: search, $options: "i" } }];
|
|
5214
|
+
cacheOptions.search = search;
|
|
5215
|
+
}
|
|
5216
|
+
const cacheKey = (0, import_node_server_utils19.makeCacheKey)(namespace_collection, cacheOptions);
|
|
5217
|
+
const cachedData = await getCache(cacheKey);
|
|
5218
|
+
if (cachedData) {
|
|
5219
|
+
import_node_server_utils19.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
5220
|
+
return cachedData;
|
|
5221
|
+
}
|
|
5222
|
+
try {
|
|
5223
|
+
const items = await collection.aggregate([
|
|
5224
|
+
{ $match: query },
|
|
5225
|
+
{ $skip: page * limit },
|
|
5226
|
+
{ $limit: limit }
|
|
5227
|
+
]).toArray();
|
|
5228
|
+
const length = await collection.countDocuments(query);
|
|
5229
|
+
const data = (0, import_node_server_utils19.paginate)(items, page, limit, length);
|
|
5230
|
+
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
5231
|
+
import_node_server_utils19.logger.info(`Cache set for key: ${cacheKey}`);
|
|
5232
|
+
}).catch((err) => {
|
|
5233
|
+
import_node_server_utils19.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
5234
|
+
});
|
|
5235
|
+
return data;
|
|
5236
|
+
} catch (error) {
|
|
5237
|
+
throw error;
|
|
5238
|
+
}
|
|
5239
|
+
}
|
|
5179
5240
|
return {
|
|
5180
5241
|
createIndexes,
|
|
5181
5242
|
createSite,
|
|
@@ -5190,7 +5251,8 @@ function useSiteRepo() {
|
|
|
5190
5251
|
updateSiteIncidentCounter,
|
|
5191
5252
|
updateSiteById,
|
|
5192
5253
|
getAllSitesUnpaginated,
|
|
5193
|
-
siteInformation
|
|
5254
|
+
siteInformation,
|
|
5255
|
+
getAllSitesForResidentCreation
|
|
5194
5256
|
};
|
|
5195
5257
|
}
|
|
5196
5258
|
|
|
@@ -12296,7 +12358,7 @@ function useServiceProviderController() {
|
|
|
12296
12358
|
const validation = import_joi30.default.object({
|
|
12297
12359
|
search: import_joi30.default.string().optional().allow("", null),
|
|
12298
12360
|
page: import_joi30.default.number().integer().min(1).allow("", null).default(1),
|
|
12299
|
-
limit: import_joi30.default.number().integer().min(1).max(
|
|
12361
|
+
limit: import_joi30.default.number().integer().min(1).max(1e3).allow("", null).default(10),
|
|
12300
12362
|
orgId: import_joi30.default.string().hex().optional().allow("", null),
|
|
12301
12363
|
siteId: import_joi30.default.string().hex().optional().allow("", null),
|
|
12302
12364
|
serviceProviderOrgId: import_joi30.default.string().hex().optional().allow("", null),
|
|
@@ -13473,6 +13535,10 @@ var schemaFiles = import_joi35.default.object({
|
|
|
13473
13535
|
id: import_joi35.default.string().hex().required(),
|
|
13474
13536
|
name: import_joi35.default.string().optional().allow(null, "")
|
|
13475
13537
|
});
|
|
13538
|
+
var schemaApprover = import_joi35.default.object({
|
|
13539
|
+
id: import_joi35.default.string().hex().required(),
|
|
13540
|
+
name: import_joi35.default.string().optional().allow(null, "")
|
|
13541
|
+
});
|
|
13476
13542
|
var schemaPerson = import_joi35.default.object({
|
|
13477
13543
|
_id: import_joi35.default.string().hex().optional().allow("", null),
|
|
13478
13544
|
user: import_joi35.default.string().hex().length(24).optional().allow(null, ""),
|
|
@@ -13496,7 +13562,9 @@ var schemaPerson = import_joi35.default.object({
|
|
|
13496
13562
|
isOwner: import_joi35.default.boolean().required(),
|
|
13497
13563
|
files: import_joi35.default.array().items(schemaFiles).optional().allow(null),
|
|
13498
13564
|
password: import_joi35.default.string().optional().allow(null, ""),
|
|
13499
|
-
plateNumber: import_joi35.default.string().optional().allow(null, "")
|
|
13565
|
+
plateNumber: import_joi35.default.string().optional().allow(null, ""),
|
|
13566
|
+
platform: import_joi35.default.string().valid("web", "mobile").optional().allow(null, ""),
|
|
13567
|
+
approvedBy: schemaApprover.optional().allow(null, "")
|
|
13500
13568
|
});
|
|
13501
13569
|
var schemaUpdatePerson = import_joi35.default.object({
|
|
13502
13570
|
_id: import_joi35.default.string().hex().required(),
|
|
@@ -13517,12 +13585,14 @@ var schemaUpdatePerson = import_joi35.default.object({
|
|
|
13517
13585
|
isOwner: import_joi35.default.boolean().optional().allow(null, ""),
|
|
13518
13586
|
files: import_joi35.default.array().items(schemaFiles).optional().allow(null),
|
|
13519
13587
|
password: import_joi35.default.string().optional().allow(null, ""),
|
|
13520
|
-
plateNumber: import_joi35.default.string().optional().allow(null, "")
|
|
13588
|
+
plateNumber: import_joi35.default.string().optional().allow(null, ""),
|
|
13589
|
+
platform: import_joi35.default.string().valid("web", "mobile").optional().allow(null, ""),
|
|
13590
|
+
approvedBy: schemaApprover.optional().allow(null, "")
|
|
13521
13591
|
});
|
|
13522
13592
|
function MPerson(value) {
|
|
13523
13593
|
const { error } = schemaPerson.validate(value);
|
|
13524
13594
|
if (error) {
|
|
13525
|
-
throw new
|
|
13595
|
+
throw new import_node_server_utils68.BadRequestError(error.details[0].message);
|
|
13526
13596
|
}
|
|
13527
13597
|
if (value._id && typeof value._id === "string") {
|
|
13528
13598
|
try {
|
|
@@ -13588,6 +13658,8 @@ function MPerson(value) {
|
|
|
13588
13658
|
isOwner: value.isOwner ?? false,
|
|
13589
13659
|
files: value.files ?? [],
|
|
13590
13660
|
plateNumber: value.plateNumber ?? "",
|
|
13661
|
+
platForm: value.platform ?? "",
|
|
13662
|
+
approvedBy: value.approvedBy ?? { id: "", name: "" },
|
|
13591
13663
|
createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
13592
13664
|
updatedAt: value.updatedAt,
|
|
13593
13665
|
deletedAt: value.deletedAt
|
|
@@ -13626,8 +13698,8 @@ var schemaVisitorTransaction = import_joi36.default.object({
|
|
|
13626
13698
|
contact: import_joi36.default.string().optional().allow(null, ""),
|
|
13627
13699
|
plateNumber: import_joi36.default.string().optional().allow(null, ""),
|
|
13628
13700
|
recNo: import_joi36.default.string().optional().allow(null, ""),
|
|
13629
|
-
checkIn: import_joi36.default.date().optional().allow(null
|
|
13630
|
-
checkOut: import_joi36.default.date().optional().allow(null
|
|
13701
|
+
checkIn: import_joi36.default.date().iso().optional().allow(null),
|
|
13702
|
+
checkOut: import_joi36.default.date().iso().optional().allow(null),
|
|
13631
13703
|
deliveryType: import_joi36.default.string().optional().allow(null, ""),
|
|
13632
13704
|
status: import_joi36.default.string().optional().valid(...Object.values(VisitorStatus)).default("registered" /* REGISTERED */),
|
|
13633
13705
|
remarks: import_joi36.default.string().optional().allow(null, ""),
|
|
@@ -13691,8 +13763,8 @@ var schemaUpdateVisTrans = import_joi36.default.object({
|
|
|
13691
13763
|
contact: import_joi36.default.string().optional().allow(null, ""),
|
|
13692
13764
|
plateNumber: import_joi36.default.string().optional().allow(null, ""),
|
|
13693
13765
|
recNo: import_joi36.default.string().optional().allow(null, ""),
|
|
13694
|
-
checkIn: import_joi36.default.date().optional().allow(null
|
|
13695
|
-
checkOut: import_joi36.default.date().optional().allow(null
|
|
13766
|
+
checkIn: import_joi36.default.date().iso().optional().allow(null),
|
|
13767
|
+
checkOut: import_joi36.default.date().iso().optional().allow(null),
|
|
13696
13768
|
deliveryType: import_joi36.default.string().optional().allow(null, ""),
|
|
13697
13769
|
status: import_joi36.default.string().optional().allow(null, ""),
|
|
13698
13770
|
remarks: import_joi36.default.string().optional().allow(null, ""),
|
|
@@ -15269,7 +15341,7 @@ function usePersonRepo() {
|
|
|
15269
15341
|
]
|
|
15270
15342
|
} : void 0;
|
|
15271
15343
|
const query = {
|
|
15272
|
-
status,
|
|
15344
|
+
...status && status !== "all" ? { status } : { status: { $nin: ["deleted", "rejected"] } },
|
|
15273
15345
|
...start && { start },
|
|
15274
15346
|
...end,
|
|
15275
15347
|
...search && {
|
|
@@ -15307,12 +15379,29 @@ function usePersonRepo() {
|
|
|
15307
15379
|
return cachedData;
|
|
15308
15380
|
}
|
|
15309
15381
|
try {
|
|
15310
|
-
const basePipeline = [
|
|
15311
|
-
|
|
15312
|
-
|
|
15313
|
-
|
|
15314
|
-
|
|
15315
|
-
|
|
15382
|
+
const basePipeline = [{ $match: query }];
|
|
15383
|
+
if (status && status == "all") {
|
|
15384
|
+
basePipeline.push(
|
|
15385
|
+
{
|
|
15386
|
+
$addFields: {
|
|
15387
|
+
sortPriority: {
|
|
15388
|
+
$cond: [{ $eq: ["$status", "pending"] }, 1, 2]
|
|
15389
|
+
}
|
|
15390
|
+
}
|
|
15391
|
+
},
|
|
15392
|
+
{
|
|
15393
|
+
$sort: {
|
|
15394
|
+
sortPriority: 1,
|
|
15395
|
+
...sort
|
|
15396
|
+
}
|
|
15397
|
+
}
|
|
15398
|
+
);
|
|
15399
|
+
} else {
|
|
15400
|
+
basePipeline.push({
|
|
15401
|
+
$sort: sort
|
|
15402
|
+
});
|
|
15403
|
+
}
|
|
15404
|
+
basePipeline.push({ $skip: page * limit }, { $limit: limit });
|
|
15316
15405
|
const [items, countResult] = await Promise.all([
|
|
15317
15406
|
collection.aggregate(basePipeline, { session }).toArray(),
|
|
15318
15407
|
collection.aggregate([{ $match: query }, { $count: "total" }], { session }).toArray()
|
|
@@ -15761,6 +15850,37 @@ function usePersonRepo() {
|
|
|
15761
15850
|
}
|
|
15762
15851
|
}
|
|
15763
15852
|
}
|
|
15853
|
+
async function reviewResidentPerson(_id, value, session) {
|
|
15854
|
+
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
15855
|
+
try {
|
|
15856
|
+
_id = new import_mongodb44.ObjectId(_id);
|
|
15857
|
+
} catch (error) {
|
|
15858
|
+
throw new import_node_server_utils72.BadRequestError("Invalid ID format.");
|
|
15859
|
+
}
|
|
15860
|
+
try {
|
|
15861
|
+
const res = await collection.updateOne(
|
|
15862
|
+
{ _id },
|
|
15863
|
+
{ $set: value },
|
|
15864
|
+
{ session }
|
|
15865
|
+
);
|
|
15866
|
+
if (res.modifiedCount === 0) {
|
|
15867
|
+
throw new import_node_server_utils72.InternalServerError(`Unable to ${value.status} person.`);
|
|
15868
|
+
}
|
|
15869
|
+
delNamespace().then(() => {
|
|
15870
|
+
import_node_server_utils72.logger.info(
|
|
15871
|
+
`Cache cleared for namespace: ${site_people_namespace_collection}`
|
|
15872
|
+
);
|
|
15873
|
+
}).catch((err) => {
|
|
15874
|
+
import_node_server_utils72.logger.error(
|
|
15875
|
+
`Failed to clear cache for namespace: ${site_people_namespace_collection}`,
|
|
15876
|
+
err
|
|
15877
|
+
);
|
|
15878
|
+
});
|
|
15879
|
+
return res;
|
|
15880
|
+
} catch (error) {
|
|
15881
|
+
throw error;
|
|
15882
|
+
}
|
|
15883
|
+
}
|
|
15764
15884
|
return {
|
|
15765
15885
|
add,
|
|
15766
15886
|
getAll,
|
|
@@ -15778,7 +15898,8 @@ function usePersonRepo() {
|
|
|
15778
15898
|
getPeopleByNRIC,
|
|
15779
15899
|
pushVehicleById,
|
|
15780
15900
|
pullVehicleByRecNo,
|
|
15781
|
-
getByUserId
|
|
15901
|
+
getByUserId,
|
|
15902
|
+
reviewResidentPerson
|
|
15782
15903
|
};
|
|
15783
15904
|
}
|
|
15784
15905
|
|
|
@@ -18082,7 +18203,8 @@ function useSiteController() {
|
|
|
18082
18203
|
getSites: _getSites,
|
|
18083
18204
|
getSiteById: _getSiteById,
|
|
18084
18205
|
updateSiteBlock: _updateSiteBlock,
|
|
18085
|
-
deleteSite: _deleteSite
|
|
18206
|
+
deleteSite: _deleteSite,
|
|
18207
|
+
getAllSitesForResidentCreation: _getAllSitesForResidentCreation
|
|
18086
18208
|
} = useSiteRepo();
|
|
18087
18209
|
const { updateGuardPostById, siteInformation: _siteInformation } = useSiteService();
|
|
18088
18210
|
async function createSite(req, res, next) {
|
|
@@ -18267,14 +18389,13 @@ function useSiteController() {
|
|
|
18267
18389
|
id: import_joi42.default.string().hex().required(),
|
|
18268
18390
|
bgImage: import_joi42.default.string().optional().allow("", null),
|
|
18269
18391
|
description: import_joi42.default.string().optional().allow("", null),
|
|
18270
|
-
docs: import_joi42.default.array().items(
|
|
18271
|
-
|
|
18272
|
-
|
|
18273
|
-
|
|
18274
|
-
|
|
18275
|
-
|
|
18276
|
-
|
|
18277
|
-
);
|
|
18392
|
+
docs: import_joi42.default.array().items(
|
|
18393
|
+
import_joi42.default.object({
|
|
18394
|
+
id: import_joi42.default.string().hex().optional().allow("", null),
|
|
18395
|
+
name: import_joi42.default.string().optional().allow("", null)
|
|
18396
|
+
})
|
|
18397
|
+
).optional().allow("", null)
|
|
18398
|
+
}).validate({ id, ...payload }, { abortEarly: false });
|
|
18278
18399
|
if (error) {
|
|
18279
18400
|
import_node_server_utils78.logger.log({ level: "error", message: error.message });
|
|
18280
18401
|
next(new import_node_server_utils78.BadRequestError(error.message));
|
|
@@ -18290,6 +18411,36 @@ function useSiteController() {
|
|
|
18290
18411
|
return;
|
|
18291
18412
|
}
|
|
18292
18413
|
}
|
|
18414
|
+
async function getAllSitesForResidentCreation(req, res, next) {
|
|
18415
|
+
const validation = import_joi42.default.object({
|
|
18416
|
+
search: import_joi42.default.string().optional().allow("", null),
|
|
18417
|
+
page: import_joi42.default.number().integer().min(1).allow("", null).default(1),
|
|
18418
|
+
limit: import_joi42.default.number().integer().min(1).max(100).allow("", null).default(10)
|
|
18419
|
+
});
|
|
18420
|
+
const query = { ...req.query };
|
|
18421
|
+
const { error } = validation.validate(query);
|
|
18422
|
+
if (error) {
|
|
18423
|
+
import_node_server_utils78.logger.log({ level: "error", message: error.message });
|
|
18424
|
+
next(new import_node_server_utils78.BadRequestError(error.message));
|
|
18425
|
+
return;
|
|
18426
|
+
}
|
|
18427
|
+
const search = req.query.search ?? "";
|
|
18428
|
+
const page = parseInt(req.query.page ?? "1");
|
|
18429
|
+
const limit = parseInt(req.query.limit ?? "10");
|
|
18430
|
+
try {
|
|
18431
|
+
const data = await _getAllSitesForResidentCreation({
|
|
18432
|
+
search,
|
|
18433
|
+
page,
|
|
18434
|
+
limit
|
|
18435
|
+
});
|
|
18436
|
+
res.json(data);
|
|
18437
|
+
return;
|
|
18438
|
+
} catch (error2) {
|
|
18439
|
+
import_node_server_utils78.logger.log({ level: "error", message: error2.message });
|
|
18440
|
+
next(error2);
|
|
18441
|
+
return;
|
|
18442
|
+
}
|
|
18443
|
+
}
|
|
18293
18444
|
return {
|
|
18294
18445
|
createSite,
|
|
18295
18446
|
getSites,
|
|
@@ -18298,7 +18449,8 @@ function useSiteController() {
|
|
|
18298
18449
|
deleteSite,
|
|
18299
18450
|
updateById,
|
|
18300
18451
|
updateGuardPostsById,
|
|
18301
|
-
siteInformation
|
|
18452
|
+
siteInformation,
|
|
18453
|
+
getAllSitesForResidentCreation
|
|
18302
18454
|
};
|
|
18303
18455
|
}
|
|
18304
18456
|
|
|
@@ -22574,6 +22726,7 @@ function useVisitorTransactionService() {
|
|
|
22574
22726
|
const { getAllSites: _getAllSites } = useSiteRepo();
|
|
22575
22727
|
const { getByUserId: _getByUserId } = usePersonRepo();
|
|
22576
22728
|
const { add: addVehicle } = useVehicleRepo();
|
|
22729
|
+
const { getById: _getUnitById } = useBuildingUnitRepo();
|
|
22577
22730
|
function extractKeyId(item) {
|
|
22578
22731
|
if (!item)
|
|
22579
22732
|
return null;
|
|
@@ -22658,6 +22811,10 @@ function useVisitorTransactionService() {
|
|
|
22658
22811
|
_getSiteById(value.site)
|
|
22659
22812
|
]);
|
|
22660
22813
|
}
|
|
22814
|
+
if (!value.unitName && value.unit) {
|
|
22815
|
+
const unit = await _getUnitById(value.unit);
|
|
22816
|
+
value.unitName = unit?.name;
|
|
22817
|
+
}
|
|
22661
22818
|
const hourExpiration = site?.dahuaTimeExpiration ? site?.dahuaTimeExpiration : 24 * 60;
|
|
22662
22819
|
const end = value.checkOut ? new Date(value.checkOut) : new Date(start.getTime() + hourExpiration * 60 * 1e3);
|
|
22663
22820
|
const startDahuaDate = formatDahuaDate(start);
|
|
@@ -22952,6 +23109,14 @@ function useVisitorTransactionService() {
|
|
|
22952
23109
|
}
|
|
22953
23110
|
value.passKeys = keptPassKeys;
|
|
22954
23111
|
}
|
|
23112
|
+
if (value.checkIn) {
|
|
23113
|
+
const parsed = new Date(value.checkIn);
|
|
23114
|
+
value.checkIn = isNaN(parsed.getTime()) ? null : parsed;
|
|
23115
|
+
}
|
|
23116
|
+
if (value.checkOut) {
|
|
23117
|
+
const parsed = new Date(value.checkOut);
|
|
23118
|
+
value.checkOut = isNaN(parsed.getTime()) ? null : parsed;
|
|
23119
|
+
}
|
|
22955
23120
|
await _updateVisitorTansactionById(id, value, session);
|
|
22956
23121
|
await session?.commitTransaction();
|
|
22957
23122
|
return "Successfully updated visitor transaction.";
|
|
@@ -23904,13 +24069,15 @@ function usePersonService() {
|
|
|
23904
24069
|
add: _add,
|
|
23905
24070
|
getById: _getById,
|
|
23906
24071
|
updateById: _updateById,
|
|
23907
|
-
getByUserId: _getByUserId
|
|
24072
|
+
getByUserId: _getByUserId,
|
|
24073
|
+
reviewResidentPerson: _reviewResidentPerson
|
|
23908
24074
|
} = usePersonRepo();
|
|
23909
24075
|
const { addPlateNumber: _addPlateNumber } = useDahuaService();
|
|
23910
24076
|
const {
|
|
23911
24077
|
createUser: addUser,
|
|
23912
24078
|
getUserByEmail,
|
|
23913
|
-
updateUserFieldById: _updateUserFieldById
|
|
24079
|
+
updateUserFieldById: _updateUserFieldById,
|
|
24080
|
+
getUserById
|
|
23914
24081
|
} = useUserRepo();
|
|
23915
24082
|
const { add: addMember } = useMemberRepo();
|
|
23916
24083
|
const { getById: _getUnitById, updateById: updateUnitById } = useBuildingUnitRepo();
|
|
@@ -23951,10 +24118,11 @@ function usePersonService() {
|
|
|
23951
24118
|
email: value.email,
|
|
23952
24119
|
password: hashedPassword,
|
|
23953
24120
|
name: value.name,
|
|
24121
|
+
status: value.platform == "mobile" ? "deleted" : "active",
|
|
23954
24122
|
defaultOrg: value.org?.toString() || ""
|
|
23955
24123
|
};
|
|
23956
24124
|
const userId = await addUser(user, session);
|
|
23957
|
-
value.user = userId;
|
|
24125
|
+
value.user = userId.toString();
|
|
23958
24126
|
let org = null;
|
|
23959
24127
|
if (userId) {
|
|
23960
24128
|
if (value?.org) {
|
|
@@ -24067,9 +24235,31 @@ function usePersonService() {
|
|
|
24067
24235
|
}
|
|
24068
24236
|
return { start: "", end: "" };
|
|
24069
24237
|
}
|
|
24238
|
+
async function reviewResidentPerson(id, value) {
|
|
24239
|
+
const session = import_node_server_utils107.useAtlas.getClient()?.startSession();
|
|
24240
|
+
session?.startTransaction();
|
|
24241
|
+
try {
|
|
24242
|
+
if (value.approvedBy) {
|
|
24243
|
+
const approvedBy = await getUserById(value.approvedBy.id);
|
|
24244
|
+
if (!approvedBy || !approvedBy.name)
|
|
24245
|
+
throw new import_node_server_utils107.BadRequestError("Created by not found.");
|
|
24246
|
+
value.approvedBy.name = approvedBy.name;
|
|
24247
|
+
value.approvedBy.id = approvedBy._id;
|
|
24248
|
+
}
|
|
24249
|
+
await _reviewResidentPerson(id, value, session);
|
|
24250
|
+
await session?.commitTransaction();
|
|
24251
|
+
return `Successfully ${value.status} person`;
|
|
24252
|
+
} catch (error) {
|
|
24253
|
+
await session?.abortTransaction();
|
|
24254
|
+
throw error;
|
|
24255
|
+
} finally {
|
|
24256
|
+
session?.endSession();
|
|
24257
|
+
}
|
|
24258
|
+
}
|
|
24070
24259
|
return {
|
|
24071
24260
|
add,
|
|
24072
|
-
updateById
|
|
24261
|
+
updateById,
|
|
24262
|
+
reviewResidentPerson
|
|
24073
24263
|
};
|
|
24074
24264
|
}
|
|
24075
24265
|
|
|
@@ -24086,7 +24276,11 @@ function usePersonController() {
|
|
|
24086
24276
|
getPeopleByNRIC: _getPeopleByNRIC,
|
|
24087
24277
|
getByUserId: _getByUserId
|
|
24088
24278
|
} = usePersonRepo();
|
|
24089
|
-
const {
|
|
24279
|
+
const {
|
|
24280
|
+
add: _add,
|
|
24281
|
+
updateById: _updateById,
|
|
24282
|
+
reviewResidentPerson: _reviewResidentPerson
|
|
24283
|
+
} = usePersonService();
|
|
24090
24284
|
async function add(req, res, next) {
|
|
24091
24285
|
const payload = { ...req.body };
|
|
24092
24286
|
const { error } = schemaPerson.validate(payload, {
|
|
@@ -24401,6 +24595,38 @@ function usePersonController() {
|
|
|
24401
24595
|
return;
|
|
24402
24596
|
}
|
|
24403
24597
|
}
|
|
24598
|
+
async function reviewResidentPerson(req, res, next) {
|
|
24599
|
+
const cookies = req.headers.cookie?.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
24600
|
+
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
24601
|
+
{}
|
|
24602
|
+
);
|
|
24603
|
+
req.body.approvedBy = cookies?.["user"] ? cookies["user"].toString() : req.body.approvedBy;
|
|
24604
|
+
const _id = req.params.id;
|
|
24605
|
+
const payload = { _id, ...req.body };
|
|
24606
|
+
const schema2 = import_joi58.default.object({
|
|
24607
|
+
_id: import_joi58.default.string().hex().required(),
|
|
24608
|
+
status: import_joi58.default.string().valid("approved", "rejected", "resubmit").required(),
|
|
24609
|
+
approvedBy: import_joi58.default.string().required(),
|
|
24610
|
+
remarks: import_joi58.default.string().optional().allow("", null)
|
|
24611
|
+
});
|
|
24612
|
+
const { error } = schema2.validate(payload);
|
|
24613
|
+
if (error) {
|
|
24614
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
24615
|
+
import_node_server_utils108.logger.log({ level: "error", message: messages });
|
|
24616
|
+
next(new import_node_server_utils108.BadRequestError(messages));
|
|
24617
|
+
return;
|
|
24618
|
+
}
|
|
24619
|
+
try {
|
|
24620
|
+
req.body.approvedBy = { id: req.body.approvedBy, name: "" };
|
|
24621
|
+
const result = await _reviewResidentPerson(_id, req.body);
|
|
24622
|
+
res.status(200).json({ message: result });
|
|
24623
|
+
return;
|
|
24624
|
+
} catch (error2) {
|
|
24625
|
+
import_node_server_utils108.logger.log({ level: "error", message: error2.message });
|
|
24626
|
+
next(error2);
|
|
24627
|
+
return;
|
|
24628
|
+
}
|
|
24629
|
+
}
|
|
24404
24630
|
return {
|
|
24405
24631
|
add,
|
|
24406
24632
|
getAll,
|
|
@@ -24412,7 +24638,8 @@ function usePersonController() {
|
|
|
24412
24638
|
getCompany,
|
|
24413
24639
|
getPeopleByPlateNumber,
|
|
24414
24640
|
getPeopleByNRIC,
|
|
24415
|
-
getPersonByUserId
|
|
24641
|
+
getPersonByUserId,
|
|
24642
|
+
reviewResidentPerson
|
|
24416
24643
|
};
|
|
24417
24644
|
}
|
|
24418
24645
|
|
|
@@ -29535,7 +29762,7 @@ function useBulletinBoardController() {
|
|
|
29535
29762
|
page: import_joi76.default.number().integer().min(1).allow("", null).default(1),
|
|
29536
29763
|
limit: import_joi76.default.number().integer().min(1).max(100).allow("", null).default(10),
|
|
29537
29764
|
sort: import_joi76.default.string().valid(...Object.values(BulletinSort)).default("_id" /* ID */),
|
|
29538
|
-
order: import_joi76.default.string().valid(...Object.values(SortOrder)).default("
|
|
29765
|
+
order: import_joi76.default.string().valid(...Object.values(SortOrder)).default("desc" /* DESC */),
|
|
29539
29766
|
site: import_joi76.default.string().hex().length(24).required(),
|
|
29540
29767
|
status: import_joi76.default.string().valid(...Object.values(BuildingStatus)).optional().default("active" /* ACTIVE */),
|
|
29541
29768
|
recipients: import_joi76.default.alternatives().try(
|
|
@@ -32702,7 +32929,7 @@ var MAccessCard = class {
|
|
|
32702
32929
|
accessType = "Normal" /* NORMAL */,
|
|
32703
32930
|
cardNo,
|
|
32704
32931
|
pin,
|
|
32705
|
-
qrData,
|
|
32932
|
+
qrData = null,
|
|
32706
32933
|
startDate,
|
|
32707
32934
|
endDate,
|
|
32708
32935
|
isActivated,
|
|
@@ -33035,10 +33262,6 @@ function UseAccessManagementRepo() {
|
|
|
33035
33262
|
payload.updatedAt = new Date(payload.updatedAt);
|
|
33036
33263
|
payload.assignedUnit = payload.unit?.map((id) => new import_mongodb90.ObjectId(id));
|
|
33037
33264
|
delete payload.unit;
|
|
33038
|
-
payload.qrData = await createQrData({
|
|
33039
|
-
cardNumber: payload.cardNo,
|
|
33040
|
-
facilityCode: parseInt(payload.cardNo.slice(0, 4), 10)
|
|
33041
|
-
});
|
|
33042
33265
|
const accessCardObj = new MAccessCard(payload);
|
|
33043
33266
|
const result = await collection().insertOne(accessCardObj);
|
|
33044
33267
|
return result.insertedId;
|
|
@@ -33100,10 +33323,6 @@ function UseAccessManagementRepo() {
|
|
|
33100
33323
|
cardNo,
|
|
33101
33324
|
accessType: "Normal" /* NORMAL */,
|
|
33102
33325
|
pin: "123456",
|
|
33103
|
-
qrData: await createQrData({
|
|
33104
|
-
cardNumber: cardNo,
|
|
33105
|
-
facilityCode: parseInt(cardNo.slice(0, 4), 10)
|
|
33106
|
-
}),
|
|
33107
33326
|
startDate: /* @__PURE__ */ new Date(),
|
|
33108
33327
|
endDate,
|
|
33109
33328
|
isActivated: true,
|
|
@@ -33153,10 +33372,6 @@ function UseAccessManagementRepo() {
|
|
|
33153
33372
|
cardNo,
|
|
33154
33373
|
accessType: "Normal" /* NORMAL */,
|
|
33155
33374
|
pin: "123456",
|
|
33156
|
-
qrData: await createQrData({
|
|
33157
|
-
cardNumber: cardNo,
|
|
33158
|
-
facilityCode: parseInt(cardNo.slice(0, 4), 10)
|
|
33159
|
-
}),
|
|
33160
33375
|
startDate: /* @__PURE__ */ new Date(),
|
|
33161
33376
|
endDate,
|
|
33162
33377
|
isActivated: true,
|
|
@@ -34298,7 +34513,6 @@ function UseAccessManagementRepo() {
|
|
|
34298
34513
|
accessType: "Normal" /* NORMAL */,
|
|
34299
34514
|
cardNo: `${facilityCode}${cardNumber}`,
|
|
34300
34515
|
pin,
|
|
34301
|
-
qrData: await createQrData({ cardNumber: `${facilityCode}${cardNumber}` }),
|
|
34302
34516
|
startDate: new Date(item["startDate (format MM/DD/YYYY)"]),
|
|
34303
34517
|
endDate: new Date(item["endDate (format MM/DD/YYYY)"] || endDate),
|
|
34304
34518
|
isActivated: true,
|
|
@@ -41421,6 +41635,17 @@ var import_node_server_utils184 = require("@7365admin1/node-server-utils");
|
|
|
41421
41635
|
// src/models/occurrence-subject.model.ts
|
|
41422
41636
|
var import_mongodb108 = require("mongodb");
|
|
41423
41637
|
var import_joi103 = __toESM(require("joi"));
|
|
41638
|
+
var SubjectSort = /* @__PURE__ */ ((SubjectSort2) => {
|
|
41639
|
+
SubjectSort2["CREATED_AT"] = "createdAt";
|
|
41640
|
+
SubjectSort2["NAME"] = "name";
|
|
41641
|
+
SubjectSort2["ID"] = "_id";
|
|
41642
|
+
return SubjectSort2;
|
|
41643
|
+
})(SubjectSort || {});
|
|
41644
|
+
var SubjectOrder = /* @__PURE__ */ ((SubjectOrder2) => {
|
|
41645
|
+
SubjectOrder2["ASC"] = "asc";
|
|
41646
|
+
SubjectOrder2["DESC"] = "desc";
|
|
41647
|
+
return SubjectOrder2;
|
|
41648
|
+
})(SubjectOrder || {});
|
|
41424
41649
|
var schemaOccurrenceSubject = import_joi103.default.object({
|
|
41425
41650
|
site: import_joi103.default.string().hex().required(),
|
|
41426
41651
|
subject: import_joi103.default.string().required(),
|
|
@@ -41529,7 +41754,8 @@ function useOccurrenceSubjectRepo() {
|
|
|
41529
41754
|
}
|
|
41530
41755
|
const baseQuery = {
|
|
41531
41756
|
site,
|
|
41532
|
-
status: { $ne: "deleted" }
|
|
41757
|
+
status: { $ne: "deleted" },
|
|
41758
|
+
...search && { $text: { $search: search } }
|
|
41533
41759
|
};
|
|
41534
41760
|
let query = { ...baseQuery };
|
|
41535
41761
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
@@ -41538,12 +41764,9 @@ function useOccurrenceSubjectRepo() {
|
|
|
41538
41764
|
sort: JSON.stringify(sort),
|
|
41539
41765
|
page,
|
|
41540
41766
|
limit,
|
|
41541
|
-
status: { $ne: "deleted" }
|
|
41767
|
+
status: { $ne: "deleted" },
|
|
41768
|
+
...search && { search }
|
|
41542
41769
|
};
|
|
41543
|
-
if (search) {
|
|
41544
|
-
query.$text = { $search: search };
|
|
41545
|
-
cacheOptions.search = search;
|
|
41546
|
-
}
|
|
41547
41770
|
const cacheKey = (0, import_node_server_utils184.makeCacheKey)(namespace_collection, cacheOptions);
|
|
41548
41771
|
const cachedData = await getCache(cacheKey);
|
|
41549
41772
|
if (cachedData) {
|
|
@@ -41622,11 +41845,22 @@ function useOccurrenceSubjectRepo() {
|
|
|
41622
41845
|
} catch (error) {
|
|
41623
41846
|
throw new import_node_server_utils184.BadRequestError("Invalid occurrence subject ID format.");
|
|
41624
41847
|
}
|
|
41848
|
+
const cacheKey = (0, import_node_server_utils184.makeCacheKey)(namespace_collection, { _id });
|
|
41849
|
+
const cachedData = await getCache(cacheKey);
|
|
41850
|
+
if (cachedData) {
|
|
41851
|
+
import_node_server_utils184.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
41852
|
+
return cachedData;
|
|
41853
|
+
}
|
|
41625
41854
|
try {
|
|
41626
41855
|
const data = await collection.findOne({ _id }, { session });
|
|
41627
41856
|
if (!data) {
|
|
41628
41857
|
throw new import_node_server_utils184.NotFoundError("Occurrence subject not found.");
|
|
41629
41858
|
}
|
|
41859
|
+
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
41860
|
+
import_node_server_utils184.logger.info(`Cache set for key: ${cacheKey}`);
|
|
41861
|
+
}).catch((err) => {
|
|
41862
|
+
import_node_server_utils184.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
41863
|
+
});
|
|
41630
41864
|
return data;
|
|
41631
41865
|
} catch (error) {
|
|
41632
41866
|
throw error;
|
|
@@ -41813,62 +42047,49 @@ function useOccurrenceEntryController() {
|
|
|
41813
42047
|
getLatestSerialNumber: _getLatestSerialNumber
|
|
41814
42048
|
} = useOccurrenceEntryRepo();
|
|
41815
42049
|
async function add(req, res, next) {
|
|
41816
|
-
const { error, value } = schemaOccurrenceEntry.validate(req.body, {
|
|
41817
|
-
abortEarly: false
|
|
41818
|
-
});
|
|
41819
|
-
if (error) {
|
|
41820
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
41821
|
-
import_node_server_utils186.logger.log({ level: "error", message: messages });
|
|
41822
|
-
next(new import_node_server_utils186.BadRequestError(messages));
|
|
41823
|
-
return;
|
|
41824
|
-
}
|
|
41825
42050
|
try {
|
|
42051
|
+
const { error, value } = schemaOccurrenceEntry.validate(req.body, {
|
|
42052
|
+
abortEarly: false
|
|
42053
|
+
});
|
|
42054
|
+
if (error) {
|
|
42055
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
42056
|
+
import_node_server_utils186.logger.log({ level: "error", message: messages });
|
|
42057
|
+
next(new import_node_server_utils186.BadRequestError(messages));
|
|
42058
|
+
return;
|
|
42059
|
+
}
|
|
41826
42060
|
const data = await _add(value);
|
|
41827
42061
|
res.status(201).json(data);
|
|
41828
42062
|
return;
|
|
41829
|
-
} catch (
|
|
41830
|
-
import_node_server_utils186.logger.log({ level: "error", message:
|
|
41831
|
-
next(
|
|
42063
|
+
} catch (error) {
|
|
42064
|
+
import_node_server_utils186.logger.log({ level: "error", message: error.message });
|
|
42065
|
+
next(error);
|
|
41832
42066
|
return;
|
|
41833
42067
|
}
|
|
41834
42068
|
}
|
|
41835
42069
|
async function getAll(req, res, next) {
|
|
41836
|
-
const allowedFields = ["createdAt", "name"];
|
|
41837
|
-
const allowedOrder = ["asc", "desc"];
|
|
41838
|
-
const validation = import_joi104.default.object({
|
|
41839
|
-
search: import_joi104.default.string().optional().allow("", null),
|
|
41840
|
-
page: import_joi104.default.number().integer().min(1).allow("", null).default(1),
|
|
41841
|
-
limit: import_joi104.default.number().integer().min(1).max(100).allow("", null).default(10),
|
|
41842
|
-
sort: import_joi104.default.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("", ...allowedFields),
|
|
41843
|
-
order: import_joi104.default.string().pattern(/^(asc|desc)(,(asc|desc))*$/).optional().allow("", ...allowedOrder),
|
|
41844
|
-
site: import_joi104.default.string().hex().required(),
|
|
41845
|
-
dailyOccurrenceBookId: import_joi104.default.string().optional().allow("", null)
|
|
41846
|
-
});
|
|
41847
|
-
const query = { ...req.query };
|
|
41848
|
-
const { error } = validation.validate(query, {
|
|
41849
|
-
abortEarly: false
|
|
41850
|
-
});
|
|
41851
|
-
if (error) {
|
|
41852
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
41853
|
-
import_node_server_utils186.logger.log({ level: "error", message: messages });
|
|
41854
|
-
next(new import_node_server_utils186.BadRequestError(messages));
|
|
41855
|
-
return;
|
|
41856
|
-
}
|
|
41857
|
-
const search = req.query.search ?? "";
|
|
41858
|
-
const page = parseInt(req.query.page ?? "1");
|
|
41859
|
-
const limit = parseInt(req.query.limit ?? "10");
|
|
41860
|
-
const site = req.query.site ?? "";
|
|
41861
|
-
const dailyOccurrenceBookId = req.query.dailyOccurrenceBookId ?? "";
|
|
41862
|
-
const sortObj = {};
|
|
41863
|
-
const sortFields = String(req.query.sort).split(",");
|
|
41864
|
-
const sortOrders = String(req.query.order).split(",");
|
|
41865
|
-
sortFields.forEach((field, index) => {
|
|
41866
|
-
if (allowedFields.includes(field)) {
|
|
41867
|
-
const order = sortOrders[index] === "asc" ? 1 : -1;
|
|
41868
|
-
sortObj[field] = order;
|
|
41869
|
-
}
|
|
41870
|
-
});
|
|
41871
42070
|
try {
|
|
42071
|
+
const schema2 = import_joi104.default.object({
|
|
42072
|
+
search: import_joi104.default.string().optional().allow("", null),
|
|
42073
|
+
page: import_joi104.default.number().integer().min(1).allow("", null).default(1),
|
|
42074
|
+
limit: import_joi104.default.number().integer().min(1).max(100).allow("", null).default(10),
|
|
42075
|
+
sort: import_joi104.default.string().valid(...Object.values(EntrySort)).default("_id" /* ID */),
|
|
42076
|
+
order: import_joi104.default.string().valid(...Object.values(EntryOrder)).default("desc" /* DESC */),
|
|
42077
|
+
site: import_joi104.default.string().hex().required(),
|
|
42078
|
+
dailyOccurrenceBookId: import_joi104.default.string().hex().length(24).optional().allow("", null)
|
|
42079
|
+
});
|
|
42080
|
+
const { error, value } = schema2.validate(req.query, {
|
|
42081
|
+
abortEarly: false
|
|
42082
|
+
});
|
|
42083
|
+
if (error) {
|
|
42084
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
42085
|
+
import_node_server_utils186.logger.log({ level: "error", message: messages });
|
|
42086
|
+
next(new import_node_server_utils186.BadRequestError(messages));
|
|
42087
|
+
return;
|
|
42088
|
+
}
|
|
42089
|
+
const { search, page, limit, site, dailyOccurrenceBookId, sort, order } = value;
|
|
42090
|
+
const sortObj = {
|
|
42091
|
+
[sort ? sort : "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
|
|
42092
|
+
};
|
|
41872
42093
|
const data = await _getAll({
|
|
41873
42094
|
search,
|
|
41874
42095
|
page,
|
|
@@ -41879,69 +42100,73 @@ function useOccurrenceEntryController() {
|
|
|
41879
42100
|
});
|
|
41880
42101
|
res.status(200).json(data);
|
|
41881
42102
|
return;
|
|
41882
|
-
} catch (
|
|
41883
|
-
import_node_server_utils186.logger.log({ level: "error", message:
|
|
41884
|
-
next(
|
|
42103
|
+
} catch (error) {
|
|
42104
|
+
import_node_server_utils186.logger.log({ level: "error", message: error.message });
|
|
42105
|
+
next(error);
|
|
41885
42106
|
return;
|
|
41886
42107
|
}
|
|
41887
42108
|
}
|
|
41888
42109
|
async function getOccurrenceEntryById(req, res, next) {
|
|
41889
|
-
const validation = import_joi104.default.string().hex().required();
|
|
41890
|
-
const _id = req.params.id;
|
|
41891
|
-
const { error } = validation.validate(_id);
|
|
41892
|
-
if (error) {
|
|
41893
|
-
import_node_server_utils186.logger.log({ level: "error", message: error.message });
|
|
41894
|
-
next(new import_node_server_utils186.BadRequestError(error.message));
|
|
41895
|
-
return;
|
|
41896
|
-
}
|
|
41897
42110
|
try {
|
|
42111
|
+
const schema2 = import_joi104.default.object({
|
|
42112
|
+
_id: import_joi104.default.string().hex().length(24).required()
|
|
42113
|
+
});
|
|
42114
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
42115
|
+
if (error) {
|
|
42116
|
+
import_node_server_utils186.logger.log({ level: "error", message: error.message });
|
|
42117
|
+
next(new import_node_server_utils186.BadRequestError(error.message));
|
|
42118
|
+
return;
|
|
42119
|
+
}
|
|
42120
|
+
const { _id } = value;
|
|
41898
42121
|
const data = await _getOccurrenceEntryById(_id);
|
|
41899
42122
|
res.status(200).json(data);
|
|
41900
42123
|
return;
|
|
41901
|
-
} catch (
|
|
41902
|
-
import_node_server_utils186.logger.log({ level: "error", message:
|
|
41903
|
-
next(
|
|
42124
|
+
} catch (error) {
|
|
42125
|
+
import_node_server_utils186.logger.log({ level: "error", message: error.message });
|
|
42126
|
+
next(error);
|
|
41904
42127
|
return;
|
|
41905
42128
|
}
|
|
41906
42129
|
}
|
|
41907
42130
|
async function updateOccurrenceEntryById(req, res, next) {
|
|
41908
|
-
const payload = { _id: req.params.id, ...req.body };
|
|
41909
|
-
const { error, value } = schemaUpdateOccurrenceEntry.validate(payload, {
|
|
41910
|
-
abortEarly: false
|
|
41911
|
-
});
|
|
41912
|
-
if (error) {
|
|
41913
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
41914
|
-
import_node_server_utils186.logger.log({ level: "error", message: messages });
|
|
41915
|
-
next(new import_node_server_utils186.BadRequestError(messages));
|
|
41916
|
-
return;
|
|
41917
|
-
}
|
|
41918
|
-
const { _id, ...rest } = value;
|
|
41919
42131
|
try {
|
|
42132
|
+
const payload = { _id: req.params.id, ...req.body };
|
|
42133
|
+
const { error, value } = schemaUpdateOccurrenceEntry.validate(payload, {
|
|
42134
|
+
abortEarly: false
|
|
42135
|
+
});
|
|
42136
|
+
if (error) {
|
|
42137
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
42138
|
+
import_node_server_utils186.logger.log({ level: "error", message: messages });
|
|
42139
|
+
next(new import_node_server_utils186.BadRequestError(messages));
|
|
42140
|
+
return;
|
|
42141
|
+
}
|
|
42142
|
+
const { _id, ...rest } = value;
|
|
41920
42143
|
const result = await _updateOccurrenceEntryById(_id, rest);
|
|
41921
42144
|
res.status(200).json({ message: result });
|
|
41922
42145
|
return;
|
|
41923
|
-
} catch (
|
|
41924
|
-
import_node_server_utils186.logger.log({ level: "error", message:
|
|
41925
|
-
next(
|
|
42146
|
+
} catch (error) {
|
|
42147
|
+
import_node_server_utils186.logger.log({ level: "error", message: error.message });
|
|
42148
|
+
next(error);
|
|
41926
42149
|
return;
|
|
41927
42150
|
}
|
|
41928
42151
|
}
|
|
41929
42152
|
async function deleteOccurrenceEntryById(req, res, next) {
|
|
41930
|
-
const validation = import_joi104.default.string().hex().required();
|
|
41931
|
-
const _id = req.params.id;
|
|
41932
|
-
const { error } = validation.validate(_id);
|
|
41933
|
-
if (error) {
|
|
41934
|
-
import_node_server_utils186.logger.log({ level: "error", message: error.message });
|
|
41935
|
-
next(new import_node_server_utils186.BadRequestError(error.message));
|
|
41936
|
-
return;
|
|
41937
|
-
}
|
|
41938
42153
|
try {
|
|
42154
|
+
const schema2 = import_joi104.default.object({
|
|
42155
|
+
_id: import_joi104.default.string().hex().length(24).required()
|
|
42156
|
+
});
|
|
42157
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
42158
|
+
if (error) {
|
|
42159
|
+
import_node_server_utils186.logger.log({ level: "error", message: error.message });
|
|
42160
|
+
next(new import_node_server_utils186.BadRequestError(error.message));
|
|
42161
|
+
return;
|
|
42162
|
+
}
|
|
42163
|
+
const { _id } = value;
|
|
41939
42164
|
await _deleteOccurrenceEntryById(_id);
|
|
41940
42165
|
res.status(200).json({ message: "Successfully deleted occurrence entry." });
|
|
41941
42166
|
return;
|
|
41942
|
-
} catch (
|
|
41943
|
-
import_node_server_utils186.logger.log({ level: "error", message:
|
|
41944
|
-
next(
|
|
42167
|
+
} catch (error) {
|
|
42168
|
+
import_node_server_utils186.logger.log({ level: "error", message: error.message });
|
|
42169
|
+
next(error);
|
|
41945
42170
|
return;
|
|
41946
42171
|
}
|
|
41947
42172
|
}
|
|
@@ -42578,61 +42803,48 @@ function useOccurrenceSubjectController() {
|
|
|
42578
42803
|
deleteOccurrenceSubjectById: _deleteOccurrenceSubjectById
|
|
42579
42804
|
} = useOccurrenceSubjectRepo();
|
|
42580
42805
|
async function add(req, res, next) {
|
|
42581
|
-
const payload = { ...req.body };
|
|
42582
|
-
const { error } = schemaOccurrenceSubject.validate(payload, {
|
|
42583
|
-
abortEarly: false
|
|
42584
|
-
});
|
|
42585
|
-
if (error) {
|
|
42586
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
42587
|
-
import_node_server_utils190.logger.log({ level: "error", message: messages });
|
|
42588
|
-
next(new import_node_server_utils190.BadRequestError(messages));
|
|
42589
|
-
return;
|
|
42590
|
-
}
|
|
42591
42806
|
try {
|
|
42592
|
-
const
|
|
42807
|
+
const { error, value } = schemaOccurrenceSubject.validate(req.body, {
|
|
42808
|
+
abortEarly: false
|
|
42809
|
+
});
|
|
42810
|
+
if (error) {
|
|
42811
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
42812
|
+
import_node_server_utils190.logger.log({ level: "error", message: messages });
|
|
42813
|
+
next(new import_node_server_utils190.BadRequestError(messages));
|
|
42814
|
+
return;
|
|
42815
|
+
}
|
|
42816
|
+
const data = await _add(value);
|
|
42593
42817
|
res.status(201).json(data);
|
|
42594
42818
|
return;
|
|
42595
|
-
} catch (
|
|
42596
|
-
import_node_server_utils190.logger.log({ level: "error", message:
|
|
42597
|
-
next(
|
|
42819
|
+
} catch (error) {
|
|
42820
|
+
import_node_server_utils190.logger.log({ level: "error", message: error.message });
|
|
42821
|
+
next(error);
|
|
42598
42822
|
return;
|
|
42599
42823
|
}
|
|
42600
42824
|
}
|
|
42601
42825
|
async function getAll(req, res, next) {
|
|
42602
|
-
const allowedFields = ["createdAt", "name"];
|
|
42603
|
-
const allowedOrder = ["asc", "desc"];
|
|
42604
|
-
const validation = import_joi107.default.object({
|
|
42605
|
-
search: import_joi107.default.string().optional().allow("", null),
|
|
42606
|
-
page: import_joi107.default.number().integer().min(1).allow("", null).default(1),
|
|
42607
|
-
limit: import_joi107.default.number().integer().min(1).max(100).allow("", null).default(10),
|
|
42608
|
-
sort: import_joi107.default.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("", ...allowedFields),
|
|
42609
|
-
order: import_joi107.default.string().pattern(/^(asc|desc)(,(asc|desc))*$/).optional().allow("", ...allowedOrder),
|
|
42610
|
-
site: import_joi107.default.string().hex().required()
|
|
42611
|
-
});
|
|
42612
|
-
const query = { ...req.query };
|
|
42613
|
-
const { error } = validation.validate(query, {
|
|
42614
|
-
abortEarly: false
|
|
42615
|
-
});
|
|
42616
|
-
if (error) {
|
|
42617
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
42618
|
-
import_node_server_utils190.logger.log({ level: "error", message: messages });
|
|
42619
|
-
next(new import_node_server_utils190.BadRequestError(messages));
|
|
42620
|
-
return;
|
|
42621
|
-
}
|
|
42622
|
-
const search = req.query.search ?? "";
|
|
42623
|
-
const page = parseInt(req.query.page ?? "1");
|
|
42624
|
-
const limit = parseInt(req.query.limit ?? "10");
|
|
42625
|
-
const site = req.query.site ?? "";
|
|
42626
|
-
const sortObj = {};
|
|
42627
|
-
const sortFields = String(req.query.sort).split(",");
|
|
42628
|
-
const sortOrders = String(req.query.order).split(",");
|
|
42629
|
-
sortFields.forEach((field, index) => {
|
|
42630
|
-
if (allowedFields.includes(field)) {
|
|
42631
|
-
const order = sortOrders[index] === "asc" ? 1 : -1;
|
|
42632
|
-
sortObj[field] = order;
|
|
42633
|
-
}
|
|
42634
|
-
});
|
|
42635
42826
|
try {
|
|
42827
|
+
const validation = import_joi107.default.object({
|
|
42828
|
+
search: import_joi107.default.string().optional().allow("", null),
|
|
42829
|
+
page: import_joi107.default.number().integer().min(1).allow("", null).default(1),
|
|
42830
|
+
limit: import_joi107.default.number().integer().min(1).max(100).allow("", null).default(10),
|
|
42831
|
+
sort: import_joi107.default.string().valid(...Object.values(SubjectSort)).default("_id" /* ID */),
|
|
42832
|
+
order: import_joi107.default.string().valid(...Object.values(SubjectOrder)).default("desc" /* DESC */),
|
|
42833
|
+
site: import_joi107.default.string().hex().length(24).required()
|
|
42834
|
+
});
|
|
42835
|
+
const { error, value } = validation.validate(req.query, {
|
|
42836
|
+
abortEarly: false
|
|
42837
|
+
});
|
|
42838
|
+
if (error) {
|
|
42839
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
42840
|
+
import_node_server_utils190.logger.log({ level: "error", message: messages });
|
|
42841
|
+
next(new import_node_server_utils190.BadRequestError(messages));
|
|
42842
|
+
return;
|
|
42843
|
+
}
|
|
42844
|
+
const { search, page, limit, site, sort, order } = value;
|
|
42845
|
+
const sortObj = {
|
|
42846
|
+
[sort ? sort : "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
|
|
42847
|
+
};
|
|
42636
42848
|
const data = await _getAll({
|
|
42637
42849
|
search,
|
|
42638
42850
|
page,
|
|
@@ -42642,50 +42854,54 @@ function useOccurrenceSubjectController() {
|
|
|
42642
42854
|
});
|
|
42643
42855
|
res.status(200).json(data);
|
|
42644
42856
|
return;
|
|
42645
|
-
} catch (
|
|
42646
|
-
import_node_server_utils190.logger.log({ level: "error", message:
|
|
42647
|
-
next(
|
|
42857
|
+
} catch (error) {
|
|
42858
|
+
import_node_server_utils190.logger.log({ level: "error", message: error.message });
|
|
42859
|
+
next(error);
|
|
42648
42860
|
return;
|
|
42649
42861
|
}
|
|
42650
42862
|
}
|
|
42651
42863
|
async function getOccurrenceSubjectById(req, res, next) {
|
|
42652
|
-
const validation = import_joi107.default.string().hex().required();
|
|
42653
|
-
const _id = req.params.id;
|
|
42654
|
-
const { error } = validation.validate(_id);
|
|
42655
|
-
if (error) {
|
|
42656
|
-
import_node_server_utils190.logger.log({ level: "error", message: error.message });
|
|
42657
|
-
next(new import_node_server_utils190.BadRequestError(error.message));
|
|
42658
|
-
return;
|
|
42659
|
-
}
|
|
42660
42864
|
try {
|
|
42865
|
+
const schema2 = import_joi107.default.object({
|
|
42866
|
+
_id: import_joi107.default.string().hex().length(24).required()
|
|
42867
|
+
});
|
|
42868
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
42869
|
+
if (error) {
|
|
42870
|
+
import_node_server_utils190.logger.log({ level: "error", message: error.message });
|
|
42871
|
+
next(new import_node_server_utils190.BadRequestError(error.message));
|
|
42872
|
+
return;
|
|
42873
|
+
}
|
|
42874
|
+
const { _id } = value;
|
|
42661
42875
|
const data = await _getOccurrenceSubjectById(_id);
|
|
42662
42876
|
res.status(200).json(data);
|
|
42663
42877
|
return;
|
|
42664
|
-
} catch (
|
|
42665
|
-
import_node_server_utils190.logger.log({ level: "error", message:
|
|
42666
|
-
next(
|
|
42878
|
+
} catch (error) {
|
|
42879
|
+
import_node_server_utils190.logger.log({ level: "error", message: error.message });
|
|
42880
|
+
next(error);
|
|
42667
42881
|
return;
|
|
42668
42882
|
}
|
|
42669
42883
|
}
|
|
42670
42884
|
async function updateOccurrenceSubjectById(req, res, next) {
|
|
42671
|
-
const _id = req.params.id;
|
|
42672
|
-
const payload = { _id, ...req.body };
|
|
42673
|
-
const { error } = schemaUpdateOccurrenceSubject.validate(payload, {
|
|
42674
|
-
abortEarly: false
|
|
42675
|
-
});
|
|
42676
|
-
if (error) {
|
|
42677
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
42678
|
-
import_node_server_utils190.logger.log({ level: "error", message: messages });
|
|
42679
|
-
next(new import_node_server_utils190.BadRequestError(messages));
|
|
42680
|
-
return;
|
|
42681
|
-
}
|
|
42682
42885
|
try {
|
|
42683
|
-
const
|
|
42886
|
+
const { error, value } = schemaUpdateOccurrenceSubject.validate(
|
|
42887
|
+
{ _id: req.params.id, ...req.body },
|
|
42888
|
+
{
|
|
42889
|
+
abortEarly: false
|
|
42890
|
+
}
|
|
42891
|
+
);
|
|
42892
|
+
if (error) {
|
|
42893
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
42894
|
+
import_node_server_utils190.logger.log({ level: "error", message: messages });
|
|
42895
|
+
next(new import_node_server_utils190.BadRequestError(messages));
|
|
42896
|
+
return;
|
|
42897
|
+
}
|
|
42898
|
+
const { _id, ...rest } = value;
|
|
42899
|
+
const result = await _updateOccurrenceSubjectById(_id, rest);
|
|
42684
42900
|
res.status(200).json({ message: result });
|
|
42685
42901
|
return;
|
|
42686
|
-
} catch (
|
|
42687
|
-
import_node_server_utils190.logger.log({ level: "error", message:
|
|
42688
|
-
next(
|
|
42902
|
+
} catch (error) {
|
|
42903
|
+
import_node_server_utils190.logger.log({ level: "error", message: error.message });
|
|
42904
|
+
next(error);
|
|
42689
42905
|
return;
|
|
42690
42906
|
}
|
|
42691
42907
|
}
|
|
@@ -49893,6 +50109,8 @@ function useRoleControllerV2() {
|
|
|
49893
50109
|
EAccessCardTypes,
|
|
49894
50110
|
EAccessCardUserTypes,
|
|
49895
50111
|
EmailSender,
|
|
50112
|
+
EntryOrder,
|
|
50113
|
+
EntrySort,
|
|
49896
50114
|
FacilitySort,
|
|
49897
50115
|
FacilityStatus,
|
|
49898
50116
|
GuestSort,
|
|
@@ -49974,6 +50192,8 @@ function useRoleControllerV2() {
|
|
|
49974
50192
|
SortFields,
|
|
49975
50193
|
SortOrder,
|
|
49976
50194
|
Status,
|
|
50195
|
+
SubjectOrder,
|
|
50196
|
+
SubjectSort,
|
|
49977
50197
|
SubscriptionType,
|
|
49978
50198
|
UseAccessManagementRepo,
|
|
49979
50199
|
UserStatus,
|
|
@@ -50029,6 +50249,7 @@ function useRoleControllerV2() {
|
|
|
50029
50249
|
robotSchema,
|
|
50030
50250
|
schema,
|
|
50031
50251
|
schemaApprovedBy,
|
|
50252
|
+
schemaApprover,
|
|
50032
50253
|
schemaBilling,
|
|
50033
50254
|
schemaBillingConfiguration,
|
|
50034
50255
|
schemaBillingItem,
|