@7365admin1/core 2.77.0 → 2.78.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +42 -6
- package/dist/index.js +1154 -735
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1805 -1387
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -225,6 +225,7 @@ __export(src_exports, {
|
|
|
225
225
|
schemaFormEntry: () => schemaFormEntry,
|
|
226
226
|
schemaGuestManagement: () => schemaGuestManagement,
|
|
227
227
|
schemaIncidentReport: () => schemaIncidentReport,
|
|
228
|
+
schemaMultipleDocumentManagement: () => schemaMultipleDocumentManagement,
|
|
228
229
|
schemaNfcPatrolLog: () => schemaNfcPatrolLog,
|
|
229
230
|
schemaNfcPatrolRoute: () => schemaNfcPatrolRoute,
|
|
230
231
|
schemaNfcPatrolTag: () => schemaNfcPatrolTag,
|
|
@@ -416,7 +417,7 @@ __export(src_exports, {
|
|
|
416
417
|
usePersonRepo: () => usePersonRepo,
|
|
417
418
|
usePostFavoriteController: () => usePostFavoriteController,
|
|
418
419
|
usePostFavoriteRepo: () => usePostFavoriteRepo,
|
|
419
|
-
usePostFavoriteService: () =>
|
|
420
|
+
usePostFavoriteService: () => usePostFavoriteService2,
|
|
420
421
|
usePostPrelovedController: () => usePostPrelovedController,
|
|
421
422
|
usePostPrelovedRepo: () => usePostPrelovedRepo,
|
|
422
423
|
usePriceController: () => usePriceController,
|
|
@@ -5196,6 +5197,38 @@ function useOrgRepo() {
|
|
|
5196
5197
|
throw new import_node_server_utils17.NotFoundError("Organization not found.");
|
|
5197
5198
|
return org;
|
|
5198
5199
|
}
|
|
5200
|
+
async function completeOnboardingById(_id, session) {
|
|
5201
|
+
try {
|
|
5202
|
+
_id = new import_mongodb15.ObjectId(_id);
|
|
5203
|
+
} catch (error) {
|
|
5204
|
+
throw new import_node_server_utils17.BadRequestError("Invalid organization ID format.");
|
|
5205
|
+
}
|
|
5206
|
+
try {
|
|
5207
|
+
const result = await collection.updateOne(
|
|
5208
|
+
{ _id },
|
|
5209
|
+
{
|
|
5210
|
+
$set: {
|
|
5211
|
+
onboardingCompleted: true,
|
|
5212
|
+
onboardingCompletedAt: /* @__PURE__ */ new Date(),
|
|
5213
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
5214
|
+
}
|
|
5215
|
+
},
|
|
5216
|
+
{ session }
|
|
5217
|
+
);
|
|
5218
|
+
if (result.matchedCount === 0) {
|
|
5219
|
+
throw new import_node_server_utils17.NotFoundError("Organization not found.");
|
|
5220
|
+
}
|
|
5221
|
+
await delNamespace();
|
|
5222
|
+
return "Successfully completed organization onboarding.";
|
|
5223
|
+
} catch (error) {
|
|
5224
|
+
if (error instanceof import_node_server_utils17.AppError) {
|
|
5225
|
+
throw error;
|
|
5226
|
+
}
|
|
5227
|
+
throw new import_node_server_utils17.InternalServerError(
|
|
5228
|
+
"Failed to complete organization onboarding."
|
|
5229
|
+
);
|
|
5230
|
+
}
|
|
5231
|
+
}
|
|
5199
5232
|
return {
|
|
5200
5233
|
createIndex,
|
|
5201
5234
|
createTextIndex,
|
|
@@ -5211,7 +5244,8 @@ function useOrgRepo() {
|
|
|
5211
5244
|
deleteById,
|
|
5212
5245
|
getOrgsByEmail,
|
|
5213
5246
|
getOrganizationsWithSubscription,
|
|
5214
|
-
getAdminOrgForResident
|
|
5247
|
+
getAdminOrgForResident,
|
|
5248
|
+
completeOnboardingById
|
|
5215
5249
|
};
|
|
5216
5250
|
}
|
|
5217
5251
|
|
|
@@ -9303,7 +9337,8 @@ function useOrgController() {
|
|
|
9303
9337
|
add: _add,
|
|
9304
9338
|
update: _update,
|
|
9305
9339
|
getOrgsByEmail: _getOrgsByEmail,
|
|
9306
|
-
getAdminOrgForResident: _getAdminOrgForResident
|
|
9340
|
+
getAdminOrgForResident: _getAdminOrgForResident,
|
|
9341
|
+
completeOnboardingById: _completeOnboardingById
|
|
9307
9342
|
} = useOrgRepo();
|
|
9308
9343
|
async function add(req, res, next) {
|
|
9309
9344
|
const validation = import_joi18.default.object({
|
|
@@ -9549,6 +9584,35 @@ function useOrgController() {
|
|
|
9549
9584
|
next(error);
|
|
9550
9585
|
}
|
|
9551
9586
|
}
|
|
9587
|
+
async function completeOnboarding(req, res, next) {
|
|
9588
|
+
const validation = import_joi18.default.string().hex().required();
|
|
9589
|
+
const id = req.params.id;
|
|
9590
|
+
const { error } = validation.validate(id);
|
|
9591
|
+
if (error) {
|
|
9592
|
+
import_node_server_utils35.logger.log({
|
|
9593
|
+
level: "error",
|
|
9594
|
+
message: error.message
|
|
9595
|
+
});
|
|
9596
|
+
next(new import_node_server_utils35.BadRequestError(error.message));
|
|
9597
|
+
return;
|
|
9598
|
+
}
|
|
9599
|
+
try {
|
|
9600
|
+
await _completeOnboardingById(id);
|
|
9601
|
+
const data = await _getById(id);
|
|
9602
|
+
res.json({
|
|
9603
|
+
message: "Organization onboarding completed successfully",
|
|
9604
|
+
data
|
|
9605
|
+
});
|
|
9606
|
+
return;
|
|
9607
|
+
} catch (error2) {
|
|
9608
|
+
import_node_server_utils35.logger.log({
|
|
9609
|
+
level: "error",
|
|
9610
|
+
message: error2.message
|
|
9611
|
+
});
|
|
9612
|
+
next(error2);
|
|
9613
|
+
return;
|
|
9614
|
+
}
|
|
9615
|
+
}
|
|
9552
9616
|
return {
|
|
9553
9617
|
add,
|
|
9554
9618
|
addOnboardingOrg,
|
|
@@ -9559,7 +9623,8 @@ function useOrgController() {
|
|
|
9559
9623
|
getByEmail,
|
|
9560
9624
|
update,
|
|
9561
9625
|
getOrgsByEmail,
|
|
9562
|
-
getAdminOrgForResident
|
|
9626
|
+
getAdminOrgForResident,
|
|
9627
|
+
completeOnboarding
|
|
9563
9628
|
};
|
|
9564
9629
|
}
|
|
9565
9630
|
|
|
@@ -15267,29 +15332,23 @@ function useVisitorTransactionRepo() {
|
|
|
15267
15332
|
...status && { status },
|
|
15268
15333
|
...tab == "Overnight Parking" && { isOvernightParking: true }
|
|
15269
15334
|
};
|
|
15270
|
-
|
|
15335
|
+
const finalSort = Object.keys(sort).length > 0 ? sort : { latestDate: -1 };
|
|
15271
15336
|
try {
|
|
15272
15337
|
const basePipeline = [
|
|
15273
15338
|
{ $match: query },
|
|
15274
15339
|
{
|
|
15275
15340
|
$addFields: {
|
|
15276
|
-
latestDate: {
|
|
15277
|
-
$max: ["$createdAt", "$updatedAt"]
|
|
15278
|
-
}
|
|
15341
|
+
latestDate: { $max: ["$createdAt", "$updatedAt"] }
|
|
15279
15342
|
}
|
|
15280
15343
|
},
|
|
15281
|
-
{ $sort:
|
|
15282
|
-
{ $skip: skip },
|
|
15283
|
-
{ $limit: limit },
|
|
15284
|
-
{
|
|
15285
|
-
$project: {
|
|
15286
|
-
latestDate: 0
|
|
15287
|
-
}
|
|
15288
|
-
}
|
|
15344
|
+
{ $sort: finalSort }
|
|
15289
15345
|
];
|
|
15290
15346
|
const [items, countResult] = await Promise.all([
|
|
15291
15347
|
collection.aggregate([
|
|
15292
15348
|
...basePipeline,
|
|
15349
|
+
{ $skip: skip },
|
|
15350
|
+
{ $limit: limit },
|
|
15351
|
+
{ $project: { latestDate: 0 } },
|
|
15293
15352
|
{
|
|
15294
15353
|
$lookup: {
|
|
15295
15354
|
from: "access-cards",
|
|
@@ -32452,12 +32511,51 @@ function useSiteFacilityBookingController() {
|
|
|
32452
32511
|
// src/models/document-management.model.ts
|
|
32453
32512
|
var import_joi75 = __toESM(require("joi"));
|
|
32454
32513
|
var import_mongodb79 = require("mongodb");
|
|
32514
|
+
var schemaMultipleDocumentManagement = import_joi75.default.object({
|
|
32515
|
+
_id: import_joi75.default.string().hex().optional().allow("", null),
|
|
32516
|
+
name: import_joi75.default.string().required(),
|
|
32517
|
+
type: import_joi75.default.string().optional().allow("", null),
|
|
32518
|
+
size: import_joi75.default.number().optional().allow(null, "").default(0),
|
|
32519
|
+
items: import_joi75.default.when("type", {
|
|
32520
|
+
is: "folder",
|
|
32521
|
+
then: import_joi75.default.forbidden(),
|
|
32522
|
+
otherwise: import_joi75.default.array().items(
|
|
32523
|
+
import_joi75.default.object({
|
|
32524
|
+
id: import_joi75.default.string().hex().required(),
|
|
32525
|
+
name: import_joi75.default.string().optional().allow("", null),
|
|
32526
|
+
type: import_joi75.default.string().optional().allow("", null),
|
|
32527
|
+
size: import_joi75.default.number().optional().allow(null, "").default(0),
|
|
32528
|
+
attachment: import_joi75.default.alternatives().try(
|
|
32529
|
+
import_joi75.default.string().optional().allow("", null),
|
|
32530
|
+
import_joi75.default.array().items(import_joi75.default.string()).optional()
|
|
32531
|
+
),
|
|
32532
|
+
remarks: import_joi75.default.string().optional().allow("", null)
|
|
32533
|
+
})
|
|
32534
|
+
)
|
|
32535
|
+
}),
|
|
32536
|
+
remarks: import_joi75.default.string().optional().allow("", null),
|
|
32537
|
+
org: import_joi75.default.string().hex().optional().allow("", null),
|
|
32538
|
+
site: import_joi75.default.string().hex().optional().allow("", null),
|
|
32539
|
+
parentId: import_joi75.default.string().hex().optional().allow("", null),
|
|
32540
|
+
createdBy: import_joi75.default.string().hex().required(),
|
|
32541
|
+
updatedBy: import_joi75.default.string().hex().optional().allow("", null),
|
|
32542
|
+
createdAt: import_joi75.default.date().optional().allow("", null),
|
|
32543
|
+
updatedAt: import_joi75.default.date().optional().allow("", null),
|
|
32544
|
+
status: import_joi75.default.string().optional().allow("", null).default("active")
|
|
32545
|
+
});
|
|
32455
32546
|
var schemaDocumentManagement = import_joi75.default.object({
|
|
32456
32547
|
_id: import_joi75.default.string().hex().optional().allow("", null),
|
|
32457
32548
|
name: import_joi75.default.string().required(),
|
|
32458
32549
|
type: import_joi75.default.string().optional().allow("", null),
|
|
32459
32550
|
size: import_joi75.default.number().optional().allow(null, "").default(0),
|
|
32460
|
-
attachment: import_joi75.default.when("type", {
|
|
32551
|
+
attachment: import_joi75.default.when("type", {
|
|
32552
|
+
is: "folder",
|
|
32553
|
+
then: import_joi75.default.forbidden(),
|
|
32554
|
+
otherwise: import_joi75.default.alternatives().try(
|
|
32555
|
+
import_joi75.default.string().optional().allow("", null),
|
|
32556
|
+
import_joi75.default.array().items(import_joi75.default.string()).optional()
|
|
32557
|
+
)
|
|
32558
|
+
}),
|
|
32461
32559
|
remarks: import_joi75.default.string().optional().allow("", null),
|
|
32462
32560
|
org: import_joi75.default.string().hex().optional().allow("", null),
|
|
32463
32561
|
site: import_joi75.default.string().hex().optional().allow("", null),
|
|
@@ -32473,14 +32571,19 @@ var schemaUpdateDocumentManagement = import_joi75.default.object({
|
|
|
32473
32571
|
name: import_joi75.default.string().optional().allow("", null),
|
|
32474
32572
|
type: import_joi75.default.string().optional().allow("", null),
|
|
32475
32573
|
size: import_joi75.default.number().optional().allow(null, ""),
|
|
32476
|
-
attachment: import_joi75.default.when("type", {
|
|
32574
|
+
attachment: import_joi75.default.when("type", {
|
|
32575
|
+
is: "folder",
|
|
32576
|
+
then: import_joi75.default.forbidden(),
|
|
32577
|
+
otherwise: import_joi75.default.alternatives().try(
|
|
32578
|
+
import_joi75.default.string().optional().allow("", null),
|
|
32579
|
+
import_joi75.default.array().items(import_joi75.default.string()).optional()
|
|
32580
|
+
)
|
|
32581
|
+
}),
|
|
32477
32582
|
remarks: import_joi75.default.string().optional().allow("", null),
|
|
32478
32583
|
org: import_joi75.default.string().hex().optional().allow("", null),
|
|
32479
32584
|
site: import_joi75.default.string().hex().optional().allow("", null),
|
|
32480
32585
|
parentId: import_joi75.default.string().hex().optional().allow("", null),
|
|
32481
|
-
updatedBy: import_joi75.default.string().hex().optional().allow("", null)
|
|
32482
|
-
updatedAt: import_joi75.default.date().optional().allow("", null),
|
|
32483
|
-
status: import_joi75.default.string().optional().allow("", null)
|
|
32586
|
+
updatedBy: import_joi75.default.string().hex().optional().allow("", null)
|
|
32484
32587
|
});
|
|
32485
32588
|
function MDocumentManagement(value) {
|
|
32486
32589
|
const { error } = schemaDocumentManagement.validate(value);
|
|
@@ -32827,9 +32930,37 @@ function useDocumentManagementRepo() {
|
|
|
32827
32930
|
|
|
32828
32931
|
// src/services/document-management.service.ts
|
|
32829
32932
|
var import_node_server_utils137 = require("@7365admin1/node-server-utils");
|
|
32933
|
+
var import_mongodb81 = require("mongodb");
|
|
32830
32934
|
function useDocumentManagementService() {
|
|
32831
32935
|
const { add: _add, updateDocumentById: _updateDocumentById } = useDocumentManagementRepo();
|
|
32832
32936
|
const { updateStatusById, getFileById } = useFileRepo();
|
|
32937
|
+
function normalizeAttachments(input) {
|
|
32938
|
+
if (!input)
|
|
32939
|
+
return [];
|
|
32940
|
+
if (typeof input === "string")
|
|
32941
|
+
return [{ id: input }];
|
|
32942
|
+
if (Array.isArray(input))
|
|
32943
|
+
return input.map(
|
|
32944
|
+
(it) => typeof it === "string" ? { id: it } : { id: it.id, name: it.name }
|
|
32945
|
+
);
|
|
32946
|
+
if (typeof input === "object")
|
|
32947
|
+
return [{ id: input.id, name: input.name }];
|
|
32948
|
+
return [];
|
|
32949
|
+
}
|
|
32950
|
+
function inferTypeFromName(name) {
|
|
32951
|
+
if (!name)
|
|
32952
|
+
return void 0;
|
|
32953
|
+
const lower = name.toLowerCase();
|
|
32954
|
+
if (lower.endsWith(".pdf"))
|
|
32955
|
+
return "pdf";
|
|
32956
|
+
if (lower.endsWith(".csv"))
|
|
32957
|
+
return "csv";
|
|
32958
|
+
if (lower.endsWith(".doc") || lower.endsWith(".docx"))
|
|
32959
|
+
return "doc";
|
|
32960
|
+
if (lower.endsWith(".xls") || lower.endsWith(".xlsx"))
|
|
32961
|
+
return "csv";
|
|
32962
|
+
return void 0;
|
|
32963
|
+
}
|
|
32833
32964
|
async function createDocument(value) {
|
|
32834
32965
|
const session = import_node_server_utils137.useAtlas.getClient()?.startSession();
|
|
32835
32966
|
if (!session) {
|
|
@@ -32837,21 +32968,97 @@ function useDocumentManagementService() {
|
|
|
32837
32968
|
}
|
|
32838
32969
|
try {
|
|
32839
32970
|
await session.startTransaction();
|
|
32840
|
-
|
|
32841
|
-
|
|
32842
|
-
|
|
32843
|
-
|
|
32844
|
-
|
|
32845
|
-
|
|
32846
|
-
|
|
32847
|
-
|
|
32848
|
-
|
|
32971
|
+
if ("items" in value && Array.isArray(value.items)) {
|
|
32972
|
+
for (const item of value.items) {
|
|
32973
|
+
const attachments = normalizeAttachments(item.attachment);
|
|
32974
|
+
let itemType = item.type;
|
|
32975
|
+
let itemSize = item.size ?? 0;
|
|
32976
|
+
if (attachments.length) {
|
|
32977
|
+
let totalSize = 0;
|
|
32978
|
+
for (const att of attachments) {
|
|
32979
|
+
await updateStatusById(att.id, { status: "active" }, session);
|
|
32980
|
+
try {
|
|
32981
|
+
const storedFile = await getFileById(att.id);
|
|
32982
|
+
if (storedFile) {
|
|
32983
|
+
totalSize += storedFile?.size ?? storedFile?.file_size ?? 0;
|
|
32984
|
+
if (!att.name) {
|
|
32985
|
+
att.name = storedFile?.name ?? att.id;
|
|
32986
|
+
}
|
|
32987
|
+
if (!att.type) {
|
|
32988
|
+
att.type = storedFile?.type ?? inferTypeFromName(att.name);
|
|
32989
|
+
}
|
|
32990
|
+
}
|
|
32991
|
+
} catch (err) {
|
|
32992
|
+
import_node_server_utils137.logger.log({
|
|
32993
|
+
level: "error",
|
|
32994
|
+
message: `Failed to retrieve file ${att.id}: ${err}`
|
|
32995
|
+
});
|
|
32996
|
+
}
|
|
32997
|
+
}
|
|
32998
|
+
item.attachment = attachments;
|
|
32999
|
+
itemSize = totalSize;
|
|
33000
|
+
const types = Array.from(
|
|
33001
|
+
new Set(attachments.map((a) => a.type).filter(Boolean))
|
|
33002
|
+
);
|
|
33003
|
+
if (types.length === 1) {
|
|
33004
|
+
itemType = types[0];
|
|
33005
|
+
} else if (types.length > 1) {
|
|
33006
|
+
itemType = "mixed";
|
|
33007
|
+
}
|
|
33008
|
+
}
|
|
33009
|
+
const doc = {
|
|
33010
|
+
_id: typeof item.id === "string" ? new import_mongodb81.ObjectId(item.id) : item.id,
|
|
33011
|
+
name: item.name || value.name,
|
|
33012
|
+
remarks: item.remarks || value.remarks,
|
|
33013
|
+
org: value.org,
|
|
33014
|
+
site: value.site,
|
|
33015
|
+
parentId: value.parentId,
|
|
33016
|
+
createdBy: value.createdBy,
|
|
33017
|
+
status: value.status || "active",
|
|
33018
|
+
attachment: item.attachment,
|
|
33019
|
+
type: itemType,
|
|
33020
|
+
size: itemSize
|
|
33021
|
+
};
|
|
33022
|
+
await _add(doc, session);
|
|
33023
|
+
}
|
|
33024
|
+
} else {
|
|
33025
|
+
const val = value;
|
|
33026
|
+
const attachments = normalizeAttachments(val.attachment);
|
|
33027
|
+
if (attachments.length) {
|
|
33028
|
+
let totalSize = 0;
|
|
33029
|
+
for (const att of attachments) {
|
|
33030
|
+
await updateStatusById(att.id, { status: "active" }, session);
|
|
33031
|
+
try {
|
|
33032
|
+
const storedFile = await getFileById(att.id);
|
|
33033
|
+
if (storedFile) {
|
|
33034
|
+
totalSize += storedFile?.size ?? storedFile?.file_size ?? 0;
|
|
33035
|
+
if (!att.name) {
|
|
33036
|
+
att.name = storedFile?.name ?? att.id;
|
|
33037
|
+
}
|
|
33038
|
+
if (!att.type) {
|
|
33039
|
+
att.type = storedFile?.type ?? inferTypeFromName(att.name);
|
|
33040
|
+
}
|
|
33041
|
+
}
|
|
33042
|
+
} catch (err) {
|
|
33043
|
+
import_node_server_utils137.logger.log({
|
|
33044
|
+
level: "error",
|
|
33045
|
+
message: `Failed to retrieve file ${att.id}: ${err}`
|
|
33046
|
+
});
|
|
33047
|
+
}
|
|
33048
|
+
}
|
|
33049
|
+
val.attachment = attachments;
|
|
33050
|
+
val.size = totalSize;
|
|
33051
|
+
const types = Array.from(
|
|
33052
|
+
new Set(attachments.map((a) => a.type).filter(Boolean))
|
|
33053
|
+
);
|
|
33054
|
+
if (types.length === 1) {
|
|
33055
|
+
val.type = types[0];
|
|
33056
|
+
} else if (types.length > 1) {
|
|
33057
|
+
val.type = "mixed";
|
|
33058
|
+
}
|
|
32849
33059
|
}
|
|
32850
|
-
|
|
32851
|
-
const storedFile = await getFileById2(document2);
|
|
32852
|
-
value.size = storedFile?.size ?? storedFile?.file_size ?? 0;
|
|
33060
|
+
await _add(val, session);
|
|
32853
33061
|
}
|
|
32854
|
-
await _add(value, session);
|
|
32855
33062
|
await session?.commitTransaction();
|
|
32856
33063
|
return "Successfully added document.";
|
|
32857
33064
|
} catch (error) {
|
|
@@ -32869,20 +33076,40 @@ function useDocumentManagementService() {
|
|
|
32869
33076
|
delete value.attachment;
|
|
32870
33077
|
delete value.size;
|
|
32871
33078
|
} else {
|
|
32872
|
-
|
|
32873
|
-
|
|
32874
|
-
|
|
32875
|
-
value.attachment = "";
|
|
32876
|
-
}
|
|
32877
|
-
if (value.attachment) {
|
|
32878
|
-
try {
|
|
32879
|
-
const f = await getFileById(value.attachment);
|
|
32880
|
-
value.size = f?.size ?? f?.file_size ?? 0;
|
|
32881
|
-
} catch (err) {
|
|
32882
|
-
value.size = 0;
|
|
32883
|
-
}
|
|
32884
|
-
} else {
|
|
33079
|
+
const attachments = normalizeAttachments(value.attachment);
|
|
33080
|
+
if (!attachments.length) {
|
|
33081
|
+
value.attachment = [];
|
|
32885
33082
|
value.size = 0;
|
|
33083
|
+
} else {
|
|
33084
|
+
let totalSize = 0;
|
|
33085
|
+
for (const att of attachments) {
|
|
33086
|
+
try {
|
|
33087
|
+
const f = await getFileById(att.id);
|
|
33088
|
+
if (f) {
|
|
33089
|
+
totalSize += f?.size ?? f?.file_size ?? 0;
|
|
33090
|
+
if (!att.name)
|
|
33091
|
+
att.name = f?.name ?? att.id;
|
|
33092
|
+
if (!att.type) {
|
|
33093
|
+
att.type = f?.type ?? inferTypeFromName(att.name);
|
|
33094
|
+
}
|
|
33095
|
+
}
|
|
33096
|
+
} catch (err) {
|
|
33097
|
+
import_node_server_utils137.logger.log({
|
|
33098
|
+
level: "error",
|
|
33099
|
+
message: `Failed to retrieve file ${att.id}: ${err}`
|
|
33100
|
+
});
|
|
33101
|
+
}
|
|
33102
|
+
}
|
|
33103
|
+
value.attachment = attachments;
|
|
33104
|
+
value.size = totalSize;
|
|
33105
|
+
const types = Array.from(
|
|
33106
|
+
new Set(attachments.map((a) => a.type).filter(Boolean))
|
|
33107
|
+
);
|
|
33108
|
+
if (types.length === 1) {
|
|
33109
|
+
value.type = types[0];
|
|
33110
|
+
} else if (types.length > 1) {
|
|
33111
|
+
value.type = "mixed";
|
|
33112
|
+
}
|
|
32886
33113
|
}
|
|
32887
33114
|
}
|
|
32888
33115
|
return await _updateDocumentById(_id, value);
|
|
@@ -32922,13 +33149,10 @@ function useDocumentManagementController() {
|
|
|
32922
33149
|
if (payload.type === "folder") {
|
|
32923
33150
|
delete payload.attachment;
|
|
32924
33151
|
} else {
|
|
32925
|
-
if (Array.isArray(payload.attachment)) {
|
|
32926
|
-
payload.attachment = payload.attachment[0];
|
|
32927
|
-
} else if (!payload.attachment) {
|
|
32928
|
-
payload.attachment = "";
|
|
32929
|
-
}
|
|
32930
33152
|
}
|
|
32931
|
-
const
|
|
33153
|
+
const hasItems = Array.isArray(payload.items);
|
|
33154
|
+
const schema2 = hasItems ? schemaMultipleDocumentManagement : schemaDocumentManagement;
|
|
33155
|
+
const { error } = schema2.validate(payload, {
|
|
32932
33156
|
abortEarly: false
|
|
32933
33157
|
});
|
|
32934
33158
|
if (error) {
|
|
@@ -33009,14 +33233,6 @@ function useDocumentManagementController() {
|
|
|
33009
33233
|
}
|
|
33010
33234
|
}
|
|
33011
33235
|
async function updateDocumentById(req, res, next) {
|
|
33012
|
-
const validation = import_joi76.default.object({
|
|
33013
|
-
_id: import_joi76.default.string().hex().required(),
|
|
33014
|
-
attachment: import_joi76.default.string().optional(),
|
|
33015
|
-
name: import_joi76.default.string().required(),
|
|
33016
|
-
type: import_joi76.default.string().optional().allow("", null),
|
|
33017
|
-
status: import_joi76.default.string().optional().allow("", null),
|
|
33018
|
-
updatedBy: import_joi76.default.string().hex().optional().allow("", null)
|
|
33019
|
-
});
|
|
33020
33236
|
const cookies = req.headers.cookie?.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
33021
33237
|
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
33022
33238
|
{}
|
|
@@ -33038,7 +33254,10 @@ function useDocumentManagementController() {
|
|
|
33038
33254
|
if (payload.size !== void 0) {
|
|
33039
33255
|
delete payload.size;
|
|
33040
33256
|
}
|
|
33041
|
-
const { error } =
|
|
33257
|
+
const { error } = schemaUpdateDocumentManagement.validate(
|
|
33258
|
+
{ _id, ...payload },
|
|
33259
|
+
{ abortEarly: false }
|
|
33260
|
+
);
|
|
33042
33261
|
if (error) {
|
|
33043
33262
|
import_node_server_utils138.logger.log({ level: "error", message: error.message });
|
|
33044
33263
|
next(new import_node_server_utils138.BadRequestError(error.message));
|
|
@@ -33105,7 +33324,7 @@ function useDocumentManagementController() {
|
|
|
33105
33324
|
|
|
33106
33325
|
// src/models/bulletin-board.model.ts
|
|
33107
33326
|
var import_joi77 = __toESM(require("joi"));
|
|
33108
|
-
var
|
|
33327
|
+
var import_mongodb82 = require("mongodb");
|
|
33109
33328
|
var BulletinRecipient = /* @__PURE__ */ ((BulletinRecipient2) => {
|
|
33110
33329
|
BulletinRecipient2["RESIDENT"] = "resident";
|
|
33111
33330
|
BulletinRecipient2["SECURITY_AGENCY"] = "security_agency";
|
|
@@ -33185,21 +33404,21 @@ function MBulletinBoard(value) {
|
|
|
33185
33404
|
}
|
|
33186
33405
|
if (value._id && typeof value._id === "string") {
|
|
33187
33406
|
try {
|
|
33188
|
-
value._id = new
|
|
33407
|
+
value._id = new import_mongodb82.ObjectId(value._id);
|
|
33189
33408
|
} catch {
|
|
33190
33409
|
throw new Error("Invalid ID.");
|
|
33191
33410
|
}
|
|
33192
33411
|
}
|
|
33193
33412
|
if (value.site && typeof value.site === "string") {
|
|
33194
33413
|
try {
|
|
33195
|
-
value.site = new
|
|
33414
|
+
value.site = new import_mongodb82.ObjectId(value.site);
|
|
33196
33415
|
} catch {
|
|
33197
33416
|
throw new Error("Invalid site ID.");
|
|
33198
33417
|
}
|
|
33199
33418
|
}
|
|
33200
33419
|
if (value.orgId && typeof value.orgId === "string") {
|
|
33201
33420
|
try {
|
|
33202
|
-
value.orgId = new
|
|
33421
|
+
value.orgId = new import_mongodb82.ObjectId(value.orgId);
|
|
33203
33422
|
} catch {
|
|
33204
33423
|
throw new Error("Invalid org ID.");
|
|
33205
33424
|
}
|
|
@@ -33208,7 +33427,7 @@ function MBulletinBoard(value) {
|
|
|
33208
33427
|
value.file = value.file.map((f) => {
|
|
33209
33428
|
if (f._id && typeof f._id === "string") {
|
|
33210
33429
|
try {
|
|
33211
|
-
return { ...f, _id: new
|
|
33430
|
+
return { ...f, _id: new import_mongodb82.ObjectId(f._id) };
|
|
33212
33431
|
} catch {
|
|
33213
33432
|
throw new Error("Invalid file ID.");
|
|
33214
33433
|
}
|
|
@@ -33217,7 +33436,7 @@ function MBulletinBoard(value) {
|
|
|
33217
33436
|
});
|
|
33218
33437
|
}
|
|
33219
33438
|
return {
|
|
33220
|
-
_id: value._id ?? new
|
|
33439
|
+
_id: value._id ?? new import_mongodb82.ObjectId(),
|
|
33221
33440
|
site: value.site ?? "",
|
|
33222
33441
|
orgId: value.orgId ?? "",
|
|
33223
33442
|
recipients: value.recipients ?? [],
|
|
@@ -33236,7 +33455,7 @@ function MBulletinBoard(value) {
|
|
|
33236
33455
|
|
|
33237
33456
|
// src/repositories/bulletin-board.repo.ts
|
|
33238
33457
|
var import_node_server_utils139 = require("@7365admin1/node-server-utils");
|
|
33239
|
-
var
|
|
33458
|
+
var import_mongodb83 = require("mongodb");
|
|
33240
33459
|
var bulletin_boards_namespace_collection = "bulletin-boards";
|
|
33241
33460
|
function useBulletinBoardRepo() {
|
|
33242
33461
|
const db = import_node_server_utils139.useAtlas.getDb();
|
|
@@ -33289,7 +33508,7 @@ function useBulletinBoardRepo() {
|
|
|
33289
33508
|
}, session) {
|
|
33290
33509
|
page = page > 0 ? page - 1 : 0;
|
|
33291
33510
|
try {
|
|
33292
|
-
site = new
|
|
33511
|
+
site = new import_mongodb83.ObjectId(site);
|
|
33293
33512
|
} catch (error) {
|
|
33294
33513
|
throw new import_node_server_utils139.BadRequestError("Invalid site ID format.");
|
|
33295
33514
|
}
|
|
@@ -33348,7 +33567,7 @@ function useBulletinBoardRepo() {
|
|
|
33348
33567
|
}
|
|
33349
33568
|
async function getBulletinBoardById(_id, session) {
|
|
33350
33569
|
try {
|
|
33351
|
-
_id = new
|
|
33570
|
+
_id = new import_mongodb83.ObjectId(_id);
|
|
33352
33571
|
} catch (error) {
|
|
33353
33572
|
throw new import_node_server_utils139.BadRequestError("Invalid bulletin board ID format.");
|
|
33354
33573
|
}
|
|
@@ -33378,13 +33597,13 @@ function useBulletinBoardRepo() {
|
|
|
33378
33597
|
async function updateBulletinBoardById(_id, value, session) {
|
|
33379
33598
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
33380
33599
|
try {
|
|
33381
|
-
_id = new
|
|
33600
|
+
_id = new import_mongodb83.ObjectId(_id);
|
|
33382
33601
|
} catch (error) {
|
|
33383
33602
|
throw new import_node_server_utils139.BadRequestError("Invalid ID format.");
|
|
33384
33603
|
}
|
|
33385
33604
|
if (value.site && typeof value.site === "string") {
|
|
33386
33605
|
try {
|
|
33387
|
-
value.site = new
|
|
33606
|
+
value.site = new import_mongodb83.ObjectId(value.site);
|
|
33388
33607
|
} catch {
|
|
33389
33608
|
throw new Error("Invalid site ID.");
|
|
33390
33609
|
}
|
|
@@ -33415,7 +33634,7 @@ function useBulletinBoardRepo() {
|
|
|
33415
33634
|
}
|
|
33416
33635
|
async function deleteBulletinBoardById(_id, session) {
|
|
33417
33636
|
try {
|
|
33418
|
-
_id = new
|
|
33637
|
+
_id = new import_mongodb83.ObjectId(_id);
|
|
33419
33638
|
} catch (error) {
|
|
33420
33639
|
throw new import_node_server_utils139.BadRequestError("Invalid bulletin board ID format.");
|
|
33421
33640
|
}
|
|
@@ -33849,7 +34068,7 @@ function useBulletinBoardController() {
|
|
|
33849
34068
|
|
|
33850
34069
|
// src/models/site-billing-item.model.ts
|
|
33851
34070
|
var import_node_server_utils142 = require("@7365admin1/node-server-utils");
|
|
33852
|
-
var
|
|
34071
|
+
var import_mongodb84 = require("mongodb");
|
|
33853
34072
|
var import_joi79 = __toESM(require("joi"));
|
|
33854
34073
|
|
|
33855
34074
|
// src/types/enums/billing-frequency.enum.ts
|
|
@@ -33920,21 +34139,21 @@ function MBillingItem(value) {
|
|
|
33920
34139
|
}
|
|
33921
34140
|
if (value._id && typeof value._id === "string") {
|
|
33922
34141
|
try {
|
|
33923
|
-
value._id = new
|
|
34142
|
+
value._id = new import_mongodb84.ObjectId(value._id);
|
|
33924
34143
|
} catch {
|
|
33925
34144
|
throw new import_node_server_utils142.BadRequestError("Invalid _id format");
|
|
33926
34145
|
}
|
|
33927
34146
|
}
|
|
33928
34147
|
if (value.site && typeof value.site === "string") {
|
|
33929
34148
|
try {
|
|
33930
|
-
value.site = new
|
|
34149
|
+
value.site = new import_mongodb84.ObjectId(value.site);
|
|
33931
34150
|
} catch {
|
|
33932
34151
|
throw new import_node_server_utils142.BadRequestError("Invalid site id format");
|
|
33933
34152
|
}
|
|
33934
34153
|
}
|
|
33935
34154
|
if (value.org && typeof value.org === "string") {
|
|
33936
34155
|
try {
|
|
33937
|
-
value.org = new
|
|
34156
|
+
value.org = new import_mongodb84.ObjectId(value.org);
|
|
33938
34157
|
} catch {
|
|
33939
34158
|
throw new import_node_server_utils142.BadRequestError("Invalid org id format");
|
|
33940
34159
|
}
|
|
@@ -33943,7 +34162,7 @@ function MBillingItem(value) {
|
|
|
33943
34162
|
value.units = value.units.map((unit) => {
|
|
33944
34163
|
if (unit._id && typeof unit._id === "string") {
|
|
33945
34164
|
try {
|
|
33946
|
-
unit._id = new
|
|
34165
|
+
unit._id = new import_mongodb84.ObjectId(unit._id);
|
|
33947
34166
|
} catch {
|
|
33948
34167
|
throw new import_node_server_utils142.BadRequestError("Invalid unit id format");
|
|
33949
34168
|
}
|
|
@@ -33952,7 +34171,7 @@ function MBillingItem(value) {
|
|
|
33952
34171
|
});
|
|
33953
34172
|
}
|
|
33954
34173
|
return {
|
|
33955
|
-
_id: value._id ?? new
|
|
34174
|
+
_id: value._id ?? new import_mongodb84.ObjectId(),
|
|
33956
34175
|
site: value.site,
|
|
33957
34176
|
org: value.org,
|
|
33958
34177
|
name: value.name,
|
|
@@ -33980,7 +34199,7 @@ function MBillingItem(value) {
|
|
|
33980
34199
|
|
|
33981
34200
|
// src/repositories/site-billing-item.repo.ts
|
|
33982
34201
|
var import_node_server_utils143 = require("@7365admin1/node-server-utils");
|
|
33983
|
-
var
|
|
34202
|
+
var import_mongodb85 = require("mongodb");
|
|
33984
34203
|
function useSiteBillingItemRepo() {
|
|
33985
34204
|
const db = import_node_server_utils143.useAtlas.getDb();
|
|
33986
34205
|
if (!db) {
|
|
@@ -34067,7 +34286,7 @@ function useSiteBillingItemRepo() {
|
|
|
34067
34286
|
}
|
|
34068
34287
|
]
|
|
34069
34288
|
},
|
|
34070
|
-
...
|
|
34289
|
+
...import_mongodb85.ObjectId.isValid(site) && { site: new import_mongodb85.ObjectId(site) }
|
|
34071
34290
|
};
|
|
34072
34291
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
34073
34292
|
const cacheOptions = {
|
|
@@ -34107,7 +34326,7 @@ function useSiteBillingItemRepo() {
|
|
|
34107
34326
|
}
|
|
34108
34327
|
async function getById(_id, session) {
|
|
34109
34328
|
try {
|
|
34110
|
-
_id = new
|
|
34329
|
+
_id = new import_mongodb85.ObjectId(_id);
|
|
34111
34330
|
} catch (error) {
|
|
34112
34331
|
throw new import_node_server_utils143.BadRequestError("Invalid ID.");
|
|
34113
34332
|
}
|
|
@@ -34146,22 +34365,22 @@ function useSiteBillingItemRepo() {
|
|
|
34146
34365
|
}
|
|
34147
34366
|
async function updateById(_id, value, session) {
|
|
34148
34367
|
try {
|
|
34149
|
-
_id = new
|
|
34368
|
+
_id = new import_mongodb85.ObjectId(_id);
|
|
34150
34369
|
} catch (error) {
|
|
34151
34370
|
throw new import_node_server_utils143.BadRequestError(
|
|
34152
34371
|
"Invalid site billing item transaction ID format."
|
|
34153
34372
|
);
|
|
34154
34373
|
}
|
|
34155
|
-
if (value.site &&
|
|
34374
|
+
if (value.site && import_mongodb85.ObjectId.isValid(value.site.toString())) {
|
|
34156
34375
|
try {
|
|
34157
|
-
value.site = new
|
|
34376
|
+
value.site = new import_mongodb85.ObjectId(value.site.toString());
|
|
34158
34377
|
} catch {
|
|
34159
34378
|
throw new import_node_server_utils143.BadRequestError("Invalid _id format");
|
|
34160
34379
|
}
|
|
34161
34380
|
}
|
|
34162
|
-
if (value.org &&
|
|
34381
|
+
if (value.org && import_mongodb85.ObjectId.isValid(value.org.toString())) {
|
|
34163
34382
|
try {
|
|
34164
|
-
value.org = new
|
|
34383
|
+
value.org = new import_mongodb85.ObjectId(value.org.toString());
|
|
34165
34384
|
} catch {
|
|
34166
34385
|
throw new import_node_server_utils143.BadRequestError("Invalid _id format");
|
|
34167
34386
|
}
|
|
@@ -34181,7 +34400,7 @@ function useSiteBillingItemRepo() {
|
|
|
34181
34400
|
}
|
|
34182
34401
|
async function deleteById(_id) {
|
|
34183
34402
|
try {
|
|
34184
|
-
_id = new
|
|
34403
|
+
_id = new import_mongodb85.ObjectId(_id);
|
|
34185
34404
|
} catch (error) {
|
|
34186
34405
|
throw new import_node_server_utils143.BadRequestError(
|
|
34187
34406
|
"Invalid site billing item transaction ID format."
|
|
@@ -34238,7 +34457,7 @@ var import_node_server_utils145 = require("@7365admin1/node-server-utils");
|
|
|
34238
34457
|
|
|
34239
34458
|
// src/models/site-billing-configuration.model.ts
|
|
34240
34459
|
var import_node_server_utils144 = require("@7365admin1/node-server-utils");
|
|
34241
|
-
var
|
|
34460
|
+
var import_mongodb86 = require("mongodb");
|
|
34242
34461
|
var import_joi80 = __toESM(require("joi"));
|
|
34243
34462
|
var schemaBillingConfiguration = import_joi80.default.object({
|
|
34244
34463
|
_id: import_joi80.default.string().hex().optional(),
|
|
@@ -34299,34 +34518,34 @@ function MBillingConfiguration(value) {
|
|
|
34299
34518
|
}
|
|
34300
34519
|
if (value._id && typeof value._id === "string") {
|
|
34301
34520
|
try {
|
|
34302
|
-
value._id = new
|
|
34521
|
+
value._id = new import_mongodb86.ObjectId(value._id);
|
|
34303
34522
|
} catch {
|
|
34304
34523
|
throw new import_node_server_utils144.BadRequestError("Invalid _id format");
|
|
34305
34524
|
}
|
|
34306
34525
|
}
|
|
34307
34526
|
if (value.site && typeof value.site === "string") {
|
|
34308
34527
|
try {
|
|
34309
|
-
value.site = new
|
|
34528
|
+
value.site = new import_mongodb86.ObjectId(value.site);
|
|
34310
34529
|
} catch {
|
|
34311
34530
|
throw new import_node_server_utils144.BadRequestError("Invalid site id format");
|
|
34312
34531
|
}
|
|
34313
34532
|
}
|
|
34314
34533
|
if (value.org && typeof value.org === "string") {
|
|
34315
34534
|
try {
|
|
34316
|
-
value.org = new
|
|
34535
|
+
value.org = new import_mongodb86.ObjectId(value.org);
|
|
34317
34536
|
} catch {
|
|
34318
34537
|
throw new import_node_server_utils144.BadRequestError("Invalid org id format");
|
|
34319
34538
|
}
|
|
34320
34539
|
}
|
|
34321
34540
|
if (value.createdBy && typeof value.createdBy === "string") {
|
|
34322
34541
|
try {
|
|
34323
|
-
value.createdBy = new
|
|
34542
|
+
value.createdBy = new import_mongodb86.ObjectId(value.createdBy);
|
|
34324
34543
|
} catch {
|
|
34325
34544
|
throw new import_node_server_utils144.BadRequestError("Invalid createdBy id format");
|
|
34326
34545
|
}
|
|
34327
34546
|
}
|
|
34328
34547
|
return {
|
|
34329
|
-
_id: value._id ?? new
|
|
34548
|
+
_id: value._id ?? new import_mongodb86.ObjectId(),
|
|
34330
34549
|
site: value.site,
|
|
34331
34550
|
org: value.org,
|
|
34332
34551
|
siteName: value.siteName,
|
|
@@ -34355,7 +34574,7 @@ function MBillingConfiguration(value) {
|
|
|
34355
34574
|
}
|
|
34356
34575
|
|
|
34357
34576
|
// src/repositories/site-billing-configuration.repo.ts
|
|
34358
|
-
var
|
|
34577
|
+
var import_mongodb87 = require("mongodb");
|
|
34359
34578
|
function useSiteBillingConfigurationRepo() {
|
|
34360
34579
|
const db = import_node_server_utils145.useAtlas.getDb();
|
|
34361
34580
|
if (!db) {
|
|
@@ -34428,7 +34647,7 @@ function useSiteBillingConfigurationRepo() {
|
|
|
34428
34647
|
const query = {
|
|
34429
34648
|
status,
|
|
34430
34649
|
...search && { $text: { $search: search } },
|
|
34431
|
-
...
|
|
34650
|
+
...import_mongodb87.ObjectId.isValid(site) && { site: new import_mongodb87.ObjectId(site) }
|
|
34432
34651
|
};
|
|
34433
34652
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
34434
34653
|
const cacheOptions = {
|
|
@@ -34468,7 +34687,7 @@ function useSiteBillingConfigurationRepo() {
|
|
|
34468
34687
|
}
|
|
34469
34688
|
async function getById(_id) {
|
|
34470
34689
|
try {
|
|
34471
|
-
_id = new
|
|
34690
|
+
_id = new import_mongodb87.ObjectId(_id);
|
|
34472
34691
|
} catch (error) {
|
|
34473
34692
|
throw new import_node_server_utils145.BadRequestError("Invalid ID.");
|
|
34474
34693
|
}
|
|
@@ -34509,22 +34728,22 @@ function useSiteBillingConfigurationRepo() {
|
|
|
34509
34728
|
}
|
|
34510
34729
|
async function updateById(_id, value, session) {
|
|
34511
34730
|
try {
|
|
34512
|
-
_id = new
|
|
34731
|
+
_id = new import_mongodb87.ObjectId(_id);
|
|
34513
34732
|
} catch (error) {
|
|
34514
34733
|
throw new import_node_server_utils145.BadRequestError(
|
|
34515
34734
|
"Invalid site billing configuration transaction ID format."
|
|
34516
34735
|
);
|
|
34517
34736
|
}
|
|
34518
|
-
if (value.site &&
|
|
34737
|
+
if (value.site && import_mongodb87.ObjectId.isValid(value.site.toString())) {
|
|
34519
34738
|
try {
|
|
34520
|
-
value.site = new
|
|
34739
|
+
value.site = new import_mongodb87.ObjectId(value.site.toString());
|
|
34521
34740
|
} catch {
|
|
34522
34741
|
throw new import_node_server_utils145.BadRequestError("Invalid _id format");
|
|
34523
34742
|
}
|
|
34524
34743
|
}
|
|
34525
|
-
if (value.org &&
|
|
34744
|
+
if (value.org && import_mongodb87.ObjectId.isValid(value.org.toString())) {
|
|
34526
34745
|
try {
|
|
34527
|
-
value.org = new
|
|
34746
|
+
value.org = new import_mongodb87.ObjectId(value.org.toString());
|
|
34528
34747
|
} catch {
|
|
34529
34748
|
throw new import_node_server_utils145.BadRequestError("Invalid _id format");
|
|
34530
34749
|
}
|
|
@@ -34544,7 +34763,7 @@ function useSiteBillingConfigurationRepo() {
|
|
|
34544
34763
|
}
|
|
34545
34764
|
async function deleteById(_id) {
|
|
34546
34765
|
try {
|
|
34547
|
-
_id = new
|
|
34766
|
+
_id = new import_mongodb87.ObjectId(_id);
|
|
34548
34767
|
} catch (error) {
|
|
34549
34768
|
throw new import_node_server_utils145.BadRequestError(
|
|
34550
34769
|
"Invalid site billing configuration transaction ID format."
|
|
@@ -35122,7 +35341,7 @@ function useSiteBillingConfigurationController() {
|
|
|
35122
35341
|
}
|
|
35123
35342
|
|
|
35124
35343
|
// src/models/event-management.model.ts
|
|
35125
|
-
var
|
|
35344
|
+
var import_mongodb88 = require("mongodb");
|
|
35126
35345
|
var import_joi83 = __toESM(require("joi"));
|
|
35127
35346
|
var EventStatus = /* @__PURE__ */ ((EventStatus2) => {
|
|
35128
35347
|
EventStatus2["PLANNED"] = "planned";
|
|
@@ -35166,20 +35385,20 @@ var schemaUpdateEventManagement = import_joi83.default.object({
|
|
|
35166
35385
|
function MEventManagement(value) {
|
|
35167
35386
|
if (value._id && typeof value._id === "string") {
|
|
35168
35387
|
try {
|
|
35169
|
-
value._id = new
|
|
35388
|
+
value._id = new import_mongodb88.ObjectId(value._id);
|
|
35170
35389
|
} catch {
|
|
35171
35390
|
throw new Error("Invalid ID.");
|
|
35172
35391
|
}
|
|
35173
35392
|
}
|
|
35174
35393
|
if (value.site && typeof value.site === "string") {
|
|
35175
35394
|
try {
|
|
35176
|
-
value.site = new
|
|
35395
|
+
value.site = new import_mongodb88.ObjectId(value.site);
|
|
35177
35396
|
} catch {
|
|
35178
35397
|
throw new Error("Invalid site ID.");
|
|
35179
35398
|
}
|
|
35180
35399
|
}
|
|
35181
35400
|
return {
|
|
35182
|
-
_id: value._id ?? new
|
|
35401
|
+
_id: value._id ?? new import_mongodb88.ObjectId(),
|
|
35183
35402
|
site: value.site,
|
|
35184
35403
|
title: value.title,
|
|
35185
35404
|
description: value.description ?? "",
|
|
@@ -35194,7 +35413,7 @@ function MEventManagement(value) {
|
|
|
35194
35413
|
|
|
35195
35414
|
// src/repositories/event-management.repo.ts
|
|
35196
35415
|
var import_node_server_utils150 = require("@7365admin1/node-server-utils");
|
|
35197
|
-
var
|
|
35416
|
+
var import_mongodb89 = require("mongodb");
|
|
35198
35417
|
var events_namespace_collection = "event-management";
|
|
35199
35418
|
function useEventManagementRepo() {
|
|
35200
35419
|
const db = import_node_server_utils150.useAtlas.getDb();
|
|
@@ -35262,7 +35481,7 @@ function useEventManagementRepo() {
|
|
|
35262
35481
|
}, session) {
|
|
35263
35482
|
page = page > 0 ? page - 1 : 0;
|
|
35264
35483
|
try {
|
|
35265
|
-
site = new
|
|
35484
|
+
site = new import_mongodb89.ObjectId(site);
|
|
35266
35485
|
} catch (error) {
|
|
35267
35486
|
throw new import_node_server_utils150.BadRequestError("Invalid site ID format.");
|
|
35268
35487
|
}
|
|
@@ -35350,7 +35569,7 @@ function useEventManagementRepo() {
|
|
|
35350
35569
|
}
|
|
35351
35570
|
async function getEventManagementById(_id, session) {
|
|
35352
35571
|
try {
|
|
35353
|
-
_id = new
|
|
35572
|
+
_id = new import_mongodb89.ObjectId(_id);
|
|
35354
35573
|
} catch (error) {
|
|
35355
35574
|
throw new import_node_server_utils150.BadRequestError("Invalid event ID format.");
|
|
35356
35575
|
}
|
|
@@ -35378,13 +35597,13 @@ function useEventManagementRepo() {
|
|
|
35378
35597
|
async function updateEventManagementById(_id, value, session) {
|
|
35379
35598
|
value.updatedAt = /* @__PURE__ */ new Date();
|
|
35380
35599
|
try {
|
|
35381
|
-
_id = new
|
|
35600
|
+
_id = new import_mongodb89.ObjectId(_id);
|
|
35382
35601
|
} catch (error) {
|
|
35383
35602
|
throw new import_node_server_utils150.BadRequestError("Invalid ID format.");
|
|
35384
35603
|
}
|
|
35385
35604
|
if (value.site && typeof value.site === "string") {
|
|
35386
35605
|
try {
|
|
35387
|
-
value.site = new
|
|
35606
|
+
value.site = new import_mongodb89.ObjectId(value.site);
|
|
35388
35607
|
} catch {
|
|
35389
35608
|
throw new Error("Invalid site ID.");
|
|
35390
35609
|
}
|
|
@@ -35415,7 +35634,7 @@ function useEventManagementRepo() {
|
|
|
35415
35634
|
}
|
|
35416
35635
|
async function deleteEventManagementById(_id) {
|
|
35417
35636
|
try {
|
|
35418
|
-
_id = new
|
|
35637
|
+
_id = new import_mongodb89.ObjectId(_id);
|
|
35419
35638
|
} catch (error) {
|
|
35420
35639
|
throw new import_node_server_utils150.BadRequestError("Invalid event ID format.");
|
|
35421
35640
|
}
|
|
@@ -35703,7 +35922,7 @@ function useEventManagementController() {
|
|
|
35703
35922
|
|
|
35704
35923
|
// src/models/site-unit-billing.model.ts
|
|
35705
35924
|
var import_node_server_utils153 = require("@7365admin1/node-server-utils");
|
|
35706
|
-
var
|
|
35925
|
+
var import_mongodb90 = require("mongodb");
|
|
35707
35926
|
var import_joi85 = __toESM(require("joi"));
|
|
35708
35927
|
var Status = /* @__PURE__ */ ((Status2) => {
|
|
35709
35928
|
Status2["PENDING"] = "pending";
|
|
@@ -35798,48 +36017,48 @@ function MUnitBilling(value) {
|
|
|
35798
36017
|
}
|
|
35799
36018
|
if (value._id && typeof value._id === "string") {
|
|
35800
36019
|
try {
|
|
35801
|
-
value._id = new
|
|
36020
|
+
value._id = new import_mongodb90.ObjectId(value._id);
|
|
35802
36021
|
} catch {
|
|
35803
36022
|
throw new import_node_server_utils153.BadRequestError("Invalid _id format");
|
|
35804
36023
|
}
|
|
35805
36024
|
}
|
|
35806
36025
|
if (value.site && typeof value.site === "string") {
|
|
35807
36026
|
try {
|
|
35808
|
-
value.site = new
|
|
36027
|
+
value.site = new import_mongodb90.ObjectId(value.site);
|
|
35809
36028
|
} catch {
|
|
35810
36029
|
throw new import_node_server_utils153.BadRequestError("Invalid site id format");
|
|
35811
36030
|
}
|
|
35812
36031
|
}
|
|
35813
36032
|
if (value.org && typeof value.org === "string") {
|
|
35814
36033
|
try {
|
|
35815
|
-
value.org = new
|
|
36034
|
+
value.org = new import_mongodb90.ObjectId(value.org);
|
|
35816
36035
|
} catch {
|
|
35817
36036
|
throw new import_node_server_utils153.BadRequestError("Invalid org id format");
|
|
35818
36037
|
}
|
|
35819
36038
|
}
|
|
35820
36039
|
if (value.paidBy && typeof value.paidBy === "string") {
|
|
35821
36040
|
try {
|
|
35822
|
-
value.paidBy = new
|
|
36041
|
+
value.paidBy = new import_mongodb90.ObjectId(value.paidBy);
|
|
35823
36042
|
} catch {
|
|
35824
36043
|
throw new import_node_server_utils153.BadRequestError("Invalid paidBy id format");
|
|
35825
36044
|
}
|
|
35826
36045
|
}
|
|
35827
36046
|
if (value.billItem && typeof value.billItem === "string") {
|
|
35828
36047
|
try {
|
|
35829
|
-
value.billItem = new
|
|
36048
|
+
value.billItem = new import_mongodb90.ObjectId(value.billItem);
|
|
35830
36049
|
} catch {
|
|
35831
36050
|
throw new import_node_server_utils153.BadRequestError("Invalid billItem id format");
|
|
35832
36051
|
}
|
|
35833
36052
|
}
|
|
35834
36053
|
if (value.unitId && typeof value.unitId === "string") {
|
|
35835
36054
|
try {
|
|
35836
|
-
value.unitId = new
|
|
36055
|
+
value.unitId = new import_mongodb90.ObjectId(value.unitId);
|
|
35837
36056
|
} catch {
|
|
35838
36057
|
throw new import_node_server_utils153.BadRequestError("Invalid unitId id format");
|
|
35839
36058
|
}
|
|
35840
36059
|
}
|
|
35841
36060
|
return {
|
|
35842
|
-
_id: value._id ?? new
|
|
36061
|
+
_id: value._id ?? new import_mongodb90.ObjectId(),
|
|
35843
36062
|
site: value.site ?? "",
|
|
35844
36063
|
org: value.org ?? "",
|
|
35845
36064
|
billItem: value.billItem ?? "",
|
|
@@ -35875,7 +36094,7 @@ function MUnitBilling(value) {
|
|
|
35875
36094
|
|
|
35876
36095
|
// src/repositories/site-unit-billing.repo.ts
|
|
35877
36096
|
var import_node_server_utils154 = require("@7365admin1/node-server-utils");
|
|
35878
|
-
var
|
|
36097
|
+
var import_mongodb91 = require("mongodb");
|
|
35879
36098
|
function useSiteUnitBillingRepo() {
|
|
35880
36099
|
const db = import_node_server_utils154.useAtlas.getDb();
|
|
35881
36100
|
if (!db) {
|
|
@@ -35925,7 +36144,7 @@ function useSiteUnitBillingRepo() {
|
|
|
35925
36144
|
const res = await collection.insertOne(value, { session });
|
|
35926
36145
|
const acronym = createAcronym(value.billName || "NA");
|
|
35927
36146
|
const dateFormatted = formatDateString(/* @__PURE__ */ new Date());
|
|
35928
|
-
const newId = new
|
|
36147
|
+
const newId = new import_mongodb91.ObjectId(res.insertedId).toString().slice(-6);
|
|
35929
36148
|
const referenceNumber = `${acronym}${newId}${dateFormatted}`;
|
|
35930
36149
|
await collection.updateOne(
|
|
35931
36150
|
{ _id: res.insertedId },
|
|
@@ -36003,7 +36222,7 @@ function useSiteUnitBillingRepo() {
|
|
|
36003
36222
|
}
|
|
36004
36223
|
]
|
|
36005
36224
|
},
|
|
36006
|
-
...
|
|
36225
|
+
...import_mongodb91.ObjectId.isValid(site) && { site: new import_mongodb91.ObjectId(site) },
|
|
36007
36226
|
...dateExpr
|
|
36008
36227
|
};
|
|
36009
36228
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
@@ -36069,7 +36288,7 @@ function useSiteUnitBillingRepo() {
|
|
|
36069
36288
|
}
|
|
36070
36289
|
async function getById(_id) {
|
|
36071
36290
|
try {
|
|
36072
|
-
_id = new
|
|
36291
|
+
_id = new import_mongodb91.ObjectId(_id);
|
|
36073
36292
|
} catch (error) {
|
|
36074
36293
|
throw new import_node_server_utils154.BadRequestError("Invalid ID.");
|
|
36075
36294
|
}
|
|
@@ -36128,8 +36347,8 @@ function useSiteUnitBillingRepo() {
|
|
|
36128
36347
|
}
|
|
36129
36348
|
const query = {
|
|
36130
36349
|
status,
|
|
36131
|
-
...unitId &&
|
|
36132
|
-
...site &&
|
|
36350
|
+
...unitId && import_mongodb91.ObjectId.isValid(unitId) && { unitId: new import_mongodb91.ObjectId(unitId) },
|
|
36351
|
+
...site && import_mongodb91.ObjectId.isValid(site) && { site: new import_mongodb91.ObjectId(site) },
|
|
36133
36352
|
...dateExpr
|
|
36134
36353
|
};
|
|
36135
36354
|
try {
|
|
@@ -36167,43 +36386,43 @@ function useSiteUnitBillingRepo() {
|
|
|
36167
36386
|
}
|
|
36168
36387
|
async function updateById(_id, value, session) {
|
|
36169
36388
|
try {
|
|
36170
|
-
_id = new
|
|
36389
|
+
_id = new import_mongodb91.ObjectId(_id);
|
|
36171
36390
|
} catch (error) {
|
|
36172
36391
|
throw new import_node_server_utils154.BadRequestError(
|
|
36173
36392
|
"Invalid site unit billing transaction ID format."
|
|
36174
36393
|
);
|
|
36175
36394
|
}
|
|
36176
|
-
if (value.site &&
|
|
36395
|
+
if (value.site && import_mongodb91.ObjectId.isValid(value.site.toString())) {
|
|
36177
36396
|
try {
|
|
36178
|
-
value.site = new
|
|
36397
|
+
value.site = new import_mongodb91.ObjectId(value.site.toString());
|
|
36179
36398
|
} catch {
|
|
36180
36399
|
throw new import_node_server_utils154.BadRequestError("Invalid _id format");
|
|
36181
36400
|
}
|
|
36182
36401
|
}
|
|
36183
|
-
if (value.org &&
|
|
36402
|
+
if (value.org && import_mongodb91.ObjectId.isValid(value.org.toString())) {
|
|
36184
36403
|
try {
|
|
36185
|
-
value.org = new
|
|
36404
|
+
value.org = new import_mongodb91.ObjectId(value.org.toString());
|
|
36186
36405
|
} catch {
|
|
36187
36406
|
throw new import_node_server_utils154.BadRequestError("Invalid _id format");
|
|
36188
36407
|
}
|
|
36189
36408
|
}
|
|
36190
|
-
if (value.paidBy &&
|
|
36409
|
+
if (value.paidBy && import_mongodb91.ObjectId.isValid(value.paidBy.toString())) {
|
|
36191
36410
|
try {
|
|
36192
|
-
value.org = new
|
|
36411
|
+
value.org = new import_mongodb91.ObjectId(value.paidBy.toString());
|
|
36193
36412
|
} catch {
|
|
36194
36413
|
throw new import_node_server_utils154.BadRequestError("Invalid _id format");
|
|
36195
36414
|
}
|
|
36196
36415
|
}
|
|
36197
|
-
if (value.billItem &&
|
|
36416
|
+
if (value.billItem && import_mongodb91.ObjectId.isValid(value.billItem.toString())) {
|
|
36198
36417
|
try {
|
|
36199
|
-
value.billItem = new
|
|
36418
|
+
value.billItem = new import_mongodb91.ObjectId(value.billItem.toString());
|
|
36200
36419
|
} catch {
|
|
36201
36420
|
throw new import_node_server_utils154.BadRequestError("Invalid _id format");
|
|
36202
36421
|
}
|
|
36203
36422
|
}
|
|
36204
|
-
if (value.unitId &&
|
|
36423
|
+
if (value.unitId && import_mongodb91.ObjectId.isValid(value.unitId.toString())) {
|
|
36205
36424
|
try {
|
|
36206
|
-
value.unitId = new
|
|
36425
|
+
value.unitId = new import_mongodb91.ObjectId(value.unitId.toString());
|
|
36207
36426
|
} catch {
|
|
36208
36427
|
throw new import_node_server_utils154.BadRequestError("Invalid _id format");
|
|
36209
36428
|
}
|
|
@@ -36223,7 +36442,7 @@ function useSiteUnitBillingRepo() {
|
|
|
36223
36442
|
}
|
|
36224
36443
|
async function deleteById(_id) {
|
|
36225
36444
|
try {
|
|
36226
|
-
_id = new
|
|
36445
|
+
_id = new import_mongodb91.ObjectId(_id);
|
|
36227
36446
|
} catch (error) {
|
|
36228
36447
|
throw new import_node_server_utils154.BadRequestError(
|
|
36229
36448
|
"Invalid site unit billing transaction ID format."
|
|
@@ -36289,9 +36508,9 @@ function useSiteUnitBillingRepo() {
|
|
|
36289
36508
|
}
|
|
36290
36509
|
]
|
|
36291
36510
|
},
|
|
36292
|
-
...
|
|
36511
|
+
...import_mongodb91.ObjectId.isValid(site) && { site: new import_mongodb91.ObjectId(site) },
|
|
36293
36512
|
...dateExpr,
|
|
36294
|
-
...
|
|
36513
|
+
...import_mongodb91.ObjectId.isValid(unitId) && { unitId: new import_mongodb91.ObjectId(unitId) }
|
|
36295
36514
|
};
|
|
36296
36515
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
36297
36516
|
try {
|
|
@@ -36378,9 +36597,9 @@ function useSiteUnitBillingRepo() {
|
|
|
36378
36597
|
}
|
|
36379
36598
|
]
|
|
36380
36599
|
},
|
|
36381
|
-
...
|
|
36600
|
+
...import_mongodb91.ObjectId.isValid(site) && { site: new import_mongodb91.ObjectId(site) },
|
|
36382
36601
|
...dateExpr,
|
|
36383
|
-
...
|
|
36602
|
+
...import_mongodb91.ObjectId.isValid(unitId) && { unitId: new import_mongodb91.ObjectId(unitId) }
|
|
36384
36603
|
};
|
|
36385
36604
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
36386
36605
|
try {
|
|
@@ -36463,7 +36682,7 @@ function useSiteUnitBillingRepo() {
|
|
|
36463
36682
|
|
|
36464
36683
|
// src/services/site-unit-billing.service.ts
|
|
36465
36684
|
var import_node_server_utils155 = require("@7365admin1/node-server-utils");
|
|
36466
|
-
var
|
|
36685
|
+
var import_mongodb92 = require("mongodb");
|
|
36467
36686
|
function useSiteUnitBillingService() {
|
|
36468
36687
|
const {
|
|
36469
36688
|
add: _add,
|
|
@@ -36620,7 +36839,7 @@ function useSiteUnitBillingService() {
|
|
|
36620
36839
|
return unitsWithOwner || [];
|
|
36621
36840
|
} else {
|
|
36622
36841
|
if (units && units.length > 0) {
|
|
36623
|
-
const unitIds = units.map((unit) => new
|
|
36842
|
+
const unitIds = units.map((unit) => new import_mongodb92.ObjectId(unit._id));
|
|
36624
36843
|
const specificUnitsWithOwner = await _getBuildingUnitsWithOwner(
|
|
36625
36844
|
site || "",
|
|
36626
36845
|
unitIds
|
|
@@ -36901,7 +37120,7 @@ function useSiteUnitBillingController() {
|
|
|
36901
37120
|
}
|
|
36902
37121
|
|
|
36903
37122
|
// src/models/access-management.model.ts
|
|
36904
|
-
var
|
|
37123
|
+
var import_mongodb93 = require("mongodb");
|
|
36905
37124
|
var EAccessCardTypes = /* @__PURE__ */ ((EAccessCardTypes2) => {
|
|
36906
37125
|
EAccessCardTypes2["NFC"] = "NFC";
|
|
36907
37126
|
EAccessCardTypes2["QR"] = "QRCODE";
|
|
@@ -36923,7 +37142,7 @@ var AccessTypeProps = /* @__PURE__ */ ((AccessTypeProps2) => {
|
|
|
36923
37142
|
})(AccessTypeProps || {});
|
|
36924
37143
|
var MAccessCardTransaction = class {
|
|
36925
37144
|
constructor({
|
|
36926
|
-
_id = new
|
|
37145
|
+
_id = new import_mongodb93.ObjectId(),
|
|
36927
37146
|
index,
|
|
36928
37147
|
site,
|
|
36929
37148
|
cardNo,
|
|
@@ -36950,7 +37169,7 @@ var MAccessCardTransaction = class {
|
|
|
36950
37169
|
};
|
|
36951
37170
|
var MAccessCard = class {
|
|
36952
37171
|
constructor({
|
|
36953
|
-
_id = new
|
|
37172
|
+
_id = new import_mongodb93.ObjectId(),
|
|
36954
37173
|
userId,
|
|
36955
37174
|
site,
|
|
36956
37175
|
staffNo = null,
|
|
@@ -37008,7 +37227,7 @@ var MAccessCard = class {
|
|
|
37008
37227
|
|
|
37009
37228
|
// src/repositories/access-management.repo.ts
|
|
37010
37229
|
var import_node_server_utils157 = require("@7365admin1/node-server-utils");
|
|
37011
|
-
var
|
|
37230
|
+
var import_mongodb94 = require("mongodb");
|
|
37012
37231
|
|
|
37013
37232
|
// src/utils/access-management.ts
|
|
37014
37233
|
var import_fs4 = __toESM(require("fs"));
|
|
@@ -37318,12 +37537,12 @@ function UseAccessManagementRepo() {
|
|
|
37318
37537
|
payload
|
|
37319
37538
|
}) {
|
|
37320
37539
|
try {
|
|
37321
|
-
payload.site = new
|
|
37540
|
+
payload.site = new import_mongodb94.ObjectId(payload.site);
|
|
37322
37541
|
payload.startDate = new Date(payload.startDate);
|
|
37323
37542
|
payload.endDate = new Date(payload.endDate);
|
|
37324
37543
|
payload.createdAt = new Date(payload.createdAt);
|
|
37325
37544
|
payload.updatedAt = new Date(payload.updatedAt);
|
|
37326
|
-
payload.assignedUnit = payload.unit?.map((id) => new
|
|
37545
|
+
payload.assignedUnit = payload.unit?.map((id) => new import_mongodb94.ObjectId(id));
|
|
37327
37546
|
delete payload.unit;
|
|
37328
37547
|
const accessCardObj = new MAccessCard(payload);
|
|
37329
37548
|
const result = await collection().insertOne(accessCardObj);
|
|
@@ -37362,7 +37581,7 @@ function UseAccessManagementRepo() {
|
|
|
37362
37581
|
async function addNonPhysicalCardRepo(params) {
|
|
37363
37582
|
try {
|
|
37364
37583
|
const MAX_RETRIES = 3;
|
|
37365
|
-
const site = new
|
|
37584
|
+
const site = new import_mongodb94.ObjectId(params.site);
|
|
37366
37585
|
const date = /* @__PURE__ */ new Date();
|
|
37367
37586
|
const endDate = new Date(date.setFullYear(date.getFullYear() + 10));
|
|
37368
37587
|
const countPerUnit = params.quantity;
|
|
@@ -37394,7 +37613,7 @@ function UseAccessManagementRepo() {
|
|
|
37394
37613
|
userType: params.userType,
|
|
37395
37614
|
doorName: params.doorName,
|
|
37396
37615
|
liftName: params.liftName,
|
|
37397
|
-
assignedUnit: new
|
|
37616
|
+
assignedUnit: new import_mongodb94.ObjectId(units[i]),
|
|
37398
37617
|
createdAt: new Date(params.createdAt),
|
|
37399
37618
|
updatedAt: new Date(params.updatedAt),
|
|
37400
37619
|
isWinsland: params.isWinsland
|
|
@@ -37480,7 +37699,7 @@ function UseAccessManagementRepo() {
|
|
|
37480
37699
|
}
|
|
37481
37700
|
async function accessManagementSettingsRepo(params) {
|
|
37482
37701
|
try {
|
|
37483
|
-
params.site = new
|
|
37702
|
+
params.site = new import_mongodb94.ObjectId(params.site);
|
|
37484
37703
|
const result = collectionName("entrypass-settings").updateOne(
|
|
37485
37704
|
{ site: params.site },
|
|
37486
37705
|
{
|
|
@@ -37502,7 +37721,7 @@ function UseAccessManagementRepo() {
|
|
|
37502
37721
|
}
|
|
37503
37722
|
async function allAccessCardsCountsRepo(params) {
|
|
37504
37723
|
try {
|
|
37505
|
-
const site = new
|
|
37724
|
+
const site = new import_mongodb94.ObjectId(params.site);
|
|
37506
37725
|
const userType = params.userType;
|
|
37507
37726
|
const result = await collection().aggregate([
|
|
37508
37727
|
{
|
|
@@ -37562,7 +37781,7 @@ function UseAccessManagementRepo() {
|
|
|
37562
37781
|
}
|
|
37563
37782
|
async function availableAccessCardsRepo(params) {
|
|
37564
37783
|
try {
|
|
37565
|
-
const site = new
|
|
37784
|
+
const site = new import_mongodb94.ObjectId(params.site);
|
|
37566
37785
|
const userType = params.userType;
|
|
37567
37786
|
const type = params.type;
|
|
37568
37787
|
const query = {
|
|
@@ -37677,7 +37896,7 @@ function UseAccessManagementRepo() {
|
|
|
37677
37896
|
}
|
|
37678
37897
|
async function userTypeAccessCardsRepo(params) {
|
|
37679
37898
|
try {
|
|
37680
|
-
const site = new
|
|
37899
|
+
const site = new import_mongodb94.ObjectId(params.site);
|
|
37681
37900
|
const userType = params.userType;
|
|
37682
37901
|
const page = params.page ? Number(params.page) - 1 : 0;
|
|
37683
37902
|
const limit = Number(params.limit) || 10;
|
|
@@ -38076,7 +38295,7 @@ function UseAccessManagementRepo() {
|
|
|
38076
38295
|
}
|
|
38077
38296
|
async function assignedAccessCardsRepo(params) {
|
|
38078
38297
|
try {
|
|
38079
|
-
const site = new
|
|
38298
|
+
const site = new import_mongodb94.ObjectId(params.site);
|
|
38080
38299
|
const userType = params.userType;
|
|
38081
38300
|
const type = params.type;
|
|
38082
38301
|
const search = params.search;
|
|
@@ -38251,12 +38470,12 @@ function UseAccessManagementRepo() {
|
|
|
38251
38470
|
session?.startTransaction();
|
|
38252
38471
|
const { userId, cardId, site } = params;
|
|
38253
38472
|
const allUserId = await Promise.all(
|
|
38254
|
-
userId.map(async (id) => new
|
|
38473
|
+
userId.map(async (id) => new import_mongodb94.ObjectId(id))
|
|
38255
38474
|
);
|
|
38256
38475
|
const allCardId = await Promise.all(
|
|
38257
|
-
cardId.map(async (id) => new
|
|
38476
|
+
cardId.map(async (id) => new import_mongodb94.ObjectId(id))
|
|
38258
38477
|
);
|
|
38259
|
-
const siteId = new
|
|
38478
|
+
const siteId = new import_mongodb94.ObjectId(site);
|
|
38260
38479
|
const result = await collection().updateMany(
|
|
38261
38480
|
{
|
|
38262
38481
|
$or: [
|
|
@@ -38287,7 +38506,7 @@ function UseAccessManagementRepo() {
|
|
|
38287
38506
|
async function accessandLiftCardsRepo(params) {
|
|
38288
38507
|
try {
|
|
38289
38508
|
const { accessLevel, liftAccessLevel, site, userType, type } = params;
|
|
38290
|
-
const siteId = new
|
|
38509
|
+
const siteId = new import_mongodb94.ObjectId(site);
|
|
38291
38510
|
const query = {
|
|
38292
38511
|
site: { $in: [siteId] },
|
|
38293
38512
|
userType,
|
|
@@ -38320,9 +38539,9 @@ function UseAccessManagementRepo() {
|
|
|
38320
38539
|
const session = import_node_server_utils157.useAtlas.getClient()?.startSession();
|
|
38321
38540
|
try {
|
|
38322
38541
|
session?.startTransaction();
|
|
38323
|
-
const siteId = new
|
|
38324
|
-
const userId = new
|
|
38325
|
-
const cardId = new
|
|
38542
|
+
const siteId = new import_mongodb94.ObjectId(params.site);
|
|
38543
|
+
const userId = new import_mongodb94.ObjectId(params.userId);
|
|
38544
|
+
const cardId = new import_mongodb94.ObjectId(params.cardId);
|
|
38326
38545
|
const quantity = 1;
|
|
38327
38546
|
const cardCredentials = await collection().findOneAndUpdate(
|
|
38328
38547
|
{ _id: cardId },
|
|
@@ -38348,7 +38567,7 @@ function UseAccessManagementRepo() {
|
|
|
38348
38567
|
(no) => no.toString().padStart(10, "0")
|
|
38349
38568
|
);
|
|
38350
38569
|
const accessCards = [];
|
|
38351
|
-
const convertedUnits = unit.map((obj) => new
|
|
38570
|
+
const convertedUnits = unit.map((obj) => new import_mongodb94.ObjectId(obj));
|
|
38352
38571
|
for (let j = 0; j < (unit.length > 0 ? unit.length : quantity); j++) {
|
|
38353
38572
|
accessCards.push(
|
|
38354
38573
|
new MAccessCard({
|
|
@@ -38437,7 +38656,7 @@ function UseAccessManagementRepo() {
|
|
|
38437
38656
|
session?.startTransaction();
|
|
38438
38657
|
const results = [];
|
|
38439
38658
|
for (let nfc of params.nfcList) {
|
|
38440
|
-
nfc._id = new
|
|
38659
|
+
nfc._id = new import_mongodb94.ObjectId(nfc._id);
|
|
38441
38660
|
const card = await collection().findOne({ _id: nfc._id }, { session });
|
|
38442
38661
|
if (card) {
|
|
38443
38662
|
const updateFields = {
|
|
@@ -38471,7 +38690,7 @@ function UseAccessManagementRepo() {
|
|
|
38471
38690
|
async function doorAndLiftDropdownRepo(params) {
|
|
38472
38691
|
try {
|
|
38473
38692
|
const { site, type, userType } = params;
|
|
38474
|
-
const id = new
|
|
38693
|
+
const id = new import_mongodb94.ObjectId(site);
|
|
38475
38694
|
const res = collection().aggregate([
|
|
38476
38695
|
{
|
|
38477
38696
|
$match: {
|
|
@@ -38558,10 +38777,10 @@ function UseAccessManagementRepo() {
|
|
|
38558
38777
|
const session = import_node_server_utils157.useAtlas.getClient()?.startSession();
|
|
38559
38778
|
try {
|
|
38560
38779
|
const { cardId, remarks, issuedCardId, unitId, userId } = params;
|
|
38561
|
-
const id = new
|
|
38562
|
-
const newCardId = new
|
|
38563
|
-
const unit = new
|
|
38564
|
-
const user = new
|
|
38780
|
+
const id = new import_mongodb94.ObjectId(cardId);
|
|
38781
|
+
const newCardId = new import_mongodb94.ObjectId(issuedCardId);
|
|
38782
|
+
const unit = new import_mongodb94.ObjectId(unitId);
|
|
38783
|
+
const user = new import_mongodb94.ObjectId(userId);
|
|
38565
38784
|
session?.startTransaction();
|
|
38566
38785
|
const sessionResult = await Promise.all([
|
|
38567
38786
|
await collection().findOneAndUpdate(
|
|
@@ -38594,7 +38813,7 @@ function UseAccessManagementRepo() {
|
|
|
38594
38813
|
async function visitorAccessCardsRepo(params) {
|
|
38595
38814
|
try {
|
|
38596
38815
|
const page = params.page ? params.page - 1 : 0;
|
|
38597
|
-
const siteId = new
|
|
38816
|
+
const siteId = new import_mongodb94.ObjectId(params.site);
|
|
38598
38817
|
const search = params.search;
|
|
38599
38818
|
const type = params.type;
|
|
38600
38819
|
const limit = Number(params.limit);
|
|
@@ -38662,7 +38881,7 @@ function UseAccessManagementRepo() {
|
|
|
38662
38881
|
}
|
|
38663
38882
|
async function getCardReplacementRepo(params) {
|
|
38664
38883
|
try {
|
|
38665
|
-
const site = new
|
|
38884
|
+
const site = new import_mongodb94.ObjectId(params.site);
|
|
38666
38885
|
const search = params.search;
|
|
38667
38886
|
const statusFilter = params.statusFilter;
|
|
38668
38887
|
const dateFrom = params.dateFrom;
|
|
@@ -38834,7 +39053,7 @@ function UseAccessManagementRepo() {
|
|
|
38834
39053
|
async function getAccessManagementSettingsRepo(params) {
|
|
38835
39054
|
try {
|
|
38836
39055
|
const { site } = params;
|
|
38837
|
-
const siteId = new
|
|
39056
|
+
const siteId = new import_mongodb94.ObjectId(site);
|
|
38838
39057
|
const res = await collectionName("entrypass-settings").findOne(
|
|
38839
39058
|
{ site: siteId },
|
|
38840
39059
|
{ allowDiskUse: true }
|
|
@@ -38868,7 +39087,7 @@ function UseAccessManagementRepo() {
|
|
|
38868
39087
|
const rawAccessGroup = item["accessGroup (value ex. Full Access, No Access)"];
|
|
38869
39088
|
const accessGroup = typeof rawAccessGroup === "string" ? rawAccessGroup.split(",").map((v) => v.trim()).filter((v) => v !== "") : [];
|
|
38870
39089
|
return new MAccessCard({
|
|
38871
|
-
site: new
|
|
39090
|
+
site: new import_mongodb94.ObjectId(site),
|
|
38872
39091
|
type: "NFC" /* NFC */,
|
|
38873
39092
|
staffNo: null,
|
|
38874
39093
|
accessLevel,
|
|
@@ -38919,8 +39138,8 @@ function UseAccessManagementRepo() {
|
|
|
38919
39138
|
liftAccessLevel
|
|
38920
39139
|
} = params;
|
|
38921
39140
|
const [convertedUnits, convertedSite] = await Promise.all([
|
|
38922
|
-
Promise.all(units.map((id) => new
|
|
38923
|
-
new
|
|
39141
|
+
Promise.all(units.map((id) => new import_mongodb94.ObjectId(id))),
|
|
39142
|
+
new import_mongodb94.ObjectId(site)
|
|
38924
39143
|
]);
|
|
38925
39144
|
const totalRequired = quantity * convertedUnits.length;
|
|
38926
39145
|
const availableCards = await collection().find({
|
|
@@ -38972,7 +39191,7 @@ function UseAccessManagementRepo() {
|
|
|
38972
39191
|
async function deleteCardRepo(params) {
|
|
38973
39192
|
try {
|
|
38974
39193
|
const { cardId, remarks } = params;
|
|
38975
|
-
const id = new
|
|
39194
|
+
const id = new import_mongodb94.ObjectId(cardId);
|
|
38976
39195
|
const result = await collection().findOneAndUpdate(
|
|
38977
39196
|
{ _id: id },
|
|
38978
39197
|
{
|
|
@@ -38993,8 +39212,8 @@ function UseAccessManagementRepo() {
|
|
|
38993
39212
|
async function getCardDetailsRepo(params) {
|
|
38994
39213
|
try {
|
|
38995
39214
|
const { siteId, cardId } = params;
|
|
38996
|
-
const convertedSiteId = new
|
|
38997
|
-
const convertedCardId = new
|
|
39215
|
+
const convertedSiteId = new import_mongodb94.ObjectId(siteId);
|
|
39216
|
+
const convertedCardId = new import_mongodb94.ObjectId(cardId);
|
|
38998
39217
|
const card = await collection().findOne(
|
|
38999
39218
|
{
|
|
39000
39219
|
_id: convertedCardId,
|
|
@@ -39043,7 +39262,7 @@ function UseAccessManagementRepo() {
|
|
|
39043
39262
|
async function addQrTagRepo(params) {
|
|
39044
39263
|
try {
|
|
39045
39264
|
const { site, payload } = params;
|
|
39046
|
-
const id = new
|
|
39265
|
+
const id = new import_mongodb94.ObjectId(site);
|
|
39047
39266
|
const highestCardNo = await collection().aggregate([
|
|
39048
39267
|
{
|
|
39049
39268
|
$match: {
|
|
@@ -39077,7 +39296,7 @@ function UseAccessManagementRepo() {
|
|
|
39077
39296
|
);
|
|
39078
39297
|
const bulkOps = await Promise.all(
|
|
39079
39298
|
payload.map(async (doc, index) => {
|
|
39080
|
-
const id2 = new
|
|
39299
|
+
const id2 = new import_mongodb94.ObjectId(doc._id);
|
|
39081
39300
|
return {
|
|
39082
39301
|
updateOne: {
|
|
39083
39302
|
filter: { _id: id2 },
|
|
@@ -39100,7 +39319,7 @@ function UseAccessManagementRepo() {
|
|
|
39100
39319
|
async function allQrTagRepo(params) {
|
|
39101
39320
|
try {
|
|
39102
39321
|
const { site } = params;
|
|
39103
|
-
const siteId = new
|
|
39322
|
+
const siteId = new import_mongodb94.ObjectId(site);
|
|
39104
39323
|
const query = {
|
|
39105
39324
|
site: siteId,
|
|
39106
39325
|
assignedUnit: { $ne: null },
|
|
@@ -39149,8 +39368,8 @@ function UseAccessManagementRepo() {
|
|
|
39149
39368
|
}
|
|
39150
39369
|
async function availableCardContractorsRepo(params) {
|
|
39151
39370
|
try {
|
|
39152
|
-
const siteId = new
|
|
39153
|
-
const unitId = new
|
|
39371
|
+
const siteId = new import_mongodb94.ObjectId(params.siteId);
|
|
39372
|
+
const unitId = new import_mongodb94.ObjectId(params.unitId);
|
|
39154
39373
|
const page = Number(params.page) - 1;
|
|
39155
39374
|
const limit = Number(params.limit) || 10;
|
|
39156
39375
|
const type = params.type;
|
|
@@ -39251,8 +39470,8 @@ function UseAccessManagementRepo() {
|
|
|
39251
39470
|
}
|
|
39252
39471
|
async function vmsgenerateQrCodesRepo(params) {
|
|
39253
39472
|
try {
|
|
39254
|
-
const site = new
|
|
39255
|
-
const unitId = new
|
|
39473
|
+
const site = new import_mongodb94.ObjectId(params.site);
|
|
39474
|
+
const unitId = new import_mongodb94.ObjectId(params.unitId);
|
|
39256
39475
|
const quantity = Number(params.quantity);
|
|
39257
39476
|
const normalizedUnitId = params.normalizedUnitId;
|
|
39258
39477
|
const date = /* @__PURE__ */ new Date();
|
|
@@ -39307,11 +39526,11 @@ function UseAccessManagementRepo() {
|
|
|
39307
39526
|
let isAborted = false;
|
|
39308
39527
|
try {
|
|
39309
39528
|
await session?.startTransaction();
|
|
39310
|
-
const siteId = new
|
|
39311
|
-
const unitId = new
|
|
39529
|
+
const siteId = new import_mongodb94.ObjectId(params.site);
|
|
39530
|
+
const unitId = new import_mongodb94.ObjectId(params.unitId);
|
|
39312
39531
|
const quantity = params.quantity;
|
|
39313
39532
|
const type = params.type;
|
|
39314
|
-
const visitorId = new
|
|
39533
|
+
const visitorId = new import_mongodb94.ObjectId(params.visitorId);
|
|
39315
39534
|
const nfcCards = params.nfcCards;
|
|
39316
39535
|
const acm_url = params.acm_url;
|
|
39317
39536
|
let cards = [];
|
|
@@ -39333,7 +39552,7 @@ function UseAccessManagementRepo() {
|
|
|
39333
39552
|
} else if (type === "NFC" /* NFC */) {
|
|
39334
39553
|
if (nfcCards && nfcCards.length > 0) {
|
|
39335
39554
|
const objectIds = nfcCards.map(
|
|
39336
|
-
(card) => new
|
|
39555
|
+
(card) => new import_mongodb94.ObjectId(card._id)
|
|
39337
39556
|
);
|
|
39338
39557
|
cards = await collection().find({ _id: { $in: objectIds } }).toArray();
|
|
39339
39558
|
const nfcList = objectIds.map((card) => ({
|
|
@@ -39440,7 +39659,7 @@ function UseAccessManagementRepo() {
|
|
|
39440
39659
|
}
|
|
39441
39660
|
async function signQrCodeRepo(params) {
|
|
39442
39661
|
try {
|
|
39443
|
-
const cardId = new
|
|
39662
|
+
const cardId = new import_mongodb94.ObjectId(params.cardId);
|
|
39444
39663
|
const purpose = params.purpose;
|
|
39445
39664
|
let validity = 5;
|
|
39446
39665
|
const card = await collection().findOne({ _id: cardId });
|
|
@@ -39465,7 +39684,7 @@ function UseAccessManagementRepo() {
|
|
|
39465
39684
|
const session = import_node_server_utils157.useAtlas.getClient()?.startSession();
|
|
39466
39685
|
try {
|
|
39467
39686
|
await session?.startTransaction();
|
|
39468
|
-
const userId = new
|
|
39687
|
+
const userId = new import_mongodb94.ObjectId(params.userId);
|
|
39469
39688
|
const result = await collection().updateMany(
|
|
39470
39689
|
{ userId },
|
|
39471
39690
|
{ $set: { userId: null, status: "Available", updatedAt: /* @__PURE__ */ new Date() } }
|
|
@@ -39480,7 +39699,7 @@ function UseAccessManagementRepo() {
|
|
|
39480
39699
|
}
|
|
39481
39700
|
}
|
|
39482
39701
|
async function getBlockLevelAndUnitListRepo(params) {
|
|
39483
|
-
const site = new
|
|
39702
|
+
const site = new import_mongodb94.ObjectId(params.site);
|
|
39484
39703
|
try {
|
|
39485
39704
|
const blocks = await collectionName("buildings").aggregate([
|
|
39486
39705
|
{
|
|
@@ -39550,7 +39769,7 @@ function UseAccessManagementRepo() {
|
|
|
39550
39769
|
url
|
|
39551
39770
|
}) {
|
|
39552
39771
|
page = page ? page - 1 : 0;
|
|
39553
|
-
site = new
|
|
39772
|
+
site = new import_mongodb94.ObjectId(site);
|
|
39554
39773
|
try {
|
|
39555
39774
|
let index = await collectionName("access-card-transactions").findOne(
|
|
39556
39775
|
{},
|
|
@@ -39685,9 +39904,9 @@ function UseAccessManagementRepo() {
|
|
|
39685
39904
|
throw new Error("No user to Assign.");
|
|
39686
39905
|
}
|
|
39687
39906
|
assignees = assignees.map(
|
|
39688
|
-
(data) => new
|
|
39907
|
+
(data) => new import_mongodb94.ObjectId(data)
|
|
39689
39908
|
);
|
|
39690
|
-
unit = new
|
|
39909
|
+
unit = new import_mongodb94.ObjectId(unit);
|
|
39691
39910
|
let availableCards = [];
|
|
39692
39911
|
let update = [];
|
|
39693
39912
|
let cards = [];
|
|
@@ -39720,13 +39939,13 @@ function UseAccessManagementRepo() {
|
|
|
39720
39939
|
throw new Error(`Not enough ${type} cards available.`);
|
|
39721
39940
|
}
|
|
39722
39941
|
cards = availableCards?.slice(0, assignees.length).map((card, index) => {
|
|
39723
|
-
const userId = new
|
|
39942
|
+
const userId = new import_mongodb94.ObjectId(assignees[index].toString());
|
|
39724
39943
|
card.staffNo = userId.toString().slice(-10);
|
|
39725
39944
|
return card;
|
|
39726
39945
|
});
|
|
39727
39946
|
update = availableCards.slice(0, assignees.length).map((card, index) => ({
|
|
39728
39947
|
_id: card._id,
|
|
39729
|
-
userId: new
|
|
39948
|
+
userId: new import_mongodb94.ObjectId(assignees[index])
|
|
39730
39949
|
}));
|
|
39731
39950
|
const commands = cards.map((item, index) => {
|
|
39732
39951
|
let ag = null;
|
|
@@ -39792,7 +40011,7 @@ function UseAccessManagementRepo() {
|
|
|
39792
40011
|
const session = import_node_server_utils157.useAtlas.getClient()?.startSession();
|
|
39793
40012
|
try {
|
|
39794
40013
|
session?.startTransaction();
|
|
39795
|
-
const id = new
|
|
40014
|
+
const id = new import_mongodb94.ObjectId(userId);
|
|
39796
40015
|
await collection().updateMany(
|
|
39797
40016
|
{ userId: id },
|
|
39798
40017
|
{ $set: { userId: null, status: "Available" } },
|
|
@@ -39812,8 +40031,8 @@ function UseAccessManagementRepo() {
|
|
|
39812
40031
|
id,
|
|
39813
40032
|
name
|
|
39814
40033
|
}) {
|
|
39815
|
-
site = new
|
|
39816
|
-
id = new
|
|
40034
|
+
site = new import_mongodb94.ObjectId(site);
|
|
40035
|
+
id = new import_mongodb94.ObjectId(id);
|
|
39817
40036
|
try {
|
|
39818
40037
|
const result = await collectionName("sites").updateOne(
|
|
39819
40038
|
{ _id: site },
|
|
@@ -39830,9 +40049,9 @@ function UseAccessManagementRepo() {
|
|
|
39830
40049
|
unitId
|
|
39831
40050
|
}) {
|
|
39832
40051
|
try {
|
|
39833
|
-
orgId = new
|
|
39834
|
-
siteId = new
|
|
39835
|
-
unitId = new
|
|
40052
|
+
orgId = new import_mongodb94.ObjectId(orgId);
|
|
40053
|
+
siteId = new import_mongodb94.ObjectId(siteId);
|
|
40054
|
+
unitId = new import_mongodb94.ObjectId(unitId);
|
|
39836
40055
|
const result = await collectionName("users").aggregate([
|
|
39837
40056
|
{
|
|
39838
40057
|
$match: {
|
|
@@ -39867,17 +40086,23 @@ function UseAccessManagementRepo() {
|
|
|
39867
40086
|
async function userAccessCardsRepo({
|
|
39868
40087
|
userId,
|
|
39869
40088
|
siteId,
|
|
39870
|
-
isLiftCard
|
|
40089
|
+
isLiftCard,
|
|
40090
|
+
search
|
|
39871
40091
|
}) {
|
|
39872
40092
|
try {
|
|
39873
|
-
siteId = new
|
|
39874
|
-
userId = new
|
|
40093
|
+
siteId = new import_mongodb94.ObjectId(siteId);
|
|
40094
|
+
userId = new import_mongodb94.ObjectId(userId);
|
|
39875
40095
|
const query = {
|
|
39876
40096
|
site: siteId,
|
|
39877
40097
|
userId,
|
|
39878
40098
|
isLiftCard,
|
|
39879
40099
|
userType: "Visitor/Resident" /* DEFAULT */
|
|
39880
40100
|
};
|
|
40101
|
+
if (search !== "") {
|
|
40102
|
+
query.$or = [
|
|
40103
|
+
{ cardNo: { $regex: search, $options: "i" } }
|
|
40104
|
+
];
|
|
40105
|
+
}
|
|
39881
40106
|
console.log(query);
|
|
39882
40107
|
const res = await collection().aggregate([
|
|
39883
40108
|
{
|
|
@@ -39892,7 +40117,7 @@ function UseAccessManagementRepo() {
|
|
|
39892
40117
|
}
|
|
39893
40118
|
}
|
|
39894
40119
|
async function removeTemplateRepo({ site }) {
|
|
39895
|
-
site = new
|
|
40120
|
+
site = new import_mongodb94.ObjectId(site);
|
|
39896
40121
|
try {
|
|
39897
40122
|
const result = await collectionName("entrypass-settings").updateOne({ _id: site }, { $set: { "settings.template": {} } });
|
|
39898
40123
|
return result;
|
|
@@ -39905,8 +40130,8 @@ function UseAccessManagementRepo() {
|
|
|
39905
40130
|
page = page ? page - 1 : 0;
|
|
39906
40131
|
let defaultQuery = {};
|
|
39907
40132
|
let searchQuery = {};
|
|
39908
|
-
site = new
|
|
39909
|
-
userId = new
|
|
40133
|
+
site = new import_mongodb94.ObjectId(site);
|
|
40134
|
+
userId = new import_mongodb94.ObjectId(userId);
|
|
39910
40135
|
if (search) {
|
|
39911
40136
|
searchQuery = {
|
|
39912
40137
|
$or: [{ fullName: { $regex: search, $options: "i" } }, { cardNo: { $regex: search, $options: "i" } }]
|
|
@@ -40378,13 +40603,15 @@ function useAccessManagementSvc() {
|
|
|
40378
40603
|
const userAccessCardsSvc = async ({
|
|
40379
40604
|
userId,
|
|
40380
40605
|
siteId,
|
|
40381
|
-
isLiftCard
|
|
40606
|
+
isLiftCard,
|
|
40607
|
+
search
|
|
40382
40608
|
}) => {
|
|
40383
40609
|
try {
|
|
40384
40610
|
const response = await userAccessCardsRepo({
|
|
40385
40611
|
userId,
|
|
40386
40612
|
siteId,
|
|
40387
|
-
isLiftCard
|
|
40613
|
+
isLiftCard,
|
|
40614
|
+
search
|
|
40388
40615
|
});
|
|
40389
40616
|
return response;
|
|
40390
40617
|
} catch (err) {
|
|
@@ -41523,13 +41750,14 @@ function useAccessManagementController() {
|
|
|
41523
41750
|
};
|
|
41524
41751
|
const userAccessCards = async (req, res) => {
|
|
41525
41752
|
try {
|
|
41526
|
-
const { userId, siteId, isLiftCard } = req.query;
|
|
41753
|
+
const { userId, siteId, isLiftCard, search = "" } = req.query;
|
|
41527
41754
|
const schema2 = import_joi87.default.object({
|
|
41528
41755
|
isLiftCard: import_joi87.default.string().valid("true", "false").required(),
|
|
41529
41756
|
siteId: import_joi87.default.string().hex().required(),
|
|
41530
|
-
userId: import_joi87.default.string().hex().required()
|
|
41757
|
+
userId: import_joi87.default.string().hex().required(),
|
|
41758
|
+
search: import_joi87.default.string().optional().allow(null, "")
|
|
41531
41759
|
});
|
|
41532
|
-
const { error } = schema2.validate({ userId, siteId, isLiftCard });
|
|
41760
|
+
const { error } = schema2.validate({ userId, siteId, isLiftCard, search });
|
|
41533
41761
|
if (error) {
|
|
41534
41762
|
return res.status(400).json({ message: error.message });
|
|
41535
41763
|
}
|
|
@@ -41537,7 +41765,8 @@ function useAccessManagementController() {
|
|
|
41537
41765
|
const result = await userAccessCardsSvc({
|
|
41538
41766
|
userId,
|
|
41539
41767
|
siteId,
|
|
41540
|
-
isLiftCard: isLiftCardBool
|
|
41768
|
+
isLiftCard: isLiftCardBool,
|
|
41769
|
+
search
|
|
41541
41770
|
});
|
|
41542
41771
|
return res.status(200).json({ data: result });
|
|
41543
41772
|
} catch (error) {
|
|
@@ -41652,7 +41881,7 @@ function useAccessManagementController() {
|
|
|
41652
41881
|
}
|
|
41653
41882
|
|
|
41654
41883
|
// src/models/nfc-patrol-tag.model.ts
|
|
41655
|
-
var
|
|
41884
|
+
var import_mongodb95 = require("mongodb");
|
|
41656
41885
|
var import_joi88 = __toESM(require("joi"));
|
|
41657
41886
|
var import_node_server_utils158 = require("@7365admin1/node-server-utils");
|
|
41658
41887
|
var DEVICE_STATUS = {
|
|
@@ -41679,27 +41908,27 @@ var schemaNfcPatrolTag = import_joi88.default.object({
|
|
|
41679
41908
|
function MNfcPatrolTag(value) {
|
|
41680
41909
|
if (value._id && typeof value._id === "string") {
|
|
41681
41910
|
try {
|
|
41682
|
-
value._id = new
|
|
41911
|
+
value._id = new import_mongodb95.ObjectId(value._id);
|
|
41683
41912
|
} catch {
|
|
41684
41913
|
throw new import_node_server_utils158.BadRequestError("Invalid ID.");
|
|
41685
41914
|
}
|
|
41686
41915
|
}
|
|
41687
41916
|
if (value.site && typeof value.site === "string") {
|
|
41688
41917
|
try {
|
|
41689
|
-
value.site = new
|
|
41918
|
+
value.site = new import_mongodb95.ObjectId(value.site);
|
|
41690
41919
|
} catch {
|
|
41691
41920
|
throw new import_node_server_utils158.BadRequestError("Invalid site ID.");
|
|
41692
41921
|
}
|
|
41693
41922
|
}
|
|
41694
41923
|
if (value.createdBy && typeof value.createdBy === "string") {
|
|
41695
41924
|
try {
|
|
41696
|
-
value.createdBy = new
|
|
41925
|
+
value.createdBy = new import_mongodb95.ObjectId(value.createdBy);
|
|
41697
41926
|
} catch {
|
|
41698
41927
|
throw new import_node_server_utils158.BadRequestError("Invalid Created By ID.");
|
|
41699
41928
|
}
|
|
41700
41929
|
}
|
|
41701
41930
|
return {
|
|
41702
|
-
_id: value._id ?? new
|
|
41931
|
+
_id: value._id ?? new import_mongodb95.ObjectId(),
|
|
41703
41932
|
site: value.site,
|
|
41704
41933
|
tagID: value.tagID,
|
|
41705
41934
|
name: value.name,
|
|
@@ -41711,7 +41940,7 @@ function MNfcPatrolTag(value) {
|
|
|
41711
41940
|
|
|
41712
41941
|
// src/repositories/nfc-patrol-tag.repository.ts
|
|
41713
41942
|
var import_node_server_utils159 = require("@7365admin1/node-server-utils");
|
|
41714
|
-
var
|
|
41943
|
+
var import_mongodb96 = require("mongodb");
|
|
41715
41944
|
function useNfcPatrolTagRepo() {
|
|
41716
41945
|
const db = import_node_server_utils159.useAtlas.getDb();
|
|
41717
41946
|
if (!db) {
|
|
@@ -41765,7 +41994,7 @@ function useNfcPatrolTagRepo() {
|
|
|
41765
41994
|
}, session) {
|
|
41766
41995
|
page = page > 0 ? page - 1 : 0;
|
|
41767
41996
|
try {
|
|
41768
|
-
site = new
|
|
41997
|
+
site = new import_mongodb96.ObjectId(site);
|
|
41769
41998
|
} catch (error) {
|
|
41770
41999
|
throw new import_node_server_utils159.BadRequestError("Invalid site ID format.");
|
|
41771
42000
|
}
|
|
@@ -41809,19 +42038,19 @@ function useNfcPatrolTagRepo() {
|
|
|
41809
42038
|
const [updateType, findObject, setData, session] = args;
|
|
41810
42039
|
if (findObject?.site && typeof findObject.site === "string") {
|
|
41811
42040
|
try {
|
|
41812
|
-
findObject.site = new
|
|
42041
|
+
findObject.site = new import_mongodb96.ObjectId(findObject.site);
|
|
41813
42042
|
} catch {
|
|
41814
42043
|
throw new import_node_server_utils159.BadRequestError("Invalid site ID.");
|
|
41815
42044
|
}
|
|
41816
42045
|
}
|
|
41817
42046
|
if (updateType == "Edit" && findObject?._id && typeof findObject._id === "string") {
|
|
41818
42047
|
try {
|
|
41819
|
-
findObject._id = new
|
|
42048
|
+
findObject._id = new import_mongodb96.ObjectId(findObject._id);
|
|
41820
42049
|
} catch {
|
|
41821
42050
|
throw new import_node_server_utils159.BadRequestError("Invalid nfc patrol tag document ID.");
|
|
41822
42051
|
}
|
|
41823
42052
|
try {
|
|
41824
|
-
setData.updatedBy = new
|
|
42053
|
+
setData.updatedBy = new import_mongodb96.ObjectId(setData.updatedBy);
|
|
41825
42054
|
} catch {
|
|
41826
42055
|
throw new import_node_server_utils159.BadRequestError("Invalid updatedBy ID.");
|
|
41827
42056
|
}
|
|
@@ -42112,7 +42341,7 @@ function useNfcPatrolTagController() {
|
|
|
42112
42341
|
}
|
|
42113
42342
|
|
|
42114
42343
|
// src/models/occurrence-book.model.ts
|
|
42115
|
-
var
|
|
42344
|
+
var import_mongodb97 = require("mongodb");
|
|
42116
42345
|
var import_joi90 = __toESM(require("joi"));
|
|
42117
42346
|
var DOBStatus = /* @__PURE__ */ ((DOBStatus3) => {
|
|
42118
42347
|
DOBStatus3["OPEN"] = "open";
|
|
@@ -42138,20 +42367,20 @@ var schemaUpdateOccurrenceBook = import_joi90.default.object({
|
|
|
42138
42367
|
function MOccurrenceBook(value) {
|
|
42139
42368
|
if (value._id && typeof value._id === "string") {
|
|
42140
42369
|
try {
|
|
42141
|
-
value._id = new
|
|
42370
|
+
value._id = new import_mongodb97.ObjectId(value._id);
|
|
42142
42371
|
} catch {
|
|
42143
42372
|
throw new Error("Invalid ID.");
|
|
42144
42373
|
}
|
|
42145
42374
|
}
|
|
42146
42375
|
if (value.site && typeof value.site === "string") {
|
|
42147
42376
|
try {
|
|
42148
|
-
value.site = new
|
|
42377
|
+
value.site = new import_mongodb97.ObjectId(value.site);
|
|
42149
42378
|
} catch {
|
|
42150
42379
|
throw new Error("Invalid site ID.");
|
|
42151
42380
|
}
|
|
42152
42381
|
}
|
|
42153
42382
|
return {
|
|
42154
|
-
_id: value._id ?? new
|
|
42383
|
+
_id: value._id ?? new import_mongodb97.ObjectId(),
|
|
42155
42384
|
site: value.site,
|
|
42156
42385
|
date: value.date ?? "",
|
|
42157
42386
|
totalInput: value.totalInput ?? 0,
|
|
@@ -42166,7 +42395,7 @@ function MOccurrenceBook(value) {
|
|
|
42166
42395
|
|
|
42167
42396
|
// src/repositories/occurrence-book.repo.ts
|
|
42168
42397
|
var import_node_server_utils162 = require("@7365admin1/node-server-utils");
|
|
42169
|
-
var
|
|
42398
|
+
var import_mongodb98 = require("mongodb");
|
|
42170
42399
|
var occurrence_book_namespace_collection = "occurrence-books";
|
|
42171
42400
|
function useOccurrenceBookRepo() {
|
|
42172
42401
|
const db = import_node_server_utils162.useAtlas.getDb();
|
|
@@ -42310,7 +42539,7 @@ function useOccurrenceBookRepo() {
|
|
|
42310
42539
|
}
|
|
42311
42540
|
async function getOccurrenceBookById(_id, session) {
|
|
42312
42541
|
try {
|
|
42313
|
-
_id = new
|
|
42542
|
+
_id = new import_mongodb98.ObjectId(_id);
|
|
42314
42543
|
} catch (error) {
|
|
42315
42544
|
throw new import_node_server_utils162.BadRequestError("Invalid occurrence book ID format.");
|
|
42316
42545
|
}
|
|
@@ -42340,7 +42569,7 @@ function useOccurrenceBookRepo() {
|
|
|
42340
42569
|
async function updateOccurrenceBookById(_id, value, session) {
|
|
42341
42570
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
42342
42571
|
try {
|
|
42343
|
-
_id = new
|
|
42572
|
+
_id = new import_mongodb98.ObjectId(_id);
|
|
42344
42573
|
} catch (error) {
|
|
42345
42574
|
throw new import_node_server_utils162.BadRequestError("Invalid ID format.");
|
|
42346
42575
|
}
|
|
@@ -42372,7 +42601,7 @@ function useOccurrenceBookRepo() {
|
|
|
42372
42601
|
}
|
|
42373
42602
|
async function deleteOccurrenceBookById(_id) {
|
|
42374
42603
|
try {
|
|
42375
|
-
_id = new
|
|
42604
|
+
_id = new import_mongodb98.ObjectId(_id);
|
|
42376
42605
|
} catch (error) {
|
|
42377
42606
|
throw new import_node_server_utils162.BadRequestError("Invalid occurrence book ID format.");
|
|
42378
42607
|
}
|
|
@@ -42757,7 +42986,7 @@ function useOccurrenceBookController() {
|
|
|
42757
42986
|
}
|
|
42758
42987
|
|
|
42759
42988
|
// src/models/bulletin-video.model.ts
|
|
42760
|
-
var
|
|
42989
|
+
var import_mongodb99 = require("mongodb");
|
|
42761
42990
|
var import_joi92 = __toESM(require("joi"));
|
|
42762
42991
|
var BulletinVideoSort = /* @__PURE__ */ ((BulletinVideoSort2) => {
|
|
42763
42992
|
BulletinVideoSort2["CREATED_AT"] = "createdAt";
|
|
@@ -42785,27 +43014,27 @@ var schemaUpdateBulletinVideo = import_joi92.default.object({
|
|
|
42785
43014
|
function MBulletinVideo(value) {
|
|
42786
43015
|
if (value._id && typeof value._id === "string") {
|
|
42787
43016
|
try {
|
|
42788
|
-
value._id = new
|
|
43017
|
+
value._id = new import_mongodb99.ObjectId(value._id);
|
|
42789
43018
|
} catch {
|
|
42790
43019
|
throw new Error("Invalid ID.");
|
|
42791
43020
|
}
|
|
42792
43021
|
}
|
|
42793
43022
|
if (value.site && typeof value.site === "string") {
|
|
42794
43023
|
try {
|
|
42795
|
-
value.site = new
|
|
43024
|
+
value.site = new import_mongodb99.ObjectId(value.site);
|
|
42796
43025
|
} catch {
|
|
42797
43026
|
throw new Error("Invalid site ID.");
|
|
42798
43027
|
}
|
|
42799
43028
|
}
|
|
42800
43029
|
if (value.file && typeof value.file === "string") {
|
|
42801
43030
|
try {
|
|
42802
|
-
value.file = new
|
|
43031
|
+
value.file = new import_mongodb99.ObjectId(value.file);
|
|
42803
43032
|
} catch {
|
|
42804
43033
|
throw new Error("Invalid file ID.");
|
|
42805
43034
|
}
|
|
42806
43035
|
}
|
|
42807
43036
|
return {
|
|
42808
|
-
_id: value._id ?? new
|
|
43037
|
+
_id: value._id ?? new import_mongodb99.ObjectId(),
|
|
42809
43038
|
site: value.site,
|
|
42810
43039
|
title: value.title ?? "",
|
|
42811
43040
|
description: value.description ?? "",
|
|
@@ -42818,7 +43047,7 @@ function MBulletinVideo(value) {
|
|
|
42818
43047
|
|
|
42819
43048
|
// src/repositories/bulletin-video.repo.ts
|
|
42820
43049
|
var import_node_server_utils165 = require("@7365admin1/node-server-utils");
|
|
42821
|
-
var
|
|
43050
|
+
var import_mongodb100 = require("mongodb");
|
|
42822
43051
|
function useBulletinVideoRepo() {
|
|
42823
43052
|
const db = import_node_server_utils165.useAtlas.getDb();
|
|
42824
43053
|
if (!db) {
|
|
@@ -42880,7 +43109,7 @@ function useBulletinVideoRepo() {
|
|
|
42880
43109
|
}, session) {
|
|
42881
43110
|
page = page > 0 ? page - 1 : 0;
|
|
42882
43111
|
try {
|
|
42883
|
-
site = new
|
|
43112
|
+
site = new import_mongodb100.ObjectId(site);
|
|
42884
43113
|
} catch (error) {
|
|
42885
43114
|
throw new import_node_server_utils165.BadRequestError("Invalid site ID format.");
|
|
42886
43115
|
}
|
|
@@ -42960,7 +43189,7 @@ function useBulletinVideoRepo() {
|
|
|
42960
43189
|
}
|
|
42961
43190
|
async function getBulletinVideoById(_id, session) {
|
|
42962
43191
|
try {
|
|
42963
|
-
_id = new
|
|
43192
|
+
_id = new import_mongodb100.ObjectId(_id);
|
|
42964
43193
|
} catch (error) {
|
|
42965
43194
|
throw new import_node_server_utils165.BadRequestError("Invalid bulletin video ID format.");
|
|
42966
43195
|
}
|
|
@@ -42991,13 +43220,13 @@ function useBulletinVideoRepo() {
|
|
|
42991
43220
|
async function updateBulletinVideoById(_id, value, session) {
|
|
42992
43221
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
42993
43222
|
try {
|
|
42994
|
-
_id = new
|
|
43223
|
+
_id = new import_mongodb100.ObjectId(_id);
|
|
42995
43224
|
} catch (error) {
|
|
42996
43225
|
throw new import_node_server_utils165.BadRequestError("Invalid ID format.");
|
|
42997
43226
|
}
|
|
42998
43227
|
if (value.file && typeof value.file === "string") {
|
|
42999
43228
|
try {
|
|
43000
|
-
value.file = new
|
|
43229
|
+
value.file = new import_mongodb100.ObjectId(value.file);
|
|
43001
43230
|
} catch {
|
|
43002
43231
|
throw new Error("Invalid file ID.");
|
|
43003
43232
|
}
|
|
@@ -43026,7 +43255,7 @@ function useBulletinVideoRepo() {
|
|
|
43026
43255
|
}
|
|
43027
43256
|
async function deleteBulletinVideoById(_id, session) {
|
|
43028
43257
|
try {
|
|
43029
|
-
_id = new
|
|
43258
|
+
_id = new import_mongodb100.ObjectId(_id);
|
|
43030
43259
|
} catch (error) {
|
|
43031
43260
|
throw new import_node_server_utils165.BadRequestError("Invalid bulletin video ID format.");
|
|
43032
43261
|
}
|
|
@@ -43290,7 +43519,7 @@ function useBulletinVideoController() {
|
|
|
43290
43519
|
|
|
43291
43520
|
// src/models/site-soa.model.ts
|
|
43292
43521
|
var import_node_server_utils168 = require("@7365admin1/node-server-utils");
|
|
43293
|
-
var
|
|
43522
|
+
var import_mongodb101 = require("mongodb");
|
|
43294
43523
|
var import_joi94 = __toESM(require("joi"));
|
|
43295
43524
|
var schemaSOABillingItem = import_joi94.default.object({
|
|
43296
43525
|
_id: import_joi94.default.string().required(),
|
|
@@ -43358,28 +43587,28 @@ function MStatementOfAccount(value) {
|
|
|
43358
43587
|
}
|
|
43359
43588
|
if (value._id && typeof value._id === "string") {
|
|
43360
43589
|
try {
|
|
43361
|
-
value._id = new
|
|
43590
|
+
value._id = new import_mongodb101.ObjectId(value._id);
|
|
43362
43591
|
} catch {
|
|
43363
43592
|
throw new import_node_server_utils168.BadRequestError("Invalid _id format");
|
|
43364
43593
|
}
|
|
43365
43594
|
}
|
|
43366
43595
|
if (value.site && typeof value.site === "string") {
|
|
43367
43596
|
try {
|
|
43368
|
-
value.site = new
|
|
43597
|
+
value.site = new import_mongodb101.ObjectId(value.site);
|
|
43369
43598
|
} catch {
|
|
43370
43599
|
throw new import_node_server_utils168.BadRequestError("Invalid site format");
|
|
43371
43600
|
}
|
|
43372
43601
|
}
|
|
43373
43602
|
if (value.createdBy && typeof value.createdBy === "string") {
|
|
43374
43603
|
try {
|
|
43375
|
-
value.createdBy = new
|
|
43604
|
+
value.createdBy = new import_mongodb101.ObjectId(value.createdBy);
|
|
43376
43605
|
} catch {
|
|
43377
43606
|
throw new import_node_server_utils168.BadRequestError("Invalid createBy format");
|
|
43378
43607
|
}
|
|
43379
43608
|
}
|
|
43380
43609
|
if (value.unitId && typeof value.unitId === "string") {
|
|
43381
43610
|
try {
|
|
43382
|
-
value.unitId = new
|
|
43611
|
+
value.unitId = new import_mongodb101.ObjectId(value.unitId);
|
|
43383
43612
|
} catch {
|
|
43384
43613
|
throw new import_node_server_utils168.BadRequestError("Invalid unitId format");
|
|
43385
43614
|
}
|
|
@@ -43388,7 +43617,7 @@ function MStatementOfAccount(value) {
|
|
|
43388
43617
|
value.billing = value.billing.map((bill) => {
|
|
43389
43618
|
if (bill._id && typeof bill._id === "string") {
|
|
43390
43619
|
try {
|
|
43391
|
-
bill._id = new
|
|
43620
|
+
bill._id = new import_mongodb101.ObjectId(bill._id);
|
|
43392
43621
|
} catch {
|
|
43393
43622
|
throw new import_node_server_utils168.BadRequestError("Invalid billing id format");
|
|
43394
43623
|
}
|
|
@@ -43397,7 +43626,7 @@ function MStatementOfAccount(value) {
|
|
|
43397
43626
|
});
|
|
43398
43627
|
}
|
|
43399
43628
|
return {
|
|
43400
|
-
_id: value._id ?? new
|
|
43629
|
+
_id: value._id ?? new import_mongodb101.ObjectId(),
|
|
43401
43630
|
site: value.site,
|
|
43402
43631
|
unitId: value.unitId ?? "",
|
|
43403
43632
|
unit: value.unit ?? "",
|
|
@@ -43420,7 +43649,7 @@ function MStatementOfAccount(value) {
|
|
|
43420
43649
|
|
|
43421
43650
|
// src/repositories/site-soa.repo.ts
|
|
43422
43651
|
var import_node_server_utils169 = require("@7365admin1/node-server-utils");
|
|
43423
|
-
var
|
|
43652
|
+
var import_mongodb102 = require("mongodb");
|
|
43424
43653
|
function useStatementOfAccountRepo() {
|
|
43425
43654
|
const db = import_node_server_utils169.useAtlas.getDb();
|
|
43426
43655
|
if (!db) {
|
|
@@ -43518,7 +43747,7 @@ function useStatementOfAccountRepo() {
|
|
|
43518
43747
|
{ category: { $regex: search, $options: "i" } }
|
|
43519
43748
|
]
|
|
43520
43749
|
},
|
|
43521
|
-
...
|
|
43750
|
+
...import_mongodb102.ObjectId.isValid(site) && { site: new import_mongodb102.ObjectId(site) },
|
|
43522
43751
|
...dateExpr
|
|
43523
43752
|
};
|
|
43524
43753
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
@@ -43573,7 +43802,7 @@ function useStatementOfAccountRepo() {
|
|
|
43573
43802
|
}
|
|
43574
43803
|
async function getById(_id) {
|
|
43575
43804
|
try {
|
|
43576
|
-
_id = new
|
|
43805
|
+
_id = new import_mongodb102.ObjectId(_id);
|
|
43577
43806
|
} catch (error) {
|
|
43578
43807
|
throw new import_node_server_utils169.BadRequestError("Invalid ID.");
|
|
43579
43808
|
}
|
|
@@ -43612,7 +43841,7 @@ function useStatementOfAccountRepo() {
|
|
|
43612
43841
|
}
|
|
43613
43842
|
async function updateById(_id, value, session) {
|
|
43614
43843
|
try {
|
|
43615
|
-
_id = new
|
|
43844
|
+
_id = new import_mongodb102.ObjectId(_id);
|
|
43616
43845
|
} catch (error) {
|
|
43617
43846
|
throw new import_node_server_utils169.BadRequestError("Invalid site SOA transaction ID format.");
|
|
43618
43847
|
}
|
|
@@ -43631,7 +43860,7 @@ function useStatementOfAccountRepo() {
|
|
|
43631
43860
|
}
|
|
43632
43861
|
async function deleteById(_id) {
|
|
43633
43862
|
try {
|
|
43634
|
-
_id = new
|
|
43863
|
+
_id = new import_mongodb102.ObjectId(_id);
|
|
43635
43864
|
} catch (error) {
|
|
43636
43865
|
throw new import_node_server_utils169.BadRequestError("Invalid site SOA transaction ID format.");
|
|
43637
43866
|
}
|
|
@@ -43653,7 +43882,7 @@ function useStatementOfAccountRepo() {
|
|
|
43653
43882
|
}
|
|
43654
43883
|
async function updateStatusById(_id, value, session) {
|
|
43655
43884
|
try {
|
|
43656
|
-
_id = new
|
|
43885
|
+
_id = new import_mongodb102.ObjectId(_id);
|
|
43657
43886
|
} catch (error) {
|
|
43658
43887
|
throw new import_node_server_utils169.BadRequestError("Invalid file ID format.");
|
|
43659
43888
|
}
|
|
@@ -43708,9 +43937,9 @@ function useStatementOfAccountRepo() {
|
|
|
43708
43937
|
{ category: { $regex: search, $options: "i" } }
|
|
43709
43938
|
]
|
|
43710
43939
|
},
|
|
43711
|
-
...
|
|
43940
|
+
...import_mongodb102.ObjectId.isValid(site) && { site: new import_mongodb102.ObjectId(site) },
|
|
43712
43941
|
...dateExpr,
|
|
43713
|
-
...
|
|
43942
|
+
...import_mongodb102.ObjectId.isValid(unitId) && { unitId: new import_mongodb102.ObjectId(unitId) },
|
|
43714
43943
|
...category && { category }
|
|
43715
43944
|
};
|
|
43716
43945
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
@@ -43760,7 +43989,7 @@ function useStatementOfAccountRepo() {
|
|
|
43760
43989
|
async function reviewSOA(_id, value, session) {
|
|
43761
43990
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
43762
43991
|
try {
|
|
43763
|
-
_id = new
|
|
43992
|
+
_id = new import_mongodb102.ObjectId(_id);
|
|
43764
43993
|
} catch (error) {
|
|
43765
43994
|
throw new import_node_server_utils169.BadRequestError("Invalid ID format.");
|
|
43766
43995
|
}
|
|
@@ -43805,7 +44034,7 @@ var import_node_server_utils171 = require("@7365admin1/node-server-utils");
|
|
|
43805
44034
|
|
|
43806
44035
|
// src/services/site-soa.service.ts
|
|
43807
44036
|
var import_node_server_utils170 = require("@7365admin1/node-server-utils");
|
|
43808
|
-
var
|
|
44037
|
+
var import_mongodb103 = require("mongodb");
|
|
43809
44038
|
var import_puppeteer = require("puppeteer");
|
|
43810
44039
|
function useStatementOfAccountService() {
|
|
43811
44040
|
const { add: _add, reviewSOA: _reviewSOA } = useStatementOfAccountRepo();
|
|
@@ -43942,7 +44171,7 @@ function useStatementOfAccountService() {
|
|
|
43942
44171
|
if (!approvedBy || !approvedBy.name)
|
|
43943
44172
|
throw new import_node_server_utils170.BadRequestError("Created by not found.");
|
|
43944
44173
|
value.approvedBy.name = approvedBy.name;
|
|
43945
|
-
value.approvedBy._id = new
|
|
44174
|
+
value.approvedBy._id = new import_mongodb103.ObjectId(approvedBy._id);
|
|
43946
44175
|
}
|
|
43947
44176
|
await _reviewSOA(id, value, session);
|
|
43948
44177
|
await session?.commitTransaction();
|
|
@@ -44324,7 +44553,7 @@ function useStatementOfAccountController() {
|
|
|
44324
44553
|
|
|
44325
44554
|
// src/models/site-entrypass-settings.model.ts
|
|
44326
44555
|
var import_node_server_utils172 = require("@7365admin1/node-server-utils");
|
|
44327
|
-
var
|
|
44556
|
+
var import_mongodb104 = require("mongodb");
|
|
44328
44557
|
var import_joi96 = __toESM(require("joi"));
|
|
44329
44558
|
var schemaEntryPassSettings = import_joi96.default.object({
|
|
44330
44559
|
_id: import_joi96.default.string().hex().optional().allow("", null),
|
|
@@ -44372,21 +44601,21 @@ function MEntryPassSettings(value) {
|
|
|
44372
44601
|
}
|
|
44373
44602
|
if (value._id && typeof value._id === "string") {
|
|
44374
44603
|
try {
|
|
44375
|
-
value._id = new
|
|
44604
|
+
value._id = new import_mongodb104.ObjectId(value._id);
|
|
44376
44605
|
} catch {
|
|
44377
44606
|
throw new import_node_server_utils172.BadRequestError("Invalid _id format");
|
|
44378
44607
|
}
|
|
44379
44608
|
}
|
|
44380
44609
|
if (value.site && typeof value.site === "string") {
|
|
44381
44610
|
try {
|
|
44382
|
-
value.site = new
|
|
44611
|
+
value.site = new import_mongodb104.ObjectId(value.site);
|
|
44383
44612
|
} catch {
|
|
44384
44613
|
throw new import_node_server_utils172.BadRequestError("Invalid site format");
|
|
44385
44614
|
}
|
|
44386
44615
|
}
|
|
44387
44616
|
if (value.org && typeof value.org === "string") {
|
|
44388
44617
|
try {
|
|
44389
|
-
value.org = new
|
|
44618
|
+
value.org = new import_mongodb104.ObjectId(value.org);
|
|
44390
44619
|
} catch {
|
|
44391
44620
|
throw new import_node_server_utils172.BadRequestError("Invalid org format");
|
|
44392
44621
|
}
|
|
@@ -44416,7 +44645,7 @@ function MEntryPassSettings(value) {
|
|
|
44416
44645
|
|
|
44417
44646
|
// src/repositories/site-entrypass-settings.repo.ts
|
|
44418
44647
|
var import_node_server_utils173 = require("@7365admin1/node-server-utils");
|
|
44419
|
-
var
|
|
44648
|
+
var import_mongodb105 = require("mongodb");
|
|
44420
44649
|
function useEntryPassSettingsRepo() {
|
|
44421
44650
|
const db = import_node_server_utils173.useAtlas.getDb();
|
|
44422
44651
|
if (!db) {
|
|
@@ -44526,7 +44755,7 @@ function useEntryPassSettingsRepo() {
|
|
|
44526
44755
|
}
|
|
44527
44756
|
async function getEntryPassSettingsById(_id) {
|
|
44528
44757
|
try {
|
|
44529
|
-
_id = new
|
|
44758
|
+
_id = new import_mongodb105.ObjectId(_id);
|
|
44530
44759
|
} catch (error) {
|
|
44531
44760
|
throw new import_node_server_utils173.BadRequestError("Invalid entry pass settings ID format.");
|
|
44532
44761
|
}
|
|
@@ -44593,7 +44822,7 @@ function useEntryPassSettingsRepo() {
|
|
|
44593
44822
|
}
|
|
44594
44823
|
async function updateEntryPassSettingsById(_id, value) {
|
|
44595
44824
|
try {
|
|
44596
|
-
_id = new
|
|
44825
|
+
_id = new import_mongodb105.ObjectId(_id);
|
|
44597
44826
|
} catch (error) {
|
|
44598
44827
|
throw new import_node_server_utils173.BadRequestError("Invalid entry pass settings ID format.");
|
|
44599
44828
|
}
|
|
@@ -44621,7 +44850,7 @@ function useEntryPassSettingsRepo() {
|
|
|
44621
44850
|
}
|
|
44622
44851
|
async function deleteEntryPassSettingsById(_id, session) {
|
|
44623
44852
|
try {
|
|
44624
|
-
_id = new
|
|
44853
|
+
_id = new import_mongodb105.ObjectId(_id);
|
|
44625
44854
|
} catch (error) {
|
|
44626
44855
|
throw new import_node_server_utils173.BadRequestError("Invalid card ID format.");
|
|
44627
44856
|
}
|
|
@@ -44654,7 +44883,7 @@ function useEntryPassSettingsRepo() {
|
|
|
44654
44883
|
}
|
|
44655
44884
|
async function getEntryPassSettingsBySiteId(site) {
|
|
44656
44885
|
try {
|
|
44657
|
-
site = new
|
|
44886
|
+
site = new import_mongodb105.ObjectId(site);
|
|
44658
44887
|
} catch (error) {
|
|
44659
44888
|
throw new import_node_server_utils173.BadRequestError("Invalid entry pass settings ID format.");
|
|
44660
44889
|
}
|
|
@@ -44721,7 +44950,7 @@ function useEntryPassSettingsRepo() {
|
|
|
44721
44950
|
}
|
|
44722
44951
|
async function updateEntryPassSettingsBySiteId(site, value) {
|
|
44723
44952
|
try {
|
|
44724
|
-
site = new
|
|
44953
|
+
site = new import_mongodb105.ObjectId(site);
|
|
44725
44954
|
} catch (error) {
|
|
44726
44955
|
throw new import_node_server_utils173.BadRequestError("Invalid entry pass settings ID format.");
|
|
44727
44956
|
}
|
|
@@ -45080,7 +45309,7 @@ function useDashboardController() {
|
|
|
45080
45309
|
}
|
|
45081
45310
|
|
|
45082
45311
|
// src/models/nfc-patrol-route.model.ts
|
|
45083
|
-
var
|
|
45312
|
+
var import_mongodb106 = require("mongodb");
|
|
45084
45313
|
var import_joi99 = __toESM(require("joi"));
|
|
45085
45314
|
var import_node_server_utils177 = require("@7365admin1/node-server-utils");
|
|
45086
45315
|
var schemaNfcPatrolRoute = import_joi99.default.object({
|
|
@@ -45116,23 +45345,23 @@ function MNfcPatrolRoute(value) {
|
|
|
45116
45345
|
}
|
|
45117
45346
|
if (value._id && typeof value._id === "string") {
|
|
45118
45347
|
try {
|
|
45119
|
-
value._id = new
|
|
45348
|
+
value._id = new import_mongodb106.ObjectId(value._id);
|
|
45120
45349
|
} catch (error2) {
|
|
45121
45350
|
throw new import_node_server_utils177.BadRequestError("Invalid _id format");
|
|
45122
45351
|
}
|
|
45123
45352
|
}
|
|
45124
45353
|
try {
|
|
45125
|
-
value.site = new
|
|
45354
|
+
value.site = new import_mongodb106.ObjectId(value.site);
|
|
45126
45355
|
} catch (error2) {
|
|
45127
45356
|
throw new import_node_server_utils177.BadRequestError("Invalid site format");
|
|
45128
45357
|
}
|
|
45129
45358
|
try {
|
|
45130
|
-
value.createdBy = new
|
|
45359
|
+
value.createdBy = new import_mongodb106.ObjectId(value.createdBy);
|
|
45131
45360
|
} catch (error2) {
|
|
45132
45361
|
throw new import_node_server_utils177.BadRequestError("Invalid createdBy format");
|
|
45133
45362
|
}
|
|
45134
45363
|
return {
|
|
45135
|
-
_id: value._id ?? new
|
|
45364
|
+
_id: value._id ?? new import_mongodb106.ObjectId(),
|
|
45136
45365
|
site: value.site,
|
|
45137
45366
|
name: value.name,
|
|
45138
45367
|
checkPointNumber: value.checkPointNumber,
|
|
@@ -45148,7 +45377,7 @@ function MNfcPatrolRoute(value) {
|
|
|
45148
45377
|
|
|
45149
45378
|
// src/repositories/nfc-patrol-route.repository.ts
|
|
45150
45379
|
var import_node_server_utils178 = require("@7365admin1/node-server-utils");
|
|
45151
|
-
var
|
|
45380
|
+
var import_mongodb107 = require("mongodb");
|
|
45152
45381
|
function useNfcPatrolRouteRepo() {
|
|
45153
45382
|
const db = import_node_server_utils178.useAtlas.getDb();
|
|
45154
45383
|
if (!db) {
|
|
@@ -45192,7 +45421,7 @@ function useNfcPatrolRouteRepo() {
|
|
|
45192
45421
|
}, session) {
|
|
45193
45422
|
page = page > 0 ? page - 1 : 0;
|
|
45194
45423
|
try {
|
|
45195
|
-
site = new
|
|
45424
|
+
site = new import_mongodb107.ObjectId(site);
|
|
45196
45425
|
} catch (error) {
|
|
45197
45426
|
throw new import_node_server_utils178.BadRequestError("Invalid site ID format.");
|
|
45198
45427
|
}
|
|
@@ -45263,7 +45492,7 @@ function useNfcPatrolRouteRepo() {
|
|
|
45263
45492
|
}
|
|
45264
45493
|
async function getById(_id, isStart) {
|
|
45265
45494
|
try {
|
|
45266
|
-
_id = new
|
|
45495
|
+
_id = new import_mongodb107.ObjectId(_id);
|
|
45267
45496
|
} catch (error) {
|
|
45268
45497
|
throw new import_node_server_utils178.BadRequestError("Invalid ID.");
|
|
45269
45498
|
}
|
|
@@ -45373,18 +45602,18 @@ function useNfcPatrolRouteRepo() {
|
|
|
45373
45602
|
throw new import_node_server_utils178.BadRequestError(error.message);
|
|
45374
45603
|
}
|
|
45375
45604
|
try {
|
|
45376
|
-
_id = new
|
|
45605
|
+
_id = new import_mongodb107.ObjectId(_id);
|
|
45377
45606
|
} catch (error2) {
|
|
45378
45607
|
throw new import_node_server_utils178.BadRequestError("Invalid ID.");
|
|
45379
45608
|
}
|
|
45380
45609
|
try {
|
|
45381
|
-
value.site = new
|
|
45610
|
+
value.site = new import_mongodb107.ObjectId(value.site);
|
|
45382
45611
|
} catch (error2) {
|
|
45383
45612
|
throw new import_node_server_utils178.BadRequestError("Invalid site format");
|
|
45384
45613
|
}
|
|
45385
45614
|
if (value.updatedBy) {
|
|
45386
45615
|
try {
|
|
45387
|
-
value.updatedBy = new
|
|
45616
|
+
value.updatedBy = new import_mongodb107.ObjectId(value.updatedBy);
|
|
45388
45617
|
} catch (error2) {
|
|
45389
45618
|
throw new import_node_server_utils178.BadRequestError("Invalid createdBy format");
|
|
45390
45619
|
}
|
|
@@ -45609,7 +45838,7 @@ function useNfcPatrolRouteController() {
|
|
|
45609
45838
|
}
|
|
45610
45839
|
|
|
45611
45840
|
// src/models/incident-report.model.ts
|
|
45612
|
-
var
|
|
45841
|
+
var import_mongodb108 = require("mongodb");
|
|
45613
45842
|
var import_joi101 = __toESM(require("joi"));
|
|
45614
45843
|
var residentSchema = import_joi101.default.object({
|
|
45615
45844
|
_id: import_joi101.default.string().hex().optional().allow(null, ""),
|
|
@@ -45815,28 +46044,28 @@ var schemaUpdateIncidentReport = import_joi101.default.object({
|
|
|
45815
46044
|
function MIncidentReport(value) {
|
|
45816
46045
|
if (value._id && typeof value._id === "string") {
|
|
45817
46046
|
try {
|
|
45818
|
-
value._id = new
|
|
46047
|
+
value._id = new import_mongodb108.ObjectId(value._id);
|
|
45819
46048
|
} catch {
|
|
45820
46049
|
throw new Error("Invalid incident report ID.");
|
|
45821
46050
|
}
|
|
45822
46051
|
}
|
|
45823
46052
|
if (value.organization && typeof value.organization === "string") {
|
|
45824
46053
|
try {
|
|
45825
|
-
value.organization = new
|
|
46054
|
+
value.organization = new import_mongodb108.ObjectId(value.organization);
|
|
45826
46055
|
} catch {
|
|
45827
46056
|
throw new Error("Invalid organization ID.");
|
|
45828
46057
|
}
|
|
45829
46058
|
}
|
|
45830
46059
|
if (value.site && typeof value.site === "string") {
|
|
45831
46060
|
try {
|
|
45832
|
-
value.site = new
|
|
46061
|
+
value.site = new import_mongodb108.ObjectId(value.site);
|
|
45833
46062
|
} catch {
|
|
45834
46063
|
throw new Error("Invalid site ID.");
|
|
45835
46064
|
}
|
|
45836
46065
|
}
|
|
45837
46066
|
if (value.approvedBy && typeof value.approvedBy === "string") {
|
|
45838
46067
|
try {
|
|
45839
|
-
value.approvedBy = new
|
|
46068
|
+
value.approvedBy = new import_mongodb108.ObjectId(value.approvedBy);
|
|
45840
46069
|
} catch {
|
|
45841
46070
|
throw new Error("Invalid approvedBy ID.");
|
|
45842
46071
|
}
|
|
@@ -45844,7 +46073,7 @@ function MIncidentReport(value) {
|
|
|
45844
46073
|
const { incidentInformation } = value;
|
|
45845
46074
|
if (incidentInformation?.siteInfo?.site && typeof incidentInformation.siteInfo.site === "string") {
|
|
45846
46075
|
try {
|
|
45847
|
-
incidentInformation.siteInfo.site = new
|
|
46076
|
+
incidentInformation.siteInfo.site = new import_mongodb108.ObjectId(
|
|
45848
46077
|
incidentInformation.siteInfo.site
|
|
45849
46078
|
);
|
|
45850
46079
|
} catch {
|
|
@@ -45858,7 +46087,7 @@ function MIncidentReport(value) {
|
|
|
45858
46087
|
incidentInformation.submissionForm.dateOfReport = incidentInformation.submissionForm.dateOfReport.toISOString();
|
|
45859
46088
|
}
|
|
45860
46089
|
return {
|
|
45861
|
-
_id: value._id ?? new
|
|
46090
|
+
_id: value._id ?? new import_mongodb108.ObjectId(),
|
|
45862
46091
|
reportId: value.reportId,
|
|
45863
46092
|
incidentInformation: value.incidentInformation,
|
|
45864
46093
|
affectedEntities: value.affectedEntities,
|
|
@@ -45883,7 +46112,7 @@ var import_node_server_utils182 = require("@7365admin1/node-server-utils");
|
|
|
45883
46112
|
|
|
45884
46113
|
// src/repositories/incident-report.repo.ts
|
|
45885
46114
|
var import_node_server_utils181 = require("@7365admin1/node-server-utils");
|
|
45886
|
-
var
|
|
46115
|
+
var import_mongodb109 = require("mongodb");
|
|
45887
46116
|
var incidents_namespace_collection = "incident-reports";
|
|
45888
46117
|
function useIncidentReportRepo() {
|
|
45889
46118
|
const db = import_node_server_utils181.useAtlas.getDb();
|
|
@@ -45950,7 +46179,7 @@ function useIncidentReportRepo() {
|
|
|
45950
46179
|
page = page > 0 ? page - 1 : 0;
|
|
45951
46180
|
let dateExpr = {};
|
|
45952
46181
|
try {
|
|
45953
|
-
site = new
|
|
46182
|
+
site = new import_mongodb109.ObjectId(site);
|
|
45954
46183
|
} catch (error) {
|
|
45955
46184
|
throw new import_node_server_utils181.BadRequestError("Invalid site ID format.");
|
|
45956
46185
|
}
|
|
@@ -46051,7 +46280,7 @@ function useIncidentReportRepo() {
|
|
|
46051
46280
|
page = page > 0 ? page - 1 : 0;
|
|
46052
46281
|
let dateExpr = {};
|
|
46053
46282
|
try {
|
|
46054
|
-
site = new
|
|
46283
|
+
site = new import_mongodb109.ObjectId(site);
|
|
46055
46284
|
} catch (error) {
|
|
46056
46285
|
throw new import_node_server_utils181.BadRequestError("Invalid site ID format.");
|
|
46057
46286
|
}
|
|
@@ -46120,7 +46349,7 @@ function useIncidentReportRepo() {
|
|
|
46120
46349
|
}
|
|
46121
46350
|
async function getIncidentReportById(_id, session) {
|
|
46122
46351
|
try {
|
|
46123
|
-
_id = new
|
|
46352
|
+
_id = new import_mongodb109.ObjectId(_id);
|
|
46124
46353
|
} catch (error) {
|
|
46125
46354
|
throw new import_node_server_utils181.BadRequestError("Invalid incident report ID format.");
|
|
46126
46355
|
}
|
|
@@ -46151,27 +46380,27 @@ function useIncidentReportRepo() {
|
|
|
46151
46380
|
async function updateIncidentReportById(_id, value, session) {
|
|
46152
46381
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
46153
46382
|
try {
|
|
46154
|
-
_id = new
|
|
46383
|
+
_id = new import_mongodb109.ObjectId(_id);
|
|
46155
46384
|
} catch (error) {
|
|
46156
46385
|
throw new import_node_server_utils181.BadRequestError("Invalid ID format.");
|
|
46157
46386
|
}
|
|
46158
46387
|
if (value.organization && typeof value.organization === "string") {
|
|
46159
46388
|
try {
|
|
46160
|
-
value.organization = new
|
|
46389
|
+
value.organization = new import_mongodb109.ObjectId(value.organization);
|
|
46161
46390
|
} catch {
|
|
46162
46391
|
throw new Error("Invalid organization ID.");
|
|
46163
46392
|
}
|
|
46164
46393
|
}
|
|
46165
46394
|
if (value.site && typeof value.site === "string") {
|
|
46166
46395
|
try {
|
|
46167
|
-
value.site = new
|
|
46396
|
+
value.site = new import_mongodb109.ObjectId(value.site);
|
|
46168
46397
|
} catch {
|
|
46169
46398
|
throw new Error("Invalid site ID.");
|
|
46170
46399
|
}
|
|
46171
46400
|
}
|
|
46172
46401
|
if (value.approvedBy && typeof value.approvedBy === "string") {
|
|
46173
46402
|
try {
|
|
46174
|
-
value.approvedBy = new
|
|
46403
|
+
value.approvedBy = new import_mongodb109.ObjectId(value.approvedBy);
|
|
46175
46404
|
} catch {
|
|
46176
46405
|
throw new Error("Invalid approvedBy ID.");
|
|
46177
46406
|
}
|
|
@@ -46179,7 +46408,7 @@ function useIncidentReportRepo() {
|
|
|
46179
46408
|
const { incidentInformation } = value;
|
|
46180
46409
|
if (incidentInformation?.siteInfo?.site && typeof incidentInformation.siteInfo.site === "string") {
|
|
46181
46410
|
try {
|
|
46182
|
-
incidentInformation.siteInfo.site = new
|
|
46411
|
+
incidentInformation.siteInfo.site = new import_mongodb109.ObjectId(
|
|
46183
46412
|
incidentInformation.siteInfo.site
|
|
46184
46413
|
);
|
|
46185
46414
|
} catch {
|
|
@@ -46214,7 +46443,7 @@ function useIncidentReportRepo() {
|
|
|
46214
46443
|
}
|
|
46215
46444
|
async function deleteIncidentReportById(_id) {
|
|
46216
46445
|
try {
|
|
46217
|
-
_id = new
|
|
46446
|
+
_id = new import_mongodb109.ObjectId(_id);
|
|
46218
46447
|
} catch (error) {
|
|
46219
46448
|
throw new import_node_server_utils181.BadRequestError("Invalid occurrence subject ID format.");
|
|
46220
46449
|
}
|
|
@@ -46246,7 +46475,7 @@ function useIncidentReportRepo() {
|
|
|
46246
46475
|
async function reviewIncidentReport(_id, value, session) {
|
|
46247
46476
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
46248
46477
|
try {
|
|
46249
|
-
_id = new
|
|
46478
|
+
_id = new import_mongodb109.ObjectId(_id);
|
|
46250
46479
|
} catch (error) {
|
|
46251
46480
|
throw new import_node_server_utils181.BadRequestError("Invalid ID format.");
|
|
46252
46481
|
}
|
|
@@ -46739,7 +46968,7 @@ function useIncidentReportController() {
|
|
|
46739
46968
|
}
|
|
46740
46969
|
|
|
46741
46970
|
// src/models/nfc-patrol-settings.model.ts
|
|
46742
|
-
var
|
|
46971
|
+
var import_mongodb110 = require("mongodb");
|
|
46743
46972
|
var import_joi103 = __toESM(require("joi"));
|
|
46744
46973
|
var import_node_server_utils184 = require("@7365admin1/node-server-utils");
|
|
46745
46974
|
var objectId = import_joi103.default.string().hex().length(24);
|
|
@@ -46765,7 +46994,7 @@ function MNfcPatrolSettings(value) {
|
|
|
46765
46994
|
}
|
|
46766
46995
|
if (value.site) {
|
|
46767
46996
|
try {
|
|
46768
|
-
value.site = new
|
|
46997
|
+
value.site = new import_mongodb110.ObjectId(value.site);
|
|
46769
46998
|
} catch (error2) {
|
|
46770
46999
|
throw new import_node_server_utils184.BadRequestError("Invalid site ID format.");
|
|
46771
47000
|
}
|
|
@@ -46785,7 +47014,7 @@ function MNfcPatrolSettingsUpdate(value) {
|
|
|
46785
47014
|
}
|
|
46786
47015
|
if (value.updatedBy) {
|
|
46787
47016
|
try {
|
|
46788
|
-
value.updatedBy = new
|
|
47017
|
+
value.updatedBy = new import_mongodb110.ObjectId(value.updatedBy);
|
|
46789
47018
|
} catch (error2) {
|
|
46790
47019
|
throw new import_node_server_utils184.BadRequestError("Invalid updatedBy ID format.");
|
|
46791
47020
|
}
|
|
@@ -46799,7 +47028,7 @@ function MNfcPatrolSettingsUpdate(value) {
|
|
|
46799
47028
|
|
|
46800
47029
|
// src/repositories/nfc-patrol-settings.repository.ts
|
|
46801
47030
|
var import_node_server_utils185 = require("@7365admin1/node-server-utils");
|
|
46802
|
-
var
|
|
47031
|
+
var import_mongodb111 = require("mongodb");
|
|
46803
47032
|
function useNfcPatrolSettingsRepository() {
|
|
46804
47033
|
const db = import_node_server_utils185.useAtlas.getDb();
|
|
46805
47034
|
if (!db) {
|
|
@@ -46829,7 +47058,7 @@ function useNfcPatrolSettingsRepository() {
|
|
|
46829
47058
|
}
|
|
46830
47059
|
async function getNfcPatrolSettingsBySite(site, session) {
|
|
46831
47060
|
try {
|
|
46832
|
-
site = new
|
|
47061
|
+
site = new import_mongodb111.ObjectId(site);
|
|
46833
47062
|
} catch (error) {
|
|
46834
47063
|
throw new import_node_server_utils185.BadRequestError("Invalid nfc patrol settings site ID format.");
|
|
46835
47064
|
}
|
|
@@ -46873,7 +47102,7 @@ function useNfcPatrolSettingsRepository() {
|
|
|
46873
47102
|
}
|
|
46874
47103
|
async function updateNfcPatrolSettings(site, value, session) {
|
|
46875
47104
|
try {
|
|
46876
|
-
site = new
|
|
47105
|
+
site = new import_mongodb111.ObjectId(site);
|
|
46877
47106
|
} catch (error) {
|
|
46878
47107
|
throw new import_node_server_utils185.BadRequestError("Invalid attendance settings ID format.");
|
|
46879
47108
|
}
|
|
@@ -47038,13 +47267,13 @@ function useNfcPatrolSettingsController() {
|
|
|
47038
47267
|
|
|
47039
47268
|
// src/services/occurrence-entry.service.ts
|
|
47040
47269
|
var import_node_server_utils189 = require("@7365admin1/node-server-utils");
|
|
47041
|
-
var
|
|
47270
|
+
var import_mongodb114 = require("mongodb");
|
|
47042
47271
|
|
|
47043
47272
|
// src/repositories/occurrence-subject.repo.ts
|
|
47044
47273
|
var import_node_server_utils188 = require("@7365admin1/node-server-utils");
|
|
47045
47274
|
|
|
47046
47275
|
// src/models/occurrence-subject.model.ts
|
|
47047
|
-
var
|
|
47276
|
+
var import_mongodb112 = require("mongodb");
|
|
47048
47277
|
var import_joi105 = __toESM(require("joi"));
|
|
47049
47278
|
var SubjectSort = /* @__PURE__ */ ((SubjectSort2) => {
|
|
47050
47279
|
SubjectSort2["CREATED_AT"] = "createdAt";
|
|
@@ -47069,27 +47298,27 @@ var schemaUpdateOccurrenceSubject = import_joi105.default.object({
|
|
|
47069
47298
|
function MOccurrenceSubject(value) {
|
|
47070
47299
|
if (value._id && typeof value._id === "string") {
|
|
47071
47300
|
try {
|
|
47072
|
-
value._id = new
|
|
47301
|
+
value._id = new import_mongodb112.ObjectId(value._id);
|
|
47073
47302
|
} catch {
|
|
47074
47303
|
throw new Error("Invalid ID.");
|
|
47075
47304
|
}
|
|
47076
47305
|
}
|
|
47077
47306
|
if (value.site && typeof value.site === "string") {
|
|
47078
47307
|
try {
|
|
47079
|
-
value.site = new
|
|
47308
|
+
value.site = new import_mongodb112.ObjectId(value.site);
|
|
47080
47309
|
} catch {
|
|
47081
47310
|
throw new Error("Invalid site ID.");
|
|
47082
47311
|
}
|
|
47083
47312
|
}
|
|
47084
47313
|
if (value.addedBy && typeof value.addedBy === "string") {
|
|
47085
47314
|
try {
|
|
47086
|
-
value.addedBy = new
|
|
47315
|
+
value.addedBy = new import_mongodb112.ObjectId(value.addedBy);
|
|
47087
47316
|
} catch {
|
|
47088
47317
|
throw new Error("Invalid addedBy ID.");
|
|
47089
47318
|
}
|
|
47090
47319
|
}
|
|
47091
47320
|
return {
|
|
47092
|
-
_id: value._id ?? new
|
|
47321
|
+
_id: value._id ?? new import_mongodb112.ObjectId(),
|
|
47093
47322
|
site: value.site,
|
|
47094
47323
|
subject: value.subject,
|
|
47095
47324
|
addedBy: value.addedBy ?? "",
|
|
@@ -47100,7 +47329,7 @@ function MOccurrenceSubject(value) {
|
|
|
47100
47329
|
}
|
|
47101
47330
|
|
|
47102
47331
|
// src/repositories/occurrence-subject.repo.ts
|
|
47103
|
-
var
|
|
47332
|
+
var import_mongodb113 = require("mongodb");
|
|
47104
47333
|
function useOccurrenceSubjectRepo() {
|
|
47105
47334
|
const db = import_node_server_utils188.useAtlas.getDb();
|
|
47106
47335
|
if (!db) {
|
|
@@ -47159,7 +47388,7 @@ function useOccurrenceSubjectRepo() {
|
|
|
47159
47388
|
}, session) {
|
|
47160
47389
|
page = page > 0 ? page - 1 : 0;
|
|
47161
47390
|
try {
|
|
47162
|
-
site = new
|
|
47391
|
+
site = new import_mongodb113.ObjectId(site);
|
|
47163
47392
|
} catch (error) {
|
|
47164
47393
|
throw new import_node_server_utils188.BadRequestError("Invalid site ID format.");
|
|
47165
47394
|
}
|
|
@@ -47252,7 +47481,7 @@ function useOccurrenceSubjectRepo() {
|
|
|
47252
47481
|
}
|
|
47253
47482
|
async function getOccurrenceSubjectById(_id, session) {
|
|
47254
47483
|
try {
|
|
47255
|
-
_id = new
|
|
47484
|
+
_id = new import_mongodb113.ObjectId(_id);
|
|
47256
47485
|
} catch (error) {
|
|
47257
47486
|
throw new import_node_server_utils188.BadRequestError("Invalid occurrence subject ID format.");
|
|
47258
47487
|
}
|
|
@@ -47280,7 +47509,7 @@ function useOccurrenceSubjectRepo() {
|
|
|
47280
47509
|
async function updateOccurrenceSubjectById(_id, value, session) {
|
|
47281
47510
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
47282
47511
|
try {
|
|
47283
|
-
_id = new
|
|
47512
|
+
_id = new import_mongodb113.ObjectId(_id);
|
|
47284
47513
|
} catch (error) {
|
|
47285
47514
|
throw new import_node_server_utils188.BadRequestError("Invalid ID format.");
|
|
47286
47515
|
}
|
|
@@ -47310,7 +47539,7 @@ function useOccurrenceSubjectRepo() {
|
|
|
47310
47539
|
}
|
|
47311
47540
|
async function deleteOccurrenceSubjectById(_id) {
|
|
47312
47541
|
try {
|
|
47313
|
-
_id = new
|
|
47542
|
+
_id = new import_mongodb113.ObjectId(_id);
|
|
47314
47543
|
} catch (error) {
|
|
47315
47544
|
throw new import_node_server_utils188.BadRequestError("Invalid occurrence subject ID format.");
|
|
47316
47545
|
}
|
|
@@ -47441,8 +47670,8 @@ function useOccurrenceEntryService() {
|
|
|
47441
47670
|
value.dailyOccurrenceBookId = occurrenceEntry.dailyOccurrenceBookId;
|
|
47442
47671
|
value.bookEntryCount = value.bookEntryCount ? value.bookEntryCount : occurrenceEntry.bookEntryCount;
|
|
47443
47672
|
value.occurrence = value.occurrence ? value.occurrence : occurrenceEntry.occurrence;
|
|
47444
|
-
value.signature = value.signature ? new
|
|
47445
|
-
value.eSignature = value.eSignature ? new
|
|
47673
|
+
value.signature = value.signature ? new import_mongodb114.ObjectId(value.signature) : occurrenceEntry.signature._id;
|
|
47674
|
+
value.eSignature = value.eSignature ? new import_mongodb114.ObjectId(value.eSignature) : occurrenceEntry.eSignature;
|
|
47446
47675
|
value.createdAt = /* @__PURE__ */ new Date();
|
|
47447
47676
|
value.date = value.date ? value.date : occurrenceEntry.date;
|
|
47448
47677
|
value.userName = value.userName ? value.userName : occurrenceEntry.signature.name;
|
|
@@ -47634,7 +47863,7 @@ function useOccurrenceEntryController() {
|
|
|
47634
47863
|
|
|
47635
47864
|
// src/models/online-form.model.ts
|
|
47636
47865
|
var import_joi107 = __toESM(require("joi"));
|
|
47637
|
-
var
|
|
47866
|
+
var import_mongodb115 = require("mongodb");
|
|
47638
47867
|
var schemaOnlineForm = import_joi107.default.object({
|
|
47639
47868
|
_id: import_joi107.default.string().hex().optional().allow("", null),
|
|
47640
47869
|
name: import_joi107.default.string().required(),
|
|
@@ -47682,21 +47911,21 @@ function MOnlineForm(value) {
|
|
|
47682
47911
|
}
|
|
47683
47912
|
if (value._id && typeof value._id === "string") {
|
|
47684
47913
|
try {
|
|
47685
|
-
value._id = new
|
|
47914
|
+
value._id = new import_mongodb115.ObjectId(value._id);
|
|
47686
47915
|
} catch (error2) {
|
|
47687
47916
|
throw new Error("Invalid ID.");
|
|
47688
47917
|
}
|
|
47689
47918
|
}
|
|
47690
47919
|
if (value.org && typeof value.org === "string") {
|
|
47691
47920
|
try {
|
|
47692
|
-
value.org = new
|
|
47921
|
+
value.org = new import_mongodb115.ObjectId(value.org);
|
|
47693
47922
|
} catch (error2) {
|
|
47694
47923
|
throw new Error("Invalid org ID.");
|
|
47695
47924
|
}
|
|
47696
47925
|
}
|
|
47697
47926
|
if (value.site && typeof value.site === "string") {
|
|
47698
47927
|
try {
|
|
47699
|
-
value.site = new
|
|
47928
|
+
value.site = new import_mongodb115.ObjectId(value.site);
|
|
47700
47929
|
} catch (error2) {
|
|
47701
47930
|
throw new Error("Invalid site ID.");
|
|
47702
47931
|
}
|
|
@@ -47719,7 +47948,7 @@ function MOnlineForm(value) {
|
|
|
47719
47948
|
|
|
47720
47949
|
// src/repositories/online-form.repo.ts
|
|
47721
47950
|
var import_node_server_utils191 = require("@7365admin1/node-server-utils");
|
|
47722
|
-
var
|
|
47951
|
+
var import_mongodb116 = require("mongodb");
|
|
47723
47952
|
function useOnlineFormRepo() {
|
|
47724
47953
|
const db = import_node_server_utils191.useAtlas.getDb();
|
|
47725
47954
|
if (!db) {
|
|
@@ -47771,7 +48000,7 @@ function useOnlineFormRepo() {
|
|
|
47771
48000
|
}) {
|
|
47772
48001
|
page = page > 0 ? page - 1 : 0;
|
|
47773
48002
|
try {
|
|
47774
|
-
site = new
|
|
48003
|
+
site = new import_mongodb116.ObjectId(site);
|
|
47775
48004
|
} catch (error) {
|
|
47776
48005
|
throw new import_node_server_utils191.BadRequestError("Invalid site ID format.");
|
|
47777
48006
|
}
|
|
@@ -47831,7 +48060,7 @@ function useOnlineFormRepo() {
|
|
|
47831
48060
|
}
|
|
47832
48061
|
async function getOnlineFormById(_id) {
|
|
47833
48062
|
try {
|
|
47834
|
-
_id = new
|
|
48063
|
+
_id = new import_mongodb116.ObjectId(_id);
|
|
47835
48064
|
} catch (error) {
|
|
47836
48065
|
throw new import_node_server_utils191.BadRequestError("Invalid online form ID format.");
|
|
47837
48066
|
}
|
|
@@ -47874,7 +48103,7 @@ function useOnlineFormRepo() {
|
|
|
47874
48103
|
}
|
|
47875
48104
|
async function updateOnlineFormById(_id, value) {
|
|
47876
48105
|
try {
|
|
47877
|
-
_id = new
|
|
48106
|
+
_id = new import_mongodb116.ObjectId(_id);
|
|
47878
48107
|
} catch (error) {
|
|
47879
48108
|
throw new import_node_server_utils191.BadRequestError("Invalid online form ID format.");
|
|
47880
48109
|
}
|
|
@@ -47902,7 +48131,7 @@ function useOnlineFormRepo() {
|
|
|
47902
48131
|
}
|
|
47903
48132
|
async function deleteOnlineFormById(_id, session) {
|
|
47904
48133
|
try {
|
|
47905
|
-
_id = new
|
|
48134
|
+
_id = new import_mongodb116.ObjectId(_id);
|
|
47906
48135
|
} catch (error) {
|
|
47907
48136
|
throw new import_node_server_utils191.BadRequestError("Invalid online form ID format.");
|
|
47908
48137
|
}
|
|
@@ -47935,7 +48164,7 @@ function useOnlineFormRepo() {
|
|
|
47935
48164
|
}
|
|
47936
48165
|
async function getOnlineFormsBySiteId(site, { search = "", page = 1, limit = 10, status = "active" }) {
|
|
47937
48166
|
try {
|
|
47938
|
-
site = new
|
|
48167
|
+
site = new import_mongodb116.ObjectId(site);
|
|
47939
48168
|
} catch (error) {
|
|
47940
48169
|
throw new import_node_server_utils191.BadRequestError(
|
|
47941
48170
|
"Invalid online form configuration site ID format."
|
|
@@ -48367,7 +48596,7 @@ function useOccurrenceSubjectController() {
|
|
|
48367
48596
|
}
|
|
48368
48597
|
|
|
48369
48598
|
// src/models/nfc-patrol-log.model.ts
|
|
48370
|
-
var
|
|
48599
|
+
var import_mongodb117 = require("mongodb");
|
|
48371
48600
|
var import_joi110 = __toESM(require("joi"));
|
|
48372
48601
|
var import_node_server_utils195 = require("@7365admin1/node-server-utils");
|
|
48373
48602
|
var schemaNfcPatrolLog = import_joi110.default.object({
|
|
@@ -48419,32 +48648,32 @@ function MNfcPatrolLog(valueArg) {
|
|
|
48419
48648
|
}
|
|
48420
48649
|
if (value._id && typeof value._id === "string") {
|
|
48421
48650
|
try {
|
|
48422
|
-
value._id = new
|
|
48651
|
+
value._id = new import_mongodb117.ObjectId(value._id);
|
|
48423
48652
|
} catch (error2) {
|
|
48424
48653
|
throw new import_node_server_utils195.BadRequestError("Invalid _id format");
|
|
48425
48654
|
}
|
|
48426
48655
|
}
|
|
48427
48656
|
try {
|
|
48428
|
-
value.site = new
|
|
48657
|
+
value.site = new import_mongodb117.ObjectId(value.site);
|
|
48429
48658
|
} catch (error2) {
|
|
48430
48659
|
throw new import_node_server_utils195.BadRequestError("Invalid site format");
|
|
48431
48660
|
}
|
|
48432
48661
|
if (value?.createdBy) {
|
|
48433
48662
|
try {
|
|
48434
|
-
value.createdBy = new
|
|
48663
|
+
value.createdBy = new import_mongodb117.ObjectId(value.createdBy);
|
|
48435
48664
|
} catch (error2) {
|
|
48436
48665
|
throw new import_node_server_utils195.BadRequestError("Invalid createdBy format");
|
|
48437
48666
|
}
|
|
48438
48667
|
}
|
|
48439
48668
|
if (value?.route?._id) {
|
|
48440
48669
|
try {
|
|
48441
|
-
value.route._id = new
|
|
48670
|
+
value.route._id = new import_mongodb117.ObjectId(value.route._id);
|
|
48442
48671
|
} catch (error2) {
|
|
48443
48672
|
throw new import_node_server_utils195.BadRequestError("Invalid route _id format");
|
|
48444
48673
|
}
|
|
48445
48674
|
}
|
|
48446
48675
|
return {
|
|
48447
|
-
_id: value._id ?? new
|
|
48676
|
+
_id: value._id ?? new import_mongodb117.ObjectId(),
|
|
48448
48677
|
site: value.site,
|
|
48449
48678
|
route: value.route,
|
|
48450
48679
|
date: value.date,
|
|
@@ -48458,7 +48687,7 @@ function MNfcPatrolLog(valueArg) {
|
|
|
48458
48687
|
|
|
48459
48688
|
// src/repositories/nfc-patrol-log.repository.ts
|
|
48460
48689
|
var import_node_server_utils196 = require("@7365admin1/node-server-utils");
|
|
48461
|
-
var
|
|
48690
|
+
var import_mongodb118 = require("mongodb");
|
|
48462
48691
|
function useNfcPatrolLogRepo() {
|
|
48463
48692
|
const db = import_node_server_utils196.useAtlas.getDb();
|
|
48464
48693
|
if (!db) {
|
|
@@ -48511,7 +48740,7 @@ function useNfcPatrolLogRepo() {
|
|
|
48511
48740
|
const pageIndex = page > 0 ? page - 1 : 0;
|
|
48512
48741
|
let siteId;
|
|
48513
48742
|
try {
|
|
48514
|
-
siteId = typeof site === "string" ? new
|
|
48743
|
+
siteId = typeof site === "string" ? new import_mongodb118.ObjectId(site) : site;
|
|
48515
48744
|
} catch {
|
|
48516
48745
|
throw new import_node_server_utils196.BadRequestError("Invalid site ID format.");
|
|
48517
48746
|
}
|
|
@@ -48522,7 +48751,7 @@ function useNfcPatrolLogRepo() {
|
|
|
48522
48751
|
query.date = date;
|
|
48523
48752
|
}
|
|
48524
48753
|
if (route?._id) {
|
|
48525
|
-
query["route._id"] = typeof route._id === "string" ? new
|
|
48754
|
+
query["route._id"] = typeof route._id === "string" ? new import_mongodb118.ObjectId(route._id) : route._id;
|
|
48526
48755
|
}
|
|
48527
48756
|
if (route?.startTime) {
|
|
48528
48757
|
query["route.startTime"] = route.startTime;
|
|
@@ -49381,7 +49610,7 @@ function useNewDashboardController() {
|
|
|
49381
49610
|
|
|
49382
49611
|
// src/models/manpower-monitoring.model.ts
|
|
49383
49612
|
var import_joi113 = __toESM(require("joi"));
|
|
49384
|
-
var
|
|
49613
|
+
var import_mongodb119 = require("mongodb");
|
|
49385
49614
|
var shiftSchema = import_joi113.default.object({
|
|
49386
49615
|
name: import_joi113.default.string().required(),
|
|
49387
49616
|
checkIn: import_joi113.default.string().optional().allow("", null),
|
|
@@ -49406,7 +49635,7 @@ var manpowerMonitoringSchema = import_joi113.default.object({
|
|
|
49406
49635
|
});
|
|
49407
49636
|
var MManpowerMonitoring = class {
|
|
49408
49637
|
constructor(data) {
|
|
49409
|
-
this._id = new
|
|
49638
|
+
this._id = new import_mongodb119.ObjectId();
|
|
49410
49639
|
this.serviceProviderId = data.serviceProviderId || "";
|
|
49411
49640
|
this.siteId = data.siteId || "";
|
|
49412
49641
|
this.siteName = data.siteName;
|
|
@@ -49873,7 +50102,7 @@ var hrmlabs_attendance_util_default = {
|
|
|
49873
50102
|
};
|
|
49874
50103
|
|
|
49875
50104
|
// src/repositories/manpower-monitoring.repo.ts
|
|
49876
|
-
var
|
|
50105
|
+
var import_mongodb120 = require("mongodb");
|
|
49877
50106
|
var { hrmLabsAuthentication: hrmLabsAuthentication2, fetchSites: fetchSites2 } = hrmlabs_attendance_util_default;
|
|
49878
50107
|
function useManpowerMonitoringRepo() {
|
|
49879
50108
|
const db = import_node_server_utils201.useAtlas.getDb();
|
|
@@ -49908,11 +50137,11 @@ function useManpowerMonitoringRepo() {
|
|
|
49908
50137
|
try {
|
|
49909
50138
|
value = new MManpowerMonitoring(value);
|
|
49910
50139
|
if (value.createdBy)
|
|
49911
|
-
value.createdBy = new
|
|
50140
|
+
value.createdBy = new import_mongodb120.ObjectId(value.createdBy);
|
|
49912
50141
|
if (value.siteId)
|
|
49913
|
-
value.siteId = new
|
|
50142
|
+
value.siteId = new import_mongodb120.ObjectId(value.siteId);
|
|
49914
50143
|
if (value.serviceProviderId)
|
|
49915
|
-
value.serviceProviderId = new
|
|
50144
|
+
value.serviceProviderId = new import_mongodb120.ObjectId(value.serviceProviderId);
|
|
49916
50145
|
const result = await collection.insertOne(value, { session });
|
|
49917
50146
|
return result;
|
|
49918
50147
|
} catch (error) {
|
|
@@ -49953,8 +50182,8 @@ function useManpowerMonitoringRepo() {
|
|
|
49953
50182
|
}
|
|
49954
50183
|
async function getManpowerSettingsBySiteId(_id, serviceProviderId) {
|
|
49955
50184
|
try {
|
|
49956
|
-
_id = new
|
|
49957
|
-
serviceProviderId = new
|
|
50185
|
+
_id = new import_mongodb120.ObjectId(_id);
|
|
50186
|
+
serviceProviderId = new import_mongodb120.ObjectId(serviceProviderId);
|
|
49958
50187
|
} catch (error) {
|
|
49959
50188
|
throw new Error("Invalid Site ID format.");
|
|
49960
50189
|
}
|
|
@@ -49970,7 +50199,7 @@ function useManpowerMonitoringRepo() {
|
|
|
49970
50199
|
}
|
|
49971
50200
|
async function updateManpowerMonitoringSettings(_id, value) {
|
|
49972
50201
|
try {
|
|
49973
|
-
_id = new
|
|
50202
|
+
_id = new import_mongodb120.ObjectId(_id);
|
|
49974
50203
|
} catch (error) {
|
|
49975
50204
|
throw new import_node_server_utils201.BadRequestError("Invalid ID format.");
|
|
49976
50205
|
}
|
|
@@ -49997,7 +50226,7 @@ function useManpowerMonitoringRepo() {
|
|
|
49997
50226
|
for (let item of value) {
|
|
49998
50227
|
item = new MManpowerMonitoring(item);
|
|
49999
50228
|
const data = await collection.findOne({
|
|
50000
|
-
siteId: new
|
|
50229
|
+
siteId: new import_mongodb120.ObjectId(item.siteId)
|
|
50001
50230
|
});
|
|
50002
50231
|
if (data) {
|
|
50003
50232
|
let updateValue;
|
|
@@ -50022,11 +50251,11 @@ function useManpowerMonitoringRepo() {
|
|
|
50022
50251
|
}
|
|
50023
50252
|
} else {
|
|
50024
50253
|
if (item.createdBy)
|
|
50025
|
-
item.createdBy = new
|
|
50254
|
+
item.createdBy = new import_mongodb120.ObjectId(item.createdBy);
|
|
50026
50255
|
if (item.siteId)
|
|
50027
|
-
item.siteId = new
|
|
50256
|
+
item.siteId = new import_mongodb120.ObjectId(item.siteId);
|
|
50028
50257
|
if (item.serviceProviderId)
|
|
50029
|
-
item.serviceProviderId = new
|
|
50258
|
+
item.serviceProviderId = new import_mongodb120.ObjectId(item.serviceProviderId);
|
|
50030
50259
|
const result = await collection.insertOne(item);
|
|
50031
50260
|
if (result.insertedId) {
|
|
50032
50261
|
results.inserted++;
|
|
@@ -50050,7 +50279,7 @@ function useManpowerMonitoringRepo() {
|
|
|
50050
50279
|
const siteUrl = process.env.HRMLABS_SITE_URL;
|
|
50051
50280
|
try {
|
|
50052
50281
|
const serviceProvider = await serviceProviderCollection.findOne({
|
|
50053
|
-
_id: new
|
|
50282
|
+
_id: new import_mongodb120.ObjectId(serviceProviderId)
|
|
50054
50283
|
});
|
|
50055
50284
|
if (!serviceProvider) {
|
|
50056
50285
|
throw new Error("Service Provider not found.");
|
|
@@ -50093,7 +50322,7 @@ var import_node_server_utils202 = require("@7365admin1/node-server-utils");
|
|
|
50093
50322
|
|
|
50094
50323
|
// src/models/manpower-remarks.model.ts
|
|
50095
50324
|
var import_joi114 = __toESM(require("joi"));
|
|
50096
|
-
var
|
|
50325
|
+
var import_mongodb121 = require("mongodb");
|
|
50097
50326
|
var remarksSchema = import_joi114.default.object({
|
|
50098
50327
|
name: import_joi114.default.string().required(),
|
|
50099
50328
|
remark: import_joi114.default.object({
|
|
@@ -50117,7 +50346,7 @@ var manpowerRemarksSchema = import_joi114.default.object({
|
|
|
50117
50346
|
});
|
|
50118
50347
|
var MManpowerRemarks = class {
|
|
50119
50348
|
constructor(data) {
|
|
50120
|
-
this._id = new
|
|
50349
|
+
this._id = new import_mongodb121.ObjectId();
|
|
50121
50350
|
this.serviceProviderId = data.serviceProviderId || "";
|
|
50122
50351
|
this.siteId = data.siteId || "";
|
|
50123
50352
|
this.siteName = data.siteName || "";
|
|
@@ -50135,7 +50364,7 @@ var MManpowerRemarks = class {
|
|
|
50135
50364
|
};
|
|
50136
50365
|
|
|
50137
50366
|
// src/repositories/manpower-remarks.repo.ts
|
|
50138
|
-
var
|
|
50367
|
+
var import_mongodb122 = require("mongodb");
|
|
50139
50368
|
var import_moment_timezone2 = __toESM(require("moment-timezone"));
|
|
50140
50369
|
function useManpowerRemarksRepo() {
|
|
50141
50370
|
const db = import_node_server_utils202.useAtlas.getDb();
|
|
@@ -50169,9 +50398,9 @@ function useManpowerRemarksRepo() {
|
|
|
50169
50398
|
try {
|
|
50170
50399
|
value = new MManpowerRemarks(value);
|
|
50171
50400
|
if (value.siteId)
|
|
50172
|
-
value.siteId = new
|
|
50401
|
+
value.siteId = new import_mongodb122.ObjectId(value.siteId);
|
|
50173
50402
|
if (value.serviceProviderId)
|
|
50174
|
-
value.serviceProviderId = new
|
|
50403
|
+
value.serviceProviderId = new import_mongodb122.ObjectId(value.serviceProviderId);
|
|
50175
50404
|
const result = await collection.insertOne(value, { session });
|
|
50176
50405
|
return result;
|
|
50177
50406
|
} catch (error) {
|
|
@@ -50191,7 +50420,7 @@ function useManpowerRemarksRepo() {
|
|
|
50191
50420
|
limit = limit || 10;
|
|
50192
50421
|
const searchQuery = {};
|
|
50193
50422
|
const nowSGT = (0, import_moment_timezone2.default)().tz("Asia/Singapore");
|
|
50194
|
-
searchQuery.serviceProviderId = new
|
|
50423
|
+
searchQuery.serviceProviderId = new import_mongodb122.ObjectId(serviceProviderId);
|
|
50195
50424
|
if (search != "") {
|
|
50196
50425
|
searchQuery.siteName = { $regex: search, $options: "i" };
|
|
50197
50426
|
}
|
|
@@ -50223,8 +50452,8 @@ function useManpowerRemarksRepo() {
|
|
|
50223
50452
|
}
|
|
50224
50453
|
async function getManpowerRemarksBySiteId(_id, date, serviceProviderId) {
|
|
50225
50454
|
try {
|
|
50226
|
-
_id = new
|
|
50227
|
-
serviceProviderId = new
|
|
50455
|
+
_id = new import_mongodb122.ObjectId(_id);
|
|
50456
|
+
serviceProviderId = new import_mongodb122.ObjectId(serviceProviderId);
|
|
50228
50457
|
} catch (error) {
|
|
50229
50458
|
throw new Error("Invalid Site ID format.");
|
|
50230
50459
|
}
|
|
@@ -50241,13 +50470,13 @@ function useManpowerRemarksRepo() {
|
|
|
50241
50470
|
}
|
|
50242
50471
|
async function updateManpowerRemarks(_id, value) {
|
|
50243
50472
|
try {
|
|
50244
|
-
_id = new
|
|
50473
|
+
_id = new import_mongodb122.ObjectId(_id);
|
|
50245
50474
|
} catch (error) {
|
|
50246
50475
|
throw new import_node_server_utils202.BadRequestError("Invalid ID format.");
|
|
50247
50476
|
}
|
|
50248
50477
|
try {
|
|
50249
50478
|
if (value.createdBy) {
|
|
50250
|
-
value.createdBy = new
|
|
50479
|
+
value.createdBy = new import_mongodb122.ObjectId(value.createdBy);
|
|
50251
50480
|
}
|
|
50252
50481
|
const updateValue = {
|
|
50253
50482
|
...value,
|
|
@@ -50264,7 +50493,7 @@ function useManpowerRemarksRepo() {
|
|
|
50264
50493
|
}
|
|
50265
50494
|
async function updateRemarksStatus(_id, value) {
|
|
50266
50495
|
try {
|
|
50267
|
-
_id = new
|
|
50496
|
+
_id = new import_mongodb122.ObjectId(_id);
|
|
50268
50497
|
} catch (error) {
|
|
50269
50498
|
throw new import_node_server_utils202.BadRequestError("Invalid ID format.");
|
|
50270
50499
|
}
|
|
@@ -50534,7 +50763,7 @@ function useManpowerMonitoringCtrl() {
|
|
|
50534
50763
|
|
|
50535
50764
|
// src/models/manpower-designations.model.ts
|
|
50536
50765
|
var import_joi116 = __toESM(require("joi"));
|
|
50537
|
-
var
|
|
50766
|
+
var import_mongodb123 = require("mongodb");
|
|
50538
50767
|
var designationsSchema = import_joi116.default.object({
|
|
50539
50768
|
title: import_joi116.default.string().required(),
|
|
50540
50769
|
shifts: import_joi116.default.object({
|
|
@@ -50553,7 +50782,7 @@ var manpowerDesignationsSchema = import_joi116.default.object({
|
|
|
50553
50782
|
});
|
|
50554
50783
|
var MManpowerDesignations = class {
|
|
50555
50784
|
constructor(data) {
|
|
50556
|
-
this._id = new
|
|
50785
|
+
this._id = new import_mongodb123.ObjectId();
|
|
50557
50786
|
this.siteId = data.siteId || "";
|
|
50558
50787
|
this.siteName = data.siteName || "";
|
|
50559
50788
|
this.serviceProviderId = data.serviceProviderId || "";
|
|
@@ -50567,7 +50796,7 @@ var MManpowerDesignations = class {
|
|
|
50567
50796
|
|
|
50568
50797
|
// src/repositories/manpower-designations.repo.ts
|
|
50569
50798
|
var import_node_server_utils205 = require("@7365admin1/node-server-utils");
|
|
50570
|
-
var
|
|
50799
|
+
var import_mongodb124 = require("mongodb");
|
|
50571
50800
|
function useManpowerDesignationRepo() {
|
|
50572
50801
|
const db = import_node_server_utils205.useAtlas.getDb();
|
|
50573
50802
|
if (!db) {
|
|
@@ -50599,11 +50828,11 @@ function useManpowerDesignationRepo() {
|
|
|
50599
50828
|
try {
|
|
50600
50829
|
value = new MManpowerDesignations(value);
|
|
50601
50830
|
if (value.createdBy)
|
|
50602
|
-
value.createdBy = new
|
|
50831
|
+
value.createdBy = new import_mongodb124.ObjectId(value.createdBy);
|
|
50603
50832
|
if (value.siteId)
|
|
50604
|
-
value.siteId = new
|
|
50833
|
+
value.siteId = new import_mongodb124.ObjectId(value.siteId);
|
|
50605
50834
|
if (value.serviceProviderId)
|
|
50606
|
-
value.serviceProviderId = new
|
|
50835
|
+
value.serviceProviderId = new import_mongodb124.ObjectId(value.serviceProviderId);
|
|
50607
50836
|
const result = await collection.insertOne(value);
|
|
50608
50837
|
return result;
|
|
50609
50838
|
} catch (error) {
|
|
@@ -50612,8 +50841,8 @@ function useManpowerDesignationRepo() {
|
|
|
50612
50841
|
}
|
|
50613
50842
|
async function getManpowerDesignationsBySiteId(_id, serviceProviderId) {
|
|
50614
50843
|
try {
|
|
50615
|
-
_id = new
|
|
50616
|
-
serviceProviderId = new
|
|
50844
|
+
_id = new import_mongodb124.ObjectId(_id);
|
|
50845
|
+
serviceProviderId = new import_mongodb124.ObjectId(serviceProviderId);
|
|
50617
50846
|
} catch (error) {
|
|
50618
50847
|
throw new Error("Invalid Site ID format.");
|
|
50619
50848
|
}
|
|
@@ -50629,7 +50858,7 @@ function useManpowerDesignationRepo() {
|
|
|
50629
50858
|
}
|
|
50630
50859
|
async function updateManpowerDesignations(_id, value) {
|
|
50631
50860
|
try {
|
|
50632
|
-
_id = new
|
|
50861
|
+
_id = new import_mongodb124.ObjectId(_id);
|
|
50633
50862
|
} catch (error) {
|
|
50634
50863
|
throw new Error("Invalid ID format.");
|
|
50635
50864
|
}
|
|
@@ -50733,7 +50962,7 @@ function useManpowerDesignationCtrl() {
|
|
|
50733
50962
|
|
|
50734
50963
|
// src/models/overnight-parking.model.ts
|
|
50735
50964
|
var import_joi118 = __toESM(require("joi"));
|
|
50736
|
-
var
|
|
50965
|
+
var import_mongodb125 = require("mongodb");
|
|
50737
50966
|
var dayScheduleSchema = import_joi118.default.object({
|
|
50738
50967
|
isEnabled: import_joi118.default.boolean().required(),
|
|
50739
50968
|
startTime: import_joi118.default.string().pattern(/^([01]\d|2[0-3]):([0-5]\d)$/).optional().allow(null, "").messages({
|
|
@@ -50775,7 +51004,7 @@ function MOvernightParkingApprovalHours(value) {
|
|
|
50775
51004
|
}
|
|
50776
51005
|
if (value.site && typeof value.site === "string") {
|
|
50777
51006
|
try {
|
|
50778
|
-
value.site = new
|
|
51007
|
+
value.site = new import_mongodb125.ObjectId(value.site);
|
|
50779
51008
|
} catch {
|
|
50780
51009
|
throw new Error("Invalid site ID.");
|
|
50781
51010
|
}
|
|
@@ -52380,7 +52609,7 @@ function useManpowerRemarkCtrl() {
|
|
|
52380
52609
|
|
|
52381
52610
|
// src/models/manpower-sites.model.ts
|
|
52382
52611
|
var import_joi124 = __toESM(require("joi"));
|
|
52383
|
-
var
|
|
52612
|
+
var import_mongodb126 = require("mongodb");
|
|
52384
52613
|
var manpowerSitesSchema = import_joi124.default.object({
|
|
52385
52614
|
id: import_joi124.default.string().hex().required(),
|
|
52386
52615
|
text: import_joi124.default.string().hex().optional().allow("", null),
|
|
@@ -52391,7 +52620,7 @@ var manpowerSitesSchema = import_joi124.default.object({
|
|
|
52391
52620
|
});
|
|
52392
52621
|
var MManpowerSites = class {
|
|
52393
52622
|
constructor(data) {
|
|
52394
|
-
this._id = new
|
|
52623
|
+
this._id = new import_mongodb126.ObjectId();
|
|
52395
52624
|
this.id = data.id || "";
|
|
52396
52625
|
this.text = data.text || "";
|
|
52397
52626
|
this.contractID = data.contractID || "";
|
|
@@ -52601,7 +52830,7 @@ function useManpowerSitesCtrl() {
|
|
|
52601
52830
|
|
|
52602
52831
|
// src/utils/cron.util.ts
|
|
52603
52832
|
var import_node_server_utils219 = require("@7365admin1/node-server-utils");
|
|
52604
|
-
var
|
|
52833
|
+
var import_mongodb127 = require("mongodb");
|
|
52605
52834
|
var import_moment_timezone4 = __toESM(require("moment-timezone"));
|
|
52606
52835
|
var createManpowerRemarksDaily = async () => {
|
|
52607
52836
|
const db = import_node_server_utils219.useAtlas.getDb();
|
|
@@ -52761,7 +52990,7 @@ var updateRemarksisAcknowledged = async () => {
|
|
|
52761
52990
|
for (const id of updatedIds) {
|
|
52762
52991
|
const doc = await remarks.findOne({ _id: id });
|
|
52763
52992
|
const setting = await settings.findOne(
|
|
52764
|
-
{ siteId: new
|
|
52993
|
+
{ siteId: new import_mongodb127.ObjectId(doc?.siteId) },
|
|
52765
52994
|
{ projection: { emails: 1 } }
|
|
52766
52995
|
);
|
|
52767
52996
|
const payload = {
|
|
@@ -52847,7 +53076,7 @@ var updateRemarksStatusEod = async () => {
|
|
|
52847
53076
|
for (const doc of docs) {
|
|
52848
53077
|
let shiftsToCheck = [];
|
|
52849
53078
|
const endShiftTime = await settings.findOne(
|
|
52850
|
-
{ siteId: new
|
|
53079
|
+
{ siteId: new import_mongodb127.ObjectId(doc.siteId) },
|
|
52851
53080
|
{ projection: { shifts: 1, shiftType: 1 } }
|
|
52852
53081
|
);
|
|
52853
53082
|
if (doc.createdAtSGT === nowSGT) {
|
|
@@ -52953,7 +53182,7 @@ var isWithinHour = (alertTime, timeNow) => {
|
|
|
52953
53182
|
|
|
52954
53183
|
// src/events/manpower.event.ts
|
|
52955
53184
|
var import_node_server_utils220 = require("@7365admin1/node-server-utils");
|
|
52956
|
-
var
|
|
53185
|
+
var import_mongodb128 = require("mongodb");
|
|
52957
53186
|
var import_moment_timezone5 = __toESM(require("moment-timezone"));
|
|
52958
53187
|
async function manpowerEvents(io) {
|
|
52959
53188
|
let intervalId = null;
|
|
@@ -52979,7 +53208,7 @@ async function manpowerEvents(io) {
|
|
|
52979
53208
|
}).toArray();
|
|
52980
53209
|
for (const doc of docs) {
|
|
52981
53210
|
const siteSettings = await settings.findOne(
|
|
52982
|
-
{ siteId: new
|
|
53211
|
+
{ siteId: new import_mongodb128.ObjectId(doc.siteId), enabled: true },
|
|
52983
53212
|
{ projection: { shifts: 1, shiftType: 1 } }
|
|
52984
53213
|
);
|
|
52985
53214
|
const shiftType = siteSettings?.shiftType || "2-shifts";
|
|
@@ -53098,11 +53327,11 @@ function genericSignature(params, secretKey) {
|
|
|
53098
53327
|
}
|
|
53099
53328
|
|
|
53100
53329
|
// src/repositories/reddot-payment.repository.ts
|
|
53101
|
-
var
|
|
53330
|
+
var import_mongodb130 = require("mongodb");
|
|
53102
53331
|
|
|
53103
53332
|
// src/models/billing-payments.model.ts
|
|
53104
53333
|
var import_node_server_utils221 = require("@7365admin1/node-server-utils");
|
|
53105
|
-
var
|
|
53334
|
+
var import_mongodb129 = require("mongodb");
|
|
53106
53335
|
var import_joi126 = __toESM(require("joi"));
|
|
53107
53336
|
var schemaBillingItems = import_joi126.default.object({
|
|
53108
53337
|
_id: import_joi126.default.string().hex().optional(),
|
|
@@ -53136,21 +53365,21 @@ function MBillingItems(value) {
|
|
|
53136
53365
|
}
|
|
53137
53366
|
if (value._id && typeof value._id === "string") {
|
|
53138
53367
|
try {
|
|
53139
|
-
value._id = new
|
|
53368
|
+
value._id = new import_mongodb129.ObjectId(value._id);
|
|
53140
53369
|
} catch {
|
|
53141
53370
|
throw new import_node_server_utils221.BadRequestError("Invalid _id format");
|
|
53142
53371
|
}
|
|
53143
53372
|
}
|
|
53144
53373
|
if (value.unitId && typeof value.unitId === "string") {
|
|
53145
53374
|
try {
|
|
53146
|
-
value.unitId = new
|
|
53375
|
+
value.unitId = new import_mongodb129.ObjectId(value.unitId);
|
|
53147
53376
|
} catch {
|
|
53148
53377
|
throw new import_node_server_utils221.BadRequestError("Invalid unitId id format");
|
|
53149
53378
|
}
|
|
53150
53379
|
}
|
|
53151
53380
|
if (value.paidBy && typeof value.paidBy === "string") {
|
|
53152
53381
|
try {
|
|
53153
|
-
value.paidBy = new
|
|
53382
|
+
value.paidBy = new import_mongodb129.ObjectId(value.paidBy);
|
|
53154
53383
|
} catch {
|
|
53155
53384
|
throw new import_node_server_utils221.BadRequestError("Invalid paidBy id format");
|
|
53156
53385
|
}
|
|
@@ -53160,7 +53389,7 @@ function MBillingItems(value) {
|
|
|
53160
53389
|
value.unitBillingItems = value.unitBillingItems.map((unitBillingItem) => {
|
|
53161
53390
|
if (typeof unitBillingItem._id === "string") {
|
|
53162
53391
|
try {
|
|
53163
|
-
unitBillingItem._id = new
|
|
53392
|
+
unitBillingItem._id = new import_mongodb129.ObjectId(unitBillingItem._id);
|
|
53164
53393
|
} catch {
|
|
53165
53394
|
throw new import_node_server_utils221.BadRequestError("Invalid unit billing id format");
|
|
53166
53395
|
}
|
|
@@ -53172,7 +53401,7 @@ function MBillingItems(value) {
|
|
|
53172
53401
|
}
|
|
53173
53402
|
}
|
|
53174
53403
|
return {
|
|
53175
|
-
_id: value._id ?? new
|
|
53404
|
+
_id: value._id ?? new import_mongodb129.ObjectId(),
|
|
53176
53405
|
unitBillingItems: value.unitBillingItems ?? [],
|
|
53177
53406
|
unitId: value.unitId ?? "",
|
|
53178
53407
|
unitOwner: value.unitOwner ?? "",
|
|
@@ -53240,7 +53469,7 @@ var useRedDotPaymentRepo = () => {
|
|
|
53240
53469
|
const res = await paymentCollection().insertOne(payload, { session });
|
|
53241
53470
|
const unit = payload.unitId?.toString().slice(-4);
|
|
53242
53471
|
const dateFormatted = formatDateString(/* @__PURE__ */ new Date());
|
|
53243
|
-
const newId = new
|
|
53472
|
+
const newId = new import_mongodb130.ObjectId(res.insertedId).toString().slice(-6);
|
|
53244
53473
|
const referenceNumber = `${unit}${newId}${dateFormatted}`;
|
|
53245
53474
|
await paymentCollection().updateOne(
|
|
53246
53475
|
{ _id: res.insertedId },
|
|
@@ -54340,7 +54569,7 @@ var import_node_server_utils228 = require("@7365admin1/node-server-utils");
|
|
|
54340
54569
|
var import_uuid2 = require("uuid");
|
|
54341
54570
|
|
|
54342
54571
|
// src/repositories/user-v2.repo.ts
|
|
54343
|
-
var
|
|
54572
|
+
var import_mongodb131 = require("mongodb");
|
|
54344
54573
|
var import_node_server_utils227 = require("@7365admin1/node-server-utils");
|
|
54345
54574
|
function useUserRepoV2() {
|
|
54346
54575
|
const { updateFeedbackCreatedByName } = useFeedbackRepo();
|
|
@@ -54541,7 +54770,7 @@ function useUserRepoV2() {
|
|
|
54541
54770
|
}
|
|
54542
54771
|
if (organization) {
|
|
54543
54772
|
try {
|
|
54544
|
-
query.defaultOrg = new
|
|
54773
|
+
query.defaultOrg = new import_mongodb131.ObjectId(organization);
|
|
54545
54774
|
cacheOptions.organization = organization.toString();
|
|
54546
54775
|
} catch (error) {
|
|
54547
54776
|
throw new import_node_server_utils227.BadRequestError("Invalid organization ID format.");
|
|
@@ -54680,13 +54909,13 @@ function useUserRepoV2() {
|
|
|
54680
54909
|
);
|
|
54681
54910
|
}
|
|
54682
54911
|
try {
|
|
54683
|
-
_id = new
|
|
54912
|
+
_id = new import_mongodb131.ObjectId(_id);
|
|
54684
54913
|
} catch (error) {
|
|
54685
54914
|
throw new import_node_server_utils227.BadRequestError("Invalid ID.");
|
|
54686
54915
|
}
|
|
54687
54916
|
if (field === "defaultOrg") {
|
|
54688
54917
|
try {
|
|
54689
|
-
value = new
|
|
54918
|
+
value = new import_mongodb131.ObjectId(value);
|
|
54690
54919
|
} catch (error) {
|
|
54691
54920
|
throw new import_node_server_utils227.BadRequestError("Invalid organization ID.");
|
|
54692
54921
|
}
|
|
@@ -54727,7 +54956,7 @@ function useUserRepoV2() {
|
|
|
54727
54956
|
year
|
|
54728
54957
|
}, session) {
|
|
54729
54958
|
try {
|
|
54730
|
-
_id = new
|
|
54959
|
+
_id = new import_mongodb131.ObjectId(_id);
|
|
54731
54960
|
} catch (error) {
|
|
54732
54961
|
throw new import_node_server_utils227.BadRequestError("Invalid user ID format.");
|
|
54733
54962
|
}
|
|
@@ -54757,7 +54986,7 @@ function useUserRepoV2() {
|
|
|
54757
54986
|
}
|
|
54758
54987
|
async function updatePassword({ _id, password }, session) {
|
|
54759
54988
|
try {
|
|
54760
|
-
_id = new
|
|
54989
|
+
_id = new import_mongodb131.ObjectId(_id);
|
|
54761
54990
|
} catch (error) {
|
|
54762
54991
|
throw new import_node_server_utils227.BadRequestError("Invalid user ID format.");
|
|
54763
54992
|
}
|
|
@@ -55512,38 +55741,38 @@ function useUserControllerV2() {
|
|
|
55512
55741
|
|
|
55513
55742
|
// src/models/role-v2.model.ts
|
|
55514
55743
|
var import_node_server_utils232 = require("@7365admin1/node-server-utils");
|
|
55515
|
-
var
|
|
55744
|
+
var import_mongodb132 = require("mongodb");
|
|
55516
55745
|
var MRoleV2 = class {
|
|
55517
55746
|
constructor(value) {
|
|
55518
55747
|
if (typeof value._id === "string") {
|
|
55519
55748
|
try {
|
|
55520
|
-
value._id = new
|
|
55749
|
+
value._id = new import_mongodb132.ObjectId(value._id);
|
|
55521
55750
|
} catch (error) {
|
|
55522
55751
|
throw new import_node_server_utils232.BadRequestError("Invalid role-v2 ID format.");
|
|
55523
55752
|
}
|
|
55524
55753
|
}
|
|
55525
55754
|
if (typeof value.site === "string" && value.site.length === 24) {
|
|
55526
55755
|
try {
|
|
55527
|
-
value.site = new
|
|
55756
|
+
value.site = new import_mongodb132.ObjectId(value.site);
|
|
55528
55757
|
} catch (error) {
|
|
55529
55758
|
throw new import_node_server_utils232.BadRequestError("Invalid site ID format.");
|
|
55530
55759
|
}
|
|
55531
55760
|
}
|
|
55532
55761
|
if (typeof value.org === "string" && value.org.length === 24) {
|
|
55533
55762
|
try {
|
|
55534
|
-
value.org = new
|
|
55763
|
+
value.org = new import_mongodb132.ObjectId(value.org);
|
|
55535
55764
|
} catch (error) {
|
|
55536
55765
|
throw new import_node_server_utils232.BadRequestError("Invalid org ID format.");
|
|
55537
55766
|
}
|
|
55538
55767
|
}
|
|
55539
55768
|
if (value.createdBy) {
|
|
55540
55769
|
try {
|
|
55541
|
-
value.createdBy = new
|
|
55770
|
+
value.createdBy = new import_mongodb132.ObjectId(value.createdBy);
|
|
55542
55771
|
} catch (error) {
|
|
55543
55772
|
throw new import_node_server_utils232.BadRequestError("Invalid created by ID format.");
|
|
55544
55773
|
}
|
|
55545
55774
|
}
|
|
55546
|
-
this._id = value._id ?? new
|
|
55775
|
+
this._id = value._id ?? new import_mongodb132.ObjectId();
|
|
55547
55776
|
this.name = value.name ?? "";
|
|
55548
55777
|
this.permissions = value.permissions ?? [];
|
|
55549
55778
|
this.site = value.site ?? "";
|
|
@@ -55678,7 +55907,7 @@ function useRoleControllerV2() {
|
|
|
55678
55907
|
|
|
55679
55908
|
// src/models/post-preloved.model.ts
|
|
55680
55909
|
var import_joi133 = __toESM(require("joi"));
|
|
55681
|
-
var
|
|
55910
|
+
var import_mongodb133 = require("mongodb");
|
|
55682
55911
|
var PostStatus = /* @__PURE__ */ ((PostStatus2) => {
|
|
55683
55912
|
PostStatus2["PUBLISHED"] = "published";
|
|
55684
55913
|
PostStatus2["RESERVED"] = "reserved";
|
|
@@ -55734,28 +55963,28 @@ function MPost(value) {
|
|
|
55734
55963
|
}
|
|
55735
55964
|
if (value._id && typeof value._id === "string") {
|
|
55736
55965
|
try {
|
|
55737
|
-
value._id = new
|
|
55966
|
+
value._id = new import_mongodb133.ObjectId(value._id);
|
|
55738
55967
|
} catch {
|
|
55739
55968
|
throw new Error("Invalid ID.");
|
|
55740
55969
|
}
|
|
55741
55970
|
}
|
|
55742
55971
|
if (value.site && typeof value.site === "string") {
|
|
55743
55972
|
try {
|
|
55744
|
-
value.site = new
|
|
55973
|
+
value.site = new import_mongodb133.ObjectId(value.site);
|
|
55745
55974
|
} catch {
|
|
55746
55975
|
throw new Error("Invalid site ID.");
|
|
55747
55976
|
}
|
|
55748
55977
|
}
|
|
55749
55978
|
if (value.createdBy && typeof value.createdBy === "string") {
|
|
55750
55979
|
try {
|
|
55751
|
-
value.createdBy = new
|
|
55980
|
+
value.createdBy = new import_mongodb133.ObjectId(value.createdBy);
|
|
55752
55981
|
} catch {
|
|
55753
55982
|
throw new Error("Invalid createdBy ID.");
|
|
55754
55983
|
}
|
|
55755
55984
|
}
|
|
55756
55985
|
if (value.reserverId && typeof value.reserverId === "string") {
|
|
55757
55986
|
try {
|
|
55758
|
-
value.reserverId = new
|
|
55987
|
+
value.reserverId = new import_mongodb133.ObjectId(value.reserverId);
|
|
55759
55988
|
} catch {
|
|
55760
55989
|
throw new Error("Invalid reserver ID.");
|
|
55761
55990
|
}
|
|
@@ -55764,7 +55993,7 @@ function MPost(value) {
|
|
|
55764
55993
|
value.attachments = value.attachments.map((id) => {
|
|
55765
55994
|
if (typeof id === "string") {
|
|
55766
55995
|
try {
|
|
55767
|
-
return new
|
|
55996
|
+
return new import_mongodb133.ObjectId(id);
|
|
55768
55997
|
} catch {
|
|
55769
55998
|
throw new Error("Invalid attachment ID.");
|
|
55770
55999
|
}
|
|
@@ -55774,20 +56003,20 @@ function MPost(value) {
|
|
|
55774
56003
|
}
|
|
55775
56004
|
if (value.category && typeof value.category === "string") {
|
|
55776
56005
|
try {
|
|
55777
|
-
value.category = new
|
|
56006
|
+
value.category = new import_mongodb133.ObjectId(value.category);
|
|
55778
56007
|
} catch {
|
|
55779
56008
|
throw new Error("Invalid category ID.");
|
|
55780
56009
|
}
|
|
55781
56010
|
}
|
|
55782
56011
|
if (value.subcategory && typeof value.subcategory === "string") {
|
|
55783
56012
|
try {
|
|
55784
|
-
value.subcategory = new
|
|
56013
|
+
value.subcategory = new import_mongodb133.ObjectId(value.subcategory);
|
|
55785
56014
|
} catch {
|
|
55786
56015
|
throw new Error("Invalid subcategory ID.");
|
|
55787
56016
|
}
|
|
55788
56017
|
}
|
|
55789
56018
|
return {
|
|
55790
|
-
_id: value._id ?? new
|
|
56019
|
+
_id: value._id ?? new import_mongodb133.ObjectId(),
|
|
55791
56020
|
title: value.title ?? "",
|
|
55792
56021
|
description: value.description ?? "",
|
|
55793
56022
|
attachments: value.attachments ?? [],
|
|
@@ -55807,7 +56036,7 @@ function MPost(value) {
|
|
|
55807
56036
|
|
|
55808
56037
|
// src/repositories/post-preloved.repo.ts
|
|
55809
56038
|
var import_node_server_utils235 = require("@7365admin1/node-server-utils");
|
|
55810
|
-
var
|
|
56039
|
+
var import_mongodb134 = require("mongodb");
|
|
55811
56040
|
function usePostPrelovedRepo() {
|
|
55812
56041
|
const db = import_node_server_utils235.useAtlas.getDb();
|
|
55813
56042
|
if (!db) {
|
|
@@ -55869,18 +56098,62 @@ function usePostPrelovedRepo() {
|
|
|
55869
56098
|
throw error;
|
|
55870
56099
|
}
|
|
55871
56100
|
}
|
|
55872
|
-
async function getById(_id) {
|
|
56101
|
+
async function getById(_id, userId) {
|
|
55873
56102
|
try {
|
|
55874
|
-
_id = new
|
|
56103
|
+
_id = new import_mongodb134.ObjectId(_id);
|
|
55875
56104
|
} catch {
|
|
55876
56105
|
throw new import_node_server_utils235.BadRequestError("Invalid post ID format.");
|
|
55877
56106
|
}
|
|
56107
|
+
let userObjectId = null;
|
|
56108
|
+
if (userId) {
|
|
56109
|
+
try {
|
|
56110
|
+
userObjectId = new import_mongodb134.ObjectId(userId);
|
|
56111
|
+
} catch {
|
|
56112
|
+
throw new import_node_server_utils235.BadRequestError("Invalid user ID format.");
|
|
56113
|
+
}
|
|
56114
|
+
}
|
|
56115
|
+
const favoriteUserIds = {
|
|
56116
|
+
$ifNull: [{ $arrayElemAt: ["$favoriteData.userIds", 0] }, []]
|
|
56117
|
+
};
|
|
55878
56118
|
try {
|
|
55879
56119
|
const result = await collection.aggregate([
|
|
55880
56120
|
{ $match: { _id, status: { $ne: "deleted" /* DELETED */ } } },
|
|
55881
56121
|
USER_LOOKUP,
|
|
55882
56122
|
USER_UNWIND,
|
|
55883
|
-
|
|
56123
|
+
{
|
|
56124
|
+
$lookup: {
|
|
56125
|
+
from: "category-preloved",
|
|
56126
|
+
localField: "category",
|
|
56127
|
+
foreignField: "_id",
|
|
56128
|
+
pipeline: [{ $project: { name: 1 } }],
|
|
56129
|
+
as: "category"
|
|
56130
|
+
}
|
|
56131
|
+
},
|
|
56132
|
+
{
|
|
56133
|
+
$lookup: {
|
|
56134
|
+
from: "subcategory-preloved",
|
|
56135
|
+
localField: "subcategory",
|
|
56136
|
+
foreignField: "_id",
|
|
56137
|
+
pipeline: [{ $project: { name: 1 } }],
|
|
56138
|
+
as: "subcategory"
|
|
56139
|
+
}
|
|
56140
|
+
},
|
|
56141
|
+
{
|
|
56142
|
+
$lookup: {
|
|
56143
|
+
from: "post-favorites",
|
|
56144
|
+
localField: "_id",
|
|
56145
|
+
foreignField: "postId",
|
|
56146
|
+
pipeline: [{ $project: { userIds: 1 } }],
|
|
56147
|
+
as: "favoriteData"
|
|
56148
|
+
}
|
|
56149
|
+
},
|
|
56150
|
+
{
|
|
56151
|
+
$addFields: {
|
|
56152
|
+
favoriteCount: { $size: favoriteUserIds },
|
|
56153
|
+
isFavorited: userObjectId ? { $in: [userObjectId, favoriteUserIds] } : false
|
|
56154
|
+
}
|
|
56155
|
+
},
|
|
56156
|
+
{ $unset: "favoriteData" }
|
|
55884
56157
|
]).toArray();
|
|
55885
56158
|
const data = result[0] ?? null;
|
|
55886
56159
|
if (!data)
|
|
@@ -55904,7 +56177,7 @@ function usePostPrelovedRepo() {
|
|
|
55904
56177
|
page = page > 0 ? page - 1 : 0;
|
|
55905
56178
|
if (site) {
|
|
55906
56179
|
try {
|
|
55907
|
-
site = new
|
|
56180
|
+
site = new import_mongodb134.ObjectId(site);
|
|
55908
56181
|
} catch {
|
|
55909
56182
|
throw new import_node_server_utils235.BadRequestError("Invalid site ID format.");
|
|
55910
56183
|
}
|
|
@@ -55913,14 +56186,14 @@ function usePostPrelovedRepo() {
|
|
|
55913
56186
|
let subcategoryIds = null;
|
|
55914
56187
|
if (category && subcategory) {
|
|
55915
56188
|
try {
|
|
55916
|
-
categoryId = new
|
|
56189
|
+
categoryId = new import_mongodb134.ObjectId(category);
|
|
55917
56190
|
} catch {
|
|
55918
56191
|
throw new import_node_server_utils235.BadRequestError("Invalid category ID format.");
|
|
55919
56192
|
}
|
|
55920
56193
|
if (subcategory.length > 0) {
|
|
55921
56194
|
subcategoryIds = subcategory.map((id) => {
|
|
55922
56195
|
try {
|
|
55923
|
-
return new
|
|
56196
|
+
return new import_mongodb134.ObjectId(id);
|
|
55924
56197
|
} catch {
|
|
55925
56198
|
throw new import_node_server_utils235.BadRequestError("Invalid subcategory ID format.");
|
|
55926
56199
|
}
|
|
@@ -55945,7 +56218,7 @@ function usePostPrelovedRepo() {
|
|
|
55945
56218
|
let userObjectId = null;
|
|
55946
56219
|
if (userId) {
|
|
55947
56220
|
try {
|
|
55948
|
-
userObjectId = new
|
|
56221
|
+
userObjectId = new import_mongodb134.ObjectId(userId);
|
|
55949
56222
|
} catch {
|
|
55950
56223
|
throw new import_node_server_utils235.BadRequestError("Invalid user ID format.");
|
|
55951
56224
|
}
|
|
@@ -55994,7 +56267,7 @@ function usePostPrelovedRepo() {
|
|
|
55994
56267
|
}
|
|
55995
56268
|
async function updateById(_id, value, session) {
|
|
55996
56269
|
try {
|
|
55997
|
-
_id = new
|
|
56270
|
+
_id = new import_mongodb134.ObjectId(_id);
|
|
55998
56271
|
} catch {
|
|
55999
56272
|
throw new import_node_server_utils235.BadRequestError("Invalid post ID format.");
|
|
56000
56273
|
}
|
|
@@ -56015,7 +56288,7 @@ function usePostPrelovedRepo() {
|
|
|
56015
56288
|
}
|
|
56016
56289
|
async function deleteById(_id, session) {
|
|
56017
56290
|
try {
|
|
56018
|
-
_id = new
|
|
56291
|
+
_id = new import_mongodb134.ObjectId(_id);
|
|
56019
56292
|
} catch {
|
|
56020
56293
|
throw new import_node_server_utils235.BadRequestError("Invalid post ID format.");
|
|
56021
56294
|
}
|
|
@@ -56041,7 +56314,7 @@ function usePostPrelovedRepo() {
|
|
|
56041
56314
|
}
|
|
56042
56315
|
async function updateStatus(_id, status, session) {
|
|
56043
56316
|
try {
|
|
56044
|
-
_id = new
|
|
56317
|
+
_id = new import_mongodb134.ObjectId(_id);
|
|
56045
56318
|
} catch {
|
|
56046
56319
|
throw new import_node_server_utils235.BadRequestError("Invalid post ID format.");
|
|
56047
56320
|
}
|
|
@@ -56069,11 +56342,181 @@ function usePostPrelovedRepo() {
|
|
|
56069
56342
|
}
|
|
56070
56343
|
|
|
56071
56344
|
// src/controllers/post-preloved.controller.ts
|
|
56345
|
+
var import_node_server_utils238 = require("@7365admin1/node-server-utils");
|
|
56346
|
+
var import_joi135 = __toESM(require("joi"));
|
|
56347
|
+
|
|
56348
|
+
// src/services/post-preloved.service.ts
|
|
56349
|
+
var import_node_server_utils237 = require("@7365admin1/node-server-utils");
|
|
56350
|
+
|
|
56351
|
+
// src/repositories/post-favorite.repo.ts
|
|
56072
56352
|
var import_node_server_utils236 = require("@7365admin1/node-server-utils");
|
|
56353
|
+
var import_mongodb136 = require("mongodb");
|
|
56354
|
+
|
|
56355
|
+
// src/models/post-favorite.model.ts
|
|
56073
56356
|
var import_joi134 = __toESM(require("joi"));
|
|
56357
|
+
var import_mongodb135 = require("mongodb");
|
|
56358
|
+
var schemaUpdatePostFavorite = import_joi134.default.object({
|
|
56359
|
+
userId: import_joi134.default.string().hex().length(24).required()
|
|
56360
|
+
});
|
|
56361
|
+
var schemaPostFavorite = import_joi134.default.object({
|
|
56362
|
+
_id: import_joi134.default.string().hex().optional().allow("", null),
|
|
56363
|
+
postId: import_joi134.default.string().hex().required(),
|
|
56364
|
+
userIds: import_joi134.default.array().items(import_joi134.default.string().hex().optional()).optional().allow(null),
|
|
56365
|
+
createdAt: import_joi134.default.date().optional().allow(null),
|
|
56366
|
+
updatedAt: import_joi134.default.date().optional().allow(null)
|
|
56367
|
+
});
|
|
56368
|
+
function MPostFavorite(value) {
|
|
56369
|
+
const { error } = schemaPostFavorite.validate(value);
|
|
56370
|
+
if (error) {
|
|
56371
|
+
throw new Error(error.details[0].message);
|
|
56372
|
+
}
|
|
56373
|
+
if (value._id && typeof value._id === "string") {
|
|
56374
|
+
try {
|
|
56375
|
+
value._id = new import_mongodb135.ObjectId(value._id);
|
|
56376
|
+
} catch {
|
|
56377
|
+
throw new Error("Invalid ID.");
|
|
56378
|
+
}
|
|
56379
|
+
}
|
|
56380
|
+
if (value.postId && typeof value.postId === "string") {
|
|
56381
|
+
try {
|
|
56382
|
+
value.postId = new import_mongodb135.ObjectId(value.postId);
|
|
56383
|
+
} catch {
|
|
56384
|
+
throw new Error("Invalid post ID.");
|
|
56385
|
+
}
|
|
56386
|
+
}
|
|
56387
|
+
if (value.userIds && Array.isArray(value.userIds)) {
|
|
56388
|
+
value.userIds = value.userIds.map((id) => {
|
|
56389
|
+
if (typeof id === "string") {
|
|
56390
|
+
try {
|
|
56391
|
+
return new import_mongodb135.ObjectId(id);
|
|
56392
|
+
} catch {
|
|
56393
|
+
throw new Error("Invalid user ID.");
|
|
56394
|
+
}
|
|
56395
|
+
}
|
|
56396
|
+
return id;
|
|
56397
|
+
});
|
|
56398
|
+
}
|
|
56399
|
+
return {
|
|
56400
|
+
_id: value._id ?? new import_mongodb135.ObjectId(),
|
|
56401
|
+
postId: value.postId ?? "",
|
|
56402
|
+
userIds: value.userIds ?? [],
|
|
56403
|
+
createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
56404
|
+
updatedAt: value.updatedAt ?? null
|
|
56405
|
+
};
|
|
56406
|
+
}
|
|
56407
|
+
|
|
56408
|
+
// src/repositories/post-favorite.repo.ts
|
|
56409
|
+
function usePostFavoriteRepo() {
|
|
56410
|
+
const db = import_node_server_utils236.useAtlas.getDb();
|
|
56411
|
+
if (!db) {
|
|
56412
|
+
throw new import_node_server_utils236.InternalServerError("Unable to connect to server.");
|
|
56413
|
+
}
|
|
56414
|
+
const FAVORITE_COLLECTION = "post-favorites";
|
|
56415
|
+
const collection = db.collection(FAVORITE_COLLECTION);
|
|
56416
|
+
async function addFavorite(value, session) {
|
|
56417
|
+
try {
|
|
56418
|
+
const doc = MPostFavorite(value);
|
|
56419
|
+
const res = await collection.insertOne(doc, { session });
|
|
56420
|
+
return res.insertedId;
|
|
56421
|
+
} catch (error) {
|
|
56422
|
+
const isDuplicated = error.message?.includes("duplicate");
|
|
56423
|
+
if (isDuplicated)
|
|
56424
|
+
throw new import_node_server_utils236.BadRequestError("Post Favorite already exists.");
|
|
56425
|
+
throw error;
|
|
56426
|
+
}
|
|
56427
|
+
}
|
|
56428
|
+
async function getById(_id) {
|
|
56429
|
+
try {
|
|
56430
|
+
_id = new import_mongodb136.ObjectId(_id);
|
|
56431
|
+
} catch {
|
|
56432
|
+
throw new import_node_server_utils236.BadRequestError("Invalid favorite ID format.");
|
|
56433
|
+
}
|
|
56434
|
+
const result = await collection.findOne({ _id });
|
|
56435
|
+
if (!result)
|
|
56436
|
+
throw new import_node_server_utils236.NotFoundError("Favorite not found.");
|
|
56437
|
+
return result;
|
|
56438
|
+
}
|
|
56439
|
+
async function getByPostId(postId) {
|
|
56440
|
+
try {
|
|
56441
|
+
postId = new import_mongodb136.ObjectId(postId);
|
|
56442
|
+
} catch {
|
|
56443
|
+
throw new import_node_server_utils236.BadRequestError("Invalid post ID format.");
|
|
56444
|
+
}
|
|
56445
|
+
const result = await collection.findOne({ postId });
|
|
56446
|
+
if (!result)
|
|
56447
|
+
throw new import_node_server_utils236.NotFoundError("Favorite not found.");
|
|
56448
|
+
return result;
|
|
56449
|
+
}
|
|
56450
|
+
async function updateById(_id, userId, session) {
|
|
56451
|
+
try {
|
|
56452
|
+
_id = new import_mongodb136.ObjectId(_id);
|
|
56453
|
+
} catch {
|
|
56454
|
+
throw new import_node_server_utils236.BadRequestError("Invalid favorite ID format.");
|
|
56455
|
+
}
|
|
56456
|
+
let userObjectId;
|
|
56457
|
+
try {
|
|
56458
|
+
userObjectId = new import_mongodb136.ObjectId(userId);
|
|
56459
|
+
} catch {
|
|
56460
|
+
throw new import_node_server_utils236.BadRequestError("Invalid user ID format.");
|
|
56461
|
+
}
|
|
56462
|
+
const existing = await collection.findOne(
|
|
56463
|
+
{ postId: _id, userIds: userObjectId },
|
|
56464
|
+
{ session }
|
|
56465
|
+
);
|
|
56466
|
+
const update = existing ? {
|
|
56467
|
+
$pull: { userIds: userObjectId },
|
|
56468
|
+
$set: { updatedAt: (/* @__PURE__ */ new Date()).toISOString() }
|
|
56469
|
+
} : {
|
|
56470
|
+
$addToSet: { userIds: userObjectId },
|
|
56471
|
+
$set: { updatedAt: (/* @__PURE__ */ new Date()).toISOString() }
|
|
56472
|
+
};
|
|
56473
|
+
const res = await collection.updateOne({ postId: _id }, update, {
|
|
56474
|
+
session
|
|
56475
|
+
});
|
|
56476
|
+
if (res.modifiedCount === 0)
|
|
56477
|
+
throw new import_node_server_utils236.InternalServerError("Unable to update favorite.");
|
|
56478
|
+
return existing ? "removed" : "added";
|
|
56479
|
+
}
|
|
56480
|
+
return {
|
|
56481
|
+
addFavorite,
|
|
56482
|
+
getById,
|
|
56483
|
+
getByPostId,
|
|
56484
|
+
updateById
|
|
56485
|
+
};
|
|
56486
|
+
}
|
|
56487
|
+
|
|
56488
|
+
// src/services/post-preloved.service.ts
|
|
56489
|
+
function usePostFavoriteService() {
|
|
56490
|
+
const { add: _addPost } = usePostPrelovedRepo();
|
|
56491
|
+
const { addFavorite: _addFavorite } = usePostFavoriteRepo();
|
|
56492
|
+
async function add(value) {
|
|
56493
|
+
const session = import_node_server_utils237.useAtlas.getClient()?.startSession();
|
|
56494
|
+
session?.startTransaction();
|
|
56495
|
+
try {
|
|
56496
|
+
const post = await _addPost(value, session);
|
|
56497
|
+
const payload = {
|
|
56498
|
+
postId: post.toString(),
|
|
56499
|
+
userIds: []
|
|
56500
|
+
};
|
|
56501
|
+
await _addFavorite(payload, session);
|
|
56502
|
+
await session?.commitTransaction();
|
|
56503
|
+
return "Successfully added to favorites.";
|
|
56504
|
+
} catch (error) {
|
|
56505
|
+
await session?.abortTransaction();
|
|
56506
|
+
throw error;
|
|
56507
|
+
} finally {
|
|
56508
|
+
session?.endSession();
|
|
56509
|
+
}
|
|
56510
|
+
}
|
|
56511
|
+
return {
|
|
56512
|
+
add
|
|
56513
|
+
};
|
|
56514
|
+
}
|
|
56515
|
+
|
|
56516
|
+
// src/controllers/post-preloved.controller.ts
|
|
56074
56517
|
function usePostPrelovedController() {
|
|
56518
|
+
const { add: _add } = usePostFavoriteService();
|
|
56075
56519
|
const {
|
|
56076
|
-
add: _add,
|
|
56077
56520
|
getById: _getById,
|
|
56078
56521
|
getAll: _getAll,
|
|
56079
56522
|
updateById: _updateById,
|
|
@@ -56086,8 +56529,8 @@ function usePostPrelovedController() {
|
|
|
56086
56529
|
});
|
|
56087
56530
|
if (error) {
|
|
56088
56531
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
56089
|
-
|
|
56090
|
-
next(new
|
|
56532
|
+
import_node_server_utils238.logger.log({ level: "error", message: messages });
|
|
56533
|
+
next(new import_node_server_utils238.BadRequestError(messages));
|
|
56091
56534
|
return;
|
|
56092
56535
|
}
|
|
56093
56536
|
try {
|
|
@@ -56095,53 +56538,57 @@ function usePostPrelovedController() {
|
|
|
56095
56538
|
res.status(201).json(data);
|
|
56096
56539
|
return;
|
|
56097
56540
|
} catch (error2) {
|
|
56098
|
-
|
|
56541
|
+
import_node_server_utils238.logger.log({ level: "error", message: error2.message });
|
|
56099
56542
|
next(error2);
|
|
56100
56543
|
return;
|
|
56101
56544
|
}
|
|
56102
56545
|
}
|
|
56103
56546
|
async function getById(req, res, next) {
|
|
56104
|
-
const schema2 =
|
|
56105
|
-
_id:
|
|
56547
|
+
const schema2 = import_joi135.default.object({
|
|
56548
|
+
_id: import_joi135.default.string().hex().length(24).required(),
|
|
56549
|
+
userId: import_joi135.default.string().hex().length(24).optional().allow("", null)
|
|
56550
|
+
});
|
|
56551
|
+
const { error, value } = schema2.validate({
|
|
56552
|
+
_id: req.params.id,
|
|
56553
|
+
userId: req.query.userId
|
|
56106
56554
|
});
|
|
56107
|
-
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
56108
56555
|
if (error) {
|
|
56109
|
-
|
|
56110
|
-
next(new
|
|
56556
|
+
import_node_server_utils238.logger.log({ level: "error", message: error.message });
|
|
56557
|
+
next(new import_node_server_utils238.BadRequestError(error.message));
|
|
56111
56558
|
return;
|
|
56112
56559
|
}
|
|
56113
56560
|
try {
|
|
56114
|
-
const data = await _getById(value._id);
|
|
56561
|
+
const data = await _getById(value._id, value.userId);
|
|
56115
56562
|
res.status(200).json(data);
|
|
56116
56563
|
return;
|
|
56117
56564
|
} catch (error2) {
|
|
56118
|
-
|
|
56565
|
+
import_node_server_utils238.logger.log({ level: "error", message: error2.message });
|
|
56119
56566
|
next(error2);
|
|
56120
56567
|
return;
|
|
56121
56568
|
}
|
|
56122
56569
|
}
|
|
56123
56570
|
async function getAll(req, res, next) {
|
|
56124
|
-
const validation =
|
|
56125
|
-
page:
|
|
56126
|
-
limit:
|
|
56127
|
-
search:
|
|
56128
|
-
filter:
|
|
56129
|
-
site:
|
|
56130
|
-
status:
|
|
56131
|
-
|
|
56132
|
-
|
|
56571
|
+
const validation = import_joi135.default.object({
|
|
56572
|
+
page: import_joi135.default.number().integer().min(1).allow("", null).default(1),
|
|
56573
|
+
limit: import_joi135.default.number().integer().min(1).max(100).allow("", null).default(10),
|
|
56574
|
+
search: import_joi135.default.string().optional().allow("", null),
|
|
56575
|
+
filter: import_joi135.default.string().valid("recent", "price-low-high", "price-high-low").optional().allow("", null),
|
|
56576
|
+
site: import_joi135.default.string().hex().length(24).optional().allow("", null),
|
|
56577
|
+
status: import_joi135.default.alternatives().try(
|
|
56578
|
+
import_joi135.default.array().items(import_joi135.default.string().valid(...Object.values(PostStatus))),
|
|
56579
|
+
import_joi135.default.string().valid(...Object.values(PostStatus))
|
|
56133
56580
|
).optional().allow(null),
|
|
56134
|
-
category:
|
|
56135
|
-
subcategory:
|
|
56136
|
-
userId:
|
|
56581
|
+
category: import_joi135.default.string().hex().length(24).optional().allow("", null),
|
|
56582
|
+
subcategory: import_joi135.default.array().items(import_joi135.default.string()).single().optional().allow(null),
|
|
56583
|
+
userId: import_joi135.default.string().optional().allow("", null)
|
|
56137
56584
|
});
|
|
56138
56585
|
const { error, value } = validation.validate(req.query, {
|
|
56139
56586
|
abortEarly: false
|
|
56140
56587
|
});
|
|
56141
56588
|
if (error) {
|
|
56142
56589
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
56143
|
-
|
|
56144
|
-
next(new
|
|
56590
|
+
import_node_server_utils238.logger.log({ level: "error", message: messages });
|
|
56591
|
+
next(new import_node_server_utils238.BadRequestError(messages));
|
|
56145
56592
|
return;
|
|
56146
56593
|
}
|
|
56147
56594
|
const {
|
|
@@ -56170,7 +56617,7 @@ function usePostPrelovedController() {
|
|
|
56170
56617
|
res.status(200).json(data);
|
|
56171
56618
|
return;
|
|
56172
56619
|
} catch (error2) {
|
|
56173
|
-
|
|
56620
|
+
import_node_server_utils238.logger.log({ level: "error", message: error2.message });
|
|
56174
56621
|
next(error2);
|
|
56175
56622
|
return;
|
|
56176
56623
|
}
|
|
@@ -56183,8 +56630,8 @@ function usePostPrelovedController() {
|
|
|
56183
56630
|
});
|
|
56184
56631
|
if (error) {
|
|
56185
56632
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
56186
|
-
|
|
56187
|
-
next(new
|
|
56633
|
+
import_node_server_utils238.logger.log({ level: "error", message: messages });
|
|
56634
|
+
next(new import_node_server_utils238.BadRequestError(messages));
|
|
56188
56635
|
return;
|
|
56189
56636
|
}
|
|
56190
56637
|
try {
|
|
@@ -56192,19 +56639,19 @@ function usePostPrelovedController() {
|
|
|
56192
56639
|
res.status(200).json(data);
|
|
56193
56640
|
return;
|
|
56194
56641
|
} catch (error2) {
|
|
56195
|
-
|
|
56642
|
+
import_node_server_utils238.logger.log({ level: "error", message: error2.message });
|
|
56196
56643
|
next(error2);
|
|
56197
56644
|
return;
|
|
56198
56645
|
}
|
|
56199
56646
|
}
|
|
56200
56647
|
async function deleteById(req, res, next) {
|
|
56201
|
-
const schema2 =
|
|
56202
|
-
_id:
|
|
56648
|
+
const schema2 = import_joi135.default.object({
|
|
56649
|
+
_id: import_joi135.default.string().hex().length(24).required()
|
|
56203
56650
|
});
|
|
56204
56651
|
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
56205
56652
|
if (error) {
|
|
56206
|
-
|
|
56207
|
-
next(new
|
|
56653
|
+
import_node_server_utils238.logger.log({ level: "error", message: error.message });
|
|
56654
|
+
next(new import_node_server_utils238.BadRequestError(error.message));
|
|
56208
56655
|
return;
|
|
56209
56656
|
}
|
|
56210
56657
|
try {
|
|
@@ -56212,23 +56659,23 @@ function usePostPrelovedController() {
|
|
|
56212
56659
|
res.status(200).json({ message: "Successfully deleted post." });
|
|
56213
56660
|
return;
|
|
56214
56661
|
} catch (error2) {
|
|
56215
|
-
|
|
56662
|
+
import_node_server_utils238.logger.log({ level: "error", message: error2.message });
|
|
56216
56663
|
next(error2);
|
|
56217
56664
|
return;
|
|
56218
56665
|
}
|
|
56219
56666
|
}
|
|
56220
56667
|
async function updateStatus(req, res, next) {
|
|
56221
|
-
const schema2 =
|
|
56222
|
-
_id:
|
|
56223
|
-
status:
|
|
56668
|
+
const schema2 = import_joi135.default.object({
|
|
56669
|
+
_id: import_joi135.default.string().hex().length(24).required(),
|
|
56670
|
+
status: import_joi135.default.string().valid(...Object.values(PostStatus)).required()
|
|
56224
56671
|
});
|
|
56225
56672
|
const { error, value } = schema2.validate({
|
|
56226
56673
|
_id: req.params.id,
|
|
56227
56674
|
status: req.body.status
|
|
56228
56675
|
});
|
|
56229
56676
|
if (error) {
|
|
56230
|
-
|
|
56231
|
-
next(new
|
|
56677
|
+
import_node_server_utils238.logger.log({ level: "error", message: error.message });
|
|
56678
|
+
next(new import_node_server_utils238.BadRequestError(error.message));
|
|
56232
56679
|
return;
|
|
56233
56680
|
}
|
|
56234
56681
|
try {
|
|
@@ -56236,7 +56683,7 @@ function usePostPrelovedController() {
|
|
|
56236
56683
|
res.status(200).json(data);
|
|
56237
56684
|
return;
|
|
56238
56685
|
} catch (error2) {
|
|
56239
|
-
|
|
56686
|
+
import_node_server_utils238.logger.log({ level: "error", message: error2.message });
|
|
56240
56687
|
next(error2);
|
|
56241
56688
|
return;
|
|
56242
56689
|
}
|
|
@@ -56251,139 +56698,12 @@ function usePostPrelovedController() {
|
|
|
56251
56698
|
};
|
|
56252
56699
|
}
|
|
56253
56700
|
|
|
56254
|
-
// src/models/post-favorite.model.ts
|
|
56255
|
-
var import_joi135 = __toESM(require("joi"));
|
|
56256
|
-
var import_mongodb134 = require("mongodb");
|
|
56257
|
-
var schemaUpdatePostFavorite = import_joi135.default.object({
|
|
56258
|
-
userId: import_joi135.default.string().hex().length(24).required()
|
|
56259
|
-
});
|
|
56260
|
-
var schemaPostFavorite = import_joi135.default.object({
|
|
56261
|
-
_id: import_joi135.default.string().hex().optional().allow("", null),
|
|
56262
|
-
postId: import_joi135.default.string().hex().required(),
|
|
56263
|
-
userIds: import_joi135.default.array().items(import_joi135.default.string().hex().optional()).optional().allow(null),
|
|
56264
|
-
createdAt: import_joi135.default.date().optional().allow(null),
|
|
56265
|
-
updatedAt: import_joi135.default.date().optional().allow(null)
|
|
56266
|
-
});
|
|
56267
|
-
function MPostFavorite(value) {
|
|
56268
|
-
const { error } = schemaPostFavorite.validate(value);
|
|
56269
|
-
if (error) {
|
|
56270
|
-
throw new Error(error.details[0].message);
|
|
56271
|
-
}
|
|
56272
|
-
if (value._id && typeof value._id === "string") {
|
|
56273
|
-
try {
|
|
56274
|
-
value._id = new import_mongodb134.ObjectId(value._id);
|
|
56275
|
-
} catch {
|
|
56276
|
-
throw new Error("Invalid ID.");
|
|
56277
|
-
}
|
|
56278
|
-
}
|
|
56279
|
-
if (value.postId && typeof value.postId === "string") {
|
|
56280
|
-
try {
|
|
56281
|
-
value.postId = new import_mongodb134.ObjectId(value.postId);
|
|
56282
|
-
} catch {
|
|
56283
|
-
throw new Error("Invalid post ID.");
|
|
56284
|
-
}
|
|
56285
|
-
}
|
|
56286
|
-
if (value.userIds && Array.isArray(value.userIds)) {
|
|
56287
|
-
value.userIds = value.userIds.map((id) => {
|
|
56288
|
-
if (typeof id === "string") {
|
|
56289
|
-
try {
|
|
56290
|
-
return new import_mongodb134.ObjectId(id);
|
|
56291
|
-
} catch {
|
|
56292
|
-
throw new Error("Invalid user ID.");
|
|
56293
|
-
}
|
|
56294
|
-
}
|
|
56295
|
-
return id;
|
|
56296
|
-
});
|
|
56297
|
-
}
|
|
56298
|
-
return {
|
|
56299
|
-
_id: value._id ?? new import_mongodb134.ObjectId(),
|
|
56300
|
-
postId: value.postId ?? "",
|
|
56301
|
-
userIds: value.userIds ?? [],
|
|
56302
|
-
createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
56303
|
-
updatedAt: value.updatedAt ?? null
|
|
56304
|
-
};
|
|
56305
|
-
}
|
|
56306
|
-
|
|
56307
|
-
// src/repositories/post-favorite.repo.ts
|
|
56308
|
-
var import_node_server_utils237 = require("@7365admin1/node-server-utils");
|
|
56309
|
-
var import_mongodb135 = require("mongodb");
|
|
56310
|
-
function usePostFavoriteRepo() {
|
|
56311
|
-
const db = import_node_server_utils237.useAtlas.getDb();
|
|
56312
|
-
if (!db) {
|
|
56313
|
-
throw new import_node_server_utils237.InternalServerError("Unable to connect to server.");
|
|
56314
|
-
}
|
|
56315
|
-
const FAVORITE_COLLECTION = "post-favorites";
|
|
56316
|
-
const collection = db.collection(FAVORITE_COLLECTION);
|
|
56317
|
-
async function addFavorite(value, session) {
|
|
56318
|
-
try {
|
|
56319
|
-
const doc = MPostFavorite(value);
|
|
56320
|
-
const res = await collection.insertOne(doc, { session });
|
|
56321
|
-
return res.insertedId;
|
|
56322
|
-
} catch (error) {
|
|
56323
|
-
const isDuplicated = error.message?.includes("duplicate");
|
|
56324
|
-
if (isDuplicated)
|
|
56325
|
-
throw new import_node_server_utils237.BadRequestError("Post Favorite already exists.");
|
|
56326
|
-
throw error;
|
|
56327
|
-
}
|
|
56328
|
-
}
|
|
56329
|
-
async function getById(_id) {
|
|
56330
|
-
try {
|
|
56331
|
-
_id = new import_mongodb135.ObjectId(_id);
|
|
56332
|
-
} catch {
|
|
56333
|
-
throw new import_node_server_utils237.BadRequestError("Invalid favorite ID format.");
|
|
56334
|
-
}
|
|
56335
|
-
const result = await collection.findOne({ _id });
|
|
56336
|
-
if (!result)
|
|
56337
|
-
throw new import_node_server_utils237.NotFoundError("Favorite not found.");
|
|
56338
|
-
return result;
|
|
56339
|
-
}
|
|
56340
|
-
async function getByPostId(postId) {
|
|
56341
|
-
try {
|
|
56342
|
-
postId = new import_mongodb135.ObjectId(postId);
|
|
56343
|
-
} catch {
|
|
56344
|
-
throw new import_node_server_utils237.BadRequestError("Invalid post ID format.");
|
|
56345
|
-
}
|
|
56346
|
-
const result = await collection.findOne({ postId });
|
|
56347
|
-
if (!result)
|
|
56348
|
-
throw new import_node_server_utils237.NotFoundError("Favorite not found.");
|
|
56349
|
-
return result;
|
|
56350
|
-
}
|
|
56351
|
-
async function updateById(_id, userId, session) {
|
|
56352
|
-
try {
|
|
56353
|
-
_id = new import_mongodb135.ObjectId(_id);
|
|
56354
|
-
} catch {
|
|
56355
|
-
throw new import_node_server_utils237.BadRequestError("Invalid favorite ID format.");
|
|
56356
|
-
}
|
|
56357
|
-
let userObjectId;
|
|
56358
|
-
try {
|
|
56359
|
-
userObjectId = new import_mongodb135.ObjectId(userId);
|
|
56360
|
-
} catch {
|
|
56361
|
-
throw new import_node_server_utils237.BadRequestError("Invalid user ID format.");
|
|
56362
|
-
}
|
|
56363
|
-
const existing = await collection.findOne(
|
|
56364
|
-
{ _id, userIds: userObjectId },
|
|
56365
|
-
{ session }
|
|
56366
|
-
);
|
|
56367
|
-
const update = existing ? { $pull: { userIds: userObjectId }, $set: { updatedAt: (/* @__PURE__ */ new Date()).toISOString() } } : { $addToSet: { userIds: userObjectId }, $set: { updatedAt: (/* @__PURE__ */ new Date()).toISOString() } };
|
|
56368
|
-
const res = await collection.updateOne({ _id }, update, { session });
|
|
56369
|
-
if (res.modifiedCount === 0)
|
|
56370
|
-
throw new import_node_server_utils237.InternalServerError("Unable to update favorite.");
|
|
56371
|
-
return existing ? "removed" : "added";
|
|
56372
|
-
}
|
|
56373
|
-
return {
|
|
56374
|
-
addFavorite,
|
|
56375
|
-
getById,
|
|
56376
|
-
getByPostId,
|
|
56377
|
-
updateById
|
|
56378
|
-
};
|
|
56379
|
-
}
|
|
56380
|
-
|
|
56381
56701
|
// src/services/post-favorite.service.ts
|
|
56382
|
-
var
|
|
56383
|
-
function
|
|
56702
|
+
var import_node_server_utils239 = require("@7365admin1/node-server-utils");
|
|
56703
|
+
function usePostFavoriteService2() {
|
|
56384
56704
|
const { addFavorite: _addFavorite, updateById: _updateById } = usePostFavoriteRepo();
|
|
56385
56705
|
async function addFavorite(value) {
|
|
56386
|
-
const session =
|
|
56706
|
+
const session = import_node_server_utils239.useAtlas.getClient()?.startSession();
|
|
56387
56707
|
session?.startTransaction();
|
|
56388
56708
|
try {
|
|
56389
56709
|
await _addFavorite(value, session);
|
|
@@ -56397,7 +56717,7 @@ function usePostFavoriteService() {
|
|
|
56397
56717
|
}
|
|
56398
56718
|
}
|
|
56399
56719
|
async function toggleFavorite(_id, userId) {
|
|
56400
|
-
const session =
|
|
56720
|
+
const session = import_node_server_utils239.useAtlas.getClient()?.startSession();
|
|
56401
56721
|
session?.startTransaction();
|
|
56402
56722
|
try {
|
|
56403
56723
|
const action = await _updateById(_id, userId, session);
|
|
@@ -56417,10 +56737,10 @@ function usePostFavoriteService() {
|
|
|
56417
56737
|
}
|
|
56418
56738
|
|
|
56419
56739
|
// src/controllers/post-favorite.controller.ts
|
|
56420
|
-
var
|
|
56740
|
+
var import_node_server_utils240 = require("@7365admin1/node-server-utils");
|
|
56421
56741
|
var import_joi136 = __toESM(require("joi"));
|
|
56422
56742
|
function usePostFavoriteController() {
|
|
56423
|
-
const { addFavorite: _addFavorite, toggleFavorite: _toggleFavorite } =
|
|
56743
|
+
const { addFavorite: _addFavorite, toggleFavorite: _toggleFavorite } = usePostFavoriteService2();
|
|
56424
56744
|
const { getById: _getById, getByPostId: _getByPostId } = usePostFavoriteRepo();
|
|
56425
56745
|
async function addFavorite(req, res, next) {
|
|
56426
56746
|
const { error, value } = schemaPostFavorite.validate(req.body, {
|
|
@@ -56428,8 +56748,8 @@ function usePostFavoriteController() {
|
|
|
56428
56748
|
});
|
|
56429
56749
|
if (error) {
|
|
56430
56750
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
56431
|
-
|
|
56432
|
-
next(new
|
|
56751
|
+
import_node_server_utils240.logger.log({ level: "error", message: messages });
|
|
56752
|
+
next(new import_node_server_utils240.BadRequestError(messages));
|
|
56433
56753
|
return;
|
|
56434
56754
|
}
|
|
56435
56755
|
try {
|
|
@@ -56437,7 +56757,7 @@ function usePostFavoriteController() {
|
|
|
56437
56757
|
res.status(201).json(data);
|
|
56438
56758
|
return;
|
|
56439
56759
|
} catch (error2) {
|
|
56440
|
-
|
|
56760
|
+
import_node_server_utils240.logger.log({ level: "error", message: error2.message });
|
|
56441
56761
|
next(error2);
|
|
56442
56762
|
return;
|
|
56443
56763
|
}
|
|
@@ -56448,8 +56768,8 @@ function usePostFavoriteController() {
|
|
|
56448
56768
|
});
|
|
56449
56769
|
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
56450
56770
|
if (error) {
|
|
56451
|
-
|
|
56452
|
-
next(new
|
|
56771
|
+
import_node_server_utils240.logger.log({ level: "error", message: error.message });
|
|
56772
|
+
next(new import_node_server_utils240.BadRequestError(error.message));
|
|
56453
56773
|
return;
|
|
56454
56774
|
}
|
|
56455
56775
|
try {
|
|
@@ -56457,7 +56777,7 @@ function usePostFavoriteController() {
|
|
|
56457
56777
|
res.status(200).json(data);
|
|
56458
56778
|
return;
|
|
56459
56779
|
} catch (error2) {
|
|
56460
|
-
|
|
56780
|
+
import_node_server_utils240.logger.log({ level: "error", message: error2.message });
|
|
56461
56781
|
next(error2);
|
|
56462
56782
|
return;
|
|
56463
56783
|
}
|
|
@@ -56468,8 +56788,8 @@ function usePostFavoriteController() {
|
|
|
56468
56788
|
});
|
|
56469
56789
|
const { error, value } = schema2.validate({ postId: req.params.postId });
|
|
56470
56790
|
if (error) {
|
|
56471
|
-
|
|
56472
|
-
next(new
|
|
56791
|
+
import_node_server_utils240.logger.log({ level: "error", message: error.message });
|
|
56792
|
+
next(new import_node_server_utils240.BadRequestError(error.message));
|
|
56473
56793
|
return;
|
|
56474
56794
|
}
|
|
56475
56795
|
try {
|
|
@@ -56477,7 +56797,7 @@ function usePostFavoriteController() {
|
|
|
56477
56797
|
res.status(200).json(data);
|
|
56478
56798
|
return;
|
|
56479
56799
|
} catch (error2) {
|
|
56480
|
-
|
|
56800
|
+
import_node_server_utils240.logger.log({ level: "error", message: error2.message });
|
|
56481
56801
|
next(error2);
|
|
56482
56802
|
return;
|
|
56483
56803
|
}
|
|
@@ -56490,21 +56810,21 @@ function usePostFavoriteController() {
|
|
|
56490
56810
|
_id: req.params.id
|
|
56491
56811
|
});
|
|
56492
56812
|
if (paramsError) {
|
|
56493
|
-
next(new
|
|
56813
|
+
next(new import_node_server_utils240.BadRequestError(paramsError.message));
|
|
56494
56814
|
return;
|
|
56495
56815
|
}
|
|
56496
56816
|
const { error: bodyError, value: bodyValue } = schemaUpdatePostFavorite.validate(req.body, { abortEarly: false });
|
|
56497
56817
|
if (bodyError) {
|
|
56498
56818
|
const messages = bodyError.details.map((d) => d.message).join(", ");
|
|
56499
|
-
|
|
56500
|
-
next(new
|
|
56819
|
+
import_node_server_utils240.logger.log({ level: "error", message: messages });
|
|
56820
|
+
next(new import_node_server_utils240.BadRequestError(messages));
|
|
56501
56821
|
return;
|
|
56502
56822
|
}
|
|
56503
56823
|
try {
|
|
56504
56824
|
const data = await _toggleFavorite(paramsValue._id, bodyValue.userId);
|
|
56505
56825
|
res.status(200).json(data);
|
|
56506
56826
|
} catch (error) {
|
|
56507
|
-
|
|
56827
|
+
import_node_server_utils240.logger.log({ level: "error", message: error.message });
|
|
56508
56828
|
next(error);
|
|
56509
56829
|
}
|
|
56510
56830
|
}
|
|
@@ -56518,7 +56838,7 @@ function usePostFavoriteController() {
|
|
|
56518
56838
|
|
|
56519
56839
|
// src/models/category-preloved.model.ts
|
|
56520
56840
|
var import_joi137 = __toESM(require("joi"));
|
|
56521
|
-
var
|
|
56841
|
+
var import_mongodb137 = require("mongodb");
|
|
56522
56842
|
var schemaCategoryPreloved = import_joi137.default.object({
|
|
56523
56843
|
name: import_joi137.default.string().required(),
|
|
56524
56844
|
createdBy: import_joi137.default.string().hex().optional().allow("", null),
|
|
@@ -56535,14 +56855,14 @@ function MCategoryPreloved(value) {
|
|
|
56535
56855
|
}
|
|
56536
56856
|
if (value.createdBy && typeof value.createdBy === "string") {
|
|
56537
56857
|
try {
|
|
56538
|
-
value.createdBy = new
|
|
56858
|
+
value.createdBy = new import_mongodb137.ObjectId(value.createdBy);
|
|
56539
56859
|
} catch {
|
|
56540
56860
|
throw new Error("Invalid createdBy ID.");
|
|
56541
56861
|
}
|
|
56542
56862
|
}
|
|
56543
56863
|
if (value.site && typeof value.site === "string") {
|
|
56544
56864
|
try {
|
|
56545
|
-
value.site = new
|
|
56865
|
+
value.site = new import_mongodb137.ObjectId(value.site);
|
|
56546
56866
|
} catch {
|
|
56547
56867
|
throw new Error("Invalid site ID.");
|
|
56548
56868
|
}
|
|
@@ -56557,12 +56877,12 @@ function MCategoryPreloved(value) {
|
|
|
56557
56877
|
}
|
|
56558
56878
|
|
|
56559
56879
|
// src/repositories/category-preloved.repo.ts
|
|
56560
|
-
var
|
|
56561
|
-
var
|
|
56880
|
+
var import_node_server_utils241 = require("@7365admin1/node-server-utils");
|
|
56881
|
+
var import_mongodb138 = require("mongodb");
|
|
56562
56882
|
function useCategoryPrelovedRepo() {
|
|
56563
|
-
const db =
|
|
56883
|
+
const db = import_node_server_utils241.useAtlas.getDb();
|
|
56564
56884
|
if (!db) {
|
|
56565
|
-
throw new
|
|
56885
|
+
throw new import_node_server_utils241.InternalServerError("Unable to connect to server.");
|
|
56566
56886
|
}
|
|
56567
56887
|
const CATEGORY_COLLECTION = "category-preloved";
|
|
56568
56888
|
const collection = db.collection(CATEGORY_COLLECTION);
|
|
@@ -56572,9 +56892,9 @@ function useCategoryPrelovedRepo() {
|
|
|
56572
56892
|
} = {}) {
|
|
56573
56893
|
if (site) {
|
|
56574
56894
|
try {
|
|
56575
|
-
site = new
|
|
56895
|
+
site = new import_mongodb138.ObjectId(site);
|
|
56576
56896
|
} catch {
|
|
56577
|
-
throw new
|
|
56897
|
+
throw new import_node_server_utils241.BadRequestError("Invalid site ID format.");
|
|
56578
56898
|
}
|
|
56579
56899
|
}
|
|
56580
56900
|
const query = {
|
|
@@ -56591,14 +56911,14 @@ function useCategoryPrelovedRepo() {
|
|
|
56591
56911
|
async function getById(_id) {
|
|
56592
56912
|
let objectId2;
|
|
56593
56913
|
try {
|
|
56594
|
-
objectId2 = new
|
|
56914
|
+
objectId2 = new import_mongodb138.ObjectId(_id);
|
|
56595
56915
|
} catch {
|
|
56596
|
-
throw new
|
|
56916
|
+
throw new import_node_server_utils241.BadRequestError("Invalid category-preloved ID format.");
|
|
56597
56917
|
}
|
|
56598
56918
|
try {
|
|
56599
56919
|
const data = await collection.findOne({ _id: objectId2 });
|
|
56600
56920
|
if (!data) {
|
|
56601
|
-
throw new
|
|
56921
|
+
throw new import_node_server_utils241.NotFoundError("Category not found.");
|
|
56602
56922
|
}
|
|
56603
56923
|
return data;
|
|
56604
56924
|
} catch (error) {
|
|
@@ -56614,18 +56934,36 @@ function useCategoryPrelovedRepo() {
|
|
|
56614
56934
|
} catch (error) {
|
|
56615
56935
|
const isDuplicated = error.message?.includes("duplicate");
|
|
56616
56936
|
if (isDuplicated)
|
|
56617
|
-
throw new
|
|
56937
|
+
throw new import_node_server_utils241.BadRequestError("Category already exists.");
|
|
56618
56938
|
throw error;
|
|
56619
56939
|
}
|
|
56620
56940
|
}
|
|
56621
|
-
|
|
56941
|
+
async function updateById(_id, value) {
|
|
56942
|
+
let objectId2;
|
|
56943
|
+
try {
|
|
56944
|
+
objectId2 = new import_mongodb138.ObjectId(_id);
|
|
56945
|
+
} catch {
|
|
56946
|
+
throw new import_node_server_utils241.BadRequestError("Invalid category ID format.");
|
|
56947
|
+
}
|
|
56948
|
+
const existing = await collection.findOne({ _id: objectId2 });
|
|
56949
|
+
if (!existing)
|
|
56950
|
+
throw new import_node_server_utils241.NotFoundError("Category not found.");
|
|
56951
|
+
const res = await collection.updateOne(
|
|
56952
|
+
{ _id: objectId2 },
|
|
56953
|
+
{ $set: { ...value, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } }
|
|
56954
|
+
);
|
|
56955
|
+
if (res.modifiedCount === 0)
|
|
56956
|
+
throw new import_node_server_utils241.InternalServerError("Unable to update category.");
|
|
56957
|
+
return "Category updated successfully.";
|
|
56958
|
+
}
|
|
56959
|
+
return { getAll, getById, addCategory, updateById };
|
|
56622
56960
|
}
|
|
56623
56961
|
|
|
56624
56962
|
// src/controllers/category-preloved.controller.ts
|
|
56625
|
-
var
|
|
56963
|
+
var import_node_server_utils242 = require("@7365admin1/node-server-utils");
|
|
56626
56964
|
var import_joi138 = __toESM(require("joi"));
|
|
56627
56965
|
function useCategoryPrelovedController() {
|
|
56628
|
-
const { getAll: _getAll, getById: _getById, addCategory: _addCategory } = useCategoryPrelovedRepo();
|
|
56966
|
+
const { getAll: _getAll, getById: _getById, addCategory: _addCategory, updateById: _updateById } = useCategoryPrelovedRepo();
|
|
56629
56967
|
async function getAll(req, res, next) {
|
|
56630
56968
|
const schema2 = import_joi138.default.object({
|
|
56631
56969
|
search: import_joi138.default.string().optional().allow("", null),
|
|
@@ -56634,8 +56972,8 @@ function useCategoryPrelovedController() {
|
|
|
56634
56972
|
const { error, value } = schema2.validate(req.query, { abortEarly: false });
|
|
56635
56973
|
if (error) {
|
|
56636
56974
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
56637
|
-
|
|
56638
|
-
next(new
|
|
56975
|
+
import_node_server_utils242.logger.log({ level: "error", message: messages });
|
|
56976
|
+
next(new import_node_server_utils242.BadRequestError(messages));
|
|
56639
56977
|
return;
|
|
56640
56978
|
}
|
|
56641
56979
|
try {
|
|
@@ -56643,7 +56981,7 @@ function useCategoryPrelovedController() {
|
|
|
56643
56981
|
res.status(200).json({ data });
|
|
56644
56982
|
return;
|
|
56645
56983
|
} catch (error2) {
|
|
56646
|
-
|
|
56984
|
+
import_node_server_utils242.logger.log({ level: "error", message: error2.message });
|
|
56647
56985
|
next(error2);
|
|
56648
56986
|
return;
|
|
56649
56987
|
}
|
|
@@ -56654,8 +56992,8 @@ function useCategoryPrelovedController() {
|
|
|
56654
56992
|
});
|
|
56655
56993
|
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
56656
56994
|
if (error) {
|
|
56657
|
-
|
|
56658
|
-
next(new
|
|
56995
|
+
import_node_server_utils242.logger.log({ level: "error", message: error.message });
|
|
56996
|
+
next(new import_node_server_utils242.BadRequestError(error.message));
|
|
56659
56997
|
return;
|
|
56660
56998
|
}
|
|
56661
56999
|
try {
|
|
@@ -56663,7 +57001,7 @@ function useCategoryPrelovedController() {
|
|
|
56663
57001
|
res.status(200).json({ data });
|
|
56664
57002
|
return;
|
|
56665
57003
|
} catch (error2) {
|
|
56666
|
-
|
|
57004
|
+
import_node_server_utils242.logger.log({ level: "error", message: error2.message });
|
|
56667
57005
|
next(error2);
|
|
56668
57006
|
return;
|
|
56669
57007
|
}
|
|
@@ -56674,24 +57012,42 @@ function useCategoryPrelovedController() {
|
|
|
56674
57012
|
});
|
|
56675
57013
|
if (error) {
|
|
56676
57014
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
56677
|
-
|
|
56678
|
-
next(new
|
|
57015
|
+
import_node_server_utils242.logger.log({ level: "error", message: messages });
|
|
57016
|
+
next(new import_node_server_utils242.BadRequestError(messages));
|
|
56679
57017
|
return;
|
|
56680
57018
|
}
|
|
56681
57019
|
try {
|
|
56682
57020
|
const data = await _addCategory(value);
|
|
56683
57021
|
res.status(201).json(data);
|
|
56684
57022
|
} catch (error2) {
|
|
56685
|
-
|
|
57023
|
+
import_node_server_utils242.logger.log({ level: "error", message: error2.message });
|
|
57024
|
+
next(error2);
|
|
57025
|
+
}
|
|
57026
|
+
}
|
|
57027
|
+
async function updateById(req, res, next) {
|
|
57028
|
+
const { error, value } = schemaUpdateCategoryPreloved.validate(req.body, {
|
|
57029
|
+
abortEarly: false
|
|
57030
|
+
});
|
|
57031
|
+
if (error) {
|
|
57032
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
57033
|
+
import_node_server_utils242.logger.log({ level: "error", message: messages });
|
|
57034
|
+
next(new import_node_server_utils242.BadRequestError(messages));
|
|
57035
|
+
return;
|
|
57036
|
+
}
|
|
57037
|
+
try {
|
|
57038
|
+
const data = await _updateById(req.params.id, value);
|
|
57039
|
+
res.status(200).json(data);
|
|
57040
|
+
} catch (error2) {
|
|
57041
|
+
import_node_server_utils242.logger.log({ level: "error", message: error2.message });
|
|
56686
57042
|
next(error2);
|
|
56687
57043
|
}
|
|
56688
57044
|
}
|
|
56689
|
-
return { getAll, getById, addCategory };
|
|
57045
|
+
return { getAll, getById, addCategory, updateById };
|
|
56690
57046
|
}
|
|
56691
57047
|
|
|
56692
57048
|
// src/models/subcategory-preloved.model.ts
|
|
56693
57049
|
var import_joi139 = __toESM(require("joi"));
|
|
56694
|
-
var
|
|
57050
|
+
var import_mongodb139 = require("mongodb");
|
|
56695
57051
|
var schemaSubcategoryPreloved = import_joi139.default.object({
|
|
56696
57052
|
name: import_joi139.default.string().required(),
|
|
56697
57053
|
createdBy: import_joi139.default.string().hex().optional().allow("", null),
|
|
@@ -56710,21 +57066,21 @@ function MSubcategoryPreloved(value) {
|
|
|
56710
57066
|
}
|
|
56711
57067
|
if (value.createdBy && typeof value.createdBy === "string") {
|
|
56712
57068
|
try {
|
|
56713
|
-
value.createdBy = new
|
|
57069
|
+
value.createdBy = new import_mongodb139.ObjectId(value.createdBy);
|
|
56714
57070
|
} catch {
|
|
56715
57071
|
throw new Error("Invalid createdBy ID.");
|
|
56716
57072
|
}
|
|
56717
57073
|
}
|
|
56718
57074
|
if (value.site && typeof value.site === "string") {
|
|
56719
57075
|
try {
|
|
56720
|
-
value.site = new
|
|
57076
|
+
value.site = new import_mongodb139.ObjectId(value.site);
|
|
56721
57077
|
} catch {
|
|
56722
57078
|
throw new Error("Invalid site ID.");
|
|
56723
57079
|
}
|
|
56724
57080
|
}
|
|
56725
57081
|
if (value.category_id && typeof value.category_id === "string") {
|
|
56726
57082
|
try {
|
|
56727
|
-
value.category_id = new
|
|
57083
|
+
value.category_id = new import_mongodb139.ObjectId(value.category_id);
|
|
56728
57084
|
} catch {
|
|
56729
57085
|
throw new Error("Invalid category ID.");
|
|
56730
57086
|
}
|
|
@@ -56740,12 +57096,12 @@ function MSubcategoryPreloved(value) {
|
|
|
56740
57096
|
}
|
|
56741
57097
|
|
|
56742
57098
|
// src/repositories/subcategory-preloved.repo.ts
|
|
56743
|
-
var
|
|
56744
|
-
var
|
|
57099
|
+
var import_node_server_utils243 = require("@7365admin1/node-server-utils");
|
|
57100
|
+
var import_mongodb140 = require("mongodb");
|
|
56745
57101
|
function useSubcategoryPrelovedRepo() {
|
|
56746
|
-
const db =
|
|
57102
|
+
const db = import_node_server_utils243.useAtlas.getDb();
|
|
56747
57103
|
if (!db) {
|
|
56748
|
-
throw new
|
|
57104
|
+
throw new import_node_server_utils243.InternalServerError("Unable to connect to server.");
|
|
56749
57105
|
}
|
|
56750
57106
|
const SUBCATEGORY_COLLECTION = "subcategory-preloved";
|
|
56751
57107
|
const collection = db.collection(SUBCATEGORY_COLLECTION);
|
|
@@ -56756,16 +57112,16 @@ function useSubcategoryPrelovedRepo() {
|
|
|
56756
57112
|
} = {}) {
|
|
56757
57113
|
if (site) {
|
|
56758
57114
|
try {
|
|
56759
|
-
site = new
|
|
57115
|
+
site = new import_mongodb140.ObjectId(site);
|
|
56760
57116
|
} catch {
|
|
56761
|
-
throw new
|
|
57117
|
+
throw new import_node_server_utils243.BadRequestError("Invalid site ID format.");
|
|
56762
57118
|
}
|
|
56763
57119
|
}
|
|
56764
57120
|
if (category_id) {
|
|
56765
57121
|
try {
|
|
56766
|
-
category_id = new
|
|
57122
|
+
category_id = new import_mongodb140.ObjectId(category_id);
|
|
56767
57123
|
} catch {
|
|
56768
|
-
throw new
|
|
57124
|
+
throw new import_node_server_utils243.BadRequestError("Invalid category ID format.");
|
|
56769
57125
|
}
|
|
56770
57126
|
}
|
|
56771
57127
|
const query = {
|
|
@@ -56782,14 +57138,14 @@ function useSubcategoryPrelovedRepo() {
|
|
|
56782
57138
|
async function getById(_id) {
|
|
56783
57139
|
let objectId2;
|
|
56784
57140
|
try {
|
|
56785
|
-
objectId2 = new
|
|
57141
|
+
objectId2 = new import_mongodb140.ObjectId(_id);
|
|
56786
57142
|
} catch {
|
|
56787
|
-
throw new
|
|
57143
|
+
throw new import_node_server_utils243.BadRequestError("Invalid subcategory-preloved ID format.");
|
|
56788
57144
|
}
|
|
56789
57145
|
try {
|
|
56790
57146
|
const data = await collection.findOne({ _id: objectId2 });
|
|
56791
57147
|
if (!data) {
|
|
56792
|
-
throw new
|
|
57148
|
+
throw new import_node_server_utils243.NotFoundError("Subcategory not found.");
|
|
56793
57149
|
}
|
|
56794
57150
|
return data;
|
|
56795
57151
|
} catch (error) {
|
|
@@ -56804,29 +57160,29 @@ function useSubcategoryPrelovedRepo() {
|
|
|
56804
57160
|
} catch (error) {
|
|
56805
57161
|
const isDuplicated = error.message?.includes("duplicate");
|
|
56806
57162
|
if (isDuplicated)
|
|
56807
|
-
throw new
|
|
57163
|
+
throw new import_node_server_utils243.BadRequestError("Subcategory already exists.");
|
|
56808
57164
|
throw error;
|
|
56809
57165
|
}
|
|
56810
57166
|
}
|
|
56811
57167
|
async function updateById(_id, value, session) {
|
|
56812
57168
|
let objectId2;
|
|
56813
57169
|
try {
|
|
56814
|
-
objectId2 = new
|
|
57170
|
+
objectId2 = new import_mongodb140.ObjectId(_id);
|
|
56815
57171
|
} catch {
|
|
56816
|
-
throw new
|
|
57172
|
+
throw new import_node_server_utils243.BadRequestError("Invalid subcategory ID format.");
|
|
56817
57173
|
}
|
|
56818
57174
|
if (value.category_id && typeof value.category_id === "string") {
|
|
56819
57175
|
try {
|
|
56820
|
-
value.category_id = new
|
|
57176
|
+
value.category_id = new import_mongodb140.ObjectId(value.category_id);
|
|
56821
57177
|
} catch {
|
|
56822
|
-
throw new
|
|
57178
|
+
throw new import_node_server_utils243.BadRequestError("Invalid category ID format.");
|
|
56823
57179
|
}
|
|
56824
57180
|
}
|
|
56825
57181
|
if (value.site && typeof value.site === "string") {
|
|
56826
57182
|
try {
|
|
56827
|
-
value.site = new
|
|
57183
|
+
value.site = new import_mongodb140.ObjectId(value.site);
|
|
56828
57184
|
} catch {
|
|
56829
|
-
throw new
|
|
57185
|
+
throw new import_node_server_utils243.BadRequestError("Invalid site ID format.");
|
|
56830
57186
|
}
|
|
56831
57187
|
}
|
|
56832
57188
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -56836,26 +57192,26 @@ function useSubcategoryPrelovedRepo() {
|
|
|
56836
57192
|
{ session }
|
|
56837
57193
|
);
|
|
56838
57194
|
if (res.modifiedCount === 0)
|
|
56839
|
-
throw new
|
|
57195
|
+
throw new import_node_server_utils243.InternalServerError("Unable to update subcategory.");
|
|
56840
57196
|
return res;
|
|
56841
57197
|
}
|
|
56842
57198
|
async function deleteById(_id, session) {
|
|
56843
57199
|
let objectId2;
|
|
56844
57200
|
try {
|
|
56845
|
-
objectId2 = new
|
|
57201
|
+
objectId2 = new import_mongodb140.ObjectId(_id);
|
|
56846
57202
|
} catch {
|
|
56847
|
-
throw new
|
|
57203
|
+
throw new import_node_server_utils243.BadRequestError("Invalid subcategory ID format.");
|
|
56848
57204
|
}
|
|
56849
57205
|
const res = await collection.deleteOne({ _id: objectId2 }, { session });
|
|
56850
57206
|
if (res.deletedCount === 0)
|
|
56851
|
-
throw new
|
|
57207
|
+
throw new import_node_server_utils243.InternalServerError("Unable to delete subcategory.");
|
|
56852
57208
|
return res.deletedCount;
|
|
56853
57209
|
}
|
|
56854
57210
|
return { getAll, getById, addSubcategory, updateById, deleteById };
|
|
56855
57211
|
}
|
|
56856
57212
|
|
|
56857
57213
|
// src/controllers/subcategory-preloved.controller.ts
|
|
56858
|
-
var
|
|
57214
|
+
var import_node_server_utils244 = require("@7365admin1/node-server-utils");
|
|
56859
57215
|
var import_joi140 = __toESM(require("joi"));
|
|
56860
57216
|
function useSubcategoryPrelovedController() {
|
|
56861
57217
|
const {
|
|
@@ -56874,8 +57230,8 @@ function useSubcategoryPrelovedController() {
|
|
|
56874
57230
|
const { error, value } = schema2.validate(req.query, { abortEarly: false });
|
|
56875
57231
|
if (error) {
|
|
56876
57232
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
56877
|
-
|
|
56878
|
-
next(new
|
|
57233
|
+
import_node_server_utils244.logger.log({ level: "error", message: messages });
|
|
57234
|
+
next(new import_node_server_utils244.BadRequestError(messages));
|
|
56879
57235
|
return;
|
|
56880
57236
|
}
|
|
56881
57237
|
try {
|
|
@@ -56883,7 +57239,7 @@ function useSubcategoryPrelovedController() {
|
|
|
56883
57239
|
res.status(200).json({ data });
|
|
56884
57240
|
return;
|
|
56885
57241
|
} catch (error2) {
|
|
56886
|
-
|
|
57242
|
+
import_node_server_utils244.logger.log({ level: "error", message: error2.message });
|
|
56887
57243
|
next(error2);
|
|
56888
57244
|
return;
|
|
56889
57245
|
}
|
|
@@ -56894,8 +57250,8 @@ function useSubcategoryPrelovedController() {
|
|
|
56894
57250
|
});
|
|
56895
57251
|
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
56896
57252
|
if (error) {
|
|
56897
|
-
|
|
56898
|
-
next(new
|
|
57253
|
+
import_node_server_utils244.logger.log({ level: "error", message: error.message });
|
|
57254
|
+
next(new import_node_server_utils244.BadRequestError(error.message));
|
|
56899
57255
|
return;
|
|
56900
57256
|
}
|
|
56901
57257
|
try {
|
|
@@ -56903,7 +57259,7 @@ function useSubcategoryPrelovedController() {
|
|
|
56903
57259
|
res.status(200).json({ data });
|
|
56904
57260
|
return;
|
|
56905
57261
|
} catch (error2) {
|
|
56906
|
-
|
|
57262
|
+
import_node_server_utils244.logger.log({ level: "error", message: error2.message });
|
|
56907
57263
|
next(error2);
|
|
56908
57264
|
return;
|
|
56909
57265
|
}
|
|
@@ -56914,15 +57270,15 @@ function useSubcategoryPrelovedController() {
|
|
|
56914
57270
|
});
|
|
56915
57271
|
if (error) {
|
|
56916
57272
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
56917
|
-
|
|
56918
|
-
next(new
|
|
57273
|
+
import_node_server_utils244.logger.log({ level: "error", message: messages });
|
|
57274
|
+
next(new import_node_server_utils244.BadRequestError(messages));
|
|
56919
57275
|
return;
|
|
56920
57276
|
}
|
|
56921
57277
|
try {
|
|
56922
57278
|
const data = await _addSubcategory(value);
|
|
56923
57279
|
res.status(201).json(data);
|
|
56924
57280
|
} catch (error2) {
|
|
56925
|
-
|
|
57281
|
+
import_node_server_utils244.logger.log({ level: "error", message: error2.message });
|
|
56926
57282
|
next(error2);
|
|
56927
57283
|
}
|
|
56928
57284
|
}
|
|
@@ -56934,21 +57290,21 @@ function useSubcategoryPrelovedController() {
|
|
|
56934
57290
|
_id: req.params.id
|
|
56935
57291
|
});
|
|
56936
57292
|
if (paramsError) {
|
|
56937
|
-
next(new
|
|
57293
|
+
next(new import_node_server_utils244.BadRequestError(paramsError.message));
|
|
56938
57294
|
return;
|
|
56939
57295
|
}
|
|
56940
57296
|
const { error: bodyError, value: bodyValue } = schemaUpdateSubcategoryPreloved.validate(req.body, { abortEarly: false });
|
|
56941
57297
|
if (bodyError) {
|
|
56942
57298
|
const messages = bodyError.details.map((d) => d.message).join(", ");
|
|
56943
|
-
|
|
56944
|
-
next(new
|
|
57299
|
+
import_node_server_utils244.logger.log({ level: "error", message: messages });
|
|
57300
|
+
next(new import_node_server_utils244.BadRequestError(messages));
|
|
56945
57301
|
return;
|
|
56946
57302
|
}
|
|
56947
57303
|
try {
|
|
56948
57304
|
const data = await _updateById(paramsValue._id, bodyValue);
|
|
56949
57305
|
res.status(200).json(data);
|
|
56950
57306
|
} catch (error) {
|
|
56951
|
-
|
|
57307
|
+
import_node_server_utils244.logger.log({ level: "error", message: error.message });
|
|
56952
57308
|
next(error);
|
|
56953
57309
|
}
|
|
56954
57310
|
}
|
|
@@ -56958,14 +57314,14 @@ function useSubcategoryPrelovedController() {
|
|
|
56958
57314
|
});
|
|
56959
57315
|
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
56960
57316
|
if (error) {
|
|
56961
|
-
next(new
|
|
57317
|
+
next(new import_node_server_utils244.BadRequestError(error.message));
|
|
56962
57318
|
return;
|
|
56963
57319
|
}
|
|
56964
57320
|
try {
|
|
56965
57321
|
const data = await _deleteById(value._id);
|
|
56966
57322
|
res.status(200).json(data);
|
|
56967
57323
|
} catch (error2) {
|
|
56968
|
-
|
|
57324
|
+
import_node_server_utils244.logger.log({ level: "error", message: error2.message });
|
|
56969
57325
|
next(error2);
|
|
56970
57326
|
}
|
|
56971
57327
|
}
|
|
@@ -56974,7 +57330,7 @@ function useSubcategoryPrelovedController() {
|
|
|
56974
57330
|
|
|
56975
57331
|
// src/models/online-forms-v2.model.ts
|
|
56976
57332
|
var import_joi141 = __toESM(require("joi"));
|
|
56977
|
-
var
|
|
57333
|
+
var import_mongodb141 = require("mongodb");
|
|
56978
57334
|
var FormEntryStatus = /* @__PURE__ */ ((FormEntryStatus2) => {
|
|
56979
57335
|
FormEntryStatus2["ACTIVE"] = "active";
|
|
56980
57336
|
FormEntryStatus2["INACTIVE"] = "inactive";
|
|
@@ -57008,6 +57364,9 @@ var schemaFormEntry = import_joi141.default.object({
|
|
|
57008
57364
|
var schemaUpdateFormEntry = import_joi141.default.object({
|
|
57009
57365
|
_id: import_joi141.default.string().hex().required(),
|
|
57010
57366
|
formType: import_joi141.default.string().optional().allow("", null),
|
|
57367
|
+
block: import_joi141.default.string().optional().allow(null, ""),
|
|
57368
|
+
level: import_joi141.default.string().optional().allow(null, ""),
|
|
57369
|
+
unit: import_joi141.default.string().optional().allow(null, ""),
|
|
57011
57370
|
fields: import_joi141.default.object().pattern(
|
|
57012
57371
|
import_joi141.default.string(),
|
|
57013
57372
|
import_joi141.default.alternatives().try(
|
|
@@ -57018,7 +57377,6 @@ var schemaUpdateFormEntry = import_joi141.default.object({
|
|
|
57018
57377
|
)
|
|
57019
57378
|
).optional(),
|
|
57020
57379
|
status: import_joi141.default.string().optional().allow("", null),
|
|
57021
|
-
createdAt: import_joi141.default.date().optional().allow("", null),
|
|
57022
57380
|
updatedAt: import_joi141.default.date().optional().allow("", null),
|
|
57023
57381
|
deletedAt: import_joi141.default.date().optional().allow("", null)
|
|
57024
57382
|
});
|
|
@@ -57029,21 +57387,21 @@ function MFormEntry(value) {
|
|
|
57029
57387
|
}
|
|
57030
57388
|
if (value._id && typeof value._id === "string") {
|
|
57031
57389
|
try {
|
|
57032
|
-
value._id = new
|
|
57390
|
+
value._id = new import_mongodb141.ObjectId(value._id);
|
|
57033
57391
|
} catch {
|
|
57034
57392
|
throw new Error("Invalid ID.");
|
|
57035
57393
|
}
|
|
57036
57394
|
}
|
|
57037
57395
|
if (value.org && typeof value.org === "string") {
|
|
57038
57396
|
try {
|
|
57039
|
-
value.org = new
|
|
57397
|
+
value.org = new import_mongodb141.ObjectId(value.org);
|
|
57040
57398
|
} catch {
|
|
57041
57399
|
throw new Error("Invalid org ID.");
|
|
57042
57400
|
}
|
|
57043
57401
|
}
|
|
57044
57402
|
if (value.site && typeof value.site === "string") {
|
|
57045
57403
|
try {
|
|
57046
|
-
value.site = new
|
|
57404
|
+
value.site = new import_mongodb141.ObjectId(value.site);
|
|
57047
57405
|
} catch {
|
|
57048
57406
|
throw new Error("Invalid site ID.");
|
|
57049
57407
|
}
|
|
@@ -57051,6 +57409,11 @@ function MFormEntry(value) {
|
|
|
57051
57409
|
return {
|
|
57052
57410
|
_id: value._id,
|
|
57053
57411
|
formType: value.formType,
|
|
57412
|
+
block: value.block,
|
|
57413
|
+
level: value.level,
|
|
57414
|
+
unit: value.unit,
|
|
57415
|
+
name: value.name,
|
|
57416
|
+
phoneNumber: value.phoneNumber,
|
|
57054
57417
|
fields: value.fields,
|
|
57055
57418
|
status: value.status,
|
|
57056
57419
|
org: value.org,
|
|
@@ -57062,16 +57425,16 @@ function MFormEntry(value) {
|
|
|
57062
57425
|
}
|
|
57063
57426
|
|
|
57064
57427
|
// src/repositories/online-forms-v2.repository.ts
|
|
57065
|
-
var
|
|
57066
|
-
var
|
|
57428
|
+
var import_node_server_utils245 = require("@7365admin1/node-server-utils");
|
|
57429
|
+
var import_mongodb142 = require("mongodb");
|
|
57067
57430
|
var online_forms_namespace_collection = "online-forms";
|
|
57068
57431
|
function useFormEntryRepo() {
|
|
57069
|
-
const db =
|
|
57432
|
+
const db = import_node_server_utils245.useAtlas.getDb();
|
|
57070
57433
|
if (!db) {
|
|
57071
|
-
throw new
|
|
57434
|
+
throw new import_node_server_utils245.InternalServerError("Unable to connect to server.");
|
|
57072
57435
|
}
|
|
57073
57436
|
const collection = db.collection(online_forms_namespace_collection);
|
|
57074
|
-
const { delNamespace, getCache, setCache } = (0,
|
|
57437
|
+
const { delNamespace, getCache, setCache } = (0, import_node_server_utils245.useCache)(
|
|
57075
57438
|
online_forms_namespace_collection
|
|
57076
57439
|
);
|
|
57077
57440
|
async function createTextIndex() {
|
|
@@ -57080,7 +57443,7 @@ function useFormEntryRepo() {
|
|
|
57080
57443
|
name: "text"
|
|
57081
57444
|
});
|
|
57082
57445
|
} catch (error) {
|
|
57083
|
-
throw new
|
|
57446
|
+
throw new import_node_server_utils245.InternalServerError(
|
|
57084
57447
|
"Failed to create text index on online form."
|
|
57085
57448
|
);
|
|
57086
57449
|
}
|
|
@@ -57090,11 +57453,11 @@ function useFormEntryRepo() {
|
|
|
57090
57453
|
value = MFormEntry(value);
|
|
57091
57454
|
const res = await collection.insertOne(value, { session });
|
|
57092
57455
|
delNamespace().then(() => {
|
|
57093
|
-
|
|
57456
|
+
import_node_server_utils245.logger.info(
|
|
57094
57457
|
`Cache cleared for namespace: ${online_forms_namespace_collection}`
|
|
57095
57458
|
);
|
|
57096
57459
|
}).catch((err) => {
|
|
57097
|
-
|
|
57460
|
+
import_node_server_utils245.logger.error(
|
|
57098
57461
|
`Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
|
|
57099
57462
|
err
|
|
57100
57463
|
);
|
|
@@ -57103,7 +57466,7 @@ function useFormEntryRepo() {
|
|
|
57103
57466
|
} catch (error) {
|
|
57104
57467
|
const isDuplicated = error.message.includes("duplicate");
|
|
57105
57468
|
if (isDuplicated) {
|
|
57106
|
-
throw new
|
|
57469
|
+
throw new import_node_server_utils245.BadRequestError("Online Form already exists.");
|
|
57107
57470
|
}
|
|
57108
57471
|
throw error;
|
|
57109
57472
|
}
|
|
@@ -57129,16 +57492,16 @@ function useFormEntryRepo() {
|
|
|
57129
57492
|
};
|
|
57130
57493
|
const query = {
|
|
57131
57494
|
...status ? { $and: [{ status }, { status: { $ne: "deleted" } }] } : { status: { $ne: "deleted" } },
|
|
57132
|
-
...site && { site: new
|
|
57495
|
+
...site && { site: new import_mongodb142.ObjectId(site) },
|
|
57133
57496
|
...search && { search: [{ name: { $regex: search, $options: "i" } }] }
|
|
57134
57497
|
};
|
|
57135
|
-
const cacheKey = (0,
|
|
57498
|
+
const cacheKey = (0, import_node_server_utils245.makeCacheKey)(
|
|
57136
57499
|
online_forms_namespace_collection,
|
|
57137
57500
|
cacheOptions
|
|
57138
57501
|
);
|
|
57139
57502
|
const cachedData = await getCache(cacheKey);
|
|
57140
57503
|
if (cachedData) {
|
|
57141
|
-
|
|
57504
|
+
import_node_server_utils245.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
57142
57505
|
return cachedData;
|
|
57143
57506
|
}
|
|
57144
57507
|
try {
|
|
@@ -57149,11 +57512,11 @@ function useFormEntryRepo() {
|
|
|
57149
57512
|
{ $limit: limit }
|
|
57150
57513
|
]).toArray();
|
|
57151
57514
|
const length = await collection.countDocuments(query);
|
|
57152
|
-
const data = (0,
|
|
57515
|
+
const data = (0, import_node_server_utils245.paginate)(items, page, limit, length);
|
|
57153
57516
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
57154
|
-
|
|
57517
|
+
import_node_server_utils245.logger.info(`Cache set for key: ${cacheKey}`);
|
|
57155
57518
|
}).catch((err) => {
|
|
57156
|
-
|
|
57519
|
+
import_node_server_utils245.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
57157
57520
|
});
|
|
57158
57521
|
return data;
|
|
57159
57522
|
} catch (error) {
|
|
@@ -57161,43 +57524,74 @@ function useFormEntryRepo() {
|
|
|
57161
57524
|
}
|
|
57162
57525
|
}
|
|
57163
57526
|
async function getFormEntryById(_id) {
|
|
57164
|
-
const cacheKey = (0,
|
|
57527
|
+
const cacheKey = (0, import_node_server_utils245.makeCacheKey)(online_forms_namespace_collection, { _id });
|
|
57165
57528
|
const cachedData = await getCache(cacheKey);
|
|
57166
57529
|
if (cachedData) {
|
|
57167
|
-
|
|
57530
|
+
import_node_server_utils245.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
57168
57531
|
return cachedData;
|
|
57169
57532
|
}
|
|
57170
57533
|
try {
|
|
57171
|
-
_id = new
|
|
57534
|
+
_id = new import_mongodb142.ObjectId(_id);
|
|
57172
57535
|
} catch (error) {
|
|
57173
|
-
throw new
|
|
57536
|
+
throw new import_node_server_utils245.BadRequestError("Invalid online form ID format.");
|
|
57174
57537
|
}
|
|
57175
57538
|
const query = { _id, status: { $ne: "deleted" } };
|
|
57176
57539
|
try {
|
|
57177
57540
|
const [data] = await collection.aggregate([{ $match: query }]).toArray();
|
|
57178
57541
|
if (!data) {
|
|
57179
|
-
throw new
|
|
57542
|
+
throw new import_node_server_utils245.NotFoundError("Document not found.");
|
|
57180
57543
|
}
|
|
57181
57544
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
57182
|
-
|
|
57545
|
+
import_node_server_utils245.logger.info(`Cache set for key: ${cacheKey}`);
|
|
57183
57546
|
}).catch((err) => {
|
|
57184
|
-
|
|
57547
|
+
import_node_server_utils245.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
57185
57548
|
});
|
|
57186
57549
|
return data;
|
|
57187
57550
|
} catch (error) {
|
|
57188
57551
|
throw error;
|
|
57189
57552
|
}
|
|
57190
57553
|
}
|
|
57554
|
+
async function updateFormEntryById(_id, value) {
|
|
57555
|
+
try {
|
|
57556
|
+
_id = new import_mongodb142.ObjectId(_id);
|
|
57557
|
+
} catch (error) {
|
|
57558
|
+
throw new import_node_server_utils245.BadRequestError("Invalid online form ID format.");
|
|
57559
|
+
}
|
|
57560
|
+
try {
|
|
57561
|
+
const updateValue = {
|
|
57562
|
+
...value,
|
|
57563
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
57564
|
+
};
|
|
57565
|
+
const res = await collection.updateOne({ _id }, { $set: updateValue });
|
|
57566
|
+
if (res.modifiedCount === 0) {
|
|
57567
|
+
throw new import_node_server_utils245.InternalServerError("Unable to update online form.");
|
|
57568
|
+
}
|
|
57569
|
+
delNamespace().then(() => {
|
|
57570
|
+
import_node_server_utils245.logger.info(
|
|
57571
|
+
`Cache cleared for namespace: ${online_forms_namespace_collection}`
|
|
57572
|
+
);
|
|
57573
|
+
}).catch((err) => {
|
|
57574
|
+
import_node_server_utils245.logger.error(
|
|
57575
|
+
`Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
|
|
57576
|
+
err
|
|
57577
|
+
);
|
|
57578
|
+
});
|
|
57579
|
+
return res.modifiedCount;
|
|
57580
|
+
} catch (error) {
|
|
57581
|
+
throw error;
|
|
57582
|
+
}
|
|
57583
|
+
}
|
|
57191
57584
|
return {
|
|
57192
57585
|
add,
|
|
57193
57586
|
getAll,
|
|
57194
57587
|
getFormEntryById,
|
|
57588
|
+
updateFormEntryById,
|
|
57195
57589
|
createTextIndex
|
|
57196
57590
|
};
|
|
57197
57591
|
}
|
|
57198
57592
|
|
|
57199
57593
|
// src/controllers/online-forms-v2.controller.ts
|
|
57200
|
-
var
|
|
57594
|
+
var import_node_server_utils246 = require("@7365admin1/node-server-utils");
|
|
57201
57595
|
var import_joi142 = __toESM(require("joi"));
|
|
57202
57596
|
var import_exceljs3 = __toESM(require("exceljs"));
|
|
57203
57597
|
var import_fs6 = __toESM(require("fs"));
|
|
@@ -57205,7 +57599,8 @@ function useFormEntryController() {
|
|
|
57205
57599
|
const {
|
|
57206
57600
|
add: _add,
|
|
57207
57601
|
getAll: _getAll,
|
|
57208
|
-
getFormEntryById: _getFormEntryById
|
|
57602
|
+
getFormEntryById: _getFormEntryById,
|
|
57603
|
+
updateFormEntryById: _updateFormEntryById
|
|
57209
57604
|
} = useFormEntryRepo();
|
|
57210
57605
|
function toCamelCase(str) {
|
|
57211
57606
|
return str.replace(/\s(.)/g, (_, char) => char.toUpperCase()).replace(/\s+/g, "").replace(/^(.)/, (_, char) => char.toLowerCase());
|
|
@@ -57220,14 +57615,14 @@ function useFormEntryController() {
|
|
|
57220
57615
|
async function uploadFormEntrys(req, res, next) {
|
|
57221
57616
|
try {
|
|
57222
57617
|
if (!req.file) {
|
|
57223
|
-
next(new
|
|
57618
|
+
next(new import_node_server_utils246.BadRequestError("Excel file is required."));
|
|
57224
57619
|
return;
|
|
57225
57620
|
}
|
|
57226
57621
|
const workbook = new import_exceljs3.default.Workbook();
|
|
57227
57622
|
await workbook.xlsx.readFile(req.file.path);
|
|
57228
57623
|
const worksheet = workbook.worksheets[0];
|
|
57229
57624
|
if (!worksheet) {
|
|
57230
|
-
next(new
|
|
57625
|
+
next(new import_node_server_utils246.BadRequestError("No worksheet found in uploaded Excel file."));
|
|
57231
57626
|
return;
|
|
57232
57627
|
}
|
|
57233
57628
|
const headerRow = worksheet.getRow(1);
|
|
@@ -57255,8 +57650,8 @@ function useFormEntryController() {
|
|
|
57255
57650
|
});
|
|
57256
57651
|
if (error) {
|
|
57257
57652
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
57258
|
-
|
|
57259
|
-
next(new
|
|
57653
|
+
import_node_server_utils246.logger.log({ level: "error", message: messages });
|
|
57654
|
+
next(new import_node_server_utils246.BadRequestError(messages));
|
|
57260
57655
|
return;
|
|
57261
57656
|
}
|
|
57262
57657
|
const result = await _add(value);
|
|
@@ -57264,7 +57659,7 @@ function useFormEntryController() {
|
|
|
57264
57659
|
import_fs6.default.unlink(req.file.path, () => {
|
|
57265
57660
|
});
|
|
57266
57661
|
} catch (error) {
|
|
57267
|
-
|
|
57662
|
+
import_node_server_utils246.logger.log({ level: "error", message: error.message });
|
|
57268
57663
|
next(error);
|
|
57269
57664
|
}
|
|
57270
57665
|
}
|
|
@@ -57281,8 +57676,8 @@ function useFormEntryController() {
|
|
|
57281
57676
|
const { error, value } = schema2.validate(req.query);
|
|
57282
57677
|
if (error) {
|
|
57283
57678
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
57284
|
-
|
|
57285
|
-
next(new
|
|
57679
|
+
import_node_server_utils246.logger.log({ level: "error", message: messages });
|
|
57680
|
+
next(new import_node_server_utils246.BadRequestError(messages));
|
|
57286
57681
|
return;
|
|
57287
57682
|
}
|
|
57288
57683
|
const { search, page, limit, status, org, site } = value;
|
|
@@ -57290,7 +57685,7 @@ function useFormEntryController() {
|
|
|
57290
57685
|
res.json(data);
|
|
57291
57686
|
return;
|
|
57292
57687
|
} catch (error) {
|
|
57293
|
-
|
|
57688
|
+
import_node_server_utils246.logger.log({ level: "error", message: error.message });
|
|
57294
57689
|
next(error);
|
|
57295
57690
|
return;
|
|
57296
57691
|
}
|
|
@@ -57303,8 +57698,8 @@ function useFormEntryController() {
|
|
|
57303
57698
|
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
57304
57699
|
if (error) {
|
|
57305
57700
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
57306
|
-
|
|
57307
|
-
next(new
|
|
57701
|
+
import_node_server_utils246.logger.log({ level: "error", message: messages });
|
|
57702
|
+
next(new import_node_server_utils246.BadRequestError(messages));
|
|
57308
57703
|
return;
|
|
57309
57704
|
}
|
|
57310
57705
|
const { _id } = value;
|
|
@@ -57312,7 +57707,29 @@ function useFormEntryController() {
|
|
|
57312
57707
|
res.json(data);
|
|
57313
57708
|
return;
|
|
57314
57709
|
} catch (error) {
|
|
57315
|
-
|
|
57710
|
+
import_node_server_utils246.logger.log({ level: "error", message: error.message });
|
|
57711
|
+
next(error);
|
|
57712
|
+
return;
|
|
57713
|
+
}
|
|
57714
|
+
}
|
|
57715
|
+
async function updateFormEntryById(req, res, next) {
|
|
57716
|
+
try {
|
|
57717
|
+
const { error, value } = schemaUpdateFormEntry.validate({
|
|
57718
|
+
_id: req.params.id,
|
|
57719
|
+
...req.body
|
|
57720
|
+
});
|
|
57721
|
+
if (error) {
|
|
57722
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
57723
|
+
import_node_server_utils246.logger.log({ level: "error", message: messages });
|
|
57724
|
+
next(new import_node_server_utils246.BadRequestError(messages));
|
|
57725
|
+
return;
|
|
57726
|
+
}
|
|
57727
|
+
const { _id, ...rest } = value;
|
|
57728
|
+
await _updateFormEntryById(_id, rest);
|
|
57729
|
+
res.json({ message: "Successfully updated online form." });
|
|
57730
|
+
return;
|
|
57731
|
+
} catch (error) {
|
|
57732
|
+
import_node_server_utils246.logger.log({ level: "error", message: error.message });
|
|
57316
57733
|
next(error);
|
|
57317
57734
|
return;
|
|
57318
57735
|
}
|
|
@@ -57320,16 +57737,17 @@ function useFormEntryController() {
|
|
|
57320
57737
|
return {
|
|
57321
57738
|
uploadFormEntrys,
|
|
57322
57739
|
getAll,
|
|
57323
|
-
getFormEntryById
|
|
57740
|
+
getFormEntryById,
|
|
57741
|
+
updateFormEntryById
|
|
57324
57742
|
};
|
|
57325
57743
|
}
|
|
57326
57744
|
|
|
57327
57745
|
// src/services/building-level.service.ts
|
|
57328
|
-
var
|
|
57746
|
+
var import_node_server_utils247 = require("@7365admin1/node-server-utils");
|
|
57329
57747
|
function useBuildingLevelService() {
|
|
57330
57748
|
const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelRepo();
|
|
57331
57749
|
async function add(value) {
|
|
57332
|
-
const session =
|
|
57750
|
+
const session = import_node_server_utils247.useAtlas.getClient()?.startSession();
|
|
57333
57751
|
try {
|
|
57334
57752
|
session?.startTransaction();
|
|
57335
57753
|
await _add(value, session);
|
|
@@ -57343,7 +57761,7 @@ function useBuildingLevelService() {
|
|
|
57343
57761
|
}
|
|
57344
57762
|
}
|
|
57345
57763
|
async function updateLevelById(_id, value) {
|
|
57346
|
-
const session =
|
|
57764
|
+
const session = import_node_server_utils247.useAtlas.getClient()?.startSession();
|
|
57347
57765
|
try {
|
|
57348
57766
|
session?.startTransaction();
|
|
57349
57767
|
await _updateLevelById(_id, value, session);
|
|
@@ -57363,7 +57781,7 @@ function useBuildingLevelService() {
|
|
|
57363
57781
|
}
|
|
57364
57782
|
|
|
57365
57783
|
// src/controllers/building-level.controller.ts
|
|
57366
|
-
var
|
|
57784
|
+
var import_node_server_utils248 = require("@7365admin1/node-server-utils");
|
|
57367
57785
|
var import_joi143 = __toESM(require("joi"));
|
|
57368
57786
|
function useBuildingLevelController() {
|
|
57369
57787
|
const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelService();
|
|
@@ -57379,8 +57797,8 @@ function useBuildingLevelController() {
|
|
|
57379
57797
|
});
|
|
57380
57798
|
if (error) {
|
|
57381
57799
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
57382
|
-
|
|
57383
|
-
next(new
|
|
57800
|
+
import_node_server_utils248.logger.log({ level: "error", message: messages });
|
|
57801
|
+
next(new import_node_server_utils248.BadRequestError(messages));
|
|
57384
57802
|
return;
|
|
57385
57803
|
}
|
|
57386
57804
|
const result = await _add(value);
|
|
@@ -57403,8 +57821,8 @@ function useBuildingLevelController() {
|
|
|
57403
57821
|
});
|
|
57404
57822
|
if (error) {
|
|
57405
57823
|
const messages = error.details.map((d) => d.message);
|
|
57406
|
-
|
|
57407
|
-
next(new
|
|
57824
|
+
import_node_server_utils248.logger.log({ level: "error", message: messages.join(", ") });
|
|
57825
|
+
next(new import_node_server_utils248.BadRequestError(messages.join(", ")));
|
|
57408
57826
|
return;
|
|
57409
57827
|
}
|
|
57410
57828
|
const { page, limit, status, site, search } = value;
|
|
@@ -57429,8 +57847,8 @@ function useBuildingLevelController() {
|
|
|
57429
57847
|
const { error, value } = schema2.validate({ id: req.params.id });
|
|
57430
57848
|
if (error) {
|
|
57431
57849
|
const messages = error.details.map((d) => d.message);
|
|
57432
|
-
|
|
57433
|
-
next(new
|
|
57850
|
+
import_node_server_utils248.logger.log({ level: "error", message: messages.join(", ") });
|
|
57851
|
+
next(new import_node_server_utils248.BadRequestError(messages.join(", ")));
|
|
57434
57852
|
return;
|
|
57435
57853
|
}
|
|
57436
57854
|
const { id } = value;
|
|
@@ -57449,8 +57867,8 @@ function useBuildingLevelController() {
|
|
|
57449
57867
|
});
|
|
57450
57868
|
if (error) {
|
|
57451
57869
|
const messages = error.details.map((d) => d.message);
|
|
57452
|
-
|
|
57453
|
-
next(new
|
|
57870
|
+
import_node_server_utils248.logger.log({ level: "error", message: messages.join(", ") });
|
|
57871
|
+
next(new import_node_server_utils248.BadRequestError(messages.join(", ")));
|
|
57454
57872
|
return;
|
|
57455
57873
|
}
|
|
57456
57874
|
const { _id, ...rest } = value;
|
|
@@ -57468,8 +57886,8 @@ function useBuildingLevelController() {
|
|
|
57468
57886
|
const { error, value } = schema2.validate({ id: req.params.id });
|
|
57469
57887
|
if (error) {
|
|
57470
57888
|
const messages = error.details.map((d) => d.message);
|
|
57471
|
-
|
|
57472
|
-
next(new
|
|
57889
|
+
import_node_server_utils248.logger.log({ level: "error", message: messages.join(", ") });
|
|
57890
|
+
next(new import_node_server_utils248.BadRequestError(messages.join(", ")));
|
|
57473
57891
|
return;
|
|
57474
57892
|
}
|
|
57475
57893
|
const { id } = value;
|
|
@@ -57685,6 +58103,7 @@ function useBuildingLevelController() {
|
|
|
57685
58103
|
schemaFormEntry,
|
|
57686
58104
|
schemaGuestManagement,
|
|
57687
58105
|
schemaIncidentReport,
|
|
58106
|
+
schemaMultipleDocumentManagement,
|
|
57688
58107
|
schemaNfcPatrolLog,
|
|
57689
58108
|
schemaNfcPatrolRoute,
|
|
57690
58109
|
schemaNfcPatrolTag,
|