@7365admin1/core 2.60.0 → 2.62.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.mjs CHANGED
@@ -3060,6 +3060,39 @@ function useMemberRepo() {
3060
3060
  }
3061
3061
  }
3062
3062
  }
3063
+ async function getAllByUserId(user) {
3064
+ try {
3065
+ user = new ObjectId11(user);
3066
+ } catch (error) {
3067
+ throw new BadRequestError11("Invalid user ID format.");
3068
+ }
3069
+ const cacheKey = makeCacheKey6(namespace_collection, {
3070
+ user: user.toString(),
3071
+ type: "all"
3072
+ });
3073
+ const cachedData = await getCache(cacheKey);
3074
+ if (cachedData) {
3075
+ logger8.info(`Cache hit for key: ${cacheKey}`);
3076
+ return cachedData;
3077
+ }
3078
+ try {
3079
+ const data = await collection.find({ user }).toArray();
3080
+ setCache(cacheKey, data, 15 * 60).then(() => {
3081
+ logger8.info(`Cache set for key: ${cacheKey}`);
3082
+ }).catch((err) => {
3083
+ logger8.error(`Failed to set cache for key: ${cacheKey}`, err);
3084
+ });
3085
+ return data;
3086
+ } catch (error) {
3087
+ if (error instanceof AppError2) {
3088
+ throw error;
3089
+ } else {
3090
+ throw new InternalServerError6(
3091
+ "Internal server error, failed to retrieve members."
3092
+ );
3093
+ }
3094
+ }
3095
+ }
3063
3096
  async function getByRoleId(role) {
3064
3097
  try {
3065
3098
  role = new ObjectId11(role);
@@ -3535,6 +3568,58 @@ function useMemberRepo() {
3535
3568
  throw new InternalServerError6("Failed to count user memberships.");
3536
3569
  }
3537
3570
  }
3571
+ async function updateSiteById(_id, siteId, siteName) {
3572
+ try {
3573
+ _id = new ObjectId11(_id);
3574
+ } catch (error) {
3575
+ throw new BadRequestError11("Invalid member ID format.");
3576
+ }
3577
+ try {
3578
+ siteId = new ObjectId11(siteId);
3579
+ } catch (error) {
3580
+ throw new BadRequestError11("Invalid site ID format.");
3581
+ }
3582
+ try {
3583
+ const updateValue = {
3584
+ siteId,
3585
+ siteName,
3586
+ updatedAt: /* @__PURE__ */ new Date()
3587
+ };
3588
+ const res = await collection.updateOne(
3589
+ { _id },
3590
+ { $set: updateValue }
3591
+ );
3592
+ if (res.modifiedCount === 0) {
3593
+ throw new InternalServerError6(
3594
+ "Unable to update member site."
3595
+ );
3596
+ }
3597
+ const cacheKey = makeCacheKey6(namespace_collection, {
3598
+ _id: _id.toString()
3599
+ });
3600
+ delCache(cacheKey).then(() => {
3601
+ logger8.info(`Cache deleted for key: ${cacheKey}`);
3602
+ }).catch((err) => {
3603
+ logger8.error(
3604
+ `Failed to delete cache for key: ${cacheKey}`,
3605
+ err
3606
+ );
3607
+ });
3608
+ delNamespace().then(() => {
3609
+ logger8.info(
3610
+ `Cache cleared for namespace: ${namespace_collection}`
3611
+ );
3612
+ }).catch((err) => {
3613
+ logger8.error(
3614
+ `Failed to clear cache for namespace: ${namespace_collection}`,
3615
+ err
3616
+ );
3617
+ });
3618
+ return res.modifiedCount;
3619
+ } catch (error) {
3620
+ throw error;
3621
+ }
3622
+ }
3538
3623
  return {
3539
3624
  createIndex,
3540
3625
  createUniqueIndex,
@@ -3542,6 +3627,7 @@ function useMemberRepo() {
3542
3627
  add,
3543
3628
  getById,
3544
3629
  getByUserId,
3630
+ getAllByUserId,
3545
3631
  getByUserIdType,
3546
3632
  getByRoleId,
3547
3633
  getAll,
@@ -3553,7 +3639,8 @@ function useMemberRepo() {
3553
3639
  countByOrg,
3554
3640
  countUserMembershipById,
3555
3641
  updateRoleById,
3556
- getByRoles
3642
+ getByRoles,
3643
+ updateSiteById
3557
3644
  };
3558
3645
  }
3559
3646
 
@@ -4106,6 +4193,25 @@ function useOrgRepo() {
4106
4193
  }
4107
4194
  }
4108
4195
  }
4196
+ async function update(id, value, session) {
4197
+ try {
4198
+ await collection.updateOne(
4199
+ { _id: new ObjectId15(id) },
4200
+ {
4201
+ $set: {
4202
+ ...value,
4203
+ updatedAt: /* @__PURE__ */ new Date()
4204
+ }
4205
+ },
4206
+ { session }
4207
+ );
4208
+ await delNamespace();
4209
+ return id;
4210
+ } catch (error) {
4211
+ logger10.log({ level: "error", message: error.message });
4212
+ throw new InternalServerError9("Failed to update organization.");
4213
+ }
4214
+ }
4109
4215
  async function getAll({
4110
4216
  search = "",
4111
4217
  page = 1,
@@ -4341,6 +4447,7 @@ function useOrgRepo() {
4341
4447
  createTextIndex,
4342
4448
  createUniqueIndex,
4343
4449
  add,
4450
+ update,
4344
4451
  getAll,
4345
4452
  getById,
4346
4453
  getByName,
@@ -5301,6 +5408,7 @@ function useVerificationService() {
5301
5408
  const { getUserByEmail } = useUserRepo();
5302
5409
  const { getById: getOrgById, getByEmail: getOrgByEmail } = useOrgRepo();
5303
5410
  const { getSiteById } = useSiteRepo();
5411
+ const { getByUserIdType } = useMemberRepo();
5304
5412
  async function createUserInvite({
5305
5413
  email,
5306
5414
  metadata
@@ -5356,8 +5464,77 @@ function useVerificationService() {
5356
5464
  throw error;
5357
5465
  }
5358
5466
  }
5359
- async function createSimpleUserInvite({ email, metadata }) {
5467
+ async function createSimpleUserInvite({
5468
+ email,
5469
+ metadata
5470
+ }) {
5360
5471
  const type = "user-invite";
5472
+ const apps = Array.isArray(metadata.app) ? metadata.app : [metadata.app];
5473
+ if (metadata?.org) {
5474
+ await getOrgById(metadata.org);
5475
+ }
5476
+ if (metadata?.siteId) {
5477
+ await getSiteById(metadata.siteId);
5478
+ }
5479
+ const verificationIds = [];
5480
+ const invitedApps = [];
5481
+ for (const app of apps) {
5482
+ await useVerificationRepo().findOne({
5483
+ type,
5484
+ email,
5485
+ "metadata.app": app,
5486
+ "metadata.org": metadata.org,
5487
+ "metadata.siteId": metadata.siteId
5488
+ });
5489
+ const value = {
5490
+ type,
5491
+ email,
5492
+ metadata: {
5493
+ ...metadata,
5494
+ app
5495
+ },
5496
+ expireAt: new Date(
5497
+ Date.now() + 72 * 60 * 60 * 1e3
5498
+ ).toISOString(),
5499
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
5500
+ };
5501
+ const createdId = await add(value);
5502
+ verificationIds.push(createdId.toString());
5503
+ invitedApps.push(app);
5504
+ }
5505
+ const link = `${APP_MAIN}/verify/invitation/${verificationIds[0]}`;
5506
+ const appsSet = new Set(invitedApps);
5507
+ const emailContent = compileHandlebar({
5508
+ context: {
5509
+ email,
5510
+ validity: VERIFICATION_USER_INVITE_DURATION,
5511
+ link,
5512
+ hasPropertyManagement: appsSet.has("property_management_agency"),
5513
+ hasSecurity: appsSet.has("security_agency"),
5514
+ hasCleaning: appsSet.has("cleaning_services"),
5515
+ hasMechanical: appsSet.has("mechanical_electrical_services"),
5516
+ hasLandscape: appsSet.has("landscaping_services"),
5517
+ hasPestControl: appsSet.has("pest_control_services"),
5518
+ hasPoolMaintenance: appsSet.has("pool_maintenance_services")
5519
+ },
5520
+ filePath: getDirectory(
5521
+ __dirname,
5522
+ "./public/handlebars/user-invite"
5523
+ )
5524
+ });
5525
+ await mailer.sendMail({
5526
+ to: email,
5527
+ subject: "User Invite",
5528
+ html: emailContent,
5529
+ sender: "iService365"
5530
+ });
5531
+ return verificationIds;
5532
+ }
5533
+ async function createSimpleMemberInvite({
5534
+ email,
5535
+ metadata
5536
+ }) {
5537
+ const type = "member-invite";
5361
5538
  if (metadata?.org)
5362
5539
  await getOrgById(metadata.org);
5363
5540
  if (metadata?.siteId)
@@ -5365,12 +5542,14 @@ function useVerificationService() {
5365
5542
  const existing = await useVerificationRepo().findOne({
5366
5543
  type,
5367
5544
  email,
5368
- "metadata.app": metadata.app
5545
+ "metadata.app": metadata.app,
5546
+ "metadata.org": metadata.org,
5547
+ "metadata.siteId": metadata.siteId
5369
5548
  });
5370
5549
  if (existing) {
5371
5550
  if (existing.status === "complete") {
5372
5551
  throw new BadRequestError20(
5373
- `User already completed invite for app: ${metadata.app}`
5552
+ `User already completed member invite for app: ${metadata.app}`
5374
5553
  );
5375
5554
  }
5376
5555
  return existing._id;
@@ -5383,18 +5562,18 @@ function useVerificationService() {
5383
5562
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
5384
5563
  };
5385
5564
  const res = await add(value);
5386
- const link = `${APP_MAIN}/verify/invitation/${res}`;
5565
+ const link = `${APP_MAIN}/verify/membership/${res}`;
5387
5566
  const emailContent = compileHandlebar({
5388
5567
  context: {
5389
5568
  email,
5390
5569
  validity: VERIFICATION_USER_INVITE_DURATION,
5391
5570
  link
5392
5571
  },
5393
- filePath: getDirectory(__dirname, "./public/handlebars/user-invite")
5572
+ filePath: getDirectory(__dirname, "./public/handlebars/member-invite")
5394
5573
  });
5395
5574
  await mailer.sendMail({
5396
5575
  to: email,
5397
- subject: "User Invite",
5576
+ subject: "Member Invite",
5398
5577
  html: emailContent,
5399
5578
  sender: "iService365"
5400
5579
  });
@@ -5483,6 +5662,72 @@ function useVerificationService() {
5483
5662
  throw error2;
5484
5663
  }
5485
5664
  }
5665
+ async function createSimpleServiceProviderInvite({ email, app, name, role, orgId, siteId, siteName }) {
5666
+ const schema2 = Joi11.object({
5667
+ email: Joi11.string().email().lowercase().required(),
5668
+ app: Joi11.string().allow("", null),
5669
+ name: Joi11.string().allow("", null),
5670
+ role: Joi11.string().hex().allow("", null),
5671
+ orgId: Joi11.string().hex().length(24).required(),
5672
+ siteId: Joi11.string().hex().length(24).required(),
5673
+ siteName: Joi11.string().required()
5674
+ });
5675
+ const { error } = schema2.validate({
5676
+ email,
5677
+ app,
5678
+ name,
5679
+ role,
5680
+ orgId,
5681
+ siteId,
5682
+ siteName
5683
+ });
5684
+ if (error) {
5685
+ const messages = error.details.map((d) => d.message).join(", ");
5686
+ logger14.log({ level: "error", message: messages });
5687
+ throw new BadRequestError20(`Invalid input: ${error.message}`);
5688
+ }
5689
+ const subject = "Service Provider Invite" /* _SERVICE_PROVIDER_INVITE */;
5690
+ const type = "service-provider-invite" /* SERVICE_PROVIDER_INVITE */;
5691
+ const value = {
5692
+ type,
5693
+ email,
5694
+ metadata: {
5695
+ app,
5696
+ name,
5697
+ role,
5698
+ org: orgId,
5699
+ siteId,
5700
+ siteName
5701
+ },
5702
+ expireAt: new Date(Date.now() + 72 * 60 * 60 * 1e3).toISOString(),
5703
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
5704
+ };
5705
+ try {
5706
+ const id = await _add(value);
5707
+ const filePath = getDirectory(__dirname, `./public/handlebars/${value.type}`);
5708
+ const link = `${APP_MAIN}/verify/${value.type}/${id}`;
5709
+ const emailContent = compileHandlebar({
5710
+ context: {
5711
+ email,
5712
+ app,
5713
+ name,
5714
+ role,
5715
+ siteName,
5716
+ link
5717
+ },
5718
+ filePath
5719
+ });
5720
+ await mailer.sendMail({
5721
+ to: email,
5722
+ subject,
5723
+ html: emailContent,
5724
+ sender: "iService365" /* ISERVICE365 */
5725
+ });
5726
+ return id;
5727
+ } catch (error2) {
5728
+ throw error2;
5729
+ }
5730
+ }
5486
5731
  async function createForgetPassword(email) {
5487
5732
  const value = {
5488
5733
  type: "forget-password",
@@ -5694,7 +5939,9 @@ function useVerificationService() {
5694
5939
  updateStatusById,
5695
5940
  signUp,
5696
5941
  checkExpiredInvitation,
5697
- createSimpleUserInvite
5942
+ createSimpleUserInvite,
5943
+ createSimpleMemberInvite,
5944
+ createSimpleServiceProviderInvite
5698
5945
  };
5699
5946
  }
5700
5947
 
@@ -7241,7 +7488,9 @@ function useMemberService() {
7241
7488
  const {
7242
7489
  add: addMember,
7243
7490
  updateRoleById: _updateRoleById,
7244
- getByRoles
7491
+ getByRoles,
7492
+ updateSiteById: _updateSiteById,
7493
+ getAllByUserId: _getAllByUserId
7245
7494
  } = useMemberRepo();
7246
7495
  const { getById: _getVerificationById, updateStatusById } = useVerificationRepo();
7247
7496
  const { getUserByEmail, updateDefaultOrgByEmail, getUserById } = useUserRepo();
@@ -7377,10 +7626,37 @@ function useMemberService() {
7377
7626
  throw error;
7378
7627
  }
7379
7628
  }
7629
+ async function updateSiteById(id, siteId, siteName) {
7630
+ try {
7631
+ await _updateSiteById(
7632
+ id,
7633
+ siteId,
7634
+ siteName
7635
+ );
7636
+ return {
7637
+ message: "Member site updated successfully."
7638
+ };
7639
+ } catch (error) {
7640
+ throw error;
7641
+ }
7642
+ }
7643
+ async function getAllByUser(user) {
7644
+ try {
7645
+ const members = await _getAllByUserId(user);
7646
+ return {
7647
+ items: members,
7648
+ total: members.length
7649
+ };
7650
+ } catch (error) {
7651
+ throw error;
7652
+ }
7653
+ }
7380
7654
  return {
7381
7655
  createMember,
7382
7656
  createMemberDirect,
7383
- updateRoleById
7657
+ updateRoleById,
7658
+ updateSiteById,
7659
+ getAllByUser
7384
7660
  };
7385
7661
  }
7386
7662
 
@@ -7392,9 +7668,10 @@ function useMemberController() {
7392
7668
  getOrgsByMembership: _getOrgsByMembership,
7393
7669
  getByUserIdType: _getByUserIdType,
7394
7670
  updateMemberStatus: _updateMemberStatus,
7395
- updateStatusByUserId: _updateStatusByUserId
7671
+ updateStatusByUserId: _updateStatusByUserId,
7672
+ updateSiteById: _updateSiteById
7396
7673
  } = useMemberRepo();
7397
- const { createMember: _createMember, createMemberDirect: _createMemberDirect, updateRoleById: _updateRoleById } = useMemberService();
7674
+ const { createMember: _createMember, createMemberDirect: _createMemberDirect, updateRoleById: _updateRoleById, getAllByUser: _getAllByUser } = useMemberService();
7398
7675
  async function createMember(req, res, next) {
7399
7676
  const validation = Joi15.string().hex().required();
7400
7677
  const _id = req.params.id;
@@ -7433,6 +7710,31 @@ function useMemberController() {
7433
7710
  return;
7434
7711
  }
7435
7712
  }
7713
+ async function getAllByUser(req, res, next) {
7714
+ const validation = Joi15.string().hex().required();
7715
+ const userId = req.params.id;
7716
+ const { error } = validation.validate(userId);
7717
+ if (error) {
7718
+ logger21.log({
7719
+ level: "error",
7720
+ message: error.message
7721
+ });
7722
+ next(new BadRequestError30(error.message));
7723
+ return;
7724
+ }
7725
+ try {
7726
+ const data = await _getAllByUser(userId);
7727
+ res.json(data);
7728
+ return;
7729
+ } catch (error2) {
7730
+ logger21.log({
7731
+ level: "error",
7732
+ message: error2.message
7733
+ });
7734
+ next(error2);
7735
+ return;
7736
+ }
7737
+ }
7436
7738
  async function getByUserIdType(req, res, next) {
7437
7739
  const validation = Joi15.object({
7438
7740
  id: Joi15.string().hex().required(),
@@ -7609,6 +7911,32 @@ function useMemberController() {
7609
7911
  return;
7610
7912
  }
7611
7913
  }
7914
+ async function updateSiteById(req, res, next) {
7915
+ const id = req.body.id?.trim();
7916
+ const siteId = req.body.siteId?.trim();
7917
+ const siteName = req.body.siteName?.trim();
7918
+ const validation = Joi15.object({
7919
+ id: Joi15.string().pattern(/^[0-9a-fA-F]{24}$/).required(),
7920
+ siteId: Joi15.string().pattern(/^[0-9a-fA-F]{24}$/).required(),
7921
+ siteName: Joi15.string().required()
7922
+ });
7923
+ const { error } = validation.validate({
7924
+ id,
7925
+ siteId,
7926
+ siteName
7927
+ });
7928
+ if (error) {
7929
+ return next(new BadRequestError30(error.message));
7930
+ }
7931
+ try {
7932
+ await _updateSiteById(id, siteId, siteName);
7933
+ res.json({
7934
+ message: "Successfully updated member site."
7935
+ });
7936
+ } catch (error2) {
7937
+ next(error2);
7938
+ }
7939
+ }
7612
7940
  return {
7613
7941
  createMember,
7614
7942
  getByUserId,
@@ -7617,7 +7945,9 @@ function useMemberController() {
7617
7945
  getOrgsByMembership,
7618
7946
  updateMemberStatus,
7619
7947
  updateRoleById,
7620
- createMemberDirect
7948
+ createMemberDirect,
7949
+ updateSiteById,
7950
+ getAllByUser
7621
7951
  };
7622
7952
  }
7623
7953
 
@@ -7628,7 +7958,9 @@ function useVerificationController() {
7628
7958
  const {
7629
7959
  createUserInvite: _createUserInvite,
7630
7960
  createSimpleUserInvite: _createSimpleUserInvite,
7961
+ createSimpleMemberInvite: _createSimpleMemberInvite,
7631
7962
  createServiceProviderInvite: _createServiceProviderInvite,
7963
+ createSimpleServiceProviderInvite: _createSimpleServiceProviderInvite,
7632
7964
  createForgetPassword: _createForgetPassword,
7633
7965
  verify: _verify,
7634
7966
  updateStatusById: _updateStatusById,
@@ -7683,7 +8015,7 @@ function useVerificationController() {
7683
8015
  const payload = { ...req.body };
7684
8016
  const validation = Joi16.object({
7685
8017
  email: Joi16.string().email().required(),
7686
- app: Joi16.string().optional().allow("", null),
8018
+ app: Joi16.array().items(Joi16.string()).min(1).required(),
7687
8019
  role: Joi16.string().hex().optional().allow("", null),
7688
8020
  name: Joi16.string().optional().allow("", null),
7689
8021
  org: Joi16.string().hex().optional().allow("", null),
@@ -7700,7 +8032,7 @@ function useVerificationController() {
7700
8032
  return;
7701
8033
  }
7702
8034
  const email = req.body.email ?? "";
7703
- const app = req.body.app ?? "";
8035
+ const app = req.body.app ?? [];
7704
8036
  const role = req.body.role ?? "";
7705
8037
  const name = req.body.name ?? "";
7706
8038
  const org = req.body.org ?? "";
@@ -7731,6 +8063,58 @@ function useVerificationController() {
7731
8063
  return;
7732
8064
  }
7733
8065
  }
8066
+ async function createSimpleMemberInvite(req, res, next) {
8067
+ const payload = { ...req.body };
8068
+ const validation = Joi16.object({
8069
+ email: Joi16.string().email().required(),
8070
+ app: Joi16.string().optional().allow("", null),
8071
+ role: Joi16.string().hex().optional().allow("", null),
8072
+ name: Joi16.string().optional().allow("", null),
8073
+ org: Joi16.string().hex().optional().allow("", null),
8074
+ siteId: Joi16.string().hex().optional().allow("", null),
8075
+ siteName: Joi16.string().optional().allow("", null)
8076
+ });
8077
+ const { error } = validation.validate(payload);
8078
+ if (error) {
8079
+ logger22.log({
8080
+ level: "error",
8081
+ message: `${error.message}`
8082
+ });
8083
+ next(new BadRequestError31(error.message));
8084
+ return;
8085
+ }
8086
+ const email = req.body.email ?? "";
8087
+ const app = req.body.app ?? "";
8088
+ const role = req.body.role ?? "";
8089
+ const name = req.body.name ?? "";
8090
+ const org = req.body.org ?? "";
8091
+ const siteId = req.body.siteId ?? "";
8092
+ const siteName = req.body.siteName ?? "";
8093
+ try {
8094
+ await _createSimpleMemberInvite({
8095
+ email,
8096
+ metadata: {
8097
+ app,
8098
+ role,
8099
+ name,
8100
+ org,
8101
+ siteId,
8102
+ siteName
8103
+ }
8104
+ });
8105
+ res.status(201).json({
8106
+ message: "Successfully invited member."
8107
+ });
8108
+ return;
8109
+ } catch (error2) {
8110
+ logger22.log({
8111
+ level: "error",
8112
+ message: `${error2.message}`
8113
+ });
8114
+ next(error2);
8115
+ return;
8116
+ }
8117
+ }
7734
8118
  async function createServiceProviderInvite(req, res, next) {
7735
8119
  const payload = req.body;
7736
8120
  const validation = Joi16.object({
@@ -7760,6 +8144,56 @@ function useVerificationController() {
7760
8144
  return;
7761
8145
  }
7762
8146
  }
8147
+ async function createSimpleServiceProviderInvite(req, res, next) {
8148
+ const payload = { ...req.body };
8149
+ const validation = Joi16.object({
8150
+ email: Joi16.string().email().required(),
8151
+ app: Joi16.string().optional().allow("", null),
8152
+ name: Joi16.string().optional().allow("", null),
8153
+ role: Joi16.string().hex().optional().allow("", null),
8154
+ orgId: Joi16.string().hex().required(),
8155
+ siteId: Joi16.string().hex().required(),
8156
+ siteName: Joi16.string().required()
8157
+ });
8158
+ const { error } = validation.validate(payload);
8159
+ if (error) {
8160
+ logger22.log({
8161
+ level: "error",
8162
+ message: `${error.message}`
8163
+ });
8164
+ next(new BadRequestError31(error.message));
8165
+ return;
8166
+ }
8167
+ const email = req.body.email ?? "";
8168
+ const app = req.body.app ?? "";
8169
+ const name = req.body.name ?? "";
8170
+ const role = req.body.role ?? "";
8171
+ const orgId = req.body.orgId ?? "";
8172
+ const siteId = req.body.siteId ?? "";
8173
+ const siteName = req.body.siteName ?? "";
8174
+ try {
8175
+ await _createSimpleServiceProviderInvite({
8176
+ email,
8177
+ app,
8178
+ name,
8179
+ role,
8180
+ orgId,
8181
+ siteId,
8182
+ siteName
8183
+ });
8184
+ res.status(201).json({
8185
+ message: "Successfully invited service provider."
8186
+ });
8187
+ return;
8188
+ } catch (error2) {
8189
+ logger22.log({
8190
+ level: "error",
8191
+ message: `${error2.message}`
8192
+ });
8193
+ next(error2);
8194
+ return;
8195
+ }
8196
+ }
7763
8197
  async function createForgetPassword(req, res, next) {
7764
8198
  const validation = Joi16.string().email().required();
7765
8199
  const email = req.body.email;
@@ -7892,11 +8326,13 @@ function useVerificationController() {
7892
8326
  getVerifications,
7893
8327
  createUserInvite,
7894
8328
  createServiceProviderInvite,
8329
+ createSimpleServiceProviderInvite,
7895
8330
  createForgetPassword,
7896
8331
  verify,
7897
8332
  updateVerificationStatus,
7898
8333
  cancelUserInvitation,
7899
- createSimpleUserInvite
8334
+ createSimpleUserInvite,
8335
+ createSimpleMemberInvite
7900
8336
  };
7901
8337
  }
7902
8338
 
@@ -8065,7 +8501,8 @@ function useOrgController() {
8065
8501
  getById: _getById,
8066
8502
  getByEmail: _getByEmail,
8067
8503
  getAll: _getAll,
8068
- add: _add
8504
+ add: _add,
8505
+ update: _update
8069
8506
  } = useOrgRepo();
8070
8507
  async function add(req, res, next) {
8071
8508
  const validation = Joi18.object({
@@ -8096,7 +8533,8 @@ function useOrgController() {
8096
8533
  search: Joi18.string().optional().allow("", null),
8097
8534
  page: Joi18.number().integer().min(1).allow("", null).default(1),
8098
8535
  limit: Joi18.number().integer().min(1).max(100).allow("", null).default(10),
8099
- nature: Joi18.string().valid(...allowedNatures).optional().allow("", null)
8536
+ nature: Joi18.string().valid(...allowedNatures).optional().allow("", null),
8537
+ sort: Joi18.string().optional().allow("", null)
8100
8538
  });
8101
8539
  const query = { ...req.query };
8102
8540
  const { error } = validation.validate(query);
@@ -8248,6 +8686,31 @@ function useOrgController() {
8248
8686
  return;
8249
8687
  }
8250
8688
  }
8689
+ async function update(req, res, next) {
8690
+ const validation = Joi18.object({
8691
+ name: Joi18.string().optional(),
8692
+ type: Joi18.string().optional(),
8693
+ nature: Joi18.string().valid(...allowedNatures).optional(),
8694
+ email: Joi18.string().email().allow("", null).optional(),
8695
+ contact: Joi18.string().allow("", null).optional()
8696
+ });
8697
+ const { error } = validation.validate(req.body);
8698
+ if (error) {
8699
+ next(new BadRequestError33(error.message));
8700
+ return;
8701
+ }
8702
+ const id = req.params.id;
8703
+ try {
8704
+ await _update(id, req.body);
8705
+ const data = await _getById(id);
8706
+ res.json({
8707
+ message: "Organization updated successfully",
8708
+ data
8709
+ });
8710
+ } catch (err) {
8711
+ next(err);
8712
+ }
8713
+ }
8251
8714
  return {
8252
8715
  add,
8253
8716
  addOnboardingOrg,
@@ -8255,7 +8718,8 @@ function useOrgController() {
8255
8718
  getOrgsByUserId,
8256
8719
  getByName,
8257
8720
  getById,
8258
- getByEmail
8721
+ getByEmail,
8722
+ update
8259
8723
  };
8260
8724
  }
8261
8725
 
@@ -16828,6 +17292,32 @@ function useBuildingUnitRepo() {
16828
17292
  }
16829
17293
  }
16830
17294
  }
17295
+ async function bulkAddBuildingUnits(value, session) {
17296
+ try {
17297
+ const operations = value.map((unit) => ({
17298
+ insertOne: {
17299
+ document: unit
17300
+ }
17301
+ }));
17302
+ const res = await collection.bulkWrite(operations, { session });
17303
+ delCachedData();
17304
+ return res;
17305
+ } catch (error) {
17306
+ logger53.log({
17307
+ level: "error",
17308
+ message: error.message
17309
+ });
17310
+ const isDuplicated = error.message.includes("duplicate");
17311
+ if (isDuplicated) {
17312
+ throw new BadRequestError72("Some building units already exist.");
17313
+ }
17314
+ if (error instanceof AppError10) {
17315
+ throw error;
17316
+ } else {
17317
+ throw new Error("Failed to bulk insert building units.");
17318
+ }
17319
+ }
17320
+ }
16831
17321
  return {
16832
17322
  createIndexes,
16833
17323
  add,
@@ -16843,7 +17333,8 @@ function useBuildingUnitRepo() {
16843
17333
  getBuildingUnitsForResident,
16844
17334
  getBuildingUnitsWithOwner,
16845
17335
  getUnitByBlockLevelUnitNumber,
16846
- getBySiteBuildingLevel
17336
+ getBySiteBuildingLevel,
17337
+ bulkAddBuildingUnits
16847
17338
  };
16848
17339
  }
16849
17340
 
@@ -17618,6 +18109,167 @@ function useVehicleService() {
17618
18109
  throw error;
17619
18110
  }
17620
18111
  }
18112
+ async function blocklistVehicles(_id, value) {
18113
+ const session = useAtlas34.getClient()?.startSession();
18114
+ if (!session) {
18115
+ throw new Error("Unable to start session for vehicle service.");
18116
+ }
18117
+ try {
18118
+ session.startTransaction();
18119
+ const vehicle = await _getVehicleById(_id);
18120
+ const plate = vehicle.plates.find((p) => p._id.toString() === _id);
18121
+ const _name = value.name ? value.name : vehicle.name;
18122
+ const _plateNumber = plate?.plateNumber;
18123
+ const _start = vehicle.start;
18124
+ const _end = vehicle.end;
18125
+ const _recNo = plate.recNo;
18126
+ const _type = plate.type;
18127
+ if (value.peopleId) {
18128
+ value.peopleId = new ObjectId46(value.peopleId);
18129
+ }
18130
+ const { site } = value;
18131
+ const startDahua = formatDahuaDate(_start);
18132
+ const endPlus24Hours = _end ? _end : new Date(new Date(_end).getTime() + 24 * 60 * 60 * 1e3);
18133
+ const endDahua = formatDahuaDate(endPlus24Hours);
18134
+ if (_plateNumber) {
18135
+ const siteCameras = [];
18136
+ let page = 1;
18137
+ let pages = 1;
18138
+ const limit = 20;
18139
+ do {
18140
+ const siteCameraReq = await _getAllSiteCameras({
18141
+ site,
18142
+ type: "anpr",
18143
+ direction: ["both", "entry"],
18144
+ page,
18145
+ limit
18146
+ });
18147
+ pages = siteCameraReq.pages || 1;
18148
+ siteCameras.push(...siteCameraReq.items);
18149
+ page++;
18150
+ } while (page < pages);
18151
+ if (!siteCameras.length) {
18152
+ throw new BadRequestError73("No site cameras found.");
18153
+ }
18154
+ for (const camera of siteCameras) {
18155
+ const { host, username, password } = camera;
18156
+ const removePlateNumber = {
18157
+ host,
18158
+ username,
18159
+ password,
18160
+ mode: _type === "blocklist" /* BLOCKLIST */ ? "TrafficBlackList" /* TRAFFIC_BLACKLIST */ : "TrafficRedList" /* TRAFFIC_REDLIST */,
18161
+ recno: _recNo
18162
+ };
18163
+ const responseForDeletion = await _removePlateNumber(
18164
+ removePlateNumber
18165
+ );
18166
+ if (responseForDeletion?.statusCode !== 200) {
18167
+ throw new BadRequestError73("Failed to delete plate number to ANPR");
18168
+ }
18169
+ const dahuaPayload = {
18170
+ host,
18171
+ username,
18172
+ password,
18173
+ plateNumber: _plateNumber,
18174
+ mode: "TrafficBlackList" /* TRAFFIC_BLACKLIST */,
18175
+ owner: _name,
18176
+ ...startDahua ? { start: startDahua } : {},
18177
+ ...endDahua ? { end: endDahua } : {}
18178
+ };
18179
+ const dahuaResponse = await _addPlateNumber(dahuaPayload);
18180
+ if (dahuaResponse?.statusCode !== 200) {
18181
+ throw new BadRequestError73("Failed to update plate number to ANPR");
18182
+ }
18183
+ const responseData = dahuaResponse?.data?.toString("utf-8") ?? "";
18184
+ value.recNo = responseData.split("=")[1]?.trim();
18185
+ const normalizedPlateNumber = _plateNumber;
18186
+ if (value.peopleId && value.recNo) {
18187
+ await _pushVehicleById(
18188
+ value.peopleId,
18189
+ {
18190
+ plateNumber: normalizedPlateNumber,
18191
+ recNo: value.recNo
18192
+ },
18193
+ session
18194
+ );
18195
+ }
18196
+ }
18197
+ }
18198
+ const formattedValue = {
18199
+ type: "blocklist" /* BLOCKLIST */,
18200
+ recNo: value.recNo
18201
+ };
18202
+ await _updateVehicleById(_id, formattedValue, session);
18203
+ await session.commitTransaction();
18204
+ } catch (error) {
18205
+ await session.abortTransaction();
18206
+ throw error;
18207
+ } finally {
18208
+ session.endSession();
18209
+ }
18210
+ }
18211
+ async function removeFromBlocklist(_id, value) {
18212
+ const session = useAtlas34.getClient()?.startSession();
18213
+ if (!session) {
18214
+ throw new Error("Unable to start session for vehicle service.");
18215
+ }
18216
+ try {
18217
+ session.startTransaction();
18218
+ const vehicle = await _getVehicleById(_id);
18219
+ const plate = vehicle.plates.find((p) => p._id.toString() === _id);
18220
+ const _plateNumber = plate?.plateNumber;
18221
+ const _recNo = plate.recNo;
18222
+ if (value.peopleId) {
18223
+ value.peopleId = new ObjectId46(value.peopleId);
18224
+ }
18225
+ const { site } = value;
18226
+ if (_plateNumber) {
18227
+ const siteCameras = [];
18228
+ let page = 1;
18229
+ let pages = 1;
18230
+ const limit = 20;
18231
+ do {
18232
+ const siteCameraReq = await _getAllSiteCameras({
18233
+ site,
18234
+ type: "anpr",
18235
+ direction: ["both", "entry"],
18236
+ page,
18237
+ limit
18238
+ });
18239
+ pages = siteCameraReq.pages || 1;
18240
+ siteCameras.push(...siteCameraReq.items);
18241
+ page++;
18242
+ } while (page < pages);
18243
+ if (!siteCameras.length) {
18244
+ throw new BadRequestError73("No site cameras found.");
18245
+ }
18246
+ for (const camera of siteCameras) {
18247
+ const { host, username, password } = camera;
18248
+ const removePlateNumber = {
18249
+ host,
18250
+ username,
18251
+ password,
18252
+ mode: "TrafficBlackList" /* TRAFFIC_BLACKLIST */,
18253
+ recno: _recNo
18254
+ };
18255
+ console.log(removePlateNumber);
18256
+ const responseForDeletion = await _removePlateNumber(
18257
+ removePlateNumber
18258
+ );
18259
+ if (responseForDeletion?.statusCode !== 200) {
18260
+ throw new BadRequestError73("Failed to delete plate number to ANPR");
18261
+ }
18262
+ }
18263
+ }
18264
+ await _deleteVehicle(_id, session);
18265
+ await session.commitTransaction();
18266
+ } catch (error) {
18267
+ await session.abortTransaction();
18268
+ throw error;
18269
+ } finally {
18270
+ session.endSession();
18271
+ }
18272
+ }
17621
18273
  return {
17622
18274
  add,
17623
18275
  deleteVehicle,
@@ -17625,7 +18277,9 @@ function useVehicleService() {
17625
18277
  processDeletingExpiredVehicles,
17626
18278
  reactivateVehicleById,
17627
18279
  updateVehicleById,
17628
- bulkUpsertVehicles
18280
+ bulkUpsertVehicles,
18281
+ blocklistVehicles,
18282
+ removeFromBlocklist
17629
18283
  };
17630
18284
  }
17631
18285
 
@@ -19995,7 +20649,7 @@ function useBuildingService() {
19995
20649
  getByBuildingLevel,
19996
20650
  updateLevelByBuildingLevel,
19997
20651
  updateByBuildingId,
19998
- add: _addBuildingUnit
20652
+ bulkAddBuildingUnits: _bulkAddBuildingUnits
19999
20653
  } = useBuildingUnitRepo();
20000
20654
  const { updateStatusById } = useFileRepo();
20001
20655
  const { deleteFile } = useFileService();
@@ -20184,15 +20838,16 @@ function useBuildingService() {
20184
20838
  companyName: "",
20185
20839
  companyRegistrationNumber: "",
20186
20840
  billing: [],
20187
- unitNumber: parseInt(unit.replace("Unit ", ""), 10) || null
20841
+ unitNumber: parseInt(unit.replace("Unit ", ""), 10) || null,
20842
+ createdAt: /* @__PURE__ */ new Date(),
20843
+ updatedAt: "",
20844
+ deletedAt: ""
20188
20845
  });
20189
20846
  });
20190
20847
  });
20191
20848
  }
20192
20849
  );
20193
- for (const buildingUnitPayload of buildingUnitPayloads) {
20194
- const result = await _addBuildingUnit(buildingUnitPayload);
20195
- }
20850
+ await _bulkAddBuildingUnits(buildingUnitPayloads);
20196
20851
  await session?.commitTransaction();
20197
20852
  return { buildingPayloads, buildingUnitPayloads };
20198
20853
  } catch (error) {
@@ -20938,7 +21593,9 @@ function useVehicleController() {
20938
21593
  approveVehicleById: _approveVehicleById,
20939
21594
  reactivateVehicleById: _reactivateVehicleById,
20940
21595
  updateVehicleById: _updateVehicleById,
20941
- bulkUpsertVehicles: _bulkUpsertVehicles
21596
+ bulkUpsertVehicles: _bulkUpsertVehicles,
21597
+ blocklistVehicles: _blocklistVehicles,
21598
+ removeFromBlocklist: _removeFromBlocklist
20942
21599
  } = useVehicleService();
20943
21600
  const {
20944
21601
  getSeasonPassTypes: _getSeasonPassTypes,
@@ -21515,6 +22172,68 @@ function useVehicleController() {
21515
22172
  return;
21516
22173
  }
21517
22174
  }
22175
+ async function blocklistVehicles(req, res, next) {
22176
+ try {
22177
+ const schema2 = Joi47.object({
22178
+ _id: Joi47.string().hex().length(24).required(),
22179
+ site: Joi47.string().hex().length(24).required(),
22180
+ peopleId: Joi47.string().hex().length(24).optional().allow(null, ""),
22181
+ remarks: Joi47.string().optional().allow("", null)
22182
+ });
22183
+ const { error, value } = schema2.validate(
22184
+ {
22185
+ _id: req.params.id,
22186
+ ...req.body
22187
+ },
22188
+ { abortEarly: false }
22189
+ );
22190
+ if (error) {
22191
+ const messages = error.details.map((d) => d.message).join(", ");
22192
+ logger66.log({ level: "error", message: messages });
22193
+ next(new BadRequestError85(messages));
22194
+ return;
22195
+ }
22196
+ const { _id, ...rest } = value;
22197
+ await _blocklistVehicles(_id, rest);
22198
+ res.json({ message: "Successfully blocked vehicle." });
22199
+ return;
22200
+ } catch (error) {
22201
+ logger66.log({ level: "error", message: error.message });
22202
+ next(error);
22203
+ return;
22204
+ }
22205
+ }
22206
+ async function removeFromBlocklist(req, res, next) {
22207
+ try {
22208
+ const schema2 = Joi47.object({
22209
+ _id: Joi47.string().hex().length(24).required(),
22210
+ site: Joi47.string().hex().length(24).required(),
22211
+ peopleId: Joi47.string().hex().length(24).optional().allow(null, ""),
22212
+ remarks: Joi47.string().optional().allow("", null)
22213
+ });
22214
+ const { error, value } = schema2.validate(
22215
+ {
22216
+ _id: req.params.id,
22217
+ ...req.body
22218
+ },
22219
+ { abortEarly: false }
22220
+ );
22221
+ if (error) {
22222
+ const messages = error.details.map((d) => d.message).join(", ");
22223
+ logger66.log({ level: "error", message: messages });
22224
+ next(new BadRequestError85(messages));
22225
+ return;
22226
+ }
22227
+ const { _id, ...rest } = value;
22228
+ await _removeFromBlocklist(_id, rest);
22229
+ res.json({ message: "Successfully removed vehicle from blocklist." });
22230
+ return;
22231
+ } catch (error) {
22232
+ logger66.log({ level: "error", message: error.message });
22233
+ next(error);
22234
+ return;
22235
+ }
22236
+ }
21518
22237
  return {
21519
22238
  add,
21520
22239
  getVehicles,
@@ -21528,7 +22247,9 @@ function useVehicleController() {
21528
22247
  getAllVehiclesByUnitId,
21529
22248
  uploadSpreadsheetVehicles,
21530
22249
  getSpecificVehicleById,
21531
- getBlocklistedVehicles
22250
+ getBlocklistedVehicles,
22251
+ blocklistVehicles,
22252
+ removeFromBlocklist
21532
22253
  };
21533
22254
  }
21534
22255
 
@@ -31160,6 +31881,18 @@ function MBulletinBoard(value) {
31160
31881
  throw new Error("Invalid org ID.");
31161
31882
  }
31162
31883
  }
31884
+ if (value.file && Array.isArray(value.file)) {
31885
+ value.file = value.file.map((f) => {
31886
+ if (f._id && typeof f._id === "string") {
31887
+ try {
31888
+ return { ...f, _id: new ObjectId78(f._id) };
31889
+ } catch {
31890
+ throw new Error("Invalid file ID.");
31891
+ }
31892
+ }
31893
+ return f;
31894
+ });
31895
+ }
31163
31896
  return {
31164
31897
  _id: value._id ?? new ObjectId78(),
31165
31898
  site: value.site ?? "",
@@ -31477,7 +32210,7 @@ function useBulletinBoardRepo() {
31477
32210
  }
31478
32211
 
31479
32212
  // src/services/bulletin-board.service.ts
31480
- import { useAtlas as useAtlas67 } from "@7365admin1/node-server-utils";
32213
+ import { useAtlas as useAtlas67, NotFoundError as NotFoundError31 } from "@7365admin1/node-server-utils";
31481
32214
  function useBulletinBoardService() {
31482
32215
  const {
31483
32216
  add: _add,
@@ -31487,7 +32220,7 @@ function useBulletinBoardService() {
31487
32220
  deleteBulletinBoardById: _deleteBulletinBoardById,
31488
32221
  getBulletinBoardById: _getBulletinBoardById
31489
32222
  } = useBulletinBoardRepo();
31490
- const { deleteFileById: _deleteFileById } = useFileRepo();
32223
+ const { deleteFileById: _deleteFileById, updateStatusById } = useFileRepo();
31491
32224
  async function add(value) {
31492
32225
  const session = useAtlas67.getClient()?.startSession();
31493
32226
  session?.startTransaction();
@@ -31495,6 +32228,21 @@ function useBulletinBoardService() {
31495
32228
  value.status = "upcoming" /* UPCOMING */;
31496
32229
  }
31497
32230
  try {
32231
+ const bulletinFiles = value?.file ?? [];
32232
+ if (bulletinFiles.length > 0) {
32233
+ for (const bulletinFile of bulletinFiles) {
32234
+ if (!bulletinFile._id)
32235
+ continue;
32236
+ const file = await updateStatusById(
32237
+ bulletinFile._id.toString(),
32238
+ { status: "active" },
32239
+ session
32240
+ );
32241
+ if (!file) {
32242
+ throw new NotFoundError31("File not found.");
32243
+ }
32244
+ }
32245
+ }
31498
32246
  await _add(value, session);
31499
32247
  await session?.commitTransaction();
31500
32248
  return "Successfully added bulletin board.";
@@ -33126,7 +33874,7 @@ import {
33126
33874
  InternalServerError as InternalServerError45,
33127
33875
  logger as logger115,
33128
33876
  makeCacheKey as makeCacheKey42,
33129
- NotFoundError as NotFoundError33,
33877
+ NotFoundError as NotFoundError34,
33130
33878
  paginate as paginate37,
33131
33879
  useAtlas as useAtlas72,
33132
33880
  useCache as useCache44
@@ -33290,7 +34038,7 @@ function useEventManagementRepo() {
33290
34038
  try {
33291
34039
  const data = await collection.findOne({ _id }, { session });
33292
34040
  if (!data) {
33293
- throw new NotFoundError33("Event not found.");
34041
+ throw new NotFoundError34("Event not found.");
33294
34042
  }
33295
34043
  setCache(cacheKey, data, 15 * 60).then(() => {
33296
34044
  logger115.info(`Cache set for key: ${cacheKey}`);
@@ -33387,7 +34135,7 @@ function useEventManagementRepo() {
33387
34135
  { session }
33388
34136
  );
33389
34137
  if (res.matchedCount === 0) {
33390
- throw new NotFoundError33("No bulletin boards found to update.");
34138
+ throw new NotFoundError34("No bulletin boards found to update.");
33391
34139
  }
33392
34140
  delNamespace().then(() => {
33393
34141
  logger115.info(
@@ -37308,6 +38056,19 @@ function UseAccessManagementRepo() {
37308
38056
  await session?.endSession();
37309
38057
  }
37310
38058
  }
38059
+ async function uploadTemplateRepo({ site, id, name }) {
38060
+ site = new ObjectId90(site);
38061
+ id = new ObjectId90(id);
38062
+ try {
38063
+ const result = await collectionName("sites").updateOne(
38064
+ { _id: site },
38065
+ { $set: { "siteSettings.entryPass.settings.template": { id, name } } }
38066
+ );
38067
+ return result;
38068
+ } catch (error) {
38069
+ throw new Error(error.message);
38070
+ }
38071
+ }
37311
38072
  return {
37312
38073
  createIndexes,
37313
38074
  createIndexForEntrypass,
@@ -37342,7 +38103,8 @@ function UseAccessManagementRepo() {
37342
38103
  indexCombination,
37343
38104
  getTransactionsRepo,
37344
38105
  assignMultipleCardsRepo,
37345
- visitorCheckoutRepo
38106
+ visitorCheckoutRepo,
38107
+ uploadTemplateRepo
37346
38108
  };
37347
38109
  }
37348
38110
 
@@ -37385,7 +38147,8 @@ function useAccessManagementSvc() {
37385
38147
  getBlockLevelAndUnitListRepo,
37386
38148
  getTransactionsRepo,
37387
38149
  assignMultipleCardsRepo,
37388
- visitorCheckoutRepo
38150
+ visitorCheckoutRepo,
38151
+ uploadTemplateRepo
37389
38152
  } = UseAccessManagementRepo();
37390
38153
  const addPhysicalCardSvc = async (payload) => {
37391
38154
  try {
@@ -37698,7 +38461,15 @@ function useAccessManagementSvc() {
37698
38461
  const response = await visitorCheckoutRepo({ userId });
37699
38462
  return response;
37700
38463
  } catch (err) {
37701
- return Promise.reject("Server internal error.");
38464
+ throw new Error(err.message);
38465
+ }
38466
+ };
38467
+ const uploadTemplateSvc = async ({ site, id, name }) => {
38468
+ try {
38469
+ const response = await uploadTemplateRepo({ site, id, name });
38470
+ return response;
38471
+ } catch (err) {
38472
+ throw new Error(err.message);
37702
38473
  }
37703
38474
  };
37704
38475
  return {
@@ -37738,7 +38509,8 @@ function useAccessManagementSvc() {
37738
38509
  getBlockLevelAndUnitListSvc,
37739
38510
  getTransactionsSvc,
37740
38511
  assignMultipleCardsSvc,
37741
- visitorCheckoutSvc
38512
+ visitorCheckoutSvc,
38513
+ uploadTemplateSvc
37742
38514
  };
37743
38515
  }
37744
38516
 
@@ -37781,7 +38553,8 @@ function useAccessManagementController() {
37781
38553
  getBlockLevelAndUnitListSvc,
37782
38554
  getTransactionsSvc,
37783
38555
  assignMultipleCardsSvc,
37784
- visitorCheckoutSvc
38556
+ visitorCheckoutSvc,
38557
+ uploadTemplateSvc
37785
38558
  } = useAccessManagementSvc();
37786
38559
  const addPhysicalCard = async (req, res) => {
37787
38560
  try {
@@ -38598,7 +39371,32 @@ function useAccessManagementController() {
38598
39371
  const result = await visitorCheckoutSvc({ userId });
38599
39372
  return res.status(200).json({ message: "Success", data: result });
38600
39373
  } catch (error) {
38601
- return Promise.reject("Internal Server Error");
39374
+ return res.status(400).json({
39375
+ data: null,
39376
+ message: error.message
39377
+ });
39378
+ }
39379
+ };
39380
+ const uploadTemplate = async (req, res) => {
39381
+ try {
39382
+ const { site } = req.query;
39383
+ const { id, name } = req.body;
39384
+ const schema2 = Joi86.object({
39385
+ site: Joi86.string().hex().required(),
39386
+ id: Joi86.string().hex().required(),
39387
+ name: Joi86.string().required()
39388
+ });
39389
+ const { error } = schema2.validate({ site, id, name });
39390
+ if (error) {
39391
+ return res.status(400).json({ message: error.message });
39392
+ }
39393
+ const result = await uploadTemplateSvc({ site, id, name });
39394
+ return res.status(200).json({ message: "Success", data: result });
39395
+ } catch (error) {
39396
+ return res.status(400).json({
39397
+ data: null,
39398
+ message: error.message
39399
+ });
38602
39400
  }
38603
39401
  };
38604
39402
  return {
@@ -38636,7 +39434,8 @@ function useAccessManagementController() {
38636
39434
  getBlockLevelAndUnitList,
38637
39435
  getTransactions: getTransactions2,
38638
39436
  assignMultipleCards,
38639
- visitorCheckout
39437
+ visitorCheckout,
39438
+ uploadTemplate
38640
39439
  };
38641
39440
  }
38642
39441
 
@@ -39167,7 +39966,7 @@ import {
39167
39966
  InternalServerError as InternalServerError49,
39168
39967
  logger as logger124,
39169
39968
  makeCacheKey as makeCacheKey46,
39170
- NotFoundError as NotFoundError37,
39969
+ NotFoundError as NotFoundError38,
39171
39970
  paginate as paginate41,
39172
39971
  toObjectId as toObjectId14,
39173
39972
  useAtlas as useAtlas79,
@@ -39332,7 +40131,7 @@ function useOccurrenceBookRepo() {
39332
40131
  try {
39333
40132
  const data = await collection.findOne({ _id }, { session });
39334
40133
  if (!data) {
39335
- throw new NotFoundError37("Occurrence book not found.");
40134
+ throw new NotFoundError38("Occurrence book not found.");
39336
40135
  }
39337
40136
  setCache(cacheKey, data, 15 * 60).then(() => {
39338
40137
  logger124.info(`Cache set for key: ${cacheKey}`);
@@ -39829,7 +40628,7 @@ import {
39829
40628
  InternalServerError as InternalServerError50,
39830
40629
  logger as logger126,
39831
40630
  makeCacheKey as makeCacheKey47,
39832
- NotFoundError as NotFoundError38,
40631
+ NotFoundError as NotFoundError39,
39833
40632
  paginate as paginate42,
39834
40633
  useAtlas as useAtlas81,
39835
40634
  useCache as useCache49
@@ -39965,7 +40764,7 @@ function useBulletinVideoRepo() {
39965
40764
  { session }
39966
40765
  );
39967
40766
  if (!data) {
39968
- throw new NotFoundError38("Bulletin video not found.");
40767
+ throw new NotFoundError39("Bulletin video not found.");
39969
40768
  }
39970
40769
  setCache(cacheKey, data, 15 * 60).then(() => {
39971
40770
  logger126.info(`Cache set for key: ${cacheKey}`);
@@ -40058,7 +40857,7 @@ function useBulletinVideoRepo() {
40058
40857
  }
40059
40858
 
40060
40859
  // src/services/bulletin-video.service.ts
40061
- import { useAtlas as useAtlas82 } from "@7365admin1/node-server-utils";
40860
+ import { useAtlas as useAtlas82, NotFoundError as NotFoundError40 } from "@7365admin1/node-server-utils";
40062
40861
  function useBulletinVideoService() {
40063
40862
  const {
40064
40863
  add: _add,
@@ -40066,11 +40865,22 @@ function useBulletinVideoService() {
40066
40865
  deleteBulletinVideoById: _deleteBulletinVideoById,
40067
40866
  getBulletinVideoById: _getBulletinVideoById
40068
40867
  } = useBulletinVideoRepo();
40069
- const { deleteFileById: _deleteFileById } = useFileRepo();
40868
+ const { deleteFileById: _deleteFileById, updateStatusById } = useFileRepo();
40070
40869
  async function add(value) {
40071
40870
  const session = useAtlas82.getClient()?.startSession();
40072
40871
  session?.startTransaction();
40073
40872
  try {
40873
+ const bulletinVideo = value.file;
40874
+ if (bulletinVideo) {
40875
+ const file = await updateStatusById(
40876
+ bulletinVideo,
40877
+ { status: "active" },
40878
+ session
40879
+ );
40880
+ if (!file) {
40881
+ throw new NotFoundError40("File not found.");
40882
+ }
40883
+ }
40074
40884
  await _add(value, session);
40075
40885
  await session?.commitTransaction();
40076
40886
  return "Successfully added bulletin video.";
@@ -41407,7 +42217,7 @@ import {
41407
42217
  InternalServerError as InternalServerError52,
41408
42218
  logger as logger133,
41409
42219
  makeCacheKey as makeCacheKey49,
41410
- NotFoundError as NotFoundError40,
42220
+ NotFoundError as NotFoundError42,
41411
42221
  paginate as paginate44,
41412
42222
  useAtlas as useAtlas85,
41413
42223
  useCache as useCache51
@@ -41575,7 +42385,7 @@ function useEntryPassSettingsRepo() {
41575
42385
  }
41576
42386
  ]).toArray();
41577
42387
  if (!data || !data.length) {
41578
- throw new NotFoundError40("Entry Pass Settings not found.");
42388
+ throw new NotFoundError42("Entry Pass Settings not found.");
41579
42389
  }
41580
42390
  setCache(cacheKey, data[0], 15 * 60).then(() => {
41581
42391
  logger133.info(`Cache set for key: ${cacheKey}`);
@@ -41703,7 +42513,7 @@ function useEntryPassSettingsRepo() {
41703
42513
  }
41704
42514
  ]).toArray();
41705
42515
  if (!data || !data.length) {
41706
- throw new NotFoundError40("Entry Pass Settings not found.");
42516
+ throw new NotFoundError42("Entry Pass Settings not found.");
41707
42517
  }
41708
42518
  setCache(cacheKey, data[0], 15 * 60).then(() => {
41709
42519
  logger133.info(`Cache set for key: ${cacheKey}`);
@@ -42503,7 +43313,7 @@ function useNfcPatrolRouteService() {
42503
43313
  import {
42504
43314
  BadRequestError as BadRequestError163,
42505
43315
  logger as logger140,
42506
- NotFoundError as NotFoundError42
43316
+ NotFoundError as NotFoundError44
42507
43317
  } from "@7365admin1/node-server-utils";
42508
43318
  import Joi99 from "joi";
42509
43319
  function useNfcPatrolRouteController() {
@@ -42592,7 +43402,7 @@ function useNfcPatrolRouteController() {
42592
43402
  try {
42593
43403
  const nfcPatrolRoute = await _getById(value?.id, value?.isStart);
42594
43404
  if (!nfcPatrolRoute) {
42595
- throw new NotFoundError42("NFC Patrol Route not found.");
43405
+ throw new NotFoundError44("NFC Patrol Route not found.");
42596
43406
  }
42597
43407
  res.json({
42598
43408
  message: "Successfully retrieved nfc patrol route.",
@@ -42901,7 +43711,7 @@ function MIncidentReport(value) {
42901
43711
  import {
42902
43712
  useAtlas as useAtlas90,
42903
43713
  BadRequestError as BadRequestError165,
42904
- NotFoundError as NotFoundError44
43714
+ NotFoundError as NotFoundError46
42905
43715
  } from "@7365admin1/node-server-utils";
42906
43716
 
42907
43717
  // src/repositories/incident-report.repo.ts
@@ -42910,7 +43720,7 @@ import {
42910
43720
  InternalServerError as InternalServerError55,
42911
43721
  logger as logger141,
42912
43722
  makeCacheKey as makeCacheKey52,
42913
- NotFoundError as NotFoundError43,
43723
+ NotFoundError as NotFoundError45,
42914
43724
  paginate as paginate46,
42915
43725
  useAtlas as useAtlas89,
42916
43726
  useCache as useCache54
@@ -43168,7 +43978,7 @@ function useIncidentReportRepo() {
43168
43978
  { session }
43169
43979
  );
43170
43980
  if (!data) {
43171
- throw new NotFoundError43("Incident report not found.");
43981
+ throw new NotFoundError45("Incident report not found.");
43172
43982
  }
43173
43983
  setCache(cacheKey, data, 15 * 60).then(() => {
43174
43984
  logger141.info(`Cache set for key: ${cacheKey}`);
@@ -43365,7 +44175,7 @@ function useIncidentReportService() {
43365
44175
  session
43366
44176
  );
43367
44177
  if (!file) {
43368
- throw new NotFoundError44("File not found.");
44178
+ throw new NotFoundError46("File not found.");
43369
44179
  }
43370
44180
  }
43371
44181
  }
@@ -43835,7 +44645,7 @@ import {
43835
44645
  InternalServerError as InternalServerError56,
43836
44646
  logger as logger144,
43837
44647
  makeCacheKey as makeCacheKey53,
43838
- NotFoundError as NotFoundError45,
44648
+ NotFoundError as NotFoundError47,
43839
44649
  useAtlas as useAtlas91,
43840
44650
  useCache as useCache55
43841
44651
  } from "@7365admin1/node-server-utils";
@@ -43925,7 +44735,7 @@ function useNfcPatrolSettingsRepository() {
43925
44735
  { session }
43926
44736
  );
43927
44737
  if (res.matchedCount === 0) {
43928
- throw new NotFoundError45("NFC patrol settings not found for this site.");
44738
+ throw new NotFoundError47("NFC patrol settings not found for this site.");
43929
44739
  }
43930
44740
  delNamespace().then(() => {
43931
44741
  logger144.info(`Cache cleared for namespace: ${namespace_collection}`);
@@ -44090,7 +44900,7 @@ import {
44090
44900
  InternalServerError as InternalServerError57,
44091
44901
  logger as logger147,
44092
44902
  makeCacheKey as makeCacheKey54,
44093
- NotFoundError as NotFoundError46,
44903
+ NotFoundError as NotFoundError48,
44094
44904
  paginate as paginate47,
44095
44905
  useAtlas as useAtlas93,
44096
44906
  useCache as useCache56
@@ -44318,7 +45128,7 @@ function useOccurrenceSubjectRepo() {
44318
45128
  try {
44319
45129
  const data = await collection.findOne({ _id }, { session });
44320
45130
  if (!data) {
44321
- throw new NotFoundError46("Occurrence subject not found.");
45131
+ throw new NotFoundError48("Occurrence subject not found.");
44322
45132
  }
44323
45133
  setCache(cacheKey, data, 15 * 60).then(() => {
44324
45134
  logger147.info(`Cache set for key: ${cacheKey}`);
@@ -44776,7 +45586,7 @@ import {
44776
45586
  InternalServerError as InternalServerError58,
44777
45587
  logger as logger149,
44778
45588
  makeCacheKey as makeCacheKey55,
44779
- NotFoundError as NotFoundError47,
45589
+ NotFoundError as NotFoundError49,
44780
45590
  paginate as paginate48,
44781
45591
  useAtlas as useAtlas95,
44782
45592
  useCache as useCache57
@@ -44922,7 +45732,7 @@ function useOnlineFormRepo() {
44922
45732
  }
44923
45733
  ]).toArray();
44924
45734
  if (!data || !data.length) {
44925
- throw new NotFoundError47("Document not found.");
45735
+ throw new NotFoundError49("Document not found.");
44926
45736
  }
44927
45737
  setCache(cacheKey, data[0], 15 * 60).then(() => {
44928
45738
  logger149.info(`Cache set for key: ${cacheKey}`);
@@ -50801,7 +51611,7 @@ import {
50801
51611
  logger as logger178,
50802
51612
  getDirectory as getDirectory5,
50803
51613
  BadRequestError as BadRequestError200,
50804
- NotFoundError as NotFoundError51,
51614
+ NotFoundError as NotFoundError53,
50805
51615
  InternalServerError as InternalServerError69,
50806
51616
  useAtlas as useAtlas113,
50807
51617
  hashPassword as hashPassword4
@@ -50930,7 +51740,7 @@ function useVerificationServiceV2() {
50930
51740
  session?.startTransaction();
50931
51741
  const item = await _getByVerificationCode(verificationCode);
50932
51742
  if (!item) {
50933
- throw new NotFoundError51("Verification not found.");
51743
+ throw new NotFoundError53("Verification not found.");
50934
51744
  }
50935
51745
  switch (item.status) {
50936
51746
  case "expired" /* EXPIRED */:
@@ -51420,7 +52230,7 @@ import {
51420
52230
  BadRequestError as BadRequestError203,
51421
52231
  comparePassword as comparePassword3,
51422
52232
  InternalServerError as InternalServerError71,
51423
- NotFoundError as NotFoundError53,
52233
+ NotFoundError as NotFoundError55,
51424
52234
  useCache as useCache67
51425
52235
  } from "@7365admin1/node-server-utils";
51426
52236
  import { v4 as uuidv42 } from "uuid";
@@ -51433,7 +52243,7 @@ import {
51433
52243
  logger as logger180,
51434
52244
  BadRequestError as BadRequestError202,
51435
52245
  paginate as paginate58,
51436
- NotFoundError as NotFoundError52,
52246
+ NotFoundError as NotFoundError54,
51437
52247
  AppError as AppError28,
51438
52248
  useCache as useCache66,
51439
52249
  makeCacheKey as makeCacheKey64,
@@ -51566,7 +52376,7 @@ function useUserRepoV2() {
51566
52376
  ]).toArray();
51567
52377
  const data = results.length > 0 ? results[0] : null;
51568
52378
  if (!data)
51569
- throw new NotFoundError52("User not found.");
52379
+ throw new NotFoundError54("User not found.");
51570
52380
  setCache(cacheKey, data, 15 * 60).then(() => logger180.info(`Cache set for key: ${cacheKey}`)).catch(
51571
52381
  (err) => logger180.error(`Failed to set cache for key: ${cacheKey}`, err)
51572
52382
  );
@@ -51907,7 +52717,7 @@ function useAuthServiceV2() {
51907
52717
  try {
51908
52718
  const user = await getUserByEmail(email);
51909
52719
  if (!user) {
51910
- throw new NotFoundError53(
52720
+ throw new NotFoundError55(
51911
52721
  "Invalid user email. Please check your email and try again."
51912
52722
  );
51913
52723
  }
@@ -51977,7 +52787,7 @@ import {
51977
52787
  comparePassword as comparePassword4,
51978
52788
  hashPassword as hashPassword5,
51979
52789
  InternalServerError as InternalServerError72,
51980
- NotFoundError as NotFoundError54,
52790
+ NotFoundError as NotFoundError56,
51981
52791
  useAtlas as useAtlas115,
51982
52792
  useS3 as useS33
51983
52793
  } from "@7365admin1/node-server-utils";
@@ -52081,14 +52891,14 @@ function useUserServiceV2() {
52081
52891
  try {
52082
52892
  const otpDoc = await _getVerificationById(id);
52083
52893
  if (!otpDoc) {
52084
- throw new NotFoundError54("You are using an invalid reset link.");
52894
+ throw new NotFoundError56("You are using an invalid reset link.");
52085
52895
  }
52086
52896
  if (otpDoc.status === "complete" /* COMPLETE */) {
52087
52897
  throw new BadRequestError204("This link has already been invalidated.");
52088
52898
  }
52089
52899
  const user = await _getUserByEmail(otpDoc.email);
52090
52900
  if (!user) {
52091
- throw new NotFoundError54("User not found.");
52901
+ throw new NotFoundError56("User not found.");
52092
52902
  }
52093
52903
  if (!user._id) {
52094
52904
  throw new InternalServerError72("Invalid user ID.");