@7365admin1/core 2.9.0 → 2.10.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/dist/index.js CHANGED
@@ -671,7 +671,8 @@ function useFeedbackRepo() {
671
671
  query.$or = [
672
672
  { subject: { $regex: search, $options: "i" } },
673
673
  { description: { $regex: search, $options: "i" } },
674
- { createdByName: { $regex: search, $options: "i" } }
674
+ { createdByName: { $regex: search, $options: "i" } },
675
+ { category: { $regex: search, $options: "i" } }
675
676
  ];
676
677
  cacheOptions.search = search;
677
678
  }
@@ -1283,7 +1284,9 @@ function useWorkOrderRepo() {
1283
1284
  if (search) {
1284
1285
  query.$or = [
1285
1286
  { subject: { $regex: search, $options: "i" } },
1286
- { createdByName: { $regex: search, $options: "i" } }
1287
+ { createdByName: { $regex: search, $options: "i" } },
1288
+ { description: { $regex: search, $options: "i" } },
1289
+ { category: { $regex: search, $options: "i" } }
1287
1290
  ];
1288
1291
  cacheOptions.search = search;
1289
1292
  }
@@ -3473,7 +3476,8 @@ var allowedFieldsSite = [
3473
3476
  "metadata.block",
3474
3477
  "metadata.guardPosts",
3475
3478
  "metadata.gracePeriod",
3476
- "metadata.incidentCounter"
3479
+ "metadata.incidentCounter",
3480
+ "metadata.incidentLogo"
3477
3481
  ];
3478
3482
  var siteSchema = import_joi8.default.object({
3479
3483
  name: import_joi8.default.string().required(),
@@ -10931,7 +10935,8 @@ function useFeedbackController() {
10931
10935
  }
10932
10936
  async function deleteFeedback(req, res, next) {
10933
10937
  const validation = import_joi28.default.string().hex().required();
10934
- const _id = req.params.id;
10938
+ const _id = req.query.id;
10939
+ console.log(_id);
10935
10940
  const { error } = validation.validate(_id);
10936
10941
  if (error) {
10937
10942
  import_node_server_utils55.logger.log({ level: "error", message: error.message });
@@ -11295,7 +11300,8 @@ function useWorkOrderController() {
11295
11300
  }
11296
11301
  async function deleteWorkOrder(req, res, next) {
11297
11302
  const validation = import_joi29.default.string().hex().required();
11298
- const _id = req.params.id;
11303
+ const _id = req.query.id;
11304
+ console.log(_id);
11299
11305
  const { error } = validation.validate(_id);
11300
11306
  if (error) {
11301
11307
  import_node_server_utils57.logger.log({ level: "error", message: error.message });
@@ -12806,7 +12812,7 @@ function useSiteController() {
12806
12812
  const validation = import_joi36.default.object({
12807
12813
  _id: import_joi36.default.string().hex().required(),
12808
12814
  field: import_joi36.default.string().valid(...allowedFieldsSite).required(),
12809
- value: import_joi36.default.number().integer().min(0).required()
12815
+ value: import_joi36.default.alternatives().try(import_joi36.default.number().integer().min(0), import_joi36.default.string().hex().length(24)).required()
12810
12816
  });
12811
12817
  const _id = req.params.id ?? "";
12812
12818
  const field = req.body.field ?? "";
@@ -27056,11 +27062,11 @@ var EAccessCardTypes = /* @__PURE__ */ ((EAccessCardTypes2) => {
27056
27062
  EAccessCardTypes2["QR"] = "QRCODE";
27057
27063
  return EAccessCardTypes2;
27058
27064
  })(EAccessCardTypes || {});
27059
- var EAccessCardUserTypes = /* @__PURE__ */ ((EAccessCardUserTypes2) => {
27060
- EAccessCardUserTypes2["RESIDENT"] = "Resident/Tenant";
27061
- EAccessCardUserTypes2["CONTRACTOR"] = "Contractor";
27062
- EAccessCardUserTypes2["VISITOR"] = "Visitor";
27063
- return EAccessCardUserTypes2;
27065
+ var EAccessCardUserTypes = /* @__PURE__ */ ((EAccessCardUserTypes4) => {
27066
+ EAccessCardUserTypes4["RESIDENT"] = "Resident/Tenant";
27067
+ EAccessCardUserTypes4["CONTRACTOR"] = "Contractor";
27068
+ EAccessCardUserTypes4["VISITOR"] = "Visitor";
27069
+ return EAccessCardUserTypes4;
27064
27070
  })(EAccessCardUserTypes || {});
27065
27071
  var AccessTypeProps = /* @__PURE__ */ ((AccessTypeProps2) => {
27066
27072
  AccessTypeProps2["NORMAL"] = "Normal";
@@ -27122,7 +27128,8 @@ var MAccessCard = class {
27122
27128
  doorName,
27123
27129
  liftName,
27124
27130
  replacementStatus,
27125
- vmsRemarks
27131
+ vmsRemarks,
27132
+ isWinsland = false
27126
27133
  } = {}) {
27127
27134
  this._id = _id;
27128
27135
  this.userId = userId;
@@ -27149,6 +27156,7 @@ var MAccessCard = class {
27149
27156
  this.liftName = liftName;
27150
27157
  this.replacementStatus = replacementStatus;
27151
27158
  this.vmsRemarks = vmsRemarks;
27159
+ this.isWinsland = isWinsland;
27152
27160
  }
27153
27161
  };
27154
27162
 
@@ -27198,6 +27206,15 @@ function UseAccessManagementRepo() {
27198
27206
  return Promise.reject("Failed to create Access cards indexes.");
27199
27207
  }
27200
27208
  }
27209
+ async function createIndexForEntrypass() {
27210
+ try {
27211
+ const entrypass = collectionName("entrypass-settings");
27212
+ await Promise.all([entrypass.createIndex({ site: 1 })]);
27213
+ return Promise.resolve("Access cards indexes created.");
27214
+ } catch (error) {
27215
+ return Promise.reject("Failed to create Access cards indexes.");
27216
+ }
27217
+ }
27201
27218
  async function addPhysicalCardRepo({
27202
27219
  payload
27203
27220
  }) {
@@ -27288,7 +27305,8 @@ function UseAccessManagementRepo() {
27288
27305
  liftName: params.liftName,
27289
27306
  assignedUnit: new import_mongodb83.ObjectId(units[i]),
27290
27307
  createdAt: new Date(params.createdAt),
27291
- updatedAt: new Date(params.updatedAt)
27308
+ updatedAt: new Date(params.updatedAt),
27309
+ isWinsland: params.isWinsland
27292
27310
  });
27293
27311
  try {
27294
27312
  const result = await collection().insertOne(newCard);
@@ -27340,7 +27358,8 @@ function UseAccessManagementRepo() {
27340
27358
  liftName: params.liftName,
27341
27359
  assignedUnit: null,
27342
27360
  createdAt: new Date(params.createdAt),
27343
- updatedAt: new Date(params.updatedAt)
27361
+ updatedAt: new Date(params.updatedAt),
27362
+ isWinsland: params.isWinsland
27344
27363
  });
27345
27364
  try {
27346
27365
  const result = await collection().insertOne(newCard);
@@ -27372,10 +27391,362 @@ function UseAccessManagementRepo() {
27372
27391
  throw new Error(error.message);
27373
27392
  }
27374
27393
  }
27394
+ async function accessManagementSettingsRepo(params) {
27395
+ try {
27396
+ params.site = new import_mongodb83.ObjectId(params.site);
27397
+ const result = collectionName("entrypass-settings").updateOne(
27398
+ { site: params.site },
27399
+ {
27400
+ $set: {
27401
+ ...params,
27402
+ updatedAt: /* @__PURE__ */ new Date()
27403
+ },
27404
+ $setOnInsert: {
27405
+ createdAt: /* @__PURE__ */ new Date()
27406
+ }
27407
+ },
27408
+ { upsert: true }
27409
+ );
27410
+ await createIndexForEntrypass();
27411
+ return result;
27412
+ } catch (error) {
27413
+ throw new Error(error.message);
27414
+ }
27415
+ }
27416
+ async function allAccessCardsCountsRepo(params) {
27417
+ try {
27418
+ const site = new import_mongodb83.ObjectId(params.site);
27419
+ const userType = params.userType;
27420
+ const result = await collection().aggregate([
27421
+ {
27422
+ $match: { site, userType }
27423
+ },
27424
+ {
27425
+ $facet: {
27426
+ available_physical: [{ $match: { assignedUnit: { $eq: null }, type: "NFC" /* NFC */ } }, { $count: "count" }],
27427
+ available_non_physical: [{ $match: { assignedUnit: { $eq: null }, type: "QRCODE" /* QR */ } }, { $count: "count" }],
27428
+ assigned_physical: [{ $match: { assignedUnit: { $ne: null }, type: "NFC" /* NFC */ } }, { $count: "count" }],
27429
+ assigned_non_physical: [{ $match: { assignedUnit: { $ne: null }, type: "QRCODE" /* QR */ } }, { $count: "count" }]
27430
+ }
27431
+ }
27432
+ ]).toArray();
27433
+ const totalCardCount = {
27434
+ available_physical: result[0].available_physical[0] ? result[0].available_physical[0].count : 0,
27435
+ available_non_physical: result[0].available_non_physical[0] ? result[0].available_non_physical[0].count : 0,
27436
+ assigned_physical: result[0].assigned_physical[0] ? result[0].assigned_physical[0].count : 0,
27437
+ assigned_non_physical: result[0].assigned_non_physical[0] ? result[0].assigned_non_physical[0].count : 0
27438
+ };
27439
+ return totalCardCount;
27440
+ } catch (error) {
27441
+ throw new Error(error.message);
27442
+ }
27443
+ }
27444
+ async function availableAccessCardsRepo(params) {
27445
+ try {
27446
+ const site = new import_mongodb83.ObjectId(params.site);
27447
+ const userType = params.userType;
27448
+ const type = params.type;
27449
+ const query = {
27450
+ site: { $in: [site] },
27451
+ userType,
27452
+ assignedUnit: null,
27453
+ type,
27454
+ isActivated: true
27455
+ };
27456
+ const result = await collection().aggregate([
27457
+ {
27458
+ $match: { ...query }
27459
+ },
27460
+ {
27461
+ $project: {
27462
+ accessLevel: 1,
27463
+ liftAccessLevel: 1,
27464
+ doorName: 1,
27465
+ liftName: 1
27466
+ }
27467
+ },
27468
+ {
27469
+ $group: {
27470
+ _id: {
27471
+ accessLevel: "$accessLevel",
27472
+ liftAccessLevel: "$liftAccessLevel",
27473
+ doorName: "$doorName",
27474
+ liftName: "$liftName"
27475
+ },
27476
+ count: { $sum: 1 }
27477
+ }
27478
+ },
27479
+ {
27480
+ $project: {
27481
+ _id: 0,
27482
+ accessLevel: "$_id.accessLevel",
27483
+ liftAccessLevel: "$_id.liftAccessLevel",
27484
+ doorName: "$_id.doorName",
27485
+ liftName: "$_id.liftName",
27486
+ count: 1
27487
+ }
27488
+ }
27489
+ ]).toArray();
27490
+ return result;
27491
+ } catch (error) {
27492
+ throw new Error(error.message);
27493
+ }
27494
+ }
27495
+ function buildSearchQuery(search) {
27496
+ if (!search) {
27497
+ return {};
27498
+ }
27499
+ const terms = search.split("/").map((s) => s.trim()).filter(Boolean);
27500
+ if (search.includes("/") && terms.length <= 3) {
27501
+ switch (terms.length) {
27502
+ case 3:
27503
+ return {
27504
+ $and: [
27505
+ { $expr: { $eq: [{ $toLower: "$name" }, terms[0].toLowerCase()] } },
27506
+ { $expr: { $eq: [{ $toLower: "$level.level" }, terms[1].toLowerCase()] } },
27507
+ { $expr: { $eq: [{ $toLower: "$level.units.name" }, terms[2].toLowerCase()] } }
27508
+ ]
27509
+ };
27510
+ case 2:
27511
+ return {
27512
+ $and: [
27513
+ { $expr: { $eq: [{ $toLower: "$name" }, terms[0].toLowerCase()] } },
27514
+ { $expr: { $eq: [{ $toLower: "$level.level" }, terms[1].toLowerCase()] } }
27515
+ ]
27516
+ };
27517
+ default:
27518
+ return {
27519
+ $expr: { $eq: [{ $toLower: "$name" }, terms[0].toLowerCase()] }
27520
+ };
27521
+ }
27522
+ }
27523
+ return {
27524
+ $or: [
27525
+ { name: { $regex: search.trim(), $options: "i" } },
27526
+ { "level.level": { $regex: search.trim(), $options: "i" } },
27527
+ { "level.units.name": { $regex: search.trim(), $options: "i" } }
27528
+ ]
27529
+ };
27530
+ }
27531
+ async function userTypeAccessCardsRepo(params) {
27532
+ try {
27533
+ const site = new import_mongodb83.ObjectId(params.site);
27534
+ const userType = params.userType;
27535
+ const page = params.page ? Number(params.page) - 1 : 0;
27536
+ const limit = Number(params.limit) || 10;
27537
+ const search = params.search;
27538
+ const defaultQuery = {
27539
+ site
27540
+ };
27541
+ const searchQuery = buildSearchQuery(search);
27542
+ const result = await collectionName("buildings").aggregate([
27543
+ // ✅ Match early with index-friendly query
27544
+ {
27545
+ $match: {
27546
+ ...defaultQuery,
27547
+ status: { $ne: "deleted" }
27548
+ }
27549
+ },
27550
+ // ✅ Only project needed fields before heavy lookups
27551
+ {
27552
+ $project: {
27553
+ _id: 1,
27554
+ name: 1,
27555
+ site: 1
27556
+ }
27557
+ },
27558
+ // ✅ Use localField/foreignField for better index usage
27559
+ {
27560
+ $lookup: {
27561
+ from: "building-levels",
27562
+ localField: "_id",
27563
+ foreignField: "block",
27564
+ pipeline: [
27565
+ { $match: { status: { $ne: "deleted" } } },
27566
+ {
27567
+ $lookup: {
27568
+ from: "building-units",
27569
+ localField: "_id",
27570
+ foreignField: "level",
27571
+ pipeline: [
27572
+ { $match: { status: { $ne: "deleted" } } },
27573
+ { $project: { _id: 1, name: 1 } }
27574
+ ],
27575
+ as: "units"
27576
+ }
27577
+ },
27578
+ {
27579
+ $match: { "units.0": { $exists: true } }
27580
+ },
27581
+ {
27582
+ $project: {
27583
+ _id: 1,
27584
+ level: 1,
27585
+ units: 1
27586
+ }
27587
+ }
27588
+ ],
27589
+ as: "level"
27590
+ }
27591
+ },
27592
+ // ✅ Filter out buildings with no levels early
27593
+ {
27594
+ $match: { "level.0": { $exists: true } }
27595
+ },
27596
+ // ✅ Unwind to flatten the hierarchy
27597
+ {
27598
+ $unwind: {
27599
+ path: "$level",
27600
+ preserveNullAndEmptyArrays: false
27601
+ }
27602
+ },
27603
+ {
27604
+ $unwind: {
27605
+ path: "$level.units",
27606
+ preserveNullAndEmptyArrays: false
27607
+ }
27608
+ },
27609
+ // Groups by unit _id and keeps only the first occurrence
27610
+ {
27611
+ $group: {
27612
+ _id: "$level.units._id",
27613
+ doc: { $first: "$$ROOT" }
27614
+ }
27615
+ },
27616
+ {
27617
+ $replaceRoot: { newRoot: "$doc" }
27618
+ },
27619
+ // ✅ Apply search filter
27620
+ {
27621
+ $match: {
27622
+ ...searchQuery
27623
+ }
27624
+ },
27625
+ {
27626
+ $facet: {
27627
+ totalCount: [{ $count: "count" }],
27628
+ items: [
27629
+ // ✅ Sort BEFORE skip/limit for correct pagination
27630
+ { $sort: { _id: -1 } },
27631
+ { $skip: page * limit },
27632
+ { $limit: limit },
27633
+ // ✅ Users lookup - optimized with index hint
27634
+ {
27635
+ $lookup: {
27636
+ from: "users",
27637
+ let: { unit: "$level.units._id" },
27638
+ pipeline: [
27639
+ {
27640
+ $match: {
27641
+ $expr: { $eq: ["$unitNumber", "$$unit"] },
27642
+ residentType: "House/Unit Owner"
27643
+ }
27644
+ },
27645
+ { $limit: 1 },
27646
+ { $project: { _id: 1, givenName: 1, surname: 1 } }
27647
+ ],
27648
+ as: "unitOwner"
27649
+ }
27650
+ },
27651
+ // ✅ Access card lookup - optimized query
27652
+ {
27653
+ $lookup: {
27654
+ from: "access-cards",
27655
+ let: { unit: "$level.units._id" },
27656
+ pipeline: [
27657
+ {
27658
+ $match: {
27659
+ $expr: {
27660
+ $in: [
27661
+ "$$unit",
27662
+ { $cond: [{ $isArray: "$assignedUnit" }, "$assignedUnit", ["$assignedUnit"]] }
27663
+ ]
27664
+ },
27665
+ userType
27666
+ }
27667
+ },
27668
+ { $project: { _id: 1, userId: 1, type: 1, cardNo: 1, isActivated: 1 } }
27669
+ ],
27670
+ as: "accessCards"
27671
+ }
27672
+ },
27673
+ // ✅ Compute all card categorization and counts in ONE stage
27674
+ {
27675
+ $addFields: {
27676
+ f_Available: {
27677
+ $filter: {
27678
+ input: "$accessCards",
27679
+ as: "card",
27680
+ cond: { $and: [{ $eq: ["$$card.userId", null] }, { $eq: ["$$card.isActivated", true] }] }
27681
+ }
27682
+ },
27683
+ f_Assigned: {
27684
+ $filter: {
27685
+ input: "$accessCards",
27686
+ as: "card",
27687
+ cond: { $ne: ["$$card.userId", null] }
27688
+ }
27689
+ }
27690
+ }
27691
+ },
27692
+ // ✅ Final projection with all computed fields
27693
+ {
27694
+ $project: {
27695
+ _id: "$level.units._id",
27696
+ name: "$level.units.name",
27697
+ level: { _id: "$level._id", level: "$level.level" },
27698
+ block: { _id: "$_id", name: "$name" },
27699
+ site: "$site",
27700
+ unit_owner: { $arrayElemAt: ["$unitOwner", 0] },
27701
+ available: {
27702
+ physical: { $filter: { input: "$f_Available", as: "c", cond: { $eq: ["$$c.type", "NFC" /* NFC */] } } },
27703
+ non_physical: { $filter: { input: "$f_Available", as: "c", cond: { $eq: ["$$c.type", "QRCODE" /* QR */] } } }
27704
+ },
27705
+ assigned: {
27706
+ physical: { $filter: { input: "$f_Assigned", as: "c", cond: { $eq: ["$$c.type", "NFC" /* NFC */] } } },
27707
+ non_physical: { $filter: { input: "$f_Assigned", as: "c", cond: { $eq: ["$$c.type", "QRCODE" /* QR */] } } }
27708
+ },
27709
+ cardCounts: {
27710
+ available: {
27711
+ physical: { $size: { $filter: { input: { $ifNull: ["$f_Available", []] }, as: "c", cond: { $eq: ["$$c.type", "NFC" /* NFC */] } } } },
27712
+ non_physical: { $size: { $filter: { input: { $ifNull: ["$f_Available", []] }, as: "c", cond: { $eq: ["$$c.type", "QRCODE" /* QR */] } } } }
27713
+ },
27714
+ assigned: {
27715
+ physical: { $size: { $filter: { input: { $ifNull: ["$f_Assigned", []] }, as: "c", cond: { $eq: ["$$c.type", "NFC" /* NFC */] } } } },
27716
+ non_physical: { $size: { $filter: { input: { $ifNull: ["$f_Assigned", []] }, as: "c", cond: { $eq: ["$$c.type", "QRCODE" /* QR */] } } } }
27717
+ }
27718
+ },
27719
+ totalCardCount: {
27720
+ $add: [
27721
+ { $size: { $filter: { input: { $ifNull: ["$f_Available", []] }, as: "c", cond: { $eq: ["$$c.type", "NFC" /* NFC */] } } } },
27722
+ { $size: { $filter: { input: { $ifNull: ["$f_Available", []] }, as: "c", cond: { $eq: ["$$c.type", "QRCODE" /* QR */] } } } },
27723
+ { $size: { $filter: { input: { $ifNull: ["$f_Assigned", []] }, as: "c", cond: { $eq: ["$$c.type", "NFC" /* NFC */] } } } },
27724
+ { $size: { $filter: { input: { $ifNull: ["$f_Assigned", []] }, as: "c", cond: { $eq: ["$$c.type", "QRCODE" /* QR */] } } } }
27725
+ ]
27726
+ }
27727
+ }
27728
+ }
27729
+ ]
27730
+ }
27731
+ }
27732
+ ], { allowDiskUse: true }).toArray();
27733
+ const totalCount = result[0]?.totalCount?.[0]?.count ?? 0;
27734
+ const items = result[0]?.items ?? [];
27735
+ const paginatedResult = (0, import_node_server_utils149.paginate)(items, page, limit, totalCount);
27736
+ return paginatedResult;
27737
+ } catch (error) {
27738
+ throw new Error(error.message);
27739
+ }
27740
+ }
27375
27741
  return {
27376
27742
  createIndexes,
27743
+ createIndexForEntrypass,
27377
27744
  addPhysicalCardRepo,
27378
- addNonPhysicalCardRepo
27745
+ addNonPhysicalCardRepo,
27746
+ accessManagementSettingsRepo,
27747
+ allAccessCardsCountsRepo,
27748
+ availableAccessCardsRepo,
27749
+ userTypeAccessCardsRepo
27379
27750
  };
27380
27751
  }
27381
27752
 
@@ -27481,7 +27852,14 @@ var formatAccessGroup = (data, search) => {
27481
27852
  // src/services/access-management.service.ts
27482
27853
  var import_xml2js = require("xml2js");
27483
27854
  function useAccessManagementSvc() {
27484
- const { addPhysicalCardRepo, addNonPhysicalCardRepo } = UseAccessManagementRepo();
27855
+ const {
27856
+ addPhysicalCardRepo,
27857
+ addNonPhysicalCardRepo,
27858
+ accessManagementSettingsRepo,
27859
+ allAccessCardsCountsRepo,
27860
+ availableAccessCardsRepo,
27861
+ userTypeAccessCardsRepo
27862
+ } = UseAccessManagementRepo();
27485
27863
  const addPhysicalCardSvc = async (payload) => {
27486
27864
  try {
27487
27865
  const response = await addPhysicalCardRepo({ payload });
@@ -27528,7 +27906,39 @@ function useAccessManagementSvc() {
27528
27906
  const format = await formatAccessGroup(res);
27529
27907
  return format;
27530
27908
  } catch (err) {
27531
- console.error("Failed to connect:", err);
27909
+ throw new Error(err.message);
27910
+ }
27911
+ };
27912
+ const accessManagementSettingsSvc = async (settings) => {
27913
+ try {
27914
+ const response = await accessManagementSettingsRepo({ ...settings });
27915
+ return response;
27916
+ } catch (err) {
27917
+ throw new Error(err.message);
27918
+ }
27919
+ };
27920
+ const allAccessCardsCountsSvc = async (params) => {
27921
+ try {
27922
+ const response = await allAccessCardsCountsRepo({ ...params });
27923
+ return response;
27924
+ } catch (err) {
27925
+ throw new Error(err.message);
27926
+ }
27927
+ };
27928
+ const availableAccessCardsSvc = async (params) => {
27929
+ try {
27930
+ const response = await availableAccessCardsRepo({ ...params });
27931
+ return response;
27932
+ } catch (err) {
27933
+ throw new Error(err.message);
27934
+ }
27935
+ };
27936
+ const userTypeAccessCardsSvc = async (params) => {
27937
+ try {
27938
+ const response = await userTypeAccessCardsRepo({ ...params });
27939
+ return response;
27940
+ } catch (err) {
27941
+ throw new Error(err.message);
27532
27942
  }
27533
27943
  };
27534
27944
  return {
@@ -27536,7 +27946,11 @@ function useAccessManagementSvc() {
27536
27946
  addNonPhysicalCardSvc,
27537
27947
  doorAccessLevelsSvc,
27538
27948
  liftAccessLevelsSvc,
27539
- accessGroupsSvc
27949
+ accessGroupsSvc,
27950
+ accessManagementSettingsSvc,
27951
+ allAccessCardsCountsSvc,
27952
+ availableAccessCardsSvc,
27953
+ userTypeAccessCardsSvc
27540
27954
  };
27541
27955
  }
27542
27956
 
@@ -27547,7 +27961,11 @@ function useAccessManagementController() {
27547
27961
  addNonPhysicalCardSvc,
27548
27962
  doorAccessLevelsSvc,
27549
27963
  liftAccessLevelsSvc,
27550
- accessGroupsSvc
27964
+ accessGroupsSvc,
27965
+ accessManagementSettingsSvc,
27966
+ allAccessCardsCountsSvc,
27967
+ availableAccessCardsSvc,
27968
+ userTypeAccessCardsSvc
27551
27969
  } = useAccessManagementSvc();
27552
27970
  const addPhysicalCard = async (req, res) => {
27553
27971
  try {
@@ -27607,7 +28025,8 @@ function useAccessManagementController() {
27607
28025
  createdAt,
27608
28026
  updatedAt,
27609
28027
  startDate,
27610
- endDate
28028
+ endDate,
28029
+ isWinsland
27611
28030
  } = req.body;
27612
28031
  const schema2 = import_joi85.default.object({
27613
28032
  site: import_joi85.default.string().hex().required(),
@@ -27623,7 +28042,8 @@ function useAccessManagementController() {
27623
28042
  startDate: import_joi85.default.date().required(),
27624
28043
  endDate: import_joi85.default.date().required(),
27625
28044
  createdAt: import_joi85.default.date().required(),
27626
- updatedAt: import_joi85.default.date().required()
28045
+ updatedAt: import_joi85.default.date().required(),
28046
+ isWinsland: import_joi85.default.boolean().optional().allow(null)
27627
28047
  });
27628
28048
  const { error } = schema2.validate({
27629
28049
  site,
@@ -27639,7 +28059,8 @@ function useAccessManagementController() {
27639
28059
  startDate,
27640
28060
  endDate,
27641
28061
  createdAt,
27642
- updatedAt
28062
+ updatedAt,
28063
+ isWinsland
27643
28064
  });
27644
28065
  if (error) {
27645
28066
  throw new Error(`${error.message}`);
@@ -27658,7 +28079,8 @@ function useAccessManagementController() {
27658
28079
  startDate,
27659
28080
  endDate,
27660
28081
  createdAt,
27661
- updatedAt
28082
+ updatedAt,
28083
+ isWinsland
27662
28084
  });
27663
28085
  return res.status(201).json({
27664
28086
  data: result,
@@ -27716,12 +28138,100 @@ function useAccessManagementController() {
27716
28138
  });
27717
28139
  }
27718
28140
  };
28141
+ const accessManagementSettings = async (req, res) => {
28142
+ try {
28143
+ const settings = req.body;
28144
+ const result = await accessManagementSettingsSvc(settings);
28145
+ return res.status(201).json({ message: "Success", data: result });
28146
+ } catch (error) {
28147
+ return res.status(400).json({
28148
+ data: null,
28149
+ message: error.message
28150
+ });
28151
+ }
28152
+ };
28153
+ const allAccessCardsCounts = async (req, res) => {
28154
+ try {
28155
+ const { site, userType } = req.query;
28156
+ const schema2 = import_joi85.default.object({
28157
+ site: import_joi85.default.string().hex().required(),
28158
+ userType: import_joi85.default.string().required()
28159
+ });
28160
+ const { error } = schema2.validate({ site, userType });
28161
+ if (error) {
28162
+ throw new Error(`${error.message}`);
28163
+ }
28164
+ const result = await allAccessCardsCountsSvc({ site, userType });
28165
+ return res.status(200).json({ message: "Success", data: result });
28166
+ } catch (error) {
28167
+ return res.status(400).json({
28168
+ data: null,
28169
+ message: error.message
28170
+ });
28171
+ }
28172
+ };
28173
+ const availableAccessCards = async (req, res) => {
28174
+ try {
28175
+ const { site, userType, type } = req.query;
28176
+ const schema2 = import_joi85.default.object({
28177
+ site: import_joi85.default.string().hex().required(),
28178
+ userType: import_joi85.default.string().optional().allow("", null),
28179
+ type: import_joi85.default.string().optional().allow("", null)
28180
+ });
28181
+ const { error } = schema2.validate({ site, userType, type });
28182
+ if (error) {
28183
+ return res.status(400).json({ message: error.message });
28184
+ }
28185
+ const result = await availableAccessCardsSvc({ site, userType, type });
28186
+ return res.status(200).json({ message: "Success", data: result });
28187
+ } catch (error) {
28188
+ return res.status(400).json({
28189
+ data: null,
28190
+ message: error.message
28191
+ });
28192
+ }
28193
+ };
28194
+ const userTypeAccessCards = async (req, res) => {
28195
+ try {
28196
+ const {
28197
+ page = 1,
28198
+ limit = 10,
28199
+ search = "",
28200
+ site,
28201
+ organization,
28202
+ userType
28203
+ } = req.query;
28204
+ const schema2 = import_joi85.default.object({
28205
+ page: import_joi85.default.number().required(),
28206
+ limit: import_joi85.default.number().optional().default(10),
28207
+ site: import_joi85.default.string().hex().required(),
28208
+ organization: import_joi85.default.string().hex().optional().allow("", null),
28209
+ search: import_joi85.default.string().optional().allow("", null),
28210
+ userType: import_joi85.default.string().required()
28211
+ });
28212
+ const { error } = schema2.validate({ page, limit, site, organization, search, userType });
28213
+ if (error) {
28214
+ return res.status(400).json({ message: error.message });
28215
+ }
28216
+ const result = await userTypeAccessCardsSvc({ page, limit, search, site, organization, userType });
28217
+ return res.status(200).json({ message: "Success", data: result });
28218
+ } catch (error) {
28219
+ return res.status(500).json({
28220
+ data: null,
28221
+ message: error.message
28222
+ });
28223
+ }
28224
+ };
27719
28225
  return {
27720
28226
  addPhysicalCard,
27721
28227
  addNonPhysicalCard,
27722
28228
  doorAccessLevels,
27723
28229
  liftAccessLevels,
27724
- accessGroups
28230
+ accessGroups,
28231
+ accessManagementSettings,
28232
+ allAccessCardsCounts,
28233
+ availableAccessCards,
28234
+ userTypeAccessCards
27725
28235
  };
27726
28236
  }
27727
28237
 
@@ -31917,15 +32427,18 @@ function useIncidentReportService() {
31917
32427
  const {
31918
32428
  add: _add,
31919
32429
  updateIncidentReportById: _updateIncidentReportById,
31920
- reviewIncidentReport: _reviewIncidentReport
32430
+ reviewIncidentReport: _reviewIncidentReport,
32431
+ getIncidentReportById: _getIncidentReportById
31921
32432
  } = useIncidentReportRepo();
31922
32433
  const {
31923
32434
  updateSiteIncidentCounter: _updateSiteIncidentCounter,
31924
32435
  getSiteById: _getSiteById
31925
32436
  } = useSiteRepo();
32437
+ const { updateStatusById } = useFileRepo();
31926
32438
  const { getUserById } = useUserRepo();
31927
32439
  const { getById: _getUnitById } = useBuildingUnitRepo();
31928
32440
  const { getById: _getOrganizationById } = useOrgRepo();
32441
+ const { deleteFile } = useFileService();
31929
32442
  async function add(value) {
31930
32443
  const session = import_node_server_utils174.useAtlas.getClient()?.startSession();
31931
32444
  session?.startTransaction();
@@ -31943,6 +32456,19 @@ function useIncidentReportService() {
31943
32456
  );
31944
32457
  }
31945
32458
  }
32459
+ const incidentAttachments = value?.photos ?? [];
32460
+ if (incidentAttachments.length > 0) {
32461
+ for (const attachment of incidentAttachments) {
32462
+ const file = await updateStatusById(
32463
+ attachment,
32464
+ { status: "active" },
32465
+ session
32466
+ );
32467
+ if (!file) {
32468
+ throw new import_node_server_utils174.NotFoundError("File not found.");
32469
+ }
32470
+ }
32471
+ }
31946
32472
  const result = await _add(value, session);
31947
32473
  await session?.commitTransaction();
31948
32474
  return result;
@@ -31957,6 +32483,26 @@ function useIncidentReportService() {
31957
32483
  const session = import_node_server_utils174.useAtlas.getClient()?.startSession();
31958
32484
  session?.startTransaction();
31959
32485
  try {
32486
+ const incidentReport = await _getIncidentReportById(id);
32487
+ const dataAttchments = value?.photos || [];
32488
+ const incidentAttachments = incidentReport?.photos || [];
32489
+ const deletedFiles = [];
32490
+ incidentAttachments.forEach((id2) => {
32491
+ if (!dataAttchments.includes(id2)) {
32492
+ deletedFiles.push(id2);
32493
+ }
32494
+ });
32495
+ if (deletedFiles.length > 0) {
32496
+ await Promise.all(
32497
+ deletedFiles.map(async (id2) => {
32498
+ try {
32499
+ await deleteFile(id2);
32500
+ } catch (error) {
32501
+ throw error;
32502
+ }
32503
+ })
32504
+ );
32505
+ }
31960
32506
  await _updateIncidentReportById(id, value, session);
31961
32507
  await session?.commitTransaction();
31962
32508
  return "Successfully updated incident report.";