@7365admin1/core 3.11.0 → 3.12.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 +2 -0
- package/dist/index.js +261 -130
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +261 -130
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -20867,14 +20867,20 @@ var schemaUpdateVisTrans = Joi37.object({
|
|
|
20867
20867
|
Joi37.object({
|
|
20868
20868
|
keyId: Joi37.string().hex().length(24).required(),
|
|
20869
20869
|
status: Joi37.string().optional().allow(null, ""),
|
|
20870
|
-
remarks: Joi37.string().optional().allow(null, "")
|
|
20870
|
+
remarks: Joi37.string().optional().allow(null, ""),
|
|
20871
|
+
receivedDate: Joi37.string().optional().allow(null, ""),
|
|
20872
|
+
lastUpdate: Joi37.string().optional().allow(null, ""),
|
|
20873
|
+
add: Joi37.boolean().optional().allow(null, "")
|
|
20871
20874
|
})
|
|
20872
20875
|
).optional().allow(null),
|
|
20873
20876
|
passKeys: Joi37.array().items(
|
|
20874
20877
|
Joi37.object({
|
|
20875
20878
|
keyId: Joi37.string().hex().length(24).required(),
|
|
20876
20879
|
status: Joi37.string().optional().allow(null, ""),
|
|
20877
|
-
remarks: Joi37.string().optional().allow(null, "")
|
|
20880
|
+
remarks: Joi37.string().optional().allow(null, ""),
|
|
20881
|
+
receivedDate: Joi37.string().optional().allow(null, ""),
|
|
20882
|
+
lastUpdate: Joi37.string().optional().allow(null, ""),
|
|
20883
|
+
add: Joi37.boolean().optional().allow(null, "")
|
|
20878
20884
|
})
|
|
20879
20885
|
).optional().allow(null),
|
|
20880
20886
|
checkInRemarks: Joi37.string().optional().allow("", null),
|
|
@@ -21056,6 +21062,15 @@ async function convertObjectIdUtil2(id, fieldName) {
|
|
|
21056
21062
|
throw new Error(`Invalid ID conversion to ObjectId of ${fieldName}.`);
|
|
21057
21063
|
}
|
|
21058
21064
|
}
|
|
21065
|
+
function convertObjectIdUtilNonAsync(id, fieldName) {
|
|
21066
|
+
try {
|
|
21067
|
+
if (!id)
|
|
21068
|
+
throw new Error(`Invalid ID conversion to ObjectId of ${fieldName}.`);
|
|
21069
|
+
return new ObjectId40(id);
|
|
21070
|
+
} catch (_) {
|
|
21071
|
+
throw new Error(`Invalid ID conversion to ObjectId of ${fieldName}.`);
|
|
21072
|
+
}
|
|
21073
|
+
}
|
|
21059
21074
|
|
|
21060
21075
|
// src/repositories/visitor-transaction.repo.ts
|
|
21061
21076
|
import moment from "moment-timezone";
|
|
@@ -21249,6 +21264,7 @@ function useVisitorTransactionRepo() {
|
|
|
21249
21264
|
preserveNullAndEmptyArrays: true
|
|
21250
21265
|
}
|
|
21251
21266
|
},
|
|
21267
|
+
// 1. Lookup visitorPass into a temporary field
|
|
21252
21268
|
{
|
|
21253
21269
|
$lookup: {
|
|
21254
21270
|
from: "keys",
|
|
@@ -21260,48 +21276,66 @@ function useVisitorTransactionRepo() {
|
|
|
21260
21276
|
from: "qr-code-templates",
|
|
21261
21277
|
localField: "template",
|
|
21262
21278
|
foreignField: "_id",
|
|
21263
|
-
pipeline: [
|
|
21264
|
-
{
|
|
21265
|
-
$project: {
|
|
21266
|
-
_id: 1,
|
|
21267
|
-
prefixPass: 1,
|
|
21268
|
-
name: 1,
|
|
21269
|
-
remarks: 1
|
|
21270
|
-
}
|
|
21271
|
-
}
|
|
21272
|
-
],
|
|
21279
|
+
pipeline: [{ $project: { prefixPass: 1, name: 1 } }],
|
|
21273
21280
|
as: "template"
|
|
21274
21281
|
}
|
|
21275
21282
|
},
|
|
21276
21283
|
{
|
|
21277
21284
|
$project: {
|
|
21278
|
-
_id:
|
|
21279
|
-
|
|
21280
|
-
status: 1,
|
|
21281
|
-
description: 1,
|
|
21282
|
-
remarks: {
|
|
21283
|
-
$arrayElemAt: ["$template.remarks", 0]
|
|
21284
|
-
},
|
|
21285
|
-
templatePrefixPass: {
|
|
21286
|
-
$arrayElemAt: ["$template.prefixPass", 0]
|
|
21287
|
-
},
|
|
21285
|
+
_id: 1,
|
|
21286
|
+
// Kept only for matching purposes
|
|
21288
21287
|
prefixAndName: {
|
|
21289
21288
|
$concat: [
|
|
21290
|
-
{
|
|
21291
|
-
$ifNull: [
|
|
21292
|
-
{ $arrayElemAt: ["$template.prefixPass", 0] },
|
|
21293
|
-
""
|
|
21294
|
-
]
|
|
21295
|
-
},
|
|
21289
|
+
{ $ifNull: [{ $arrayElemAt: ["$template.prefixPass", 0] }, ""] },
|
|
21296
21290
|
{ $ifNull: ["$name", ""] }
|
|
21297
21291
|
]
|
|
21298
21292
|
}
|
|
21299
21293
|
}
|
|
21300
21294
|
}
|
|
21301
21295
|
],
|
|
21302
|
-
as: "
|
|
21296
|
+
as: "visitorPass_lookup"
|
|
21297
|
+
}
|
|
21298
|
+
},
|
|
21299
|
+
// 2. Map through original array, keep all fields, and inject prefixAndName
|
|
21300
|
+
{
|
|
21301
|
+
$addFields: {
|
|
21302
|
+
visitorPass: {
|
|
21303
|
+
$map: {
|
|
21304
|
+
input: "$visitorPass",
|
|
21305
|
+
as: "original",
|
|
21306
|
+
in: {
|
|
21307
|
+
// Explicitly retain all original fields from your document
|
|
21308
|
+
keyId: "$$original.keyId",
|
|
21309
|
+
receivedDate: "$$original.receivedDate",
|
|
21310
|
+
status: "$$original.status",
|
|
21311
|
+
lastUpdate: "$$original.lastUpdate",
|
|
21312
|
+
remarks: "$$original.remarks",
|
|
21313
|
+
// Find and extract ONLY the prefixAndName string from lookup
|
|
21314
|
+
prefixAndName: {
|
|
21315
|
+
$let: {
|
|
21316
|
+
vars: {
|
|
21317
|
+
matched: {
|
|
21318
|
+
$arrayElemAt: [
|
|
21319
|
+
{
|
|
21320
|
+
$filter: {
|
|
21321
|
+
input: "$visitorPass_lookup",
|
|
21322
|
+
as: "lookup",
|
|
21323
|
+
cond: { $eq: ["$$lookup._id", "$$original.keyId"] }
|
|
21324
|
+
}
|
|
21325
|
+
},
|
|
21326
|
+
0
|
|
21327
|
+
]
|
|
21328
|
+
}
|
|
21329
|
+
},
|
|
21330
|
+
in: "$$matched.prefixAndName"
|
|
21331
|
+
}
|
|
21332
|
+
}
|
|
21333
|
+
}
|
|
21334
|
+
}
|
|
21335
|
+
}
|
|
21303
21336
|
}
|
|
21304
21337
|
},
|
|
21338
|
+
// 3. Lookup passKeys into a temporary field
|
|
21305
21339
|
{
|
|
21306
21340
|
$lookup: {
|
|
21307
21341
|
from: "keys",
|
|
@@ -21313,46 +21347,69 @@ function useVisitorTransactionRepo() {
|
|
|
21313
21347
|
from: "qr-code-templates",
|
|
21314
21348
|
localField: "template",
|
|
21315
21349
|
foreignField: "_id",
|
|
21316
|
-
pipeline: [
|
|
21317
|
-
{
|
|
21318
|
-
$project: {
|
|
21319
|
-
_id: 1,
|
|
21320
|
-
prefixPass: 1,
|
|
21321
|
-
name: 1,
|
|
21322
|
-
remarks: 1
|
|
21323
|
-
}
|
|
21324
|
-
}
|
|
21325
|
-
],
|
|
21350
|
+
pipeline: [{ $project: { prefixPass: 1, name: 1 } }],
|
|
21326
21351
|
as: "template"
|
|
21327
21352
|
}
|
|
21328
21353
|
},
|
|
21329
21354
|
{
|
|
21330
21355
|
$project: {
|
|
21331
|
-
_id:
|
|
21332
|
-
keyId: "$_id",
|
|
21333
|
-
status: 1,
|
|
21334
|
-
description: 1,
|
|
21335
|
-
remarks: {
|
|
21336
|
-
$arrayElemAt: ["$template.remarks", 0]
|
|
21337
|
-
},
|
|
21338
|
-
templatePrefixPass: {
|
|
21339
|
-
$arrayElemAt: ["$template.prefixPass", 0]
|
|
21340
|
-
},
|
|
21356
|
+
_id: 1,
|
|
21341
21357
|
prefixAndName: {
|
|
21342
21358
|
$concat: [
|
|
21343
|
-
{
|
|
21344
|
-
$ifNull: [
|
|
21345
|
-
{ $arrayElemAt: ["$template.prefixPass", 0] },
|
|
21346
|
-
""
|
|
21347
|
-
]
|
|
21348
|
-
},
|
|
21359
|
+
{ $ifNull: [{ $arrayElemAt: ["$template.prefixPass", 0] }, ""] },
|
|
21349
21360
|
{ $ifNull: ["$name", ""] }
|
|
21350
21361
|
]
|
|
21351
21362
|
}
|
|
21352
21363
|
}
|
|
21353
21364
|
}
|
|
21354
21365
|
],
|
|
21355
|
-
as: "
|
|
21366
|
+
as: "passKeys_lookup"
|
|
21367
|
+
}
|
|
21368
|
+
},
|
|
21369
|
+
// 4. Map through original passKeys array, keep all fields, inject prefixAndName
|
|
21370
|
+
{
|
|
21371
|
+
$addFields: {
|
|
21372
|
+
passKeys: {
|
|
21373
|
+
$map: {
|
|
21374
|
+
input: "$passKeys",
|
|
21375
|
+
as: "original",
|
|
21376
|
+
in: {
|
|
21377
|
+
// Explicitly retain all original fields from your document
|
|
21378
|
+
keyId: "$$original.keyId",
|
|
21379
|
+
receivedDate: "$$original.receivedDate",
|
|
21380
|
+
status: "$$original.status",
|
|
21381
|
+
lastUpdate: "$$original.lastUpdate",
|
|
21382
|
+
remarks: "$$original.remarks",
|
|
21383
|
+
// Find and extract ONLY the prefixAndName string from lookup
|
|
21384
|
+
prefixAndName: {
|
|
21385
|
+
$let: {
|
|
21386
|
+
vars: {
|
|
21387
|
+
matched: {
|
|
21388
|
+
$arrayElemAt: [
|
|
21389
|
+
{
|
|
21390
|
+
$filter: {
|
|
21391
|
+
input: "$passKeys_lookup",
|
|
21392
|
+
as: "lookup",
|
|
21393
|
+
cond: { $eq: ["$$lookup._id", "$$original.keyId"] }
|
|
21394
|
+
}
|
|
21395
|
+
},
|
|
21396
|
+
0
|
|
21397
|
+
]
|
|
21398
|
+
}
|
|
21399
|
+
},
|
|
21400
|
+
in: "$$matched.prefixAndName"
|
|
21401
|
+
}
|
|
21402
|
+
}
|
|
21403
|
+
}
|
|
21404
|
+
}
|
|
21405
|
+
}
|
|
21406
|
+
}
|
|
21407
|
+
},
|
|
21408
|
+
// 5. Cleanup temporary arrays
|
|
21409
|
+
{
|
|
21410
|
+
$project: {
|
|
21411
|
+
visitorPass_lookup: 0,
|
|
21412
|
+
passKeys_lookup: 0
|
|
21356
21413
|
}
|
|
21357
21414
|
},
|
|
21358
21415
|
{
|
|
@@ -21549,6 +21606,7 @@ function useVisitorTransactionRepo() {
|
|
|
21549
21606
|
}
|
|
21550
21607
|
try {
|
|
21551
21608
|
const updateFields = {};
|
|
21609
|
+
const pushFields = {};
|
|
21552
21610
|
const arrayFilters = [];
|
|
21553
21611
|
Object.keys(value).forEach((key) => {
|
|
21554
21612
|
if (key !== "visitorPass" && key !== "passKeys") {
|
|
@@ -21558,34 +21616,63 @@ function useVisitorTransactionRepo() {
|
|
|
21558
21616
|
});
|
|
21559
21617
|
if (Array.isArray(value.visitorPass)) {
|
|
21560
21618
|
value.visitorPass.forEach((item, index) => {
|
|
21561
|
-
|
|
21562
|
-
|
|
21563
|
-
|
|
21564
|
-
|
|
21565
|
-
|
|
21566
|
-
updateFields[`visitorPass.$[${elementKey}].${itemKey}`] = itemValue;
|
|
21619
|
+
if (item.add === true) {
|
|
21620
|
+
const { add: add2, ...cleanItem } = item;
|
|
21621
|
+
cleanItem.keyId = convertObjectIdUtilNonAsync(cleanItem.keyId, "Pass Id");
|
|
21622
|
+
if (!pushFields["visitorPass"]) {
|
|
21623
|
+
pushFields["visitorPass"] = { $each: [] };
|
|
21567
21624
|
}
|
|
21568
|
-
|
|
21569
|
-
|
|
21625
|
+
pushFields["visitorPass"].$each.push(cleanItem);
|
|
21626
|
+
} else {
|
|
21627
|
+
const elementKey = `vElem${index}`;
|
|
21628
|
+
Object.keys(item).forEach((itemKey) => {
|
|
21629
|
+
if (itemKey !== "keyId") {
|
|
21630
|
+
const typedItemKey = itemKey;
|
|
21631
|
+
let itemValue = item[typedItemKey];
|
|
21632
|
+
updateFields[`visitorPass.$[${elementKey}].${itemKey}`] = itemValue;
|
|
21633
|
+
}
|
|
21634
|
+
});
|
|
21635
|
+
arrayFilters.push({ [`${elementKey}.keyId`]: new ObjectId41(item.keyId) });
|
|
21636
|
+
}
|
|
21570
21637
|
});
|
|
21571
21638
|
}
|
|
21572
21639
|
if (Array.isArray(value.passKeys)) {
|
|
21573
21640
|
value.passKeys.forEach((item, index) => {
|
|
21574
|
-
|
|
21575
|
-
|
|
21576
|
-
|
|
21577
|
-
|
|
21578
|
-
|
|
21579
|
-
updateFields[`passKeys.$[${elementKey}].${itemKey}`] = itemValue;
|
|
21641
|
+
if (item.add === true) {
|
|
21642
|
+
const { add: add2, ...cleanItem } = item;
|
|
21643
|
+
cleanItem.keyId = convertObjectIdUtilNonAsync(cleanItem.keyId, "Key Id");
|
|
21644
|
+
if (!pushFields["passKeys"]) {
|
|
21645
|
+
pushFields["passKeys"] = { $each: [] };
|
|
21580
21646
|
}
|
|
21581
|
-
|
|
21582
|
-
|
|
21647
|
+
pushFields["passKeys"].$each.push(cleanItem);
|
|
21648
|
+
} else {
|
|
21649
|
+
const elementKey = `pElem${index}`;
|
|
21650
|
+
Object.keys(item).forEach((itemKey) => {
|
|
21651
|
+
if (itemKey !== "keyId") {
|
|
21652
|
+
const typedItemKey = itemKey;
|
|
21653
|
+
let itemValue = item[typedItemKey];
|
|
21654
|
+
updateFields[`passKeys.$[${elementKey}].${itemKey}`] = itemValue;
|
|
21655
|
+
}
|
|
21656
|
+
});
|
|
21657
|
+
arrayFilters.push({ [`${elementKey}.keyId`]: new ObjectId41(item.keyId) });
|
|
21658
|
+
}
|
|
21583
21659
|
});
|
|
21584
21660
|
}
|
|
21661
|
+
const updatePayload = {};
|
|
21662
|
+
if (Object.keys(updateFields).length > 0) {
|
|
21663
|
+
updatePayload.$set = updateFields;
|
|
21664
|
+
}
|
|
21665
|
+
if (Object.keys(pushFields).length > 0) {
|
|
21666
|
+
updatePayload.$push = pushFields;
|
|
21667
|
+
}
|
|
21585
21668
|
const result = await collection.updateOne(
|
|
21586
21669
|
{ _id: new ObjectId41(_id) },
|
|
21587
|
-
|
|
21588
|
-
{
|
|
21670
|
+
updatePayload,
|
|
21671
|
+
{
|
|
21672
|
+
...arrayFilters.length > 0 && { arrayFilters },
|
|
21673
|
+
// Only pass if not empty
|
|
21674
|
+
session
|
|
21675
|
+
}
|
|
21589
21676
|
);
|
|
21590
21677
|
return result;
|
|
21591
21678
|
} catch (error) {
|
|
@@ -34004,43 +34091,45 @@ function useVisitorTransactionService() {
|
|
|
34004
34091
|
throw new BadRequestError100("This plate number is blocklisted");
|
|
34005
34092
|
}
|
|
34006
34093
|
await KeyRepo.checkPassKeyAvailability(value.visitorPass, value.passKeys);
|
|
34094
|
+
if (Array.isArray(value.visitorPass)) {
|
|
34095
|
+
for (const item of value.visitorPass) {
|
|
34096
|
+
item.receivedDate = /* @__PURE__ */ new Date();
|
|
34097
|
+
item.status = "Not Returned" /* NOT_RETURNED */;
|
|
34098
|
+
item.lastUpdate = null;
|
|
34099
|
+
item.remarks = "";
|
|
34100
|
+
}
|
|
34101
|
+
}
|
|
34102
|
+
if (Array.isArray(value.passKeys)) {
|
|
34103
|
+
for (const item of value.passKeys) {
|
|
34104
|
+
item.receivedDate = /* @__PURE__ */ new Date();
|
|
34105
|
+
item.status = "Not Returned" /* NOT_RETURNED */;
|
|
34106
|
+
item.lastUpdate = null;
|
|
34107
|
+
item.remarks = "";
|
|
34108
|
+
}
|
|
34109
|
+
}
|
|
34007
34110
|
const result = await _add(value, session);
|
|
34008
34111
|
if (Array.isArray(value.visitorPass)) {
|
|
34009
34112
|
for (const item of value.visitorPass) {
|
|
34010
34113
|
await KeyRepo.updateKeyById(
|
|
34011
34114
|
item.keyId,
|
|
34012
|
-
{
|
|
34013
|
-
status: "In Use" /* IN_USE */,
|
|
34014
|
-
updatedBy: value.createdBy
|
|
34015
|
-
},
|
|
34115
|
+
{ status: "In Use" /* IN_USE */, updatedBy: value.createdBy },
|
|
34016
34116
|
value.site,
|
|
34017
34117
|
session,
|
|
34018
34118
|
void 0,
|
|
34019
34119
|
result
|
|
34020
34120
|
);
|
|
34021
|
-
item.receivedDate = /* @__PURE__ */ new Date();
|
|
34022
|
-
item.status = "Not Returned" /* NOT_RETURNED */;
|
|
34023
|
-
item.lastUpdate = null;
|
|
34024
|
-
item.remarks = "";
|
|
34025
34121
|
}
|
|
34026
34122
|
}
|
|
34027
34123
|
if (Array.isArray(value.passKeys)) {
|
|
34028
34124
|
for (const item of value.passKeys) {
|
|
34029
34125
|
await KeyRepo.updateKeyById(
|
|
34030
34126
|
item.keyId,
|
|
34031
|
-
{
|
|
34032
|
-
status: "In Use" /* IN_USE */,
|
|
34033
|
-
updatedBy: value.createdBy
|
|
34034
|
-
},
|
|
34127
|
+
{ status: "In Use" /* IN_USE */, updatedBy: value.createdBy },
|
|
34035
34128
|
value.site,
|
|
34036
34129
|
session,
|
|
34037
34130
|
void 0,
|
|
34038
34131
|
result
|
|
34039
34132
|
);
|
|
34040
|
-
item.receivedDate = /* @__PURE__ */ new Date();
|
|
34041
|
-
item.status = "Not Returned" /* NOT_RETURNED */;
|
|
34042
|
-
item.lastUpdate = null;
|
|
34043
|
-
item.remarks = "";
|
|
34044
34133
|
}
|
|
34045
34134
|
}
|
|
34046
34135
|
await session?.commitTransaction();
|
|
@@ -34137,54 +34226,96 @@ function useVisitorTransactionService() {
|
|
|
34137
34226
|
}
|
|
34138
34227
|
if (Array.isArray(value.visitorPass)) {
|
|
34139
34228
|
for (const item of value.visitorPass) {
|
|
34140
|
-
|
|
34141
|
-
|
|
34142
|
-
|
|
34143
|
-
|
|
34144
|
-
|
|
34145
|
-
|
|
34146
|
-
|
|
34229
|
+
if (item.add) {
|
|
34230
|
+
await KeyRepo.updateKeyById(
|
|
34231
|
+
item.keyId,
|
|
34232
|
+
{
|
|
34233
|
+
status: "In Use" /* IN_USE */,
|
|
34234
|
+
updatedBy: value.updatedBy
|
|
34235
|
+
},
|
|
34236
|
+
value.site,
|
|
34237
|
+
session,
|
|
34238
|
+
void 0,
|
|
34239
|
+
id
|
|
34240
|
+
);
|
|
34241
|
+
item.receivedDate = /* @__PURE__ */ new Date();
|
|
34242
|
+
item.status = "Not Returned" /* NOT_RETURNED */;
|
|
34243
|
+
item.lastUpdate = null;
|
|
34244
|
+
item.remarks = "";
|
|
34147
34245
|
} else {
|
|
34148
|
-
|
|
34246
|
+
let status = "Invalid";
|
|
34247
|
+
if (item?.status == "Returned" /* RETURNED */) {
|
|
34248
|
+
status = "Available" /* AVAILABLE */;
|
|
34249
|
+
} else if (item?.status == "Removed" /* REMOVED */) {
|
|
34250
|
+
status = "Available" /* AVAILABLE */;
|
|
34251
|
+
} else if (item?.status == "Not Returned" /* NOT_RETURNED */) {
|
|
34252
|
+
status = "In Use" /* IN_USE */;
|
|
34253
|
+
} else if (item?.status && VALID_STATUSES.has(item.status)) {
|
|
34254
|
+
status = item.status;
|
|
34255
|
+
} else {
|
|
34256
|
+
throw new Error("Invalid Visitor Pass Status");
|
|
34257
|
+
}
|
|
34258
|
+
await KeyRepo.updateKeyById(
|
|
34259
|
+
item.keyId,
|
|
34260
|
+
{
|
|
34261
|
+
status,
|
|
34262
|
+
updatedBy: value.updatedBy
|
|
34263
|
+
},
|
|
34264
|
+
value.site,
|
|
34265
|
+
session,
|
|
34266
|
+
void 0,
|
|
34267
|
+
id
|
|
34268
|
+
);
|
|
34269
|
+
delete item.receivedDate;
|
|
34270
|
+
item.lastUpdate = /* @__PURE__ */ new Date();
|
|
34149
34271
|
}
|
|
34150
|
-
await KeyRepo.updateKeyById(
|
|
34151
|
-
item.keyId,
|
|
34152
|
-
{
|
|
34153
|
-
status,
|
|
34154
|
-
updatedBy: value.updatedBy
|
|
34155
|
-
},
|
|
34156
|
-
value.site,
|
|
34157
|
-
session,
|
|
34158
|
-
void 0,
|
|
34159
|
-
id
|
|
34160
|
-
);
|
|
34161
|
-
item.lastUpdate = /* @__PURE__ */ new Date();
|
|
34162
34272
|
}
|
|
34163
34273
|
}
|
|
34164
34274
|
if (Array.isArray(value.passKeys)) {
|
|
34165
34275
|
for (const item of value.passKeys) {
|
|
34166
|
-
|
|
34167
|
-
|
|
34168
|
-
|
|
34169
|
-
|
|
34170
|
-
|
|
34171
|
-
|
|
34172
|
-
|
|
34276
|
+
if (item.add) {
|
|
34277
|
+
await KeyRepo.updateKeyById(
|
|
34278
|
+
item.keyId,
|
|
34279
|
+
{
|
|
34280
|
+
status: "In Use" /* IN_USE */,
|
|
34281
|
+
updatedBy: value.updatedBy
|
|
34282
|
+
},
|
|
34283
|
+
value.site,
|
|
34284
|
+
session,
|
|
34285
|
+
void 0,
|
|
34286
|
+
id
|
|
34287
|
+
);
|
|
34288
|
+
item.receivedDate = /* @__PURE__ */ new Date();
|
|
34289
|
+
item.status = "Not Returned" /* NOT_RETURNED */;
|
|
34290
|
+
item.lastUpdate = null;
|
|
34291
|
+
item.remarks = "";
|
|
34173
34292
|
} else {
|
|
34174
|
-
|
|
34293
|
+
let status = "Invalid";
|
|
34294
|
+
if (item?.status == "Returned" /* RETURNED */) {
|
|
34295
|
+
status = "Available" /* AVAILABLE */;
|
|
34296
|
+
} else if (item?.status == "Removed" /* REMOVED */) {
|
|
34297
|
+
status = "Available" /* AVAILABLE */;
|
|
34298
|
+
} else if (item?.status == "Not Returned" /* NOT_RETURNED */) {
|
|
34299
|
+
status = "In Use" /* IN_USE */;
|
|
34300
|
+
} else if (item?.status && VALID_STATUSES.has(item.status)) {
|
|
34301
|
+
status = item.status;
|
|
34302
|
+
} else {
|
|
34303
|
+
throw new Error("Invalid Visitor Pass Status");
|
|
34304
|
+
}
|
|
34305
|
+
await KeyRepo.updateKeyById(
|
|
34306
|
+
item.keyId,
|
|
34307
|
+
{
|
|
34308
|
+
status,
|
|
34309
|
+
updatedBy: value.updatedBy
|
|
34310
|
+
},
|
|
34311
|
+
value.site,
|
|
34312
|
+
session,
|
|
34313
|
+
void 0,
|
|
34314
|
+
id
|
|
34315
|
+
);
|
|
34316
|
+
delete item.receivedDate;
|
|
34317
|
+
item.lastUpdate = /* @__PURE__ */ new Date();
|
|
34175
34318
|
}
|
|
34176
|
-
await KeyRepo.updateKeyById(
|
|
34177
|
-
item.keyId,
|
|
34178
|
-
{
|
|
34179
|
-
status,
|
|
34180
|
-
updatedBy: value.updatedBy
|
|
34181
|
-
},
|
|
34182
|
-
value.site,
|
|
34183
|
-
session,
|
|
34184
|
-
void 0,
|
|
34185
|
-
id
|
|
34186
|
-
);
|
|
34187
|
-
item.lastUpdate = /* @__PURE__ */ new Date();
|
|
34188
34319
|
}
|
|
34189
34320
|
}
|
|
34190
34321
|
await _updateVisitorTansactionById(id, value, session);
|