@7365admin1/core 3.2.0 → 3.4.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
@@ -6064,6 +6064,7 @@ __export(src_exports, {
6064
6064
  poolDashboardCollection: () => poolDashboardCollection,
6065
6065
  promoCodeSchema: () => promoCodeSchema,
6066
6066
  remarksSchema: () => remarksSchema,
6067
+ residentFormEntry: () => residentFormEntry,
6067
6068
  robotSchema: () => robotSchema,
6068
6069
  schema: () => schema,
6069
6070
  schemaApprovedBy: () => schemaApprovedBy,
@@ -9170,6 +9171,9 @@ function MMember(value) {
9170
9171
  siteId: import_joi7.default.string().hex().optional().allow("", null),
9171
9172
  siteName: import_joi7.default.string().optional().allow("", null),
9172
9173
  status: import_joi7.default.string().optional().allow("", null),
9174
+ onboardingRequired: import_joi7.default.boolean().optional(),
9175
+ onboardingCompleted: import_joi7.default.boolean().optional(),
9176
+ onboardingCompletedAt: import_joi7.default.string().optional().allow("", null),
9173
9177
  createdAt: import_joi7.default.string().optional().allow("", null),
9174
9178
  updatedAt: import_joi7.default.string().optional().allow("", null),
9175
9179
  deletedAt: import_joi7.default.string().optional().allow("", null)
@@ -9217,6 +9221,9 @@ function MMember(value) {
9217
9221
  siteId: value.siteId ?? "",
9218
9222
  siteName: value.siteName ?? "",
9219
9223
  status: value.status || "active",
9224
+ onboardingRequired: value.onboardingRequired ?? false,
9225
+ onboardingCompleted: value.onboardingCompleted ?? !value.onboardingRequired,
9226
+ onboardingCompletedAt: value.onboardingCompletedAt ?? "",
9220
9227
  createdAt: value.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
9221
9228
  updatedAt: "",
9222
9229
  deletedAt: ""
@@ -10067,6 +10074,35 @@ function useMemberRepo() {
10067
10074
  );
10068
10075
  }
10069
10076
  }
10077
+ async function completeOnboardingById(_id, session) {
10078
+ try {
10079
+ _id = new import_mongodb11.ObjectId(_id);
10080
+ } catch {
10081
+ throw new import_node_server_utils12.BadRequestError("Invalid member ID format.");
10082
+ }
10083
+ const result = await collection.updateOne(
10084
+ {
10085
+ _id,
10086
+ onboardingRequired: true,
10087
+ onboardingCompleted: false
10088
+ },
10089
+ {
10090
+ $set: {
10091
+ onboardingCompleted: true,
10092
+ onboardingCompletedAt: (/* @__PURE__ */ new Date()).toISOString(),
10093
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
10094
+ }
10095
+ },
10096
+ { session }
10097
+ );
10098
+ if (!result.matchedCount) {
10099
+ throw new import_node_server_utils12.NotFoundError(
10100
+ "Member not found or onboarding is not required."
10101
+ );
10102
+ }
10103
+ await delNamespace();
10104
+ return "Successfully completed onboarding.";
10105
+ }
10070
10106
  return {
10071
10107
  createIndex,
10072
10108
  createUniqueIndex,
@@ -10088,7 +10124,8 @@ function useMemberRepo() {
10088
10124
  updateRoleById,
10089
10125
  getByRoles,
10090
10126
  updateSiteById,
10091
- getByUserIdTypeOrg
10127
+ getByUserIdTypeOrg,
10128
+ completeOnboardingById
10092
10129
  };
10093
10130
  }
10094
10131
 
@@ -10539,9 +10576,6 @@ var orgSchema = import_joi8.default.object({
10539
10576
  busInst: import_joi8.default.string().optional().allow("", null),
10540
10577
  status: import_joi8.default.string().optional().allow("", null),
10541
10578
  defaultSite: import_joi8.default.string().hex().optional().allow("", null),
10542
- onboardingRequired: import_joi8.default.boolean().optional(),
10543
- onboardingCompleted: import_joi8.default.boolean().optional(),
10544
- onboardingCompletedAt: import_joi8.default.date().optional().allow(null),
10545
10579
  terms: import_joi8.default.string().optional().allow("", null),
10546
10580
  policies: import_joi8.default.string().optional().allow("", null),
10547
10581
  createdAt: import_joi8.default.string().optional().allow("", null),
@@ -10571,9 +10605,6 @@ function MOrg(value) {
10571
10605
  busInst: value.busInst,
10572
10606
  status: value.status || "active",
10573
10607
  defaultSite: value.defaultSite,
10574
- onboardingRequired: value.onboardingRequired || false,
10575
- onboardingCompleted: value.onboardingCompleted || false,
10576
- onboardingCompletedAt: value.onboardingCompletedAt || null,
10577
10608
  terms: value.terms ?? "",
10578
10609
  policies: value.policies ?? "",
10579
10610
  createdAt: value.createdAt || /* @__PURE__ */ new Date(),
@@ -14182,7 +14213,8 @@ function useMemberService() {
14182
14213
  updateRoleById: _updateRoleById,
14183
14214
  getByRoles,
14184
14215
  updateSiteById: _updateSiteById,
14185
- getAllByUserId: _getAllByUserId
14216
+ getAllByUserId: _getAllByUserId,
14217
+ completeOnboardingById: _completeOnboardingById
14186
14218
  } = useMemberRepo();
14187
14219
  const { getById: _getVerificationById, updateStatusById } = useVerificationRepo();
14188
14220
  const { getUserByEmail, updateDefaultOrgByEmail, getUserById } = useUserRepo();
@@ -14253,7 +14285,8 @@ function useMemberService() {
14253
14285
  roleId,
14254
14286
  app,
14255
14287
  siteId,
14256
- siteName
14288
+ siteName,
14289
+ onboardingRequired
14257
14290
  }) {
14258
14291
  const session = import_node_server_utils30.useAtlas.getClient()?.startSession();
14259
14292
  session?.startTransaction();
@@ -14273,7 +14306,10 @@ function useMemberService() {
14273
14306
  role: roleId,
14274
14307
  type: app,
14275
14308
  siteId: siteId ?? "",
14276
- siteName: siteName ?? ""
14309
+ siteName: siteName ?? "",
14310
+ onboardingRequired,
14311
+ onboardingCompleted: false,
14312
+ onboardingCompletedAt: ""
14277
14313
  },
14278
14314
  session
14279
14315
  );
@@ -14343,12 +14379,19 @@ function useMemberService() {
14343
14379
  throw error;
14344
14380
  }
14345
14381
  }
14382
+ async function completeOnboarding(memberId) {
14383
+ await _completeOnboardingById(memberId);
14384
+ return {
14385
+ message: "Member onboarding completed."
14386
+ };
14387
+ }
14346
14388
  return {
14347
14389
  createMember,
14348
14390
  createMemberDirect,
14349
14391
  updateRoleById,
14350
14392
  updateSiteById,
14351
- getAllByUser
14393
+ getAllByUser,
14394
+ completeOnboarding
14352
14395
  };
14353
14396
  }
14354
14397
 
@@ -14364,7 +14407,7 @@ function useMemberController() {
14364
14407
  updateStatusByUserId: _updateStatusByUserId,
14365
14408
  updateSiteById: _updateSiteById
14366
14409
  } = useMemberRepo();
14367
- const { createMember: _createMember, createMemberDirect: _createMemberDirect, updateRoleById: _updateRoleById, getAllByUser: _getAllByUser } = useMemberService();
14410
+ const { createMember: _createMember, createMemberDirect: _createMemberDirect, updateRoleById: _updateRoleById, getAllByUser: _getAllByUser, completeOnboarding: _completeOnboarding } = useMemberService();
14368
14411
  async function createMember(req, res, next) {
14369
14412
  const validation = import_joi15.default.string().hex().required();
14370
14413
  const _id = req.params.id;
@@ -14588,7 +14631,8 @@ function useMemberController() {
14588
14631
  roleId: import_joi15.default.string().hex().required(),
14589
14632
  app: import_joi15.default.string().required(),
14590
14633
  siteId: import_joi15.default.string().hex().optional().allow("", null),
14591
- siteName: import_joi15.default.string().optional().allow("", null)
14634
+ siteName: import_joi15.default.string().optional().allow("", null),
14635
+ onboardingRequired: import_joi15.default.boolean().optional()
14592
14636
  });
14593
14637
  const { error } = validation.validate(req.body);
14594
14638
  if (error) {
@@ -14596,9 +14640,9 @@ function useMemberController() {
14596
14640
  next(new import_node_server_utils31.BadRequestError(error.message));
14597
14641
  return;
14598
14642
  }
14599
- const { userId, orgId, roleId, app, siteId, siteName } = req.body;
14643
+ const { userId, orgId, roleId, app, siteId, siteName, onboardingRequired } = req.body;
14600
14644
  try {
14601
- const data = await _createMemberDirect({ userId, orgId, roleId, app, siteId, siteName });
14645
+ const data = await _createMemberDirect({ userId, orgId, roleId, app, siteId, siteName, onboardingRequired });
14602
14646
  res.status(201).json(data);
14603
14647
  return;
14604
14648
  } catch (error2) {
@@ -14672,6 +14716,23 @@ function useMemberController() {
14672
14716
  return;
14673
14717
  }
14674
14718
  }
14719
+ async function completeOnboarding(req, res, next) {
14720
+ const validation = import_joi15.default.object({
14721
+ id: import_joi15.default.string().hex().required()
14722
+ });
14723
+ const { error } = validation.validate(req.params);
14724
+ if (error) {
14725
+ return next(new import_node_server_utils31.BadRequestError(error.message));
14726
+ }
14727
+ try {
14728
+ const data = await _completeOnboarding(
14729
+ req.params.id
14730
+ );
14731
+ res.json(data);
14732
+ } catch (error2) {
14733
+ next(error2);
14734
+ }
14735
+ }
14675
14736
  return {
14676
14737
  createMember,
14677
14738
  getByUserId,
@@ -14683,7 +14744,8 @@ function useMemberController() {
14683
14744
  updateRoleById,
14684
14745
  createMemberDirect,
14685
14746
  updateSiteById,
14686
- getByUserIdTypeOrg
14747
+ getByUserIdTypeOrg,
14748
+ completeOnboarding
14687
14749
  };
14688
14750
  }
14689
14751
 
@@ -15328,7 +15390,7 @@ function useOrgController() {
15328
15390
  return;
15329
15391
  }
15330
15392
  try {
15331
- const _id = await _add({ ...req.body, onboardingRequired: true, onboardingCompleted: false, onboardingCompletedAt: null });
15393
+ const _id = await _add(req.body);
15332
15394
  const data = await _getById(_id);
15333
15395
  res.status(201).json({
15334
15396
  message: "Successfully created organization.",
@@ -15497,35 +15559,6 @@ function useOrgController() {
15497
15559
  next(error);
15498
15560
  }
15499
15561
  }
15500
- async function completeOnboarding(req, res, next) {
15501
- const validation = import_joi18.default.string().hex().required();
15502
- const id = req.params.id;
15503
- const { error } = validation.validate(id);
15504
- if (error) {
15505
- import_node_server_utils35.logger.log({
15506
- level: "error",
15507
- message: error.message
15508
- });
15509
- next(new import_node_server_utils35.BadRequestError(error.message));
15510
- return;
15511
- }
15512
- try {
15513
- await _completeOnboardingById(id);
15514
- const data = await _getById(id);
15515
- res.json({
15516
- message: "Organization onboarding completed successfully",
15517
- data
15518
- });
15519
- return;
15520
- } catch (error2) {
15521
- import_node_server_utils35.logger.log({
15522
- level: "error",
15523
- message: error2.message
15524
- });
15525
- next(error2);
15526
- return;
15527
- }
15528
- }
15529
15562
  return {
15530
15563
  add,
15531
15564
  addOnboardingOrg,
@@ -15536,8 +15569,7 @@ function useOrgController() {
15536
15569
  getByEmail,
15537
15570
  update,
15538
15571
  getOrgsByEmail,
15539
- getAdminOrgForResident,
15540
- completeOnboarding
15572
+ getAdminOrgForResident
15541
15573
  };
15542
15574
  }
15543
15575
 
@@ -21517,15 +21549,9 @@ function useVisitorTransactionRepo() {
21517
21549
  {
21518
21550
  $lookup: {
21519
21551
  from: "buildings",
21520
- let: { blockId: "$block" },
21521
- pipeline: [
21522
- {
21523
- $match: {
21524
- $expr: { $eq: ["$_id", "$$blockId"] }
21525
- }
21526
- },
21527
- { $project: { _id: 1, name: 1, block: 1 } }
21528
- ],
21552
+ localField: "block",
21553
+ foreignField: "_id",
21554
+ pipeline: [{ $project: { name: 1, block: 1 } }],
21529
21555
  as: "block"
21530
21556
  }
21531
21557
  },
@@ -21533,15 +21559,9 @@ function useVisitorTransactionRepo() {
21533
21559
  {
21534
21560
  $lookup: {
21535
21561
  from: "building-levels",
21536
- let: { levelId: "$level" },
21537
- pipeline: [
21538
- {
21539
- $match: {
21540
- $expr: { $eq: ["$_id", "$$levelId"] }
21541
- }
21542
- },
21543
- { $project: { _id: 1, name: 1 } }
21544
- ],
21562
+ localField: "level",
21563
+ foreignField: "_id",
21564
+ pipeline: [{ $project: { name: 1 } }],
21545
21565
  as: "level"
21546
21566
  }
21547
21567
  },
@@ -21549,15 +21569,9 @@ function useVisitorTransactionRepo() {
21549
21569
  {
21550
21570
  $lookup: {
21551
21571
  from: "building-units",
21552
- let: { unitId: "$unit" },
21553
- pipeline: [
21554
- {
21555
- $match: {
21556
- $expr: { $eq: ["$_id", "$$unitId"] }
21557
- }
21558
- },
21559
- { $project: { _id: 1, name: 1 } }
21560
- ],
21572
+ localField: "unit",
21573
+ foreignField: "_id",
21574
+ pipeline: [{ $project: { name: 1 } }],
21561
21575
  as: "unit"
21562
21576
  }
21563
21577
  },
@@ -21611,15 +21625,9 @@ function useVisitorTransactionRepo() {
21611
21625
  {
21612
21626
  $lookup: {
21613
21627
  from: "buildings",
21614
- let: { blockId: "$block" },
21615
- pipeline: [
21616
- {
21617
- $match: {
21618
- $expr: { $eq: [{ $toString: "$_id" }, "$$blockId"] }
21619
- }
21620
- },
21621
- { $project: { _id: 1, name: 1, block: 1 } }
21622
- ],
21628
+ localField: "block",
21629
+ foreignField: "_id",
21630
+ pipeline: [{ $project: { name: 1, block: 1 } }],
21623
21631
  as: "block"
21624
21632
  }
21625
21633
  },
@@ -21627,15 +21635,9 @@ function useVisitorTransactionRepo() {
21627
21635
  {
21628
21636
  $lookup: {
21629
21637
  from: "building-levels",
21630
- let: { levelId: "$level" },
21631
- pipeline: [
21632
- {
21633
- $match: {
21634
- $expr: { $eq: [{ $toString: "$_id" }, "$$levelId"] }
21635
- }
21636
- },
21637
- { $project: { _id: 1, name: 1 } }
21638
- ],
21638
+ localField: "level",
21639
+ foreignField: "_id",
21640
+ pipeline: [{ $project: { name: 1 } }],
21639
21641
  as: "level"
21640
21642
  }
21641
21643
  },
@@ -21643,15 +21645,9 @@ function useVisitorTransactionRepo() {
21643
21645
  {
21644
21646
  $lookup: {
21645
21647
  from: "building-units",
21646
- let: { unitId: { $toString: "$unit" } },
21647
- pipeline: [
21648
- {
21649
- $match: {
21650
- $expr: { $eq: [{ $toString: "$_id" }, "$$unitId"] }
21651
- }
21652
- },
21653
- { $project: { _id: 1, name: 1 } }
21654
- ],
21648
+ localField: "unit",
21649
+ foreignField: "_id",
21650
+ pipeline: [{ $project: { name: 1 } }],
21655
21651
  as: "unit"
21656
21652
  }
21657
21653
  },
@@ -22311,15 +22307,9 @@ function useVehicleRepo() {
22311
22307
  {
22312
22308
  $lookup: {
22313
22309
  from: "buildings",
22314
- let: { blockId: "$block" },
22315
- pipeline: [
22316
- {
22317
- $match: {
22318
- $expr: { $eq: ["$_id", "$$blockId"] }
22319
- }
22320
- },
22321
- { $project: { _id: 1, name: 1, block: 1 } }
22322
- ],
22310
+ localField: "block",
22311
+ foreignField: "_id",
22312
+ pipeline: [{ $project: { name: 1, block: 1 } }],
22323
22313
  as: "block"
22324
22314
  }
22325
22315
  },
@@ -22327,15 +22317,9 @@ function useVehicleRepo() {
22327
22317
  {
22328
22318
  $lookup: {
22329
22319
  from: "building-levels",
22330
- let: { levelId: "$level" },
22331
- pipeline: [
22332
- {
22333
- $match: {
22334
- $expr: { $eq: ["$_id", "$$levelId"] }
22335
- }
22336
- },
22337
- { $project: { _id: 1, name: 1 } }
22338
- ],
22320
+ localField: "level",
22321
+ foreignField: "_id",
22322
+ pipeline: [{ $project: { name: 1 } }],
22339
22323
  as: "level"
22340
22324
  }
22341
22325
  },
@@ -22343,15 +22327,9 @@ function useVehicleRepo() {
22343
22327
  {
22344
22328
  $lookup: {
22345
22329
  from: "building-units",
22346
- let: { unitId: "$unit" },
22347
- pipeline: [
22348
- {
22349
- $match: {
22350
- $expr: { $eq: ["$_id", "$$unitId"] }
22351
- }
22352
- },
22353
- { $project: { _id: 1, name: 1 } }
22354
- ],
22330
+ localField: "unit",
22331
+ foreignField: "_id",
22332
+ pipeline: [{ $project: { name: 1 } }],
22355
22333
  as: "unit"
22356
22334
  }
22357
22335
  },
@@ -22616,15 +22594,9 @@ function useVehicleRepo() {
22616
22594
  {
22617
22595
  $lookup: {
22618
22596
  from: "buildings",
22619
- let: { blockId: "$block" },
22620
- pipeline: [
22621
- {
22622
- $match: {
22623
- $expr: { $eq: [{ $toString: "$_id" }, "$$blockId"] }
22624
- }
22625
- },
22626
- { $project: { _id: 1, name: 1, block: 1 } }
22627
- ],
22597
+ localField: "block",
22598
+ foreignField: "_id",
22599
+ pipeline: [{ $project: { name: 1, block: 1 } }],
22628
22600
  as: "block"
22629
22601
  }
22630
22602
  },
@@ -22632,15 +22604,9 @@ function useVehicleRepo() {
22632
22604
  {
22633
22605
  $lookup: {
22634
22606
  from: "building-levels",
22635
- let: { levelId: "$level" },
22636
- pipeline: [
22637
- {
22638
- $match: {
22639
- $expr: { $eq: [{ $toString: "$_id" }, "$$levelId"] }
22640
- }
22641
- },
22642
- { $project: { _id: 1, name: 1 } }
22643
- ],
22607
+ localField: "level",
22608
+ foreignField: "_id",
22609
+ pipeline: [{ $project: { name: 1 } }],
22644
22610
  as: "level"
22645
22611
  }
22646
22612
  },
@@ -22648,15 +22614,9 @@ function useVehicleRepo() {
22648
22614
  {
22649
22615
  $lookup: {
22650
22616
  from: "building-units",
22651
- let: { unitId: { $toString: "$unit" } },
22652
- pipeline: [
22653
- {
22654
- $match: {
22655
- $expr: { $eq: [{ $toString: "$_id" }, "$$unitId"] }
22656
- }
22657
- },
22658
- { $project: { _id: 1, name: 1 } }
22659
- ],
22617
+ localField: "unit",
22618
+ foreignField: "_id",
22619
+ pipeline: [{ $project: { name: 1 } }],
22660
22620
  as: "unit"
22661
22621
  }
22662
22622
  },
@@ -24621,15 +24581,9 @@ function usePersonRepo() {
24621
24581
  {
24622
24582
  $lookup: {
24623
24583
  from: "buildings",
24624
- let: { blockId: "$block" },
24625
- pipeline: [
24626
- {
24627
- $match: {
24628
- $expr: { $eq: ["$_id", "$$blockId"] }
24629
- }
24630
- },
24631
- { $project: { _id: 1, name: 1, block: 1 } }
24632
- ],
24584
+ localField: "block",
24585
+ foreignField: "_id",
24586
+ pipeline: [{ $project: { _id: 1, name: 1, block: 1 } }],
24633
24587
  as: "block"
24634
24588
  }
24635
24589
  },
@@ -24637,15 +24591,9 @@ function usePersonRepo() {
24637
24591
  {
24638
24592
  $lookup: {
24639
24593
  from: "building-levels",
24640
- let: { levelId: "$level" },
24641
- pipeline: [
24642
- {
24643
- $match: {
24644
- $expr: { $eq: ["$_id", "$$levelId"] }
24645
- }
24646
- },
24647
- { $project: { _id: 1, name: 1 } }
24648
- ],
24594
+ localField: "level",
24595
+ foreignField: "_id",
24596
+ pipeline: [{ $project: { _id: 1, name: 1 } }],
24649
24597
  as: "level"
24650
24598
  }
24651
24599
  },
@@ -24653,15 +24601,9 @@ function usePersonRepo() {
24653
24601
  {
24654
24602
  $lookup: {
24655
24603
  from: "building-units",
24656
- let: { unitId: { $toString: "$unit" } },
24657
- pipeline: [
24658
- {
24659
- $match: {
24660
- $expr: { $eq: [{ $toString: "$_id" }, "$$unitId"] }
24661
- }
24662
- },
24663
- { $project: { _id: 1, name: 1 } }
24664
- ],
24604
+ localField: "unit",
24605
+ foreignField: "_id",
24606
+ pipeline: [{ $project: { _id: 1, name: 1 } }],
24665
24607
  as: "unit"
24666
24608
  }
24667
24609
  },
@@ -24868,15 +24810,9 @@ function usePersonRepo() {
24868
24810
  {
24869
24811
  $lookup: {
24870
24812
  from: "buildings",
24871
- let: { blockId: "$block" },
24872
- pipeline: [
24873
- {
24874
- $match: {
24875
- $expr: { $eq: ["$_id", "$$blockId"] }
24876
- }
24877
- },
24878
- { $project: { _id: 1, name: 1, block: 1 } }
24879
- ],
24813
+ localField: "block",
24814
+ foreignField: "_id",
24815
+ pipeline: [{ $project: { _id: 1, name: 1, block: 1 } }],
24880
24816
  as: "block"
24881
24817
  }
24882
24818
  },
@@ -24884,15 +24820,9 @@ function usePersonRepo() {
24884
24820
  {
24885
24821
  $lookup: {
24886
24822
  from: "building-levels",
24887
- let: { levelId: "$level" },
24888
- pipeline: [
24889
- {
24890
- $match: {
24891
- $expr: { $eq: ["$_id", "$$levelId"] }
24892
- }
24893
- },
24894
- { $project: { _id: 1, name: 1 } }
24895
- ],
24823
+ localField: "level",
24824
+ foreignField: "_id",
24825
+ pipeline: [{ $project: { _id: 1, name: 1 } }],
24896
24826
  as: "level"
24897
24827
  }
24898
24828
  },
@@ -24900,15 +24830,9 @@ function usePersonRepo() {
24900
24830
  {
24901
24831
  $lookup: {
24902
24832
  from: "building-units",
24903
- let: { unitId: { $toString: "$unit" } },
24904
- pipeline: [
24905
- {
24906
- $match: {
24907
- $expr: { $eq: [{ $toString: "$_id" }, "$$unitId"] }
24908
- }
24909
- },
24910
- { $project: { _id: 1, name: 1 } }
24911
- ],
24833
+ localField: "unit",
24834
+ foreignField: "_id",
24835
+ pipeline: [{ $project: { _id: 1, name: 1 } }],
24912
24836
  as: "unit"
24913
24837
  }
24914
24838
  },
@@ -24958,15 +24882,9 @@ function usePersonRepo() {
24958
24882
  {
24959
24883
  $lookup: {
24960
24884
  from: "buildings",
24961
- let: { blockId: "$block" },
24962
- pipeline: [
24963
- {
24964
- $match: {
24965
- $expr: { $eq: ["$_id", "$$blockId"] }
24966
- }
24967
- },
24968
- { $project: { _id: 1, name: 1, block: 1 } }
24969
- ],
24885
+ localField: "block",
24886
+ foreignField: "_id",
24887
+ pipeline: [{ $project: { _id: 1, name: 1, block: 1 } }],
24970
24888
  as: "block"
24971
24889
  }
24972
24890
  },
@@ -24974,15 +24892,9 @@ function usePersonRepo() {
24974
24892
  {
24975
24893
  $lookup: {
24976
24894
  from: "building-levels",
24977
- let: { levelId: "$level" },
24978
- pipeline: [
24979
- {
24980
- $match: {
24981
- $expr: { $eq: ["$_id", "$$levelId"] }
24982
- }
24983
- },
24984
- { $project: { _id: 1, name: 1 } }
24985
- ],
24895
+ localField: "level",
24896
+ foreignField: "_id",
24897
+ pipeline: [{ $project: { _id: 1, name: 1 } }],
24986
24898
  as: "level"
24987
24899
  }
24988
24900
  },
@@ -24990,15 +24902,9 @@ function usePersonRepo() {
24990
24902
  {
24991
24903
  $lookup: {
24992
24904
  from: "building-units",
24993
- let: { unitId: { $toString: "$unit" } },
24994
- pipeline: [
24995
- {
24996
- $match: {
24997
- $expr: { $eq: [{ $toString: "$_id" }, "$$unitId"] }
24998
- }
24999
- },
25000
- { $project: { _id: 1, name: 1 } }
25001
- ],
24905
+ localField: "unit",
24906
+ foreignField: "_id",
24907
+ pipeline: [{ $project: { _id: 1, name: 1 } }],
25002
24908
  as: "unit"
25003
24909
  }
25004
24910
  },
@@ -35159,10 +35065,37 @@ function usePersonService() {
35159
35065
  session?.endSession();
35160
35066
  }
35161
35067
  }
35068
+ async function suspendResidentById(id) {
35069
+ const session = import_node_server_utils111.useAtlas.getClient()?.startSession();
35070
+ if (!session) {
35071
+ throw new import_node_server_utils111.BadRequestError("Database session not available.");
35072
+ }
35073
+ try {
35074
+ session.startTransaction();
35075
+ const person = await _getByUserId(id.toString());
35076
+ if (!person)
35077
+ throw new import_node_server_utils111.NotFoundError("Person not found.");
35078
+ await _updateById(person._id, { status: "deleted" }, session);
35079
+ if (person.user) {
35080
+ await _updateUserFieldById(
35081
+ { _id: person.user.toString(), field: "status", value: "suspended" },
35082
+ session
35083
+ );
35084
+ }
35085
+ await session.commitTransaction();
35086
+ return "Resident suspended successfully.";
35087
+ } catch (error) {
35088
+ await session.abortTransaction();
35089
+ throw error;
35090
+ } finally {
35091
+ session.endSession();
35092
+ }
35093
+ }
35162
35094
  return {
35163
35095
  add,
35164
35096
  updateById,
35165
- reviewResidentPerson
35097
+ reviewResidentPerson,
35098
+ suspendResidentById
35166
35099
  };
35167
35100
  }
35168
35101
 
@@ -35182,7 +35115,8 @@ function usePersonController() {
35182
35115
  const {
35183
35116
  add: _add,
35184
35117
  updateById: _updateById,
35185
- reviewResidentPerson: _reviewResidentPerson
35118
+ reviewResidentPerson: _reviewResidentPerson,
35119
+ suspendResidentById: _suspendResidentById
35186
35120
  } = usePersonService();
35187
35121
  async function add(req, res, next) {
35188
35122
  const payload = { ...req.body };
@@ -35526,6 +35460,26 @@ function usePersonController() {
35526
35460
  const result = await _reviewResidentPerson(_id, req.body);
35527
35461
  res.status(200).json({ message: result });
35528
35462
  return;
35463
+ } catch (error2) {
35464
+ console.log("error", error2.message);
35465
+ console.log("error", error2);
35466
+ import_node_server_utils112.logger.log({ level: "error", message: error2.message });
35467
+ next(error2);
35468
+ return;
35469
+ }
35470
+ }
35471
+ async function suspendResidentById(req, res, next) {
35472
+ const _id = req.params.id;
35473
+ const { error } = import_joi60.default.string().hex().required().validate(_id);
35474
+ if (error) {
35475
+ import_node_server_utils112.logger.log({ level: "error", message: error.message });
35476
+ next(new import_node_server_utils112.BadRequestError(error.message));
35477
+ return;
35478
+ }
35479
+ try {
35480
+ const result = await _suspendResidentById(_id);
35481
+ res.status(200).json({ message: result });
35482
+ return;
35529
35483
  } catch (error2) {
35530
35484
  import_node_server_utils112.logger.log({ level: "error", message: error2.message });
35531
35485
  next(error2);
@@ -35544,7 +35498,8 @@ function usePersonController() {
35544
35498
  getPeopleByPlateNumber,
35545
35499
  getPeopleByNRIC,
35546
35500
  getPersonByUserId,
35547
- reviewResidentPerson
35501
+ reviewResidentPerson,
35502
+ suspendResidentById
35548
35503
  };
35549
35504
  }
35550
35505
 
@@ -53308,7 +53263,7 @@ function MIncidentReport(value) {
53308
53263
  approvedByName: value.approvedByName ?? "",
53309
53264
  remarks: value.remarks ?? null,
53310
53265
  status: value.status ?? "pending",
53311
- platForm: value.platform ?? "",
53266
+ platform: value.platform ?? "",
53312
53267
  createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
53313
53268
  updatedAt: value.updatedAt,
53314
53269
  deletedAt: value.deletedAt
@@ -65030,6 +64985,26 @@ function MFormEntry(value) {
65030
64985
  deletedAt: value.deletedAt ?? null
65031
64986
  };
65032
64987
  }
64988
+ var residentFormEntry = import_joi144.default.object({
64989
+ _id: import_joi144.default.string().hex().optional().allow("", null),
64990
+ typeOfForm: import_joi144.default.string().optional().allow("", null),
64991
+ unitNumber: import_joi144.default.string().optional().allow(null, ""),
64992
+ fields: import_joi144.default.object().pattern(
64993
+ import_joi144.default.string(),
64994
+ import_joi144.default.alternatives().try(
64995
+ import_joi144.default.string(),
64996
+ import_joi144.default.number(),
64997
+ import_joi144.default.boolean(),
64998
+ import_joi144.default.valid(null)
64999
+ )
65000
+ ).optional().allow(null, ""),
65001
+ status: import_joi144.default.string().optional().allow("", null),
65002
+ org: import_joi144.default.string().hex().optional().allow("", null),
65003
+ site: import_joi144.default.string().hex().optional().allow("", null),
65004
+ createdAt: import_joi144.default.date().optional().allow("", null),
65005
+ updatedAt: import_joi144.default.date().optional().allow("", null),
65006
+ deletedAt: import_joi144.default.date().optional().allow("", null)
65007
+ });
65033
65008
 
65034
65009
  // src/repositories/online-forms-v2.repository.ts
65035
65010
  var import_node_server_utils249 = require("@7365admin1/node-server-utils");
@@ -65106,7 +65081,8 @@ function useFormEntryRepo() {
65106
65081
  };
65107
65082
  if (search && search !== "") {
65108
65083
  query.$or = [
65109
- { formType: { $regex: search, $options: "i" } }
65084
+ { typeOfForm: { $regex: search, $options: "i" } },
65085
+ { unitNumber: { $regex: search, $options: "i" } }
65110
65086
  ];
65111
65087
  }
65112
65088
  const cacheKey = (0, import_node_server_utils249.makeCacheKey)(
@@ -65228,13 +65204,38 @@ function useFormEntryRepo() {
65228
65204
  throw new Error(error.message);
65229
65205
  }
65230
65206
  }
65207
+ async function addResidentForm(value, session) {
65208
+ try {
65209
+ value.site = new import_mongodb146.ObjectId(value.site);
65210
+ value.org = new import_mongodb146.ObjectId(value.org);
65211
+ const res = await collection.insertOne(value, { session });
65212
+ delNamespace().then(() => {
65213
+ import_node_server_utils249.logger.info(
65214
+ `Cache cleared for namespace: ${online_forms_namespace_collection}`
65215
+ );
65216
+ }).catch((err) => {
65217
+ import_node_server_utils249.logger.error(
65218
+ `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
65219
+ err
65220
+ );
65221
+ });
65222
+ return res.insertedId;
65223
+ } catch (error) {
65224
+ const isDuplicated = error.message.includes("duplicate");
65225
+ if (isDuplicated) {
65226
+ throw new import_node_server_utils249.BadRequestError("Online Form already exists.");
65227
+ }
65228
+ throw error;
65229
+ }
65230
+ }
65231
65231
  return {
65232
65232
  add,
65233
65233
  getAll,
65234
65234
  getFormEntryById,
65235
65235
  updateFormEntryById,
65236
65236
  createTextIndex,
65237
- deleteOnlineFormById
65237
+ deleteOnlineFormById,
65238
+ addResidentForm
65238
65239
  };
65239
65240
  }
65240
65241
 
@@ -65249,7 +65250,8 @@ function useFormEntryController() {
65249
65250
  getAll: _getAll,
65250
65251
  getFormEntryById: _getFormEntryById,
65251
65252
  updateFormEntryById: _updateFormEntryById,
65252
- deleteOnlineFormById: _deleteOnlineFormById
65253
+ deleteOnlineFormById: _deleteOnlineFormById,
65254
+ addResidentForm: _addResidentForm
65253
65255
  } = useFormEntryRepo();
65254
65256
  function toCamelCase(str) {
65255
65257
  return str.replace(/\s(.)/g, (_, char) => char.toUpperCase()).replace(/\s+/g, "").replace(/^(.)/, (_, char) => char.toLowerCase());
@@ -65363,7 +65365,7 @@ function useFormEntryController() {
65363
65365
  }
65364
65366
  async function updateFormEntryById(req, res, next) {
65365
65367
  try {
65366
- const { error, value } = schemaUpdateFormEntry.validate({
65368
+ const { error, value } = residentFormEntry.validate({
65367
65369
  _id: req.params.id,
65368
65370
  ...req.body
65369
65371
  });
@@ -65428,13 +65430,35 @@ function useFormEntryController() {
65428
65430
  return;
65429
65431
  }
65430
65432
  }
65433
+ async function residentFormSubmission(req, res, next) {
65434
+ const payload = { ...req.body };
65435
+ const { error } = residentFormEntry.validate(payload, {
65436
+ abortEarly: false
65437
+ });
65438
+ if (error) {
65439
+ const messages = error.details.map((d) => d.message).join(", ");
65440
+ import_node_server_utils250.logger.log({ level: "error", message: messages });
65441
+ next(new import_node_server_utils250.BadRequestError(messages));
65442
+ return;
65443
+ }
65444
+ try {
65445
+ const data = await _addResidentForm(payload);
65446
+ res.status(201).json({ message: data });
65447
+ return;
65448
+ } catch (error2) {
65449
+ import_node_server_utils250.logger.log({ level: "error", message: error2.message });
65450
+ next(error2);
65451
+ return;
65452
+ }
65453
+ }
65431
65454
  return {
65432
65455
  add,
65433
65456
  uploadFormEntrys,
65434
65457
  getAll,
65435
65458
  getFormEntryById,
65436
65459
  updateFormEntryById,
65437
- deleteFormEntryById
65460
+ deleteFormEntryById,
65461
+ residentFormSubmission
65438
65462
  };
65439
65463
  }
65440
65464
 
@@ -65834,6 +65858,7 @@ function useBuildingLevelController() {
65834
65858
  poolDashboardCollection,
65835
65859
  promoCodeSchema,
65836
65860
  remarksSchema,
65861
+ residentFormEntry,
65837
65862
  robotSchema,
65838
65863
  schema,
65839
65864
  schemaApprovedBy,