@eeplatform/core 1.8.4 → 1.8.7

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
@@ -47,8 +47,6 @@ __export(src_exports, {
47
47
  MAILER_TRANSPORT_PORT: () => MAILER_TRANSPORT_PORT,
48
48
  MAILER_TRANSPORT_SECURE: () => MAILER_TRANSPORT_SECURE,
49
49
  MAddress: () => MAddress,
50
- MBuilding: () => MBuilding,
51
- MBuildingUnit: () => MBuildingUnit,
52
50
  MFile: () => MFile,
53
51
  MMember: () => MMember,
54
52
  MONGO_DB: () => MONGO_DB,
@@ -81,23 +79,14 @@ __export(src_exports, {
81
79
  addressSchema: () => addressSchema,
82
80
  isDev: () => isDev,
83
81
  modelPSGC: () => modelPSGC,
84
- schemaBuilding: () => schemaBuilding,
85
- schemaBuildingUnit: () => schemaBuildingUnit,
86
82
  schemaOrg: () => schemaOrg,
87
83
  schemaPSGC: () => schemaPSGC,
88
- schemaUpdateOptions: () => schemaUpdateOptions,
89
84
  transactionSchema: () => transactionSchema,
90
85
  useAddressController: () => useAddressController,
91
86
  useAddressRepo: () => useAddressRepo,
92
87
  useAudioTranscriptionController: () => useAudioTranscriptionController,
93
88
  useAuthController: () => useAuthController,
94
89
  useAuthService: () => useAuthService,
95
- useBuildingController: () => useBuildingController,
96
- useBuildingRepo: () => useBuildingRepo,
97
- useBuildingService: () => useBuildingService,
98
- useBuildingUnitController: () => useBuildingUnitController,
99
- useBuildingUnitRepo: () => useBuildingUnitRepo,
100
- useBuildingUnitService: () => useBuildingUnitService,
101
90
  useCounterModel: () => useCounterModel,
102
91
  useCounterRepo: () => useCounterRepo,
103
92
  useFileController: () => useFileController,
@@ -1337,6 +1326,44 @@ function useMemberRepo() {
1337
1326
  );
1338
1327
  }
1339
1328
  }
1329
+ async function getByOrg(org) {
1330
+ try {
1331
+ org = new import_mongodb8.ObjectId(org);
1332
+ } catch (error) {
1333
+ throw new import_nodejs_utils8.BadRequestError("Invalid ID.");
1334
+ }
1335
+ try {
1336
+ const cacheKey = (0, import_nodejs_utils8.makeCacheKey)(namespace_collection, {
1337
+ org: String(org),
1338
+ tag: "byOrg"
1339
+ });
1340
+ const cached = await getCache(cacheKey);
1341
+ if (cached) {
1342
+ import_nodejs_utils8.logger.log({
1343
+ level: "info",
1344
+ message: `Cache hit for getByOrg member: ${cacheKey}`
1345
+ });
1346
+ return cached;
1347
+ }
1348
+ const data = await collection.findOne({ org });
1349
+ setCache(cacheKey, data, 300).then(() => {
1350
+ import_nodejs_utils8.logger.log({
1351
+ level: "info",
1352
+ message: `Cache set for member by org: ${cacheKey}`
1353
+ });
1354
+ }).catch((err) => {
1355
+ import_nodejs_utils8.logger.log({
1356
+ level: "error",
1357
+ message: `Failed to set cache for member by org: ${err.message}`
1358
+ });
1359
+ });
1360
+ return data;
1361
+ } catch (error) {
1362
+ throw new import_nodejs_utils8.InternalServerError(
1363
+ "Internal server error, failed to retrieve member."
1364
+ );
1365
+ }
1366
+ }
1340
1367
  async function getByUserId(user) {
1341
1368
  try {
1342
1369
  user = new import_mongodb8.ObjectId(user);
@@ -1491,9 +1518,6 @@ function useMemberRepo() {
1491
1518
  {
1492
1519
  $match: query
1493
1520
  },
1494
- {
1495
- $sort: { _id: -1 }
1496
- },
1497
1521
  {
1498
1522
  $limit: limit
1499
1523
  },
@@ -1787,6 +1811,7 @@ function useMemberRepo() {
1787
1811
  createTextIndex,
1788
1812
  add,
1789
1813
  getById,
1814
+ getByOrg,
1790
1815
  getAll,
1791
1816
  getOrgsByUserId,
1792
1817
  updateStatusByUserId,
@@ -2481,8 +2506,9 @@ function useRoleRepo() {
2481
2506
  throw new import_nodejs_utils10.BadRequestError("Invalid ID.");
2482
2507
  }
2483
2508
  try {
2484
- await collection.deleteOne(
2509
+ await collection.updateOne(
2485
2510
  { _id },
2511
+ { $set: { status: "deleted", updateAt: /* @__PURE__ */ new Date() } },
2486
2512
  {
2487
2513
  session
2488
2514
  }
@@ -2908,7 +2934,6 @@ function useAuthController() {
2908
2934
  level: "error",
2909
2935
  message: `Error during login: ${error2.message}`
2910
2936
  });
2911
- console.log(`Error during login: ${error2}`);
2912
2937
  if (error2 instanceof import_nodejs_utils12.AppError) {
2913
2938
  next(error2);
2914
2939
  } else {
@@ -3713,8 +3738,210 @@ function useOrgController() {
3713
3738
  }
3714
3739
 
3715
3740
  // src/resources/role/role.controller.ts
3741
+ var import_joi8 = __toESM(require("joi"));
3742
+ var import_nodejs_utils20 = require("@eeplatform/nodejs-utils");
3743
+
3744
+ // src/resources/role/role.service.ts
3745
+ var import_nodejs_utils19 = require("@eeplatform/nodejs-utils");
3746
+ var import_joi7 = __toESM(require("joi"));
3747
+
3748
+ // src/resources/member/member.controller.ts
3716
3749
  var import_joi6 = __toESM(require("joi"));
3717
3750
  var import_nodejs_utils18 = require("@eeplatform/nodejs-utils");
3751
+ function useMemberController() {
3752
+ const {
3753
+ getByUserId: _getByUserId,
3754
+ getAll: _getAll,
3755
+ getOrgsByMembership: _getOrgsByMembership,
3756
+ updateStatusByUserId: _updateStatusByUserId,
3757
+ getByUserType: _getByUserType
3758
+ } = useMemberRepo();
3759
+ async function getByUserId(req, res, next) {
3760
+ const userId = req.params.id;
3761
+ const validation = import_joi6.default.object({
3762
+ id: import_joi6.default.string().hex().required()
3763
+ });
3764
+ const { error } = validation.validate({ id: userId });
3765
+ if (error) {
3766
+ next(new import_nodejs_utils18.BadRequestError(error.message));
3767
+ return;
3768
+ }
3769
+ try {
3770
+ const member = await _getByUserId(userId);
3771
+ if (!member) {
3772
+ res.status(404).json({ message: "Member not found." });
3773
+ return;
3774
+ }
3775
+ res.json(member);
3776
+ } catch (error2) {
3777
+ next(error2);
3778
+ }
3779
+ }
3780
+ async function getByUserType(req, res, next) {
3781
+ const validation = import_joi6.default.object({
3782
+ org: import_joi6.default.string().hex().optional().allow("", null),
3783
+ user: import_joi6.default.string().hex().required(),
3784
+ type: import_joi6.default.string().required()
3785
+ });
3786
+ const { error } = validation.validate({ ...req.params, ...req.query });
3787
+ if (error) {
3788
+ next(new import_nodejs_utils18.BadRequestError(error.message));
3789
+ return;
3790
+ }
3791
+ const orgId = req.query.org;
3792
+ const userId = req.params.user;
3793
+ const type = req.params.type;
3794
+ try {
3795
+ const member = await _getByUserType(userId, type, orgId);
3796
+ if (!member) {
3797
+ res.status(404).json({ message: "Member not found." });
3798
+ return;
3799
+ }
3800
+ res.json(member);
3801
+ } catch (error2) {
3802
+ next(error2);
3803
+ }
3804
+ }
3805
+ async function getAll(req, res, next) {
3806
+ const limit = Number(req.query.limit) ?? 10;
3807
+ const search = req.query.search ?? "";
3808
+ const page = Number(req.query.page) ?? 1;
3809
+ const user = req.query.user ?? "";
3810
+ const org = req.query.org ?? "";
3811
+ const type = req.query.type ?? "main";
3812
+ const status = req.query.status ?? "active";
3813
+ const validation = import_joi6.default.object({
3814
+ limit: import_joi6.default.number().min(10).max(300).required(),
3815
+ search: import_joi6.default.string().optional().allow("", null),
3816
+ page: import_joi6.default.number().required(),
3817
+ user: import_joi6.default.string().hex().optional().allow("", null),
3818
+ org: import_joi6.default.string().hex().optional().allow("", null),
3819
+ type: import_joi6.default.string().required(),
3820
+ status: import_joi6.default.string().required()
3821
+ });
3822
+ const { error } = validation.validate({
3823
+ search,
3824
+ page,
3825
+ user,
3826
+ org,
3827
+ type,
3828
+ limit,
3829
+ status
3830
+ });
3831
+ if (error) {
3832
+ next(new import_nodejs_utils18.BadRequestError(error.message));
3833
+ return;
3834
+ }
3835
+ try {
3836
+ const items = await _getAll({
3837
+ search,
3838
+ page,
3839
+ user,
3840
+ org,
3841
+ type,
3842
+ limit,
3843
+ status
3844
+ });
3845
+ res.json(items);
3846
+ return;
3847
+ } catch (error2) {
3848
+ next(error2);
3849
+ }
3850
+ }
3851
+ async function getOrgsByMembership(req, res, next) {
3852
+ const limit = Number(req.query.limit) ?? 10;
3853
+ const search = req.query.search ?? "";
3854
+ const page = Number(req.query.page) ?? 1;
3855
+ const user = req.query.user ?? "";
3856
+ const validation = import_joi6.default.object({
3857
+ limit: import_joi6.default.number().min(10).max(50).required(),
3858
+ search: import_joi6.default.string().optional().allow("", null),
3859
+ page: import_joi6.default.number().required(),
3860
+ user: import_joi6.default.string().hex().optional().allow("", null)
3861
+ });
3862
+ const { error } = validation.validate({
3863
+ search,
3864
+ page,
3865
+ user,
3866
+ limit
3867
+ });
3868
+ if (error) {
3869
+ next(new import_nodejs_utils18.BadRequestError(error.message));
3870
+ }
3871
+ try {
3872
+ const items = await _getOrgsByMembership({
3873
+ search,
3874
+ page,
3875
+ user,
3876
+ limit
3877
+ });
3878
+ res.json(items);
3879
+ return;
3880
+ } catch (error2) {
3881
+ next(error2);
3882
+ }
3883
+ }
3884
+ async function updateStatusByUserId(req, res, next) {
3885
+ const validation = import_joi6.default.object({
3886
+ id: import_joi6.default.string().hex().required(),
3887
+ status: import_joi6.default.string().valid("active", "suspended", "deleted").required()
3888
+ });
3889
+ const { error } = validation.validate(req.params);
3890
+ if (error) {
3891
+ next(new import_nodejs_utils18.BadRequestError(error.message));
3892
+ return;
3893
+ }
3894
+ const id = req.params.id;
3895
+ const status = req.params.status;
3896
+ try {
3897
+ const message = await _updateStatusByUserId(id, status);
3898
+ res.json({ message });
3899
+ } catch (error2) {
3900
+ next(error2);
3901
+ }
3902
+ }
3903
+ return {
3904
+ getByUserId,
3905
+ getAll,
3906
+ getOrgsByMembership,
3907
+ updateStatusByUserId,
3908
+ getByUserType
3909
+ };
3910
+ }
3911
+
3912
+ // src/resources/role/role.service.ts
3913
+ function useRoleService() {
3914
+ const { getByOrg } = useMemberRepo();
3915
+ const { deleteRole, getRoleById } = useRoleRepo();
3916
+ async function deleteById(_id) {
3917
+ const { error } = import_joi7.default.string().hex().length(24).validate(_id);
3918
+ if (error) {
3919
+ throw new import_nodejs_utils19.BadRequestError("Invalid Role ID");
3920
+ }
3921
+ try {
3922
+ const role = await getRoleById(_id);
3923
+ if (!role) {
3924
+ throw new import_nodejs_utils19.BadRequestError("Role not found");
3925
+ }
3926
+ const org = await getByOrg(String(role.id));
3927
+ if (org) {
3928
+ throw new import_nodejs_utils19.BadRequestError("Cannot delete role assigned to members");
3929
+ }
3930
+ await deleteRole(_id);
3931
+ return "Role deleted successfully";
3932
+ } catch (error2) {
3933
+ if (error2 instanceof import_nodejs_utils19.AppError) {
3934
+ throw error2;
3935
+ }
3936
+ throw new import_nodejs_utils19.InternalServerError("Failed to delete role");
3937
+ }
3938
+ }
3939
+ return {
3940
+ deleteById
3941
+ };
3942
+ }
3943
+
3944
+ // src/resources/role/role.controller.ts
3718
3945
  function useRoleController() {
3719
3946
  const {
3720
3947
  addRole: _createRole,
@@ -3722,20 +3949,19 @@ function useRoleController() {
3722
3949
  getRoleByUserId: _getRoleByUserId,
3723
3950
  getRoles: _getRoles,
3724
3951
  updateRole: _updateRole,
3725
- deleteRole: _deleteRole,
3726
3952
  updatePermissionsById: _updatePermissionsById
3727
3953
  } = useRoleRepo();
3728
3954
  async function createRole(req, res, next) {
3729
3955
  const payload = req.body;
3730
- const validation = import_joi6.default.object({
3731
- name: import_joi6.default.string().required(),
3732
- permissions: import_joi6.default.array().items(import_joi6.default.string()).required(),
3733
- type: import_joi6.default.string().valid("school", "division", "region", "account").required(),
3734
- id: import_joi6.default.string().hex().optional().allow("", null)
3956
+ const validation = import_joi8.default.object({
3957
+ name: import_joi8.default.string().required(),
3958
+ permissions: import_joi8.default.array().items(import_joi8.default.string()).required(),
3959
+ type: import_joi8.default.string().valid("school", "division", "region", "account").required(),
3960
+ id: import_joi8.default.string().hex().optional().allow("", null)
3735
3961
  });
3736
3962
  const { error } = validation.validate(payload);
3737
3963
  if (error) {
3738
- next(new import_nodejs_utils18.BadRequestError(error.message));
3964
+ next(new import_nodejs_utils20.BadRequestError(error.message));
3739
3965
  return;
3740
3966
  }
3741
3967
  try {
@@ -3752,16 +3978,16 @@ function useRoleController() {
3752
3978
  const limit = parseInt(req.query.limit ?? "10");
3753
3979
  const type = req.query.type ?? "";
3754
3980
  const id = req.query.id ?? "";
3755
- const validation = import_joi6.default.object({
3756
- search: import_joi6.default.string().optional().allow("", null),
3757
- page: import_joi6.default.number().required(),
3758
- limit: import_joi6.default.number().required(),
3759
- type: import_joi6.default.string().optional().allow("", null),
3760
- id: import_joi6.default.string().hex().optional().allow("", null)
3981
+ const validation = import_joi8.default.object({
3982
+ search: import_joi8.default.string().optional().allow("", null),
3983
+ page: import_joi8.default.number().required(),
3984
+ limit: import_joi8.default.number().required(),
3985
+ type: import_joi8.default.string().optional().allow("", null),
3986
+ id: import_joi8.default.string().hex().optional().allow("", null)
3761
3987
  });
3762
3988
  const { error } = validation.validate({ search, page, limit, type, id });
3763
3989
  if (error) {
3764
- next(new import_nodejs_utils18.BadRequestError(error.message));
3990
+ next(new import_nodejs_utils20.BadRequestError(error.message));
3765
3991
  return;
3766
3992
  }
3767
3993
  try {
@@ -3774,12 +4000,12 @@ function useRoleController() {
3774
4000
  }
3775
4001
  async function getRoleByUserId(req, res, next) {
3776
4002
  const userId = req.params.userId;
3777
- const validation = import_joi6.default.object({
3778
- userId: import_joi6.default.string().required()
4003
+ const validation = import_joi8.default.object({
4004
+ userId: import_joi8.default.string().required()
3779
4005
  });
3780
4006
  const { error } = validation.validate({ userId });
3781
4007
  if (error) {
3782
- next(new import_nodejs_utils18.BadRequestError(error.message));
4008
+ next(new import_nodejs_utils20.BadRequestError(error.message));
3783
4009
  return;
3784
4010
  }
3785
4011
  try {
@@ -3792,12 +4018,12 @@ function useRoleController() {
3792
4018
  }
3793
4019
  async function getRoleById(req, res, next) {
3794
4020
  const _id = req.params.id;
3795
- const validation = import_joi6.default.object({
3796
- _id: import_joi6.default.string().hex().required()
4021
+ const validation = import_joi8.default.object({
4022
+ _id: import_joi8.default.string().hex().required()
3797
4023
  });
3798
4024
  const { error } = validation.validate({ _id });
3799
4025
  if (error) {
3800
- next(new import_nodejs_utils18.BadRequestError(error.message));
4026
+ next(new import_nodejs_utils20.BadRequestError(error.message));
3801
4027
  return;
3802
4028
  }
3803
4029
  try {
@@ -3812,14 +4038,14 @@ function useRoleController() {
3812
4038
  const _id = req.params.id;
3813
4039
  const name = req.body.name ?? "";
3814
4040
  const permissions = req.body.permissions ?? [];
3815
- const validation = import_joi6.default.object({
3816
- _id: import_joi6.default.string().required(),
3817
- name: import_joi6.default.string().required(),
3818
- permissions: import_joi6.default.array().items(import_joi6.default.string()).required()
4041
+ const validation = import_joi8.default.object({
4042
+ _id: import_joi8.default.string().required(),
4043
+ name: import_joi8.default.string().required(),
4044
+ permissions: import_joi8.default.array().items(import_joi8.default.string()).required()
3819
4045
  });
3820
4046
  const { error } = validation.validate({ _id, name, permissions });
3821
4047
  if (error) {
3822
- next(new import_nodejs_utils18.BadRequestError(error.message));
4048
+ next(new import_nodejs_utils20.BadRequestError(error.message));
3823
4049
  return;
3824
4050
  }
3825
4051
  try {
@@ -3833,13 +4059,13 @@ function useRoleController() {
3833
4059
  async function updatePermissionsById(req, res, next) {
3834
4060
  const _id = req.params.id;
3835
4061
  const permissions = req.body.permissions ?? [];
3836
- const validation = import_joi6.default.object({
3837
- _id: import_joi6.default.string().required(),
3838
- permissions: import_joi6.default.array().items(import_joi6.default.string()).required()
4062
+ const validation = import_joi8.default.object({
4063
+ _id: import_joi8.default.string().required(),
4064
+ permissions: import_joi8.default.array().items(import_joi8.default.string()).required()
3839
4065
  });
3840
4066
  const { error } = validation.validate({ _id, permissions });
3841
4067
  if (error) {
3842
- next(new import_nodejs_utils18.BadRequestError(error.message));
4068
+ next(new import_nodejs_utils20.BadRequestError(error.message));
3843
4069
  return;
3844
4070
  }
3845
4071
  try {
@@ -3850,18 +4076,19 @@ function useRoleController() {
3850
4076
  next(error2);
3851
4077
  }
3852
4078
  }
4079
+ const { deleteById } = useRoleService();
3853
4080
  async function deleteRole(req, res, next) {
3854
4081
  const _id = req.params.id;
3855
- const validation = import_joi6.default.object({
3856
- _id: import_joi6.default.string().required()
4082
+ const validation = import_joi8.default.object({
4083
+ _id: import_joi8.default.string().required()
3857
4084
  });
3858
4085
  const { error } = validation.validate({ _id });
3859
4086
  if (error) {
3860
- next(new import_nodejs_utils18.BadRequestError(error.message));
4087
+ next(new import_nodejs_utils20.BadRequestError(error.message));
3861
4088
  return;
3862
4089
  }
3863
4090
  try {
3864
- const message = await _deleteRole(_id);
4091
+ const message = await deleteById(_id);
3865
4092
  res.json({ message });
3866
4093
  return;
3867
4094
  } catch (error2) {
@@ -3880,7 +4107,7 @@ function useRoleController() {
3880
4107
  }
3881
4108
 
3882
4109
  // src/resources/file/file.service.ts
3883
- var import_nodejs_utils19 = require("@eeplatform/nodejs-utils");
4110
+ var import_nodejs_utils21 = require("@eeplatform/nodejs-utils");
3884
4111
  var import_node_cron = __toESM(require("node-cron"));
3885
4112
  var fs = __toESM(require("fs"));
3886
4113
  function useFileService() {
@@ -3889,7 +4116,7 @@ function useFileService() {
3889
4116
  deleteFileById,
3890
4117
  getAllDraftedFiles
3891
4118
  } = useFileRepo();
3892
- const s3 = new import_nodejs_utils19.useS3({
4119
+ const s3 = new import_nodejs_utils21.useS3({
3893
4120
  accessKeyId: SPACES_ACCESS_KEY,
3894
4121
  secretAccessKey: SPACES_SECRET_KEY,
3895
4122
  endpoint: SPACES_ENDPOINT,
@@ -3898,7 +4125,7 @@ function useFileService() {
3898
4125
  forcePathStyle: true
3899
4126
  });
3900
4127
  async function createFile(value) {
3901
- const session = import_nodejs_utils19.useAtlas.getClient()?.startSession();
4128
+ const session = import_nodejs_utils21.useAtlas.getClient()?.startSession();
3902
4129
  session?.startTransaction();
3903
4130
  const file = {
3904
4131
  name: value.originalname,
@@ -3932,7 +4159,7 @@ function useFileService() {
3932
4159
  }
3933
4160
  }
3934
4161
  async function deleteFile(id) {
3935
- const session = import_nodejs_utils19.useAtlas.getClient()?.startSession();
4162
+ const session = import_nodejs_utils21.useAtlas.getClient()?.startSession();
3936
4163
  session?.startTransaction();
3937
4164
  try {
3938
4165
  await deleteFileById(id, session);
@@ -3953,12 +4180,12 @@ function useFileService() {
3953
4180
  const file = files[index];
3954
4181
  try {
3955
4182
  await deleteFile(file._id.toString());
3956
- await import_nodejs_utils19.logger.log({
4183
+ await import_nodejs_utils21.logger.log({
3957
4184
  level: "info",
3958
4185
  message: "Successfully deleted draft files."
3959
4186
  });
3960
4187
  } catch (error) {
3961
- import_nodejs_utils19.logger.log({
4188
+ import_nodejs_utils21.logger.log({
3962
4189
  level: "info",
3963
4190
  message: "Successfully deleted draft files."
3964
4191
  });
@@ -3975,8 +4202,8 @@ function useFileService() {
3975
4202
  }
3976
4203
 
3977
4204
  // src/resources/file/file.controller.ts
3978
- var import_nodejs_utils20 = require("@eeplatform/nodejs-utils");
3979
- var import_joi7 = __toESM(require("joi"));
4205
+ var import_nodejs_utils22 = require("@eeplatform/nodejs-utils");
4206
+ var import_joi9 = __toESM(require("joi"));
3980
4207
  function useFileController() {
3981
4208
  const { createFile, deleteFile: _deleteFile } = useFileService();
3982
4209
  async function upload(req, res, next) {
@@ -3989,29 +4216,29 @@ function useFileController() {
3989
4216
  res.json({ message: "Successfully uploaded file", id });
3990
4217
  return;
3991
4218
  } catch (error) {
3992
- if (error instanceof import_nodejs_utils20.AppError) {
4219
+ if (error instanceof import_nodejs_utils22.AppError) {
3993
4220
  next(error);
3994
4221
  } else {
3995
- next(new import_nodejs_utils20.InternalServerError(error));
4222
+ next(new import_nodejs_utils22.InternalServerError(error));
3996
4223
  }
3997
4224
  }
3998
4225
  }
3999
4226
  async function deleteFile(req, res, next) {
4000
4227
  const id = req.params.id;
4001
- const validation = import_joi7.default.string().required();
4228
+ const validation = import_joi9.default.string().required();
4002
4229
  const { error } = validation.validate(id);
4003
4230
  if (error) {
4004
- next(new import_nodejs_utils20.BadRequestError(error.message));
4231
+ next(new import_nodejs_utils22.BadRequestError(error.message));
4005
4232
  }
4006
4233
  try {
4007
4234
  const message = await _deleteFile(id);
4008
4235
  res.json({ message });
4009
4236
  return;
4010
4237
  } catch (error2) {
4011
- if (error2 instanceof import_nodejs_utils20.AppError) {
4238
+ if (error2 instanceof import_nodejs_utils22.AppError) {
4012
4239
  next(error2);
4013
4240
  } else {
4014
- next(new import_nodejs_utils20.InternalServerError(error2));
4241
+ next(new import_nodejs_utils22.InternalServerError(error2));
4015
4242
  }
4016
4243
  }
4017
4244
  }
@@ -4022,8 +4249,8 @@ function useFileController() {
4022
4249
  }
4023
4250
 
4024
4251
  // src/resources/verification/verification.controller.ts
4025
- var import_nodejs_utils21 = require("@eeplatform/nodejs-utils");
4026
- var import_joi8 = __toESM(require("joi"));
4252
+ var import_nodejs_utils23 = require("@eeplatform/nodejs-utils");
4253
+ var import_joi10 = __toESM(require("joi"));
4027
4254
  function useVerificationController() {
4028
4255
  const {
4029
4256
  createUserInvite: _createUserInvite,
@@ -4033,17 +4260,17 @@ function useVerificationController() {
4033
4260
  } = useVerificationService();
4034
4261
  const { getVerifications: _getVerifications } = useVerificationRepo();
4035
4262
  async function createUserInvite(req, res, next) {
4036
- const validation = import_joi8.default.object({
4037
- email: import_joi8.default.string().email().required(),
4038
- app: import_joi8.default.string().required(),
4039
- role: import_joi8.default.string().hex().required(),
4040
- roleName: import_joi8.default.string().required(),
4041
- org: import_joi8.default.string().hex().optional().optional().allow("", null),
4042
- orgName: import_joi8.default.string().optional().optional().allow("", null)
4263
+ const validation = import_joi10.default.object({
4264
+ email: import_joi10.default.string().email().required(),
4265
+ app: import_joi10.default.string().required(),
4266
+ role: import_joi10.default.string().hex().required(),
4267
+ roleName: import_joi10.default.string().required(),
4268
+ org: import_joi10.default.string().hex().optional().optional().allow("", null),
4269
+ orgName: import_joi10.default.string().optional().optional().allow("", null)
4043
4270
  });
4044
4271
  const { error } = validation.validate(req.body);
4045
4272
  if (error) {
4046
- next(new import_nodejs_utils21.BadRequestError(error.message));
4273
+ next(new import_nodejs_utils23.BadRequestError(error.message));
4047
4274
  return;
4048
4275
  }
4049
4276
  const email = req.body.email ?? "";
@@ -4071,10 +4298,10 @@ function useVerificationController() {
4071
4298
  }
4072
4299
  async function createForgetPassword(req, res, next) {
4073
4300
  const email = req.body.email || "";
4074
- const validation = import_joi8.default.string().email().required();
4301
+ const validation = import_joi10.default.string().email().required();
4075
4302
  const { error } = validation.validate(email);
4076
4303
  if (error) {
4077
- next(new import_nodejs_utils21.BadRequestError(error.message));
4304
+ next(new import_nodejs_utils23.BadRequestError(error.message));
4078
4305
  return;
4079
4306
  }
4080
4307
  try {
@@ -4084,25 +4311,25 @@ function useVerificationController() {
4084
4311
  });
4085
4312
  return;
4086
4313
  } catch (error2) {
4087
- if (error2 instanceof import_nodejs_utils21.AppError) {
4314
+ if (error2 instanceof import_nodejs_utils23.AppError) {
4088
4315
  next(error2);
4089
4316
  } else {
4090
- next(new import_nodejs_utils21.InternalServerError("An unexpected error occurred"));
4317
+ next(new import_nodejs_utils23.InternalServerError("An unexpected error occurred"));
4091
4318
  }
4092
4319
  }
4093
4320
  }
4094
4321
  async function getVerifications(req, res, next) {
4095
- const validation = import_joi8.default.object({
4096
- status: import_joi8.default.string().required(),
4097
- search: import_joi8.default.string().optional().allow("", null),
4098
- page: import_joi8.default.number().required(),
4099
- type: import_joi8.default.string().optional().allow("", null),
4100
- email: import_joi8.default.string().optional().allow("", null),
4101
- app: import_joi8.default.string().optional().allow("", null)
4322
+ const validation = import_joi10.default.object({
4323
+ status: import_joi10.default.string().required(),
4324
+ search: import_joi10.default.string().optional().allow("", null),
4325
+ page: import_joi10.default.number().required(),
4326
+ type: import_joi10.default.string().optional().allow("", null),
4327
+ email: import_joi10.default.string().optional().allow("", null),
4328
+ app: import_joi10.default.string().optional().allow("", null)
4102
4329
  });
4103
4330
  const { error } = validation.validate(req.query);
4104
4331
  if (error) {
4105
- next(new import_nodejs_utils21.BadRequestError(error.message));
4332
+ next(new import_nodejs_utils23.BadRequestError(error.message));
4106
4333
  return;
4107
4334
  }
4108
4335
  const status = req.query.status ?? "";
@@ -4133,10 +4360,10 @@ function useVerificationController() {
4133
4360
  }
4134
4361
  async function verify(req, res, next) {
4135
4362
  const id = req.params.id || "";
4136
- const validation = import_joi8.default.string().hex().required();
4363
+ const validation = import_joi10.default.string().hex().required();
4137
4364
  const { error } = validation.validate(id);
4138
4365
  if (error) {
4139
- next(new import_nodejs_utils21.BadRequestError(error.message));
4366
+ next(new import_nodejs_utils23.BadRequestError(error.message));
4140
4367
  return;
4141
4368
  }
4142
4369
  try {
@@ -4149,10 +4376,10 @@ function useVerificationController() {
4149
4376
  }
4150
4377
  async function cancelUserInvitation(req, res, next) {
4151
4378
  const otpId = req.params.id || "";
4152
- const validation = import_joi8.default.string().hex().required();
4379
+ const validation = import_joi10.default.string().hex().required();
4153
4380
  const { error } = validation.validate(otpId);
4154
4381
  if (error) {
4155
- next(new import_nodejs_utils21.BadRequestError(error.message));
4382
+ next(new import_nodejs_utils23.BadRequestError(error.message));
4156
4383
  return;
4157
4384
  }
4158
4385
  try {
@@ -4174,34 +4401,34 @@ function useVerificationController() {
4174
4401
  }
4175
4402
 
4176
4403
  // src/resources/address/address.model.ts
4177
- var import_nodejs_utils22 = require("@eeplatform/nodejs-utils");
4178
- var import_joi9 = __toESM(require("joi"));
4404
+ var import_nodejs_utils24 = require("@eeplatform/nodejs-utils");
4405
+ var import_joi11 = __toESM(require("joi"));
4179
4406
  var import_mongodb14 = require("mongodb");
4180
- var addressSchema = import_joi9.default.object({
4181
- type: import_joi9.default.string().required(),
4182
- user: import_joi9.default.string().hex().optional().allow("", null),
4183
- org: import_joi9.default.string().hex().optional().allow("", null),
4184
- country: import_joi9.default.string().required(),
4185
- address: import_joi9.default.string().required(),
4186
- continuedAddress: import_joi9.default.string().optional().allow("", null),
4187
- city: import_joi9.default.string().required(),
4188
- province: import_joi9.default.string().required(),
4189
- postalCode: import_joi9.default.string().required(),
4190
- taxId: import_joi9.default.string().optional().allow("", null)
4407
+ var addressSchema = import_joi11.default.object({
4408
+ type: import_joi11.default.string().required(),
4409
+ user: import_joi11.default.string().hex().optional().allow("", null),
4410
+ org: import_joi11.default.string().hex().optional().allow("", null),
4411
+ country: import_joi11.default.string().required(),
4412
+ address: import_joi11.default.string().required(),
4413
+ continuedAddress: import_joi11.default.string().optional().allow("", null),
4414
+ city: import_joi11.default.string().required(),
4415
+ province: import_joi11.default.string().required(),
4416
+ postalCode: import_joi11.default.string().required(),
4417
+ taxId: import_joi11.default.string().optional().allow("", null)
4191
4418
  });
4192
4419
  function MAddress(value) {
4193
4420
  if (value.user) {
4194
4421
  try {
4195
4422
  value.user = new import_mongodb14.ObjectId(value.user);
4196
4423
  } catch (error) {
4197
- throw new import_nodejs_utils22.BadRequestError("Invalid user ID.");
4424
+ throw new import_nodejs_utils24.BadRequestError("Invalid user ID.");
4198
4425
  }
4199
4426
  }
4200
4427
  if (value.org) {
4201
4428
  try {
4202
4429
  value.org = new import_mongodb14.ObjectId(value.org);
4203
4430
  } catch (error) {
4204
- throw new import_nodejs_utils22.BadRequestError("Invalid org ID.");
4431
+ throw new import_nodejs_utils24.BadRequestError("Invalid org ID.");
4205
4432
  }
4206
4433
  }
4207
4434
  return {
@@ -4219,1538 +4446,251 @@ function MAddress(value) {
4219
4446
  }
4220
4447
 
4221
4448
  // src/resources/address/address.repository.ts
4222
- var import_nodejs_utils23 = require("@eeplatform/nodejs-utils");
4449
+ var import_nodejs_utils25 = require("@eeplatform/nodejs-utils");
4223
4450
  var import_mongodb15 = require("mongodb");
4224
4451
  function useAddressRepo() {
4225
- const db = import_nodejs_utils23.useAtlas.getDb();
4452
+ const db = import_nodejs_utils25.useAtlas.getDb();
4226
4453
  if (!db) {
4227
- throw new import_nodejs_utils23.BadRequestError("Unable to connect to server.");
4454
+ throw new import_nodejs_utils25.BadRequestError("Unable to connect to server.");
4228
4455
  }
4229
4456
  const namespace_collection = "addresses";
4230
4457
  const collection = db.collection(namespace_collection);
4231
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils23.useCache)(namespace_collection);
4458
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils25.useCache)(namespace_collection);
4232
4459
  function delCachedData() {
4233
4460
  delNamespace().then(() => {
4234
- import_nodejs_utils23.logger.log({
4461
+ import_nodejs_utils25.logger.log({
4235
4462
  level: "info",
4236
4463
  message: `Cache namespace cleared for ${namespace_collection}`
4237
4464
  });
4238
4465
  }).catch((err) => {
4239
- import_nodejs_utils23.logger.log({
4466
+ import_nodejs_utils25.logger.log({
4240
4467
  level: "error",
4241
4468
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
4242
4469
  });
4243
4470
  });
4244
4471
  }
4245
4472
  async function createIndex() {
4246
- try {
4247
- await collection.createIndexes([
4248
- { key: { user: 1 } },
4249
- { key: { type: 1 } },
4250
- { key: { orgId: 1 } }
4251
- ]);
4252
- } catch (error) {
4253
- throw new import_nodejs_utils23.BadRequestError("Failed to create index on address.");
4254
- }
4255
- }
4256
- async function add(value, session) {
4257
- try {
4258
- value = MAddress(value);
4259
- const res = await collection.insertOne(value, { session });
4260
- delCachedData();
4261
- return res.insertedId;
4262
- } catch (error) {
4263
- throw new import_nodejs_utils23.BadRequestError("Failed to create address.");
4264
- }
4265
- }
4266
- async function updateById(_id, value, session) {
4267
- try {
4268
- _id = new import_mongodb15.ObjectId(_id);
4269
- } catch (error) {
4270
- throw new import_nodejs_utils23.BadRequestError("Invalid address ID.");
4271
- }
4272
- if (value.org) {
4273
- try {
4274
- value.org = new import_mongodb15.ObjectId(value.org);
4275
- } catch (error) {
4276
- throw new import_nodejs_utils23.BadRequestError("Invalid org ID.");
4277
- }
4278
- }
4279
- try {
4280
- await collection.updateOne(
4281
- { _id },
4282
- { $set: value },
4283
- { session, upsert: true }
4284
- );
4285
- delCachedData();
4286
- return "Successfully updated address.";
4287
- } catch (error) {
4288
- throw new import_nodejs_utils23.BadRequestError("Failed to update address.");
4289
- }
4290
- }
4291
- async function getByUserId(user) {
4292
- try {
4293
- user = new import_mongodb15.ObjectId(user);
4294
- } catch (error) {
4295
- throw new import_nodejs_utils23.BadRequestError("Invalid user ID.");
4296
- }
4297
- const cacheKey = (0, import_nodejs_utils23.makeCacheKey)(namespace_collection, { user: String(user) });
4298
- try {
4299
- const cached = await getCache(cacheKey);
4300
- if (cached) {
4301
- import_nodejs_utils23.logger.log({
4302
- level: "info",
4303
- message: `Cache hit for getByUserId address: ${cacheKey}`
4304
- });
4305
- return cached;
4306
- }
4307
- const data = await collection.findOne({ user });
4308
- if (data) {
4309
- setCache(cacheKey, data, 300).then(() => {
4310
- import_nodejs_utils23.logger.log({
4311
- level: "info",
4312
- message: `Cache set for address by user ID: ${cacheKey}`
4313
- });
4314
- }).catch((err) => {
4315
- import_nodejs_utils23.logger.log({
4316
- level: "error",
4317
- message: `Failed to set cache for address by user ID: ${err.message}`
4318
- });
4319
- });
4320
- }
4321
- return data;
4322
- } catch (error) {
4323
- throw new import_nodejs_utils23.BadRequestError("Failed to get address by ID.");
4324
- }
4325
- }
4326
- async function getByOrgId(org) {
4327
- try {
4328
- org = new import_mongodb15.ObjectId(org);
4329
- } catch (error) {
4330
- throw new import_nodejs_utils23.BadRequestError("Invalid orgId.");
4331
- }
4332
- const cacheKey = (0, import_nodejs_utils23.makeCacheKey)(namespace_collection, { org: String(org) });
4333
- try {
4334
- const cached = await getCache(cacheKey);
4335
- if (cached) {
4336
- import_nodejs_utils23.logger.log({
4337
- level: "info",
4338
- message: `Cache hit for getByOrgId address: ${cacheKey}`
4339
- });
4340
- return cached;
4341
- }
4342
- const data = await collection.findOne({ org });
4343
- if (data) {
4344
- setCache(cacheKey, data, 300).then(() => {
4345
- import_nodejs_utils23.logger.log({
4346
- level: "info",
4347
- message: `Cache set for address by org ID: ${cacheKey}`
4348
- });
4349
- }).catch((err) => {
4350
- import_nodejs_utils23.logger.log({
4351
- level: "error",
4352
- message: `Failed to set cache for address by org ID: ${err.message}`
4353
- });
4354
- });
4355
- }
4356
- return data;
4357
- } catch (error) {
4358
- throw new import_nodejs_utils23.BadRequestError("Failed to get address by orgId.");
4359
- }
4360
- }
4361
- return {
4362
- createIndex,
4363
- add,
4364
- getByUserId,
4365
- getByOrgId,
4366
- updateById
4367
- };
4368
- }
4369
-
4370
- // src/resources/address/address.controller.ts
4371
- var import_nodejs_utils24 = require("@eeplatform/nodejs-utils");
4372
- var import_joi10 = __toESM(require("joi"));
4373
- function useAddressController() {
4374
- const {
4375
- add: _add,
4376
- getByUserId: _getByUserId,
4377
- getByOrgId: _getByOrgId,
4378
- updateById: _updateById
4379
- } = useAddressRepo();
4380
- async function add(req, res, next) {
4381
- const value = req.body;
4382
- const validation = import_joi10.default.object({
4383
- type: import_joi10.default.string().required(),
4384
- user: import_joi10.default.string().hex().optional().allow("", null),
4385
- org: import_joi10.default.string().hex().optional().allow("", null),
4386
- country: import_joi10.default.string().required(),
4387
- address: import_joi10.default.string().required(),
4388
- continuedAddress: import_joi10.default.string().optional().allow("", null),
4389
- city: import_joi10.default.string().required(),
4390
- province: import_joi10.default.string().required(),
4391
- postalCode: import_joi10.default.string().required(),
4392
- taxId: import_joi10.default.string().optional().allow("", null)
4393
- });
4394
- const { error } = validation.validate(value);
4395
- if (error) {
4396
- next(new import_nodejs_utils24.BadRequestError(error.message));
4397
- }
4398
- try {
4399
- const value2 = req.body;
4400
- const id = await _add(value2);
4401
- res.json({ message: "Successfully added subscription.", id });
4402
- return;
4403
- } catch (error2) {
4404
- next(error2);
4405
- }
4406
- }
4407
- async function updateById(req, res, next) {
4408
- const id = req.params.id ?? "";
4409
- const value = req.body;
4410
- const validation = import_joi10.default.object({
4411
- id: import_joi10.default.string().hex().required(),
4412
- country: import_joi10.default.string().required(),
4413
- address: import_joi10.default.string().required(),
4414
- continuedAddress: import_joi10.default.string().optional().allow("", null),
4415
- city: import_joi10.default.string().required(),
4416
- province: import_joi10.default.string().required(),
4417
- postalCode: import_joi10.default.string().required(),
4418
- taxId: import_joi10.default.string().optional().allow("", null),
4419
- org: import_joi10.default.string().hex().optional().allow("", null)
4420
- });
4421
- const { error } = validation.validate({ id, ...value });
4422
- if (error) {
4423
- next(new import_nodejs_utils24.BadRequestError(error.message));
4424
- return;
4425
- }
4426
- try {
4427
- const message = await _updateById(id, value);
4428
- res.json({ message });
4429
- return;
4430
- } catch (error2) {
4431
- next(error2);
4432
- }
4433
- }
4434
- async function getByUserId(req, res, next) {
4435
- const user = req.params.user;
4436
- const validation = import_joi10.default.string().hex().required();
4437
- const { error } = validation.validate(user);
4438
- if (error) {
4439
- next(new import_nodejs_utils24.BadRequestError(error.message));
4440
- }
4441
- try {
4442
- const address = await _getByUserId(user);
4443
- if (!address) {
4444
- next(new import_nodejs_utils24.NotFoundError("Address not found."));
4445
- return;
4446
- }
4447
- res.json(address);
4448
- return;
4449
- } catch (error2) {
4450
- next(error2);
4451
- }
4452
- }
4453
- async function getByOrgId(req, res, next) {
4454
- const id = req.params.id;
4455
- const validation = import_joi10.default.string().hex().required();
4456
- const { error } = validation.validate(id);
4457
- if (error) {
4458
- next(new import_nodejs_utils24.BadRequestError(error.message));
4459
- }
4460
- try {
4461
- const address = await _getByOrgId(id);
4462
- if (!address) {
4463
- next(new import_nodejs_utils24.NotFoundError("Address not found."));
4464
- return;
4465
- }
4466
- res.json(address);
4467
- return;
4468
- } catch (error2) {
4469
- next(error2);
4470
- }
4471
- }
4472
- return {
4473
- add,
4474
- getByUserId,
4475
- getByOrgId,
4476
- updateById
4477
- };
4478
- }
4479
-
4480
- // src/resources/member/member.controller.ts
4481
- var import_joi11 = __toESM(require("joi"));
4482
- var import_nodejs_utils25 = require("@eeplatform/nodejs-utils");
4483
- function useMemberController() {
4484
- const {
4485
- getByUserId: _getByUserId,
4486
- getAll: _getAll,
4487
- getOrgsByMembership: _getOrgsByMembership,
4488
- updateStatusByUserId: _updateStatusByUserId,
4489
- getByUserType: _getByUserType
4490
- } = useMemberRepo();
4491
- async function getByUserId(req, res, next) {
4492
- const userId = req.params.id;
4493
- const validation = import_joi11.default.object({
4494
- id: import_joi11.default.string().hex().required()
4495
- });
4496
- const { error } = validation.validate({ id: userId });
4497
- if (error) {
4498
- next(new import_nodejs_utils25.BadRequestError(error.message));
4499
- return;
4500
- }
4501
- try {
4502
- const member = await _getByUserId(userId);
4503
- if (!member) {
4504
- res.status(404).json({ message: "Member not found." });
4505
- return;
4506
- }
4507
- res.json(member);
4508
- } catch (error2) {
4509
- next(error2);
4510
- }
4511
- }
4512
- async function getByUserType(req, res, next) {
4513
- const validation = import_joi11.default.object({
4514
- org: import_joi11.default.string().hex().optional().allow("", null),
4515
- user: import_joi11.default.string().hex().required(),
4516
- type: import_joi11.default.string().required()
4517
- });
4518
- const { error } = validation.validate({ ...req.params, ...req.query });
4519
- if (error) {
4520
- next(new import_nodejs_utils25.BadRequestError(error.message));
4521
- return;
4522
- }
4523
- const orgId = req.query.org;
4524
- const userId = req.params.user;
4525
- const type = req.params.type;
4526
- try {
4527
- const member = await _getByUserType(userId, type, orgId);
4528
- if (!member) {
4529
- res.status(404).json({ message: "Member not found." });
4530
- return;
4531
- }
4532
- res.json(member);
4533
- } catch (error2) {
4534
- next(error2);
4535
- }
4536
- }
4537
- async function getAll(req, res, next) {
4538
- const limit = Number(req.query.limit) ?? 10;
4539
- const search = req.query.search ?? "";
4540
- const page = Number(req.query.page) ?? 1;
4541
- const user = req.query.user ?? "";
4542
- const org = req.query.org ?? "";
4543
- const type = req.query.type ?? "main";
4544
- const status = req.query.status ?? "active";
4545
- const validation = import_joi11.default.object({
4546
- limit: import_joi11.default.number().min(10).max(50).required(),
4547
- search: import_joi11.default.string().optional().allow("", null),
4548
- page: import_joi11.default.number().required(),
4549
- user: import_joi11.default.string().hex().optional().allow("", null),
4550
- org: import_joi11.default.string().hex().optional().allow("", null),
4551
- type: import_joi11.default.string().required(),
4552
- status: import_joi11.default.string().required()
4553
- });
4554
- const { error } = validation.validate({
4555
- search,
4556
- page,
4557
- user,
4558
- org,
4559
- type,
4560
- limit,
4561
- status
4562
- });
4563
- if (error) {
4564
- next(new import_nodejs_utils25.BadRequestError(error.message));
4565
- return;
4566
- }
4567
- try {
4568
- const items = await _getAll({
4569
- search,
4570
- page,
4571
- user,
4572
- org,
4573
- type,
4574
- limit,
4575
- status
4576
- });
4577
- res.json(items);
4578
- return;
4579
- } catch (error2) {
4580
- next(error2);
4581
- }
4582
- }
4583
- async function getOrgsByMembership(req, res, next) {
4584
- const limit = Number(req.query.limit) ?? 10;
4585
- const search = req.query.search ?? "";
4586
- const page = Number(req.query.page) ?? 1;
4587
- const user = req.query.user ?? "";
4588
- const validation = import_joi11.default.object({
4589
- limit: import_joi11.default.number().min(10).max(50).required(),
4590
- search: import_joi11.default.string().optional().allow("", null),
4591
- page: import_joi11.default.number().required(),
4592
- user: import_joi11.default.string().hex().optional().allow("", null)
4593
- });
4594
- const { error } = validation.validate({
4595
- search,
4596
- page,
4597
- user,
4598
- limit
4599
- });
4600
- if (error) {
4601
- next(new import_nodejs_utils25.BadRequestError(error.message));
4602
- }
4603
- try {
4604
- const items = await _getOrgsByMembership({
4605
- search,
4606
- page,
4607
- user,
4608
- limit
4609
- });
4610
- res.json(items);
4611
- return;
4612
- } catch (error2) {
4613
- next(error2);
4614
- }
4615
- }
4616
- async function updateStatusByUserId(req, res, next) {
4617
- const validation = import_joi11.default.object({
4618
- id: import_joi11.default.string().hex().required(),
4619
- status: import_joi11.default.string().valid("active", "suspended", "deleted").required()
4620
- });
4621
- const { error } = validation.validate(req.params);
4622
- if (error) {
4623
- next(new import_nodejs_utils25.BadRequestError(error.message));
4624
- return;
4625
- }
4626
- const id = req.params.id;
4627
- const status = req.params.status;
4628
- try {
4629
- const message = await _updateStatusByUserId(id, status);
4630
- res.json({ message });
4631
- } catch (error2) {
4632
- next(error2);
4633
- }
4634
- }
4635
- return {
4636
- getByUserId,
4637
- getAll,
4638
- getOrgsByMembership,
4639
- updateStatusByUserId,
4640
- getByUserType
4641
- };
4642
- }
4643
-
4644
- // src/resources/building/building.model.ts
4645
- var import_nodejs_utils26 = require("@eeplatform/nodejs-utils");
4646
- var import_joi12 = __toESM(require("joi"));
4647
- var import_mongodb16 = require("mongodb");
4648
- var schemaBuilding = import_joi12.default.object({
4649
- _id: import_joi12.default.string().hex().optional(),
4650
- school: import_joi12.default.string().hex().required(),
4651
- serial: import_joi12.default.string().optional().allow("", null),
4652
- name: import_joi12.default.string().required(),
4653
- levels: import_joi12.default.number().integer().min(1).required(),
4654
- createdAt: import_joi12.default.date().optional().allow("", null),
4655
- updatedAt: import_joi12.default.date().optional().allow("", null),
4656
- deletedAt: import_joi12.default.date().optional().allow("", null),
4657
- status: import_joi12.default.string().optional().allow("", null)
4658
- });
4659
- var schemaBuildingUnit = import_joi12.default.object({
4660
- _id: import_joi12.default.string().hex().optional(),
4661
- school: import_joi12.default.string().hex().required(),
4662
- name: import_joi12.default.string().optional().allow("", null),
4663
- building: import_joi12.default.string().hex().required(),
4664
- buildingName: import_joi12.default.string().optional().allow("", null),
4665
- level: import_joi12.default.number().integer().min(1).required(),
4666
- category: import_joi12.default.string().required(),
4667
- type: import_joi12.default.string().required(),
4668
- seating_capacity: import_joi12.default.number().integer().min(0).required(),
4669
- standing_capacity: import_joi12.default.number().integer().min(0).required(),
4670
- description: import_joi12.default.string().optional().allow("", null),
4671
- unit_of_measurement: import_joi12.default.string().valid("sqm").required(),
4672
- area: import_joi12.default.number().positive().required(),
4673
- status: import_joi12.default.string().optional().allow("", null)
4674
- });
4675
- var schemaUpdateOptions = import_joi12.default.object({
4676
- name: import_joi12.default.string().optional().allow("", null),
4677
- building: import_joi12.default.string().hex().optional().allow("", null),
4678
- buildingName: import_joi12.default.string().optional().allow("", null),
4679
- level: import_joi12.default.number().integer().min(1).optional().allow("", null),
4680
- category: import_joi12.default.string().optional().allow("", null),
4681
- type: import_joi12.default.string().optional().allow("", null),
4682
- seating_capacity: import_joi12.default.number().integer().min(0).optional().allow("", null),
4683
- standing_capacity: import_joi12.default.number().integer().min(0).optional().allow("", null),
4684
- area: import_joi12.default.number().positive().optional().allow("", null)
4685
- });
4686
- function MBuilding(value) {
4687
- const { error } = schemaBuilding.validate(value);
4688
- if (error) {
4689
- import_nodejs_utils26.logger.info(`Building Model: ${error.message}`);
4690
- throw new import_nodejs_utils26.BadRequestError(error.message);
4691
- }
4692
- if (value._id && typeof value._id === "string") {
4693
- try {
4694
- value._id = new import_mongodb16.ObjectId(value._id);
4695
- } catch (error2) {
4696
- throw new import_nodejs_utils26.BadRequestError("Invalid _id format");
4697
- }
4698
- }
4699
- try {
4700
- value.school = new import_mongodb16.ObjectId(value.school);
4701
- } catch (error2) {
4702
- throw new import_nodejs_utils26.BadRequestError("Invalid school format");
4703
- }
4704
- return {
4705
- _id: value._id ?? void 0,
4706
- school: value.school,
4707
- serial: value.serial ?? "",
4708
- name: value.name ?? "",
4709
- levels: value.levels ?? 0,
4710
- status: value.status ?? "active",
4711
- createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
4712
- updatedAt: value.updatedAt ?? "",
4713
- deletedAt: value.deletedAt ?? ""
4714
- };
4715
- }
4716
- function MBuildingUnit(value) {
4717
- const { error } = schemaBuildingUnit.validate(value);
4718
- if (error) {
4719
- import_nodejs_utils26.logger.info(`Building Unit Model: ${error.message}`);
4720
- throw new import_nodejs_utils26.BadRequestError(error.message);
4721
- }
4722
- if (value._id && typeof value._id === "string") {
4723
- try {
4724
- value._id = new import_mongodb16.ObjectId(value._id);
4725
- } catch (error2) {
4726
- throw new import_nodejs_utils26.BadRequestError("Invalid ID");
4727
- }
4728
- }
4729
- try {
4730
- value.school = new import_mongodb16.ObjectId(value.school);
4731
- } catch (error2) {
4732
- throw new import_nodejs_utils26.BadRequestError("Invalid school ID");
4733
- }
4734
- try {
4735
- value.building = new import_mongodb16.ObjectId(value.building);
4736
- } catch (error2) {
4737
- throw new import_nodejs_utils26.BadRequestError("Invalid building ID");
4738
- }
4739
- return {
4740
- _id: value._id ?? void 0,
4741
- school: value.school,
4742
- name: value.name ?? "",
4743
- building: value.building,
4744
- buildingName: value.buildingName ?? "",
4745
- level: value.level ?? 0,
4746
- category: value.category ?? "",
4747
- type: value.type ?? "",
4748
- seating_capacity: value.seating_capacity ?? 0,
4749
- standing_capacity: value.standing_capacity ?? 0,
4750
- description: value.description ?? "",
4751
- unit_of_measurement: value.unit_of_measurement ?? "sqm",
4752
- area: value.area ?? 0,
4753
- status: value.status ?? "active",
4754
- createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
4755
- updatedAt: value.updatedAt ?? "",
4756
- deletedAt: value.deletedAt ?? ""
4757
- };
4758
- }
4759
-
4760
- // src/resources/building/building.repository.ts
4761
- var import_nodejs_utils27 = require("@eeplatform/nodejs-utils");
4762
- var import_mongodb17 = require("mongodb");
4763
- function useBuildingRepo() {
4764
- const db = import_nodejs_utils27.useAtlas.getDb();
4765
- if (!db) {
4766
- throw new Error("Unable to connect to server.");
4767
- }
4768
- const namespace_collection = "school.buildings";
4769
- const collection = db.collection(namespace_collection);
4770
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils27.useCache)(namespace_collection);
4771
- async function createIndexes() {
4772
- try {
4773
- await collection.createIndexes([
4774
- { key: { name: 1 }, unique: true, name: "unique_name_index" },
4775
- { key: { school: 1 } },
4776
- { key: { status: 1 } }
4777
- ]);
4778
- } catch (error) {
4779
- throw new Error("Failed to create index on buildings.");
4780
- }
4781
- }
4782
- async function add(value, session) {
4783
- try {
4784
- value = MBuilding(value);
4785
- const res = await collection.insertOne(value, { session });
4786
- delCachedData();
4787
- return res.insertedId;
4788
- } catch (error) {
4789
- import_nodejs_utils27.logger.log({
4790
- level: "error",
4791
- message: error.message
4792
- });
4793
- if (error instanceof import_nodejs_utils27.AppError) {
4794
- throw error;
4795
- } else {
4796
- const isDuplicated = error.message.includes("duplicate");
4797
- if (isDuplicated) {
4798
- throw new import_nodejs_utils27.BadRequestError("Building already exists.");
4799
- }
4800
- throw new Error("Failed to create building.");
4801
- }
4802
- }
4803
- }
4804
- async function updateById(_id, value, session) {
4805
- try {
4806
- _id = new import_mongodb17.ObjectId(_id);
4807
- } catch (error) {
4808
- throw new import_nodejs_utils27.BadRequestError("Invalid ID.");
4809
- }
4810
- try {
4811
- const res = await collection.updateOne(
4812
- { _id },
4813
- { $set: value },
4814
- { session }
4815
- );
4816
- delCachedData();
4817
- return res;
4818
- } catch (error) {
4819
- import_nodejs_utils27.logger.log({
4820
- level: "error",
4821
- message: error.message
4822
- });
4823
- if (error instanceof import_nodejs_utils27.AppError) {
4824
- throw error;
4825
- } else {
4826
- throw new Error("Failed to update building.");
4827
- }
4828
- }
4829
- }
4830
- async function getAll({
4831
- search = "",
4832
- page = 1,
4833
- limit = 10,
4834
- sort = {},
4835
- school = "",
4836
- status = "active"
4837
- } = {}) {
4838
- page = page > 0 ? page - 1 : 0;
4839
- const query = {
4840
- status
4841
- };
4842
- sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
4843
- if (search) {
4844
- query.$text = { $search: search };
4845
- }
4846
- if (school) {
4847
- try {
4848
- query.school = new import_mongodb17.ObjectId(school);
4849
- } catch (error) {
4850
- throw new import_nodejs_utils27.BadRequestError("Invalid school ID.");
4851
- }
4852
- }
4853
- const cacheParams = {
4854
- page,
4855
- limit,
4856
- sort: JSON.stringify(sort)
4857
- };
4858
- if (search)
4859
- cacheParams.search = search;
4860
- if (school)
4861
- cacheParams.school = school;
4862
- if (status !== "active")
4863
- cacheParams.status = status;
4864
- const cacheKey = (0, import_nodejs_utils27.makeCacheKey)(namespace_collection, cacheParams);
4865
- import_nodejs_utils27.logger.log({
4866
- level: "info",
4867
- message: `Cache key for getAll buildings: ${cacheKey}`
4868
- });
4869
- try {
4870
- const cached = await getCache(cacheKey);
4871
- if (cached) {
4872
- import_nodejs_utils27.logger.log({
4873
- level: "info",
4874
- message: `Cache hit for getAll buildings: ${cacheKey}`
4875
- });
4876
- return cached;
4877
- }
4878
- const items = await collection.aggregate([
4879
- { $match: query },
4880
- { $sort: sort },
4881
- { $skip: page * limit },
4882
- { $limit: limit }
4883
- ]).toArray();
4884
- const length = await collection.countDocuments(query);
4885
- const data = (0, import_nodejs_utils27.paginate)(items, page, limit, length);
4886
- setCache(cacheKey, data, 600).then(() => {
4887
- import_nodejs_utils27.logger.log({
4888
- level: "info",
4889
- message: `Cache set for getAll buildings: ${cacheKey}`
4890
- });
4891
- }).catch((err) => {
4892
- import_nodejs_utils27.logger.log({
4893
- level: "error",
4894
- message: `Failed to set cache for getAll buildings: ${err.message}`
4895
- });
4896
- });
4897
- return data;
4898
- } catch (error) {
4899
- import_nodejs_utils27.logger.log({ level: "error", message: `${error}` });
4900
- throw error;
4901
- }
4902
- }
4903
- async function getById(_id) {
4904
- try {
4905
- _id = new import_mongodb17.ObjectId(_id);
4906
- } catch (error) {
4907
- throw new import_nodejs_utils27.BadRequestError("Invalid ID.");
4908
- }
4909
- const cacheKey = (0, import_nodejs_utils27.makeCacheKey)(namespace_collection, { _id: String(_id) });
4910
- try {
4911
- const cached = await getCache(cacheKey);
4912
- if (cached) {
4913
- import_nodejs_utils27.logger.log({
4914
- level: "info",
4915
- message: `Cache hit for getById building: ${cacheKey}`
4916
- });
4917
- return cached;
4918
- }
4919
- const result = await collection.findOne({
4920
- _id
4921
- });
4922
- setCache(cacheKey, result, 300).then(() => {
4923
- import_nodejs_utils27.logger.log({
4924
- level: "info",
4925
- message: `Cache set for building by id: ${cacheKey}`
4926
- });
4927
- }).catch((err) => {
4928
- import_nodejs_utils27.logger.log({
4929
- level: "error",
4930
- message: `Failed to set cache for building by id: ${err.message}`
4931
- });
4932
- });
4933
- return result;
4934
- } catch (error) {
4935
- if (error instanceof import_nodejs_utils27.AppError) {
4936
- throw error;
4937
- } else {
4938
- throw new import_nodejs_utils27.InternalServerError("Failed to get building.");
4939
- }
4940
- }
4941
- }
4942
- async function deleteById(_id, session) {
4943
- try {
4944
- _id = new import_mongodb17.ObjectId(_id);
4945
- } catch (error) {
4946
- throw new import_nodejs_utils27.BadRequestError("Invalid ID.");
4947
- }
4948
- try {
4949
- const res = await collection.updateOne(
4950
- { _id },
4951
- { $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } }
4952
- );
4953
- delCachedData();
4954
- return res;
4955
- } catch (error) {
4956
- import_nodejs_utils27.logger.log({
4957
- level: "error",
4958
- message: error.message
4959
- });
4960
- if (error instanceof import_nodejs_utils27.AppError) {
4961
- throw error;
4962
- } else {
4963
- throw new import_nodejs_utils27.InternalServerError("Failed to delete building.");
4964
- }
4965
- }
4966
- }
4967
- function delCachedData() {
4968
- delNamespace().then(() => {
4969
- import_nodejs_utils27.logger.log({
4970
- level: "info",
4971
- message: `Cache namespace cleared for ${namespace_collection}`
4972
- });
4973
- }).catch((err) => {
4974
- import_nodejs_utils27.logger.log({
4975
- level: "error",
4976
- message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
4977
- });
4978
- });
4979
- }
4980
- return {
4981
- createIndexes,
4982
- add,
4983
- getAll,
4984
- getById,
4985
- updateById,
4986
- deleteById
4987
- };
4988
- }
4989
-
4990
- // src/resources/building/building.service.ts
4991
- var import_nodejs_utils29 = require("@eeplatform/nodejs-utils");
4992
-
4993
- // src/resources/building/building-unit.repository.ts
4994
- var import_nodejs_utils28 = require("@eeplatform/nodejs-utils");
4995
- var import_mongodb18 = require("mongodb");
4996
- function useBuildingUnitRepo() {
4997
- const db = import_nodejs_utils28.useAtlas.getDb();
4998
- if (!db) {
4999
- throw new Error("Unable to connect to server.");
5000
- }
5001
- const namespace_collection = "school.building-units";
5002
- const collection = db.collection(namespace_collection);
5003
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils28.useCache)(namespace_collection);
5004
- async function createIndexes() {
5005
- try {
5006
- await collection.createIndexes([
5007
- {
5008
- key: { name: 1, building: 1, level: 1 },
5009
- unique: true,
5010
- name: "unique_name_index"
5011
- },
5012
- { key: { school: 1 } },
5013
- { key: { building: 1 } },
5014
- { key: { status: 1 } },
5015
- { key: { createdAt: 1 } },
5016
- {
5017
- key: {
5018
- name: "text",
5019
- buildingName: "text",
5020
- category: "text",
5021
- type: "text"
5022
- }
5023
- }
5024
- ]);
5025
- } catch (error) {
5026
- throw new Error("Failed to create index on building units.");
5027
- }
5028
- }
5029
- function delCachedData() {
5030
- delNamespace().then(() => {
5031
- import_nodejs_utils28.logger.log({
5032
- level: "info",
5033
- message: `Cache namespace cleared for ${namespace_collection}`
5034
- });
5035
- }).catch((err) => {
5036
- import_nodejs_utils28.logger.log({
5037
- level: "error",
5038
- message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
5039
- });
5040
- });
5041
- }
5042
- async function add(value, session) {
5043
- try {
5044
- value = MBuildingUnit(value);
5045
- const res = await collection.insertOne(value, { session });
5046
- delCachedData();
5047
- return res.insertedId;
5048
- } catch (error) {
5049
- import_nodejs_utils28.logger.log({
5050
- level: "error",
5051
- message: error.message
5052
- });
5053
- if (error instanceof import_nodejs_utils28.AppError) {
5054
- throw error;
5055
- } else {
5056
- throw new Error("Failed to create building unit.");
5057
- }
5058
- }
5059
- }
5060
- async function updateById(_id, value, session) {
5061
- const { error } = schemaUpdateOptions.validate(value);
5062
- if (error) {
5063
- throw new import_nodejs_utils28.BadRequestError(error.message);
5064
- }
5065
- try {
5066
- _id = new import_mongodb18.ObjectId(_id);
5067
- } catch (error2) {
5068
- throw new import_nodejs_utils28.BadRequestError("Invalid ID.");
5069
- }
5070
- try {
5071
- const res = await collection.updateOne(
5072
- { _id },
5073
- { $set: value },
5074
- { session }
5075
- );
5076
- delCachedData();
5077
- return res;
5078
- } catch (error2) {
5079
- import_nodejs_utils28.logger.log({
5080
- level: "error",
5081
- message: error2.message
5082
- });
5083
- if (error2 instanceof import_nodejs_utils28.AppError) {
5084
- throw error2;
5085
- } else {
5086
- throw new Error("Failed to create building unit.");
5087
- }
5088
- }
5089
- }
5090
- async function updateByBuildingId(building, value, session) {
5091
- const { error } = schemaUpdateOptions.validate(value);
5092
- if (error) {
5093
- throw new import_nodejs_utils28.BadRequestError(error.message);
5094
- }
5095
- try {
5096
- building = new import_mongodb18.ObjectId(building);
5097
- } catch (error2) {
5098
- throw new import_nodejs_utils28.BadRequestError("Invalid building ID.");
5099
- }
5100
- try {
5101
- const res = await collection.updateMany(
5102
- { building },
5103
- { $set: value },
5104
- { session }
5105
- );
5106
- delCachedData();
5107
- return res;
5108
- } catch (error2) {
5109
- import_nodejs_utils28.logger.log({
5110
- level: "error",
5111
- message: error2.message
5112
- });
5113
- if (error2 instanceof import_nodejs_utils28.AppError) {
5114
- throw error2;
5115
- } else {
5116
- throw new Error("Failed to update building unit.");
5117
- }
5118
- }
5119
- }
5120
- async function getAll({
5121
- search = "",
5122
- page = 1,
5123
- limit = 10,
5124
- sort = {},
5125
- school = "",
5126
- building = "",
5127
- status = "active"
5128
- } = {}) {
5129
- page = page > 0 ? page - 1 : 0;
5130
- const query = {
5131
- deletedAt: { $in: ["", null] },
5132
- status: { $in: [status, "", null] }
5133
- };
5134
- sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
5135
- if (search) {
5136
- query.$text = { $search: search };
5137
- }
5138
- if (school) {
5139
- try {
5140
- query.school = new import_mongodb18.ObjectId(school);
5141
- } catch (error) {
5142
- throw new import_nodejs_utils28.BadRequestError("Invalid school ID.");
5143
- }
5144
- }
5145
- if (building) {
5146
- try {
5147
- query.building = new import_mongodb18.ObjectId(building);
5148
- } catch (error) {
5149
- throw new import_nodejs_utils28.BadRequestError("Invalid building ID.");
5150
- }
5151
- }
5152
- const cacheParams = {
5153
- page,
5154
- limit,
5155
- sort: JSON.stringify(sort)
5156
- };
5157
- if (search)
5158
- cacheParams.search = search;
5159
- if (school)
5160
- cacheParams.school = school;
5161
- if (building)
5162
- cacheParams.building = building;
5163
- if (status !== "active")
5164
- cacheParams.status = status;
5165
- const cacheKey = (0, import_nodejs_utils28.makeCacheKey)(namespace_collection, cacheParams);
5166
- import_nodejs_utils28.logger.log({
5167
- level: "info",
5168
- message: `Cache key for getAll building units: ${cacheKey}`
5169
- });
5170
- try {
5171
- const cached = await getCache(cacheKey);
5172
- if (cached) {
5173
- import_nodejs_utils28.logger.log({
5174
- level: "info",
5175
- message: `Cache hit for getAll building units: ${cacheKey}`
5176
- });
5177
- return cached;
5178
- }
5179
- const items = await collection.aggregate([
5180
- { $match: query },
5181
- { $sort: sort },
5182
- { $skip: page * limit },
5183
- { $limit: limit }
5184
- ]).toArray();
5185
- const length = await collection.countDocuments(query);
5186
- const data = (0, import_nodejs_utils28.paginate)(items, page, limit, length);
5187
- setCache(cacheKey, data, 600).then(() => {
5188
- import_nodejs_utils28.logger.log({
5189
- level: "info",
5190
- message: `Cache set for getAll building units: ${cacheKey}`
5191
- });
5192
- }).catch((err) => {
5193
- import_nodejs_utils28.logger.log({
5194
- level: "error",
5195
- message: `Failed to set cache for getAll building units: ${err.message}`
5196
- });
5197
- });
5198
- return data;
5199
- } catch (error) {
5200
- import_nodejs_utils28.logger.log({ level: "error", message: `${error}` });
5201
- throw error;
5202
- }
5203
- }
5204
- async function getById(_id) {
5205
- try {
5206
- _id = new import_mongodb18.ObjectId(_id);
5207
- } catch (error) {
5208
- throw new import_nodejs_utils28.BadRequestError("Invalid ID.");
5209
- }
5210
- const cacheKey = (0, import_nodejs_utils28.makeCacheKey)(namespace_collection, { _id: String(_id) });
5211
- try {
5212
- const cached = await getCache(cacheKey);
5213
- if (cached) {
5214
- import_nodejs_utils28.logger.log({
5215
- level: "info",
5216
- message: `Cache hit for getById building unit: ${cacheKey}`
5217
- });
5218
- return cached;
5219
- }
5220
- const result = await collection.findOne({
5221
- _id,
5222
- deletedAt: { $in: ["", null] }
5223
- });
5224
- if (!result) {
5225
- throw new import_nodejs_utils28.BadRequestError("Building unit not found.");
5226
- }
5227
- setCache(cacheKey, result, 300).then(() => {
5228
- import_nodejs_utils28.logger.log({
5229
- level: "info",
5230
- message: `Cache set for building unit by id: ${cacheKey}`
5231
- });
5232
- }).catch((err) => {
5233
- import_nodejs_utils28.logger.log({
5234
- level: "error",
5235
- message: `Failed to set cache for building unit by id: ${err.message}`
5236
- });
5237
- });
5238
- return result;
5239
- } catch (error) {
5240
- if (error instanceof import_nodejs_utils28.AppError) {
5241
- throw error;
5242
- } else {
5243
- throw new import_nodejs_utils28.InternalServerError("Failed to get building unit.");
5244
- }
5245
- }
5246
- }
5247
- async function getByBuildingLevel(building, level) {
5248
- try {
5249
- building = new import_mongodb18.ObjectId(building);
5250
- } catch (error) {
5251
- throw new import_nodejs_utils28.BadRequestError("Invalid building ID.");
5252
- }
5253
- const cacheKey = (0, import_nodejs_utils28.makeCacheKey)(namespace_collection, {
5254
- building: String(building),
5255
- level
5256
- });
5257
- try {
5258
- const cached = await getCache(cacheKey);
5259
- if (cached) {
5260
- import_nodejs_utils28.logger.log({
5261
- level: "info",
5262
- message: `Cache hit for getById building unit: ${cacheKey}`
5263
- });
5264
- return cached;
5265
- }
5266
- const result = await collection.findOne({
5267
- building,
5268
- level,
5269
- status: "active"
5270
- });
5271
- setCache(cacheKey, result, 300).then(() => {
5272
- import_nodejs_utils28.logger.log({
5273
- level: "info",
5274
- message: `Cache set for building unit by id: ${cacheKey}`
5275
- });
5276
- }).catch((err) => {
5277
- import_nodejs_utils28.logger.log({
5278
- level: "error",
5279
- message: `Failed to set cache for building unit by id: ${err.message}`
5280
- });
5281
- });
5282
- return result;
5283
- } catch (error) {
5284
- if (error instanceof import_nodejs_utils28.AppError) {
5285
- throw error;
5286
- } else {
5287
- throw new import_nodejs_utils28.InternalServerError("Failed to get building unit.");
5288
- }
5289
- }
5290
- }
5291
- async function getByBuilding(building) {
5292
- try {
5293
- building = new import_mongodb18.ObjectId(building);
5294
- } catch (error) {
5295
- throw new import_nodejs_utils28.BadRequestError("Invalid building ID.");
5296
- }
5297
- const cacheKey = (0, import_nodejs_utils28.makeCacheKey)(namespace_collection, {
5298
- building: String(building)
5299
- });
5300
- try {
5301
- const cached = await getCache(cacheKey);
5302
- if (cached) {
5303
- import_nodejs_utils28.logger.log({
5304
- level: "info",
5305
- message: `Cache hit for getById building unit: ${cacheKey}`
5306
- });
5307
- return cached;
5308
- }
5309
- const result = await collection.findOne({
5310
- building,
5311
- status: "active"
5312
- });
5313
- setCache(cacheKey, result, 300).then(() => {
5314
- import_nodejs_utils28.logger.log({
5315
- level: "info",
5316
- message: `Cache set for building unit by id: ${cacheKey}`
5317
- });
5318
- }).catch((err) => {
5319
- import_nodejs_utils28.logger.log({
5320
- level: "error",
5321
- message: `Failed to set cache for building unit by id: ${err.message}`
5322
- });
5323
- });
5324
- return result;
5325
- } catch (error) {
5326
- if (error instanceof import_nodejs_utils28.AppError) {
5327
- throw error;
5328
- } else {
5329
- throw new import_nodejs_utils28.InternalServerError("Failed to get building unit.");
5330
- }
5331
- }
5332
- }
5333
- async function deleteById(_id, session) {
5334
- try {
5335
- _id = new import_mongodb18.ObjectId(_id);
5336
- } catch (error) {
5337
- throw new import_nodejs_utils28.BadRequestError("Invalid ID.");
5338
- }
5339
- try {
5340
- const res = await collection.updateOne(
5341
- { _id },
5342
- { $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } },
5343
- { session }
5344
- );
5345
- delCachedData();
5346
- return "Room/Facility deleted successfully.";
5347
- } catch (error) {
5348
- import_nodejs_utils28.logger.log({
5349
- level: "error",
5350
- message: error.message
5351
- });
5352
- if (error instanceof import_nodejs_utils28.AppError) {
5353
- throw error;
5354
- } else {
5355
- throw new Error("Failed to deleted room/facility.");
5356
- }
5357
- }
5358
- }
5359
- return {
5360
- createIndexes,
5361
- add,
5362
- getAll,
5363
- getById,
5364
- getByBuildingLevel,
5365
- updateById,
5366
- getByBuilding,
5367
- deleteById,
5368
- updateByBuildingId
5369
- };
5370
- }
5371
-
5372
- // src/resources/building/building.service.ts
5373
- function useBuildingService() {
5374
- const {
5375
- updateById: _updateById,
5376
- getById: _getById,
5377
- deleteById: _deleteById
5378
- } = useBuildingRepo();
5379
- const { getByBuildingLevel, getByBuilding, updateByBuildingId } = useBuildingUnitRepo();
5380
- async function updateById(id, data) {
5381
- data.levels = Number(data.levels);
5382
- const session = import_nodejs_utils29.useAtlas.getClient()?.startSession();
5383
- try {
5384
- const building = await _getById(id);
5385
- if (!building) {
5386
- throw new import_nodejs_utils29.NotFoundError("Building not found.");
5387
- }
5388
- if (data.levels < building.levels) {
5389
- const unit = await getByBuildingLevel(id, building.levels);
5390
- if (unit) {
5391
- throw new import_nodejs_utils29.BadRequestError(
5392
- "Cannot reduce floors, there are existing building units at higher floors."
5393
- );
5394
- }
5395
- }
5396
- session?.startTransaction();
5397
- if (building.name !== data.name) {
5398
- await updateByBuildingId(id, { buildingName: data.name }, session);
5399
- }
5400
- const result = await _updateById(id, data, session);
5401
- await session?.commitTransaction();
5402
- return result;
5403
- } catch (error) {
5404
- await session?.abortTransaction();
5405
- throw error;
5406
- } finally {
5407
- session?.endSession();
5408
- }
5409
- }
5410
- async function deleteById(id) {
5411
- const building = await getByBuilding(id);
5412
- if (building) {
5413
- throw new import_nodejs_utils29.BadRequestError(
5414
- "Cannot delete building with existing room/facility. Please delete room/facility first."
5415
- );
5416
- }
5417
- try {
5418
- await _deleteById(id);
5419
- return "Building deleted successfully.";
5420
- } catch (error) {
5421
- throw error;
5422
- }
5423
- }
5424
- return {
5425
- updateById,
5426
- deleteById
5427
- };
5428
- }
5429
-
5430
- // src/resources/building/building.controller.ts
5431
- var import_nodejs_utils30 = require("@eeplatform/nodejs-utils");
5432
- var import_joi13 = __toESM(require("joi"));
5433
- function useBuildingController() {
5434
- const { getAll: _getAll, getById: _getById, add: _add } = useBuildingRepo();
5435
- const { updateById: _updateById, deleteById: _deleteById } = useBuildingService();
5436
- async function createBuilding(req, res, next) {
5437
- const value = req.body;
5438
- const validation = import_joi13.default.object({
5439
- name: import_joi13.default.string().required(),
5440
- school: import_joi13.default.string().hex().required(),
5441
- levels: import_joi13.default.number().integer().min(1).required(),
5442
- serial: import_joi13.default.string().optional().allow("", null),
5443
- status: import_joi13.default.string().optional().allow("", null)
5444
- });
5445
- const { error } = validation.validate(value);
5446
- if (error) {
5447
- next(new import_nodejs_utils30.BadRequestError(error.message));
5448
- import_nodejs_utils30.logger.info(`Controller: ${error.message}`);
5449
- return;
5450
- }
5451
- try {
5452
- const result = await _add(value);
5453
- res.json(result);
5454
- return;
5455
- } catch (error2) {
5456
- next(error2);
5457
- }
5458
- }
5459
- async function updateById(req, res, next) {
5460
- const value = req.body;
5461
- const id = req.params.id ?? "";
5462
- const validation = import_joi13.default.object({
5463
- id: import_joi13.default.string().hex().required(),
5464
- value: import_joi13.default.object({
5465
- name: import_joi13.default.string().required(),
5466
- serial: import_joi13.default.string().optional().allow("", null),
5467
- levels: import_joi13.default.number().integer().min(1).required()
5468
- })
5469
- });
5470
- const { error } = validation.validate({ id, value });
5471
- if (error) {
5472
- next(new import_nodejs_utils30.BadRequestError(error.message));
5473
- import_nodejs_utils30.logger.info(`Controller: ${error.message}`);
5474
- return;
5475
- }
5476
- try {
5477
- const result = await _updateById(id, value);
5478
- res.json(result);
5479
- return;
5480
- } catch (error2) {
5481
- next(error2);
5482
- }
5483
- }
5484
- async function getAll(req, res, next) {
5485
- const query = req.query;
5486
- const validation = import_joi13.default.object({
5487
- page: import_joi13.default.number().min(1).optional().allow("", null),
5488
- limit: import_joi13.default.number().min(1).optional().allow("", null),
5489
- search: import_joi13.default.string().optional().allow("", null),
5490
- school: import_joi13.default.string().hex().optional().allow("", null),
5491
- status: import_joi13.default.string().optional().allow("", null)
5492
- });
5493
- const { error } = validation.validate(query);
5494
- if (error) {
5495
- next(new import_nodejs_utils30.BadRequestError(error.message));
5496
- return;
5497
- }
5498
- const page = parseInt(req.query.page) ?? 1;
5499
- let limit = parseInt(req.query.limit) ?? 20;
5500
- limit = isNaN(limit) ? 20 : limit;
5501
- const sort = req.query.sort ? String(req.query.sort).split(",") : "";
5502
- const sortOrder = req.query.sortOrder ? String(req.query.sortOrder).split(",") : "";
5503
- const sortObj = {};
5504
- if (sort && Array.isArray(sort) && sort.length && sortOrder && Array.isArray(sortOrder) && sortOrder.length) {
5505
- sort.forEach((field, index) => {
5506
- sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
5507
- });
4473
+ try {
4474
+ await collection.createIndexes([
4475
+ { key: { user: 1 } },
4476
+ { key: { type: 1 } },
4477
+ { key: { orgId: 1 } }
4478
+ ]);
4479
+ } catch (error) {
4480
+ throw new import_nodejs_utils25.BadRequestError("Failed to create index on address.");
5508
4481
  }
5509
- const status = req.query.status ?? "active";
5510
- const school = req.query.school ?? "";
5511
- const search = req.query.search ?? "";
4482
+ }
4483
+ async function add(value, session) {
5512
4484
  try {
5513
- const buildings = await _getAll({
5514
- page,
5515
- limit,
5516
- sort: sortObj,
5517
- status,
5518
- school,
5519
- search
5520
- });
5521
- res.json(buildings);
5522
- return;
5523
- } catch (error2) {
5524
- next(error2);
4485
+ value = MAddress(value);
4486
+ const res = await collection.insertOne(value, { session });
4487
+ delCachedData();
4488
+ return res.insertedId;
4489
+ } catch (error) {
4490
+ throw new import_nodejs_utils25.BadRequestError("Failed to create address.");
5525
4491
  }
5526
4492
  }
5527
- async function getById(req, res, next) {
5528
- const id = req.params.id;
5529
- const validation = import_joi13.default.object({
5530
- id: import_joi13.default.string().hex().required()
5531
- });
5532
- const { error } = validation.validate({ id });
5533
- if (error) {
5534
- next(new import_nodejs_utils30.BadRequestError(error.message));
5535
- return;
4493
+ async function updateById(_id, value, session) {
4494
+ try {
4495
+ _id = new import_mongodb15.ObjectId(_id);
4496
+ } catch (error) {
4497
+ throw new import_nodejs_utils25.BadRequestError("Invalid address ID.");
4498
+ }
4499
+ if (value.org) {
4500
+ try {
4501
+ value.org = new import_mongodb15.ObjectId(value.org);
4502
+ } catch (error) {
4503
+ throw new import_nodejs_utils25.BadRequestError("Invalid org ID.");
4504
+ }
5536
4505
  }
5537
4506
  try {
5538
- const building = await _getById(id);
5539
- res.json({
5540
- message: "Successfully retrieved building.",
5541
- data: { building }
5542
- });
5543
- return;
5544
- } catch (error2) {
5545
- next(error2);
4507
+ await collection.updateOne(
4508
+ { _id },
4509
+ { $set: value },
4510
+ { session, upsert: true }
4511
+ );
4512
+ delCachedData();
4513
+ return "Successfully updated address.";
4514
+ } catch (error) {
4515
+ throw new import_nodejs_utils25.BadRequestError("Failed to update address.");
5546
4516
  }
5547
4517
  }
5548
- async function deleteById(req, res, next) {
5549
- const id = req.params.id;
5550
- const validation = import_joi13.default.object({
5551
- id: import_joi13.default.string().hex().required()
5552
- });
5553
- const { error } = validation.validate({ id });
5554
- if (error) {
5555
- next(new import_nodejs_utils30.BadRequestError(error.message));
5556
- return;
4518
+ async function getByUserId(user) {
4519
+ try {
4520
+ user = new import_mongodb15.ObjectId(user);
4521
+ } catch (error) {
4522
+ throw new import_nodejs_utils25.BadRequestError("Invalid user ID.");
5557
4523
  }
4524
+ const cacheKey = (0, import_nodejs_utils25.makeCacheKey)(namespace_collection, { user: String(user) });
5558
4525
  try {
5559
- const message = await _deleteById(id);
5560
- res.json(message);
5561
- return;
5562
- } catch (error2) {
5563
- next(error2);
4526
+ const cached = await getCache(cacheKey);
4527
+ if (cached) {
4528
+ import_nodejs_utils25.logger.log({
4529
+ level: "info",
4530
+ message: `Cache hit for getByUserId address: ${cacheKey}`
4531
+ });
4532
+ return cached;
4533
+ }
4534
+ const data = await collection.findOne({ user });
4535
+ if (data) {
4536
+ setCache(cacheKey, data, 300).then(() => {
4537
+ import_nodejs_utils25.logger.log({
4538
+ level: "info",
4539
+ message: `Cache set for address by user ID: ${cacheKey}`
4540
+ });
4541
+ }).catch((err) => {
4542
+ import_nodejs_utils25.logger.log({
4543
+ level: "error",
4544
+ message: `Failed to set cache for address by user ID: ${err.message}`
4545
+ });
4546
+ });
4547
+ }
4548
+ return data;
4549
+ } catch (error) {
4550
+ throw new import_nodejs_utils25.BadRequestError("Failed to get address by ID.");
5564
4551
  }
5565
4552
  }
5566
- return {
5567
- createBuilding,
5568
- getAll,
5569
- getById,
5570
- updateById,
5571
- deleteById
5572
- };
5573
- }
5574
-
5575
- // src/resources/building/building-unit.service.ts
5576
- var import_nodejs_utils31 = require("@eeplatform/nodejs-utils");
5577
- function useBuildingUnitService() {
5578
- const { add: _add } = useBuildingUnitRepo();
5579
- async function add(value) {
5580
- const session = import_nodejs_utils31.useAtlas.getClient()?.startSession();
5581
- if (!session) {
5582
- throw new Error("Unable to start session for building unit service.");
4553
+ async function getByOrgId(org) {
4554
+ try {
4555
+ org = new import_mongodb15.ObjectId(org);
4556
+ } catch (error) {
4557
+ throw new import_nodejs_utils25.BadRequestError("Invalid orgId.");
5583
4558
  }
4559
+ const cacheKey = (0, import_nodejs_utils25.makeCacheKey)(namespace_collection, { org: String(org) });
5584
4560
  try {
5585
- await session.startTransaction();
5586
- for (let index = 0; index < value.qty; index++) {
5587
- await _add(
5588
- { ...value.building, name: `${value.building.name} ${index + 1}` },
5589
- session
5590
- );
4561
+ const cached = await getCache(cacheKey);
4562
+ if (cached) {
4563
+ import_nodejs_utils25.logger.log({
4564
+ level: "info",
4565
+ message: `Cache hit for getByOrgId address: ${cacheKey}`
4566
+ });
4567
+ return cached;
4568
+ }
4569
+ const data = await collection.findOne({ org });
4570
+ if (data) {
4571
+ setCache(cacheKey, data, 300).then(() => {
4572
+ import_nodejs_utils25.logger.log({
4573
+ level: "info",
4574
+ message: `Cache set for address by org ID: ${cacheKey}`
4575
+ });
4576
+ }).catch((err) => {
4577
+ import_nodejs_utils25.logger.log({
4578
+ level: "error",
4579
+ message: `Failed to set cache for address by org ID: ${err.message}`
4580
+ });
4581
+ });
5591
4582
  }
5592
- await session.commitTransaction();
5593
- return "Building unit added successfully.";
4583
+ return data;
5594
4584
  } catch (error) {
5595
- await session.abortTransaction();
5596
- throw error;
5597
- } finally {
5598
- session.endSession();
4585
+ throw new import_nodejs_utils25.BadRequestError("Failed to get address by orgId.");
5599
4586
  }
5600
4587
  }
5601
4588
  return {
5602
- add
4589
+ createIndex,
4590
+ add,
4591
+ getByUserId,
4592
+ getByOrgId,
4593
+ updateById
5603
4594
  };
5604
4595
  }
5605
4596
 
5606
- // src/resources/building/building-unit.controller.ts
5607
- var import_nodejs_utils32 = require("@eeplatform/nodejs-utils");
5608
- var import_joi14 = __toESM(require("joi"));
5609
- function useBuildingUnitController() {
4597
+ // src/resources/address/address.controller.ts
4598
+ var import_nodejs_utils26 = require("@eeplatform/nodejs-utils");
4599
+ var import_joi12 = __toESM(require("joi"));
4600
+ function useAddressController() {
5610
4601
  const {
5611
- getAll: _getAll,
5612
- getById: _getById,
5613
- updateById: _updateById,
5614
- deleteById: _deleteById
5615
- } = useBuildingUnitRepo();
5616
- const { add: _add } = useBuildingUnitService();
4602
+ add: _add,
4603
+ getByUserId: _getByUserId,
4604
+ getByOrgId: _getByOrgId,
4605
+ updateById: _updateById
4606
+ } = useAddressRepo();
5617
4607
  async function add(req, res, next) {
5618
- const data = req.body;
5619
- const validation = import_joi14.default.object({
5620
- building: import_joi14.default.object({
5621
- school: import_joi14.default.string().hex().required(),
5622
- name: import_joi14.default.string().optional().allow("", null),
5623
- building: import_joi14.default.string().hex().required(),
5624
- buildingName: import_joi14.default.string().optional().allow("", null),
5625
- level: import_joi14.default.number().integer().min(1).required(),
5626
- category: import_joi14.default.string().required(),
5627
- type: import_joi14.default.string().required(),
5628
- seating_capacity: import_joi14.default.number().integer().min(0).required(),
5629
- standing_capacity: import_joi14.default.number().integer().min(0).required(),
5630
- description: import_joi14.default.string().optional().allow("", null),
5631
- unit_of_measurement: import_joi14.default.string().valid("sqm").required(),
5632
- area: import_joi14.default.number().positive().required(),
5633
- status: import_joi14.default.string().optional().allow("", null)
5634
- }),
5635
- qty: import_joi14.default.number().integer().min(1).max(20).optional().default(1)
4608
+ const value = req.body;
4609
+ const validation = import_joi12.default.object({
4610
+ type: import_joi12.default.string().required(),
4611
+ user: import_joi12.default.string().hex().optional().allow("", null),
4612
+ org: import_joi12.default.string().hex().optional().allow("", null),
4613
+ country: import_joi12.default.string().required(),
4614
+ address: import_joi12.default.string().required(),
4615
+ continuedAddress: import_joi12.default.string().optional().allow("", null),
4616
+ city: import_joi12.default.string().required(),
4617
+ province: import_joi12.default.string().required(),
4618
+ postalCode: import_joi12.default.string().required(),
4619
+ taxId: import_joi12.default.string().optional().allow("", null)
5636
4620
  });
5637
- const { error } = validation.validate(data);
4621
+ const { error } = validation.validate(value);
5638
4622
  if (error) {
5639
- next(new import_nodejs_utils32.BadRequestError(error.message));
5640
- return;
4623
+ next(new import_nodejs_utils26.BadRequestError(error.message));
5641
4624
  }
5642
4625
  try {
5643
- const buildingUnit = await _add(data);
5644
- res.json({
5645
- message: "Building unit added successfully.",
5646
- data: { buildingUnit }
5647
- });
4626
+ const value2 = req.body;
4627
+ const id = await _add(value2);
4628
+ res.json({ message: "Successfully added subscription.", id });
4629
+ return;
5648
4630
  } catch (error2) {
5649
4631
  next(error2);
5650
4632
  }
5651
4633
  }
5652
4634
  async function updateById(req, res, next) {
5653
- const data = req.body;
5654
4635
  const id = req.params.id ?? "";
5655
- const validation = import_joi14.default.object({
5656
- id: import_joi14.default.string().hex().required(),
5657
- value: schemaUpdateOptions
5658
- });
5659
- const { error } = validation.validate({ id, value: data });
5660
- if (error) {
5661
- next(new import_nodejs_utils32.BadRequestError(error.message));
5662
- return;
5663
- }
5664
- try {
5665
- const buildingUnit = await _updateById(id, data);
5666
- res.json({
5667
- message: "Building unit updated successfully.",
5668
- data: { buildingUnit }
5669
- });
5670
- } catch (error2) {
5671
- next(error2);
5672
- }
5673
- }
5674
- async function getAll(req, res, next) {
5675
- const query = req.query;
5676
- const validation = import_joi14.default.object({
5677
- page: import_joi14.default.number().min(1).optional().allow("", null),
5678
- limit: import_joi14.default.number().min(1).optional().allow("", null),
5679
- search: import_joi14.default.string().optional().allow("", null),
5680
- school: import_joi14.default.string().hex().optional().allow("", null),
5681
- building: import_joi14.default.string().hex().optional().allow("", null),
5682
- status: import_joi14.default.string().optional().allow("", null)
4636
+ const value = req.body;
4637
+ const validation = import_joi12.default.object({
4638
+ id: import_joi12.default.string().hex().required(),
4639
+ country: import_joi12.default.string().required(),
4640
+ address: import_joi12.default.string().required(),
4641
+ continuedAddress: import_joi12.default.string().optional().allow("", null),
4642
+ city: import_joi12.default.string().required(),
4643
+ province: import_joi12.default.string().required(),
4644
+ postalCode: import_joi12.default.string().required(),
4645
+ taxId: import_joi12.default.string().optional().allow("", null),
4646
+ org: import_joi12.default.string().hex().optional().allow("", null)
5683
4647
  });
5684
- const { error } = validation.validate(query);
4648
+ const { error } = validation.validate({ id, ...value });
5685
4649
  if (error) {
5686
- next(new import_nodejs_utils32.BadRequestError(error.message));
4650
+ next(new import_nodejs_utils26.BadRequestError(error.message));
5687
4651
  return;
5688
4652
  }
5689
- const page = parseInt(req.query.page) ?? 1;
5690
- let limit = parseInt(req.query.limit) ?? 20;
5691
- limit = isNaN(limit) ? 20 : limit;
5692
- const sort = req.query.sort ? String(req.query.sort).split(",") : "";
5693
- const sortOrder = req.query.sortOrder ? String(req.query.sortOrder).split(",") : "";
5694
- const sortObj = {};
5695
- if (sort && Array.isArray(sort) && sort.length && sortOrder && Array.isArray(sortOrder) && sortOrder.length) {
5696
- sort.forEach((field, index) => {
5697
- sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
5698
- });
5699
- }
5700
- const status = req.query.status ?? "active";
5701
- const school = req.query.school ?? "";
5702
- const building = req.query.building ?? "";
5703
- const search = req.query.search ?? "";
5704
4653
  try {
5705
- const buildings = await _getAll({
5706
- page,
5707
- limit,
5708
- sort: sortObj,
5709
- status,
5710
- school,
5711
- search,
5712
- building
5713
- });
5714
- res.json(buildings);
4654
+ const message = await _updateById(id, value);
4655
+ res.json({ message });
5715
4656
  return;
5716
4657
  } catch (error2) {
5717
4658
  next(error2);
5718
4659
  }
5719
4660
  }
5720
- async function getById(req, res, next) {
5721
- const id = req.params.id;
5722
- const validation = import_joi14.default.object({
5723
- id: import_joi14.default.string().hex().required()
5724
- });
5725
- const { error } = validation.validate({ id });
4661
+ async function getByUserId(req, res, next) {
4662
+ const user = req.params.user;
4663
+ const validation = import_joi12.default.string().hex().required();
4664
+ const { error } = validation.validate(user);
5726
4665
  if (error) {
5727
- next(new import_nodejs_utils32.BadRequestError(error.message));
5728
- return;
4666
+ next(new import_nodejs_utils26.BadRequestError(error.message));
5729
4667
  }
5730
4668
  try {
5731
- const buildingUnit = await _getById(id);
5732
- res.json({
5733
- message: "Successfully retrieved building unit.",
5734
- data: { buildingUnit }
5735
- });
4669
+ const address = await _getByUserId(user);
4670
+ if (!address) {
4671
+ next(new import_nodejs_utils26.NotFoundError("Address not found."));
4672
+ return;
4673
+ }
4674
+ res.json(address);
5736
4675
  return;
5737
4676
  } catch (error2) {
5738
4677
  next(error2);
5739
4678
  }
5740
4679
  }
5741
- async function deleteById(req, res, next) {
4680
+ async function getByOrgId(req, res, next) {
5742
4681
  const id = req.params.id;
5743
- const validation = import_joi14.default.object({
5744
- id: import_joi14.default.string().hex().required()
5745
- });
5746
- const { error } = validation.validate({ id });
4682
+ const validation = import_joi12.default.string().hex().required();
4683
+ const { error } = validation.validate(id);
5747
4684
  if (error) {
5748
- next(new import_nodejs_utils32.BadRequestError(error.message));
5749
- return;
4685
+ next(new import_nodejs_utils26.BadRequestError(error.message));
5750
4686
  }
5751
4687
  try {
5752
- const message = await _deleteById(id);
5753
- res.json({ message });
4688
+ const address = await _getByOrgId(id);
4689
+ if (!address) {
4690
+ next(new import_nodejs_utils26.NotFoundError("Address not found."));
4691
+ return;
4692
+ }
4693
+ res.json(address);
5754
4694
  return;
5755
4695
  } catch (error2) {
5756
4696
  next(error2);
@@ -5758,32 +4698,31 @@ function useBuildingUnitController() {
5758
4698
  }
5759
4699
  return {
5760
4700
  add,
5761
- getAll,
5762
- getById,
5763
- updateById,
5764
- deleteById
4701
+ getByUserId,
4702
+ getByOrgId,
4703
+ updateById
5765
4704
  };
5766
4705
  }
5767
4706
 
5768
4707
  // src/resources/token/token.model.ts
5769
- var import_mongodb19 = require("mongodb");
4708
+ var import_mongodb16 = require("mongodb");
5770
4709
  var MToken = class {
5771
4710
  constructor(value) {
5772
4711
  this.token = value.token ?? "";
5773
- this.user = value.user ?? new import_mongodb19.ObjectId();
4712
+ this.user = value.user ?? new import_mongodb16.ObjectId();
5774
4713
  this.createdAt = value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString();
5775
4714
  }
5776
4715
  };
5777
4716
 
5778
4717
  // src/resources/counter/counter.model.ts
5779
- var import_nodejs_utils33 = require("@eeplatform/nodejs-utils");
5780
- var import_mongodb20 = require("mongodb");
4718
+ var import_nodejs_utils27 = require("@eeplatform/nodejs-utils");
4719
+ var import_mongodb17 = require("mongodb");
5781
4720
  var import_zod = require("zod");
5782
4721
  var TCounter = import_zod.z.object({
5783
4722
  _id: import_zod.z.union([
5784
4723
  import_zod.z.string().length(24, "Invalid ObjectId hex string"),
5785
- import_zod.z.instanceof(import_mongodb20.ObjectId)
5786
- ]).transform((val) => typeof val === "string" ? new import_mongodb20.ObjectId(val) : val).optional(),
4724
+ import_zod.z.instanceof(import_mongodb17.ObjectId)
4725
+ ]).transform((val) => typeof val === "string" ? new import_mongodb17.ObjectId(val) : val).optional(),
5787
4726
  count: import_zod.z.number().int().min(0).default(0),
5788
4727
  type: import_zod.z.string(),
5789
4728
  createdAt: import_zod.z.date().optional().default(() => /* @__PURE__ */ new Date()),
@@ -5796,7 +4735,7 @@ function useCounterModel(db) {
5796
4735
  try {
5797
4736
  return TCounter.parse(value);
5798
4737
  } catch (error) {
5799
- throw new import_nodejs_utils33.BadRequestError(error.issues[0].message);
4738
+ throw new import_nodejs_utils27.BadRequestError(error.issues[0].message);
5800
4739
  }
5801
4740
  }
5802
4741
  function validateCounter(data) {
@@ -5810,23 +4749,23 @@ function useCounterModel(db) {
5810
4749
  }
5811
4750
 
5812
4751
  // src/resources/counter/counter.repository.ts
5813
- var import_nodejs_utils34 = require("@eeplatform/nodejs-utils");
4752
+ var import_nodejs_utils28 = require("@eeplatform/nodejs-utils");
5814
4753
  function useCounterRepo() {
5815
- const db = import_nodejs_utils34.useAtlas.getDb();
4754
+ const db = import_nodejs_utils28.useAtlas.getDb();
5816
4755
  if (!db) {
5817
4756
  throw new Error("Unable to connect to server.");
5818
4757
  }
5819
4758
  const namespace_collection = "counters";
5820
4759
  const { collection, createCounter } = useCounterModel(db);
5821
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils34.useCache)(namespace_collection);
4760
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils28.useCache)(namespace_collection);
5822
4761
  function delCachedData() {
5823
4762
  delNamespace().then(() => {
5824
- import_nodejs_utils34.logger.log({
4763
+ import_nodejs_utils28.logger.log({
5825
4764
  level: "info",
5826
4765
  message: `Cache namespace cleared for ${namespace_collection}`
5827
4766
  });
5828
4767
  }).catch((err) => {
5829
- import_nodejs_utils34.logger.log({
4768
+ import_nodejs_utils28.logger.log({
5830
4769
  level: "error",
5831
4770
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
5832
4771
  });
@@ -5878,11 +4817,11 @@ function useCounterRepo() {
5878
4817
  }
5879
4818
  }
5880
4819
  async function getByType(type) {
5881
- const cacheKey = (0, import_nodejs_utils34.makeCacheKey)(namespace_collection, { type });
4820
+ const cacheKey = (0, import_nodejs_utils28.makeCacheKey)(namespace_collection, { type });
5882
4821
  try {
5883
4822
  const cached = await getCache(cacheKey);
5884
4823
  if (cached) {
5885
- import_nodejs_utils34.logger.log({
4824
+ import_nodejs_utils28.logger.log({
5886
4825
  level: "info",
5887
4826
  message: `Cache hit for getByType counter: ${cacheKey}`
5888
4827
  });
@@ -5891,12 +4830,12 @@ function useCounterRepo() {
5891
4830
  const data = await collection.findOne({ type });
5892
4831
  if (data) {
5893
4832
  setCache(cacheKey, data, 300).then(() => {
5894
- import_nodejs_utils34.logger.log({
4833
+ import_nodejs_utils28.logger.log({
5895
4834
  level: "info",
5896
4835
  message: `Cache set for counter by type: ${cacheKey}`
5897
4836
  });
5898
4837
  }).catch((err) => {
5899
- import_nodejs_utils34.logger.log({
4838
+ import_nodejs_utils28.logger.log({
5900
4839
  level: "error",
5901
4840
  message: `Failed to set cache for counter by type: ${err.message}`
5902
4841
  });
@@ -6234,7 +5173,7 @@ IMPORTANT: Only consider it a match if the target phoneme is the FIRST sound pro
6234
5173
  }
6235
5174
 
6236
5175
  // src/resources/utils/github.service.ts
6237
- var import_nodejs_utils35 = require("@eeplatform/nodejs-utils");
5176
+ var import_nodejs_utils29 = require("@eeplatform/nodejs-utils");
6238
5177
  var import_rest = require("@octokit/rest");
6239
5178
  var import_libsodium_wrappers = __toESM(require("libsodium-wrappers"));
6240
5179
  function useGitHubService() {
@@ -6248,23 +5187,23 @@ function useGitHubService() {
6248
5187
  try {
6249
5188
  const { data: repoData } = await octokit.repos.get({ owner, repo });
6250
5189
  if (!repoData.permissions?.admin) {
6251
- throw new import_nodejs_utils35.BadRequestError(
5190
+ throw new import_nodejs_utils29.BadRequestError(
6252
5191
  "You do not have admin access to this repository."
6253
5192
  );
6254
5193
  }
6255
5194
  } catch (error) {
6256
5195
  if (error.status === 404) {
6257
- throw new import_nodejs_utils35.BadRequestError(
5196
+ throw new import_nodejs_utils29.BadRequestError(
6258
5197
  "Repository not found or you don't have access to it."
6259
5198
  );
6260
5199
  } else if (error.status === 401) {
6261
- throw new import_nodejs_utils35.BadRequestError(
5200
+ throw new import_nodejs_utils29.BadRequestError(
6262
5201
  "Invalid GitHub token or insufficient permissions."
6263
5202
  );
6264
5203
  } else if (error.message.includes("admin access")) {
6265
5204
  throw error;
6266
5205
  } else {
6267
- throw new import_nodejs_utils35.BadRequestError(
5206
+ throw new import_nodejs_utils29.BadRequestError(
6268
5207
  `Failed to check repository permissions: ${error.message}`
6269
5208
  );
6270
5209
  }
@@ -6313,7 +5252,7 @@ function useGitHubService() {
6313
5252
  key_id: publicKeyRes.key_id
6314
5253
  });
6315
5254
  } catch (encryptionError) {
6316
- throw new import_nodejs_utils35.BadRequestError(
5255
+ throw new import_nodejs_utils29.BadRequestError(
6317
5256
  `Failed to encrypt secret '${key}': ${encryptionError.message}`
6318
5257
  );
6319
5258
  }
@@ -6329,22 +5268,22 @@ function useGitHubService() {
6329
5268
  }
6330
5269
  return `Successfully set ${lines.length} ${type} variables/secrets in environment '${environment}'`;
6331
5270
  } catch (error) {
6332
- if (error instanceof import_nodejs_utils35.AppError)
5271
+ if (error instanceof import_nodejs_utils29.AppError)
6333
5272
  throw error;
6334
5273
  if (error.status === 422) {
6335
- throw new import_nodejs_utils35.BadRequestError(
5274
+ throw new import_nodejs_utils29.BadRequestError(
6336
5275
  `GitHub API validation error: ${error.message}`
6337
5276
  );
6338
5277
  } else if (error.status === 404) {
6339
- throw new import_nodejs_utils35.BadRequestError("Environment or repository not found.");
5278
+ throw new import_nodejs_utils29.BadRequestError("Environment or repository not found.");
6340
5279
  } else if (error.status === 403) {
6341
- throw new import_nodejs_utils35.BadRequestError(
5280
+ throw new import_nodejs_utils29.BadRequestError(
6342
5281
  "Forbidden: Insufficient permissions or rate limit exceeded."
6343
5282
  );
6344
5283
  } else if (error.message.includes("admin access") || error.message.includes("permissions")) {
6345
5284
  throw error;
6346
5285
  } else {
6347
- throw new import_nodejs_utils35.BadRequestError(
5286
+ throw new import_nodejs_utils29.BadRequestError(
6348
5287
  `Failed to set GitHub variables: ${error.message}`
6349
5288
  );
6350
5289
  }
@@ -6356,19 +5295,19 @@ function useGitHubService() {
6356
5295
  }
6357
5296
 
6358
5297
  // src/resources/utils/transcribe.service.ts
6359
- var import_nodejs_utils36 = require("@eeplatform/nodejs-utils");
5298
+ var import_nodejs_utils30 = require("@eeplatform/nodejs-utils");
6360
5299
  function useTranscribeService() {
6361
5300
  const { createFile } = useFileService();
6362
- const { getClient } = (0, import_nodejs_utils36.useRedis)();
5301
+ const { getClient } = (0, import_nodejs_utils30.useRedis)();
6363
5302
  const redisClient = getClient();
6364
5303
  async function transcribeAudio(file) {
6365
5304
  try {
6366
5305
  const fileId = await createFile(file);
6367
5306
  } catch (error) {
6368
- if (error instanceof import_nodejs_utils36.AppError) {
5307
+ if (error instanceof import_nodejs_utils30.AppError) {
6369
5308
  throw error;
6370
5309
  } else {
6371
- throw new import_nodejs_utils36.BadRequestError("Failed to transcribe audio file");
5310
+ throw new import_nodejs_utils30.BadRequestError("Failed to transcribe audio file");
6372
5311
  }
6373
5312
  }
6374
5313
  }
@@ -6378,28 +5317,28 @@ function useTranscribeService() {
6378
5317
  }
6379
5318
 
6380
5319
  // src/resources/utils/audio-transcription.controller.ts
6381
- var import_nodejs_utils37 = require("@eeplatform/nodejs-utils");
6382
- var import_joi15 = __toESM(require("joi"));
5320
+ var import_nodejs_utils31 = require("@eeplatform/nodejs-utils");
5321
+ var import_joi13 = __toESM(require("joi"));
6383
5322
  function useAudioTranscriptionController() {
6384
5323
  const geminiService = useGeminiAiService();
6385
- const transcriptionOptionsSchema = import_joi15.default.object({
6386
- language: import_joi15.default.string().optional().max(50),
6387
- enableTimestamps: import_joi15.default.boolean().optional(),
6388
- prompt: import_joi15.default.string().optional().max(1e3),
6389
- maxTokens: import_joi15.default.number().integer().min(1).max(8192).optional()
5324
+ const transcriptionOptionsSchema = import_joi13.default.object({
5325
+ language: import_joi13.default.string().optional().max(50),
5326
+ enableTimestamps: import_joi13.default.boolean().optional(),
5327
+ prompt: import_joi13.default.string().optional().max(1e3),
5328
+ maxTokens: import_joi13.default.number().integer().min(1).max(8192).optional()
6390
5329
  });
6391
- const phonemeOptionsSchema = import_joi15.default.object({
6392
- language: import_joi15.default.string().optional().max(50),
6393
- caseSensitive: import_joi15.default.boolean().optional(),
6394
- partialMatch: import_joi15.default.boolean().optional()
5330
+ const phonemeOptionsSchema = import_joi13.default.object({
5331
+ language: import_joi13.default.string().optional().max(50),
5332
+ caseSensitive: import_joi13.default.boolean().optional(),
5333
+ partialMatch: import_joi13.default.boolean().optional()
6395
5334
  });
6396
- const phonemeMatchSchema = import_joi15.default.object({
6397
- targetPhoneme: import_joi15.default.string().required().min(1).max(10),
5335
+ const phonemeMatchSchema = import_joi13.default.object({
5336
+ targetPhoneme: import_joi13.default.string().required().min(1).max(10),
6398
5337
  options: phonemeOptionsSchema.optional()
6399
5338
  });
6400
5339
  async function transcribeFromFile(req, res, next) {
6401
5340
  if (!req.file) {
6402
- next(new import_nodejs_utils37.BadRequestError("Audio file is required"));
5341
+ next(new import_nodejs_utils31.BadRequestError("Audio file is required"));
6403
5342
  return;
6404
5343
  }
6405
5344
  try {
@@ -6407,14 +5346,14 @@ function useAudioTranscriptionController() {
6407
5346
  req.body
6408
5347
  );
6409
5348
  if (error) {
6410
- next(new import_nodejs_utils37.BadRequestError(error.message));
5349
+ next(new import_nodejs_utils31.BadRequestError(error.message));
6411
5350
  return;
6412
5351
  }
6413
5352
  const { buffer, mimetype, originalname, size } = req.file;
6414
5353
  if (!geminiService.validateAudioFormat(mimetype)) {
6415
5354
  const supportedFormats = geminiService.getSupportedAudioFormats();
6416
5355
  next(
6417
- new import_nodejs_utils37.BadRequestError(
5356
+ new import_nodejs_utils31.BadRequestError(
6418
5357
  `Unsupported audio format: ${mimetype}. Supported formats: ${supportedFormats.join(
6419
5358
  ", "
6420
5359
  )}`
@@ -6425,7 +5364,7 @@ function useAudioTranscriptionController() {
6425
5364
  const maxSizeBytes = 25 * 1024 * 1024;
6426
5365
  if (size > maxSizeBytes) {
6427
5366
  next(
6428
- new import_nodejs_utils37.BadRequestError(
5367
+ new import_nodejs_utils31.BadRequestError(
6429
5368
  `File size too large. Maximum allowed size is ${maxSizeBytes / (1024 * 1024)}MB`
6430
5369
  )
6431
5370
  );
@@ -6455,11 +5394,11 @@ function useAudioTranscriptionController() {
6455
5394
  }
6456
5395
  });
6457
5396
  } catch (error) {
6458
- if (error instanceof import_nodejs_utils37.AppError) {
5397
+ if (error instanceof import_nodejs_utils31.AppError) {
6459
5398
  next(error);
6460
5399
  } else {
6461
5400
  next(
6462
- new import_nodejs_utils37.InternalServerError(
5401
+ new import_nodejs_utils31.InternalServerError(
6463
5402
  `Audio transcription failed: ${error.message}`
6464
5403
  )
6465
5404
  );
@@ -6468,21 +5407,21 @@ function useAudioTranscriptionController() {
6468
5407
  }
6469
5408
  async function transcribeFromBase64(req, res, next) {
6470
5409
  try {
6471
- const bodySchema = import_joi15.default.object({
6472
- audioData: import_joi15.default.string().required(),
6473
- mimeType: import_joi15.default.string().required(),
5410
+ const bodySchema = import_joi13.default.object({
5411
+ audioData: import_joi13.default.string().required(),
5412
+ mimeType: import_joi13.default.string().required(),
6474
5413
  options: transcriptionOptionsSchema.optional()
6475
5414
  });
6476
5415
  const { error, value } = bodySchema.validate(req.body);
6477
5416
  if (error) {
6478
- next(new import_nodejs_utils37.BadRequestError(error.message));
5417
+ next(new import_nodejs_utils31.BadRequestError(error.message));
6479
5418
  return;
6480
5419
  }
6481
5420
  const { audioData, mimeType, options = {} } = value;
6482
5421
  if (!geminiService.validateAudioFormat(mimeType)) {
6483
5422
  const supportedFormats = geminiService.getSupportedAudioFormats();
6484
5423
  next(
6485
- new import_nodejs_utils37.BadRequestError(
5424
+ new import_nodejs_utils31.BadRequestError(
6486
5425
  `Unsupported audio format: ${mimeType}. Supported formats: ${supportedFormats.join(
6487
5426
  ", "
6488
5427
  )}`
@@ -6494,13 +5433,13 @@ function useAudioTranscriptionController() {
6494
5433
  try {
6495
5434
  audioBuffer = Buffer.from(audioData, "base64");
6496
5435
  } catch (conversionError) {
6497
- next(new import_nodejs_utils37.BadRequestError("Invalid base64 audio data"));
5436
+ next(new import_nodejs_utils31.BadRequestError("Invalid base64 audio data"));
6498
5437
  return;
6499
5438
  }
6500
5439
  const maxSizeBytes = 25 * 1024 * 1024;
6501
5440
  if (audioBuffer.length > maxSizeBytes) {
6502
5441
  next(
6503
- new import_nodejs_utils37.BadRequestError(
5442
+ new import_nodejs_utils31.BadRequestError(
6504
5443
  `Audio data too large. Maximum allowed size is ${maxSizeBytes / (1024 * 1024)}MB`
6505
5444
  )
6506
5445
  );
@@ -6529,11 +5468,11 @@ function useAudioTranscriptionController() {
6529
5468
  }
6530
5469
  });
6531
5470
  } catch (error) {
6532
- if (error instanceof import_nodejs_utils37.AppError) {
5471
+ if (error instanceof import_nodejs_utils31.AppError) {
6533
5472
  next(error);
6534
5473
  } else {
6535
5474
  next(
6536
- new import_nodejs_utils37.InternalServerError(
5475
+ new import_nodejs_utils31.InternalServerError(
6537
5476
  `Audio transcription failed: ${error.message}`
6538
5477
  )
6539
5478
  );
@@ -6553,7 +5492,7 @@ function useAudioTranscriptionController() {
6553
5492
  });
6554
5493
  } catch (error) {
6555
5494
  next(
6556
- new import_nodejs_utils37.InternalServerError(
5495
+ new import_nodejs_utils31.InternalServerError(
6557
5496
  `Failed to get supported formats: ${error.message}`
6558
5497
  )
6559
5498
  );
@@ -6561,12 +5500,12 @@ function useAudioTranscriptionController() {
6561
5500
  }
6562
5501
  async function validateFormat(req, res, next) {
6563
5502
  try {
6564
- const schema = import_joi15.default.object({
6565
- mimeType: import_joi15.default.string().required()
5503
+ const schema = import_joi13.default.object({
5504
+ mimeType: import_joi13.default.string().required()
6566
5505
  });
6567
5506
  const { error, value } = schema.validate(req.body);
6568
5507
  if (error) {
6569
- next(new import_nodejs_utils37.BadRequestError(error.message));
5508
+ next(new import_nodejs_utils31.BadRequestError(error.message));
6570
5509
  return;
6571
5510
  }
6572
5511
  const { mimeType } = value;
@@ -6582,19 +5521,19 @@ function useAudioTranscriptionController() {
6582
5521
  });
6583
5522
  } catch (error) {
6584
5523
  next(
6585
- new import_nodejs_utils37.InternalServerError(`Format validation failed: ${error.message}`)
5524
+ new import_nodejs_utils31.InternalServerError(`Format validation failed: ${error.message}`)
6586
5525
  );
6587
5526
  }
6588
5527
  }
6589
5528
  async function checkPhonemeFromFile(req, res, next) {
6590
5529
  if (!req.file) {
6591
- next(new import_nodejs_utils37.BadRequestError("Audio file is required"));
5530
+ next(new import_nodejs_utils31.BadRequestError("Audio file is required"));
6592
5531
  return;
6593
5532
  }
6594
5533
  try {
6595
5534
  const { error, value } = phonemeMatchSchema.validate(req.body);
6596
5535
  if (error) {
6597
- next(new import_nodejs_utils37.BadRequestError(error.message));
5536
+ next(new import_nodejs_utils31.BadRequestError(error.message));
6598
5537
  return;
6599
5538
  }
6600
5539
  const { targetPhoneme, options = {} } = value;
@@ -6602,7 +5541,7 @@ function useAudioTranscriptionController() {
6602
5541
  if (!geminiService.validateAudioFormat(mimetype)) {
6603
5542
  const supportedFormats = geminiService.getSupportedAudioFormats();
6604
5543
  next(
6605
- new import_nodejs_utils37.BadRequestError(
5544
+ new import_nodejs_utils31.BadRequestError(
6606
5545
  `Unsupported audio format: ${mimetype}. Supported formats: ${supportedFormats.join(
6607
5546
  ", "
6608
5547
  )}`
@@ -6613,7 +5552,7 @@ function useAudioTranscriptionController() {
6613
5552
  const maxSizeBytes = 25 * 1024 * 1024;
6614
5553
  if (size > maxSizeBytes) {
6615
5554
  next(
6616
- new import_nodejs_utils37.BadRequestError(
5555
+ new import_nodejs_utils31.BadRequestError(
6617
5556
  `File size too large. Maximum allowed size is ${maxSizeBytes / (1024 * 1024)}MB`
6618
5557
  )
6619
5558
  );
@@ -6628,7 +5567,7 @@ function useAudioTranscriptionController() {
6628
5567
  );
6629
5568
  const processingTime = Date.now() - startTime;
6630
5569
  if (!result.isMatch) {
6631
- throw new import_nodejs_utils37.BadRequestError(
5570
+ throw new import_nodejs_utils31.BadRequestError(
6632
5571
  `Phoneme "${targetPhoneme}" not found in the provided audio. Transcription: "${result.transcription}"`
6633
5572
  );
6634
5573
  }
@@ -6656,33 +5595,33 @@ function useAudioTranscriptionController() {
6656
5595
  }
6657
5596
  });
6658
5597
  } catch (error) {
6659
- if (error instanceof import_nodejs_utils37.AppError) {
5598
+ if (error instanceof import_nodejs_utils31.AppError) {
6660
5599
  next(error);
6661
5600
  } else {
6662
5601
  next(
6663
- new import_nodejs_utils37.InternalServerError(`Phoneme analysis failed: ${error.message}`)
5602
+ new import_nodejs_utils31.InternalServerError(`Phoneme analysis failed: ${error.message}`)
6664
5603
  );
6665
5604
  }
6666
5605
  }
6667
5606
  }
6668
5607
  async function checkPhonemeFromBase64(req, res, next) {
6669
5608
  try {
6670
- const bodySchema = import_joi15.default.object({
6671
- audioData: import_joi15.default.string().required(),
6672
- mimeType: import_joi15.default.string().required(),
6673
- targetPhoneme: import_joi15.default.string().required().min(1).max(10),
5609
+ const bodySchema = import_joi13.default.object({
5610
+ audioData: import_joi13.default.string().required(),
5611
+ mimeType: import_joi13.default.string().required(),
5612
+ targetPhoneme: import_joi13.default.string().required().min(1).max(10),
6674
5613
  options: phonemeOptionsSchema.optional()
6675
5614
  });
6676
5615
  const { error, value } = bodySchema.validate(req.body);
6677
5616
  if (error) {
6678
- next(new import_nodejs_utils37.BadRequestError(error.message));
5617
+ next(new import_nodejs_utils31.BadRequestError(error.message));
6679
5618
  return;
6680
5619
  }
6681
5620
  const { audioData, mimeType, targetPhoneme, options = {} } = value;
6682
5621
  if (!geminiService.validateAudioFormat(mimeType)) {
6683
5622
  const supportedFormats = geminiService.getSupportedAudioFormats();
6684
5623
  next(
6685
- new import_nodejs_utils37.BadRequestError(
5624
+ new import_nodejs_utils31.BadRequestError(
6686
5625
  `Unsupported audio format: ${mimeType}. Supported formats: ${supportedFormats.join(
6687
5626
  ", "
6688
5627
  )}`
@@ -6694,13 +5633,13 @@ function useAudioTranscriptionController() {
6694
5633
  try {
6695
5634
  audioBuffer = Buffer.from(audioData, "base64");
6696
5635
  } catch (conversionError) {
6697
- next(new import_nodejs_utils37.BadRequestError("Invalid base64 audio data"));
5636
+ next(new import_nodejs_utils31.BadRequestError("Invalid base64 audio data"));
6698
5637
  return;
6699
5638
  }
6700
5639
  const maxSizeBytes = 25 * 1024 * 1024;
6701
5640
  if (audioBuffer.length > maxSizeBytes) {
6702
5641
  next(
6703
- new import_nodejs_utils37.BadRequestError(
5642
+ new import_nodejs_utils31.BadRequestError(
6704
5643
  `Audio data too large. Maximum allowed size is ${maxSizeBytes / (1024 * 1024)}MB`
6705
5644
  )
6706
5645
  );
@@ -6715,7 +5654,7 @@ function useAudioTranscriptionController() {
6715
5654
  );
6716
5655
  const processingTime = Date.now() - startTime;
6717
5656
  if (!result.isMatch) {
6718
- throw new import_nodejs_utils37.BadRequestError(
5657
+ throw new import_nodejs_utils31.BadRequestError(
6719
5658
  `Phoneme "${targetPhoneme}" not found in the provided audio. Transcription: "${result.transcription}"`
6720
5659
  );
6721
5660
  }
@@ -6742,28 +5681,28 @@ function useAudioTranscriptionController() {
6742
5681
  }
6743
5682
  });
6744
5683
  } catch (error) {
6745
- if (error instanceof import_nodejs_utils37.AppError) {
5684
+ if (error instanceof import_nodejs_utils31.AppError) {
6746
5685
  next(error);
6747
5686
  } else {
6748
5687
  next(
6749
- new import_nodejs_utils37.InternalServerError(`Phoneme analysis failed: ${error.message}`)
5688
+ new import_nodejs_utils31.InternalServerError(`Phoneme analysis failed: ${error.message}`)
6750
5689
  );
6751
5690
  }
6752
5691
  }
6753
5692
  }
6754
5693
  async function batchPhonemeCheck(req, res, next) {
6755
5694
  if (!req.file) {
6756
- next(new import_nodejs_utils37.BadRequestError("Audio file is required"));
5695
+ next(new import_nodejs_utils31.BadRequestError("Audio file is required"));
6757
5696
  return;
6758
5697
  }
6759
5698
  try {
6760
- const batchSchema = import_joi15.default.object({
6761
- targetPhonemes: import_joi15.default.array().items(import_joi15.default.string().min(1).max(10)).min(1).max(20).required(),
5699
+ const batchSchema = import_joi13.default.object({
5700
+ targetPhonemes: import_joi13.default.array().items(import_joi13.default.string().min(1).max(10)).min(1).max(20).required(),
6762
5701
  options: phonemeOptionsSchema.optional()
6763
5702
  });
6764
5703
  const { error, value } = batchSchema.validate(req.body);
6765
5704
  if (error) {
6766
- next(new import_nodejs_utils37.BadRequestError(error.message));
5705
+ next(new import_nodejs_utils31.BadRequestError(error.message));
6767
5706
  return;
6768
5707
  }
6769
5708
  const { targetPhonemes, options = {} } = value;
@@ -6771,7 +5710,7 @@ function useAudioTranscriptionController() {
6771
5710
  if (!geminiService.validateAudioFormat(mimetype)) {
6772
5711
  const supportedFormats = geminiService.getSupportedAudioFormats();
6773
5712
  next(
6774
- new import_nodejs_utils37.BadRequestError(
5713
+ new import_nodejs_utils31.BadRequestError(
6775
5714
  `Unsupported audio format: ${mimetype}. Supported formats: ${supportedFormats.join(
6776
5715
  ", "
6777
5716
  )}`
@@ -6782,7 +5721,7 @@ function useAudioTranscriptionController() {
6782
5721
  const maxSizeBytes = 25 * 1024 * 1024;
6783
5722
  if (size > maxSizeBytes) {
6784
5723
  next(
6785
- new import_nodejs_utils37.BadRequestError(
5724
+ new import_nodejs_utils31.BadRequestError(
6786
5725
  `File size too large. Maximum allowed size is ${maxSizeBytes / (1024 * 1024)}MB`
6787
5726
  )
6788
5727
  );
@@ -6838,11 +5777,11 @@ function useAudioTranscriptionController() {
6838
5777
  }
6839
5778
  });
6840
5779
  } catch (error) {
6841
- if (error instanceof import_nodejs_utils37.AppError) {
5780
+ if (error instanceof import_nodejs_utils31.AppError) {
6842
5781
  next(error);
6843
5782
  } else {
6844
5783
  next(
6845
- new import_nodejs_utils37.InternalServerError(
5784
+ new import_nodejs_utils31.InternalServerError(
6846
5785
  `Batch phoneme analysis failed: ${error.message}`
6847
5786
  )
6848
5787
  );
@@ -6863,7 +5802,7 @@ function useAudioTranscriptionController() {
6863
5802
  }
6864
5803
  });
6865
5804
  } catch (error) {
6866
- next(new import_nodejs_utils37.InternalServerError(`Health check failed: ${error.message}`));
5805
+ next(new import_nodejs_utils31.InternalServerError(`Health check failed: ${error.message}`));
6867
5806
  }
6868
5807
  }
6869
5808
  return {
@@ -6879,8 +5818,8 @@ function useAudioTranscriptionController() {
6879
5818
  }
6880
5819
 
6881
5820
  // src/resources/utils/util.controller.ts
6882
- var import_joi16 = __toESM(require("joi"));
6883
- var import_nodejs_utils38 = require("@eeplatform/nodejs-utils");
5821
+ var import_joi14 = __toESM(require("joi"));
5822
+ var import_nodejs_utils32 = require("@eeplatform/nodejs-utils");
6884
5823
  function useUtilController() {
6885
5824
  async function healthCheck(req, res, next) {
6886
5825
  try {
@@ -6896,32 +5835,32 @@ function useUtilController() {
6896
5835
  }
6897
5836
  });
6898
5837
  } catch (error) {
6899
- import_nodejs_utils38.logger.error("Health check failed", { error: error.message });
6900
- next(new import_nodejs_utils38.InternalServerError("Health check failed"));
5838
+ import_nodejs_utils32.logger.error("Health check failed", { error: error.message });
5839
+ next(new import_nodejs_utils32.InternalServerError("Health check failed"));
6901
5840
  }
6902
5841
  }
6903
5842
  async function setGitHubVariables(req, res, next) {
6904
5843
  try {
6905
5844
  const { githubToken, repoUrl, environment, type, keyValues } = req.body;
6906
- const validation = import_joi16.default.object({
6907
- githubToken: import_joi16.default.string().required().messages({
5845
+ const validation = import_joi14.default.object({
5846
+ githubToken: import_joi14.default.string().required().messages({
6908
5847
  "string.empty": "GitHub token is required",
6909
5848
  "any.required": "GitHub token is required"
6910
5849
  }),
6911
- repoUrl: import_joi16.default.string().uri().required().messages({
5850
+ repoUrl: import_joi14.default.string().uri().required().messages({
6912
5851
  "string.empty": "Repository URL is required",
6913
5852
  "string.uri": "Repository URL must be a valid URL",
6914
5853
  "any.required": "Repository URL is required"
6915
5854
  }),
6916
- environment: import_joi16.default.string().required().messages({
5855
+ environment: import_joi14.default.string().required().messages({
6917
5856
  "string.empty": "Environment name is required",
6918
5857
  "any.required": "Environment name is required"
6919
5858
  }),
6920
- type: import_joi16.default.string().valid("env", "secret").required().messages({
5859
+ type: import_joi14.default.string().valid("env", "secret").required().messages({
6921
5860
  "any.only": 'Type must be either "env" or "secret"',
6922
5861
  "any.required": "Type is required"
6923
5862
  }),
6924
- keyValues: import_joi16.default.string().required().messages({
5863
+ keyValues: import_joi14.default.string().required().messages({
6925
5864
  "string.empty": "Key-value pairs are required",
6926
5865
  "any.required": "Key-value pairs are required"
6927
5866
  })
@@ -6934,13 +5873,13 @@ function useUtilController() {
6934
5873
  keyValues
6935
5874
  });
6936
5875
  if (error) {
6937
- next(new import_nodejs_utils38.BadRequestError(error.message));
5876
+ next(new import_nodejs_utils32.BadRequestError(error.message));
6938
5877
  return;
6939
5878
  }
6940
5879
  const repoUrlPattern = /github\.com[:\/]([^\/]+)\/(.+)\.git$/;
6941
5880
  if (!repoUrlPattern.test(repoUrl)) {
6942
5881
  next(
6943
- new import_nodejs_utils38.BadRequestError(
5882
+ new import_nodejs_utils32.BadRequestError(
6944
5883
  "Invalid GitHub repository URL format. Expected format: https://github.com/owner/repo.git"
6945
5884
  )
6946
5885
  );
@@ -6952,7 +5891,7 @@ function useUtilController() {
6952
5891
  );
6953
5892
  if (invalidLines.length > 0) {
6954
5893
  next(
6955
- new import_nodejs_utils38.BadRequestError(
5894
+ new import_nodejs_utils32.BadRequestError(
6956
5895
  "Invalid key-value format. Each pair should be in format: KEY=value. Pairs should be separated by semicolons."
6957
5896
  )
6958
5897
  );
@@ -6966,7 +5905,7 @@ function useUtilController() {
6966
5905
  type,
6967
5906
  keyValues
6968
5907
  });
6969
- import_nodejs_utils38.logger.info(`GitHub variables set successfully`, {
5908
+ import_nodejs_utils32.logger.info(`GitHub variables set successfully`, {
6970
5909
  repoUrl,
6971
5910
  environment,
6972
5911
  type,
@@ -6983,15 +5922,15 @@ function useUtilController() {
6983
5922
  }
6984
5923
  });
6985
5924
  } catch (error) {
6986
- import_nodejs_utils38.logger.error("Failed to set GitHub variables", {
5925
+ import_nodejs_utils32.logger.error("Failed to set GitHub variables", {
6987
5926
  error: error.message,
6988
5927
  stack: error.stack
6989
5928
  });
6990
- if (error instanceof import_nodejs_utils38.AppError) {
5929
+ if (error instanceof import_nodejs_utils32.AppError) {
6991
5930
  next(error);
6992
5931
  } else {
6993
5932
  next(
6994
- new import_nodejs_utils38.InternalServerError(
5933
+ new import_nodejs_utils32.InternalServerError(
6995
5934
  `Failed to set GitHub variables: ${error.message}`
6996
5935
  )
6997
5936
  );
@@ -7005,34 +5944,34 @@ function useUtilController() {
7005
5944
  }
7006
5945
 
7007
5946
  // src/resources/utils/transaction.schema.ts
7008
- var import_joi17 = __toESM(require("joi"));
7009
- var transactionSchema = import_joi17.default.object({
7010
- _id: import_joi17.default.string().hex().optional().allow("", null),
7011
- payment: import_joi17.default.string().required(),
7012
- user: import_joi17.default.string().hex().optional().allow("", null),
7013
- org: import_joi17.default.string().hex().optional().allow("", null),
7014
- type: import_joi17.default.string().required(),
7015
- amount: import_joi17.default.number().positive().min(0).required(),
7016
- currency: import_joi17.default.string().required(),
7017
- description: import_joi17.default.string().optional().allow("", null),
7018
- metadata: import_joi17.default.object({
7019
- subscriptionId: import_joi17.default.string().hex().optional().allow("", null),
7020
- cycle: import_joi17.default.number().optional().allow("", null),
7021
- seats: import_joi17.default.number().optional().allow("", null),
7022
- promoCode: import_joi17.default.string().optional().allow("", null)
5947
+ var import_joi15 = __toESM(require("joi"));
5948
+ var transactionSchema = import_joi15.default.object({
5949
+ _id: import_joi15.default.string().hex().optional().allow("", null),
5950
+ payment: import_joi15.default.string().required(),
5951
+ user: import_joi15.default.string().hex().optional().allow("", null),
5952
+ org: import_joi15.default.string().hex().optional().allow("", null),
5953
+ type: import_joi15.default.string().required(),
5954
+ amount: import_joi15.default.number().positive().min(0).required(),
5955
+ currency: import_joi15.default.string().required(),
5956
+ description: import_joi15.default.string().optional().allow("", null),
5957
+ metadata: import_joi15.default.object({
5958
+ subscriptionId: import_joi15.default.string().hex().optional().allow("", null),
5959
+ cycle: import_joi15.default.number().optional().allow("", null),
5960
+ seats: import_joi15.default.number().optional().allow("", null),
5961
+ promoCode: import_joi15.default.string().optional().allow("", null)
7023
5962
  }).optional().allow("", null),
7024
- status: import_joi17.default.string().optional().allow("", null),
7025
- createdAt: import_joi17.default.string().optional().allow("", null),
7026
- updatedAt: import_joi17.default.string().optional().allow("", null),
7027
- deletedAt: import_joi17.default.string().optional().allow("", null)
5963
+ status: import_joi15.default.string().optional().allow("", null),
5964
+ createdAt: import_joi15.default.string().optional().allow("", null),
5965
+ updatedAt: import_joi15.default.string().optional().allow("", null),
5966
+ deletedAt: import_joi15.default.string().optional().allow("", null)
7028
5967
  });
7029
5968
 
7030
5969
  // src/resources/psgc/psgc.model.ts
7031
- var import_joi18 = __toESM(require("joi"));
7032
- var schemaPSGC = import_joi18.default.object({
7033
- code: import_joi18.default.string().length(10).required(),
7034
- name: import_joi18.default.string().required(),
7035
- type: import_joi18.default.string().valid("Reg", "Prov", "City", "Mun", "Bgy").required()
5970
+ var import_joi16 = __toESM(require("joi"));
5971
+ var schemaPSGC = import_joi16.default.object({
5972
+ code: import_joi16.default.string().length(10).required(),
5973
+ name: import_joi16.default.string().required(),
5974
+ type: import_joi16.default.string().valid("Reg", "Prov", "City", "Mun", "Bgy").required()
7036
5975
  });
7037
5976
  function modelPSGC(data) {
7038
5977
  const { error } = schemaPSGC.validate(data);
@@ -7047,16 +5986,16 @@ function modelPSGC(data) {
7047
5986
  }
7048
5987
 
7049
5988
  // src/resources/psgc/psgc.repository.ts
7050
- var import_nodejs_utils39 = require("@eeplatform/nodejs-utils");
7051
- var import_mongodb21 = require("mongodb");
5989
+ var import_nodejs_utils33 = require("@eeplatform/nodejs-utils");
5990
+ var import_mongodb18 = require("mongodb");
7052
5991
  function usePSGCRepo() {
7053
- const db = import_nodejs_utils39.useAtlas.getDb();
5992
+ const db = import_nodejs_utils33.useAtlas.getDb();
7054
5993
  if (!db) {
7055
5994
  throw new Error("Unable to connect to server.");
7056
5995
  }
7057
5996
  const namespace_collection = "psgc";
7058
5997
  const collection = db.collection(namespace_collection);
7059
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils39.useCache)(namespace_collection);
5998
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils33.useCache)(namespace_collection);
7060
5999
  async function createIndexes() {
7061
6000
  try {
7062
6001
  await collection.createIndexes([
@@ -7070,12 +6009,12 @@ function usePSGCRepo() {
7070
6009
  }
7071
6010
  function delCachedData() {
7072
6011
  delNamespace().then(() => {
7073
- import_nodejs_utils39.logger.log({
6012
+ import_nodejs_utils33.logger.log({
7074
6013
  level: "info",
7075
6014
  message: `Cache namespace cleared for ${namespace_collection}`
7076
6015
  });
7077
6016
  }).catch((err) => {
7078
- import_nodejs_utils39.logger.log({
6017
+ import_nodejs_utils33.logger.log({
7079
6018
  level: "error",
7080
6019
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
7081
6020
  });
@@ -7088,16 +6027,16 @@ function usePSGCRepo() {
7088
6027
  delCachedData();
7089
6028
  return res.insertedId;
7090
6029
  } catch (error) {
7091
- import_nodejs_utils39.logger.log({
6030
+ import_nodejs_utils33.logger.log({
7092
6031
  level: "error",
7093
6032
  message: error.message
7094
6033
  });
7095
- if (error instanceof import_nodejs_utils39.AppError) {
6034
+ if (error instanceof import_nodejs_utils33.AppError) {
7096
6035
  throw error;
7097
6036
  } else {
7098
6037
  const isDuplicated = error.message.includes("duplicate");
7099
6038
  if (isDuplicated) {
7100
- throw new import_nodejs_utils39.BadRequestError("Region already exists.");
6039
+ throw new import_nodejs_utils33.BadRequestError("Region already exists.");
7101
6040
  }
7102
6041
  throw new Error("Failed to create PSGC.");
7103
6042
  }
@@ -7133,15 +6072,15 @@ function usePSGCRepo() {
7133
6072
  query.$text = { $search: search };
7134
6073
  cacheKeyOptions.search = search;
7135
6074
  }
7136
- const cacheKey = (0, import_nodejs_utils39.makeCacheKey)(namespace_collection, cacheKeyOptions);
7137
- import_nodejs_utils39.logger.log({
6075
+ const cacheKey = (0, import_nodejs_utils33.makeCacheKey)(namespace_collection, cacheKeyOptions);
6076
+ import_nodejs_utils33.logger.log({
7138
6077
  level: "info",
7139
6078
  message: `Cache key for getAll PSGC: ${cacheKey}`
7140
6079
  });
7141
6080
  try {
7142
6081
  const cached = await getCache(cacheKey);
7143
6082
  if (cached) {
7144
- import_nodejs_utils39.logger.log({
6083
+ import_nodejs_utils33.logger.log({
7145
6084
  level: "info",
7146
6085
  message: `Cache hit for getAll PSGC: ${cacheKey}`
7147
6086
  });
@@ -7154,35 +6093,35 @@ function usePSGCRepo() {
7154
6093
  { $limit: limit }
7155
6094
  ]).toArray();
7156
6095
  const length = await collection.countDocuments(query);
7157
- const data = (0, import_nodejs_utils39.paginate)(items, page, limit, length);
6096
+ const data = (0, import_nodejs_utils33.paginate)(items, page, limit, length);
7158
6097
  setCache(cacheKey, data, 600).then(() => {
7159
- import_nodejs_utils39.logger.log({
6098
+ import_nodejs_utils33.logger.log({
7160
6099
  level: "info",
7161
6100
  message: `Cache set for getAll PSGC: ${cacheKey}`
7162
6101
  });
7163
6102
  }).catch((err) => {
7164
- import_nodejs_utils39.logger.log({
6103
+ import_nodejs_utils33.logger.log({
7165
6104
  level: "error",
7166
6105
  message: `Failed to set cache for getAll PSGC: ${err.message}`
7167
6106
  });
7168
6107
  });
7169
6108
  return data;
7170
6109
  } catch (error) {
7171
- import_nodejs_utils39.logger.log({ level: "error", message: `${error}` });
6110
+ import_nodejs_utils33.logger.log({ level: "error", message: `${error}` });
7172
6111
  throw error;
7173
6112
  }
7174
6113
  }
7175
6114
  async function getById(_id) {
7176
6115
  try {
7177
- _id = new import_mongodb21.ObjectId(_id);
6116
+ _id = new import_mongodb18.ObjectId(_id);
7178
6117
  } catch (error) {
7179
- throw new import_nodejs_utils39.BadRequestError("Invalid ID.");
6118
+ throw new import_nodejs_utils33.BadRequestError("Invalid ID.");
7180
6119
  }
7181
- const cacheKey = (0, import_nodejs_utils39.makeCacheKey)(namespace_collection, { _id: String(_id) });
6120
+ const cacheKey = (0, import_nodejs_utils33.makeCacheKey)(namespace_collection, { _id: String(_id) });
7182
6121
  try {
7183
6122
  const cached = await getCache(cacheKey);
7184
6123
  if (cached) {
7185
- import_nodejs_utils39.logger.log({
6124
+ import_nodejs_utils33.logger.log({
7186
6125
  level: "info",
7187
6126
  message: `Cache hit for getById PSGC: ${cacheKey}`
7188
6127
  });
@@ -7193,25 +6132,25 @@ function usePSGCRepo() {
7193
6132
  deletedAt: { $in: ["", null] }
7194
6133
  });
7195
6134
  if (!result) {
7196
- throw new import_nodejs_utils39.BadRequestError("Region not found.");
6135
+ throw new import_nodejs_utils33.BadRequestError("Region not found.");
7197
6136
  }
7198
6137
  setCache(cacheKey, result, 300).then(() => {
7199
- import_nodejs_utils39.logger.log({
6138
+ import_nodejs_utils33.logger.log({
7200
6139
  level: "info",
7201
6140
  message: `Cache set for PSGC by id: ${cacheKey}`
7202
6141
  });
7203
6142
  }).catch((err) => {
7204
- import_nodejs_utils39.logger.log({
6143
+ import_nodejs_utils33.logger.log({
7205
6144
  level: "error",
7206
6145
  message: `Failed to set cache for PSGC by id: ${err.message}`
7207
6146
  });
7208
6147
  });
7209
6148
  return result;
7210
6149
  } catch (error) {
7211
- if (error instanceof import_nodejs_utils39.AppError) {
6150
+ if (error instanceof import_nodejs_utils33.AppError) {
7212
6151
  throw error;
7213
6152
  } else {
7214
- throw new import_nodejs_utils39.InternalServerError("Failed to get PSGC.");
6153
+ throw new import_nodejs_utils33.InternalServerError("Failed to get PSGC.");
7215
6154
  }
7216
6155
  }
7217
6156
  }
@@ -7235,15 +6174,15 @@ function usePSGCRepo() {
7235
6174
  query.code = { $regex: `^${prefix}` };
7236
6175
  cacheKeyOptions.prefix = prefix;
7237
6176
  }
7238
- const cacheKey = (0, import_nodejs_utils39.makeCacheKey)(namespace_collection, { name });
7239
- import_nodejs_utils39.logger.log({
6177
+ const cacheKey = (0, import_nodejs_utils33.makeCacheKey)(namespace_collection, { name });
6178
+ import_nodejs_utils33.logger.log({
7240
6179
  level: "info",
7241
6180
  message: `Query for getByName PSGC: ${JSON.stringify(query)}`
7242
6181
  });
7243
6182
  try {
7244
6183
  const cached = await getCache(cacheKey);
7245
6184
  if (cached) {
7246
- import_nodejs_utils39.logger.log({
6185
+ import_nodejs_utils33.logger.log({
7247
6186
  level: "info",
7248
6187
  message: `Cache hit for getByName PSGC: ${cacheKey}`
7249
6188
  });
@@ -7251,36 +6190,36 @@ function usePSGCRepo() {
7251
6190
  }
7252
6191
  const result = await collection.findOne(query);
7253
6192
  setCache(cacheKey, result, 300).then(() => {
7254
- import_nodejs_utils39.logger.log({
6193
+ import_nodejs_utils33.logger.log({
7255
6194
  level: "info",
7256
6195
  message: `Cache set for PSGC by name: ${cacheKey}`
7257
6196
  });
7258
6197
  }).catch((err) => {
7259
- import_nodejs_utils39.logger.log({
6198
+ import_nodejs_utils33.logger.log({
7260
6199
  level: "error",
7261
6200
  message: `Failed to set cache for PSGC by name: ${err.message}`
7262
6201
  });
7263
6202
  });
7264
6203
  return result;
7265
6204
  } catch (error) {
7266
- if (error instanceof import_nodejs_utils39.AppError) {
6205
+ if (error instanceof import_nodejs_utils33.AppError) {
7267
6206
  throw error;
7268
6207
  } else {
7269
- throw new import_nodejs_utils39.InternalServerError("Failed to get PSGC.");
6208
+ throw new import_nodejs_utils33.InternalServerError("Failed to get PSGC.");
7270
6209
  }
7271
6210
  }
7272
6211
  }
7273
6212
  async function updateFieldById({ _id, field, value } = {}, session) {
7274
6213
  const allowedFields = ["name"];
7275
6214
  if (!allowedFields.includes(field)) {
7276
- throw new import_nodejs_utils39.BadRequestError(
6215
+ throw new import_nodejs_utils33.BadRequestError(
7277
6216
  `Field "${field}" is not allowed to be updated.`
7278
6217
  );
7279
6218
  }
7280
6219
  try {
7281
- _id = new import_mongodb21.ObjectId(_id);
6220
+ _id = new import_mongodb18.ObjectId(_id);
7282
6221
  } catch (error) {
7283
- throw new import_nodejs_utils39.BadRequestError("Invalid ID.");
6222
+ throw new import_nodejs_utils33.BadRequestError("Invalid ID.");
7284
6223
  }
7285
6224
  try {
7286
6225
  await collection.updateOne(
@@ -7291,14 +6230,14 @@ function usePSGCRepo() {
7291
6230
  delCachedData();
7292
6231
  return `Successfully updated PSGC ${field}.`;
7293
6232
  } catch (error) {
7294
- throw new import_nodejs_utils39.InternalServerError(`Failed to update PSGC ${field}.`);
6233
+ throw new import_nodejs_utils33.InternalServerError(`Failed to update PSGC ${field}.`);
7295
6234
  }
7296
6235
  }
7297
6236
  async function deleteById(_id) {
7298
6237
  try {
7299
- _id = new import_mongodb21.ObjectId(_id);
6238
+ _id = new import_mongodb18.ObjectId(_id);
7300
6239
  } catch (error) {
7301
- throw new import_nodejs_utils39.BadRequestError("Invalid ID.");
6240
+ throw new import_nodejs_utils33.BadRequestError("Invalid ID.");
7302
6241
  }
7303
6242
  try {
7304
6243
  await collection.updateOne(
@@ -7308,7 +6247,41 @@ function usePSGCRepo() {
7308
6247
  delCachedData();
7309
6248
  return "Successfully deleted PSGC.";
7310
6249
  } catch (error) {
7311
- throw new import_nodejs_utils39.InternalServerError("Failed to delete PSGC.");
6250
+ throw new import_nodejs_utils33.InternalServerError("Failed to delete PSGC.");
6251
+ }
6252
+ }
6253
+ async function setRegionProvinceName() {
6254
+ try {
6255
+ const cities = await collection.find({ type: { $in: ["City", "Mun"] } }).toArray();
6256
+ for (let index = 0; index < cities.length; index++) {
6257
+ const city = cities[index];
6258
+ if (city.region) {
6259
+ continue;
6260
+ }
6261
+ const province = await collection.findOne({
6262
+ type: "Prov",
6263
+ code: { $regex: `^${city.code.substring(0, 5)}` }
6264
+ });
6265
+ if (province) {
6266
+ await collection.updateOne(
6267
+ { _id: city._id },
6268
+ { $set: { province: province.name } }
6269
+ );
6270
+ }
6271
+ const region = await collection.findOne({
6272
+ type: "Reg",
6273
+ code: { $regex: `^${city.code.substring(0, 2)}` }
6274
+ });
6275
+ if (region) {
6276
+ await collection.updateOne(
6277
+ { _id: city._id },
6278
+ { $set: { region: region.name } }
6279
+ );
6280
+ }
6281
+ }
6282
+ return "Successfully set region name as province name for cities.";
6283
+ } catch (error) {
6284
+ console.log(error);
7312
6285
  }
7313
6286
  }
7314
6287
  return {
@@ -7318,13 +6291,14 @@ function usePSGCRepo() {
7318
6291
  getById,
7319
6292
  updateFieldById,
7320
6293
  deleteById,
7321
- getByName
6294
+ getByName,
6295
+ setRegionProvinceName
7322
6296
  };
7323
6297
  }
7324
6298
 
7325
6299
  // src/resources/psgc/psgc.controller.ts
7326
- var import_nodejs_utils40 = require("@eeplatform/nodejs-utils");
7327
- var import_joi19 = __toESM(require("joi"));
6300
+ var import_nodejs_utils34 = require("@eeplatform/nodejs-utils");
6301
+ var import_joi17 = __toESM(require("joi"));
7328
6302
  function usePSGCController() {
7329
6303
  const {
7330
6304
  add: _add,
@@ -7338,7 +6312,7 @@ function usePSGCController() {
7338
6312
  const value = req.body;
7339
6313
  const { error } = schemaPSGC.validate(value);
7340
6314
  if (error) {
7341
- next(new import_nodejs_utils40.BadRequestError(error.message));
6315
+ next(new import_nodejs_utils34.BadRequestError(error.message));
7342
6316
  return;
7343
6317
  }
7344
6318
  try {
@@ -7354,12 +6328,12 @@ function usePSGCController() {
7354
6328
  }
7355
6329
  async function getAll(req, res, next) {
7356
6330
  const query = req.query;
7357
- const validation = import_joi19.default.object({
7358
- page: import_joi19.default.number().min(1).optional().allow("", null),
7359
- limit: import_joi19.default.number().min(1).optional().allow("", null),
7360
- search: import_joi19.default.string().optional().allow("", null),
7361
- type: import_joi19.default.string().valid("Reg", "Prov", "City", "Mun", "Bgy").required(),
7362
- prefix: import_joi19.default.string().optional().allow("", null)
6331
+ const validation = import_joi17.default.object({
6332
+ page: import_joi17.default.number().min(1).optional().allow("", null),
6333
+ limit: import_joi17.default.number().min(1).optional().allow("", null),
6334
+ search: import_joi17.default.string().optional().allow("", null),
6335
+ type: import_joi17.default.string().valid("Reg", "Prov", "City", "Mun", "Bgy").required(),
6336
+ prefix: import_joi17.default.string().optional().allow("", null)
7363
6337
  });
7364
6338
  const { error } = validation.validate(query);
7365
6339
  const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
@@ -7369,16 +6343,16 @@ function usePSGCController() {
7369
6343
  const prefix = req.query.prefix ? String(req.query.prefix) : "";
7370
6344
  const isPageNumber = isFinite(page);
7371
6345
  if (!isPageNumber) {
7372
- next(new import_nodejs_utils40.BadRequestError("Invalid page number."));
6346
+ next(new import_nodejs_utils34.BadRequestError("Invalid page number."));
7373
6347
  return;
7374
6348
  }
7375
6349
  const isLimitNumber = isFinite(limit);
7376
6350
  if (!isLimitNumber) {
7377
- next(new import_nodejs_utils40.BadRequestError("Invalid limit number."));
6351
+ next(new import_nodejs_utils34.BadRequestError("Invalid limit number."));
7378
6352
  return;
7379
6353
  }
7380
6354
  if (error) {
7381
- next(new import_nodejs_utils40.BadRequestError(error.message));
6355
+ next(new import_nodejs_utils34.BadRequestError(error.message));
7382
6356
  return;
7383
6357
  }
7384
6358
  try {
@@ -7397,12 +6371,12 @@ function usePSGCController() {
7397
6371
  }
7398
6372
  async function getById(req, res, next) {
7399
6373
  const id = req.params.id;
7400
- const validation = import_joi19.default.object({
7401
- id: import_joi19.default.string().hex().required()
6374
+ const validation = import_joi17.default.object({
6375
+ id: import_joi17.default.string().hex().required()
7402
6376
  });
7403
6377
  const { error } = validation.validate({ id });
7404
6378
  if (error) {
7405
- next(new import_nodejs_utils40.BadRequestError(error.message));
6379
+ next(new import_nodejs_utils34.BadRequestError(error.message));
7406
6380
  return;
7407
6381
  }
7408
6382
  try {
@@ -7418,12 +6392,12 @@ function usePSGCController() {
7418
6392
  }
7419
6393
  async function getByName(req, res, next) {
7420
6394
  const name = req.params.name;
7421
- const validation = import_joi19.default.object({
7422
- name: import_joi19.default.string().required()
6395
+ const validation = import_joi17.default.object({
6396
+ name: import_joi17.default.string().required()
7423
6397
  });
7424
6398
  const { error } = validation.validate({ name });
7425
6399
  if (error) {
7426
- next(new import_nodejs_utils40.BadRequestError(error.message));
6400
+ next(new import_nodejs_utils34.BadRequestError(error.message));
7427
6401
  return;
7428
6402
  }
7429
6403
  try {
@@ -7440,14 +6414,14 @@ function usePSGCController() {
7440
6414
  async function updateField(req, res, next) {
7441
6415
  const _id = req.params.id;
7442
6416
  const { field, value } = req.body;
7443
- const validation = import_joi19.default.object({
7444
- _id: import_joi19.default.string().hex().required(),
7445
- field: import_joi19.default.string().valid("name", "director", "directorName").required(),
7446
- value: import_joi19.default.string().required()
6417
+ const validation = import_joi17.default.object({
6418
+ _id: import_joi17.default.string().hex().required(),
6419
+ field: import_joi17.default.string().valid("name", "director", "directorName").required(),
6420
+ value: import_joi17.default.string().required()
7447
6421
  });
7448
6422
  const { error } = validation.validate({ _id, field, value });
7449
6423
  if (error) {
7450
- next(new import_nodejs_utils40.BadRequestError(error.message));
6424
+ next(new import_nodejs_utils34.BadRequestError(error.message));
7451
6425
  return;
7452
6426
  }
7453
6427
  try {
@@ -7460,12 +6434,12 @@ function usePSGCController() {
7460
6434
  }
7461
6435
  async function deleteById(req, res, next) {
7462
6436
  const _id = req.params.id;
7463
- const validation = import_joi19.default.object({
7464
- _id: import_joi19.default.string().hex().required()
6437
+ const validation = import_joi17.default.object({
6438
+ _id: import_joi17.default.string().hex().required()
7465
6439
  });
7466
6440
  const { error } = validation.validate({ _id });
7467
6441
  if (error) {
7468
- next(new import_nodejs_utils40.BadRequestError(error.message));
6442
+ next(new import_nodejs_utils34.BadRequestError(error.message));
7469
6443
  return;
7470
6444
  }
7471
6445
  try {
@@ -7504,8 +6478,6 @@ function usePSGCController() {
7504
6478
  MAILER_TRANSPORT_PORT,
7505
6479
  MAILER_TRANSPORT_SECURE,
7506
6480
  MAddress,
7507
- MBuilding,
7508
- MBuildingUnit,
7509
6481
  MFile,
7510
6482
  MMember,
7511
6483
  MONGO_DB,
@@ -7538,23 +6510,14 @@ function usePSGCController() {
7538
6510
  addressSchema,
7539
6511
  isDev,
7540
6512
  modelPSGC,
7541
- schemaBuilding,
7542
- schemaBuildingUnit,
7543
6513
  schemaOrg,
7544
6514
  schemaPSGC,
7545
- schemaUpdateOptions,
7546
6515
  transactionSchema,
7547
6516
  useAddressController,
7548
6517
  useAddressRepo,
7549
6518
  useAudioTranscriptionController,
7550
6519
  useAuthController,
7551
6520
  useAuthService,
7552
- useBuildingController,
7553
- useBuildingRepo,
7554
- useBuildingService,
7555
- useBuildingUnitController,
7556
- useBuildingUnitRepo,
7557
- useBuildingUnitService,
7558
6521
  useCounterModel,
7559
6522
  useCounterRepo,
7560
6523
  useFileController,