@goweekdays/core 2.15.5 → 2.15.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.mjs CHANGED
@@ -474,9 +474,9 @@ function useAuthService() {
474
474
  // src/resources/auth/auth.controller.ts
475
475
  import Joi55 from "joi";
476
476
  import {
477
- AppError as AppError29,
477
+ AppError as AppError30,
478
478
  BadRequestError as BadRequestError59,
479
- InternalServerError as InternalServerError29,
479
+ InternalServerError as InternalServerError30,
480
480
  logger as logger31
481
481
  } from "@goweekdays/utils";
482
482
 
@@ -488,9 +488,9 @@ import {
488
488
  getDirectory as getDirectory2,
489
489
  BadRequestError as BadRequestError58,
490
490
  NotFoundError as NotFoundError3,
491
- InternalServerError as InternalServerError28,
491
+ InternalServerError as InternalServerError29,
492
492
  useAtlas as useAtlas6,
493
- AppError as AppError28
493
+ AppError as AppError29
494
494
  } from "@goweekdays/utils";
495
495
 
496
496
  // src/resources/verification/verification.model.ts
@@ -885,9 +885,9 @@ var APP_ORG = process.env.APP_ORG || "http://localhost/organizations/create";
885
885
 
886
886
  // src/resources/user/user.service.ts
887
887
  import {
888
- AppError as AppError26,
888
+ AppError as AppError27,
889
889
  BadRequestError as BadRequestError56,
890
- InternalServerError as InternalServerError26,
890
+ InternalServerError as InternalServerError27,
891
891
  NotFoundError as NotFoundError2,
892
892
  hashPassword,
893
893
  logger as logger29,
@@ -3465,6 +3465,11 @@ function useAppService() {
3465
3465
  name: "Finance",
3466
3466
  description: "Finance and billing services."
3467
3467
  },
3468
+ {
3469
+ code: "assets",
3470
+ name: "Assets",
3471
+ description: "Asset management and tracking."
3472
+ },
3468
3473
  {
3469
3474
  code: "marketplace",
3470
3475
  name: "Marketplace",
@@ -4741,10 +4746,11 @@ function useOrgRepo() {
4741
4746
 
4742
4747
  // src/resources/organization/organization.service.ts
4743
4748
  import {
4749
+ AppError as AppError26,
4744
4750
  BadRequestError as BadRequestError54,
4745
4751
  compileHandlebar,
4746
4752
  getDirectory,
4747
- logger as logger28,
4753
+ InternalServerError as InternalServerError26,
4748
4754
  useAtlas as useAtlas4,
4749
4755
  useMailer
4750
4756
  } from "@goweekdays/utils";
@@ -11005,22 +11011,23 @@ function useOrgService() {
11005
11011
  },
11006
11012
  filePath
11007
11013
  });
11008
- mailer.sendMail({
11014
+ await mailer.sendMail({
11009
11015
  to: verification.email,
11010
11016
  subject: "Welcome to GoWeekdays - Your Organization is Ready",
11011
11017
  from: `"GoWeekdays" <support@goweekdays.com>`,
11012
11018
  html: emailContent
11013
- }).catch((error2) => {
11014
- logger28.log({
11015
- level: "error",
11016
- message: `Error sending user invite email: ${error2}`
11017
- });
11018
11019
  });
11019
11020
  await session?.commitTransaction();
11020
11021
  return "Successfully created organization with verification.";
11021
11022
  } catch (error2) {
11022
11023
  await session?.abortTransaction();
11023
- throw error2;
11024
+ if (error2 instanceof AppError26) {
11025
+ throw error2;
11026
+ } else {
11027
+ throw new InternalServerError26(
11028
+ "Failed to create organization with verification."
11029
+ );
11030
+ }
11024
11031
  } finally {
11025
11032
  await session?.endSession();
11026
11033
  }
@@ -11129,22 +11136,23 @@ function useOrgService() {
11129
11136
  },
11130
11137
  filePath
11131
11138
  });
11132
- mailer.sendMail({
11139
+ await mailer.sendMail({
11133
11140
  to: verification.email,
11134
11141
  subject: "Welcome to GoWeekdays - Your Organization is Ready",
11135
11142
  from: `"GoWeekdays" <support@goweekdays.com>`,
11136
11143
  html: emailContent
11137
- }).catch((error2) => {
11138
- logger28.log({
11139
- level: "error",
11140
- message: `Error sending user invite email: ${error2}`
11141
- });
11142
11144
  });
11143
11145
  await session?.commitTransaction();
11144
11146
  return "Successfully created organization with verification.";
11145
11147
  } catch (error2) {
11146
11148
  await session?.abortTransaction();
11147
- throw error2;
11149
+ if (error2 instanceof AppError26) {
11150
+ throw error2;
11151
+ } else {
11152
+ throw new InternalServerError26(
11153
+ "Failed to create organization with verification."
11154
+ );
11155
+ }
11148
11156
  } finally {
11149
11157
  await session?.endSession();
11150
11158
  }
@@ -11455,10 +11463,10 @@ function useUserService() {
11455
11463
  });
11456
11464
  return insertedId;
11457
11465
  } catch (error) {
11458
- if (error instanceof AppError26) {
11466
+ if (error instanceof AppError27) {
11459
11467
  throw error;
11460
11468
  } else {
11461
- throw new InternalServerError26(`Error creating user: ${error}`);
11469
+ throw new InternalServerError27(`Error creating user: ${error}`);
11462
11470
  }
11463
11471
  }
11464
11472
  }
@@ -11535,10 +11543,10 @@ function useUserService() {
11535
11543
  return userId;
11536
11544
  } catch (error) {
11537
11545
  await session?.abortTransaction();
11538
- if (error instanceof AppError26) {
11546
+ if (error instanceof AppError27) {
11539
11547
  throw error;
11540
11548
  } else {
11541
- throw new InternalServerError26("Failed to create user by invite.");
11549
+ throw new InternalServerError27("Failed to create user by invite.");
11542
11550
  }
11543
11551
  } finally {
11544
11552
  session?.endSession();
@@ -11604,11 +11612,11 @@ function useUserService() {
11604
11612
  try {
11605
11613
  hashedPassword = await hashPassword(value.newPassword);
11606
11614
  } catch (error) {
11607
- throw new InternalServerError26(`Error hashing password: ${error}`);
11615
+ throw new InternalServerError27(`Error hashing password: ${error}`);
11608
11616
  }
11609
11617
  const session = useAtlas5.getClient()?.startSession();
11610
11618
  if (!session) {
11611
- throw new InternalServerError26("Failed to start database session.");
11619
+ throw new InternalServerError27("Failed to start database session.");
11612
11620
  }
11613
11621
  try {
11614
11622
  session.startTransaction();
@@ -11635,10 +11643,10 @@ function useUserService() {
11635
11643
  return "Successfully reset password.";
11636
11644
  } catch (error) {
11637
11645
  await session.abortTransaction();
11638
- if (error instanceof AppError26) {
11646
+ if (error instanceof AppError27) {
11639
11647
  throw error;
11640
11648
  }
11641
- throw new InternalServerError26("Failed to reset password.");
11649
+ throw new InternalServerError27("Failed to reset password.");
11642
11650
  }
11643
11651
  }
11644
11652
  const { updateName: updateMemberName } = useMemberRepo();
@@ -11756,9 +11764,9 @@ function useUserService() {
11756
11764
 
11757
11765
  // src/resources/user/user.controller.ts
11758
11766
  import {
11759
- AppError as AppError27,
11767
+ AppError as AppError28,
11760
11768
  BadRequestError as BadRequestError57,
11761
- InternalServerError as InternalServerError27
11769
+ InternalServerError as InternalServerError28
11762
11770
  } from "@goweekdays/utils";
11763
11771
  import Joi53 from "joi";
11764
11772
  function useUserController() {
@@ -11903,10 +11911,10 @@ function useUserController() {
11903
11911
  res.json({ message: "Successfully updated profile picture." });
11904
11912
  return;
11905
11913
  } catch (error2) {
11906
- if (error2 instanceof AppError27) {
11914
+ if (error2 instanceof AppError28) {
11907
11915
  next(error2);
11908
11916
  } else {
11909
- next(new InternalServerError27(error2));
11917
+ next(new InternalServerError28(error2));
11910
11918
  }
11911
11919
  }
11912
11920
  }
@@ -12042,16 +12050,11 @@ function useVerificationService() {
12042
12050
  },
12043
12051
  filePath: filePath2
12044
12052
  });
12045
- mailer.sendMail({
12053
+ await mailer.sendMail({
12046
12054
  to: email,
12047
12055
  subject: "Member Invite",
12048
12056
  html: emailContent2,
12049
12057
  from: `"GoWeekdays" <support@goweekdays.com>`
12050
- }).catch((error) => {
12051
- logger30.log({
12052
- level: "error",
12053
- message: `Error sending user invite email: ${error}`
12054
- });
12055
12058
  });
12056
12059
  return res2;
12057
12060
  }
@@ -12064,20 +12067,19 @@ function useVerificationService() {
12064
12067
  },
12065
12068
  filePath
12066
12069
  });
12067
- mailer.sendMail({
12070
+ await mailer.sendMail({
12068
12071
  to: email,
12069
12072
  subject: "User Invite",
12070
12073
  html: emailContent,
12071
12074
  from: `"GoWeekdays" <support@goweekdays.com>`
12072
- }).catch((error) => {
12073
- logger30.log({
12074
- level: "error",
12075
- message: `Error sending user invite email: ${error}`
12076
- });
12077
12075
  });
12078
12076
  return res;
12079
12077
  } catch (error) {
12080
- throw error;
12078
+ if (error instanceof AppError29) {
12079
+ throw error;
12080
+ } else {
12081
+ throw new InternalServerError29("Failed to create user invitation.");
12082
+ }
12081
12083
  }
12082
12084
  }
12083
12085
  async function createForgetPassword(email) {
@@ -12099,20 +12101,19 @@ function useVerificationService() {
12099
12101
  },
12100
12102
  filePath
12101
12103
  });
12102
- mailer.sendMail({
12104
+ await mailer.sendMail({
12103
12105
  to: email,
12104
12106
  subject: "Forget Password",
12105
12107
  from: `"GoWeekdays" <support@goweekdays.com>`,
12106
12108
  html: emailContent
12107
- }).catch((error) => {
12108
- logger30.log({
12109
- level: "error",
12110
- message: `Error sending forget password email: ${error}`
12111
- });
12112
12109
  });
12113
12110
  return "Successfully created a link to reset password. Please check your email.";
12114
12111
  } catch (error) {
12115
- throw new InternalServerError28("Failed to create forget password link.");
12112
+ if (error instanceof AppError29) {
12113
+ throw error;
12114
+ } else {
12115
+ throw new InternalServerError29("Failed to create forget password link.");
12116
+ }
12116
12117
  }
12117
12118
  }
12118
12119
  async function getById(id) {
@@ -12248,7 +12249,7 @@ function useVerificationService() {
12248
12249
  try {
12249
12250
  await updateStatusById(id, "cancelled");
12250
12251
  } catch (error) {
12251
- throw new InternalServerError28(
12252
+ throw new InternalServerError29(
12252
12253
  `Error cancelling user invitation: ${error}`
12253
12254
  );
12254
12255
  }
@@ -12289,20 +12290,19 @@ function useVerificationService() {
12289
12290
  },
12290
12291
  filePath
12291
12292
  });
12292
- mailer.sendMail({
12293
+ await mailer.sendMail({
12293
12294
  to: email,
12294
12295
  subject: "Sign Up Verification",
12295
12296
  html: emailContent,
12296
12297
  from: `"GoWeekdays" <support@goweekdays.com>`
12297
- }).catch((error) => {
12298
- logger30.log({
12299
- level: "error",
12300
- message: `Error sending user invite email: ${error}`
12301
- });
12302
12298
  });
12303
12299
  return res;
12304
12300
  } catch (error) {
12305
- throw error;
12301
+ if (error instanceof AppError29) {
12302
+ throw error;
12303
+ } else {
12304
+ throw new InternalServerError29("Failed to create sign up verification.");
12305
+ }
12306
12306
  }
12307
12307
  }
12308
12308
  const { getByOrg } = useSubscriptionRepo();
@@ -12381,16 +12381,11 @@ function useVerificationService() {
12381
12381
  },
12382
12382
  filePath: filePath2
12383
12383
  });
12384
- mailer.sendMail({
12384
+ await mailer.sendMail({
12385
12385
  to: value.email,
12386
12386
  subject: "Member Invite",
12387
12387
  html: emailContent2,
12388
12388
  from: `"GoWeekdays" <support@goweekdays.com>`
12389
- }).catch((error2) => {
12390
- logger30.log({
12391
- level: "error",
12392
- message: `Error sending user invite email: ${error2}`
12393
- });
12394
12389
  });
12395
12390
  return verificationId2;
12396
12391
  }
@@ -12403,7 +12398,7 @@ function useVerificationService() {
12403
12398
  },
12404
12399
  filePath
12405
12400
  });
12406
- mailer.sendMail({
12401
+ await mailer.sendMail({
12407
12402
  to: value.email,
12408
12403
  subject: "User Invite",
12409
12404
  html: emailContent,
@@ -12416,10 +12411,10 @@ function useVerificationService() {
12416
12411
  });
12417
12412
  return verificationId;
12418
12413
  } catch (error2) {
12419
- if (error2 instanceof AppError28) {
12414
+ if (error2 instanceof AppError29) {
12420
12415
  throw error2;
12421
12416
  } else {
12422
- throw new InternalServerError28("Failed to invite member.");
12417
+ throw new InternalServerError29("Failed to invite member.");
12423
12418
  }
12424
12419
  }
12425
12420
  }
@@ -12442,10 +12437,10 @@ function useVerificationService() {
12442
12437
  await _updateStatusById(id, "cancelled");
12443
12438
  return "Successfully cancelled the invitation.";
12444
12439
  } catch (error2) {
12445
- if (error2 instanceof AppError28) {
12440
+ if (error2 instanceof AppError29) {
12446
12441
  throw error2;
12447
12442
  } else {
12448
- throw new InternalServerError28("Failed to cancel the invitation.");
12443
+ throw new InternalServerError29("Failed to cancel the invitation.");
12449
12444
  }
12450
12445
  }
12451
12446
  }
@@ -12483,10 +12478,10 @@ function useVerificationService() {
12483
12478
  });
12484
12479
  return "Successfully created a link to reset password. Please check your email.";
12485
12480
  } catch (error2) {
12486
- if (error2 instanceof AppError28) {
12481
+ if (error2 instanceof AppError29) {
12487
12482
  throw error2;
12488
12483
  } else {
12489
- throw new InternalServerError28(
12484
+ throw new InternalServerError29(
12490
12485
  "Failed to process forget password request."
12491
12486
  );
12492
12487
  }
@@ -12544,10 +12539,10 @@ function useVerificationService() {
12544
12539
  message: `Error processing organization setup fee: ${error}`
12545
12540
  });
12546
12541
  await session?.abortTransaction();
12547
- if (error instanceof AppError28) {
12542
+ if (error instanceof AppError29) {
12548
12543
  throw error;
12549
12544
  }
12550
- throw new InternalServerError28(
12545
+ throw new InternalServerError29(
12551
12546
  "Failed to process organization setup fee."
12552
12547
  );
12553
12548
  } finally {
@@ -12604,10 +12599,10 @@ function useVerificationService() {
12604
12599
  message: `Error inviting organization: ${error2}`
12605
12600
  });
12606
12601
  await session?.abortTransaction();
12607
- if (error2 instanceof AppError28) {
12602
+ if (error2 instanceof AppError29) {
12608
12603
  throw error2;
12609
12604
  }
12610
- throw new InternalServerError28(
12605
+ throw new InternalServerError29(
12611
12606
  "Failed to process organization setup fee."
12612
12607
  );
12613
12608
  } finally {
@@ -12663,10 +12658,10 @@ function useAuthController() {
12663
12658
  level: "error",
12664
12659
  message: `Error during login: ${error2.message}`
12665
12660
  });
12666
- if (error2 instanceof AppError29) {
12661
+ if (error2 instanceof AppError30) {
12667
12662
  next(error2);
12668
12663
  } else {
12669
- next(new InternalServerError29("An unexpected error occurred"));
12664
+ next(new InternalServerError30("An unexpected error occurred"));
12670
12665
  }
12671
12666
  return;
12672
12667
  }
@@ -12681,10 +12676,10 @@ function useAuthController() {
12681
12676
  await useAuthService().logout(user);
12682
12677
  res.json({ message: "Logged out successfully" });
12683
12678
  } catch (error) {
12684
- if (error instanceof AppError29) {
12679
+ if (error instanceof AppError30) {
12685
12680
  next(error);
12686
12681
  } else {
12687
- next(new InternalServerError29("An unexpected error occurred"));
12682
+ next(new InternalServerError30("An unexpected error occurred"));
12688
12683
  }
12689
12684
  }
12690
12685
  }
@@ -12812,9 +12807,9 @@ function MBuildingUnit(value) {
12812
12807
 
12813
12808
  // src/resources/building/building.repository.ts
12814
12809
  import {
12815
- AppError as AppError30,
12810
+ AppError as AppError31,
12816
12811
  BadRequestError as BadRequestError61,
12817
- InternalServerError as InternalServerError30,
12812
+ InternalServerError as InternalServerError31,
12818
12813
  logger as logger33,
12819
12814
  makeCacheKey as makeCacheKey19,
12820
12815
  paginate as paginate17,
@@ -12846,7 +12841,7 @@ function useBuildingRepo() {
12846
12841
  level: "error",
12847
12842
  message: error.message
12848
12843
  });
12849
- if (error instanceof AppError30) {
12844
+ if (error instanceof AppError31) {
12850
12845
  throw error;
12851
12846
  } else {
12852
12847
  const isDuplicated = error.message.includes("duplicate");
@@ -12876,7 +12871,7 @@ function useBuildingRepo() {
12876
12871
  level: "error",
12877
12872
  message: error.message
12878
12873
  });
12879
- if (error instanceof AppError30) {
12874
+ if (error instanceof AppError31) {
12880
12875
  throw error;
12881
12876
  } else {
12882
12877
  throw new Error("Failed to update building.");
@@ -12988,10 +12983,10 @@ function useBuildingRepo() {
12988
12983
  });
12989
12984
  return result;
12990
12985
  } catch (error) {
12991
- if (error instanceof AppError30) {
12986
+ if (error instanceof AppError31) {
12992
12987
  throw error;
12993
12988
  } else {
12994
- throw new InternalServerError30("Failed to get building.");
12989
+ throw new InternalServerError31("Failed to get building.");
12995
12990
  }
12996
12991
  }
12997
12992
  }
@@ -13013,10 +13008,10 @@ function useBuildingRepo() {
13013
13008
  level: "error",
13014
13009
  message: error.message
13015
13010
  });
13016
- if (error instanceof AppError30) {
13011
+ if (error instanceof AppError31) {
13017
13012
  throw error;
13018
13013
  } else {
13019
- throw new InternalServerError30("Failed to delete building.");
13014
+ throw new InternalServerError31("Failed to delete building.");
13020
13015
  }
13021
13016
  }
13022
13017
  }
@@ -13035,9 +13030,9 @@ import { BadRequestError as BadRequestError63, NotFoundError as NotFoundError4,
13035
13030
 
13036
13031
  // src/resources/building/building-unit.repository.ts
13037
13032
  import {
13038
- AppError as AppError31,
13033
+ AppError as AppError32,
13039
13034
  BadRequestError as BadRequestError62,
13040
- InternalServerError as InternalServerError31,
13035
+ InternalServerError as InternalServerError32,
13041
13036
  logger as logger34,
13042
13037
  makeCacheKey as makeCacheKey20,
13043
13038
  paginate as paginate18,
@@ -13083,7 +13078,7 @@ function useBuildingUnitRepo() {
13083
13078
  level: "error",
13084
13079
  message: error.message
13085
13080
  });
13086
- if (error instanceof AppError31) {
13081
+ if (error instanceof AppError32) {
13087
13082
  throw error;
13088
13083
  } else {
13089
13084
  throw new Error("Failed to create building unit.");
@@ -13113,7 +13108,7 @@ function useBuildingUnitRepo() {
13113
13108
  level: "error",
13114
13109
  message: error2.message
13115
13110
  });
13116
- if (error2 instanceof AppError31) {
13111
+ if (error2 instanceof AppError32) {
13117
13112
  throw error2;
13118
13113
  } else {
13119
13114
  throw new Error("Failed to create building unit.");
@@ -13143,7 +13138,7 @@ function useBuildingUnitRepo() {
13143
13138
  level: "error",
13144
13139
  message: error2.message
13145
13140
  });
13146
- if (error2 instanceof AppError31) {
13141
+ if (error2 instanceof AppError32) {
13147
13142
  throw error2;
13148
13143
  } else {
13149
13144
  throw new Error("Failed to update building unit.");
@@ -13270,10 +13265,10 @@ function useBuildingUnitRepo() {
13270
13265
  });
13271
13266
  return result;
13272
13267
  } catch (error) {
13273
- if (error instanceof AppError31) {
13268
+ if (error instanceof AppError32) {
13274
13269
  throw error;
13275
13270
  } else {
13276
- throw new InternalServerError31("Failed to get building unit.");
13271
+ throw new InternalServerError32("Failed to get building unit.");
13277
13272
  }
13278
13273
  }
13279
13274
  }
@@ -13314,10 +13309,10 @@ function useBuildingUnitRepo() {
13314
13309
  });
13315
13310
  return result;
13316
13311
  } catch (error) {
13317
- if (error instanceof AppError31) {
13312
+ if (error instanceof AppError32) {
13318
13313
  throw error;
13319
13314
  } else {
13320
- throw new InternalServerError31("Failed to get building unit.");
13315
+ throw new InternalServerError32("Failed to get building unit.");
13321
13316
  }
13322
13317
  }
13323
13318
  }
@@ -13356,10 +13351,10 @@ function useBuildingUnitRepo() {
13356
13351
  });
13357
13352
  return result;
13358
13353
  } catch (error) {
13359
- if (error instanceof AppError31) {
13354
+ if (error instanceof AppError32) {
13360
13355
  throw error;
13361
13356
  } else {
13362
- throw new InternalServerError31("Failed to get building unit.");
13357
+ throw new InternalServerError32("Failed to get building unit.");
13363
13358
  }
13364
13359
  }
13365
13360
  }
@@ -13382,7 +13377,7 @@ function useBuildingUnitRepo() {
13382
13377
  level: "error",
13383
13378
  message: error.message
13384
13379
  });
13385
- if (error instanceof AppError31) {
13380
+ if (error instanceof AppError32) {
13386
13381
  throw error;
13387
13382
  } else {
13388
13383
  throw new Error("Failed to deleted room/facility.");
@@ -14014,9 +14009,9 @@ function useFileService() {
14014
14009
 
14015
14010
  // src/resources/file/file.controller.ts
14016
14011
  import {
14017
- AppError as AppError32,
14012
+ AppError as AppError33,
14018
14013
  BadRequestError as BadRequestError67,
14019
- InternalServerError as InternalServerError32
14014
+ InternalServerError as InternalServerError33
14020
14015
  } from "@goweekdays/utils";
14021
14016
  import Joi59 from "joi";
14022
14017
  function useFileController() {
@@ -14031,10 +14026,10 @@ function useFileController() {
14031
14026
  res.json({ message: "Successfully uploaded file", id });
14032
14027
  return;
14033
14028
  } catch (error) {
14034
- if (error instanceof AppError32) {
14029
+ if (error instanceof AppError33) {
14035
14030
  next(error);
14036
14031
  } else {
14037
- next(new InternalServerError32(error));
14032
+ next(new InternalServerError33(error));
14038
14033
  }
14039
14034
  }
14040
14035
  }
@@ -14050,10 +14045,10 @@ function useFileController() {
14050
14045
  res.json({ message });
14051
14046
  return;
14052
14047
  } catch (error2) {
14053
- if (error2 instanceof AppError32) {
14048
+ if (error2 instanceof AppError33) {
14054
14049
  next(error2);
14055
14050
  } else {
14056
- next(new InternalServerError32(error2));
14051
+ next(new InternalServerError33(error2));
14057
14052
  }
14058
14053
  }
14059
14054
  }
@@ -14065,9 +14060,9 @@ function useFileController() {
14065
14060
 
14066
14061
  // src/resources/options/option.repository.ts
14067
14062
  import {
14068
- AppError as AppError33,
14063
+ AppError as AppError34,
14069
14064
  BadRequestError as BadRequestError69,
14070
- InternalServerError as InternalServerError33,
14065
+ InternalServerError as InternalServerError34,
14071
14066
  logger as logger38,
14072
14067
  makeCacheKey as makeCacheKey22,
14073
14068
  paginate as paginate19,
@@ -14207,10 +14202,10 @@ function useOptionRepo(namespace_collection) {
14207
14202
  });
14208
14203
  return result;
14209
14204
  } catch (error) {
14210
- if (error instanceof AppError33) {
14205
+ if (error instanceof AppError34) {
14211
14206
  throw error;
14212
14207
  } else {
14213
- throw new InternalServerError33("Failed to get job post.");
14208
+ throw new InternalServerError34("Failed to get job post.");
14214
14209
  }
14215
14210
  }
14216
14211
  }
@@ -14374,13 +14369,13 @@ import { BadRequestError as BadRequestError74, logger as logger40 } from "@gowee
14374
14369
 
14375
14370
  // src/resources/job-post/job.post.repository.ts
14376
14371
  import {
14377
- AppError as AppError34,
14372
+ AppError as AppError35,
14378
14373
  BadRequestError as BadRequestError72,
14379
14374
  useRepo as useRepo24,
14380
14375
  makeCacheKey as makeCacheKey23,
14381
14376
  paginate as paginate20,
14382
14377
  logger as logger39,
14383
- InternalServerError as InternalServerError34
14378
+ InternalServerError as InternalServerError35
14384
14379
  } from "@goweekdays/utils";
14385
14380
  import { ObjectId as ObjectId39 } from "mongodb";
14386
14381
  function useJobPostRepo() {
@@ -14555,7 +14550,7 @@ function useJobPostRepo() {
14555
14550
  });
14556
14551
  return data;
14557
14552
  } catch (error) {
14558
- throw new InternalServerError34(
14553
+ throw new InternalServerError35(
14559
14554
  "Internal server error, failed to retrieve job posts."
14560
14555
  );
14561
14556
  }
@@ -14593,10 +14588,10 @@ function useJobPostRepo() {
14593
14588
  });
14594
14589
  return result;
14595
14590
  } catch (error) {
14596
- if (error instanceof AppError34) {
14591
+ if (error instanceof AppError35) {
14597
14592
  throw error;
14598
14593
  } else {
14599
- throw new InternalServerError34("Failed to get job post.");
14594
+ throw new InternalServerError35("Failed to get job post.");
14600
14595
  }
14601
14596
  }
14602
14597
  }
@@ -14618,7 +14613,7 @@ function useJobPostRepo() {
14618
14613
  repo.delCachedData();
14619
14614
  return "Successfully updated job post.";
14620
14615
  } catch (error2) {
14621
- throw new InternalServerError34("Failed to update job post.");
14616
+ throw new InternalServerError35("Failed to update job post.");
14622
14617
  }
14623
14618
  }
14624
14619
  async function deleteById(_id, session) {
@@ -14642,7 +14637,7 @@ function useJobPostRepo() {
14642
14637
  repo.delCachedData();
14643
14638
  return "Successfully deleted job post.";
14644
14639
  } catch (error) {
14645
- throw new InternalServerError34("Failed to delete job post.");
14640
+ throw new InternalServerError35("Failed to delete job post.");
14646
14641
  }
14647
14642
  }
14648
14643
  async function updateStatusById(_id, status2) {
@@ -14667,10 +14662,10 @@ function useJobPostRepo() {
14667
14662
  repo.delCachedData();
14668
14663
  return "Successfully updated job post status.";
14669
14664
  } catch (error) {
14670
- if (error instanceof AppError34) {
14665
+ if (error instanceof AppError35) {
14671
14666
  throw error;
14672
14667
  }
14673
- throw new InternalServerError34("Failed to update job post status.");
14668
+ throw new InternalServerError35("Failed to update job post status.");
14674
14669
  }
14675
14670
  }
14676
14671
  return {
@@ -14687,9 +14682,9 @@ function useJobPostRepo() {
14687
14682
 
14688
14683
  // src/resources/job-post/job.post.service.ts
14689
14684
  import {
14690
- AppError as AppError35,
14685
+ AppError as AppError36,
14691
14686
  BadRequestError as BadRequestError73,
14692
- InternalServerError as InternalServerError35,
14687
+ InternalServerError as InternalServerError36,
14693
14688
  useAtlas as useAtlas11
14694
14689
  } from "@goweekdays/utils";
14695
14690
  import Joi63 from "joi";
@@ -14707,7 +14702,7 @@ function useJobPostService() {
14707
14702
  async function add(value) {
14708
14703
  const session = useAtlas11.getClient()?.startSession();
14709
14704
  if (!session) {
14710
- throw new InternalServerError35("Failed to start database session.");
14705
+ throw new InternalServerError36("Failed to start database session.");
14711
14706
  }
14712
14707
  try {
14713
14708
  session.startTransaction();
@@ -14735,10 +14730,10 @@ function useJobPostService() {
14735
14730
  return "Successfully created job post.";
14736
14731
  } catch (error) {
14737
14732
  await session.abortTransaction();
14738
- if (error instanceof AppError35) {
14733
+ if (error instanceof AppError36) {
14739
14734
  throw error;
14740
14735
  }
14741
- throw new InternalServerError35("Failed to create job post.");
14736
+ throw new InternalServerError36("Failed to create job post.");
14742
14737
  } finally {
14743
14738
  await session.endSession();
14744
14739
  }
@@ -14752,10 +14747,10 @@ function useJobPostService() {
14752
14747
  await _deleteById(id);
14753
14748
  return "Successfully deleted job post.";
14754
14749
  } catch (error2) {
14755
- if (error2 instanceof AppError35) {
14750
+ if (error2 instanceof AppError36) {
14756
14751
  throw error2;
14757
14752
  } else {
14758
- throw new InternalServerError35("Failed to delete job post.");
14753
+ throw new InternalServerError36("Failed to delete job post.");
14759
14754
  }
14760
14755
  }
14761
14756
  }
@@ -14782,10 +14777,10 @@ function useJobPostService() {
14782
14777
  await _updateStatusById(id, newStatus);
14783
14778
  return "Successfully updated job post status.";
14784
14779
  } catch (error) {
14785
- if (error instanceof AppError35) {
14780
+ if (error instanceof AppError36) {
14786
14781
  throw error;
14787
14782
  }
14788
- throw new InternalServerError35("Failed to update job post status.");
14783
+ throw new InternalServerError36("Failed to update job post status.");
14789
14784
  }
14790
14785
  }
14791
14786
  return {
@@ -15434,7 +15429,7 @@ function modelJobProfileCert(data) {
15434
15429
 
15435
15430
  // src/resources/job-profile/job.profile.repository.ts
15436
15431
  import {
15437
- AppError as AppError36,
15432
+ AppError as AppError37,
15438
15433
  BadRequestError as BadRequestError77,
15439
15434
  logger as logger41,
15440
15435
  makeCacheKey as makeCacheKey24,
@@ -15465,7 +15460,7 @@ function useJobProfileRepo() {
15465
15460
  repo.delCachedData();
15466
15461
  return res.insertedId;
15467
15462
  } catch (error2) {
15468
- if (error2 instanceof AppError36) {
15463
+ if (error2 instanceof AppError37) {
15469
15464
  throw error2;
15470
15465
  }
15471
15466
  throw new BadRequestError77(
@@ -15517,7 +15512,7 @@ function useJobProfileRepo() {
15517
15512
  });
15518
15513
  return data;
15519
15514
  } catch (error) {
15520
- if (error instanceof AppError36) {
15515
+ if (error instanceof AppError37) {
15521
15516
  throw error;
15522
15517
  }
15523
15518
  throw new BadRequestError77(`Failed to get job profiles: ${error.message}`);
@@ -15556,7 +15551,7 @@ function useJobProfileRepo() {
15556
15551
  });
15557
15552
  return data;
15558
15553
  } catch (error2) {
15559
- if (error2 instanceof AppError36) {
15554
+ if (error2 instanceof AppError37) {
15560
15555
  throw error2;
15561
15556
  }
15562
15557
  throw new BadRequestError77(
@@ -15585,7 +15580,7 @@ function useJobProfileRepo() {
15585
15580
  repo.delCachedData();
15586
15581
  return "Successfully updated job profile contact info.";
15587
15582
  } catch (error2) {
15588
- if (error2 instanceof AppError36) {
15583
+ if (error2 instanceof AppError37) {
15589
15584
  throw error2;
15590
15585
  }
15591
15586
  throw new BadRequestError77(
@@ -15611,7 +15606,7 @@ function useJobProfileRepo() {
15611
15606
  repo.delCachedData();
15612
15607
  return "Successfully updated job profile summary.";
15613
15608
  } catch (error2) {
15614
- if (error2 instanceof AppError36) {
15609
+ if (error2 instanceof AppError37) {
15615
15610
  throw error2;
15616
15611
  }
15617
15612
  throw new BadRequestError77(
@@ -15640,7 +15635,7 @@ function useJobProfileRepo() {
15640
15635
  repo.delCachedData();
15641
15636
  return "Successfully updated job profile personal info.";
15642
15637
  } catch (error2) {
15643
- if (error2 instanceof AppError36) {
15638
+ if (error2 instanceof AppError37) {
15644
15639
  throw error2;
15645
15640
  }
15646
15641
  throw new BadRequestError77(
@@ -15670,7 +15665,7 @@ function useJobProfileRepo() {
15670
15665
  repo.delCachedData();
15671
15666
  return "Successfully added job profile work experience.";
15672
15667
  } catch (error2) {
15673
- if (error2 instanceof AppError36) {
15668
+ if (error2 instanceof AppError37) {
15674
15669
  throw error2;
15675
15670
  }
15676
15671
  throw new BadRequestError77(
@@ -15699,7 +15694,7 @@ function useJobProfileRepo() {
15699
15694
  repo.delCachedData();
15700
15695
  return "Successfully updated job profile work experience.";
15701
15696
  } catch (error2) {
15702
- if (error2 instanceof AppError36) {
15697
+ if (error2 instanceof AppError37) {
15703
15698
  throw error2;
15704
15699
  }
15705
15700
  throw new BadRequestError77(
@@ -15739,7 +15734,7 @@ function useJobProfileRepo() {
15739
15734
  repo.delCachedData();
15740
15735
  return "Successfully deleted job profile work experience.";
15741
15736
  } catch (error2) {
15742
- if (error2 instanceof AppError36) {
15737
+ if (error2 instanceof AppError37) {
15743
15738
  throw error2;
15744
15739
  }
15745
15740
  throw new BadRequestError77(
@@ -15769,7 +15764,7 @@ function useJobProfileRepo() {
15769
15764
  repo.delCachedData();
15770
15765
  return "Successfully added job profile education.";
15771
15766
  } catch (error2) {
15772
- if (error2 instanceof AppError36) {
15767
+ if (error2 instanceof AppError37) {
15773
15768
  throw error2;
15774
15769
  }
15775
15770
  throw new BadRequestError77(
@@ -15798,7 +15793,7 @@ function useJobProfileRepo() {
15798
15793
  repo.delCachedData();
15799
15794
  return "Successfully updated job profile education.";
15800
15795
  } catch (error2) {
15801
- if (error2 instanceof AppError36) {
15796
+ if (error2 instanceof AppError37) {
15802
15797
  throw error2;
15803
15798
  }
15804
15799
  throw new BadRequestError77(
@@ -15838,7 +15833,7 @@ function useJobProfileRepo() {
15838
15833
  repo.delCachedData();
15839
15834
  return "Successfully deleted job profile education.";
15840
15835
  } catch (error2) {
15841
- if (error2 instanceof AppError36) {
15836
+ if (error2 instanceof AppError37) {
15842
15837
  throw error2;
15843
15838
  }
15844
15839
  throw new BadRequestError77(
@@ -15868,7 +15863,7 @@ function useJobProfileRepo() {
15868
15863
  repo.delCachedData();
15869
15864
  return "Successfully added job profile skill.";
15870
15865
  } catch (error2) {
15871
- if (error2 instanceof AppError36) {
15866
+ if (error2 instanceof AppError37) {
15872
15867
  throw error2;
15873
15868
  }
15874
15869
  throw new BadRequestError77(
@@ -15897,7 +15892,7 @@ function useJobProfileRepo() {
15897
15892
  repo.delCachedData();
15898
15893
  return "Successfully updated job profile skill.";
15899
15894
  } catch (error2) {
15900
- if (error2 instanceof AppError36) {
15895
+ if (error2 instanceof AppError37) {
15901
15896
  throw error2;
15902
15897
  }
15903
15898
  throw new BadRequestError77(
@@ -15937,7 +15932,7 @@ function useJobProfileRepo() {
15937
15932
  repo.delCachedData();
15938
15933
  return "Successfully deleted job profile skill.";
15939
15934
  } catch (error2) {
15940
- if (error2 instanceof AppError36) {
15935
+ if (error2 instanceof AppError37) {
15941
15936
  throw error2;
15942
15937
  }
15943
15938
  throw new BadRequestError77(
@@ -15966,7 +15961,7 @@ function useJobProfileRepo() {
15966
15961
  repo.delCachedData();
15967
15962
  return "Successfully updated job profile additionalInfo.";
15968
15963
  } catch (error2) {
15969
- if (error2 instanceof AppError36) {
15964
+ if (error2 instanceof AppError37) {
15970
15965
  throw error2;
15971
15966
  }
15972
15967
  throw new BadRequestError77(
@@ -15996,7 +15991,7 @@ function useJobProfileRepo() {
15996
15991
  repo.delCachedData();
15997
15992
  return "Successfully added job profile language.";
15998
15993
  } catch (error2) {
15999
- if (error2 instanceof AppError36) {
15994
+ if (error2 instanceof AppError37) {
16000
15995
  throw error2;
16001
15996
  }
16002
15997
  throw new BadRequestError77(
@@ -16025,7 +16020,7 @@ function useJobProfileRepo() {
16025
16020
  repo.delCachedData();
16026
16021
  return "Successfully updated job profile language.";
16027
16022
  } catch (error2) {
16028
- if (error2 instanceof AppError36) {
16023
+ if (error2 instanceof AppError37) {
16029
16024
  throw error2;
16030
16025
  }
16031
16026
  throw new BadRequestError77(
@@ -16065,7 +16060,7 @@ function useJobProfileRepo() {
16065
16060
  repo.delCachedData();
16066
16061
  return "Successfully deleted job profile language.";
16067
16062
  } catch (error2) {
16068
- if (error2 instanceof AppError36) {
16063
+ if (error2 instanceof AppError37) {
16069
16064
  throw error2;
16070
16065
  }
16071
16066
  throw new BadRequestError77(
@@ -16095,7 +16090,7 @@ function useJobProfileRepo() {
16095
16090
  repo.delCachedData();
16096
16091
  return "Successfully added job profile certification.";
16097
16092
  } catch (error2) {
16098
- if (error2 instanceof AppError36) {
16093
+ if (error2 instanceof AppError37) {
16099
16094
  throw error2;
16100
16095
  }
16101
16096
  throw new BadRequestError77(
@@ -16124,7 +16119,7 @@ function useJobProfileRepo() {
16124
16119
  repo.delCachedData();
16125
16120
  return "Successfully updated job profile certification.";
16126
16121
  } catch (error2) {
16127
- if (error2 instanceof AppError36) {
16122
+ if (error2 instanceof AppError37) {
16128
16123
  throw error2;
16129
16124
  }
16130
16125
  throw new BadRequestError77(
@@ -16164,7 +16159,7 @@ function useJobProfileRepo() {
16164
16159
  repo.delCachedData();
16165
16160
  return "Successfully deleted job profile certification.";
16166
16161
  } catch (error2) {
16167
- if (error2 instanceof AppError36) {
16162
+ if (error2 instanceof AppError37) {
16168
16163
  throw error2;
16169
16164
  }
16170
16165
  throw new BadRequestError77(
@@ -16201,14 +16196,14 @@ function useJobProfileRepo() {
16201
16196
  }
16202
16197
 
16203
16198
  // src/resources/job-profile/job.profile.controller.ts
16204
- import { AppError as AppError38, BadRequestError as BadRequestError79, NotFoundError as NotFoundError5 } from "@goweekdays/utils";
16199
+ import { AppError as AppError39, BadRequestError as BadRequestError79, NotFoundError as NotFoundError5 } from "@goweekdays/utils";
16205
16200
  import Joi69 from "joi";
16206
16201
 
16207
16202
  // src/resources/job-profile/job.profile.service.ts
16208
16203
  import {
16209
- AppError as AppError37,
16204
+ AppError as AppError38,
16210
16205
  BadRequestError as BadRequestError78,
16211
- InternalServerError as InternalServerError36,
16206
+ InternalServerError as InternalServerError37,
16212
16207
  useAtlas as useAtlas12
16213
16208
  } from "@goweekdays/utils";
16214
16209
  import Joi68 from "joi";
@@ -16231,7 +16226,7 @@ function useJobPostProfileSvc() {
16231
16226
  }
16232
16227
  const session = useAtlas12.getClient()?.startSession();
16233
16228
  if (!session) {
16234
- throw new InternalServerError36("Failed to start database session.");
16229
+ throw new InternalServerError37("Failed to start database session.");
16235
16230
  }
16236
16231
  try {
16237
16232
  session.startTransaction();
@@ -16252,10 +16247,10 @@ function useJobPostProfileSvc() {
16252
16247
  return "Successfully updated contact info.";
16253
16248
  } catch (error2) {
16254
16249
  await session.abortTransaction();
16255
- if (error2 instanceof AppError37) {
16250
+ if (error2 instanceof AppError38) {
16256
16251
  throw error2;
16257
16252
  }
16258
- throw new InternalServerError36("Failed to update contact info.");
16253
+ throw new InternalServerError37("Failed to update contact info.");
16259
16254
  } finally {
16260
16255
  await session.endSession();
16261
16256
  }
@@ -16270,7 +16265,7 @@ function useJobPostProfileSvc() {
16270
16265
  }
16271
16266
  const session = useAtlas12.getClient()?.startSession();
16272
16267
  if (!session) {
16273
- throw new InternalServerError36("Failed to start database session.");
16268
+ throw new InternalServerError37("Failed to start database session.");
16274
16269
  }
16275
16270
  try {
16276
16271
  session.startTransaction();
@@ -16285,10 +16280,10 @@ function useJobPostProfileSvc() {
16285
16280
  return "Successfully updated personal info.";
16286
16281
  } catch (error2) {
16287
16282
  await session.abortTransaction();
16288
- if (error2 instanceof AppError37) {
16283
+ if (error2 instanceof AppError38) {
16289
16284
  throw error2;
16290
16285
  }
16291
- throw new InternalServerError36("Failed to update personal info.");
16286
+ throw new InternalServerError37("Failed to update personal info.");
16292
16287
  } finally {
16293
16288
  await session.endSession();
16294
16289
  }
@@ -16300,7 +16295,7 @@ function useJobPostProfileSvc() {
16300
16295
  }
16301
16296
  const session = useAtlas12.getClient()?.startSession();
16302
16297
  if (!session) {
16303
- throw new InternalServerError36("Failed to start database session.");
16298
+ throw new InternalServerError37("Failed to start database session.");
16304
16299
  }
16305
16300
  try {
16306
16301
  session.startTransaction();
@@ -16323,10 +16318,10 @@ function useJobPostProfileSvc() {
16323
16318
  return "Successfully added work experience.";
16324
16319
  } catch (error2) {
16325
16320
  await session.abortTransaction();
16326
- if (error2 instanceof AppError37) {
16321
+ if (error2 instanceof AppError38) {
16327
16322
  throw error2;
16328
16323
  }
16329
- throw new InternalServerError36("Failed to add work experience.");
16324
+ throw new InternalServerError37("Failed to add work experience.");
16330
16325
  } finally {
16331
16326
  await session.endSession();
16332
16327
  }
@@ -16338,7 +16333,7 @@ function useJobPostProfileSvc() {
16338
16333
  }
16339
16334
  const session = useAtlas12.getClient()?.startSession();
16340
16335
  if (!session) {
16341
- throw new InternalServerError36("Failed to start database session.");
16336
+ throw new InternalServerError37("Failed to start database session.");
16342
16337
  }
16343
16338
  try {
16344
16339
  session.startTransaction();
@@ -16361,10 +16356,10 @@ function useJobPostProfileSvc() {
16361
16356
  return "Successfully updated work experience.";
16362
16357
  } catch (error2) {
16363
16358
  await session.abortTransaction();
16364
- if (error2 instanceof AppError37) {
16359
+ if (error2 instanceof AppError38) {
16365
16360
  throw error2;
16366
16361
  }
16367
- throw new InternalServerError36("Failed to update work experience.");
16362
+ throw new InternalServerError37("Failed to update work experience.");
16368
16363
  } finally {
16369
16364
  await session.endSession();
16370
16365
  }
@@ -16376,7 +16371,7 @@ function useJobPostProfileSvc() {
16376
16371
  }
16377
16372
  const session = useAtlas12.getClient()?.startSession();
16378
16373
  if (!session) {
16379
- throw new InternalServerError36("Failed to start database session.");
16374
+ throw new InternalServerError37("Failed to start database session.");
16380
16375
  }
16381
16376
  try {
16382
16377
  session.startTransaction();
@@ -16395,10 +16390,10 @@ function useJobPostProfileSvc() {
16395
16390
  return "Successfully added education.";
16396
16391
  } catch (error2) {
16397
16392
  await session.abortTransaction();
16398
- if (error2 instanceof AppError37) {
16393
+ if (error2 instanceof AppError38) {
16399
16394
  throw error2;
16400
16395
  }
16401
- throw new InternalServerError36("Failed to add education.");
16396
+ throw new InternalServerError37("Failed to add education.");
16402
16397
  } finally {
16403
16398
  await session.endSession();
16404
16399
  }
@@ -16410,7 +16405,7 @@ function useJobPostProfileSvc() {
16410
16405
  }
16411
16406
  const session = useAtlas12.getClient()?.startSession();
16412
16407
  if (!session) {
16413
- throw new InternalServerError36("Failed to start database session.");
16408
+ throw new InternalServerError37("Failed to start database session.");
16414
16409
  }
16415
16410
  try {
16416
16411
  session.startTransaction();
@@ -16429,10 +16424,10 @@ function useJobPostProfileSvc() {
16429
16424
  return "Successfully updated education.";
16430
16425
  } catch (error2) {
16431
16426
  await session.abortTransaction();
16432
- if (error2 instanceof AppError37) {
16427
+ if (error2 instanceof AppError38) {
16433
16428
  throw error2;
16434
16429
  }
16435
- throw new InternalServerError36("Failed to update education.");
16430
+ throw new InternalServerError37("Failed to update education.");
16436
16431
  } finally {
16437
16432
  await session.endSession();
16438
16433
  }
@@ -16488,7 +16483,7 @@ function useJobProfileCtrl() {
16488
16483
  res.json({ message });
16489
16484
  return;
16490
16485
  } catch (error2) {
16491
- if (error2 instanceof AppError38) {
16486
+ if (error2 instanceof AppError39) {
16492
16487
  next(error2);
16493
16488
  return;
16494
16489
  }
@@ -16518,7 +16513,7 @@ function useJobProfileCtrl() {
16518
16513
  res.json(data);
16519
16514
  return;
16520
16515
  } catch (error2) {
16521
- if (error2 instanceof AppError38) {
16516
+ if (error2 instanceof AppError39) {
16522
16517
  next(error2);
16523
16518
  return;
16524
16519
  }
@@ -16541,7 +16536,7 @@ function useJobProfileCtrl() {
16541
16536
  res.json(data);
16542
16537
  return;
16543
16538
  } catch (error2) {
16544
- if (error2 instanceof AppError38) {
16539
+ if (error2 instanceof AppError39) {
16545
16540
  next(error2);
16546
16541
  return;
16547
16542
  }
@@ -16563,7 +16558,7 @@ function useJobProfileCtrl() {
16563
16558
  res.json({ message });
16564
16559
  return;
16565
16560
  } catch (error2) {
16566
- if (error2 instanceof AppError38) {
16561
+ if (error2 instanceof AppError39) {
16567
16562
  next(error2);
16568
16563
  return;
16569
16564
  }
@@ -16587,7 +16582,7 @@ function useJobProfileCtrl() {
16587
16582
  res.json({ message });
16588
16583
  return;
16589
16584
  } catch (error2) {
16590
- if (error2 instanceof AppError38) {
16585
+ if (error2 instanceof AppError39) {
16591
16586
  next(error2);
16592
16587
  return;
16593
16588
  }
@@ -16611,7 +16606,7 @@ function useJobProfileCtrl() {
16611
16606
  res.json({ message });
16612
16607
  return;
16613
16608
  } catch (error2) {
16614
- if (error2 instanceof AppError38) {
16609
+ if (error2 instanceof AppError39) {
16615
16610
  next(error2);
16616
16611
  return;
16617
16612
  }
@@ -16637,7 +16632,7 @@ function useJobProfileCtrl() {
16637
16632
  res.json({ message });
16638
16633
  return;
16639
16634
  } catch (error2) {
16640
- if (error2 instanceof AppError38) {
16635
+ if (error2 instanceof AppError39) {
16641
16636
  next(error2);
16642
16637
  return;
16643
16638
  }
@@ -16661,7 +16656,7 @@ function useJobProfileCtrl() {
16661
16656
  res.json({ message });
16662
16657
  return;
16663
16658
  } catch (error2) {
16664
- if (error2 instanceof AppError38) {
16659
+ if (error2 instanceof AppError39) {
16665
16660
  next(error2);
16666
16661
  return;
16667
16662
  }
@@ -16687,7 +16682,7 @@ function useJobProfileCtrl() {
16687
16682
  res.json({ message });
16688
16683
  return;
16689
16684
  } catch (error2) {
16690
- if (error2 instanceof AppError38) {
16685
+ if (error2 instanceof AppError39) {
16691
16686
  next(error2);
16692
16687
  return;
16693
16688
  }
@@ -16711,7 +16706,7 @@ function useJobProfileCtrl() {
16711
16706
  res.json({ message });
16712
16707
  return;
16713
16708
  } catch (error2) {
16714
- if (error2 instanceof AppError38) {
16709
+ if (error2 instanceof AppError39) {
16715
16710
  next(error2);
16716
16711
  return;
16717
16712
  }
@@ -16731,7 +16726,7 @@ function useJobProfileCtrl() {
16731
16726
  res.json({ message });
16732
16727
  return;
16733
16728
  } catch (error2) {
16734
- if (error2 instanceof AppError38) {
16729
+ if (error2 instanceof AppError39) {
16735
16730
  next(error2);
16736
16731
  return;
16737
16732
  }
@@ -16751,7 +16746,7 @@ function useJobProfileCtrl() {
16751
16746
  res.json({ message });
16752
16747
  return;
16753
16748
  } catch (error2) {
16754
- if (error2 instanceof AppError38) {
16749
+ if (error2 instanceof AppError39) {
16755
16750
  next(error2);
16756
16751
  return;
16757
16752
  }
@@ -16771,7 +16766,7 @@ function useJobProfileCtrl() {
16771
16766
  res.json({ message });
16772
16767
  return;
16773
16768
  } catch (error2) {
16774
- if (error2 instanceof AppError38) {
16769
+ if (error2 instanceof AppError39) {
16775
16770
  next(error2);
16776
16771
  return;
16777
16772
  }
@@ -16791,7 +16786,7 @@ function useJobProfileCtrl() {
16791
16786
  res.json({ message });
16792
16787
  return;
16793
16788
  } catch (error2) {
16794
- if (error2 instanceof AppError38) {
16789
+ if (error2 instanceof AppError39) {
16795
16790
  next(error2);
16796
16791
  return;
16797
16792
  }
@@ -16811,7 +16806,7 @@ function useJobProfileCtrl() {
16811
16806
  res.json({ message });
16812
16807
  return;
16813
16808
  } catch (error2) {
16814
- if (error2 instanceof AppError38) {
16809
+ if (error2 instanceof AppError39) {
16815
16810
  next(error2);
16816
16811
  return;
16817
16812
  }
@@ -16834,7 +16829,7 @@ function useJobProfileCtrl() {
16834
16829
  res.json({ message });
16835
16830
  return;
16836
16831
  } catch (error2) {
16837
- if (error2 instanceof AppError38) {
16832
+ if (error2 instanceof AppError39) {
16838
16833
  next(error2);
16839
16834
  return;
16840
16835
  }
@@ -16858,7 +16853,7 @@ function useJobProfileCtrl() {
16858
16853
  res.json({ message });
16859
16854
  return;
16860
16855
  } catch (error2) {
16861
- if (error2 instanceof AppError38) {
16856
+ if (error2 instanceof AppError39) {
16862
16857
  next(error2);
16863
16858
  return;
16864
16859
  }
@@ -16878,7 +16873,7 @@ function useJobProfileCtrl() {
16878
16873
  res.json({ message });
16879
16874
  return;
16880
16875
  } catch (error2) {
16881
- if (error2 instanceof AppError38) {
16876
+ if (error2 instanceof AppError39) {
16882
16877
  next(error2);
16883
16878
  return;
16884
16879
  }
@@ -16898,7 +16893,7 @@ function useJobProfileCtrl() {
16898
16893
  res.json({ message });
16899
16894
  return;
16900
16895
  } catch (error2) {
16901
- if (error2 instanceof AppError38) {
16896
+ if (error2 instanceof AppError39) {
16902
16897
  next(error2);
16903
16898
  return;
16904
16899
  }
@@ -16918,7 +16913,7 @@ function useJobProfileCtrl() {
16918
16913
  res.json({ message });
16919
16914
  return;
16920
16915
  } catch (error2) {
16921
- if (error2 instanceof AppError38) {
16916
+ if (error2 instanceof AppError39) {
16922
16917
  next(error2);
16923
16918
  return;
16924
16919
  }
@@ -16940,7 +16935,7 @@ function useJobProfileCtrl() {
16940
16935
  res.json({ message });
16941
16936
  return;
16942
16937
  } catch (error2) {
16943
- if (error2 instanceof AppError38) {
16938
+ if (error2 instanceof AppError39) {
16944
16939
  next(error2);
16945
16940
  return;
16946
16941
  }
@@ -16962,7 +16957,7 @@ function useJobProfileCtrl() {
16962
16957
  res.json({ message });
16963
16958
  return;
16964
16959
  } catch (error2) {
16965
- if (error2 instanceof AppError38) {
16960
+ if (error2 instanceof AppError39) {
16966
16961
  next(error2);
16967
16962
  return;
16968
16963
  }
@@ -16999,7 +16994,7 @@ function useJobProfileCtrl() {
16999
16994
 
17000
16995
  // src/resources/job-summary/job.summary.service.ts
17001
16996
  import Joi70 from "joi";
17002
- import { AppError as AppError39, BadRequestError as BadRequestError80 } from "@goweekdays/utils";
16997
+ import { AppError as AppError40, BadRequestError as BadRequestError80 } from "@goweekdays/utils";
17003
16998
  function useJobSummarySvc() {
17004
16999
  const repo = useJobSummaryRepo();
17005
17000
  async function getByOrg(org) {
@@ -17014,7 +17009,7 @@ function useJobSummarySvc() {
17014
17009
  }
17015
17010
  return await repo.getByOrg(org);
17016
17011
  } catch (error2) {
17017
- if (error2 instanceof AppError39) {
17012
+ if (error2 instanceof AppError40) {
17018
17013
  throw error2;
17019
17014
  }
17020
17015
  throw new BadRequestError80("Failed to get job summary by org.");
@@ -17449,7 +17444,7 @@ function useBusinessProfileRepo() {
17449
17444
  }
17450
17445
 
17451
17446
  // src/resources/finance-profile/finance.profile.controller.ts
17452
- import { AppError as AppError40, BadRequestError as BadRequestError84 } from "@goweekdays/utils";
17447
+ import { AppError as AppError41, BadRequestError as BadRequestError84 } from "@goweekdays/utils";
17453
17448
  function useBusinessProfileCtrl() {
17454
17449
  const repo = useBusinessProfileRepo();
17455
17450
  async function add(req, res, next) {
@@ -17469,7 +17464,7 @@ function useBusinessProfileCtrl() {
17469
17464
  res.json({ message: "Business profile created successfully" });
17470
17465
  return;
17471
17466
  } catch (error2) {
17472
- if (error2 instanceof AppError40) {
17467
+ if (error2 instanceof AppError41) {
17473
17468
  next(error2);
17474
17469
  return;
17475
17470
  }
@@ -17703,13 +17698,13 @@ function modelTax(data) {
17703
17698
 
17704
17699
  // src/resources/finance-tax/tax.repository.ts
17705
17700
  import {
17706
- AppError as AppError41,
17701
+ AppError as AppError42,
17707
17702
  BadRequestError as BadRequestError86,
17708
17703
  useRepo as useRepo27,
17709
17704
  makeCacheKey as makeCacheKey26,
17710
17705
  paginate as paginate22,
17711
17706
  logger as logger43,
17712
- InternalServerError as InternalServerError37
17707
+ InternalServerError as InternalServerError38
17713
17708
  } from "@goweekdays/utils";
17714
17709
  import { ObjectId as ObjectId45 } from "mongodb";
17715
17710
  import Joi75 from "joi";
@@ -17873,7 +17868,7 @@ function useTaxRepo() {
17873
17868
  });
17874
17869
  return data;
17875
17870
  } catch (error) {
17876
- throw new InternalServerError37(
17871
+ throw new InternalServerError38(
17877
17872
  "Internal server error, failed to retrieve taxes."
17878
17873
  );
17879
17874
  }
@@ -17911,10 +17906,10 @@ function useTaxRepo() {
17911
17906
  });
17912
17907
  return result;
17913
17908
  } catch (error) {
17914
- if (error instanceof AppError41) {
17909
+ if (error instanceof AppError42) {
17915
17910
  throw error;
17916
17911
  } else {
17917
- throw new InternalServerError37("Failed to get tax.");
17912
+ throw new InternalServerError38("Failed to get tax.");
17918
17913
  }
17919
17914
  }
17920
17915
  }
@@ -17940,7 +17935,7 @@ function useTaxRepo() {
17940
17935
  repo.delCachedData();
17941
17936
  return "Successfully updated tax.";
17942
17937
  } catch (error2) {
17943
- throw new InternalServerError37("Failed to update tax.");
17938
+ throw new InternalServerError38("Failed to update tax.");
17944
17939
  }
17945
17940
  }
17946
17941
  async function deleteById(_id, session) {
@@ -17964,7 +17959,7 @@ function useTaxRepo() {
17964
17959
  repo.delCachedData();
17965
17960
  return "Successfully deleted tax.";
17966
17961
  } catch (error) {
17967
- throw new InternalServerError37("Failed to delete tax.");
17962
+ throw new InternalServerError38("Failed to delete tax.");
17968
17963
  }
17969
17964
  }
17970
17965
  async function updateStatusById(_id, status2) {
@@ -17989,10 +17984,10 @@ function useTaxRepo() {
17989
17984
  repo.delCachedData();
17990
17985
  return "Successfully updated tax status.";
17991
17986
  } catch (error) {
17992
- if (error instanceof AppError41) {
17987
+ if (error instanceof AppError42) {
17993
17988
  throw error;
17994
17989
  }
17995
- throw new InternalServerError37("Failed to update tax status.");
17990
+ throw new InternalServerError38("Failed to update tax status.");
17996
17991
  }
17997
17992
  }
17998
17993
  return {
@@ -18287,13 +18282,13 @@ function modelChartOfAccount(data) {
18287
18282
 
18288
18283
  // src/resources/finance-account/chart-of-account.repository.ts
18289
18284
  import {
18290
- AppError as AppError42,
18285
+ AppError as AppError43,
18291
18286
  BadRequestError as BadRequestError88,
18292
18287
  useRepo as useRepo28,
18293
18288
  makeCacheKey as makeCacheKey27,
18294
18289
  paginate as paginate23,
18295
18290
  logger as logger45,
18296
- InternalServerError as InternalServerError38
18291
+ InternalServerError as InternalServerError39
18297
18292
  } from "@goweekdays/utils";
18298
18293
  import { ObjectId as ObjectId47 } from "mongodb";
18299
18294
  import Joi78 from "joi";
@@ -18505,7 +18500,7 @@ function useChartOfAccountRepo() {
18505
18500
  });
18506
18501
  return data;
18507
18502
  } catch (error) {
18508
- throw new InternalServerError38(
18503
+ throw new InternalServerError39(
18509
18504
  "Internal server error, failed to retrieve chart of accounts."
18510
18505
  );
18511
18506
  }
@@ -18543,10 +18538,10 @@ function useChartOfAccountRepo() {
18543
18538
  });
18544
18539
  return result;
18545
18540
  } catch (error) {
18546
- if (error instanceof AppError42) {
18541
+ if (error instanceof AppError43) {
18547
18542
  throw error;
18548
18543
  } else {
18549
- throw new InternalServerError38("Failed to get chart of account.");
18544
+ throw new InternalServerError39("Failed to get chart of account.");
18550
18545
  }
18551
18546
  }
18552
18547
  }
@@ -18571,7 +18566,7 @@ function useChartOfAccountRepo() {
18571
18566
  repo.delCachedData();
18572
18567
  return "Successfully updated chart of account.";
18573
18568
  } catch (error2) {
18574
- throw new InternalServerError38("Failed to update chart of account.");
18569
+ throw new InternalServerError39("Failed to update chart of account.");
18575
18570
  }
18576
18571
  }
18577
18572
  async function deleteById(_id, session) {
@@ -18595,7 +18590,7 @@ function useChartOfAccountRepo() {
18595
18590
  repo.delCachedData();
18596
18591
  return "Successfully archived chart of account.";
18597
18592
  } catch (error) {
18598
- throw new InternalServerError38("Failed to archive chart of account.");
18593
+ throw new InternalServerError39("Failed to archive chart of account.");
18599
18594
  }
18600
18595
  }
18601
18596
  async function updateStatusById(_id, status2) {
@@ -18620,10 +18615,10 @@ function useChartOfAccountRepo() {
18620
18615
  repo.delCachedData();
18621
18616
  return "Successfully updated chart of account status.";
18622
18617
  } catch (error) {
18623
- if (error instanceof AppError42) {
18618
+ if (error instanceof AppError43) {
18624
18619
  throw error;
18625
18620
  }
18626
- throw new InternalServerError38(
18621
+ throw new InternalServerError39(
18627
18622
  "Failed to update chart of account status."
18628
18623
  );
18629
18624
  }
@@ -18639,7 +18634,7 @@ function useChartOfAccountRepo() {
18639
18634
  });
18640
18635
  return count;
18641
18636
  } catch (error2) {
18642
- throw new InternalServerError38(
18637
+ throw new InternalServerError39(
18643
18638
  "Failed to count chart of accounts by path."
18644
18639
  );
18645
18640
  }
@@ -18667,7 +18662,7 @@ function useChartOfAccountRepo() {
18667
18662
  repo.delCachedData();
18668
18663
  return "Successfully updated children count.";
18669
18664
  } catch (error2) {
18670
- throw new InternalServerError38("Failed to update children count.");
18665
+ throw new InternalServerError39("Failed to update children count.");
18671
18666
  }
18672
18667
  }
18673
18668
  async function getTrialBalance(options) {
@@ -18794,7 +18789,7 @@ function useChartOfAccountRepo() {
18794
18789
  level: "error",
18795
18790
  message: `Error in getTrialBalance: ${error}`
18796
18791
  });
18797
- throw new InternalServerError38("Failed to get trial balance.");
18792
+ throw new InternalServerError39("Failed to get trial balance.");
18798
18793
  }
18799
18794
  }
18800
18795
  async function getBalanceSheet(options) {
@@ -18903,7 +18898,7 @@ function useChartOfAccountRepo() {
18903
18898
  level: "error",
18904
18899
  message: `Error in getBalanceSheet: ${error}`
18905
18900
  });
18906
- throw new InternalServerError38("Failed to get balance sheet data.");
18901
+ throw new InternalServerError39("Failed to get balance sheet data.");
18907
18902
  }
18908
18903
  }
18909
18904
  return {
@@ -19514,9 +19509,9 @@ function modelAccountBalance(value) {
19514
19509
 
19515
19510
  // src/resources/finance-account-balance/finance.account.balance.repository.ts
19516
19511
  import {
19517
- AppError as AppError43,
19512
+ AppError as AppError44,
19518
19513
  BadRequestError as BadRequestError92,
19519
- InternalServerError as InternalServerError39,
19514
+ InternalServerError as InternalServerError40,
19520
19515
  makeCacheKey as makeCacheKey28,
19521
19516
  paginate as paginate24,
19522
19517
  logger as logger47,
@@ -19563,11 +19558,11 @@ function useAccountBalanceRepo() {
19563
19558
  repo.delCachedData();
19564
19559
  return res.insertedId;
19565
19560
  } catch (error) {
19566
- if (error instanceof AppError43) {
19561
+ if (error instanceof AppError44) {
19567
19562
  throw error;
19568
19563
  }
19569
19564
  logger47.log({ level: "error", message: error.message });
19570
- throw new InternalServerError39("Failed to add account balance.");
19565
+ throw new InternalServerError40("Failed to add account balance.");
19571
19566
  }
19572
19567
  }
19573
19568
  async function getAll(options) {
@@ -19627,10 +19622,10 @@ function useAccountBalanceRepo() {
19627
19622
  });
19628
19623
  return data;
19629
19624
  } catch (error) {
19630
- if (error instanceof AppError43) {
19625
+ if (error instanceof AppError44) {
19631
19626
  throw error;
19632
19627
  }
19633
- throw new InternalServerError39("Failed to get account balances.");
19628
+ throw new InternalServerError40("Failed to get account balances.");
19634
19629
  }
19635
19630
  }
19636
19631
  async function getById(_id) {
@@ -19663,10 +19658,10 @@ function useAccountBalanceRepo() {
19663
19658
  });
19664
19659
  return result;
19665
19660
  } catch (error) {
19666
- if (error instanceof AppError43) {
19661
+ if (error instanceof AppError44) {
19667
19662
  throw error;
19668
19663
  }
19669
- throw new InternalServerError39("Failed to get account balance.");
19664
+ throw new InternalServerError40("Failed to get account balance.");
19670
19665
  }
19671
19666
  }
19672
19667
  async function getByAccount(options) {
@@ -19719,10 +19714,10 @@ function useAccountBalanceRepo() {
19719
19714
  }
19720
19715
  return result;
19721
19716
  } catch (error) {
19722
- if (error instanceof AppError43) {
19717
+ if (error instanceof AppError44) {
19723
19718
  throw error;
19724
19719
  }
19725
- throw new InternalServerError39("Failed to get account balance.");
19720
+ throw new InternalServerError40("Failed to get account balance.");
19726
19721
  }
19727
19722
  }
19728
19723
  async function getYearBalancesByAccount(options) {
@@ -19744,10 +19739,10 @@ function useAccountBalanceRepo() {
19744
19739
  { sort: { "period.fiscalMonth": 1 } }
19745
19740
  ).toArray();
19746
19741
  } catch (error) {
19747
- if (error instanceof AppError43) {
19742
+ if (error instanceof AppError44) {
19748
19743
  throw error;
19749
19744
  }
19750
- throw new InternalServerError39("Failed to get account balances by year.");
19745
+ throw new InternalServerError40("Failed to get account balances by year.");
19751
19746
  }
19752
19747
  }
19753
19748
  async function updateById(account, org, fiscalYear, fiscalMonth, options, session) {
@@ -19789,7 +19784,7 @@ function useAccountBalanceRepo() {
19789
19784
  repo.delCachedData();
19790
19785
  return "Successfully updated account balance.";
19791
19786
  } catch (error2) {
19792
- throw new InternalServerError39("Failed to update account balance.");
19787
+ throw new InternalServerError40("Failed to update account balance.");
19793
19788
  }
19794
19789
  }
19795
19790
  async function deleteById(_id, session) {
@@ -19803,7 +19798,7 @@ function useAccountBalanceRepo() {
19803
19798
  repo.delCachedData();
19804
19799
  return "Successfully deleted account balance.";
19805
19800
  } catch (error) {
19806
- throw new InternalServerError39("Failed to delete account balance.");
19801
+ throw new InternalServerError40("Failed to delete account balance.");
19807
19802
  }
19808
19803
  }
19809
19804
  return {
@@ -19961,12 +19956,12 @@ function modelJournal(data) {
19961
19956
 
19962
19957
  // src/resources/finance-journal/finance.journal.repository.ts
19963
19958
  import {
19964
- AppError as AppError44,
19959
+ AppError as AppError45,
19965
19960
  BadRequestError as BadRequestError94,
19966
19961
  makeCacheKey as makeCacheKey29,
19967
19962
  paginate as paginate25,
19968
19963
  logger as logger48,
19969
- InternalServerError as InternalServerError40,
19964
+ InternalServerError as InternalServerError41,
19970
19965
  useRepo as useRepo30
19971
19966
  } from "@goweekdays/utils";
19972
19967
  import { ObjectId as ObjectId51 } from "mongodb";
@@ -20130,10 +20125,10 @@ function useJournalRepo() {
20130
20125
  });
20131
20126
  return result;
20132
20127
  } catch (error) {
20133
- if (error instanceof AppError44) {
20128
+ if (error instanceof AppError45) {
20134
20129
  throw error;
20135
20130
  } else {
20136
- throw new InternalServerError40("Failed to get journal.");
20131
+ throw new InternalServerError41("Failed to get journal.");
20137
20132
  }
20138
20133
  }
20139
20134
  }
@@ -20187,7 +20182,7 @@ function useJournalRepo() {
20187
20182
  repo.delCachedData();
20188
20183
  return "Successfully updated journal entry.";
20189
20184
  } catch (error2) {
20190
- throw new InternalServerError40("Failed to update journal.");
20185
+ throw new InternalServerError41("Failed to update journal.");
20191
20186
  }
20192
20187
  }
20193
20188
  async function deleteById(_id, session) {
@@ -20210,7 +20205,7 @@ function useJournalRepo() {
20210
20205
  repo.delCachedData();
20211
20206
  return "Successfully voided journal.";
20212
20207
  } catch (error) {
20213
- throw new InternalServerError40("Failed to void journal.");
20208
+ throw new InternalServerError41("Failed to void journal.");
20214
20209
  }
20215
20210
  }
20216
20211
  async function updateStatusById(_id, status2, session) {
@@ -20239,10 +20234,10 @@ function useJournalRepo() {
20239
20234
  repo.delCachedData();
20240
20235
  return "Successfully updated journal status.";
20241
20236
  } catch (error) {
20242
- if (error instanceof AppError44) {
20237
+ if (error instanceof AppError45) {
20243
20238
  throw error;
20244
20239
  }
20245
- throw new InternalServerError40("Failed to update journal status.");
20240
+ throw new InternalServerError41("Failed to update journal status.");
20246
20241
  }
20247
20242
  }
20248
20243
  async function existsByTransactionId(org, transactionId) {
@@ -20354,14 +20349,14 @@ function modelJournalLine(data) {
20354
20349
 
20355
20350
  // src/resources/finance-journal-line/finance.journal.line.repository.ts
20356
20351
  import {
20357
- AppError as AppError45,
20352
+ AppError as AppError46,
20358
20353
  BadRequestError as BadRequestError96,
20359
20354
  useAtlas as useAtlas14,
20360
20355
  useCache as useCache3,
20361
20356
  makeCacheKey as makeCacheKey30,
20362
20357
  paginate as paginate26,
20363
20358
  logger as logger49,
20364
- InternalServerError as InternalServerError41
20359
+ InternalServerError as InternalServerError42
20365
20360
  } from "@goweekdays/utils";
20366
20361
  import { ObjectId as ObjectId53 } from "mongodb";
20367
20362
  import Joi86 from "joi";
@@ -20529,10 +20524,10 @@ function useJournalLineRepo() {
20529
20524
  });
20530
20525
  return result;
20531
20526
  } catch (error) {
20532
- if (error instanceof AppError45) {
20527
+ if (error instanceof AppError46) {
20533
20528
  throw error;
20534
20529
  } else {
20535
- throw new InternalServerError41("Failed to get journal line.");
20530
+ throw new InternalServerError42("Failed to get journal line.");
20536
20531
  }
20537
20532
  }
20538
20533
  }
@@ -20568,10 +20563,10 @@ function useJournalLineRepo() {
20568
20563
  });
20569
20564
  return result;
20570
20565
  } catch (error) {
20571
- if (error instanceof AppError45) {
20566
+ if (error instanceof AppError46) {
20572
20567
  throw error;
20573
20568
  } else {
20574
- throw new InternalServerError41("Failed to get journal line.");
20569
+ throw new InternalServerError42("Failed to get journal line.");
20575
20570
  }
20576
20571
  }
20577
20572
  }
@@ -20600,7 +20595,7 @@ function useJournalLineRepo() {
20600
20595
  delCachedData();
20601
20596
  return "Successfully updated journal line.";
20602
20597
  } catch (error2) {
20603
- throw new InternalServerError41("Failed to update journal line.");
20598
+ throw new InternalServerError42("Failed to update journal line.");
20604
20599
  }
20605
20600
  }
20606
20601
  async function deleteById(_id, session) {
@@ -20614,7 +20609,7 @@ function useJournalLineRepo() {
20614
20609
  delCachedData();
20615
20610
  return "Successfully deleted journal line.";
20616
20611
  } catch (error) {
20617
- throw new InternalServerError41("Failed to delete journal line.");
20612
+ throw new InternalServerError42("Failed to delete journal line.");
20618
20613
  }
20619
20614
  }
20620
20615
  async function updateBalanceById(_id, balance, session) {
@@ -20631,7 +20626,7 @@ function useJournalLineRepo() {
20631
20626
  );
20632
20627
  delCachedData();
20633
20628
  } catch (error) {
20634
- throw new InternalServerError41("Failed to update journal line balance.");
20629
+ throw new InternalServerError42("Failed to update journal line balance.");
20635
20630
  }
20636
20631
  }
20637
20632
  async function updateStatusByJournal(journalEntry, status2, session) {
@@ -20664,7 +20659,7 @@ function useJournalLineRepo() {
20664
20659
  delCachedData();
20665
20660
  return `Successfully updated journal line statuses to ${status2}.`;
20666
20661
  } catch (error2) {
20667
- throw new InternalServerError41("Failed to update journal line statuses.");
20662
+ throw new InternalServerError42("Failed to update journal line statuses.");
20668
20663
  }
20669
20664
  }
20670
20665
  return {
@@ -20682,9 +20677,9 @@ function useJournalLineRepo() {
20682
20677
 
20683
20678
  // src/resources/finance-journal/finance.journal.service.ts
20684
20679
  import {
20685
- AppError as AppError49,
20680
+ AppError as AppError50,
20686
20681
  BadRequestError as BadRequestError105,
20687
- InternalServerError as InternalServerError45,
20682
+ InternalServerError as InternalServerError46,
20688
20683
  NotFoundError as NotFoundError7,
20689
20684
  useAtlas as useAtlas16
20690
20685
  } from "@goweekdays/utils";
@@ -20901,14 +20896,14 @@ function modelJournalLog(value) {
20901
20896
 
20902
20897
  // src/resources/finance-journal-log/finance.journal.log.repository.ts
20903
20898
  import {
20904
- AppError as AppError46,
20899
+ AppError as AppError47,
20905
20900
  BadRequestError as BadRequestError99,
20906
20901
  useAtlas as useAtlas15,
20907
20902
  useCache as useCache4,
20908
20903
  makeCacheKey as makeCacheKey31,
20909
20904
  paginate as paginate27,
20910
20905
  logger as logger50,
20911
- InternalServerError as InternalServerError42
20906
+ InternalServerError as InternalServerError43
20912
20907
  } from "@goweekdays/utils";
20913
20908
  import { ObjectId as ObjectId55 } from "mongodb";
20914
20909
  import Joi88 from "joi";
@@ -21085,10 +21080,10 @@ function useJournalLogRepo() {
21085
21080
  });
21086
21081
  return result;
21087
21082
  } catch (error) {
21088
- if (error instanceof AppError46) {
21083
+ if (error instanceof AppError47) {
21089
21084
  throw error;
21090
21085
  } else {
21091
- throw new InternalServerError42("Failed to get journal log.");
21086
+ throw new InternalServerError43("Failed to get journal log.");
21092
21087
  }
21093
21088
  }
21094
21089
  }
@@ -21198,12 +21193,12 @@ function modelJournalTransaction(data) {
21198
21193
 
21199
21194
  // src/resources/finance-journal-transaction/finance.journal.transaction.repository.ts
21200
21195
  import {
21201
- AppError as AppError47,
21196
+ AppError as AppError48,
21202
21197
  BadRequestError as BadRequestError102,
21203
21198
  makeCacheKey as makeCacheKey32,
21204
21199
  paginate as paginate28,
21205
21200
  logger as logger52,
21206
- InternalServerError as InternalServerError43,
21201
+ InternalServerError as InternalServerError44,
21207
21202
  useRepo as useRepo31
21208
21203
  } from "@goweekdays/utils";
21209
21204
  import { ObjectId as ObjectId57 } from "mongodb";
@@ -21358,10 +21353,10 @@ function useJournalTransactionRepo() {
21358
21353
  });
21359
21354
  return result;
21360
21355
  } catch (error) {
21361
- if (error instanceof AppError47) {
21356
+ if (error instanceof AppError48) {
21362
21357
  throw error;
21363
21358
  } else {
21364
- throw new InternalServerError43("Failed to get journal transaction.");
21359
+ throw new InternalServerError44("Failed to get journal transaction.");
21365
21360
  }
21366
21361
  }
21367
21362
  }
@@ -21404,7 +21399,7 @@ function useJournalTransactionRepo() {
21404
21399
  repo.delCachedData();
21405
21400
  return "Successfully updated journal transaction.";
21406
21401
  } catch (error2) {
21407
- throw new InternalServerError43("Failed to update journal transaction.");
21402
+ throw new InternalServerError44("Failed to update journal transaction.");
21408
21403
  }
21409
21404
  }
21410
21405
  async function deleteById(_id, session) {
@@ -21418,7 +21413,7 @@ function useJournalTransactionRepo() {
21418
21413
  repo.delCachedData();
21419
21414
  return "Successfully deleted journal transaction.";
21420
21415
  } catch (error) {
21421
- throw new InternalServerError43("Failed to delete journal transaction.");
21416
+ throw new InternalServerError44("Failed to delete journal transaction.");
21422
21417
  }
21423
21418
  }
21424
21419
  return {
@@ -21433,9 +21428,9 @@ function useJournalTransactionRepo() {
21433
21428
 
21434
21429
  // src/resources/finance-journal-transaction/finance.journal.transaction.service.ts
21435
21430
  import {
21436
- AppError as AppError48,
21431
+ AppError as AppError49,
21437
21432
  BadRequestError as BadRequestError103,
21438
- InternalServerError as InternalServerError44,
21433
+ InternalServerError as InternalServerError45,
21439
21434
  NotFoundError as NotFoundError6
21440
21435
  } from "@goweekdays/utils";
21441
21436
  import Joi91 from "joi";
@@ -21475,10 +21470,10 @@ function useJournalTransactionService() {
21475
21470
  const id = await _add(value);
21476
21471
  return id;
21477
21472
  } catch (error2) {
21478
- if (error2 instanceof AppError48) {
21473
+ if (error2 instanceof AppError49) {
21479
21474
  throw error2;
21480
21475
  }
21481
- throw new InternalServerError44(
21476
+ throw new InternalServerError45(
21482
21477
  `Failed to create journal transaction: ${error2.message}`
21483
21478
  );
21484
21479
  }
@@ -21502,10 +21497,10 @@ function useJournalTransactionService() {
21502
21497
  try {
21503
21498
  return await _updateById(_id, options);
21504
21499
  } catch (error2) {
21505
- if (error2 instanceof AppError48) {
21500
+ if (error2 instanceof AppError49) {
21506
21501
  throw error2;
21507
21502
  }
21508
- throw new InternalServerError44(
21503
+ throw new InternalServerError45(
21509
21504
  `Failed to update journal transaction: ${error2.message}`
21510
21505
  );
21511
21506
  }
@@ -21755,10 +21750,10 @@ function useJournalService() {
21755
21750
  return "Journal entry created successfully.";
21756
21751
  } catch (error2) {
21757
21752
  await session.abortTransaction();
21758
- if (error2 instanceof AppError49) {
21753
+ if (error2 instanceof AppError50) {
21759
21754
  throw error2;
21760
21755
  }
21761
- throw new InternalServerError45(
21756
+ throw new InternalServerError46(
21762
21757
  `Failed to create general journal: ${error2.message}`
21763
21758
  );
21764
21759
  } finally {
@@ -22030,10 +22025,10 @@ function useJournalService() {
22030
22025
  return "Journal entry status updated successfully.";
22031
22026
  } catch (error2) {
22032
22027
  await session.abortTransaction();
22033
- if (error2 instanceof AppError49) {
22028
+ if (error2 instanceof AppError50) {
22034
22029
  throw error2;
22035
22030
  }
22036
- throw new InternalServerError45(
22031
+ throw new InternalServerError46(
22037
22032
  `Failed to update general journal status: ${error2.message}`
22038
22033
  );
22039
22034
  } finally {
@@ -22242,10 +22237,10 @@ function useJournalService() {
22242
22237
  return "Journal entry updated successfully.";
22243
22238
  } catch (error2) {
22244
22239
  await session.abortTransaction();
22245
- if (error2 instanceof AppError49) {
22240
+ if (error2 instanceof AppError50) {
22246
22241
  throw error2;
22247
22242
  }
22248
- throw new InternalServerError45(
22243
+ throw new InternalServerError46(
22249
22244
  `Failed to update general journal: ${error2.message}`
22250
22245
  );
22251
22246
  } finally {
@@ -22506,6 +22501,2560 @@ function useJournalLineController() {
22506
22501
  getById
22507
22502
  };
22508
22503
  }
22504
+
22505
+ // src/resources/asset-item/asset.item.model.ts
22506
+ import { BadRequestError as BadRequestError108 } from "@goweekdays/utils";
22507
+ import Joi96 from "joi";
22508
+ import { ObjectId as ObjectId58 } from "mongodb";
22509
+ var assetItemCategories = [
22510
+ "supply",
22511
+ "tool",
22512
+ "vehicle",
22513
+ "facility",
22514
+ "equipment"
22515
+ ];
22516
+ var assetItemClasses = [
22517
+ "consumable",
22518
+ "semi_expendable",
22519
+ "ppe"
22520
+ ];
22521
+ var assetItemPurposes = ["internal", "for-sale", "for-rent"];
22522
+ var assetItemTrackingTypes = ["quantity", "individual"];
22523
+ var assetItemStatuses = ["active", "archived"];
22524
+ var schemaAssetItemBase = {
22525
+ orgId: Joi96.string().hex().length(24).required(),
22526
+ name: Joi96.string().required(),
22527
+ sku: Joi96.string().optional().allow("", null).default(""),
22528
+ price: Joi96.number().min(0).optional().allow("", null).default(0),
22529
+ unit: Joi96.string().required(),
22530
+ description: Joi96.string().optional().allow("", null),
22531
+ assetCategory: Joi96.string().valid(...assetItemCategories).required(),
22532
+ assetClass: Joi96.string().valid(...assetItemClasses).optional().allow("", null),
22533
+ trackingType: Joi96.string().valid(...assetItemTrackingTypes).required(),
22534
+ purpose: Joi96.string().valid(...assetItemPurposes).required(),
22535
+ itemRefId: Joi96.string().hex().length(24).optional().allow("", null),
22536
+ remarks: Joi96.string().optional().allow("", null),
22537
+ departmentId: Joi96.string().hex().length(24).required(),
22538
+ categoryId: Joi96.string().hex().length(24).optional().allow("", null),
22539
+ subcategoryId: Joi96.string().hex().length(24).optional().allow("", null),
22540
+ categoryPath: Joi96.string().optional().allow("", null),
22541
+ brand: Joi96.string().optional().allow("", null),
22542
+ tags: Joi96.array().items(
22543
+ Joi96.object({
22544
+ id: Joi96.string().required(),
22545
+ name: Joi96.string().required()
22546
+ })
22547
+ ).optional().default([]),
22548
+ quantityOnHand: Joi96.number().min(0).optional().default(0)
22549
+ };
22550
+ var schemaAssetItem = Joi96.object({
22551
+ ...schemaAssetItemBase,
22552
+ departmentName: Joi96.string().required(),
22553
+ categoryName: Joi96.string().optional().allow("", null),
22554
+ subcategoryName: Joi96.string().optional().allow("", null),
22555
+ status: Joi96.string().valid(...assetItemStatuses).optional().allow("", null)
22556
+ });
22557
+ var schemaAssetItemCreate = Joi96.object({
22558
+ ...schemaAssetItemBase,
22559
+ tags: Joi96.array().items(
22560
+ Joi96.object({
22561
+ id: Joi96.string().required(),
22562
+ name: Joi96.string().required()
22563
+ })
22564
+ ).optional().default([])
22565
+ }).custom((value, helpers) => {
22566
+ if (value.subcategoryId && !value.categoryId) {
22567
+ return helpers.error("any.custom", {
22568
+ message: "categoryId is required when subcategoryId is provided."
22569
+ });
22570
+ }
22571
+ return value;
22572
+ }, "subcategory-requires-category");
22573
+ var schemaAssetItemUpdate = Joi96.object({
22574
+ name: Joi96.string().optional(),
22575
+ description: Joi96.string().optional().allow("", null),
22576
+ assetCategory: Joi96.string().valid(...assetItemCategories).optional(),
22577
+ assetClass: Joi96.string().valid(...assetItemClasses).optional(),
22578
+ brand: Joi96.string().optional().allow("", null),
22579
+ sku: Joi96.string().optional().allow("", null),
22580
+ price: Joi96.number().min(0).optional().allow("", null),
22581
+ tags: Joi96.array().items(
22582
+ Joi96.object({
22583
+ id: Joi96.string().required(),
22584
+ name: Joi96.string().required()
22585
+ })
22586
+ ).optional(),
22587
+ quantityOnHand: Joi96.number().min(0).optional()
22588
+ });
22589
+ function modelAssetItem(data) {
22590
+ const { error } = schemaAssetItem.validate(data);
22591
+ if (error) {
22592
+ throw new BadRequestError108(`Invalid asset item data: ${error.message}`);
22593
+ }
22594
+ try {
22595
+ data.orgId = new ObjectId58(data.orgId);
22596
+ } catch (error2) {
22597
+ throw new BadRequestError108("Invalid orgId format.");
22598
+ }
22599
+ try {
22600
+ data.departmentId = new ObjectId58(data.departmentId);
22601
+ } catch (error2) {
22602
+ throw new BadRequestError108("Invalid departmentId format.");
22603
+ }
22604
+ if (data.categoryId) {
22605
+ try {
22606
+ data.categoryId = new ObjectId58(data.categoryId);
22607
+ } catch (error2) {
22608
+ throw new BadRequestError108("Invalid categoryId format.");
22609
+ }
22610
+ }
22611
+ if (data.subcategoryId) {
22612
+ try {
22613
+ data.subcategoryId = new ObjectId58(data.subcategoryId);
22614
+ } catch (error2) {
22615
+ throw new BadRequestError108("Invalid subcategoryId format.");
22616
+ }
22617
+ }
22618
+ if (data.itemRefId) {
22619
+ try {
22620
+ data.itemRefId = new ObjectId58(data.itemRefId);
22621
+ } catch (error2) {
22622
+ throw new BadRequestError108("Invalid itemRefId format.");
22623
+ }
22624
+ }
22625
+ if (data.purpose === "for-sale" && (data.price === void 0 || data.price === null || data.price === 0)) {
22626
+ throw new BadRequestError108(
22627
+ "Price must be greater than 0 for items marked as 'for-sale'."
22628
+ );
22629
+ }
22630
+ return {
22631
+ _id: data._id,
22632
+ orgId: data.orgId,
22633
+ name: data.name,
22634
+ description: data.description ?? "",
22635
+ assetCategory: data.assetCategory,
22636
+ assetClass: data.assetClass,
22637
+ unit: data.unit ?? "",
22638
+ price: data.price ?? 0,
22639
+ sku: data.sku ?? "",
22640
+ brand: data.brand ?? "",
22641
+ trackingType: data.trackingType,
22642
+ purpose: data.purpose,
22643
+ itemRefId: data.itemRefId ?? "",
22644
+ remarks: data.remarks ?? "",
22645
+ departmentId: data.departmentId,
22646
+ departmentName: data.departmentName,
22647
+ categoryId: data.categoryId ?? "",
22648
+ categoryName: data.categoryName ?? "",
22649
+ subcategoryId: data.subcategoryId ?? "",
22650
+ subcategoryName: data.subcategoryName ?? "",
22651
+ categoryPath: data.categoryPath ?? "",
22652
+ tags: data.tags ?? [],
22653
+ quantityOnHand: data.quantityOnHand ?? 0,
22654
+ status: data.status ?? "active",
22655
+ createdAt: data.createdAt ?? /* @__PURE__ */ new Date(),
22656
+ updatedAt: data.updatedAt ?? "",
22657
+ deletedAt: data.deletedAt ?? ""
22658
+ };
22659
+ }
22660
+
22661
+ // src/resources/asset-item/asset.item.repository.ts
22662
+ import {
22663
+ AppError as AppError51,
22664
+ BadRequestError as BadRequestError109,
22665
+ InternalServerError as InternalServerError47,
22666
+ logger as logger54,
22667
+ makeCacheKey as makeCacheKey33,
22668
+ paginate as paginate29,
22669
+ useRepo as useRepo32
22670
+ } from "@goweekdays/utils";
22671
+ import { ObjectId as ObjectId59 } from "mongodb";
22672
+ function useAssetItemRepo() {
22673
+ const namespace_collection = "asset.items";
22674
+ const repo = useRepo32(namespace_collection);
22675
+ async function createIndexes() {
22676
+ try {
22677
+ await repo.collection.createIndexes([
22678
+ { key: { categoryPath: 1 } },
22679
+ { key: { departmentId: 1 } },
22680
+ { key: { categoryId: 1 } },
22681
+ { key: { subcategoryId: 1 } },
22682
+ { key: { brand: 1 } },
22683
+ { key: { "tags.name": 1 } },
22684
+ { key: { assetCategory: 1 } },
22685
+ { key: { purpose: 1 } },
22686
+ { key: { trackingType: 1 } },
22687
+ { key: { status: 1 } },
22688
+ { key: { name: "text" } }
22689
+ ]);
22690
+ } catch (error) {
22691
+ throw new BadRequestError109("Failed to create asset item indexes.");
22692
+ }
22693
+ }
22694
+ async function add(value, session) {
22695
+ try {
22696
+ value = modelAssetItem(value);
22697
+ const res = await repo.collection.insertOne(value, { session });
22698
+ repo.delCachedData();
22699
+ return res.insertedId;
22700
+ } catch (error) {
22701
+ if (error instanceof AppError51) {
22702
+ throw error;
22703
+ }
22704
+ logger54.log({ level: "error", message: error.message });
22705
+ const isDuplicated = error.message.includes("duplicate");
22706
+ if (isDuplicated) {
22707
+ throw new BadRequestError109("Asset item name already exists.");
22708
+ }
22709
+ throw new InternalServerError47("Failed to create asset item.");
22710
+ }
22711
+ }
22712
+ async function getAll({
22713
+ search = "",
22714
+ page = 1,
22715
+ limit = 10,
22716
+ status: status2 = "active",
22717
+ assetCategory = "",
22718
+ trackingType = "",
22719
+ purpose = "",
22720
+ departmentId = "",
22721
+ categoryId = "",
22722
+ subcategoryId = "",
22723
+ brand = "",
22724
+ tags = []
22725
+ } = {}) {
22726
+ page = page > 0 ? page - 1 : 0;
22727
+ const query = { status: status2 };
22728
+ if (search) {
22729
+ query.$text = { $search: search };
22730
+ }
22731
+ if (assetCategory) {
22732
+ query.assetCategory = assetCategory;
22733
+ }
22734
+ if (trackingType) {
22735
+ query.trackingType = trackingType;
22736
+ }
22737
+ if (purpose) {
22738
+ query.purpose = purpose;
22739
+ }
22740
+ if (departmentId) {
22741
+ query.departmentId = departmentId;
22742
+ }
22743
+ if (categoryId) {
22744
+ query.categoryId = categoryId;
22745
+ }
22746
+ if (subcategoryId) {
22747
+ query.subcategoryId = subcategoryId;
22748
+ }
22749
+ if (brand) {
22750
+ query.brand = brand;
22751
+ }
22752
+ if (tags.length > 0) {
22753
+ query["tags.name"] = { $all: tags };
22754
+ }
22755
+ const cacheKey = makeCacheKey33(namespace_collection, {
22756
+ search,
22757
+ page,
22758
+ limit,
22759
+ status: status2,
22760
+ assetCategory,
22761
+ trackingType,
22762
+ purpose,
22763
+ departmentId,
22764
+ categoryId,
22765
+ subcategoryId,
22766
+ brand,
22767
+ tags: tags.join(","),
22768
+ tag: "getAll"
22769
+ });
22770
+ try {
22771
+ const cached = await repo.getCache(cacheKey);
22772
+ if (cached)
22773
+ return cached;
22774
+ const items = await repo.collection.aggregate([
22775
+ { $match: query },
22776
+ { $sort: { _id: -1 } },
22777
+ { $skip: page * limit },
22778
+ { $limit: limit }
22779
+ ]).toArray();
22780
+ const length = await repo.collection.countDocuments(query);
22781
+ const data = paginate29(items, page, limit, length);
22782
+ repo.setCache(cacheKey, data, 600);
22783
+ return data;
22784
+ } catch (error) {
22785
+ logger54.log({ level: "error", message: `${error}` });
22786
+ throw error;
22787
+ }
22788
+ }
22789
+ async function getById(id) {
22790
+ const cacheKey = makeCacheKey33(namespace_collection, {
22791
+ id,
22792
+ tag: "by-id"
22793
+ });
22794
+ try {
22795
+ const cached = await repo.getCache(cacheKey);
22796
+ if (cached)
22797
+ return cached;
22798
+ const result = await repo.collection.findOne({
22799
+ _id: new ObjectId59(id)
22800
+ });
22801
+ if (!result) {
22802
+ throw new BadRequestError109("Asset item not found.");
22803
+ }
22804
+ repo.setCache(cacheKey, result, 300);
22805
+ return result;
22806
+ } catch (error) {
22807
+ if (error instanceof AppError51)
22808
+ throw error;
22809
+ throw new InternalServerError47("Failed to get asset item.");
22810
+ }
22811
+ }
22812
+ async function updateById(id, value) {
22813
+ try {
22814
+ const result = await repo.collection.findOneAndUpdate(
22815
+ { _id: new ObjectId59(id) },
22816
+ { $set: { ...value, updatedAt: /* @__PURE__ */ new Date() } },
22817
+ { returnDocument: "after" }
22818
+ );
22819
+ if (!result) {
22820
+ throw new BadRequestError109("Asset item not found.");
22821
+ }
22822
+ repo.delCachedData();
22823
+ return result;
22824
+ } catch (error) {
22825
+ if (error instanceof AppError51)
22826
+ throw error;
22827
+ throw new InternalServerError47("Failed to update asset item.");
22828
+ }
22829
+ }
22830
+ async function incrementQuantity(id, amount, session) {
22831
+ try {
22832
+ const result = await repo.collection.findOneAndUpdate(
22833
+ { _id: new ObjectId59(id) },
22834
+ {
22835
+ $inc: { quantityOnHand: amount },
22836
+ $set: { updatedAt: /* @__PURE__ */ new Date() }
22837
+ },
22838
+ { returnDocument: "after", session }
22839
+ );
22840
+ if (!result) {
22841
+ throw new BadRequestError109("Asset item not found.");
22842
+ }
22843
+ repo.delCachedData();
22844
+ return result;
22845
+ } catch (error) {
22846
+ if (error instanceof AppError51)
22847
+ throw error;
22848
+ throw new InternalServerError47("Failed to update asset item quantity.");
22849
+ }
22850
+ }
22851
+ async function deleteById(id) {
22852
+ try {
22853
+ const result = await repo.collection.findOneAndUpdate(
22854
+ { _id: new ObjectId59(id) },
22855
+ { $set: { deletedAt: /* @__PURE__ */ new Date(), status: "archived" } },
22856
+ { returnDocument: "after" }
22857
+ );
22858
+ if (!result) {
22859
+ throw new BadRequestError109("Asset item not found.");
22860
+ }
22861
+ repo.delCachedData();
22862
+ return result;
22863
+ } catch (error) {
22864
+ if (error instanceof AppError51)
22865
+ throw error;
22866
+ throw new InternalServerError47("Failed to delete asset item.");
22867
+ }
22868
+ }
22869
+ return {
22870
+ createIndexes,
22871
+ add,
22872
+ getAll,
22873
+ getById,
22874
+ updateById,
22875
+ incrementQuantity,
22876
+ deleteById
22877
+ };
22878
+ }
22879
+
22880
+ // src/resources/asset-item/asset.item.service.ts
22881
+ import {
22882
+ AppError as AppError54,
22883
+ InternalServerError as InternalServerError50,
22884
+ useAtlas as useAtlas17
22885
+ } from "@goweekdays/utils";
22886
+
22887
+ // src/resources/tag/tag.repository.ts
22888
+ import {
22889
+ AppError as AppError52,
22890
+ BadRequestError as BadRequestError110,
22891
+ useRepo as useRepo33,
22892
+ makeCacheKey as makeCacheKey34,
22893
+ paginate as paginate30,
22894
+ logger as logger55,
22895
+ InternalServerError as InternalServerError48
22896
+ } from "@goweekdays/utils";
22897
+
22898
+ // src/resources/tag/tag.model.ts
22899
+ import Joi97 from "joi";
22900
+ import { ObjectId as ObjectId60 } from "mongodb";
22901
+ var schemaTagFields = {
22902
+ name: Joi97.string().required(),
22903
+ type: Joi97.string().valid("public", "private").required(),
22904
+ orgId: Joi97.string().hex().optional().allow("", null),
22905
+ categoryPath: Joi97.string().optional().allow("", null),
22906
+ status: Joi97.string().valid("active", "pending").optional()
22907
+ };
22908
+ var schemaTagCreate = Joi97.object(schemaTagFields);
22909
+ var schemaTagStd = Joi97.object({
22910
+ ...schemaTagFields,
22911
+ normalizedName: Joi97.string().required(),
22912
+ usageCount: Joi97.number().integer().min(0).optional()
22913
+ });
22914
+ var schemaTagUpdate = Joi97.object({
22915
+ name: Joi97.string().optional(),
22916
+ type: Joi97.string().valid("public", "private").optional(),
22917
+ orgId: Joi97.string().hex().optional().allow("", null),
22918
+ categoryPath: Joi97.string().optional().allow("", null),
22919
+ status: Joi97.string().valid("active", "pending").optional()
22920
+ }).min(1);
22921
+ function modelTag(data) {
22922
+ const { error } = schemaTagStd.validate(data, { allowUnknown: false });
22923
+ if (error) {
22924
+ throw new Error(`Invalid tag data: ${error.message}`);
22925
+ }
22926
+ if (data.orgId) {
22927
+ try {
22928
+ data.orgId = new ObjectId60(data.orgId);
22929
+ } catch (error2) {
22930
+ throw new Error(`Invalid orgId: ${data.orgId}`);
22931
+ }
22932
+ }
22933
+ return {
22934
+ _id: data._id,
22935
+ name: data.name,
22936
+ normalizedName: data.normalizedName,
22937
+ type: data.type,
22938
+ orgId: data.orgId ?? "",
22939
+ categoryPath: data.categoryPath ?? "",
22940
+ status: data.status ?? "pending",
22941
+ usageCount: data.usageCount ?? 0,
22942
+ createdAt: data.createdAt ?? /* @__PURE__ */ new Date(),
22943
+ updatedAt: data.updatedAt ?? ""
22944
+ };
22945
+ }
22946
+
22947
+ // src/resources/tag/tag.repository.ts
22948
+ import { ObjectId as ObjectId61 } from "mongodb";
22949
+ import Joi98 from "joi";
22950
+ function useTagRepo() {
22951
+ const namespace_collection = "tags";
22952
+ const repo = useRepo33(namespace_collection);
22953
+ async function createIndexes() {
22954
+ try {
22955
+ await repo.collection.createIndexes([
22956
+ { key: { name: 1 } },
22957
+ { key: { normalizedName: 1 } },
22958
+ { key: { type: 1 } },
22959
+ { key: { orgId: 1 } },
22960
+ { key: { status: 1 } },
22961
+ { key: { categoryPath: 1 } },
22962
+ {
22963
+ key: { normalizedName: 1, orgId: 1 },
22964
+ unique: true,
22965
+ name: "unique_normalized_name_per_org"
22966
+ }
22967
+ ]);
22968
+ } catch (error) {
22969
+ throw new Error("Failed to create index on tags.");
22970
+ }
22971
+ }
22972
+ async function add(value, session) {
22973
+ try {
22974
+ value = modelTag(value);
22975
+ const res = await repo.collection.insertOne(value, { session });
22976
+ repo.delCachedData();
22977
+ return res.insertedId;
22978
+ } catch (error) {
22979
+ logger55.log({
22980
+ level: "error",
22981
+ message: error.message
22982
+ });
22983
+ const isDuplicate = /normalizedName|unique/i.test(error.message);
22984
+ if (isDuplicate) {
22985
+ throw new BadRequestError110("A tag with this name already exists.");
22986
+ }
22987
+ throw new BadRequestError110(`Failed to create tag: ${error.message}`);
22988
+ }
22989
+ }
22990
+ async function getAll(options) {
22991
+ const validation = Joi98.object({
22992
+ page: Joi98.number().min(1).optional().allow("", null),
22993
+ limit: Joi98.number().min(1).optional().allow("", null),
22994
+ search: Joi98.string().optional().allow("", null),
22995
+ type: Joi98.string().valid("public", "private").optional().allow("", null),
22996
+ orgId: Joi98.string().hex().optional().allow("", null),
22997
+ status: Joi98.string().valid("active", "pending").optional().allow("", null),
22998
+ categoryPath: Joi98.string().optional().allow("", null)
22999
+ });
23000
+ const { error } = validation.validate(options);
23001
+ if (error) {
23002
+ throw new BadRequestError110(error.message);
23003
+ }
23004
+ options.page = options.page && options.page > 0 ? options.page - 1 : 0;
23005
+ options.limit = options.limit ?? 10;
23006
+ const query = {};
23007
+ const cacheKeyOptions = {
23008
+ limit: options.limit,
23009
+ page: options.page
23010
+ };
23011
+ if (options.search) {
23012
+ query.name = { $regex: options.search, $options: "i" };
23013
+ cacheKeyOptions.search = options.search;
23014
+ }
23015
+ if (options.type) {
23016
+ query.type = options.type;
23017
+ cacheKeyOptions.type = options.type;
23018
+ }
23019
+ if (options.orgId) {
23020
+ query.orgId = new ObjectId61(options.orgId);
23021
+ cacheKeyOptions.orgId = options.orgId;
23022
+ }
23023
+ if (options.status) {
23024
+ query.status = options.status;
23025
+ cacheKeyOptions.status = options.status;
23026
+ }
23027
+ if (options.categoryPath) {
23028
+ query.categoryPath = options.categoryPath;
23029
+ cacheKeyOptions.categoryPath = options.categoryPath;
23030
+ }
23031
+ const cacheKey = makeCacheKey34(namespace_collection, cacheKeyOptions);
23032
+ try {
23033
+ const cached = await repo.getCache(cacheKey);
23034
+ if (cached) {
23035
+ return cached;
23036
+ }
23037
+ const items = await repo.collection.aggregate([
23038
+ { $match: query },
23039
+ { $sort: { name: 1 } },
23040
+ { $skip: options.page * options.limit },
23041
+ { $limit: options.limit },
23042
+ {
23043
+ $project: {
23044
+ _id: 1,
23045
+ name: 1,
23046
+ normalizedName: 1,
23047
+ type: 1,
23048
+ orgId: 1,
23049
+ categoryPath: 1,
23050
+ status: 1,
23051
+ usageCount: 1
23052
+ }
23053
+ }
23054
+ ]).toArray();
23055
+ const length = await repo.collection.countDocuments(query);
23056
+ const data = paginate30(items, options.page, options.limit, length);
23057
+ repo.setCache(cacheKey, data, 600).then(() => {
23058
+ logger55.log({
23059
+ level: "info",
23060
+ message: `Cache set for getAll tags: ${cacheKey}`
23061
+ });
23062
+ }).catch((err) => {
23063
+ logger55.log({
23064
+ level: "error",
23065
+ message: `Failed to set cache for getAll tags: ${err.message}`
23066
+ });
23067
+ });
23068
+ return data;
23069
+ } catch (error2) {
23070
+ logger55.log({ level: "error", message: `${error2}` });
23071
+ throw error2;
23072
+ }
23073
+ }
23074
+ async function getById(_id) {
23075
+ try {
23076
+ _id = new ObjectId61(_id);
23077
+ } catch (error) {
23078
+ throw new BadRequestError110("Invalid ID.");
23079
+ }
23080
+ const cacheKey = makeCacheKey34(namespace_collection, { _id: String(_id) });
23081
+ try {
23082
+ const cached = await repo.getCache(cacheKey);
23083
+ if (cached) {
23084
+ return cached;
23085
+ }
23086
+ const result = await repo.collection.findOne({ _id });
23087
+ if (!result) {
23088
+ throw new BadRequestError110("Tag not found.");
23089
+ }
23090
+ repo.setCache(cacheKey, result, 300).then(() => {
23091
+ logger55.log({
23092
+ level: "info",
23093
+ message: `Cache set for tag by id: ${cacheKey}`
23094
+ });
23095
+ }).catch((err) => {
23096
+ logger55.log({
23097
+ level: "error",
23098
+ message: `Failed to set cache for tag by id: ${err.message}`
23099
+ });
23100
+ });
23101
+ return result;
23102
+ } catch (error) {
23103
+ if (error instanceof AppError52) {
23104
+ throw error;
23105
+ } else {
23106
+ throw new InternalServerError48("Failed to get tag.");
23107
+ }
23108
+ }
23109
+ }
23110
+ async function updateById(_id, options, session) {
23111
+ try {
23112
+ _id = new ObjectId61(_id);
23113
+ } catch (error) {
23114
+ throw new BadRequestError110("Invalid Tag ID.");
23115
+ }
23116
+ try {
23117
+ await repo.collection.updateOne(
23118
+ { _id },
23119
+ { $set: { ...options, updatedAt: /* @__PURE__ */ new Date() } },
23120
+ { session }
23121
+ );
23122
+ repo.delCachedData();
23123
+ return "Successfully updated tag.";
23124
+ } catch (error) {
23125
+ const isDuplicate = /normalizedName|unique/i.test(error.message);
23126
+ if (isDuplicate) {
23127
+ throw new BadRequestError110("A tag with this name already exists.");
23128
+ }
23129
+ throw new InternalServerError48("Failed to update tag.");
23130
+ }
23131
+ }
23132
+ async function deleteById(_id, session) {
23133
+ try {
23134
+ _id = new ObjectId61(_id);
23135
+ } catch (error) {
23136
+ throw new BadRequestError110("Invalid ID.");
23137
+ }
23138
+ try {
23139
+ await repo.collection.deleteOne({ _id }, { session });
23140
+ repo.delCachedData();
23141
+ return "Successfully deleted tag.";
23142
+ } catch (error) {
23143
+ throw new InternalServerError48("Failed to delete tag.");
23144
+ }
23145
+ }
23146
+ async function findByNormalizedNameAndOrg(normalizedName, orgId) {
23147
+ try {
23148
+ const query = { normalizedName };
23149
+ query.orgId = new ObjectId61(orgId);
23150
+ return await repo.collection.findOne(query);
23151
+ } catch (error) {
23152
+ if (error instanceof AppError52)
23153
+ throw error;
23154
+ throw new InternalServerError48("Failed to find tag.");
23155
+ }
23156
+ }
23157
+ async function incrementUsageCount(_id, amount = 1, session) {
23158
+ try {
23159
+ _id = new ObjectId61(_id);
23160
+ } catch (error) {
23161
+ throw new BadRequestError110("Invalid ID.");
23162
+ }
23163
+ try {
23164
+ await repo.collection.updateOne(
23165
+ { _id },
23166
+ { $inc: { usageCount: amount } },
23167
+ { session }
23168
+ );
23169
+ repo.delCachedData();
23170
+ } catch (error) {
23171
+ throw new InternalServerError48("Failed to update tag usage count.");
23172
+ }
23173
+ }
23174
+ return {
23175
+ createIndexes,
23176
+ add,
23177
+ getAll,
23178
+ getById,
23179
+ findByNormalizedNameAndOrg,
23180
+ updateById,
23181
+ deleteById,
23182
+ incrementUsageCount
23183
+ };
23184
+ }
23185
+
23186
+ // src/resources/asset-item-category/category.repository.ts
23187
+ import {
23188
+ AppError as AppError53,
23189
+ BadRequestError as BadRequestError112,
23190
+ InternalServerError as InternalServerError49,
23191
+ logger as logger56,
23192
+ makeCacheKey as makeCacheKey35,
23193
+ paginate as paginate31,
23194
+ useRepo as useRepo34
23195
+ } from "@goweekdays/utils";
23196
+
23197
+ // src/resources/asset-item-category/category.model.ts
23198
+ import Joi99 from "joi";
23199
+ import { ObjectId as ObjectId62 } from "mongodb";
23200
+ import { BadRequestError as BadRequestError111 } from "@goweekdays/utils";
23201
+ var categoryLevels = [
23202
+ "department",
23203
+ "category",
23204
+ "subcategory"
23205
+ ];
23206
+ var schemaCategoryNodeFields = {
23207
+ orgId: Joi99.string().hex().length(24).optional().allow("", null),
23208
+ level: Joi99.string().valid(...categoryLevels).required(),
23209
+ type: Joi99.string().valid("public", "private").optional().default("public"),
23210
+ name: Joi99.string().required(),
23211
+ displayName: Joi99.string().required(),
23212
+ parentId: Joi99.string().hex().length(24).optional().allow("", null),
23213
+ path: Joi99.string().optional().allow("", null),
23214
+ isActive: Joi99.boolean().optional().default(true)
23215
+ };
23216
+ var schemaCategoryNodeCreate = Joi99.object({
23217
+ displayName: Joi99.string().required(),
23218
+ parentId: Joi99.string().hex().length(24).optional().allow("", null),
23219
+ orgId: Joi99.string().hex().length(24).optional().allow("", null)
23220
+ });
23221
+ var schemaCategoryNodeUpdate = Joi99.object({
23222
+ displayName: Joi99.string().optional()
23223
+ });
23224
+ var schemaCategoryNodeStd = Joi99.object(schemaCategoryNodeFields);
23225
+ var schemaCategoryGetAll = Joi99.object({
23226
+ page: Joi99.number().integer().min(1).default(1),
23227
+ limit: Joi99.number().integer().min(1).max(100).default(20),
23228
+ org: Joi99.string().hex().length(24).optional().allow("", null).default(""),
23229
+ parent: Joi99.string().hex().length(24).optional().allow("", null).default(""),
23230
+ level: Joi99.string().valid(...categoryLevels, "").optional().default(""),
23231
+ type: Joi99.string().valid("public", "private", "").optional().default(""),
23232
+ search: Joi99.string().optional().allow("", null).default(""),
23233
+ status: Joi99.string().optional().allow("", null).default("active")
23234
+ });
23235
+ function normalizeName(displayName) {
23236
+ return displayName.trim().toLowerCase().replace(/\s+/g, "_");
23237
+ }
23238
+ function buildCategoryPath(departmentName, categoryName, subcategoryName) {
23239
+ return [departmentName, categoryName, subcategoryName].filter(Boolean).join(".").replace(/ /g, "_").toLowerCase();
23240
+ }
23241
+ function modelCategoryNode(data) {
23242
+ const { error } = schemaCategoryNodeStd.validate(data);
23243
+ if (error) {
23244
+ throw new BadRequestError111(`Invalid category node data: ${error.message}`);
23245
+ }
23246
+ if (data.orgId) {
23247
+ try {
23248
+ data.orgId = new ObjectId62(data.orgId);
23249
+ } catch {
23250
+ throw new BadRequestError111(`Invalid orgId: ${data.orgId}`);
23251
+ }
23252
+ }
23253
+ if (data.parentId) {
23254
+ try {
23255
+ data.parentId = new ObjectId62(data.parentId);
23256
+ } catch {
23257
+ throw new BadRequestError111(`Invalid parentId: ${data.parentId}`);
23258
+ }
23259
+ }
23260
+ return {
23261
+ _id: data._id,
23262
+ orgId: data.orgId ?? "",
23263
+ level: data.level,
23264
+ type: data.type ?? "public",
23265
+ name: data.name,
23266
+ displayName: data.displayName,
23267
+ parentId: data.parentId ?? "",
23268
+ path: data.path ?? "",
23269
+ status: data.status ?? "active",
23270
+ createdAt: data.createdAt ?? /* @__PURE__ */ new Date(),
23271
+ updatedAt: data.updatedAt ?? ""
23272
+ };
23273
+ }
23274
+
23275
+ // src/resources/asset-item-category/category.repository.ts
23276
+ import { ObjectId as ObjectId63 } from "mongodb";
23277
+ function useCategoryRepo() {
23278
+ const namespace_collection = "categories";
23279
+ const repo = useRepo34(namespace_collection);
23280
+ async function createIndexes() {
23281
+ try {
23282
+ await repo.collection.createIndexes([
23283
+ { key: { level: 1 } },
23284
+ { key: { parentId: 1 } },
23285
+ {
23286
+ key: { name: "text" },
23287
+ name: "text_name"
23288
+ },
23289
+ {
23290
+ key: { name: 1, parentId: 1 },
23291
+ unique: true,
23292
+ name: "unique_name_per_parent"
23293
+ },
23294
+ { key: { path: 1 } },
23295
+ { key: { isActive: 1 } }
23296
+ ]);
23297
+ } catch (error) {
23298
+ throw new InternalServerError49("Failed to create category indexes.");
23299
+ }
23300
+ }
23301
+ async function add(value, session) {
23302
+ try {
23303
+ value = modelCategoryNode(value);
23304
+ const res = await repo.collection.insertOne(value, { session });
23305
+ repo.delCachedData();
23306
+ return res.insertedId;
23307
+ } catch (error) {
23308
+ logger56.log({ level: "error", message: error.message });
23309
+ const isDuplicated = error.message.includes("duplicate");
23310
+ if (isDuplicated) {
23311
+ throw new BadRequestError112(
23312
+ "Category name already exists under this parent."
23313
+ );
23314
+ }
23315
+ throw new InternalServerError49("Failed to create category node.");
23316
+ }
23317
+ }
23318
+ async function getAll({
23319
+ page = 1,
23320
+ limit = 20,
23321
+ org = "",
23322
+ parent = "",
23323
+ level = "",
23324
+ type = "",
23325
+ search = "",
23326
+ status: status2 = "active"
23327
+ } = {}) {
23328
+ page = page > 0 ? page - 1 : 0;
23329
+ const query = { status: status2 };
23330
+ if (org) {
23331
+ try {
23332
+ query.orgId = new ObjectId63(org);
23333
+ } catch (error) {
23334
+ throw new BadRequestError112("Invalid org ID.");
23335
+ }
23336
+ }
23337
+ if (level) {
23338
+ query.level = level;
23339
+ }
23340
+ if (type) {
23341
+ query.type = type;
23342
+ }
23343
+ if (parent) {
23344
+ try {
23345
+ query.parentId = new ObjectId63(parent);
23346
+ } catch (error) {
23347
+ throw new BadRequestError112("Invalid parentId.");
23348
+ }
23349
+ }
23350
+ const cacheKeyOptions = {
23351
+ page,
23352
+ limit,
23353
+ org,
23354
+ parent,
23355
+ level,
23356
+ type,
23357
+ status: status2,
23358
+ tag: "all"
23359
+ };
23360
+ if (search) {
23361
+ query.$text = { $search: `"${search}"` };
23362
+ cacheKeyOptions.search = search;
23363
+ }
23364
+ const cacheKey = makeCacheKey35(namespace_collection, cacheKeyOptions);
23365
+ logger56.log({
23366
+ level: "info",
23367
+ message: `Cache key for getAll categories: ${cacheKey}`
23368
+ });
23369
+ try {
23370
+ const cached = await repo.getCache(cacheKey);
23371
+ if (cached) {
23372
+ logger56.log({
23373
+ level: "info",
23374
+ message: `Cache hit for getAll categories: ${cacheKey}`
23375
+ });
23376
+ return cached;
23377
+ }
23378
+ const items = await repo.collection.aggregate([
23379
+ { $match: query },
23380
+ { $skip: page * limit },
23381
+ { $limit: limit }
23382
+ ]).toArray();
23383
+ const length = await repo.collection.countDocuments(query);
23384
+ const data = paginate31(items, page, limit, length);
23385
+ repo.setCache(cacheKey, data, 600).then(() => {
23386
+ logger56.log({
23387
+ level: "info",
23388
+ message: `Cache set for getAll categories: ${cacheKey}`
23389
+ });
23390
+ }).catch((err) => {
23391
+ logger56.log({
23392
+ level: "error",
23393
+ message: `Failed to set cache for getAll categories: ${err.message}`
23394
+ });
23395
+ });
23396
+ return data;
23397
+ } catch (error) {
23398
+ logger56.log({ level: "error", message: `${error}` });
23399
+ throw new InternalServerError49("Failed to get categories.");
23400
+ }
23401
+ }
23402
+ async function getById(_id) {
23403
+ try {
23404
+ _id = new ObjectId63(_id);
23405
+ } catch {
23406
+ throw new BadRequestError112("Invalid category ID.");
23407
+ }
23408
+ const cacheKey = makeCacheKey35(namespace_collection, {
23409
+ _id: String(_id),
23410
+ tag: "by-id"
23411
+ });
23412
+ try {
23413
+ const cached = await repo.getCache(cacheKey);
23414
+ if (cached)
23415
+ return cached;
23416
+ const result = await repo.collection.findOne({ _id });
23417
+ if (!result) {
23418
+ throw new BadRequestError112("Category node not found.");
23419
+ }
23420
+ repo.setCache(cacheKey, result, 300).catch((err) => {
23421
+ logger56.log({
23422
+ level: "error",
23423
+ message: `Failed to set cache for category by id: ${err.message}`
23424
+ });
23425
+ });
23426
+ return result;
23427
+ } catch (error) {
23428
+ if (error instanceof AppError53)
23429
+ throw error;
23430
+ throw new InternalServerError49("Failed to get category node.");
23431
+ }
23432
+ }
23433
+ async function getByNameParent(name, { parentId = "", orgId = "" } = {}) {
23434
+ const query = {
23435
+ $text: { $search: `"${name.trim()}"` }
23436
+ };
23437
+ if (parentId) {
23438
+ try {
23439
+ query.parentId = new ObjectId63(parentId);
23440
+ } catch (error) {
23441
+ throw new BadRequestError112("Invalid parentId.");
23442
+ }
23443
+ }
23444
+ if (orgId) {
23445
+ try {
23446
+ query.orgId = new ObjectId63(orgId);
23447
+ } catch (error) {
23448
+ throw new BadRequestError112("Invalid orgId.");
23449
+ }
23450
+ }
23451
+ try {
23452
+ const cacheKey = makeCacheKey35(namespace_collection, {
23453
+ name,
23454
+ parentId: parentId ?? "null",
23455
+ orgId: orgId ?? "null",
23456
+ tag: "by-name-parent"
23457
+ });
23458
+ logger56.log({
23459
+ level: "info",
23460
+ message: `Cache key for getByNameParentId: ${cacheKey}`
23461
+ });
23462
+ const cached = await repo.getCache(cacheKey);
23463
+ if (cached) {
23464
+ logger56.log({
23465
+ level: "info",
23466
+ message: `Cache hit for getByNameParentId: ${cacheKey}`
23467
+ });
23468
+ return cached;
23469
+ }
23470
+ const result = await repo.collection.findOne(query);
23471
+ if (result) {
23472
+ repo.setCache(cacheKey, result, 300).catch((err) => {
23473
+ logger56.log({
23474
+ level: "error",
23475
+ message: `Failed to set cache for category by name and parentId: ${err.message}`
23476
+ });
23477
+ });
23478
+ }
23479
+ return result;
23480
+ } catch (error) {
23481
+ console.log(error);
23482
+ throw new InternalServerError49("Failed to get category node by name.");
23483
+ }
23484
+ }
23485
+ async function updateById(_id, update, session) {
23486
+ try {
23487
+ _id = new ObjectId63(_id);
23488
+ } catch {
23489
+ throw new BadRequestError112("Invalid category ID.");
23490
+ }
23491
+ try {
23492
+ const res = await repo.collection.updateOne(
23493
+ { _id },
23494
+ { $set: update },
23495
+ { session }
23496
+ );
23497
+ if (res.matchedCount === 0) {
23498
+ throw new BadRequestError112("Category node not found.");
23499
+ }
23500
+ repo.delCachedData();
23501
+ } catch (error) {
23502
+ if (error instanceof AppError53)
23503
+ throw error;
23504
+ logger56.log({ level: "error", message: error.message });
23505
+ const isDuplicated = error.message.includes("duplicate");
23506
+ if (isDuplicated) {
23507
+ throw new BadRequestError112(
23508
+ "Category name already exists under this parent."
23509
+ );
23510
+ }
23511
+ throw new InternalServerError49("Failed to update category node.");
23512
+ }
23513
+ }
23514
+ async function hasChildren(_id) {
23515
+ try {
23516
+ _id = new ObjectId63(_id);
23517
+ } catch {
23518
+ throw new BadRequestError112("Invalid category ID.");
23519
+ }
23520
+ try {
23521
+ const count = await repo.collection.countDocuments({ parentId: _id });
23522
+ return count > 0;
23523
+ } catch (error) {
23524
+ throw new InternalServerError49("Failed to check for child categories.");
23525
+ }
23526
+ }
23527
+ async function softDeleteById(_id, session) {
23528
+ try {
23529
+ _id = new ObjectId63(_id);
23530
+ } catch {
23531
+ throw new BadRequestError112("Invalid category ID.");
23532
+ }
23533
+ try {
23534
+ const res = await repo.collection.updateOne(
23535
+ { _id },
23536
+ { $set: { status: "deleted", updatedAt: /* @__PURE__ */ new Date() } },
23537
+ { session }
23538
+ );
23539
+ if (res.matchedCount === 0) {
23540
+ throw new BadRequestError112("Category node not found.");
23541
+ }
23542
+ repo.delCachedData();
23543
+ } catch (error) {
23544
+ if (error instanceof AppError53)
23545
+ throw error;
23546
+ throw new InternalServerError49("Failed to delete category node.");
23547
+ }
23548
+ }
23549
+ return {
23550
+ createIndexes,
23551
+ add,
23552
+ getAll,
23553
+ getById,
23554
+ getByNameParent,
23555
+ updateById,
23556
+ hasChildren,
23557
+ softDeleteById
23558
+ };
23559
+ }
23560
+
23561
+ // src/resources/asset-item/asset.item.service.ts
23562
+ function normalizeTagName(name) {
23563
+ return name.trim().toLowerCase().replace(/\s+/g, "-");
23564
+ }
23565
+ function useAssetItemService() {
23566
+ const assetItemRepo = useAssetItemRepo();
23567
+ const tagRepo = useTagRepo();
23568
+ const categoryRepo = useCategoryRepo();
23569
+ async function resolveTags(tagNames, orgId, categoryPath, session) {
23570
+ const resolvedTags = [];
23571
+ for (const tag of tagNames) {
23572
+ const normalizedName = normalizeTagName(tag.name);
23573
+ const existing = await tagRepo.findByNormalizedNameAndOrg(
23574
+ normalizedName,
23575
+ orgId
23576
+ );
23577
+ if (existing && existing._id) {
23578
+ await tagRepo.incrementUsageCount(existing._id, 1, session);
23579
+ resolvedTags.push({
23580
+ id: String(existing._id),
23581
+ name: existing.name
23582
+ });
23583
+ } else {
23584
+ const tagData = {
23585
+ name: tag.name.trim(),
23586
+ normalizedName,
23587
+ type: "private",
23588
+ orgId,
23589
+ categoryPath,
23590
+ status: "active",
23591
+ usageCount: 1
23592
+ };
23593
+ const tagId = await tagRepo.add(tagData, session);
23594
+ resolvedTags.push({
23595
+ id: String(tagId),
23596
+ name: tag.name.trim()
23597
+ });
23598
+ }
23599
+ }
23600
+ return resolvedTags;
23601
+ }
23602
+ async function add(value) {
23603
+ const session = useAtlas17.getClient()?.startSession();
23604
+ if (!session) {
23605
+ throw new InternalServerError50(
23606
+ "Unable to start session for asset item service."
23607
+ );
23608
+ }
23609
+ try {
23610
+ await session.startTransaction();
23611
+ const department = await categoryRepo.getById(value.departmentId);
23612
+ value.departmentName = department.displayName;
23613
+ if (value.categoryId) {
23614
+ const category = await categoryRepo.getById(value.categoryId);
23615
+ value.categoryName = category.displayName;
23616
+ }
23617
+ if (value.subcategoryId) {
23618
+ const subcategory = await categoryRepo.getById(value.subcategoryId);
23619
+ value.subcategoryName = subcategory.displayName;
23620
+ }
23621
+ const categoryPath = buildCategoryPath(
23622
+ value.departmentName,
23623
+ value.categoryName ?? "",
23624
+ value.subcategoryName ?? ""
23625
+ );
23626
+ value.categoryPath = categoryPath;
23627
+ const resolvedTags = value.tags.length ? await resolveTags(
23628
+ value.tags,
23629
+ value.orgId,
23630
+ value.categoryPath,
23631
+ session
23632
+ ) : [];
23633
+ const assetItem = {
23634
+ ...value,
23635
+ tags: resolvedTags
23636
+ };
23637
+ const assetItemId = await assetItemRepo.add(assetItem, session);
23638
+ await session.commitTransaction();
23639
+ return assetItemId;
23640
+ } catch (error) {
23641
+ await session.abortTransaction();
23642
+ if (error instanceof AppError54)
23643
+ throw error;
23644
+ throw new InternalServerError50("Failed to create asset item.");
23645
+ } finally {
23646
+ session.endSession();
23647
+ }
23648
+ }
23649
+ return {
23650
+ add
23651
+ };
23652
+ }
23653
+
23654
+ // src/resources/asset-item/asset.item.controller.ts
23655
+ import Joi100 from "joi";
23656
+ import { BadRequestError as BadRequestError114 } from "@goweekdays/utils";
23657
+ var paginationSchema3 = Joi100.object({
23658
+ page: Joi100.number().min(1).optional().allow("", null),
23659
+ limit: Joi100.number().min(1).optional().allow("", null),
23660
+ search: Joi100.string().optional().allow("", null),
23661
+ status: Joi100.string().valid(...assetItemStatuses).optional().allow("", null),
23662
+ assetCategory: Joi100.string().valid(...assetItemCategories).optional().allow("", null),
23663
+ trackingType: Joi100.string().valid(...assetItemTrackingTypes).optional().allow("", null),
23664
+ purpose: Joi100.string().valid(...assetItemPurposes).optional().allow("", null),
23665
+ departmentId: Joi100.string().optional().allow("", null),
23666
+ categoryId: Joi100.string().optional().allow("", null),
23667
+ subcategoryId: Joi100.string().optional().allow("", null),
23668
+ brand: Joi100.string().optional().allow("", null),
23669
+ tags: Joi100.string().optional().allow("", null)
23670
+ });
23671
+ var idParamSchema2 = Joi100.object({
23672
+ id: Joi100.string().hex().length(24).required()
23673
+ });
23674
+ function useAssetItemController() {
23675
+ const repo = useAssetItemRepo();
23676
+ const service = useAssetItemService();
23677
+ async function add(req, res, next) {
23678
+ try {
23679
+ const { error, value } = schemaAssetItemCreate.validate(req.body);
23680
+ if (error) {
23681
+ next(new BadRequestError114(error.message));
23682
+ return;
23683
+ }
23684
+ const assetItemId = await service.add(value);
23685
+ res.status(201).json({
23686
+ message: "Asset item created successfully.",
23687
+ assetItemId
23688
+ });
23689
+ } catch (error) {
23690
+ next(error);
23691
+ }
23692
+ }
23693
+ async function getAll(req, res, next) {
23694
+ const { error } = paginationSchema3.validate(req.query);
23695
+ if (error) {
23696
+ next(new BadRequestError114(error.message));
23697
+ return;
23698
+ }
23699
+ const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
23700
+ const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
23701
+ const search = req.query.search ?? "";
23702
+ const status2 = req.query.status ?? "active";
23703
+ const assetCategory = req.query.assetCategory ?? "";
23704
+ const trackingType = req.query.trackingType ?? "";
23705
+ const purpose = req.query.purpose ?? "";
23706
+ const departmentId = req.query.departmentId ?? "";
23707
+ const categoryId = req.query.categoryId ?? "";
23708
+ const subcategoryId = req.query.subcategoryId ?? "";
23709
+ const brand = req.query.brand ?? "";
23710
+ const tagsParam = req.query.tags ?? "";
23711
+ const tags = tagsParam ? tagsParam.split(",").filter(Boolean) : [];
23712
+ if (!isFinite(page)) {
23713
+ next(new BadRequestError114("Invalid page number."));
23714
+ return;
23715
+ }
23716
+ if (!isFinite(limit)) {
23717
+ next(new BadRequestError114("Invalid limit number."));
23718
+ return;
23719
+ }
23720
+ try {
23721
+ const results = await repo.getAll({
23722
+ page,
23723
+ limit,
23724
+ search,
23725
+ status: status2,
23726
+ assetCategory,
23727
+ trackingType,
23728
+ purpose,
23729
+ departmentId,
23730
+ categoryId,
23731
+ subcategoryId,
23732
+ brand,
23733
+ tags
23734
+ });
23735
+ res.json(results);
23736
+ } catch (error2) {
23737
+ next(error2);
23738
+ }
23739
+ }
23740
+ async function getById(req, res, next) {
23741
+ const { error } = idParamSchema2.validate(req.params);
23742
+ if (error) {
23743
+ next(new BadRequestError114(error.message));
23744
+ return;
23745
+ }
23746
+ try {
23747
+ const assetItem = await repo.getById(req.params.id);
23748
+ res.json(assetItem);
23749
+ } catch (error2) {
23750
+ next(error2);
23751
+ }
23752
+ }
23753
+ async function updateById(req, res, next) {
23754
+ const { error: paramError } = idParamSchema2.validate(req.params);
23755
+ if (paramError) {
23756
+ next(new BadRequestError114(paramError.message));
23757
+ return;
23758
+ }
23759
+ const { error: bodyError } = schemaAssetItemUpdate.validate(req.body);
23760
+ if (bodyError) {
23761
+ next(new BadRequestError114(bodyError.message));
23762
+ return;
23763
+ }
23764
+ try {
23765
+ const updatedAssetItem = await repo.updateById(req.params.id, req.body);
23766
+ res.json({
23767
+ message: "Asset item updated successfully.",
23768
+ assetItem: updatedAssetItem
23769
+ });
23770
+ } catch (error) {
23771
+ next(error);
23772
+ }
23773
+ }
23774
+ async function deleteById(req, res, next) {
23775
+ const { error } = idParamSchema2.validate(req.params);
23776
+ if (error) {
23777
+ next(new BadRequestError114(error.message));
23778
+ return;
23779
+ }
23780
+ try {
23781
+ await repo.deleteById(req.params.id);
23782
+ res.json({
23783
+ message: "Asset item deleted successfully."
23784
+ });
23785
+ } catch (error2) {
23786
+ next(error2);
23787
+ }
23788
+ }
23789
+ return {
23790
+ add,
23791
+ getAll,
23792
+ getById,
23793
+ updateById,
23794
+ deleteById
23795
+ };
23796
+ }
23797
+
23798
+ // src/resources/asset-item-unit/asset.unit.model.ts
23799
+ import Joi101 from "joi";
23800
+ import { ObjectId as ObjectId64 } from "mongodb";
23801
+ var assetUnitStatuses = [
23802
+ "available",
23803
+ "assigned",
23804
+ "maintenance",
23805
+ "disposed"
23806
+ ];
23807
+ var schemaAssetUnitBase = {
23808
+ itemId: Joi101.string().hex().length(24).required(),
23809
+ serialNumber: Joi101.string().optional().allow("", null),
23810
+ plateNumber: Joi101.string().optional().allow("", null),
23811
+ status: Joi101.string().valid(...assetUnitStatuses).required(),
23812
+ locationId: Joi101.string().optional().allow("", null),
23813
+ assignedTo: Joi101.string().optional().allow("", null)
23814
+ };
23815
+ var schemaAssetUnit = Joi101.object(schemaAssetUnitBase);
23816
+ var schemaAssetUnitUpdate = Joi101.object({
23817
+ serialNumber: Joi101.string().optional().allow("", null),
23818
+ plateNumber: Joi101.string().optional().allow("", null),
23819
+ status: Joi101.string().valid(...assetUnitStatuses).optional(),
23820
+ locationId: Joi101.string().optional().allow("", null),
23821
+ assignedTo: Joi101.string().optional().allow("", null)
23822
+ });
23823
+ function modelAssetUnit(data) {
23824
+ const { error } = schemaAssetUnit.validate(data);
23825
+ if (error) {
23826
+ throw new Error(`Invalid asset unit data: ${error.message}`);
23827
+ }
23828
+ if (data.itemId && typeof data.itemId === "string") {
23829
+ try {
23830
+ data.itemId = new ObjectId64(data.itemId);
23831
+ } catch {
23832
+ throw new Error(`Invalid itemId format: ${data.itemId}`);
23833
+ }
23834
+ }
23835
+ return {
23836
+ _id: data._id,
23837
+ itemId: data.itemId,
23838
+ serialNumber: data.serialNumber ?? "",
23839
+ plateNumber: data.plateNumber ?? "",
23840
+ status: data.status,
23841
+ locationId: data.locationId ?? "",
23842
+ assignedTo: data.assignedTo ?? "",
23843
+ createdAt: data.createdAt ?? /* @__PURE__ */ new Date(),
23844
+ updatedAt: data.updatedAt ?? ""
23845
+ };
23846
+ }
23847
+
23848
+ // src/resources/asset-item-unit/asset.unit.repository.ts
23849
+ import {
23850
+ AppError as AppError55,
23851
+ BadRequestError as BadRequestError115,
23852
+ InternalServerError as InternalServerError51,
23853
+ logger as logger57,
23854
+ makeCacheKey as makeCacheKey36,
23855
+ paginate as paginate32,
23856
+ useRepo as useRepo35
23857
+ } from "@goweekdays/utils";
23858
+ import { ObjectId as ObjectId65 } from "mongodb";
23859
+ function useAssetUnitRepo() {
23860
+ const namespace_collection = "asset.units";
23861
+ const repo = useRepo35(namespace_collection);
23862
+ async function createIndexes() {
23863
+ try {
23864
+ await repo.collection.createIndexes([
23865
+ { key: { itemId: 1 } },
23866
+ { key: { status: 1 } },
23867
+ { key: { locationId: 1 } },
23868
+ { key: { itemId: 1, status: 1 } }
23869
+ ]);
23870
+ } catch (error) {
23871
+ throw new BadRequestError115("Failed to create asset unit indexes.");
23872
+ }
23873
+ }
23874
+ async function add(value, session) {
23875
+ try {
23876
+ value = modelAssetUnit(value);
23877
+ const res = await repo.collection.insertOne(value, { session });
23878
+ repo.delCachedData();
23879
+ return res.insertedId;
23880
+ } catch (error) {
23881
+ logger57.log({ level: "error", message: error.message });
23882
+ throw new InternalServerError51("Failed to create asset unit.");
23883
+ }
23884
+ }
23885
+ async function getByItemId({
23886
+ itemId,
23887
+ status: status2 = "",
23888
+ page = 1,
23889
+ limit = 10
23890
+ }) {
23891
+ page = page > 0 ? page - 1 : 0;
23892
+ const query = {
23893
+ itemId: new ObjectId65(itemId)
23894
+ };
23895
+ if (status2) {
23896
+ query.status = status2;
23897
+ }
23898
+ const cacheKey = makeCacheKey36(namespace_collection, {
23899
+ itemId,
23900
+ status: status2,
23901
+ page,
23902
+ limit,
23903
+ tag: "byItemId"
23904
+ });
23905
+ try {
23906
+ const cached = await repo.getCache(cacheKey);
23907
+ if (cached)
23908
+ return cached;
23909
+ const items = await repo.collection.aggregate([
23910
+ { $match: query },
23911
+ { $sort: { _id: -1 } },
23912
+ { $skip: page * limit },
23913
+ { $limit: limit }
23914
+ ]).toArray();
23915
+ const length = await repo.collection.countDocuments(query);
23916
+ const data = paginate32(items, page, limit, length);
23917
+ repo.setCache(cacheKey, data, 600);
23918
+ return data;
23919
+ } catch (error) {
23920
+ logger57.log({ level: "error", message: `${error}` });
23921
+ throw error;
23922
+ }
23923
+ }
23924
+ async function getById(id) {
23925
+ const cacheKey = makeCacheKey36(namespace_collection, {
23926
+ id,
23927
+ tag: "by-id"
23928
+ });
23929
+ try {
23930
+ const cached = await repo.getCache(cacheKey);
23931
+ if (cached)
23932
+ return cached;
23933
+ const result = await repo.collection.findOne({
23934
+ _id: new ObjectId65(id)
23935
+ });
23936
+ if (!result) {
23937
+ throw new BadRequestError115("Asset unit not found.");
23938
+ }
23939
+ repo.setCache(cacheKey, result, 300);
23940
+ return result;
23941
+ } catch (error) {
23942
+ if (error instanceof AppError55)
23943
+ throw error;
23944
+ throw new InternalServerError51("Failed to get asset unit.");
23945
+ }
23946
+ }
23947
+ async function updateById(id, value, session) {
23948
+ try {
23949
+ const result = await repo.collection.findOneAndUpdate(
23950
+ { _id: new ObjectId65(id) },
23951
+ { $set: { ...value, updatedAt: /* @__PURE__ */ new Date() } },
23952
+ { returnDocument: "after", session }
23953
+ );
23954
+ if (!result) {
23955
+ throw new BadRequestError115("Asset unit not found.");
23956
+ }
23957
+ repo.delCachedData();
23958
+ return result;
23959
+ } catch (error) {
23960
+ if (error instanceof AppError55)
23961
+ throw error;
23962
+ throw new InternalServerError51("Failed to update asset unit.");
23963
+ }
23964
+ }
23965
+ async function countByItemIdAndStatus(itemId, status2) {
23966
+ try {
23967
+ return await repo.collection.countDocuments({
23968
+ itemId: new ObjectId65(itemId),
23969
+ status: status2
23970
+ });
23971
+ } catch (error) {
23972
+ throw new InternalServerError51("Failed to count asset units.");
23973
+ }
23974
+ }
23975
+ return {
23976
+ createIndexes,
23977
+ add,
23978
+ getByItemId,
23979
+ getById,
23980
+ updateById,
23981
+ countByItemIdAndStatus
23982
+ };
23983
+ }
23984
+
23985
+ // src/resources/asset-item-unit/asset.unit.controller.ts
23986
+ import Joi102 from "joi";
23987
+ import { BadRequestError as BadRequestError116 } from "@goweekdays/utils";
23988
+ var querySchema = Joi102.object({
23989
+ itemId: Joi102.string().hex().length(24).required(),
23990
+ status: Joi102.string().valid(...assetUnitStatuses).optional().allow("", null),
23991
+ page: Joi102.number().min(1).optional().allow("", null),
23992
+ limit: Joi102.number().min(1).optional().allow("", null)
23993
+ });
23994
+ var idParamSchema3 = Joi102.object({
23995
+ id: Joi102.string().hex().length(24).required()
23996
+ });
23997
+ function useAssetUnitController() {
23998
+ const repo = useAssetUnitRepo();
23999
+ async function add(req, res, next) {
24000
+ try {
24001
+ const { error } = schemaAssetUnit.validate(req.body);
24002
+ if (error) {
24003
+ next(new BadRequestError116(error.message));
24004
+ return;
24005
+ }
24006
+ const unitId = await repo.add(req.body);
24007
+ res.status(201).json({
24008
+ message: "Asset unit created successfully.",
24009
+ unitId
24010
+ });
24011
+ } catch (error) {
24012
+ next(error);
24013
+ }
24014
+ }
24015
+ async function getByItemId(req, res, next) {
24016
+ const { error } = querySchema.validate(req.query);
24017
+ if (error) {
24018
+ next(new BadRequestError116(error.message));
24019
+ return;
24020
+ }
24021
+ const itemId = req.query.itemId;
24022
+ const status2 = req.query.status ?? "";
24023
+ const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
24024
+ const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
24025
+ try {
24026
+ const results = await repo.getByItemId({ itemId, status: status2, page, limit });
24027
+ res.json(results);
24028
+ } catch (error2) {
24029
+ next(error2);
24030
+ }
24031
+ }
24032
+ async function getById(req, res, next) {
24033
+ const { error } = idParamSchema3.validate(req.params);
24034
+ if (error) {
24035
+ next(new BadRequestError116(error.message));
24036
+ return;
24037
+ }
24038
+ try {
24039
+ const unit = await repo.getById(req.params.id);
24040
+ res.json(unit);
24041
+ } catch (error2) {
24042
+ next(error2);
24043
+ }
24044
+ }
24045
+ async function updateById(req, res, next) {
24046
+ const { error: paramError } = idParamSchema3.validate(req.params);
24047
+ if (paramError) {
24048
+ next(new BadRequestError116(paramError.message));
24049
+ return;
24050
+ }
24051
+ const { error: bodyError } = schemaAssetUnitUpdate.validate(req.body);
24052
+ if (bodyError) {
24053
+ next(new BadRequestError116(bodyError.message));
24054
+ return;
24055
+ }
24056
+ try {
24057
+ const updatedUnit = await repo.updateById(req.params.id, req.body);
24058
+ res.json({
24059
+ message: "Asset unit updated successfully.",
24060
+ unit: updatedUnit
24061
+ });
24062
+ } catch (error) {
24063
+ next(error);
24064
+ }
24065
+ }
24066
+ return {
24067
+ add,
24068
+ getByItemId,
24069
+ getById,
24070
+ updateById
24071
+ };
24072
+ }
24073
+
24074
+ // src/resources/asset-item-movement/stock.movement.model.ts
24075
+ import Joi103 from "joi";
24076
+ import { ObjectId as ObjectId66 } from "mongodb";
24077
+ var stockMovementTypes = [
24078
+ "in",
24079
+ "out",
24080
+ "transfer",
24081
+ "adjustment",
24082
+ "conversion"
24083
+ ];
24084
+ var stockMovementReferenceTypes = [
24085
+ "purchase",
24086
+ "sale",
24087
+ "transfer",
24088
+ "manual",
24089
+ "conversion"
24090
+ ];
24091
+ var schemaStockMovement = Joi103.object({
24092
+ itemId: Joi103.string().hex().length(24).required(),
24093
+ type: Joi103.string().valid(...stockMovementTypes).required(),
24094
+ quantity: Joi103.number().positive().required(),
24095
+ unitCost: Joi103.number().min(0).optional().allow(null),
24096
+ totalCost: Joi103.number().min(0).optional().allow(null),
24097
+ reference: Joi103.object({
24098
+ type: Joi103.string().valid(...stockMovementReferenceTypes).required(),
24099
+ id: Joi103.string().optional().allow("", null)
24100
+ }).optional().allow(null),
24101
+ fromLocationId: Joi103.string().optional().allow("", null),
24102
+ toLocationId: Joi103.string().optional().allow("", null),
24103
+ fromItemId: Joi103.string().hex().length(24).optional().allow("", null),
24104
+ toItemId: Joi103.string().hex().length(24).optional().allow("", null),
24105
+ reason: Joi103.string().optional().allow("", null)
24106
+ });
24107
+ function modelStockMovement(data) {
24108
+ const { error } = schemaStockMovement.validate(data);
24109
+ if (error) {
24110
+ throw new Error(`Invalid stock movement data: ${error.message}`);
24111
+ }
24112
+ if (data.itemId && typeof data.itemId === "string") {
24113
+ try {
24114
+ data.itemId = new ObjectId66(data.itemId);
24115
+ } catch {
24116
+ throw new Error(`Invalid itemId format: ${data.itemId}`);
24117
+ }
24118
+ }
24119
+ return {
24120
+ _id: data._id,
24121
+ itemId: data.itemId,
24122
+ type: data.type,
24123
+ quantity: data.quantity,
24124
+ unitCost: data.unitCost ?? 0,
24125
+ totalCost: data.totalCost ?? 0,
24126
+ reference: data.reference ?? void 0,
24127
+ fromLocationId: data.fromLocationId ?? "",
24128
+ toLocationId: data.toLocationId ?? "",
24129
+ fromItemId: data.fromItemId ?? "",
24130
+ toItemId: data.toItemId ?? "",
24131
+ reason: data.reason ?? "",
24132
+ createdAt: data.createdAt ?? /* @__PURE__ */ new Date()
24133
+ };
24134
+ }
24135
+
24136
+ // src/resources/asset-item-movement/stock.movement.repository.ts
24137
+ import {
24138
+ AppError as AppError56,
24139
+ BadRequestError as BadRequestError117,
24140
+ InternalServerError as InternalServerError52,
24141
+ logger as logger58,
24142
+ makeCacheKey as makeCacheKey37,
24143
+ paginate as paginate33,
24144
+ useRepo as useRepo36
24145
+ } from "@goweekdays/utils";
24146
+ import { ObjectId as ObjectId67 } from "mongodb";
24147
+ function useStockMovementRepo() {
24148
+ const namespace_collection = "stock.movements";
24149
+ const repo = useRepo36(namespace_collection);
24150
+ async function createIndexes() {
24151
+ try {
24152
+ await repo.collection.createIndexes([
24153
+ { key: { itemId: 1 } },
24154
+ { key: { createdAt: -1 } },
24155
+ { key: { itemId: 1, createdAt: -1 } },
24156
+ { key: { type: 1 } }
24157
+ ]);
24158
+ } catch (error) {
24159
+ throw new BadRequestError117("Failed to create stock movement indexes.");
24160
+ }
24161
+ }
24162
+ async function add(value, session) {
24163
+ try {
24164
+ value = modelStockMovement(value);
24165
+ const res = await repo.collection.insertOne(value, { session });
24166
+ repo.delCachedData();
24167
+ return res.insertedId;
24168
+ } catch (error) {
24169
+ logger58.log({ level: "error", message: error.message });
24170
+ throw new InternalServerError52("Failed to create stock movement.");
24171
+ }
24172
+ }
24173
+ async function getByItemId({
24174
+ itemId,
24175
+ type = "",
24176
+ page = 1,
24177
+ limit = 10
24178
+ }) {
24179
+ page = page > 0 ? page - 1 : 0;
24180
+ const query = {
24181
+ itemId: new ObjectId67(itemId)
24182
+ };
24183
+ if (type) {
24184
+ query.type = type;
24185
+ }
24186
+ const cacheKey = makeCacheKey37(namespace_collection, {
24187
+ itemId,
24188
+ type,
24189
+ page,
24190
+ limit,
24191
+ tag: "byItemId"
24192
+ });
24193
+ try {
24194
+ const cached = await repo.getCache(cacheKey);
24195
+ if (cached)
24196
+ return cached;
24197
+ const items = await repo.collection.aggregate([
24198
+ { $match: query },
24199
+ { $sort: { createdAt: -1 } },
24200
+ { $skip: page * limit },
24201
+ { $limit: limit }
24202
+ ]).toArray();
24203
+ const length = await repo.collection.countDocuments(query);
24204
+ const data = paginate33(items, page, limit, length);
24205
+ repo.setCache(cacheKey, data, 600);
24206
+ return data;
24207
+ } catch (error) {
24208
+ logger58.log({ level: "error", message: `${error}` });
24209
+ throw error;
24210
+ }
24211
+ }
24212
+ async function getById(id) {
24213
+ const cacheKey = makeCacheKey37(namespace_collection, {
24214
+ id,
24215
+ tag: "by-id"
24216
+ });
24217
+ try {
24218
+ const cached = await repo.getCache(cacheKey);
24219
+ if (cached)
24220
+ return cached;
24221
+ const result = await repo.collection.findOne({
24222
+ _id: new ObjectId67(id)
24223
+ });
24224
+ if (!result) {
24225
+ throw new BadRequestError117("Stock movement not found.");
24226
+ }
24227
+ repo.setCache(cacheKey, result, 300);
24228
+ return result;
24229
+ } catch (error) {
24230
+ if (error instanceof AppError56)
24231
+ throw error;
24232
+ throw new InternalServerError52("Failed to get stock movement.");
24233
+ }
24234
+ }
24235
+ return {
24236
+ createIndexes,
24237
+ add,
24238
+ getByItemId,
24239
+ getById
24240
+ };
24241
+ }
24242
+
24243
+ // src/resources/asset-item-movement/stock.movement.service.ts
24244
+ import { BadRequestError as BadRequestError118 } from "@goweekdays/utils";
24245
+ import { useAtlas as useAtlas18 } from "@goweekdays/utils";
24246
+ function useStockMovementService() {
24247
+ const movementRepo = useStockMovementRepo();
24248
+ const assetItemRepo = useAssetItemRepo();
24249
+ const assetUnitRepo = useAssetUnitRepo();
24250
+ async function stockIn(value, units) {
24251
+ const item = await assetItemRepo.getById(String(value.itemId));
24252
+ const session = useAtlas18.getClient()?.startSession();
24253
+ if (!session)
24254
+ throw new BadRequestError118("Failed to start session.");
24255
+ try {
24256
+ session.startTransaction();
24257
+ value.type = "in";
24258
+ const movementId = await movementRepo.add(value, session);
24259
+ if (item.trackingType === "individual" && units && units.length > 0) {
24260
+ for (const unit of units) {
24261
+ await assetUnitRepo.add(
24262
+ {
24263
+ itemId: value.itemId,
24264
+ serialNumber: unit.serialNumber,
24265
+ plateNumber: unit.plateNumber,
24266
+ status: "available",
24267
+ locationId: value.toLocationId
24268
+ },
24269
+ session
24270
+ );
24271
+ }
24272
+ }
24273
+ await assetItemRepo.incrementQuantity(
24274
+ String(value.itemId),
24275
+ value.quantity,
24276
+ session
24277
+ );
24278
+ await session.commitTransaction();
24279
+ return movementId;
24280
+ } catch (error) {
24281
+ await session.abortTransaction();
24282
+ throw error;
24283
+ } finally {
24284
+ await session.endSession();
24285
+ }
24286
+ }
24287
+ async function stockOut(value, unitIds) {
24288
+ const item = await assetItemRepo.getById(String(value.itemId));
24289
+ if (item.trackingType === "quantity" && (item.quantityOnHand ?? 0) < value.quantity) {
24290
+ throw new BadRequestError118("Insufficient stock.");
24291
+ }
24292
+ const session = useAtlas18.getClient()?.startSession();
24293
+ if (!session)
24294
+ throw new BadRequestError118("Failed to start session.");
24295
+ try {
24296
+ session.startTransaction();
24297
+ value.type = "out";
24298
+ const movementId = await movementRepo.add(value, session);
24299
+ if (item.trackingType === "individual" && unitIds && unitIds.length > 0) {
24300
+ for (const unitId of unitIds) {
24301
+ await assetUnitRepo.updateById(
24302
+ unitId,
24303
+ { status: "assigned", assignedTo: value.reference?.id },
24304
+ session
24305
+ );
24306
+ }
24307
+ }
24308
+ await assetItemRepo.incrementQuantity(
24309
+ String(value.itemId),
24310
+ -value.quantity,
24311
+ session
24312
+ );
24313
+ await session.commitTransaction();
24314
+ return movementId;
24315
+ } catch (error) {
24316
+ await session.abortTransaction();
24317
+ throw error;
24318
+ } finally {
24319
+ await session.endSession();
24320
+ }
24321
+ }
24322
+ async function transfer(value, unitIds) {
24323
+ if (!value.fromLocationId || !value.toLocationId) {
24324
+ throw new BadRequestError118(
24325
+ "Transfer requires both fromLocationId and toLocationId."
24326
+ );
24327
+ }
24328
+ const item = await assetItemRepo.getById(String(value.itemId));
24329
+ const session = useAtlas18.getClient()?.startSession();
24330
+ if (!session)
24331
+ throw new BadRequestError118("Failed to start session.");
24332
+ try {
24333
+ session.startTransaction();
24334
+ value.type = "transfer";
24335
+ const movementId = await movementRepo.add(value, session);
24336
+ if (item.trackingType === "individual" && unitIds && unitIds.length > 0) {
24337
+ for (const unitId of unitIds) {
24338
+ await assetUnitRepo.updateById(
24339
+ unitId,
24340
+ { locationId: value.toLocationId },
24341
+ session
24342
+ );
24343
+ }
24344
+ }
24345
+ await session.commitTransaction();
24346
+ return movementId;
24347
+ } catch (error) {
24348
+ await session.abortTransaction();
24349
+ throw error;
24350
+ } finally {
24351
+ await session.endSession();
24352
+ }
24353
+ }
24354
+ async function adjustment(value) {
24355
+ if (!value.reason) {
24356
+ throw new BadRequestError118("Adjustment requires a reason.");
24357
+ }
24358
+ const session = useAtlas18.getClient()?.startSession();
24359
+ if (!session)
24360
+ throw new BadRequestError118("Failed to start session.");
24361
+ try {
24362
+ session.startTransaction();
24363
+ value.type = "adjustment";
24364
+ const movementId = await movementRepo.add(value, session);
24365
+ await assetItemRepo.incrementQuantity(
24366
+ String(value.itemId),
24367
+ value.quantity,
24368
+ session
24369
+ );
24370
+ await session.commitTransaction();
24371
+ return movementId;
24372
+ } catch (error) {
24373
+ await session.abortTransaction();
24374
+ throw error;
24375
+ } finally {
24376
+ await session.endSession();
24377
+ }
24378
+ }
24379
+ async function conversion(newItem, quantity, unitIds) {
24380
+ const sourceItem = await assetItemRepo.getById(String(newItem.itemRefId));
24381
+ if (!newItem.itemRefId) {
24382
+ throw new BadRequestError118("Conversion requires itemRefId.");
24383
+ }
24384
+ if (sourceItem.trackingType === "quantity" && (sourceItem.quantityOnHand ?? 0) < quantity) {
24385
+ throw new BadRequestError118("Insufficient stock on source item.");
24386
+ }
24387
+ const session = useAtlas18.getClient()?.startSession();
24388
+ if (!session)
24389
+ throw new BadRequestError118("Failed to start session.");
24390
+ try {
24391
+ session.startTransaction();
24392
+ const newItemId = await assetItemRepo.add(newItem, session);
24393
+ const movementData = {
24394
+ itemId: newItem.itemRefId,
24395
+ type: "conversion",
24396
+ quantity,
24397
+ fromItemId: String(newItem.itemRefId),
24398
+ toItemId: String(newItemId),
24399
+ reference: { type: "conversion", id: String(newItemId) }
24400
+ };
24401
+ const movementId = await movementRepo.add(movementData, session);
24402
+ await assetItemRepo.incrementQuantity(
24403
+ String(newItem.itemRefId),
24404
+ -quantity,
24405
+ session
24406
+ );
24407
+ await assetItemRepo.incrementQuantity(
24408
+ String(newItemId),
24409
+ quantity,
24410
+ session
24411
+ );
24412
+ if (sourceItem.trackingType === "individual" && unitIds && unitIds.length > 0) {
24413
+ for (const unitId of unitIds) {
24414
+ await assetUnitRepo.updateById(
24415
+ unitId,
24416
+ { itemId: String(newItemId) },
24417
+ session
24418
+ );
24419
+ }
24420
+ }
24421
+ await session.commitTransaction();
24422
+ return { movementId, newItemId };
24423
+ } catch (error) {
24424
+ await session.abortTransaction();
24425
+ throw error;
24426
+ } finally {
24427
+ await session.endSession();
24428
+ }
24429
+ }
24430
+ return {
24431
+ stockIn,
24432
+ stockOut,
24433
+ transfer,
24434
+ adjustment,
24435
+ conversion
24436
+ };
24437
+ }
24438
+
24439
+ // src/resources/asset-item-movement/stock.movement.controller.ts
24440
+ import Joi104 from "joi";
24441
+ import { BadRequestError as BadRequestError119 } from "@goweekdays/utils";
24442
+ var querySchema2 = Joi104.object({
24443
+ itemId: Joi104.string().hex().length(24).required(),
24444
+ type: Joi104.string().valid(...stockMovementTypes).optional().allow("", null),
24445
+ page: Joi104.number().min(1).optional().allow("", null),
24446
+ limit: Joi104.number().min(1).optional().allow("", null)
24447
+ });
24448
+ var idParamSchema4 = Joi104.object({
24449
+ id: Joi104.string().hex().length(24).required()
24450
+ });
24451
+ var stockInSchema = Joi104.object({
24452
+ itemId: Joi104.string().hex().length(24).required(),
24453
+ quantity: Joi104.number().positive().required(),
24454
+ unitCost: Joi104.number().min(0).optional().allow(null),
24455
+ totalCost: Joi104.number().min(0).optional().allow(null),
24456
+ reference: Joi104.object({
24457
+ type: Joi104.string().valid("purchase", "sale", "transfer", "manual", "conversion").required(),
24458
+ id: Joi104.string().optional().allow("", null)
24459
+ }).optional().allow(null),
24460
+ toLocationId: Joi104.string().optional().allow("", null),
24461
+ units: Joi104.array().items(
24462
+ Joi104.object({
24463
+ serialNumber: Joi104.string().optional().allow("", null),
24464
+ plateNumber: Joi104.string().optional().allow("", null)
24465
+ })
24466
+ ).optional()
24467
+ });
24468
+ var stockOutSchema = Joi104.object({
24469
+ itemId: Joi104.string().hex().length(24).required(),
24470
+ quantity: Joi104.number().positive().required(),
24471
+ unitCost: Joi104.number().min(0).optional().allow(null),
24472
+ totalCost: Joi104.number().min(0).optional().allow(null),
24473
+ reference: Joi104.object({
24474
+ type: Joi104.string().valid("purchase", "sale", "transfer", "manual", "conversion").required(),
24475
+ id: Joi104.string().optional().allow("", null)
24476
+ }).optional().allow(null),
24477
+ fromLocationId: Joi104.string().optional().allow("", null),
24478
+ unitIds: Joi104.array().items(Joi104.string().hex().length(24)).optional()
24479
+ });
24480
+ var transferSchema = Joi104.object({
24481
+ itemId: Joi104.string().hex().length(24).required(),
24482
+ quantity: Joi104.number().positive().required(),
24483
+ fromLocationId: Joi104.string().required(),
24484
+ toLocationId: Joi104.string().required(),
24485
+ reference: Joi104.object({
24486
+ type: Joi104.string().valid("purchase", "sale", "transfer", "manual", "conversion").required(),
24487
+ id: Joi104.string().optional().allow("", null)
24488
+ }).optional().allow(null),
24489
+ unitIds: Joi104.array().items(Joi104.string().hex().length(24)).optional()
24490
+ });
24491
+ var adjustmentSchema = Joi104.object({
24492
+ itemId: Joi104.string().hex().length(24).required(),
24493
+ quantity: Joi104.number().required(),
24494
+ reason: Joi104.string().required(),
24495
+ reference: Joi104.object({
24496
+ type: Joi104.string().valid("purchase", "sale", "transfer", "manual", "conversion").required(),
24497
+ id: Joi104.string().optional().allow("", null)
24498
+ }).optional().allow(null)
24499
+ });
24500
+ var conversionSchema = Joi104.object({
24501
+ quantity: Joi104.number().positive().required(),
24502
+ newItem: Joi104.object({
24503
+ name: Joi104.string().required(),
24504
+ description: Joi104.string().optional().allow("", null),
24505
+ assetCategory: Joi104.string().valid(...assetItemCategories).required(),
24506
+ assetClass: Joi104.string().valid(...assetItemClasses).required(),
24507
+ trackingType: Joi104.string().valid(...assetItemTrackingTypes).required(),
24508
+ purpose: Joi104.string().valid(...assetItemPurposes).required(),
24509
+ itemRefId: Joi104.string().hex().length(24).required(),
24510
+ remarks: Joi104.string().optional().allow("", null),
24511
+ departmentId: Joi104.string().required(),
24512
+ departmentName: Joi104.string().required(),
24513
+ categoryId: Joi104.string().required(),
24514
+ categoryName: Joi104.string().required(),
24515
+ subcategoryId: Joi104.string().required(),
24516
+ subcategoryName: Joi104.string().required(),
24517
+ categoryPath: Joi104.string().required(),
24518
+ brand: Joi104.string().optional().allow("", null),
24519
+ tags: Joi104.array().items(
24520
+ Joi104.object({
24521
+ id: Joi104.string().required(),
24522
+ name: Joi104.string().required()
24523
+ })
24524
+ ).optional().default([])
24525
+ }).required(),
24526
+ unitIds: Joi104.array().items(Joi104.string().hex().length(24)).optional()
24527
+ });
24528
+ function useStockMovementController() {
24529
+ const repo = useStockMovementRepo();
24530
+ const service = useStockMovementService();
24531
+ async function stockIn(req, res, next) {
24532
+ try {
24533
+ const { error } = stockInSchema.validate(req.body);
24534
+ if (error) {
24535
+ next(new BadRequestError119(error.message));
24536
+ return;
24537
+ }
24538
+ const { units, ...movement } = req.body;
24539
+ const movementId = await service.stockIn(movement, units);
24540
+ res.status(201).json({
24541
+ message: "Stock in recorded successfully.",
24542
+ movementId
24543
+ });
24544
+ } catch (error) {
24545
+ next(error);
24546
+ }
24547
+ }
24548
+ async function stockOut(req, res, next) {
24549
+ try {
24550
+ const { error } = stockOutSchema.validate(req.body);
24551
+ if (error) {
24552
+ next(new BadRequestError119(error.message));
24553
+ return;
24554
+ }
24555
+ const { unitIds, ...movement } = req.body;
24556
+ const movementId = await service.stockOut(movement, unitIds);
24557
+ res.status(201).json({
24558
+ message: "Stock out recorded successfully.",
24559
+ movementId
24560
+ });
24561
+ } catch (error) {
24562
+ next(error);
24563
+ }
24564
+ }
24565
+ async function transfer(req, res, next) {
24566
+ try {
24567
+ const { error } = transferSchema.validate(req.body);
24568
+ if (error) {
24569
+ next(new BadRequestError119(error.message));
24570
+ return;
24571
+ }
24572
+ const { unitIds, ...movement } = req.body;
24573
+ const movementId = await service.transfer(movement, unitIds);
24574
+ res.status(201).json({
24575
+ message: "Transfer recorded successfully.",
24576
+ movementId
24577
+ });
24578
+ } catch (error) {
24579
+ next(error);
24580
+ }
24581
+ }
24582
+ async function adjustment(req, res, next) {
24583
+ try {
24584
+ const { error } = adjustmentSchema.validate(req.body);
24585
+ if (error) {
24586
+ next(new BadRequestError119(error.message));
24587
+ return;
24588
+ }
24589
+ const movementId = await service.adjustment(req.body);
24590
+ res.status(201).json({
24591
+ message: "Adjustment recorded successfully.",
24592
+ movementId
24593
+ });
24594
+ } catch (error) {
24595
+ next(error);
24596
+ }
24597
+ }
24598
+ async function getByItemId(req, res, next) {
24599
+ const { error } = querySchema2.validate(req.query);
24600
+ if (error) {
24601
+ next(new BadRequestError119(error.message));
24602
+ return;
24603
+ }
24604
+ const itemId = req.query.itemId;
24605
+ const type = req.query.type ?? "";
24606
+ const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
24607
+ const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
24608
+ try {
24609
+ const results = await repo.getByItemId({ itemId, type, page, limit });
24610
+ res.json(results);
24611
+ } catch (error2) {
24612
+ next(error2);
24613
+ }
24614
+ }
24615
+ async function getById(req, res, next) {
24616
+ const { error } = idParamSchema4.validate(req.params);
24617
+ if (error) {
24618
+ next(new BadRequestError119(error.message));
24619
+ return;
24620
+ }
24621
+ try {
24622
+ const movement = await repo.getById(req.params.id);
24623
+ res.json(movement);
24624
+ } catch (error2) {
24625
+ next(error2);
24626
+ }
24627
+ }
24628
+ async function conversion(req, res, next) {
24629
+ try {
24630
+ const { error } = conversionSchema.validate(req.body);
24631
+ if (error) {
24632
+ next(new BadRequestError119(error.message));
24633
+ return;
24634
+ }
24635
+ const { quantity, newItem, unitIds } = req.body;
24636
+ const result = await service.conversion(newItem, quantity, unitIds);
24637
+ res.status(201).json({
24638
+ message: "Conversion recorded successfully.",
24639
+ movementId: result.movementId,
24640
+ newItemId: result.newItemId
24641
+ });
24642
+ } catch (error) {
24643
+ next(error);
24644
+ }
24645
+ }
24646
+ return {
24647
+ stockIn,
24648
+ stockOut,
24649
+ transfer,
24650
+ adjustment,
24651
+ conversion,
24652
+ getByItemId,
24653
+ getById
24654
+ };
24655
+ }
24656
+
24657
+ // src/resources/asset-item-category/category.service.ts
24658
+ import { BadRequestError as BadRequestError120 } from "@goweekdays/utils";
24659
+ function useCategoryService() {
24660
+ const repo = useCategoryRepo();
24661
+ async function add(value) {
24662
+ const { error } = schemaCategoryNodeCreate.validate(value);
24663
+ if (error) {
24664
+ throw new BadRequestError120(error.message);
24665
+ }
24666
+ const name = normalizeName(value.displayName);
24667
+ let level;
24668
+ let path = "";
24669
+ if (!value.parentId) {
24670
+ level = "department";
24671
+ const existing = await repo.getByNameParent(name, { orgId: value.orgId });
24672
+ if (existing) {
24673
+ throw new BadRequestError120(
24674
+ `Department "${value.displayName}" already exists.`
24675
+ );
24676
+ }
24677
+ } else {
24678
+ const parent = await repo.getById(value.parentId);
24679
+ if (parent && parent.level === "department") {
24680
+ level = "category";
24681
+ } else if (parent && parent.level === "category") {
24682
+ level = "subcategory";
24683
+ } else {
24684
+ throw new BadRequestError120(
24685
+ "Cannot create a child under a subcategory. Maximum depth is 3 levels."
24686
+ );
24687
+ }
24688
+ const existing = await repo.getByNameParent(name, {
24689
+ parentId: value.parentId,
24690
+ orgId: value.orgId
24691
+ });
24692
+ if (existing) {
24693
+ throw new BadRequestError120(
24694
+ `"${value.displayName}" already exists under this parent.`
24695
+ );
24696
+ }
24697
+ if (level === "subcategory") {
24698
+ const department = await repo.getById(parent.parentId);
24699
+ path = buildCategoryPath(department.name, parent.name, name);
24700
+ }
24701
+ }
24702
+ const data = {
24703
+ orgId: value.orgId ?? "",
24704
+ level,
24705
+ type: value.orgId ? "private" : "public",
24706
+ name,
24707
+ displayName: value.displayName.trim(),
24708
+ parentId: value.parentId ?? "",
24709
+ path
24710
+ };
24711
+ return await repo.add(data);
24712
+ }
24713
+ async function updateById(_id, value) {
24714
+ const { error } = schemaCategoryNodeUpdate.validate(value);
24715
+ if (error) {
24716
+ throw new BadRequestError120(error.message);
24717
+ }
24718
+ const update = {
24719
+ displayName: "",
24720
+ name: "",
24721
+ updatedAt: /* @__PURE__ */ new Date()
24722
+ };
24723
+ if (value.displayName) {
24724
+ update.displayName = value.displayName.trim();
24725
+ update.name = normalizeName(value.displayName);
24726
+ }
24727
+ await repo.updateById(_id, update);
24728
+ }
24729
+ async function deleteById(_id) {
24730
+ const hasChildren = await repo.hasChildren(_id);
24731
+ if (hasChildren) {
24732
+ throw new BadRequestError120(
24733
+ "Cannot delete a category that has child categories. Remove or reassign children first."
24734
+ );
24735
+ }
24736
+ await repo.softDeleteById(_id);
24737
+ }
24738
+ return {
24739
+ add,
24740
+ updateById,
24741
+ deleteById
24742
+ };
24743
+ }
24744
+
24745
+ // src/resources/asset-item-category/category.controller.ts
24746
+ import Joi105 from "joi";
24747
+ import { BadRequestError as BadRequestError121 } from "@goweekdays/utils";
24748
+ function useCategoryController() {
24749
+ const repo = useCategoryRepo();
24750
+ const service = useCategoryService();
24751
+ async function add(req, res, next) {
24752
+ const orgId = req.params.org ?? "";
24753
+ const { error, value } = schemaCategoryNodeCreate.validate({
24754
+ ...req.body,
24755
+ orgId
24756
+ });
24757
+ if (error) {
24758
+ next(new BadRequestError121(error.message));
24759
+ return;
24760
+ }
24761
+ try {
24762
+ const id = await service.add(value);
24763
+ res.status(201).json({ message: "Category created successfully.", id });
24764
+ } catch (error2) {
24765
+ next(error2);
24766
+ }
24767
+ }
24768
+ async function getAll(req, res, next) {
24769
+ const org = req.params.org ?? "";
24770
+ const { error, value } = schemaCategoryGetAll.validate({
24771
+ ...req.query,
24772
+ org
24773
+ });
24774
+ if (error) {
24775
+ next(new BadRequestError121(error.message));
24776
+ return;
24777
+ }
24778
+ try {
24779
+ const data = await repo.getAll(value);
24780
+ res.json(data);
24781
+ } catch (error2) {
24782
+ next(error2);
24783
+ }
24784
+ }
24785
+ async function getById(req, res, next) {
24786
+ const _id = req.params.id;
24787
+ const { error: errorId } = Joi105.string().hex().length(24).required().validate(_id);
24788
+ if (errorId) {
24789
+ next(new BadRequestError121("Invalid category ID."));
24790
+ return;
24791
+ }
24792
+ try {
24793
+ const category = await repo.getById(_id);
24794
+ if (!category) {
24795
+ next(new BadRequestError121("Category not found."));
24796
+ return;
24797
+ }
24798
+ res.json(category);
24799
+ } catch (error) {
24800
+ next(error);
24801
+ }
24802
+ }
24803
+ async function updateById(req, res, next) {
24804
+ const _id = req.params.id;
24805
+ const { error: errorId } = Joi105.string().hex().length(24).required().validate(_id);
24806
+ if (errorId) {
24807
+ next(new BadRequestError121("Invalid category ID."));
24808
+ return;
24809
+ }
24810
+ const { error, value } = schemaCategoryNodeUpdate.validate(req.body);
24811
+ if (error) {
24812
+ next(new BadRequestError121(error.message));
24813
+ return;
24814
+ }
24815
+ const { displayName } = value;
24816
+ try {
24817
+ await service.updateById(_id, { displayName });
24818
+ res.json({ message: "Category updated successfully." });
24819
+ } catch (error2) {
24820
+ next(error2);
24821
+ }
24822
+ }
24823
+ async function deleteById(req, res, next) {
24824
+ const _id = req.params.id;
24825
+ const { error: errorId } = Joi105.string().hex().length(24).required().validate(_id);
24826
+ if (errorId) {
24827
+ next(new BadRequestError121("Invalid category ID."));
24828
+ return;
24829
+ }
24830
+ try {
24831
+ await service.deleteById(_id);
24832
+ res.json({ message: "Category deleted successfully." });
24833
+ } catch (error) {
24834
+ next(error);
24835
+ }
24836
+ }
24837
+ return {
24838
+ add,
24839
+ getAll,
24840
+ getById,
24841
+ updateById,
24842
+ deleteById
24843
+ };
24844
+ }
24845
+
24846
+ // src/resources/tag/tag.service.ts
24847
+ import { AppError as AppError57, BadRequestError as BadRequestError122 } from "@goweekdays/utils";
24848
+ import Joi106 from "joi";
24849
+ function normalizeTagName2(name) {
24850
+ return name.trim().toLowerCase().replace(/\s+/g, "-");
24851
+ }
24852
+ function useTagService() {
24853
+ const {
24854
+ add: _add,
24855
+ getById: _getById,
24856
+ updateById: _updateById,
24857
+ deleteById: _deleteById
24858
+ } = useTagRepo();
24859
+ async function add(value) {
24860
+ const { error } = schemaTagCreate.validate(value);
24861
+ if (error) {
24862
+ throw new BadRequestError122(error.message);
24863
+ }
24864
+ const normalizedName = normalizeTagName2(value.name);
24865
+ const data = {
24866
+ name: value.name,
24867
+ normalizedName,
24868
+ type: value.type,
24869
+ orgId: value.orgId ?? "",
24870
+ categoryPath: value.categoryPath ?? "",
24871
+ status: "pending",
24872
+ usageCount: 0
24873
+ };
24874
+ try {
24875
+ const id = await _add(data);
24876
+ return id;
24877
+ } catch (error2) {
24878
+ if (error2 instanceof AppError57)
24879
+ throw error2;
24880
+ throw new BadRequestError122("Failed to add tag.");
24881
+ }
24882
+ }
24883
+ async function updateById(id, value) {
24884
+ const { error: errorId } = Joi106.string().hex().required().validate(id);
24885
+ if (errorId) {
24886
+ throw new BadRequestError122("Invalid Tag ID.");
24887
+ }
24888
+ const { error } = schemaTagUpdate.validate(value);
24889
+ if (error) {
24890
+ throw new BadRequestError122(`Invalid tag update data: ${error.message}`);
24891
+ }
24892
+ const existingTag = await _getById(id);
24893
+ if (!existingTag) {
24894
+ throw new BadRequestError122("Tag not found.");
24895
+ }
24896
+ const updatedData = { ...value };
24897
+ if (value.name) {
24898
+ updatedData.normalizedName = normalizeTagName2(value.name);
24899
+ }
24900
+ const message = await _updateById(id, updatedData);
24901
+ return message;
24902
+ }
24903
+ async function deleteById(id) {
24904
+ const { error } = Joi106.string().hex().required().validate(id);
24905
+ if (error) {
24906
+ throw new BadRequestError122("Invalid Tag ID.");
24907
+ }
24908
+ const existingTag = await _getById(id);
24909
+ if (!existingTag) {
24910
+ throw new BadRequestError122("Tag not found.");
24911
+ }
24912
+ const message = await _deleteById(id);
24913
+ return message;
24914
+ }
24915
+ return {
24916
+ add,
24917
+ updateById,
24918
+ deleteById
24919
+ };
24920
+ }
24921
+
24922
+ // src/resources/tag/tag.controller.ts
24923
+ import Joi107 from "joi";
24924
+ import { BadRequestError as BadRequestError123, logger as logger59 } from "@goweekdays/utils";
24925
+ function useTagController() {
24926
+ const { getAll: _getAll, getById: _getById } = useTagRepo();
24927
+ const {
24928
+ add: _add,
24929
+ updateById: _updateById,
24930
+ deleteById: _deleteById
24931
+ } = useTagService();
24932
+ async function add(req, res, next) {
24933
+ const value = req.body;
24934
+ const { error } = schemaTagCreate.validate(value);
24935
+ if (error) {
24936
+ next(new BadRequestError123(error.message));
24937
+ logger59.info(`Controller: ${error.message}`);
24938
+ return;
24939
+ }
24940
+ try {
24941
+ const message = await _add(value);
24942
+ res.json({ message });
24943
+ return;
24944
+ } catch (error2) {
24945
+ next(error2);
24946
+ }
24947
+ }
24948
+ async function getAll(req, res, next) {
24949
+ const query = req.query;
24950
+ const validation = Joi107.object({
24951
+ page: Joi107.number().min(1).optional().allow("", null),
24952
+ limit: Joi107.number().min(1).optional().allow("", null),
24953
+ search: Joi107.string().optional().allow("", null),
24954
+ type: Joi107.string().valid("public", "private").optional().allow("", null),
24955
+ orgId: Joi107.string().hex().optional().allow("", null),
24956
+ status: Joi107.string().valid("active", "pending").optional().allow("", null),
24957
+ categoryPath: Joi107.string().optional().allow("", null)
24958
+ });
24959
+ const { error } = validation.validate(query);
24960
+ if (error) {
24961
+ next(new BadRequestError123(error.message));
24962
+ return;
24963
+ }
24964
+ const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
24965
+ const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
24966
+ const search = req.query.search ?? "";
24967
+ const type = req.query.type ?? "";
24968
+ const orgId = req.query.orgId ?? "";
24969
+ const status2 = req.query.status ?? "";
24970
+ const categoryPath = req.query.categoryPath ?? "";
24971
+ const isPageNumber = isFinite(page);
24972
+ if (!isPageNumber) {
24973
+ next(new BadRequestError123("Invalid page number."));
24974
+ return;
24975
+ }
24976
+ const isLimitNumber = isFinite(limit);
24977
+ if (!isLimitNumber) {
24978
+ next(new BadRequestError123("Invalid limit number."));
24979
+ return;
24980
+ }
24981
+ try {
24982
+ const tags = await _getAll({
24983
+ page,
24984
+ limit,
24985
+ search,
24986
+ type,
24987
+ orgId,
24988
+ status: status2,
24989
+ categoryPath
24990
+ });
24991
+ res.json(tags);
24992
+ return;
24993
+ } catch (error2) {
24994
+ next(error2);
24995
+ }
24996
+ }
24997
+ async function getById(req, res, next) {
24998
+ const id = req.params.id;
24999
+ const validation = Joi107.object({
25000
+ id: Joi107.string().hex().required()
25001
+ });
25002
+ const { error } = validation.validate({ id });
25003
+ if (error) {
25004
+ next(new BadRequestError123(error.message));
25005
+ return;
25006
+ }
25007
+ try {
25008
+ const tag = await _getById(id);
25009
+ res.json(tag);
25010
+ return;
25011
+ } catch (error2) {
25012
+ next(error2);
25013
+ }
25014
+ }
25015
+ async function updateById(req, res, next) {
25016
+ const _id = req.params.id;
25017
+ const { error: errorId } = Joi107.string().hex().required().validate(_id);
25018
+ if (errorId) {
25019
+ next(new BadRequestError123("Invalid Tag ID."));
25020
+ return;
25021
+ }
25022
+ const payload = req.body;
25023
+ const { error } = schemaTagUpdate.validate(payload);
25024
+ if (error) {
25025
+ next(new BadRequestError123(error.message));
25026
+ return;
25027
+ }
25028
+ try {
25029
+ const message = await _updateById(_id, payload);
25030
+ res.json({ message });
25031
+ return;
25032
+ } catch (error2) {
25033
+ next(error2);
25034
+ }
25035
+ }
25036
+ async function deleteById(req, res, next) {
25037
+ const id = req.params.id;
25038
+ if (!id) {
25039
+ next(new BadRequestError123("Tag ID is required."));
25040
+ return;
25041
+ }
25042
+ try {
25043
+ const message = await _deleteById(id);
25044
+ res.json(message);
25045
+ return;
25046
+ } catch (error) {
25047
+ next(error);
25048
+ }
25049
+ }
25050
+ return {
25051
+ add,
25052
+ getAll,
25053
+ getById,
25054
+ updateById,
25055
+ deleteById
25056
+ };
25057
+ }
22509
25058
  export {
22510
25059
  ACCESS_TOKEN_EXPIRY,
22511
25060
  ACCESS_TOKEN_SECRET,
@@ -22549,6 +25098,14 @@ export {
22549
25098
  VERIFICATION_USER_INVITE_DURATION,
22550
25099
  XENDIT_BASE_URL,
22551
25100
  XENDIT_SECRET_KEY,
25101
+ assetItemCategories,
25102
+ assetItemClasses,
25103
+ assetItemPurposes,
25104
+ assetItemStatuses,
25105
+ assetItemTrackingTypes,
25106
+ assetUnitStatuses,
25107
+ buildCategoryPath,
25108
+ categoryLevels,
22552
25109
  chartOfAccountControlTypes,
22553
25110
  chartOfAccountNormalBalances,
22554
25111
  chartOfAccountStatuses,
@@ -22563,7 +25120,10 @@ export {
22563
25120
  ledgerBillTypes,
22564
25121
  modelAccountBalance,
22565
25122
  modelApp,
25123
+ modelAssetItem,
25124
+ modelAssetUnit,
22566
25125
  modelBusinessProfile,
25126
+ modelCategoryNode,
22567
25127
  modelChartOfAccount,
22568
25128
  modelCustomer,
22569
25129
  modelJobApplication,
@@ -22589,14 +25149,22 @@ export {
22589
25149
  modelPlan,
22590
25150
  modelPromo,
22591
25151
  modelRole,
25152
+ modelStockMovement,
22592
25153
  modelSubscription,
22593
25154
  modelSubscriptionTransaction,
25155
+ modelTag,
22594
25156
  modelTax,
22595
25157
  modelUser,
22596
25158
  modelVerification,
25159
+ normalizeName,
22597
25160
  schemaAccountBalance,
22598
25161
  schemaApp,
22599
25162
  schemaAppUpdate,
25163
+ schemaAssetItem,
25164
+ schemaAssetItemCreate,
25165
+ schemaAssetItemUpdate,
25166
+ schemaAssetUnit,
25167
+ schemaAssetUnitUpdate,
22600
25168
  schemaAward,
22601
25169
  schemaBuilding,
22602
25170
  schemaBuildingUnit,
@@ -22608,6 +25176,10 @@ export {
22608
25176
  schemaBusinessProfileRegisteredAddress,
22609
25177
  schemaBusinessProfileTIN,
22610
25178
  schemaBusinessProfileTradeName,
25179
+ schemaCategoryGetAll,
25180
+ schemaCategoryNodeCreate,
25181
+ schemaCategoryNodeStd,
25182
+ schemaCategoryNodeUpdate,
22611
25183
  schemaCertification,
22612
25184
  schemaChartOfAccountBase,
22613
25185
  schemaChartOfAccountStd,
@@ -22677,6 +25249,7 @@ export {
22677
25249
  schemaRole,
22678
25250
  schemaRoleUpdate,
22679
25251
  schemaSkill,
25252
+ schemaStockMovement,
22680
25253
  schemaSubscribe,
22681
25254
  schemaSubscription,
22682
25255
  schemaSubscriptionCompute,
@@ -22684,6 +25257,9 @@ export {
22684
25257
  schemaSubscriptionSeats,
22685
25258
  schemaSubscriptionTransaction,
22686
25259
  schemaSubscriptionUpdate,
25260
+ schemaTagCreate,
25261
+ schemaTagStd,
25262
+ schemaTagUpdate,
22687
25263
  schemaTax,
22688
25264
  schemaTaxUpdate,
22689
25265
  schemaUpdateOptions,
@@ -22691,6 +25267,8 @@ export {
22691
25267
  schemaVerification,
22692
25268
  schemaVerificationOrgInvite,
22693
25269
  schemaWorkExp,
25270
+ stockMovementReferenceTypes,
25271
+ stockMovementTypes,
22694
25272
  taxDirections,
22695
25273
  taxTypes,
22696
25274
  transactionSchema,
@@ -22698,6 +25276,11 @@ export {
22698
25276
  useAppController,
22699
25277
  useAppRepo,
22700
25278
  useAppService,
25279
+ useAssetItemController,
25280
+ useAssetItemRepo,
25281
+ useAssetItemService,
25282
+ useAssetUnitController,
25283
+ useAssetUnitRepo,
22701
25284
  useAuthController,
22702
25285
  useAuthService,
22703
25286
  useBuildingController,
@@ -22708,6 +25291,9 @@ export {
22708
25291
  useBuildingUnitService,
22709
25292
  useBusinessProfileCtrl,
22710
25293
  useBusinessProfileRepo,
25294
+ useCategoryController,
25295
+ useCategoryRepo,
25296
+ useCategoryService,
22711
25297
  useChartOfAccountController,
22712
25298
  useChartOfAccountRepo,
22713
25299
  useCounterModel,
@@ -22763,11 +25349,17 @@ export {
22763
25349
  useRoleController,
22764
25350
  useRoleRepo,
22765
25351
  useRoleService,
25352
+ useStockMovementController,
25353
+ useStockMovementRepo,
25354
+ useStockMovementService,
22766
25355
  useSubscriptionController,
22767
25356
  useSubscriptionRepo,
22768
25357
  useSubscriptionService,
22769
25358
  useSubscriptionTransactionController,
22770
25359
  useSubscriptionTransactionRepo,
25360
+ useTagController,
25361
+ useTagRepo,
25362
+ useTagService,
22771
25363
  useTaxController,
22772
25364
  useTaxRepo,
22773
25365
  useUserController,