@goweekdays/core 2.11.18 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -201,11 +201,11 @@ function useUserRepo() {
201
201
  page = 1,
202
202
  limit = 10,
203
203
  sort = {},
204
- status = "active",
204
+ status: status2 = "active",
205
205
  type = ""
206
206
  } = {}) {
207
207
  page = page > 0 ? page - 1 : 0;
208
- const query = { status };
208
+ const query = { status: status2 };
209
209
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
210
210
  if (search) {
211
211
  query.$text = { $search: search };
@@ -218,7 +218,7 @@ function useUserRepo() {
218
218
  page,
219
219
  limit,
220
220
  sort: JSON.stringify(sort),
221
- status,
221
+ status: status2,
222
222
  type
223
223
  });
224
224
  logger.log({
@@ -736,15 +736,15 @@ function useVerificationRepo() {
736
736
  page = 1,
737
737
  limit = 10,
738
738
  sort = {},
739
- status = "active",
739
+ status: status2 = "active",
740
740
  type = "",
741
741
  email = "",
742
742
  app = "",
743
743
  org = ""
744
744
  } = {}) {
745
745
  page = page > 0 ? page - 1 : 0;
746
- const query = { status };
747
- const cacheKeyOptions = { status, limit, page };
746
+ const query = { status: status2 };
747
+ const cacheKeyOptions = { status: status2, limit, page };
748
748
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
749
749
  cacheKeyOptions.sort = JSON.stringify(sort);
750
750
  if (app) {
@@ -849,7 +849,7 @@ function useVerificationRepo() {
849
849
  return Promise.reject(error);
850
850
  }
851
851
  }
852
- async function updateStatusById(_id, status, session) {
852
+ async function updateStatusById(_id, status2, session) {
853
853
  try {
854
854
  _id = new ObjectId4(_id);
855
855
  } catch (error) {
@@ -858,7 +858,7 @@ function useVerificationRepo() {
858
858
  try {
859
859
  const result = await collection.updateOne(
860
860
  { _id },
861
- { $set: { status, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
861
+ { $set: { status: status2, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
862
862
  { session }
863
863
  );
864
864
  delCachedData();
@@ -1472,10 +1472,10 @@ function useMemberRepo() {
1472
1472
  );
1473
1473
  }
1474
1474
  }
1475
- async function updateStatusById(_id, status, session) {
1475
+ async function updateStatusById(_id, status2, session) {
1476
1476
  const { error } = schemaMemberStatus.validate({
1477
1477
  _id,
1478
- status
1478
+ status: status2
1479
1479
  });
1480
1480
  if (error) {
1481
1481
  throw new BadRequestError7(error.message);
@@ -1490,7 +1490,7 @@ function useMemberRepo() {
1490
1490
  { _id },
1491
1491
  {
1492
1492
  $set: {
1493
- status,
1493
+ status: status2,
1494
1494
  updatedAt: /* @__PURE__ */ new Date()
1495
1495
  }
1496
1496
  },
@@ -1504,13 +1504,13 @@ function useMemberRepo() {
1504
1504
  );
1505
1505
  }
1506
1506
  }
1507
- async function getAll({ search, limit, page, user, org, app, status } = {}) {
1507
+ async function getAll({ search, limit, page, user, org, app, status: status2 } = {}) {
1508
1508
  limit = limit && limit > 0 ? limit : 10;
1509
1509
  search = search || "";
1510
1510
  page = page && page > 0 ? page - 1 : 0;
1511
- status = status ?? "active";
1512
- const query = { app, status };
1513
- const cacheKeyOptions = { app, status, limit, page };
1511
+ status2 = status2 ?? "active";
1512
+ const query = { app, status: status2 };
1513
+ const cacheKeyOptions = { app, status: status2, limit, page };
1514
1514
  if (user) {
1515
1515
  cacheKeyOptions.user = String(user);
1516
1516
  try {
@@ -1738,7 +1738,7 @@ function useMemberRepo() {
1738
1738
  limit = 10,
1739
1739
  sort = {},
1740
1740
  user = "",
1741
- status = "active"
1741
+ status: status2 = "active"
1742
1742
  } = {}) {
1743
1743
  page = page > 0 ? page - 1 : 0;
1744
1744
  try {
@@ -1747,10 +1747,10 @@ function useMemberRepo() {
1747
1747
  throw new BadRequestError7("Invalid user ID.");
1748
1748
  }
1749
1749
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
1750
- const query = { user, status };
1750
+ const query = { user, status: status2 };
1751
1751
  const cacheKeyOptions = {
1752
1752
  user: String(user),
1753
- status,
1753
+ status: status2,
1754
1754
  limit,
1755
1755
  page,
1756
1756
  sort: JSON.stringify(sort)
@@ -1810,17 +1810,17 @@ function useMemberRepo() {
1810
1810
  );
1811
1811
  }
1812
1812
  }
1813
- async function updateStatusByUserId(user, status) {
1813
+ async function updateStatusByUserId(user, status2) {
1814
1814
  try {
1815
1815
  user = new ObjectId7(user);
1816
1816
  } catch (error) {
1817
1817
  throw new BadRequestError7("Invalid user ID.");
1818
1818
  }
1819
1819
  const options = {
1820
- status,
1820
+ status: status2,
1821
1821
  updatedAt: /* @__PURE__ */ new Date()
1822
1822
  };
1823
- if (status === "deleted") {
1823
+ if (status2 === "deleted") {
1824
1824
  options.deletedAt = /* @__PURE__ */ new Date();
1825
1825
  }
1826
1826
  try {
@@ -1866,11 +1866,11 @@ function useMemberRepo() {
1866
1866
  );
1867
1867
  }
1868
1868
  }
1869
- async function updateStatusByOrg(org, status, session) {
1869
+ async function updateStatusByOrg(org, status2, session) {
1870
1870
  const { error } = Joi4.object({
1871
1871
  org: Joi4.string().hex().length(24).required(),
1872
1872
  status: Joi4.string().valid("active", "suspended").required()
1873
- }).validate({ org, status });
1873
+ }).validate({ org, status: status2 });
1874
1874
  if (error) {
1875
1875
  throw new BadRequestError7(error.message);
1876
1876
  }
@@ -1884,7 +1884,7 @@ function useMemberRepo() {
1884
1884
  { org, status: { $ne: "deleted" }, app: { $ne: "org" } },
1885
1885
  {
1886
1886
  $set: {
1887
- status,
1887
+ status: status2,
1888
1888
  updatedAt: /* @__PURE__ */ new Date()
1889
1889
  }
1890
1890
  },
@@ -2533,7 +2533,7 @@ function usePermissionRepo() {
2533
2533
  limit = 10,
2534
2534
  sort = {},
2535
2535
  app = "",
2536
- status = "active"
2536
+ status: status2 = "active"
2537
2537
  } = {}) {
2538
2538
  page = page > 0 ? page - 1 : 0;
2539
2539
  const query = {};
@@ -2543,8 +2543,8 @@ function usePermissionRepo() {
2543
2543
  sort: JSON.stringify(sort)
2544
2544
  };
2545
2545
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
2546
- query.status = status;
2547
- cacheParams.status = status;
2546
+ query.status = status2;
2547
+ cacheParams.status = status2;
2548
2548
  if (search) {
2549
2549
  query.$text = { $search: search };
2550
2550
  cacheParams.search = search;
@@ -2845,7 +2845,7 @@ function usePermissionController() {
2845
2845
  }
2846
2846
  const app = req.query.app ?? "";
2847
2847
  const search = req.query.search ?? "";
2848
- const status = req.query.status ?? "active";
2848
+ const status2 = req.query.status ?? "active";
2849
2849
  try {
2850
2850
  const buildings = await _getAll({
2851
2851
  page,
@@ -2853,7 +2853,7 @@ function usePermissionController() {
2853
2853
  sort: sortObj,
2854
2854
  app,
2855
2855
  search,
2856
- status
2856
+ status: status2
2857
2857
  });
2858
2858
  res.json(buildings);
2859
2859
  return;
@@ -3061,7 +3061,7 @@ function usePermissionGroupRepo() {
3061
3061
  limit = 10,
3062
3062
  sort = {},
3063
3063
  app = "",
3064
- status = "active"
3064
+ status: status2 = "active"
3065
3065
  } = {}) {
3066
3066
  page = page > 0 ? page - 1 : 0;
3067
3067
  const query = {};
@@ -3071,8 +3071,8 @@ function usePermissionGroupRepo() {
3071
3071
  sort: JSON.stringify(sort)
3072
3072
  };
3073
3073
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
3074
- query.status = status;
3075
- cacheParams.status = status;
3074
+ query.status = status2;
3075
+ cacheParams.status = status2;
3076
3076
  if (search) {
3077
3077
  query.$text = { $search: search };
3078
3078
  cacheParams.search = search;
@@ -3395,16 +3395,16 @@ function useAppRepo() {
3395
3395
  page = 1,
3396
3396
  limit = 10,
3397
3397
  sort = {},
3398
- status = "active",
3398
+ status: status2 = "active",
3399
3399
  type = "standard"
3400
3400
  } = {}) {
3401
3401
  page = page > 0 ? page - 1 : 0;
3402
3402
  const query = {
3403
- status
3403
+ status: status2
3404
3404
  };
3405
3405
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
3406
3406
  const cacheParams = {
3407
- status,
3407
+ status: status2,
3408
3408
  page,
3409
3409
  limit,
3410
3410
  sort: JSON.stringify(sort)
@@ -3766,7 +3766,7 @@ function useAppController() {
3766
3766
  sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
3767
3767
  });
3768
3768
  }
3769
- const status = req.query.status ?? "active";
3769
+ const status2 = req.query.status ?? "active";
3770
3770
  const search = req.query.search ?? "";
3771
3771
  let type = req.query.type ? req.query.type.split(",") : "standard";
3772
3772
  try {
@@ -3774,7 +3774,7 @@ function useAppController() {
3774
3774
  page,
3775
3775
  limit,
3776
3776
  sort: sortObj,
3777
- status,
3777
+ status: status2,
3778
3778
  search,
3779
3779
  type
3780
3780
  });
@@ -4373,7 +4373,7 @@ function usePermissionGroupController() {
4373
4373
  }
4374
4374
  const app = req.query.app ?? "";
4375
4375
  const search = req.query.search ?? "";
4376
- const status = req.query.status ?? "active";
4376
+ const status2 = req.query.status ?? "active";
4377
4377
  try {
4378
4378
  const buildings = await _getAll({
4379
4379
  page,
@@ -4381,7 +4381,7 @@ function usePermissionGroupController() {
4381
4381
  sort: sortObj,
4382
4382
  app,
4383
4383
  search,
4384
- status
4384
+ status: status2
4385
4385
  });
4386
4386
  res.json(buildings);
4387
4387
  return;
@@ -4587,10 +4587,10 @@ function useOrgRepo() {
4587
4587
  page = 1,
4588
4588
  limit = 10,
4589
4589
  sort = {},
4590
- status = "active"
4590
+ status: status2 = "active"
4591
4591
  } = {}) {
4592
4592
  page = page > 0 ? page - 1 : 0;
4593
- const query = { status };
4593
+ const query = { status: status2 };
4594
4594
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
4595
4595
  if (search) {
4596
4596
  query.$text = { $search: search };
@@ -4600,7 +4600,7 @@ function useOrgRepo() {
4600
4600
  page,
4601
4601
  limit,
4602
4602
  sort: JSON.stringify(sort),
4603
- status
4603
+ status: status2
4604
4604
  });
4605
4605
  logger14.log({
4606
4606
  level: "info",
@@ -4825,11 +4825,11 @@ function useOrgRepo() {
4825
4825
  throw new InternalServerError11("Failed to update org info.");
4826
4826
  }
4827
4827
  }
4828
- async function updateStatusById(_id, status, session) {
4828
+ async function updateStatusById(_id, status2, session) {
4829
4829
  const allowedStatuses = ["active", "suspended", "inactive"];
4830
- if (!allowedStatuses.includes(status)) {
4830
+ if (!allowedStatuses.includes(status2)) {
4831
4831
  throw new BadRequestError21(
4832
- `Status "${status}" is not a valid organization status.`
4832
+ `Status "${status2}" is not a valid organization status.`
4833
4833
  );
4834
4834
  }
4835
4835
  try {
@@ -4840,11 +4840,11 @@ function useOrgRepo() {
4840
4840
  try {
4841
4841
  await collection.updateOne(
4842
4842
  { _id },
4843
- { $set: { status, updatedAt: /* @__PURE__ */ new Date() } },
4843
+ { $set: { status: status2, updatedAt: /* @__PURE__ */ new Date() } },
4844
4844
  { session }
4845
4845
  );
4846
4846
  delCachedData();
4847
- return `Successfully updated organization status to ${status}.`;
4847
+ return `Successfully updated organization status to ${status2}.`;
4848
4848
  } catch (error) {
4849
4849
  throw new InternalServerError11("Failed to update organization status.");
4850
4850
  }
@@ -5292,7 +5292,7 @@ function useMemberController() {
5292
5292
  const user = req.query.user ?? "";
5293
5293
  const org = req.query.org ?? "";
5294
5294
  const app = req.params.app ?? "";
5295
- const status = req.query.status ?? "active";
5295
+ const status2 = req.query.status ?? "active";
5296
5296
  const validation = Joi19.object({
5297
5297
  limit: Joi19.number().min(10).max(50).required(),
5298
5298
  search: Joi19.string().optional().allow("", null),
@@ -5309,7 +5309,7 @@ function useMemberController() {
5309
5309
  org,
5310
5310
  app,
5311
5311
  limit,
5312
- status
5312
+ status: status2
5313
5313
  });
5314
5314
  if (error) {
5315
5315
  next(new BadRequestError25(error.message));
@@ -5323,7 +5323,7 @@ function useMemberController() {
5323
5323
  org,
5324
5324
  app,
5325
5325
  limit,
5326
- status
5326
+ status: status2
5327
5327
  });
5328
5328
  res.json(items);
5329
5329
  return;
@@ -5413,9 +5413,9 @@ function useMemberController() {
5413
5413
  return;
5414
5414
  }
5415
5415
  const id = req.params.id;
5416
- const status = req.params.status;
5416
+ const status2 = req.params.status;
5417
5417
  try {
5418
- const message = await _updateStatusByUserId(id, status);
5418
+ const message = await _updateStatusByUserId(id, status2);
5419
5419
  res.json({ message });
5420
5420
  } catch (error2) {
5421
5421
  next(error2);
@@ -5637,15 +5637,15 @@ function useSubscriptionRepo() {
5637
5637
  page = 1,
5638
5638
  limit = 10,
5639
5639
  search = "",
5640
- status = "active"
5640
+ status: status2 = "active"
5641
5641
  } = {}) {
5642
5642
  page = page > 0 ? page - 1 : page;
5643
- const query = { status };
5643
+ const query = { status: status2 };
5644
5644
  const cacheKeyOptions = {
5645
5645
  page,
5646
5646
  limit,
5647
5647
  search,
5648
- status,
5648
+ status: status2,
5649
5649
  tag: "getAll"
5650
5650
  };
5651
5651
  if (search) {
@@ -5763,12 +5763,12 @@ function useSubscriptionRepo() {
5763
5763
  throw new InternalServerError15("Failed to get subscription.");
5764
5764
  }
5765
5765
  }
5766
- async function getByStatus(status = "active", limit = 100, retry = 3) {
5766
+ async function getByStatus(status2 = "active", limit = 100, retry = 3) {
5767
5767
  const validation = Joi21.object({
5768
5768
  status: Joi21.string().valid("active", "due", "overdue").required().default("active"),
5769
5769
  limit: Joi21.number().integer().min(1).max(250).default(100)
5770
5770
  });
5771
- const { error, value } = validation.validate({ status, limit });
5771
+ const { error, value } = validation.validate({ status: status2, limit });
5772
5772
  if (error) {
5773
5773
  throw new BadRequestError27(`Invalid parameters: ${error.message}`);
5774
5774
  }
@@ -5913,12 +5913,12 @@ function useSubscriptionRepo() {
5913
5913
  throw new InternalServerError15("Failed to update subscription.");
5914
5914
  }
5915
5915
  }
5916
- async function updateStatusById(_id, status, session) {
5916
+ async function updateStatusById(_id, status2, session) {
5917
5917
  const validate = Joi21.object({
5918
5918
  _id: Joi21.string().hex().length(24).required(),
5919
5919
  status: Joi21.string().valid("active", "due", "overdue", "suspended").required()
5920
5920
  });
5921
- const { error } = validate.validate({ _id, status });
5921
+ const { error } = validate.validate({ _id, status: status2 });
5922
5922
  if (error) {
5923
5923
  throw new BadRequestError27(`Invalid parameters: ${error.message}`);
5924
5924
  }
@@ -5930,7 +5930,7 @@ function useSubscriptionRepo() {
5930
5930
  try {
5931
5931
  const result = await collection.updateOne(
5932
5932
  { _id },
5933
- { $set: { status, updatedAt: /* @__PURE__ */ new Date() } },
5933
+ { $set: { status: status2, updatedAt: /* @__PURE__ */ new Date() } },
5934
5934
  { session }
5935
5935
  );
5936
5936
  if (result.modifiedCount === 0) {
@@ -6364,7 +6364,7 @@ function useLedgerBillingRepo() {
6364
6364
  search = "",
6365
6365
  page = 1,
6366
6366
  limit = 10,
6367
- status = ""
6367
+ status: status2 = ""
6368
6368
  } = {}) {
6369
6369
  page = page > 0 ? page - 1 : 0;
6370
6370
  const query = { status: { $ne: "deleted" } };
@@ -6380,9 +6380,9 @@ function useLedgerBillingRepo() {
6380
6380
  } catch (error) {
6381
6381
  throw new BadRequestError30("Invalid organization ID.");
6382
6382
  }
6383
- if (status) {
6384
- query.status = status;
6385
- cacheKeyOptions.status = status;
6383
+ if (status2) {
6384
+ query.status = status2;
6385
+ cacheKeyOptions.status = status2;
6386
6386
  }
6387
6387
  if (search) {
6388
6388
  query.$text = { $search: search };
@@ -6498,11 +6498,11 @@ function useLedgerBillingRepo() {
6498
6498
  throw new InternalServerError17("Failed to get ledger billing by invoice.");
6499
6499
  }
6500
6500
  }
6501
- async function updateStatusById(_id, status, session) {
6501
+ async function updateStatusById(_id, status2, session) {
6502
6502
  const { error } = Joi24.object({
6503
6503
  _id: Joi24.string().hex().length(24).required(),
6504
6504
  status: Joi24.string().valid("pending", "paid", "overdue", "deleted").required()
6505
- }).validate({ _id, status });
6505
+ }).validate({ _id, status: status2 });
6506
6506
  if (error) {
6507
6507
  throw new Error(`Invalid ledger billing ID: ${error.message}`);
6508
6508
  }
@@ -6514,7 +6514,7 @@ function useLedgerBillingRepo() {
6514
6514
  try {
6515
6515
  const result = await collection.updateOne(
6516
6516
  { _id },
6517
- { $set: { status } },
6517
+ { $set: { status: status2 } },
6518
6518
  { session }
6519
6519
  );
6520
6520
  delCachedData();
@@ -6525,8 +6525,8 @@ function useLedgerBillingRepo() {
6525
6525
  );
6526
6526
  }
6527
6527
  }
6528
- async function getSummary(status, org) {
6529
- const { error } = schemaLedgerBillingSummary.validate({ status, org });
6528
+ async function getSummary(status2, org) {
6529
+ const { error } = schemaLedgerBillingSummary.validate({ status: status2, org });
6530
6530
  if (error) {
6531
6531
  throw new Error(`Invalid ledger billing ID: ${error.message}`);
6532
6532
  }
@@ -6538,7 +6538,7 @@ function useLedgerBillingRepo() {
6538
6538
  try {
6539
6539
  const cacheKey = makeCacheKey12(namespace_collection, {
6540
6540
  org: String(org),
6541
- status,
6541
+ status: status2,
6542
6542
  tag: "getSummaryByOrgStatus"
6543
6543
  });
6544
6544
  const cachedData = await getCache(cacheKey);
@@ -6546,7 +6546,7 @@ function useLedgerBillingRepo() {
6546
6546
  return cachedData;
6547
6547
  }
6548
6548
  const data = await collection.aggregate([
6549
- { $match: { org, status } },
6549
+ { $match: { org, status: status2 } },
6550
6550
  {
6551
6551
  $group: {
6552
6552
  _id: "$status",
@@ -6606,7 +6606,7 @@ function useLedgerBillingController() {
6606
6606
  const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
6607
6607
  const search = req.query.search ?? "";
6608
6608
  const org = req.query.org ?? "";
6609
- const status = req.query.status ?? "";
6609
+ const status2 = req.query.status ?? "";
6610
6610
  const isPageNumber = isFinite(page);
6611
6611
  if (!isPageNumber) {
6612
6612
  next(new BadRequestError31("Invalid page number."));
@@ -6622,7 +6622,7 @@ function useLedgerBillingController() {
6622
6622
  return;
6623
6623
  }
6624
6624
  try {
6625
- const orgs = await _getAll({ org, page, limit, search, status });
6625
+ const orgs = await _getAll({ org, page, limit, search, status: status2 });
6626
6626
  res.json(orgs);
6627
6627
  return;
6628
6628
  } catch (error2) {
@@ -6651,13 +6651,13 @@ function useLedgerBillingController() {
6651
6651
  const params = req.params;
6652
6652
  const { error } = schemaLedgerBillingSummary.validate(params);
6653
6653
  const org = req.params.org ?? "";
6654
- const status = req.params.status ?? "";
6654
+ const status2 = req.params.status ?? "";
6655
6655
  if (error) {
6656
6656
  next(new BadRequestError31(error.message));
6657
6657
  return;
6658
6658
  }
6659
6659
  try {
6660
- const summary = await _getSummary(status, org);
6660
+ const summary = await _getSummary(status2, org);
6661
6661
  res.json(summary);
6662
6662
  return;
6663
6663
  } catch (error2) {
@@ -7344,15 +7344,15 @@ function usePlanRepo() {
7344
7344
  page = 1,
7345
7345
  limit = 10,
7346
7346
  search = "",
7347
- status = "active"
7347
+ status: status2 = "active"
7348
7348
  } = {}) {
7349
7349
  page = page < 1 ? page - 1 : page;
7350
- const query = { status };
7350
+ const query = { status: status2 };
7351
7351
  const cacheKeyOptions = {
7352
7352
  page,
7353
7353
  limit,
7354
7354
  search,
7355
- status,
7355
+ status: status2,
7356
7356
  tag: "getAll"
7357
7357
  };
7358
7358
  if (search) {
@@ -7550,7 +7550,7 @@ function usePlanController() {
7550
7550
  }
7551
7551
  }
7552
7552
  async function getAll(req, res, next) {
7553
- const status = req.query.status ?? "active";
7553
+ const status2 = req.query.status ?? "active";
7554
7554
  const search = req.query.search ?? "";
7555
7555
  const page = Number(req.query.page) ?? 1;
7556
7556
  const limit = Number(req.query.limit) ?? 10;
@@ -7560,13 +7560,13 @@ function usePlanController() {
7560
7560
  page: Joi31.number().required(),
7561
7561
  limit: Joi31.number().required()
7562
7562
  });
7563
- const { error } = validation.validate({ status, search, page, limit });
7563
+ const { error } = validation.validate({ status: status2, search, page, limit });
7564
7564
  if (error) {
7565
7565
  next(new BadRequestError35(error.message));
7566
7566
  return;
7567
7567
  }
7568
7568
  try {
7569
- const plans = await _getAll({ status, search, page, limit });
7569
+ const plans = await _getAll({ status: status2, search, page, limit });
7570
7570
  res.json(plans);
7571
7571
  return;
7572
7572
  } catch (error2) {
@@ -7748,15 +7748,15 @@ function usePromoRepo() {
7748
7748
  page = 1,
7749
7749
  limit = 10,
7750
7750
  search = "",
7751
- status = "active"
7751
+ status: status2 = "active"
7752
7752
  } = {}) {
7753
7753
  page = page > 0 ? page - 1 : page;
7754
- const query = { status };
7754
+ const query = { status: status2 };
7755
7755
  const cacheKeyOptions = {
7756
7756
  page,
7757
7757
  limit,
7758
7758
  search,
7759
- status,
7759
+ status: status2,
7760
7760
  tag: "getAll"
7761
7761
  };
7762
7762
  if (search) {
@@ -8253,7 +8253,7 @@ function usePromoUsageRepo() {
8253
8253
  throw new InternalServerError21("Failed to count promo usages.");
8254
8254
  }
8255
8255
  }
8256
- async function updateStatusByOrgId(orgId, status, session) {
8256
+ async function updateStatusByOrgId(orgId, status2, session) {
8257
8257
  const { error } = Joi35.string().hex().length(24).required().validate(orgId);
8258
8258
  if (error) {
8259
8259
  throw new BadRequestError38(`Invalid org ID: ${error.message}`);
@@ -8266,7 +8266,7 @@ function usePromoUsageRepo() {
8266
8266
  try {
8267
8267
  await collection.updateMany(
8268
8268
  { org: orgId, status: "active" },
8269
- { $set: { status, updatedAt: /* @__PURE__ */ new Date() } },
8269
+ { $set: { status: status2, updatedAt: /* @__PURE__ */ new Date() } },
8270
8270
  { session }
8271
8271
  );
8272
8272
  delCachedData();
@@ -8361,7 +8361,7 @@ function usePromoController() {
8361
8361
  }
8362
8362
  }
8363
8363
  async function getAll(req, res, next) {
8364
- const status = req.query.status ?? "active";
8364
+ const status2 = req.query.status ?? "active";
8365
8365
  const search = req.query.search ?? "";
8366
8366
  const page = Number(req.query.page) ?? 1;
8367
8367
  const limit = Number(req.query.limit) ?? 10;
@@ -8371,13 +8371,13 @@ function usePromoController() {
8371
8371
  page: Joi36.number().required(),
8372
8372
  limit: Joi36.number().required()
8373
8373
  });
8374
- const { error } = validation.validate({ status, search, page, limit });
8374
+ const { error } = validation.validate({ status: status2, search, page, limit });
8375
8375
  if (error) {
8376
8376
  next(new BadRequestError40(error.message));
8377
8377
  return;
8378
8378
  }
8379
8379
  try {
8380
- const promos = await _getAll({ status, search, page, limit });
8380
+ const promos = await _getAll({ status: status2, search, page, limit });
8381
8381
  res.json(promos);
8382
8382
  return;
8383
8383
  } catch (error2) {
@@ -9459,7 +9459,7 @@ function useVerificationController() {
9459
9459
  next(new BadRequestError44(error.message));
9460
9460
  return;
9461
9461
  }
9462
- const status = req.query.status ?? "";
9462
+ const status2 = req.query.status ?? "";
9463
9463
  const search = req.query.search ?? "";
9464
9464
  const page = Number(req.query.page) ?? 1;
9465
9465
  let type = req.query.type ?? "";
@@ -9473,7 +9473,7 @@ function useVerificationController() {
9473
9473
  }
9474
9474
  try {
9475
9475
  const items = await _getVerifications({
9476
- status,
9476
+ status: status2,
9477
9477
  search,
9478
9478
  page,
9479
9479
  type: hasMultipleTypes ? splitType : type,
@@ -10118,7 +10118,7 @@ function useOrgController() {
10118
10118
  const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
10119
10119
  const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
10120
10120
  const search = req.query.search ?? "";
10121
- const status = req.query.status ?? "active";
10121
+ const status2 = req.query.status ?? "active";
10122
10122
  const isPageNumber = isFinite(page);
10123
10123
  if (!isPageNumber) {
10124
10124
  next(new BadRequestError46("Invalid page number."));
@@ -10134,7 +10134,7 @@ function useOrgController() {
10134
10134
  return;
10135
10135
  }
10136
10136
  try {
10137
- const orgs = await getAllOrg({ page, limit, search, status });
10137
+ const orgs = await getAllOrg({ page, limit, search, status: status2 });
10138
10138
  res.json(orgs);
10139
10139
  return;
10140
10140
  } catch (error2) {
@@ -10620,7 +10620,7 @@ function useUserController() {
10620
10620
  } = useUserService();
10621
10621
  const { getUserById: _getUserById, getAll: _getAll } = useUserRepo();
10622
10622
  async function getAll(req, res, next) {
10623
- const status = req.query.status ?? "";
10623
+ const status2 = req.query.status ?? "";
10624
10624
  const search = req.query.search ?? "";
10625
10625
  const page = Number(req.query.page) ?? 1;
10626
10626
  const validation = Joi43.object({
@@ -10628,13 +10628,13 @@ function useUserController() {
10628
10628
  search: Joi43.string().optional().allow("", null),
10629
10629
  page: Joi43.number().required()
10630
10630
  });
10631
- const { error } = validation.validate({ status, search, page });
10631
+ const { error } = validation.validate({ status: status2, search, page });
10632
10632
  if (error) {
10633
10633
  next(new BadRequestError48(error.message));
10634
10634
  return;
10635
10635
  }
10636
10636
  try {
10637
- const items = await _getAll({ status, search, page });
10637
+ const items = await _getAll({ status: status2, search, page });
10638
10638
  res.json(items);
10639
10639
  return;
10640
10640
  } catch (error2) {
@@ -10976,7 +10976,7 @@ function useVerificationService() {
10976
10976
  async function getVerifications({
10977
10977
  search = "",
10978
10978
  page = 1,
10979
- status = "",
10979
+ status: status2 = "",
10980
10980
  type = "",
10981
10981
  email = "",
10982
10982
  limit = 10,
@@ -10986,7 +10986,7 @@ function useVerificationService() {
10986
10986
  return await _getVerifications({
10987
10987
  search,
10988
10988
  page,
10989
- status,
10989
+ status: status2,
10990
10990
  type,
10991
10991
  limit,
10992
10992
  email,
@@ -10996,28 +10996,28 @@ function useVerificationService() {
10996
10996
  throw error;
10997
10997
  }
10998
10998
  }
10999
- function errorByType(type, status) {
11000
- if (type === "user-invite" && status === "expired") {
10999
+ function errorByType(type, status2) {
11000
+ if (type === "user-invite" && status2 === "expired") {
11001
11001
  throw new BadRequestError49(
11002
11002
  "Invitation has already expired, please contact admin to resend the invitation."
11003
11003
  );
11004
11004
  }
11005
- if (type === "user-sign-up" && status === "expired") {
11005
+ if (type === "user-sign-up" && status2 === "expired") {
11006
11006
  throw new BadRequestError49(
11007
11007
  "Sign up verification has expired, please sign up again to get a new verification link."
11008
11008
  );
11009
11009
  }
11010
- if (type === "user-invite" && status === "complete") {
11010
+ if (type === "user-invite" && status2 === "complete") {
11011
11011
  throw new BadRequestError49(
11012
11012
  "User already registered, please login to continue."
11013
11013
  );
11014
11014
  }
11015
- if (type === "forget-password" && status === "complete") {
11015
+ if (type === "forget-password" && status2 === "complete") {
11016
11016
  throw new BadRequestError49(
11017
11017
  "Forget password verification has already been used, please request a new one."
11018
11018
  );
11019
11019
  }
11020
- if (type === "forget-password" && status === "expired") {
11020
+ if (type === "forget-password" && status2 === "expired") {
11021
11021
  throw new BadRequestError49(
11022
11022
  "Forget password verification has expired, please request a new one."
11023
11023
  );
@@ -11100,9 +11100,9 @@ function useVerificationService() {
11100
11100
  );
11101
11101
  }
11102
11102
  }
11103
- async function updateStatusById(_id, status) {
11103
+ async function updateStatusById(_id, status2) {
11104
11104
  try {
11105
- await _updateStatusById(_id, status);
11105
+ await _updateStatusById(_id, status2);
11106
11106
  return "Successfully updated verification status.";
11107
11107
  } catch (error) {
11108
11108
  throw error;
@@ -11747,11 +11747,11 @@ function useBuildingRepo() {
11747
11747
  limit = 10,
11748
11748
  sort = {},
11749
11749
  school = "",
11750
- status = "active"
11750
+ status: status2 = "active"
11751
11751
  } = {}) {
11752
11752
  page = page > 0 ? page - 1 : 0;
11753
11753
  const query = {
11754
- status
11754
+ status: status2
11755
11755
  };
11756
11756
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
11757
11757
  if (search) {
@@ -11773,8 +11773,8 @@ function useBuildingRepo() {
11773
11773
  cacheParams.search = search;
11774
11774
  if (school)
11775
11775
  cacheParams.school = school;
11776
- if (status !== "active")
11777
- cacheParams.status = status;
11776
+ if (status2 !== "active")
11777
+ cacheParams.status = status2;
11778
11778
  const cacheKey = makeCacheKey17(namespace_collection, cacheParams);
11779
11779
  logger29.log({
11780
11780
  level: "info",
@@ -12047,12 +12047,12 @@ function useBuildingUnitRepo() {
12047
12047
  sort = {},
12048
12048
  school = "",
12049
12049
  building = "",
12050
- status = "active"
12050
+ status: status2 = "active"
12051
12051
  } = {}) {
12052
12052
  page = page > 0 ? page - 1 : 0;
12053
12053
  const query = {
12054
12054
  deletedAt: { $in: ["", null] },
12055
- status: { $in: [status, "", null] }
12055
+ status: { $in: [status2, "", null] }
12056
12056
  };
12057
12057
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
12058
12058
  if (search) {
@@ -12083,8 +12083,8 @@ function useBuildingUnitRepo() {
12083
12083
  cacheParams.school = school;
12084
12084
  if (building)
12085
12085
  cacheParams.building = building;
12086
- if (status !== "active")
12087
- cacheParams.status = status;
12086
+ if (status2 !== "active")
12087
+ cacheParams.status = status2;
12088
12088
  const cacheKey = makeCacheKey18(namespace_collection, cacheParams);
12089
12089
  logger30.log({
12090
12090
  level: "info",
@@ -12429,7 +12429,7 @@ function useBuildingController() {
12429
12429
  sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
12430
12430
  });
12431
12431
  }
12432
- const status = req.query.status ?? "active";
12432
+ const status2 = req.query.status ?? "active";
12433
12433
  const school = req.query.school ?? "";
12434
12434
  const search = req.query.search ?? "";
12435
12435
  try {
@@ -12437,7 +12437,7 @@ function useBuildingController() {
12437
12437
  page,
12438
12438
  limit,
12439
12439
  sort: sortObj,
12440
- status,
12440
+ status: status2,
12441
12441
  school,
12442
12442
  search
12443
12443
  });
@@ -12620,7 +12620,7 @@ function useBuildingUnitController() {
12620
12620
  sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
12621
12621
  });
12622
12622
  }
12623
- const status = req.query.status ?? "active";
12623
+ const status2 = req.query.status ?? "active";
12624
12624
  const school = req.query.school ?? "";
12625
12625
  const building = req.query.building ?? "";
12626
12626
  const search = req.query.search ?? "";
@@ -12629,7 +12629,7 @@ function useBuildingUnitController() {
12629
12629
  page,
12630
12630
  limit,
12631
12631
  sort: sortObj,
12632
- status,
12632
+ status: status2,
12633
12633
  school,
12634
12634
  search,
12635
12635
  building
@@ -13127,10 +13127,10 @@ function useJobPostRepo() {
13127
13127
  search = "",
13128
13128
  page = 1,
13129
13129
  limit = 10,
13130
- status = "active"
13130
+ status: status2 = "active"
13131
13131
  } = {}) {
13132
13132
  page = page > 0 ? page - 1 : 0;
13133
- const query = { status };
13133
+ const query = { status: status2 };
13134
13134
  if (search) {
13135
13135
  query.$text = { $search: search };
13136
13136
  }
@@ -13138,7 +13138,7 @@ function useJobPostRepo() {
13138
13138
  search,
13139
13139
  page,
13140
13140
  limit,
13141
- status
13141
+ status: status2
13142
13142
  });
13143
13143
  logger34.log({
13144
13144
  level: "info",
@@ -13196,17 +13196,17 @@ function useJobPostRepo() {
13196
13196
  throw error;
13197
13197
  }
13198
13198
  }
13199
- async function getJobPostsByOrg({ search = "", page = 1, limit = 10, org = "", status = "active" } = {}) {
13199
+ async function getJobPostsByOrg({ search = "", page = 1, limit = 10, org = "", status: status2 = "active" } = {}) {
13200
13200
  page = page > 0 ? page - 1 : 0;
13201
13201
  try {
13202
13202
  org = new ObjectId30(org);
13203
13203
  } catch (error) {
13204
13204
  throw new BadRequestError60("Invalid organization ID.");
13205
13205
  }
13206
- const query = { org, status };
13206
+ const query = { org, status: status2 };
13207
13207
  const cacheKeyOptions = {
13208
13208
  org: String(org),
13209
- status,
13209
+ status: status2,
13210
13210
  limit,
13211
13211
  page
13212
13212
  };
@@ -13346,7 +13346,7 @@ function useJobPostRepo() {
13346
13346
  throw new InternalServerError31("Failed to delete job post.");
13347
13347
  }
13348
13348
  }
13349
- async function updateStatusById(_id, status) {
13349
+ async function updateStatusById(_id, status2) {
13350
13350
  try {
13351
13351
  _id = new ObjectId30(_id);
13352
13352
  } catch (error) {
@@ -13357,7 +13357,7 @@ function useJobPostRepo() {
13357
13357
  { _id },
13358
13358
  {
13359
13359
  $set: {
13360
- status,
13360
+ status: status2,
13361
13361
  updatedAt: /* @__PURE__ */ new Date()
13362
13362
  }
13363
13363
  }
@@ -13722,7 +13722,7 @@ function useJobPostController() {
13722
13722
  const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
13723
13723
  const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
13724
13724
  const search = req.query.search ?? "";
13725
- const status = req.query.status ?? "open";
13725
+ const status2 = req.query.status ?? "open";
13726
13726
  const isPageNumber = isFinite(page);
13727
13727
  if (!isPageNumber) {
13728
13728
  next(new BadRequestError64("Invalid page number."));
@@ -13738,7 +13738,7 @@ function useJobPostController() {
13738
13738
  return;
13739
13739
  }
13740
13740
  try {
13741
- const jobPosts = await _getAll({ page, limit, search, status });
13741
+ const jobPosts = await _getAll({ page, limit, search, status: status2 });
13742
13742
  res.json(jobPosts);
13743
13743
  return;
13744
13744
  } catch (error2) {
@@ -13749,7 +13749,7 @@ function useJobPostController() {
13749
13749
  const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
13750
13750
  const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
13751
13751
  const search = req.query.search ?? "";
13752
- const status = req.query.status ?? "active";
13752
+ const status2 = req.query.status ?? "active";
13753
13753
  const org = req.params.org ?? "";
13754
13754
  const isPageNumber = isFinite(page);
13755
13755
  if (!isPageNumber) {
@@ -13768,7 +13768,7 @@ function useJobPostController() {
13768
13768
  search: Joi53.string().optional().allow("", null),
13769
13769
  status: Joi53.string().optional()
13770
13770
  });
13771
- const { error } = validation.validate({ org, page, limit, search, status });
13771
+ const { error } = validation.validate({ org, page, limit, search, status: status2 });
13772
13772
  if (error) {
13773
13773
  next(new BadRequestError64(error.message));
13774
13774
  return;
@@ -13779,7 +13779,7 @@ function useJobPostController() {
13779
13779
  page,
13780
13780
  limit,
13781
13781
  search,
13782
- status
13782
+ status: status2
13783
13783
  });
13784
13784
  res.json(jobPosts);
13785
13785
  return;
@@ -13837,18 +13837,18 @@ function useJobPostController() {
13837
13837
  }
13838
13838
  async function updateStatusById(req, res, next) {
13839
13839
  const id = req.params.id;
13840
- const status = req.params.status;
13840
+ const status2 = req.params.status;
13841
13841
  const validation = Joi53.object({
13842
13842
  id: Joi53.string().hex().required(),
13843
13843
  status: Joi53.string().valid("draft", "open", "paused", "in-review", "closed").required()
13844
13844
  });
13845
- const { error } = validation.validate({ id, status });
13845
+ const { error } = validation.validate({ id, status: status2 });
13846
13846
  if (error) {
13847
13847
  next(new BadRequestError64(error.message));
13848
13848
  return;
13849
13849
  }
13850
13850
  try {
13851
- const message = await _updateStatusById(id, status);
13851
+ const message = await _updateStatusById(id, status2);
13852
13852
  res.json({ message });
13853
13853
  return;
13854
13854
  } catch (error2) {
@@ -14032,6 +14032,11 @@ function modelJobApplication(data) {
14032
14032
  } catch (error2) {
14033
14033
  throw new BadRequestError65(`Invalid job application post id: ${data.post}`);
14034
14034
  }
14035
+ try {
14036
+ data.user = new ObjectId32(data.user);
14037
+ } catch (error2) {
14038
+ throw new BadRequestError65(`Invalid job application user id: ${data.user}`);
14039
+ }
14035
14040
  if (data.company && typeof data.company === "string") {
14036
14041
  try {
14037
14042
  data.company = new ObjectId32(data.company);
@@ -14070,6 +14075,8 @@ import {
14070
14075
  useAtlas as useAtlas31,
14071
14076
  useCache as useCache23
14072
14077
  } from "@goweekdays/utils";
14078
+ import { ObjectId as ObjectId33 } from "mongodb";
14079
+ import Joi55 from "joi";
14073
14080
  function useJobApplicationRepo() {
14074
14081
  const db = useAtlas31.getDb();
14075
14082
  if (!db) {
@@ -14141,14 +14148,14 @@ function useJobApplicationRepo() {
14141
14148
  page = 1,
14142
14149
  limit = 10,
14143
14150
  search = "",
14144
- status = "new"
14151
+ status: status2 = "new"
14145
14152
  } = {}) {
14146
14153
  page = page > 0 ? page - 1 : 0;
14147
- const query = { status };
14154
+ const query = { status: status2 };
14148
14155
  const cacheKeyOptions = {
14149
14156
  page,
14150
14157
  limit,
14151
- status,
14158
+ status: status2,
14152
14159
  tag: "getAll"
14153
14160
  };
14154
14161
  if (search) {
@@ -14189,24 +14196,142 @@ function useJobApplicationRepo() {
14189
14196
  );
14190
14197
  }
14191
14198
  }
14199
+ async function getById(_id) {
14200
+ const { error } = Joi55.string().hex().length(24).validate(_id);
14201
+ if (error) {
14202
+ throw new BadRequestError66(`Invalid job application id: ${_id}`);
14203
+ }
14204
+ try {
14205
+ _id = new ObjectId33(_id);
14206
+ } catch (error2) {
14207
+ throw new BadRequestError66(`Invalid job application id: ${_id}`);
14208
+ }
14209
+ try {
14210
+ const cacheKey = makeCacheKey22(namespace_collection, {
14211
+ _id,
14212
+ tag: "getById"
14213
+ });
14214
+ const cachedData = await getCache(cacheKey);
14215
+ if (cachedData) {
14216
+ return cachedData;
14217
+ }
14218
+ const data = await collection.findOne({ _id });
14219
+ setCache(cacheKey, data).then(() => {
14220
+ logger37.log({
14221
+ level: "info",
14222
+ message: `Cache set for getById job application: ${cacheKey}`
14223
+ });
14224
+ }).catch((err) => {
14225
+ logger37.log({
14226
+ level: "error",
14227
+ message: `Failed to set cache for getById job application: ${cacheKey}, error: ${err.message}`
14228
+ });
14229
+ });
14230
+ return data;
14231
+ } catch (error2) {
14232
+ if (error2 instanceof AppError32) {
14233
+ throw error2;
14234
+ }
14235
+ throw new BadRequestError66(
14236
+ `Failed to get job application: ${error2.message}`
14237
+ );
14238
+ }
14239
+ }
14240
+ async function updateStatusById(_id, status2, session) {
14241
+ const { error } = Joi55.object({
14242
+ _id: Joi55.string().hex().length(24).required(),
14243
+ status: Joi55.string().valid(...jobApplicationStatuses).required()
14244
+ }).validate({ _id, status: status2 });
14245
+ if (error) {
14246
+ throw new BadRequestError66(`Invalid job application id: ${_id}`);
14247
+ }
14248
+ try {
14249
+ _id = new ObjectId33(_id);
14250
+ } catch (error2) {
14251
+ throw new BadRequestError66(`Invalid job application id: ${_id}`);
14252
+ }
14253
+ try {
14254
+ await collection.updateOne(
14255
+ { _id },
14256
+ { $set: { status: status2, updatedAt: /* @__PURE__ */ new Date() } },
14257
+ { session }
14258
+ );
14259
+ delCachedData();
14260
+ return "Successfully updated job application status.";
14261
+ } catch (error2) {
14262
+ if (error2 instanceof AppError32) {
14263
+ throw error2;
14264
+ }
14265
+ throw new BadRequestError66(
14266
+ `Failed to update job application status: ${error2.message}`
14267
+ );
14268
+ }
14269
+ }
14192
14270
  return {
14193
14271
  createIndexes,
14194
14272
  delCachedData,
14195
14273
  add,
14196
- getAll
14274
+ getAll,
14275
+ getById,
14276
+ updateStatusById
14197
14277
  };
14198
14278
  }
14199
14279
 
14200
14280
  // src/resources/job-applications/job.application.controller.ts
14281
+ import { AppError as AppError34, BadRequestError as BadRequestError68 } from "@goweekdays/utils";
14282
+ import Joi57 from "joi";
14283
+
14284
+ // src/resources/job-applications/job.application.service.ts
14285
+ import Joi56 from "joi";
14201
14286
  import { AppError as AppError33, BadRequestError as BadRequestError67 } from "@goweekdays/utils";
14202
- import Joi55 from "joi";
14287
+ function useJobApplicationService() {
14288
+ const { getById, updateStatusById: _updateStatusById } = useJobApplicationRepo();
14289
+ async function updateStatusById(id, status2) {
14290
+ const { error } = Joi56.object({
14291
+ id: Joi56.string().hex().length(24).required(),
14292
+ status: Joi56.string().valid(...jobApplicationStatuses).required()
14293
+ }).validate({ id, status: status2 });
14294
+ if (error) {
14295
+ throw new BadRequestError67(`Invalid parameters: ${error.message}`);
14296
+ }
14297
+ try {
14298
+ const application = await getById(id);
14299
+ if (!application) {
14300
+ throw new BadRequestError67(`Job application not found with id: ${id}`);
14301
+ }
14302
+ if (application.status === status2) {
14303
+ throw new BadRequestError67(
14304
+ `Job application already has status: ${status2}`
14305
+ );
14306
+ }
14307
+ await _updateStatusById(id, status2);
14308
+ return `Successfully updated job application status to: ${status2}`;
14309
+ } catch (error2) {
14310
+ if (error2 instanceof AppError33) {
14311
+ throw error2;
14312
+ }
14313
+ throw new BadRequestError67(
14314
+ `Failed to update job application status: ${error2.message}`
14315
+ );
14316
+ }
14317
+ }
14318
+ return {
14319
+ updateStatusById
14320
+ };
14321
+ }
14322
+
14323
+ // src/resources/job-applications/job.application.controller.ts
14203
14324
  function useJobApplicationController() {
14204
- const { add: _add, getAll: _getAll } = useJobApplicationRepo();
14325
+ const {
14326
+ add: _add,
14327
+ getAll: _getAll,
14328
+ getById: _getById
14329
+ } = useJobApplicationRepo();
14205
14330
  async function add(req, res, next) {
14206
14331
  const { error } = schemaJobApplication.validate(req.body);
14207
14332
  if (error) {
14208
14333
  next(
14209
- new BadRequestError67(`Invalid job application data: ${error.message}`)
14334
+ new BadRequestError68(`Invalid job application data: ${error.message}`)
14210
14335
  );
14211
14336
  return;
14212
14337
  }
@@ -14215,50 +14340,1791 @@ function useJobApplicationController() {
14215
14340
  res.json({ message });
14216
14341
  return;
14217
14342
  } catch (error2) {
14218
- if (error2 instanceof AppError33) {
14343
+ if (error2 instanceof AppError34) {
14219
14344
  next(error2);
14220
14345
  return;
14221
14346
  }
14222
14347
  next(
14223
- new BadRequestError67(
14348
+ new BadRequestError68(
14224
14349
  `Failed to create job application: ${error2.message}`
14225
14350
  )
14226
14351
  );
14227
14352
  }
14228
14353
  }
14229
14354
  async function getAll(req, res, next) {
14230
- const validation = Joi55.object({
14231
- page: Joi55.number().integer().min(1).optional(),
14232
- limit: Joi55.number().integer().min(1).max(100).optional(),
14233
- search: Joi55.string().optional().allow(""),
14234
- status: Joi55.string().valid(...jobApplicationStatuses).optional()
14355
+ const validation = Joi57.object({
14356
+ page: Joi57.number().integer().min(1).optional(),
14357
+ limit: Joi57.number().integer().min(1).max(100).optional(),
14358
+ search: Joi57.string().optional().allow(""),
14359
+ status: Joi57.string().valid(...jobApplicationStatuses).optional()
14235
14360
  });
14236
14361
  const { error } = validation.validate(req.query);
14237
14362
  if (error) {
14238
- next(new BadRequestError67(`Invalid query parameters: ${error.message}`));
14363
+ next(new BadRequestError68(`Invalid query parameters: ${error.message}`));
14239
14364
  return;
14240
14365
  }
14241
14366
  const page = req.query.page ? parseInt(req.query.page) : 1;
14242
14367
  const limit = req.query.limit ? parseInt(req.query.limit) : 10;
14243
14368
  const search = req.query.search ? req.query.search : "";
14244
- const status = req.query.status ? req.query.status : "new";
14369
+ const status2 = req.query.status ? req.query.status : "new";
14245
14370
  try {
14246
- const data = await _getAll({ page, limit, search, status });
14371
+ const data = await _getAll({ page, limit, search, status: status2 });
14247
14372
  res.json(data);
14248
14373
  return;
14249
14374
  } catch (error2) {
14250
- if (error2 instanceof AppError33) {
14375
+ if (error2 instanceof AppError34) {
14376
+ next(error2);
14377
+ return;
14378
+ }
14379
+ next(
14380
+ new BadRequestError68(`Failed to get job applications: ${error2.message}`)
14381
+ );
14382
+ }
14383
+ }
14384
+ async function getById(req, res, next) {
14385
+ const id = req.params.id ?? "";
14386
+ const { error } = Joi57.string().hex().length(24).required().validate(id);
14387
+ if (error) {
14388
+ next(new BadRequestError68(`Invalid job application id: ${id}`));
14389
+ return;
14390
+ }
14391
+ try {
14392
+ const data = await _getById(id);
14393
+ res.json(data);
14394
+ return;
14395
+ } catch (error2) {
14396
+ if (error2 instanceof AppError34) {
14397
+ next(error2);
14398
+ return;
14399
+ }
14400
+ next(
14401
+ new BadRequestError68(`Failed to get job application: ${error2.message}`)
14402
+ );
14403
+ }
14404
+ }
14405
+ const { updateStatusById: _updateStatusById } = useJobApplicationService();
14406
+ async function updateStatusById(req, res, next) {
14407
+ const id = req.params.id ?? "";
14408
+ const status2 = req.body.status ?? "";
14409
+ const { error } = Joi57.object({
14410
+ id: Joi57.string().hex().length(24).required(),
14411
+ status: Joi57.string().valid(...jobApplicationStatuses).required()
14412
+ }).validate({ id, status: status2 });
14413
+ if (error) {
14414
+ next(new BadRequestError68(`Invalid parameters: ${error.message}`));
14415
+ return;
14416
+ }
14417
+ try {
14418
+ const message = await _updateStatusById(id, status2);
14419
+ res.json({ message });
14420
+ return;
14421
+ } catch (error2) {
14422
+ if (error2 instanceof AppError34) {
14251
14423
  next(error2);
14252
14424
  return;
14253
14425
  }
14254
14426
  next(
14255
- new BadRequestError67(`Failed to get job applications: ${error2.message}`)
14427
+ new BadRequestError68(
14428
+ `Failed to update job application status: ${error2.message}`
14429
+ )
14256
14430
  );
14257
14431
  }
14258
14432
  }
14259
14433
  return {
14260
14434
  add,
14261
- getAll
14435
+ getAll,
14436
+ getById,
14437
+ updateStatusById
14438
+ };
14439
+ }
14440
+
14441
+ // src/resources/job-profile/job.profile.model.ts
14442
+ import { BadRequestError as BadRequestError69 } from "@goweekdays/utils";
14443
+ import Joi58 from "joi";
14444
+ import { ObjectId as ObjectId34 } from "mongodb";
14445
+ var workExp = {
14446
+ id: Joi58.string().hex().length(24).optional().allow("", null),
14447
+ jobTitle: Joi58.string().required(),
14448
+ company: Joi58.string().required(),
14449
+ country: Joi58.string().required(),
14450
+ cityState: Joi58.string().optional().allow(""),
14451
+ fromMonth: Joi58.string().required(),
14452
+ fromYear: Joi58.string().required(),
14453
+ toMonth: Joi58.string().optional().allow(""),
14454
+ toYear: Joi58.string().optional().allow(""),
14455
+ currentlyWorking: Joi58.boolean().optional(),
14456
+ description: Joi58.string().optional().allow(""),
14457
+ additionalInfo: Joi58.string().optional().allow("")
14458
+ };
14459
+ var schemaWorkExp = Joi58.object(workExp);
14460
+ var education = {
14461
+ id: Joi58.string().hex().length(24).optional().allow("", null),
14462
+ levelOfEducation: Joi58.string().required(),
14463
+ fieldOfStudy: Joi58.string().required(),
14464
+ schoolName: Joi58.string().required(),
14465
+ country: Joi58.string().required(),
14466
+ location: Joi58.string().optional().allow(""),
14467
+ currentlyEnrolled: Joi58.boolean().optional(),
14468
+ fromMonth: Joi58.string().required(),
14469
+ fromYear: Joi58.string().required(),
14470
+ toMonth: Joi58.string().optional().allow(""),
14471
+ toYear: Joi58.string().optional().allow(""),
14472
+ additionalInfo: Joi58.string().optional().allow("")
14473
+ };
14474
+ var schemaEducation = Joi58.object(education);
14475
+ var certification = {
14476
+ id: Joi58.string().hex().length(24).optional().allow("", null),
14477
+ title: Joi58.string().required(),
14478
+ noExpiry: Joi58.boolean().required(),
14479
+ fromMonth: Joi58.string().required(),
14480
+ fromYear: Joi58.string().required(),
14481
+ toMonth: Joi58.string().optional().allow(""),
14482
+ toYear: Joi58.string().optional().allow(""),
14483
+ description: Joi58.string().optional().allow("")
14484
+ };
14485
+ var schemaCertification = Joi58.object(certification);
14486
+ var schemaJobProfileCert = Joi58.object({
14487
+ ...certification,
14488
+ _id: Joi58.string().hex().length(24).required()
14489
+ });
14490
+ var schemaJobProfileCertDel = Joi58.object({
14491
+ id: Joi58.string().hex().length(24).required(),
14492
+ certId: Joi58.string().hex().length(24).required()
14493
+ });
14494
+ var skill = {
14495
+ id: Joi58.string().hex().length(24).optional().allow("", null),
14496
+ name: Joi58.string().required(),
14497
+ proficiency: Joi58.string().optional().allow("", null)
14498
+ };
14499
+ var schemaSkill = Joi58.object(skill);
14500
+ var schemaAward = Joi58.object({
14501
+ title: Joi58.string().required(),
14502
+ fromMonth: Joi58.string().required(),
14503
+ fromYear: Joi58.string().required(),
14504
+ description: Joi58.string().optional().allow("")
14505
+ });
14506
+ var schemaGroup = Joi58.object({
14507
+ title: Joi58.string().required(),
14508
+ active: Joi58.boolean().required(),
14509
+ fromMonth: Joi58.string().required(),
14510
+ fromYear: Joi58.string().required(),
14511
+ toMonth: Joi58.string().optional().allow(""),
14512
+ toYear: Joi58.string().optional().allow(""),
14513
+ description: Joi58.string().optional().allow("")
14514
+ });
14515
+ var schemaLanguage = Joi58.object({
14516
+ id: Joi58.string().hex().length(24).optional().allow("", null),
14517
+ language: Joi58.string().required(),
14518
+ proficiency: Joi58.string().required()
14519
+ });
14520
+ var schemaMilitaryExp = Joi58.object({
14521
+ country: Joi58.string().required(),
14522
+ branch: Joi58.string().required(),
14523
+ rank: Joi58.string().required(),
14524
+ serving: Joi58.boolean().required(),
14525
+ fromMonth: Joi58.string().required(),
14526
+ fromYear: Joi58.string().required(),
14527
+ toMonth: Joi58.string().optional().allow(""),
14528
+ toYear: Joi58.string().optional().allow(""),
14529
+ description: Joi58.string().optional().allow(""),
14530
+ commendations: Joi58.string().optional().allow("")
14531
+ });
14532
+ var schemaPatent = Joi58.object({
14533
+ title: Joi58.string().required(),
14534
+ patentNumber: Joi58.string().required(),
14535
+ url: Joi58.string().uri().optional().allow(""),
14536
+ fromMonth: Joi58.string().required(),
14537
+ fromYear: Joi58.string().required(),
14538
+ description: Joi58.string().optional().allow("")
14539
+ });
14540
+ var schemaPublication = Joi58.object({
14541
+ title: Joi58.string().required(),
14542
+ url: Joi58.string().uri().optional().allow(""),
14543
+ fromMonth: Joi58.string().required(),
14544
+ fromYear: Joi58.string().required(),
14545
+ description: Joi58.string().optional().allow("")
14546
+ });
14547
+ var schemaJobProfile = Joi58.object({
14548
+ _id: Joi58.string().hex().optional(),
14549
+ user: Joi58.string().hex().required(),
14550
+ firstName: Joi58.string().required(),
14551
+ lastName: Joi58.string().required(),
14552
+ headline: Joi58.string().optional().allow(""),
14553
+ contact: Joi58.string().optional().allow(""),
14554
+ showContact: Joi58.boolean().optional(),
14555
+ email: Joi58.string().email().required(),
14556
+ verifiedEmail: Joi58.boolean().optional(),
14557
+ country: Joi58.string().required(),
14558
+ streetAddress: Joi58.string().optional().allow(""),
14559
+ cityState: Joi58.string().required(),
14560
+ postalCode: Joi58.string().optional().allow(""),
14561
+ citizenship: Joi58.string().optional().allow("")
14562
+ });
14563
+ var schemaJobProfileContactInfo = Joi58.object({
14564
+ id: Joi58.string().hex().length(24).required(),
14565
+ firstName: Joi58.string().optional().allow(""),
14566
+ lastName: Joi58.string().optional().allow(""),
14567
+ headline: Joi58.string().optional().allow(""),
14568
+ contact: Joi58.string().optional().allow(""),
14569
+ showContact: Joi58.boolean().optional(),
14570
+ country: Joi58.string().optional().allow(""),
14571
+ cityState: Joi58.string().optional().allow(""),
14572
+ streetAddress: Joi58.string().optional().allow(""),
14573
+ postalCode: Joi58.string().optional().allow(""),
14574
+ relocate: Joi58.boolean().optional()
14575
+ });
14576
+ var schemaJobProfileWorkExp = Joi58.object({
14577
+ ...workExp,
14578
+ _id: Joi58.string().hex().length(24).required()
14579
+ });
14580
+ var schemaJobProfilePersonalInfo = Joi58.object({
14581
+ id: Joi58.string().hex().length(24).required(),
14582
+ citizenship: Joi58.string().optional().allow("")
14583
+ });
14584
+ var schemaJobProfileSummary = Joi58.object({
14585
+ id: Joi58.string().hex().length(24).required(),
14586
+ summary: Joi58.string().max(5e3).optional().allow("")
14587
+ });
14588
+ var schemaJobProfileWorkExpDel = Joi58.object({
14589
+ id: Joi58.string().hex().length(24).required(),
14590
+ workExpId: Joi58.string().hex().length(24).required()
14591
+ });
14592
+ var schemaJobProfileEdu = Joi58.object({
14593
+ ...education,
14594
+ _id: Joi58.string().hex().length(24).required()
14595
+ });
14596
+ var schemaJobProfileEduDel = Joi58.object({
14597
+ id: Joi58.string().hex().length(24).required(),
14598
+ eduId: Joi58.string().hex().length(24).required()
14599
+ });
14600
+ var schemaJobProfileSkill = Joi58.object({
14601
+ ...skill,
14602
+ _id: Joi58.string().hex().length(24).required()
14603
+ });
14604
+ var schemaJobProfileSkillDel = Joi58.object({
14605
+ id: Joi58.string().hex().length(24).required(),
14606
+ skillId: Joi58.string().hex().length(24).required()
14607
+ });
14608
+ var language = {
14609
+ id: Joi58.string().hex().length(24).optional().allow("", null),
14610
+ language: Joi58.string().required(),
14611
+ proficiency: Joi58.string().required()
14612
+ };
14613
+ var schemaJobProfileLang = Joi58.object({
14614
+ ...language,
14615
+ _id: Joi58.string().hex().length(24).required()
14616
+ });
14617
+ var schemaJobProfileLangDel = Joi58.object({
14618
+ id: Joi58.string().hex().length(24).required(),
14619
+ langId: Joi58.string().hex().length(24).required()
14620
+ });
14621
+ var schemaJobProfileAdditionalInfo = Joi58.object({
14622
+ id: Joi58.string().hex().length(24).required(),
14623
+ additionalInfo: Joi58.string().max(5e3).optional().allow("")
14624
+ });
14625
+ function modelJobProfile(data) {
14626
+ const { error } = schemaJobProfile.validate(data);
14627
+ if (error) {
14628
+ throw new BadRequestError69(`Invalid job profile data: ${error.message}`);
14629
+ }
14630
+ try {
14631
+ data.user = new ObjectId34(data.user);
14632
+ } catch (error2) {
14633
+ throw new BadRequestError69(`Invalid job profile user id: ${data.user}`);
14634
+ }
14635
+ if (data._id && typeof data._id === "string") {
14636
+ try {
14637
+ data._id = new ObjectId34(data._id);
14638
+ } catch (error2) {
14639
+ throw new BadRequestError69(`Invalid job profile _id: ${data._id}`);
14640
+ }
14641
+ }
14642
+ return {
14643
+ _id: data._id,
14644
+ user: data.user,
14645
+ firstName: data.firstName,
14646
+ lastName: data.lastName,
14647
+ headline: data.headline ?? "",
14648
+ contact: data.contact ?? "",
14649
+ showContact: data.showContact ?? false,
14650
+ email: data.email,
14651
+ verifiedEmail: data.verifiedEmail ?? false,
14652
+ country: data.country,
14653
+ streetAddress: data.streetAddress ?? "",
14654
+ cityState: data.cityState,
14655
+ postalCode: data.postalCode ?? "",
14656
+ relocate: data.relocate,
14657
+ summary: data.summary ?? "",
14658
+ citizenship: data.citizenship ?? "",
14659
+ workExperience: data.workExperience ?? [],
14660
+ education: data.education ?? [],
14661
+ skills: data.skills ?? [],
14662
+ certifications: data.certifications ?? [],
14663
+ additionalInfo: data.additionalInfo ?? "",
14664
+ awards: data.awards ?? [],
14665
+ groups: data.groups ?? [],
14666
+ languages: data.languages ?? [],
14667
+ links: data.links ?? [],
14668
+ militaryExperience: data.militaryExperience,
14669
+ patents: data.patents ?? [],
14670
+ publications: data.publications ?? [],
14671
+ createdAt: data.createdAt ?? /* @__PURE__ */ new Date(),
14672
+ updatedAt: data.updatedAt ?? "",
14673
+ deletedAt: data.deletedAt ?? ""
14674
+ };
14675
+ }
14676
+ function modelJobProfileWorkExp(data) {
14677
+ const { error } = schemaWorkExp.validate(data);
14678
+ if (error) {
14679
+ throw new BadRequestError69(
14680
+ `Invalid job profile work experience data: ${error.message}`
14681
+ );
14682
+ }
14683
+ try {
14684
+ data.id = new ObjectId34(data.id);
14685
+ } catch (error2) {
14686
+ throw new BadRequestError69(
14687
+ `Invalid job profile work experience id: ${data.id}`
14688
+ );
14689
+ }
14690
+ return {
14691
+ id: data.id,
14692
+ jobTitle: data.jobTitle,
14693
+ company: data.company,
14694
+ country: data.country,
14695
+ cityState: data.cityState ?? "",
14696
+ fromMonth: data.fromMonth,
14697
+ fromYear: data.fromYear,
14698
+ toMonth: data.toMonth ?? "",
14699
+ toYear: data.toYear ?? "",
14700
+ currentlyWorking: data.currentlyWorking ?? false,
14701
+ description: data.description ?? "",
14702
+ additionalInfo: data.additionalInfo ?? ""
14703
+ };
14704
+ }
14705
+ function modelJobProfileEdu(data) {
14706
+ const { error } = schemaEducation.validate(data);
14707
+ if (error) {
14708
+ throw new BadRequestError69(
14709
+ `Invalid job profile education data: ${error.message}`
14710
+ );
14711
+ }
14712
+ try {
14713
+ data.id = new ObjectId34(data.id);
14714
+ } catch (error2) {
14715
+ throw new BadRequestError69(`Invalid job profile education id: ${data.id}`);
14716
+ }
14717
+ return {
14718
+ id: data.id,
14719
+ levelOfEducation: data.levelOfEducation,
14720
+ fieldOfStudy: data.fieldOfStudy,
14721
+ schoolName: data.schoolName,
14722
+ country: data.country,
14723
+ location: data.location ?? "",
14724
+ currentlyEnrolled: data.currentlyEnrolled ?? false,
14725
+ fromMonth: data.fromMonth,
14726
+ fromYear: data.fromYear,
14727
+ toMonth: data.toMonth ?? "",
14728
+ toYear: data.toYear ?? "",
14729
+ additionalInfo: data.additionalInfo ?? ""
14730
+ };
14731
+ }
14732
+ function modelJobProfileSkill(data) {
14733
+ const { error } = schemaSkill.validate(data);
14734
+ if (error) {
14735
+ throw new BadRequestError69(
14736
+ `Invalid job profile skill data: ${error.message}`
14737
+ );
14738
+ }
14739
+ try {
14740
+ data.id = new ObjectId34(data.id);
14741
+ } catch (error2) {
14742
+ throw new BadRequestError69(`Invalid job profile skill id: ${data.id}`);
14743
+ }
14744
+ return {
14745
+ id: data.id,
14746
+ name: data.name,
14747
+ proficiency: data.proficiency ?? ""
14748
+ };
14749
+ }
14750
+ function modelJobProfileLang(data) {
14751
+ const { error } = schemaLanguage.validate(data);
14752
+ if (error) {
14753
+ throw new BadRequestError69(
14754
+ `Invalid job profile language data: ${error.message}`
14755
+ );
14756
+ }
14757
+ try {
14758
+ data.id = new ObjectId34(data.id);
14759
+ } catch (error2) {
14760
+ throw new BadRequestError69(`Invalid job profile language id: ${data.id}`);
14761
+ }
14762
+ return {
14763
+ id: data.id,
14764
+ language: data.language,
14765
+ proficiency: data.proficiency
14766
+ };
14767
+ }
14768
+ function modelJobProfileCert(data) {
14769
+ const { error } = schemaCertification.validate(data);
14770
+ if (error) {
14771
+ throw new BadRequestError69(
14772
+ `Invalid job profile certification data: ${error.message}`
14773
+ );
14774
+ }
14775
+ try {
14776
+ data.id = new ObjectId34(data.id);
14777
+ } catch (error2) {
14778
+ throw new BadRequestError69(
14779
+ `Invalid job profile certification id: ${data.id}`
14780
+ );
14781
+ }
14782
+ return {
14783
+ id: data.id,
14784
+ title: data.title,
14785
+ noExpiry: data.noExpiry,
14786
+ fromMonth: data.fromMonth,
14787
+ fromYear: data.fromYear,
14788
+ toMonth: data.toMonth ?? "",
14789
+ toYear: data.toYear ?? "",
14790
+ description: data.description ?? ""
14791
+ };
14792
+ }
14793
+
14794
+ // src/resources/job-profile/job.profile.repository.ts
14795
+ import {
14796
+ AppError as AppError35,
14797
+ BadRequestError as BadRequestError70,
14798
+ logger as logger38,
14799
+ makeCacheKey as makeCacheKey23,
14800
+ paginate as paginate20,
14801
+ useAtlas as useAtlas32,
14802
+ useCache as useCache24
14803
+ } from "@goweekdays/utils";
14804
+ import { ObjectId as ObjectId35 } from "mongodb";
14805
+ import Joi59 from "joi";
14806
+ function useJobProfileRepo() {
14807
+ const db = useAtlas32.getDb();
14808
+ if (!db) {
14809
+ throw new BadRequestError70("Unable to connect to server.");
14810
+ }
14811
+ const namespace_collection = "job.profiles";
14812
+ const collection = db.collection(namespace_collection);
14813
+ const { getCache, setCache, delNamespace } = useCache24(namespace_collection);
14814
+ function delCachedData() {
14815
+ delNamespace().then(() => {
14816
+ logger38.log({
14817
+ level: "info",
14818
+ message: `Cache namespace cleared for ${namespace_collection}`
14819
+ });
14820
+ }).catch((err) => {
14821
+ logger38.log({
14822
+ level: "error",
14823
+ message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
14824
+ });
14825
+ });
14826
+ }
14827
+ async function createIndexes() {
14828
+ try {
14829
+ await collection.createIndexes([{ key: { user: 1 }, unique: true }]);
14830
+ return "Successfully created job profile indexes.";
14831
+ } catch (error) {
14832
+ throw new BadRequestError70("Failed to create job profile indexes.");
14833
+ }
14834
+ }
14835
+ async function add(data) {
14836
+ const { error } = schemaJobProfile.validate(data);
14837
+ if (error) {
14838
+ throw new BadRequestError70(`Invalid job profile data: ${error.message}`);
14839
+ }
14840
+ try {
14841
+ data = modelJobProfile(data);
14842
+ const res = await collection.insertOne(data);
14843
+ delCachedData();
14844
+ return res.insertedId;
14845
+ } catch (error2) {
14846
+ if (error2 instanceof AppError35) {
14847
+ throw error2;
14848
+ }
14849
+ throw new BadRequestError70(
14850
+ `Failed to create job profile: ${error2.message}`
14851
+ );
14852
+ }
14853
+ }
14854
+ async function getAll({
14855
+ page = 1,
14856
+ limit = 10,
14857
+ search = "",
14858
+ status: status2 = "new"
14859
+ } = {}) {
14860
+ page = page > 0 ? page - 1 : 0;
14861
+ const query = { status: status2 };
14862
+ const cacheKeyOptions = {
14863
+ page,
14864
+ limit,
14865
+ status: status2,
14866
+ tag: "getAll"
14867
+ };
14868
+ if (search) {
14869
+ query.$text = { $search: search };
14870
+ cacheKeyOptions.search = search;
14871
+ }
14872
+ const cacheKey = makeCacheKey23(namespace_collection, cacheKeyOptions);
14873
+ const cachedData = await getCache(cacheKey);
14874
+ if (cachedData) {
14875
+ return cachedData;
14876
+ }
14877
+ try {
14878
+ const items = await collection.aggregate([
14879
+ { $match: query },
14880
+ { $skip: page * limit },
14881
+ { $limit: limit }
14882
+ ]).toArray();
14883
+ const length = await collection.countDocuments(query);
14884
+ const data = paginate20(items, page, limit, length);
14885
+ setCache(cacheKey, data).then(() => {
14886
+ logger38.log({
14887
+ level: "info",
14888
+ message: `Cache set for getAll job profiles: ${cacheKey}`
14889
+ });
14890
+ }).catch((err) => {
14891
+ logger38.log({
14892
+ level: "error",
14893
+ message: `Failed to set cache for getAll job profiles: ${cacheKey}, error: ${err.message}`
14894
+ });
14895
+ });
14896
+ return data;
14897
+ } catch (error) {
14898
+ if (error instanceof AppError35) {
14899
+ throw error;
14900
+ }
14901
+ throw new BadRequestError70(`Failed to get job profiles: ${error.message}`);
14902
+ }
14903
+ }
14904
+ async function getByUser(user) {
14905
+ const { error } = Joi59.string().hex().length(24).validate(user);
14906
+ if (error) {
14907
+ throw new BadRequestError70(`Invalid job profile id: ${user}`);
14908
+ }
14909
+ try {
14910
+ user = new ObjectId35(user);
14911
+ } catch (error2) {
14912
+ throw new BadRequestError70(`Invalid job profile id: ${user}`);
14913
+ }
14914
+ try {
14915
+ const cacheKey = makeCacheKey23(namespace_collection, {
14916
+ user,
14917
+ tag: "getByUser"
14918
+ });
14919
+ const cachedData = await getCache(cacheKey);
14920
+ if (cachedData) {
14921
+ return cachedData;
14922
+ }
14923
+ const data = await collection.findOne({ user });
14924
+ setCache(cacheKey, data).then(() => {
14925
+ logger38.log({
14926
+ level: "info",
14927
+ message: `Cache set for getByUser job profile: ${cacheKey}`
14928
+ });
14929
+ }).catch((err) => {
14930
+ logger38.log({
14931
+ level: "error",
14932
+ message: `Failed to set cache for getByUser job profile: ${cacheKey}, error: ${err.message}`
14933
+ });
14934
+ });
14935
+ return data;
14936
+ } catch (error2) {
14937
+ if (error2 instanceof AppError35) {
14938
+ throw error2;
14939
+ }
14940
+ throw new BadRequestError70(
14941
+ `Failed to get job profile: ${error2.message}`
14942
+ );
14943
+ }
14944
+ }
14945
+ async function updateContactInfoById(_id, options) {
14946
+ const { error } = schemaJobProfileContactInfo.validate({
14947
+ id: _id,
14948
+ ...options
14949
+ });
14950
+ if (error) {
14951
+ throw new BadRequestError70(`Invalid job profile data: ${error.message}`);
14952
+ }
14953
+ try {
14954
+ _id = new ObjectId35(_id);
14955
+ } catch (error2) {
14956
+ throw new BadRequestError70(`Invalid job profile id: ${_id}`);
14957
+ }
14958
+ try {
14959
+ await collection.updateOne(
14960
+ { _id },
14961
+ { $set: { ...options, updatedAt: /* @__PURE__ */ new Date() } }
14962
+ );
14963
+ delCachedData();
14964
+ return "Successfully updated job profile contact info.";
14965
+ } catch (error2) {
14966
+ if (error2 instanceof AppError35) {
14967
+ throw error2;
14968
+ }
14969
+ throw new BadRequestError70(
14970
+ `Failed to update job profile contact info: ${error2.message}`
14971
+ );
14972
+ }
14973
+ }
14974
+ async function updateSummaryById(_id, summary) {
14975
+ const { error } = schemaJobProfileSummary.validate({ id: _id, summary });
14976
+ if (error) {
14977
+ throw new BadRequestError70(`Invalid job profile data: ${error.message}`);
14978
+ }
14979
+ try {
14980
+ _id = new ObjectId35(_id);
14981
+ } catch (error2) {
14982
+ throw new BadRequestError70(`Invalid job profile id: ${_id}`);
14983
+ }
14984
+ try {
14985
+ await collection.updateOne(
14986
+ { _id },
14987
+ { $set: { summary, updatedAt: /* @__PURE__ */ new Date() } }
14988
+ );
14989
+ delCachedData();
14990
+ return "Successfully updated job profile summary.";
14991
+ } catch (error2) {
14992
+ if (error2 instanceof AppError35) {
14993
+ throw error2;
14994
+ }
14995
+ throw new BadRequestError70(
14996
+ `Failed to update job profile summary: ${error2.message}`
14997
+ );
14998
+ }
14999
+ }
15000
+ async function updatePersonalInfoById(_id, options) {
15001
+ const { error } = schemaJobProfilePersonalInfo.validate({
15002
+ id: _id,
15003
+ ...options
15004
+ });
15005
+ if (error) {
15006
+ throw new BadRequestError70(`Invalid job profile data: ${error.message}`);
15007
+ }
15008
+ try {
15009
+ _id = new ObjectId35(_id);
15010
+ } catch (error2) {
15011
+ throw new BadRequestError70(`Invalid job profile id: ${_id}`);
15012
+ }
15013
+ try {
15014
+ await collection.updateOne(
15015
+ { _id },
15016
+ { $set: { ...options, updatedAt: /* @__PURE__ */ new Date() } }
15017
+ );
15018
+ delCachedData();
15019
+ return "Successfully updated job profile personal info.";
15020
+ } catch (error2) {
15021
+ if (error2 instanceof AppError35) {
15022
+ throw error2;
15023
+ }
15024
+ throw new BadRequestError70(
15025
+ `Failed to update job profile personal info: ${error2.message}`
15026
+ );
15027
+ }
15028
+ }
15029
+ async function addWorkExpById(_id, workExp2) {
15030
+ const { error } = schemaJobProfileWorkExp.validate({ ...workExp2, _id });
15031
+ if (error) {
15032
+ throw new BadRequestError70(
15033
+ `Invalid job profile work experience data: ${error.message}`
15034
+ );
15035
+ }
15036
+ try {
15037
+ _id = new ObjectId35(_id);
15038
+ } catch (error2) {
15039
+ throw new BadRequestError70(`Invalid job profile id: ${_id}`);
15040
+ }
15041
+ try {
15042
+ workExp2 = modelJobProfileWorkExp(workExp2);
15043
+ await collection.updateOne(
15044
+ { _id },
15045
+ // @ts-ignore
15046
+ { $push: { workExperience: workExp2 }, $set: { updatedAt: /* @__PURE__ */ new Date() } }
15047
+ );
15048
+ delCachedData();
15049
+ return "Successfully added job profile work experience.";
15050
+ } catch (error2) {
15051
+ if (error2 instanceof AppError35) {
15052
+ throw error2;
15053
+ }
15054
+ throw new BadRequestError70(
15055
+ `Failed to add job profile work experience: ${error2.message}`
15056
+ );
15057
+ }
15058
+ }
15059
+ async function updateWorkExpById(_id, workExp2) {
15060
+ const { error } = schemaJobProfileWorkExp.validate({ ...workExp2, _id });
15061
+ if (error) {
15062
+ throw new BadRequestError70(
15063
+ `Invalid job profile work experience data: ${error.message}`
15064
+ );
15065
+ }
15066
+ try {
15067
+ _id = new ObjectId35(_id);
15068
+ } catch (error2) {
15069
+ throw new BadRequestError70(`Invalid job profile id: ${_id}`);
15070
+ }
15071
+ try {
15072
+ workExp2 = modelJobProfileWorkExp(workExp2);
15073
+ await collection.updateOne(
15074
+ { _id, "workExperience.id": workExp2.id },
15075
+ { $set: { "workExperience.$": workExp2, updatedAt: /* @__PURE__ */ new Date() } }
15076
+ );
15077
+ delCachedData();
15078
+ return "Successfully updated job profile work experience.";
15079
+ } catch (error2) {
15080
+ if (error2 instanceof AppError35) {
15081
+ throw error2;
15082
+ }
15083
+ throw new BadRequestError70(
15084
+ `Failed to updated job profile work experience: ${error2.message}`
15085
+ );
15086
+ }
15087
+ }
15088
+ async function deleteWorkExpById(_id, workExpId) {
15089
+ const { error } = schemaJobProfileWorkExpDel.validate({
15090
+ id: _id,
15091
+ workExpId
15092
+ });
15093
+ if (error) {
15094
+ throw new BadRequestError70(
15095
+ `Invalid job profile work experience data: ${error.message}`
15096
+ );
15097
+ }
15098
+ try {
15099
+ _id = new ObjectId35(_id);
15100
+ } catch (error2) {
15101
+ throw new BadRequestError70(`Invalid job profile _id.`);
15102
+ }
15103
+ try {
15104
+ workExpId = new ObjectId35(workExpId);
15105
+ } catch (error2) {
15106
+ throw new BadRequestError70(`Invalid job profile workExpId.`);
15107
+ }
15108
+ try {
15109
+ await collection.updateOne(
15110
+ { _id },
15111
+ {
15112
+ // @ts-ignore
15113
+ $pull: { workExperience: { id: workExpId } },
15114
+ $set: { updatedAt: /* @__PURE__ */ new Date() }
15115
+ }
15116
+ );
15117
+ delCachedData();
15118
+ return "Successfully deleted job profile work experience.";
15119
+ } catch (error2) {
15120
+ if (error2 instanceof AppError35) {
15121
+ throw error2;
15122
+ }
15123
+ throw new BadRequestError70(
15124
+ `Failed to delete job profile work experience: ${error2.message}`
15125
+ );
15126
+ }
15127
+ }
15128
+ async function addEduById(_id, edu) {
15129
+ const { error } = schemaJobProfileEdu.validate({ ...edu, _id });
15130
+ if (error) {
15131
+ throw new BadRequestError70(
15132
+ `Invalid job profile education data: ${error.message}`
15133
+ );
15134
+ }
15135
+ try {
15136
+ _id = new ObjectId35(_id);
15137
+ } catch (error2) {
15138
+ throw new BadRequestError70(`Invalid job profile id: ${_id}`);
15139
+ }
15140
+ try {
15141
+ edu = modelJobProfileEdu(edu);
15142
+ await collection.updateOne(
15143
+ { _id },
15144
+ // @ts-ignore
15145
+ { $push: { education: edu }, $set: { updatedAt: /* @__PURE__ */ new Date() } }
15146
+ );
15147
+ delCachedData();
15148
+ return "Successfully added job profile education.";
15149
+ } catch (error2) {
15150
+ if (error2 instanceof AppError35) {
15151
+ throw error2;
15152
+ }
15153
+ throw new BadRequestError70(
15154
+ `Failed to add job profile education: ${error2.message}`
15155
+ );
15156
+ }
15157
+ }
15158
+ async function updateEduById(_id, edu) {
15159
+ const { error } = schemaJobProfileEdu.validate({ ...edu, _id });
15160
+ if (error) {
15161
+ throw new BadRequestError70(
15162
+ `Invalid job profile education data: ${error.message}`
15163
+ );
15164
+ }
15165
+ try {
15166
+ _id = new ObjectId35(_id);
15167
+ } catch (error2) {
15168
+ throw new BadRequestError70(`Invalid job profile id: ${_id}`);
15169
+ }
15170
+ try {
15171
+ edu = modelJobProfileEdu(edu);
15172
+ await collection.updateOne(
15173
+ { _id, "education.id": edu.id },
15174
+ { $set: { "education.$": edu, updatedAt: /* @__PURE__ */ new Date() } }
15175
+ );
15176
+ delCachedData();
15177
+ return "Successfully updated job profile education.";
15178
+ } catch (error2) {
15179
+ if (error2 instanceof AppError35) {
15180
+ throw error2;
15181
+ }
15182
+ throw new BadRequestError70(
15183
+ `Failed to update job profile education: ${error2.message}`
15184
+ );
15185
+ }
15186
+ }
15187
+ async function deleteEduById(_id, eduId) {
15188
+ const { error } = schemaJobProfileEduDel.validate({
15189
+ id: _id,
15190
+ eduId
15191
+ });
15192
+ if (error) {
15193
+ throw new BadRequestError70(
15194
+ `Invalid job profile education data: ${error.message}`
15195
+ );
15196
+ }
15197
+ try {
15198
+ _id = new ObjectId35(_id);
15199
+ } catch (error2) {
15200
+ throw new BadRequestError70(`Invalid job profile _id.`);
15201
+ }
15202
+ try {
15203
+ eduId = new ObjectId35(eduId);
15204
+ } catch (error2) {
15205
+ throw new BadRequestError70(`Invalid job profile eduId.`);
15206
+ }
15207
+ try {
15208
+ await collection.updateOne(
15209
+ { _id },
15210
+ {
15211
+ // @ts-ignore
15212
+ $pull: { education: { id: eduId } },
15213
+ $set: { updatedAt: /* @__PURE__ */ new Date() }
15214
+ }
15215
+ );
15216
+ delCachedData();
15217
+ return "Successfully deleted job profile education.";
15218
+ } catch (error2) {
15219
+ if (error2 instanceof AppError35) {
15220
+ throw error2;
15221
+ }
15222
+ throw new BadRequestError70(
15223
+ `Failed to delete job profile education: ${error2.message}`
15224
+ );
15225
+ }
15226
+ }
15227
+ async function addSkillById(_id, skill2) {
15228
+ const { error } = schemaJobProfileSkill.validate({ ...skill2, _id });
15229
+ if (error) {
15230
+ throw new BadRequestError70(
15231
+ `Invalid job profile skill data: ${error.message}`
15232
+ );
15233
+ }
15234
+ try {
15235
+ _id = new ObjectId35(_id);
15236
+ } catch (error2) {
15237
+ throw new BadRequestError70(`Invalid job profile id: ${_id}`);
15238
+ }
15239
+ try {
15240
+ skill2 = modelJobProfileSkill(skill2);
15241
+ await collection.updateOne(
15242
+ { _id },
15243
+ // @ts-ignore
15244
+ { $push: { skills: skill2 }, $set: { updatedAt: /* @__PURE__ */ new Date() } }
15245
+ );
15246
+ delCachedData();
15247
+ return "Successfully added job profile skill.";
15248
+ } catch (error2) {
15249
+ if (error2 instanceof AppError35) {
15250
+ throw error2;
15251
+ }
15252
+ throw new BadRequestError70(
15253
+ `Failed to add job profile skill: ${error2.message}`
15254
+ );
15255
+ }
15256
+ }
15257
+ async function updateSkillById(_id, skill2) {
15258
+ const { error } = schemaJobProfileSkill.validate({ ...skill2, _id });
15259
+ if (error) {
15260
+ throw new BadRequestError70(
15261
+ `Invalid job profile skill data: ${error.message}`
15262
+ );
15263
+ }
15264
+ try {
15265
+ _id = new ObjectId35(_id);
15266
+ } catch (error2) {
15267
+ throw new BadRequestError70(`Invalid job profile id: ${_id}`);
15268
+ }
15269
+ try {
15270
+ skill2 = modelJobProfileSkill(skill2);
15271
+ await collection.updateOne(
15272
+ { _id, "skills.id": skill2.id },
15273
+ { $set: { "skills.$": skill2, updatedAt: /* @__PURE__ */ new Date() } }
15274
+ );
15275
+ delCachedData();
15276
+ return "Successfully updated job profile skill.";
15277
+ } catch (error2) {
15278
+ if (error2 instanceof AppError35) {
15279
+ throw error2;
15280
+ }
15281
+ throw new BadRequestError70(
15282
+ `Failed to update job profile skill: ${error2.message}`
15283
+ );
15284
+ }
15285
+ }
15286
+ async function deleteSkillById(_id, skillId) {
15287
+ const { error } = schemaJobProfileSkillDel.validate({
15288
+ id: _id,
15289
+ skillId
15290
+ });
15291
+ if (error) {
15292
+ throw new BadRequestError70(
15293
+ `Invalid job profile skill data: ${error.message}`
15294
+ );
15295
+ }
15296
+ try {
15297
+ _id = new ObjectId35(_id);
15298
+ } catch (error2) {
15299
+ throw new BadRequestError70(`Invalid job profile _id.`);
15300
+ }
15301
+ try {
15302
+ skillId = new ObjectId35(skillId);
15303
+ } catch (error2) {
15304
+ throw new BadRequestError70(`Invalid job profile skillId.`);
15305
+ }
15306
+ try {
15307
+ await collection.updateOne(
15308
+ { _id },
15309
+ {
15310
+ // @ts-ignore
15311
+ $pull: { skills: { id: skillId } },
15312
+ $set: { updatedAt: /* @__PURE__ */ new Date() }
15313
+ }
15314
+ );
15315
+ delCachedData();
15316
+ return "Successfully deleted job profile skill.";
15317
+ } catch (error2) {
15318
+ if (error2 instanceof AppError35) {
15319
+ throw error2;
15320
+ }
15321
+ throw new BadRequestError70(
15322
+ `Failed to delete job profile skill: ${error2.message}`
15323
+ );
15324
+ }
15325
+ }
15326
+ async function updateAdditionalInfoById(_id, additionalInfo) {
15327
+ const { error } = schemaJobProfileAdditionalInfo.validate({
15328
+ id: _id,
15329
+ additionalInfo
15330
+ });
15331
+ if (error) {
15332
+ throw new BadRequestError70(`Invalid job profile data: ${error.message}`);
15333
+ }
15334
+ try {
15335
+ _id = new ObjectId35(_id);
15336
+ } catch (error2) {
15337
+ throw new BadRequestError70(`Invalid job profile id: ${_id}`);
15338
+ }
15339
+ try {
15340
+ await collection.updateOne(
15341
+ { _id },
15342
+ { $set: { additionalInfo, updatedAt: /* @__PURE__ */ new Date() } }
15343
+ );
15344
+ delCachedData();
15345
+ return "Successfully updated job profile additionalInfo.";
15346
+ } catch (error2) {
15347
+ if (error2 instanceof AppError35) {
15348
+ throw error2;
15349
+ }
15350
+ throw new BadRequestError70(
15351
+ `Failed to update job profile additionalInfo: ${error2.message}`
15352
+ );
15353
+ }
15354
+ }
15355
+ async function addLangById(_id, lang) {
15356
+ const { error } = schemaJobProfileLang.validate({ ...lang, _id });
15357
+ if (error) {
15358
+ throw new BadRequestError70(
15359
+ `Invalid job profile language data: ${error.message}`
15360
+ );
15361
+ }
15362
+ try {
15363
+ _id = new ObjectId35(_id);
15364
+ } catch (error2) {
15365
+ throw new BadRequestError70(`Invalid job profile id: ${_id}`);
15366
+ }
15367
+ try {
15368
+ lang = modelJobProfileLang(lang);
15369
+ await collection.updateOne(
15370
+ { _id },
15371
+ // @ts-ignore
15372
+ { $push: { languages: lang }, $set: { updatedAt: /* @__PURE__ */ new Date() } }
15373
+ );
15374
+ delCachedData();
15375
+ return "Successfully added job profile language.";
15376
+ } catch (error2) {
15377
+ if (error2 instanceof AppError35) {
15378
+ throw error2;
15379
+ }
15380
+ throw new BadRequestError70(
15381
+ `Failed to add job profile language: ${error2.message}`
15382
+ );
15383
+ }
15384
+ }
15385
+ async function updateLangById(_id, lang) {
15386
+ const { error } = schemaJobProfileLang.validate({ ...lang, _id });
15387
+ if (error) {
15388
+ throw new BadRequestError70(
15389
+ `Invalid job profile language data: ${error.message}`
15390
+ );
15391
+ }
15392
+ try {
15393
+ _id = new ObjectId35(_id);
15394
+ } catch (error2) {
15395
+ throw new BadRequestError70(`Invalid job profile id: ${_id}`);
15396
+ }
15397
+ try {
15398
+ lang = modelJobProfileLang(lang);
15399
+ await collection.updateOne(
15400
+ { _id, "languages.id": lang.id },
15401
+ { $set: { "languages.$": lang, updatedAt: /* @__PURE__ */ new Date() } }
15402
+ );
15403
+ delCachedData();
15404
+ return "Successfully updated job profile language.";
15405
+ } catch (error2) {
15406
+ if (error2 instanceof AppError35) {
15407
+ throw error2;
15408
+ }
15409
+ throw new BadRequestError70(
15410
+ `Failed to update job profile language: ${error2.message}`
15411
+ );
15412
+ }
15413
+ }
15414
+ async function deleteLangById(_id, langId) {
15415
+ const { error } = schemaJobProfileLangDel.validate({
15416
+ id: _id,
15417
+ langId
15418
+ });
15419
+ if (error) {
15420
+ throw new BadRequestError70(
15421
+ `Invalid job profile language data: ${error.message}`
15422
+ );
15423
+ }
15424
+ try {
15425
+ _id = new ObjectId35(_id);
15426
+ } catch (error2) {
15427
+ throw new BadRequestError70(`Invalid job profile _id.`);
15428
+ }
15429
+ try {
15430
+ langId = new ObjectId35(langId);
15431
+ } catch (error2) {
15432
+ throw new BadRequestError70(`Invalid job profile langId.`);
15433
+ }
15434
+ try {
15435
+ await collection.updateOne(
15436
+ { _id },
15437
+ {
15438
+ // @ts-ignore
15439
+ $pull: { languages: { id: langId } },
15440
+ $set: { updatedAt: /* @__PURE__ */ new Date() }
15441
+ }
15442
+ );
15443
+ delCachedData();
15444
+ return "Successfully deleted job profile language.";
15445
+ } catch (error2) {
15446
+ if (error2 instanceof AppError35) {
15447
+ throw error2;
15448
+ }
15449
+ throw new BadRequestError70(
15450
+ `Failed to delete job profile language: ${error2.message}`
15451
+ );
15452
+ }
15453
+ }
15454
+ async function addCertById(_id, cert) {
15455
+ const { error } = schemaJobProfileCert.validate({ ...cert, _id });
15456
+ if (error) {
15457
+ throw new BadRequestError70(
15458
+ `Invalid job profile certification data: ${error.message}`
15459
+ );
15460
+ }
15461
+ try {
15462
+ _id = new ObjectId35(_id);
15463
+ } catch (error2) {
15464
+ throw new BadRequestError70(`Invalid job profile id: ${_id}`);
15465
+ }
15466
+ try {
15467
+ cert = modelJobProfileCert(cert);
15468
+ await collection.updateOne(
15469
+ { _id },
15470
+ // @ts-ignore
15471
+ { $push: { certifications: cert }, $set: { updatedAt: /* @__PURE__ */ new Date() } }
15472
+ );
15473
+ delCachedData();
15474
+ return "Successfully added job profile certification.";
15475
+ } catch (error2) {
15476
+ if (error2 instanceof AppError35) {
15477
+ throw error2;
15478
+ }
15479
+ throw new BadRequestError70(
15480
+ `Failed to add job profile certification: ${error2.message}`
15481
+ );
15482
+ }
15483
+ }
15484
+ async function updateCertById(_id, cert) {
15485
+ const { error } = schemaJobProfileCert.validate({ ...cert, _id });
15486
+ if (error) {
15487
+ throw new BadRequestError70(
15488
+ `Invalid job profile certification data: ${error.message}`
15489
+ );
15490
+ }
15491
+ try {
15492
+ _id = new ObjectId35(_id);
15493
+ } catch (error2) {
15494
+ throw new BadRequestError70(`Invalid job profile id: ${_id}`);
15495
+ }
15496
+ try {
15497
+ cert = modelJobProfileCert(cert);
15498
+ await collection.updateOne(
15499
+ { _id, "certifications.id": cert.id },
15500
+ { $set: { "certifications.$": cert, updatedAt: /* @__PURE__ */ new Date() } }
15501
+ );
15502
+ delCachedData();
15503
+ return "Successfully updated job profile certification.";
15504
+ } catch (error2) {
15505
+ if (error2 instanceof AppError35) {
15506
+ throw error2;
15507
+ }
15508
+ throw new BadRequestError70(
15509
+ `Failed to update job profile certification: ${error2.message}`
15510
+ );
15511
+ }
15512
+ }
15513
+ async function deleteCertById(_id, certId) {
15514
+ const { error } = schemaJobProfileCertDel.validate({
15515
+ id: _id,
15516
+ certId
15517
+ });
15518
+ if (error) {
15519
+ throw new BadRequestError70(
15520
+ `Invalid job profile certification data: ${error.message}`
15521
+ );
15522
+ }
15523
+ try {
15524
+ _id = new ObjectId35(_id);
15525
+ } catch (error2) {
15526
+ throw new BadRequestError70(`Invalid job profile _id.`);
15527
+ }
15528
+ try {
15529
+ certId = new ObjectId35(certId);
15530
+ } catch (error2) {
15531
+ throw new BadRequestError70(`Invalid job profile certId.`);
15532
+ }
15533
+ try {
15534
+ await collection.updateOne(
15535
+ { _id },
15536
+ {
15537
+ // @ts-ignore
15538
+ $pull: { certifications: { id: certId } },
15539
+ $set: { updatedAt: /* @__PURE__ */ new Date() }
15540
+ }
15541
+ );
15542
+ delCachedData();
15543
+ return "Successfully deleted job profile certification.";
15544
+ } catch (error2) {
15545
+ if (error2 instanceof AppError35) {
15546
+ throw error2;
15547
+ }
15548
+ throw new BadRequestError70(
15549
+ `Failed to delete job profile certification: ${error2.message}`
15550
+ );
15551
+ }
15552
+ }
15553
+ return {
15554
+ createIndexes,
15555
+ delCachedData,
15556
+ add,
15557
+ getAll,
15558
+ getByUser,
15559
+ updateContactInfoById,
15560
+ updateSummaryById,
15561
+ updatePersonalInfoById,
15562
+ addWorkExpById,
15563
+ updateWorkExpById,
15564
+ deleteWorkExpById,
15565
+ addEduById,
15566
+ updateEduById,
15567
+ deleteEduById,
15568
+ addSkillById,
15569
+ updateSkillById,
15570
+ deleteSkillById,
15571
+ addLangById,
15572
+ updateLangById,
15573
+ deleteLangById,
15574
+ addCertById,
15575
+ updateCertById,
15576
+ deleteCertById,
15577
+ updateAdditionalInfoById
15578
+ };
15579
+ }
15580
+
15581
+ // src/resources/job-profile/job.profile.controller.ts
15582
+ import { AppError as AppError36, BadRequestError as BadRequestError71, NotFoundError as NotFoundError5 } from "@goweekdays/utils";
15583
+ import Joi60 from "joi";
15584
+ function useJobProfileCtrl() {
15585
+ const {
15586
+ add: _add,
15587
+ getAll: _getAll,
15588
+ getByUser: _getByUser,
15589
+ updateContactInfoById: _updateContactInfoById,
15590
+ updateSummaryById: _updateSummaryById,
15591
+ updatePersonalInfoById: _updatePersonalInfoById,
15592
+ addWorkExpById: _addWorkExpById,
15593
+ updateWorkExpById: _updateWorkExpById,
15594
+ deleteWorkExpById: _deleteWorkExpById,
15595
+ addEduById: _addEduById,
15596
+ updateEduById: _updateEduById,
15597
+ deleteEduById: _deleteEduById,
15598
+ addSkillById: _addSkillById,
15599
+ updateSkillById: _updateSkillById,
15600
+ deleteSkillById: _deleteSkillById,
15601
+ addLangById: _addLangById,
15602
+ updateLangById: _updateLangById,
15603
+ deleteLangById: _deleteLangById,
15604
+ addCertById: _addCertById,
15605
+ updateCertById: _updateCertById,
15606
+ deleteCertById: _deleteCertById,
15607
+ updateAdditionalInfoById: _updateAdditionalInfoById
15608
+ } = useJobProfileRepo();
15609
+ async function add(req, res, next) {
15610
+ const { error } = schemaJobProfile.validate(req.body);
15611
+ if (error) {
15612
+ next(
15613
+ new BadRequestError71(`Invalid job application data: ${error.message}`)
15614
+ );
15615
+ return;
15616
+ }
15617
+ try {
15618
+ const message = await _add(req.body);
15619
+ res.json({ message });
15620
+ return;
15621
+ } catch (error2) {
15622
+ if (error2 instanceof AppError36) {
15623
+ next(error2);
15624
+ return;
15625
+ }
15626
+ next(
15627
+ new BadRequestError71(
15628
+ `Failed to create job application: ${error2.message}`
15629
+ )
15630
+ );
15631
+ }
15632
+ }
15633
+ async function getAll(req, res, next) {
15634
+ const validation = Joi60.object({
15635
+ page: Joi60.number().integer().min(1).optional(),
15636
+ limit: Joi60.number().integer().min(1).max(100).optional(),
15637
+ search: Joi60.string().optional().allow("")
15638
+ });
15639
+ const { error } = validation.validate(req.query);
15640
+ if (error) {
15641
+ next(new BadRequestError71(`Invalid query parameters: ${error.message}`));
15642
+ return;
15643
+ }
15644
+ const page = req.query.page ? parseInt(req.query.page) : 1;
15645
+ const limit = req.query.limit ? parseInt(req.query.limit) : 10;
15646
+ const search = req.query.search ? req.query.search : "";
15647
+ try {
15648
+ const data = await _getAll({ page, limit, search, status });
15649
+ res.json(data);
15650
+ return;
15651
+ } catch (error2) {
15652
+ if (error2 instanceof AppError36) {
15653
+ next(error2);
15654
+ return;
15655
+ }
15656
+ next(new BadRequestError71(`Failed to get job profiles: ${error2.message}`));
15657
+ }
15658
+ }
15659
+ async function getByUser(req, res, next) {
15660
+ const user = req.params.user ?? "";
15661
+ const { error } = Joi60.string().hex().length(24).required().validate(user);
15662
+ if (error) {
15663
+ next(new BadRequestError71(`Invalid user id: ${user}`));
15664
+ return;
15665
+ }
15666
+ try {
15667
+ const data = await _getByUser(user);
15668
+ if (!data) {
15669
+ next(new NotFoundError5(`Job profile not found for user: ${user}`));
15670
+ return;
15671
+ }
15672
+ res.json(data);
15673
+ return;
15674
+ } catch (error2) {
15675
+ if (error2 instanceof AppError36) {
15676
+ next(error2);
15677
+ return;
15678
+ }
15679
+ next(
15680
+ new BadRequestError71(`Failed to get job application: ${error2.message}`)
15681
+ );
15682
+ }
15683
+ }
15684
+ async function updateContactInfoById(req, res, next) {
15685
+ const id = req.params.id ?? "";
15686
+ const options = req.body;
15687
+ const { error } = schemaJobProfileContactInfo.validate({ ...options, id });
15688
+ if (error) {
15689
+ next(new BadRequestError71(`Invalid job profile data: ${error.message}`));
15690
+ return;
15691
+ }
15692
+ try {
15693
+ const message = await _updateContactInfoById(id, options);
15694
+ res.json({ message });
15695
+ return;
15696
+ } catch (error2) {
15697
+ if (error2 instanceof AppError36) {
15698
+ next(error2);
15699
+ return;
15700
+ }
15701
+ next(
15702
+ new BadRequestError71(
15703
+ `Failed to update job profile contact info: ${error2.message}`
15704
+ )
15705
+ );
15706
+ }
15707
+ }
15708
+ async function updateSummaryById(req, res, next) {
15709
+ const id = req.params.id ?? "";
15710
+ const summary = req.body.summary ?? "";
15711
+ const { error } = schemaJobProfileSummary.validate({ id, summary });
15712
+ if (error) {
15713
+ next(new BadRequestError71(`Invalid job profile data: ${error.message}`));
15714
+ return;
15715
+ }
15716
+ try {
15717
+ const message = await _updateSummaryById(id, summary);
15718
+ res.json({ message });
15719
+ return;
15720
+ } catch (error2) {
15721
+ if (error2 instanceof AppError36) {
15722
+ next(error2);
15723
+ return;
15724
+ }
15725
+ next(
15726
+ new BadRequestError71(
15727
+ `Failed to update job profile summary: ${error2.message}`
15728
+ )
15729
+ );
15730
+ }
15731
+ }
15732
+ async function updatePersonalInfoById(req, res, next) {
15733
+ const id = req.params.id ?? "";
15734
+ const options = req.body;
15735
+ const { error } = schemaJobProfilePersonalInfo.validate({ ...options, id });
15736
+ if (error) {
15737
+ next(new BadRequestError71(`Invalid job profile data: ${error.message}`));
15738
+ return;
15739
+ }
15740
+ try {
15741
+ const message = await _updatePersonalInfoById(id, options);
15742
+ res.json({ message });
15743
+ return;
15744
+ } catch (error2) {
15745
+ if (error2 instanceof AppError36) {
15746
+ next(error2);
15747
+ return;
15748
+ }
15749
+ next(
15750
+ new BadRequestError71(
15751
+ `Failed to update job profile personal info: ${error2.message}`
15752
+ )
15753
+ );
15754
+ }
15755
+ }
15756
+ async function addWorkExpById(req, res, next) {
15757
+ const _id = req.params.id ?? "";
15758
+ const workExp2 = req.body;
15759
+ const { error } = schemaJobProfileWorkExp.validate({ _id, ...workExp2 });
15760
+ if (error) {
15761
+ next(
15762
+ new BadRequestError71(`Invalid work experience data: ${error.message}`)
15763
+ );
15764
+ return;
15765
+ }
15766
+ try {
15767
+ const message = await _addWorkExpById(_id, workExp2);
15768
+ res.json({ message });
15769
+ return;
15770
+ } catch (error2) {
15771
+ if (error2 instanceof AppError36) {
15772
+ next(error2);
15773
+ return;
15774
+ }
15775
+ next(
15776
+ new BadRequestError71(`Failed to add work experience: ${error2.message}`)
15777
+ );
15778
+ }
15779
+ }
15780
+ async function updateWorkExpById(req, res, next) {
15781
+ const _id = req.params.id ?? "";
15782
+ const workExp2 = req.body;
15783
+ const { error } = schemaJobProfileWorkExp.validate({ _id, ...workExp2 });
15784
+ if (error) {
15785
+ next(
15786
+ new BadRequestError71(`Invalid work experience data: ${error.message}`)
15787
+ );
15788
+ return;
15789
+ }
15790
+ try {
15791
+ const message = await _updateWorkExpById(_id, workExp2);
15792
+ res.json({ message });
15793
+ return;
15794
+ } catch (error2) {
15795
+ if (error2 instanceof AppError36) {
15796
+ next(error2);
15797
+ return;
15798
+ }
15799
+ next(
15800
+ new BadRequestError71(
15801
+ `Failed to update work experience: ${error2.message}`
15802
+ )
15803
+ );
15804
+ }
15805
+ }
15806
+ async function deleteWorkExpById(req, res, next) {
15807
+ const id = req.params.id ?? "";
15808
+ const workExpId = req.params.workExpId ?? "";
15809
+ const { error } = schemaJobProfileWorkExpDel.validate({ id, workExpId });
15810
+ if (error) {
15811
+ next(
15812
+ new BadRequestError71(`Invalid work experience data: ${error.message}`)
15813
+ );
15814
+ return;
15815
+ }
15816
+ try {
15817
+ const message = await _deleteWorkExpById(id, workExpId);
15818
+ res.json({ message });
15819
+ return;
15820
+ } catch (error2) {
15821
+ if (error2 instanceof AppError36) {
15822
+ next(error2);
15823
+ return;
15824
+ }
15825
+ next(
15826
+ new BadRequestError71(
15827
+ `Failed to delete work experience: ${error2.message}`
15828
+ )
15829
+ );
15830
+ }
15831
+ }
15832
+ async function addEduById(req, res, next) {
15833
+ const _id = req.params.id ?? "";
15834
+ const edu = req.body;
15835
+ const { error } = schemaJobProfileEdu.validate({ _id, ...edu });
15836
+ if (error) {
15837
+ next(new BadRequestError71(`Invalid education data: ${error.message}`));
15838
+ return;
15839
+ }
15840
+ try {
15841
+ const message = await _addEduById(_id, edu);
15842
+ res.json({ message });
15843
+ return;
15844
+ } catch (error2) {
15845
+ if (error2 instanceof AppError36) {
15846
+ next(error2);
15847
+ return;
15848
+ }
15849
+ next(new BadRequestError71(`Failed to add education: ${error2.message}`));
15850
+ }
15851
+ }
15852
+ async function updateEduById(req, res, next) {
15853
+ const _id = req.params.id ?? "";
15854
+ const edu = req.body;
15855
+ const { error } = schemaJobProfileEdu.validate({ _id, ...edu });
15856
+ if (error) {
15857
+ next(new BadRequestError71(`Invalid education data: ${error.message}`));
15858
+ return;
15859
+ }
15860
+ try {
15861
+ const message = await _updateEduById(_id, edu);
15862
+ res.json({ message });
15863
+ return;
15864
+ } catch (error2) {
15865
+ if (error2 instanceof AppError36) {
15866
+ next(error2);
15867
+ return;
15868
+ }
15869
+ next(new BadRequestError71(`Failed to update education: ${error2.message}`));
15870
+ }
15871
+ }
15872
+ async function deleteEduById(req, res, next) {
15873
+ const id = req.params.id ?? "";
15874
+ const eduId = req.params.eduId ?? "";
15875
+ const { error } = schemaJobProfileEduDel.validate({ id, eduId });
15876
+ if (error) {
15877
+ next(new BadRequestError71(`Invalid education data: ${error.message}`));
15878
+ return;
15879
+ }
15880
+ try {
15881
+ const message = await _deleteEduById(id, eduId);
15882
+ res.json({ message });
15883
+ return;
15884
+ } catch (error2) {
15885
+ if (error2 instanceof AppError36) {
15886
+ next(error2);
15887
+ return;
15888
+ }
15889
+ next(new BadRequestError71(`Failed to delete education: ${error2.message}`));
15890
+ }
15891
+ }
15892
+ async function addSkillById(req, res, next) {
15893
+ const _id = req.params.id ?? "";
15894
+ const skill2 = req.body;
15895
+ const { error } = schemaJobProfileSkill.validate({ _id, ...skill2 });
15896
+ if (error) {
15897
+ next(new BadRequestError71(`Invalid skill data: ${error.message}`));
15898
+ return;
15899
+ }
15900
+ try {
15901
+ const message = await _addSkillById(_id, skill2);
15902
+ res.json({ message });
15903
+ return;
15904
+ } catch (error2) {
15905
+ if (error2 instanceof AppError36) {
15906
+ next(error2);
15907
+ return;
15908
+ }
15909
+ next(new BadRequestError71(`Failed to add skill: ${error2.message}`));
15910
+ }
15911
+ }
15912
+ async function updateSkillById(req, res, next) {
15913
+ const _id = req.params.id ?? "";
15914
+ const skill2 = req.body;
15915
+ const { error } = schemaJobProfileSkill.validate({ _id, ...skill2 });
15916
+ if (error) {
15917
+ next(new BadRequestError71(`Invalid skill data: ${error.message}`));
15918
+ return;
15919
+ }
15920
+ try {
15921
+ const message = await _updateSkillById(_id, skill2);
15922
+ res.json({ message });
15923
+ return;
15924
+ } catch (error2) {
15925
+ if (error2 instanceof AppError36) {
15926
+ next(error2);
15927
+ return;
15928
+ }
15929
+ next(new BadRequestError71(`Failed to update skill: ${error2.message}`));
15930
+ }
15931
+ }
15932
+ async function deleteSkillById(req, res, next) {
15933
+ const id = req.params.id ?? "";
15934
+ const skillId = req.params.skillId ?? "";
15935
+ const { error } = schemaJobProfileSkillDel.validate({ id, skillId });
15936
+ if (error) {
15937
+ next(new BadRequestError71(`Invalid skill data: ${error.message}`));
15938
+ return;
15939
+ }
15940
+ try {
15941
+ const message = await _deleteSkillById(id, skillId);
15942
+ res.json({ message });
15943
+ return;
15944
+ } catch (error2) {
15945
+ if (error2 instanceof AppError36) {
15946
+ next(error2);
15947
+ return;
15948
+ }
15949
+ next(new BadRequestError71(`Failed to delete skill: ${error2.message}`));
15950
+ }
15951
+ }
15952
+ async function updateAdditionalInfoById(req, res, next) {
15953
+ const id = req.params.id ?? "";
15954
+ const additionalInfo = req.body.additionalInfo ?? "";
15955
+ const { error } = schemaJobProfileAdditionalInfo.validate({
15956
+ id,
15957
+ additionalInfo
15958
+ });
15959
+ if (error) {
15960
+ next(new BadRequestError71(`Invalid job profile data: ${error.message}`));
15961
+ return;
15962
+ }
15963
+ try {
15964
+ const message = await _updateAdditionalInfoById(id, additionalInfo);
15965
+ res.json({ message });
15966
+ return;
15967
+ } catch (error2) {
15968
+ if (error2 instanceof AppError36) {
15969
+ next(error2);
15970
+ return;
15971
+ }
15972
+ next(
15973
+ new BadRequestError71(
15974
+ `Failed to update job profile additional info: ${error2.message}`
15975
+ )
15976
+ );
15977
+ }
15978
+ }
15979
+ async function addLangById(req, res, next) {
15980
+ const _id = req.params.id ?? "";
15981
+ const lang = req.body;
15982
+ const { error } = schemaJobProfileLang.validate({ _id, ...lang });
15983
+ if (error) {
15984
+ next(new BadRequestError71(`Invalid language data: ${error.message}`));
15985
+ return;
15986
+ }
15987
+ try {
15988
+ const message = await _addLangById(_id, lang);
15989
+ res.json({ message });
15990
+ return;
15991
+ } catch (error2) {
15992
+ if (error2 instanceof AppError36) {
15993
+ next(error2);
15994
+ return;
15995
+ }
15996
+ next(new BadRequestError71(`Failed to add language: ${error2.message}`));
15997
+ }
15998
+ }
15999
+ async function updateLangById(req, res, next) {
16000
+ const _id = req.params.id ?? "";
16001
+ const lang = req.body;
16002
+ const { error } = schemaJobProfileLang.validate({ _id, ...lang });
16003
+ if (error) {
16004
+ next(new BadRequestError71(`Invalid language data: ${error.message}`));
16005
+ return;
16006
+ }
16007
+ try {
16008
+ const message = await _updateLangById(_id, lang);
16009
+ res.json({ message });
16010
+ return;
16011
+ } catch (error2) {
16012
+ if (error2 instanceof AppError36) {
16013
+ next(error2);
16014
+ return;
16015
+ }
16016
+ next(new BadRequestError71(`Failed to update language: ${error2.message}`));
16017
+ }
16018
+ }
16019
+ async function deleteLangById(req, res, next) {
16020
+ const id = req.params.id ?? "";
16021
+ const langId = req.params.langId ?? "";
16022
+ const { error } = schemaJobProfileLangDel.validate({ id, langId });
16023
+ if (error) {
16024
+ next(new BadRequestError71(`Invalid language data: ${error.message}`));
16025
+ return;
16026
+ }
16027
+ try {
16028
+ const message = await _deleteLangById(id, langId);
16029
+ res.json({ message });
16030
+ return;
16031
+ } catch (error2) {
16032
+ if (error2 instanceof AppError36) {
16033
+ next(error2);
16034
+ return;
16035
+ }
16036
+ next(new BadRequestError71(`Failed to delete language: ${error2.message}`));
16037
+ }
16038
+ }
16039
+ async function addCertById(req, res, next) {
16040
+ const _id = req.params.id ?? "";
16041
+ const cert = req.body;
16042
+ const { error } = schemaJobProfileCert.validate({ _id, ...cert });
16043
+ if (error) {
16044
+ next(new BadRequestError71(`Invalid certification data: ${error.message}`));
16045
+ return;
16046
+ }
16047
+ try {
16048
+ const message = await _addCertById(_id, cert);
16049
+ res.json({ message });
16050
+ return;
16051
+ } catch (error2) {
16052
+ if (error2 instanceof AppError36) {
16053
+ next(error2);
16054
+ return;
16055
+ }
16056
+ next(
16057
+ new BadRequestError71(`Failed to add certification: ${error2.message}`)
16058
+ );
16059
+ }
16060
+ }
16061
+ async function updateCertById(req, res, next) {
16062
+ const _id = req.params.id ?? "";
16063
+ const cert = req.body;
16064
+ const { error } = schemaJobProfileCert.validate({ _id, ...cert });
16065
+ if (error) {
16066
+ next(new BadRequestError71(`Invalid certification data: ${error.message}`));
16067
+ return;
16068
+ }
16069
+ try {
16070
+ const message = await _updateCertById(_id, cert);
16071
+ res.json({ message });
16072
+ return;
16073
+ } catch (error2) {
16074
+ if (error2 instanceof AppError36) {
16075
+ next(error2);
16076
+ return;
16077
+ }
16078
+ next(
16079
+ new BadRequestError71(`Failed to update certification: ${error2.message}`)
16080
+ );
16081
+ }
16082
+ }
16083
+ async function deleteCertById(req, res, next) {
16084
+ const id = req.params.id ?? "";
16085
+ const certId = req.params.certId ?? "";
16086
+ const { error } = schemaJobProfileCertDel.validate({ id, certId });
16087
+ if (error) {
16088
+ next(new BadRequestError71(`Invalid certification data: ${error.message}`));
16089
+ return;
16090
+ }
16091
+ try {
16092
+ const message = await _deleteCertById(id, certId);
16093
+ res.json({ message });
16094
+ return;
16095
+ } catch (error2) {
16096
+ if (error2 instanceof AppError36) {
16097
+ next(error2);
16098
+ return;
16099
+ }
16100
+ next(
16101
+ new BadRequestError71(`Failed to delete certification: ${error2.message}`)
16102
+ );
16103
+ }
16104
+ }
16105
+ return {
16106
+ add,
16107
+ getAll,
16108
+ getByUser,
16109
+ updateContactInfoById,
16110
+ updateSummaryById,
16111
+ updatePersonalInfoById,
16112
+ addWorkExpById,
16113
+ updateWorkExpById,
16114
+ deleteWorkExpById,
16115
+ addEduById,
16116
+ updateEduById,
16117
+ deleteEduById,
16118
+ addSkillById,
16119
+ updateSkillById,
16120
+ deleteSkillById,
16121
+ addLangById,
16122
+ updateLangById,
16123
+ deleteLangById,
16124
+ addCertById,
16125
+ updateCertById,
16126
+ deleteCertById,
16127
+ updateAdditionalInfoById
14262
16128
  };
14263
16129
  }
14264
16130
  export {
@@ -14310,6 +16176,12 @@ export {
14310
16176
  modelApp,
14311
16177
  modelJobApplication,
14312
16178
  modelJobPost,
16179
+ modelJobProfile,
16180
+ modelJobProfileCert,
16181
+ modelJobProfileEdu,
16182
+ modelJobProfileLang,
16183
+ modelJobProfileSkill,
16184
+ modelJobProfileWorkExp,
14313
16185
  modelLedgerBill,
14314
16186
  modelMember,
14315
16187
  modelOrg,
@@ -14324,29 +16196,53 @@ export {
14324
16196
  modelVerification,
14325
16197
  schemaApp,
14326
16198
  schemaAppUpdate,
16199
+ schemaAward,
14327
16200
  schemaBuilding,
14328
16201
  schemaBuildingUnit,
16202
+ schemaCertification,
16203
+ schemaEducation,
16204
+ schemaGroup,
14329
16205
  schemaInviteMember,
14330
16206
  schemaJobApplication,
14331
16207
  schemaJobPost,
14332
16208
  schemaJobPostUpdate,
16209
+ schemaJobProfile,
16210
+ schemaJobProfileAdditionalInfo,
16211
+ schemaJobProfileCert,
16212
+ schemaJobProfileCertDel,
16213
+ schemaJobProfileContactInfo,
16214
+ schemaJobProfileEdu,
16215
+ schemaJobProfileEduDel,
16216
+ schemaJobProfileLang,
16217
+ schemaJobProfileLangDel,
16218
+ schemaJobProfilePersonalInfo,
16219
+ schemaJobProfileSkill,
16220
+ schemaJobProfileSkillDel,
16221
+ schemaJobProfileSummary,
16222
+ schemaJobProfileWorkExp,
16223
+ schemaJobProfileWorkExpDel,
16224
+ schemaLanguage,
14333
16225
  schemaLedgerBill,
14334
16226
  schemaLedgerBillingSummary,
14335
16227
  schemaMember,
14336
16228
  schemaMemberRole,
14337
16229
  schemaMemberStatus,
16230
+ schemaMilitaryExp,
14338
16231
  schemaOrg,
14339
16232
  schemaOrgAdd,
14340
16233
  schemaOrgPilot,
14341
16234
  schemaOrgUpdate,
16235
+ schemaPatent,
14342
16236
  schemaPermission,
14343
16237
  schemaPermissionGroup,
14344
16238
  schemaPermissionGroupUpdate,
14345
16239
  schemaPermissionUpdate,
14346
16240
  schemaPlan,
14347
16241
  schemaPromo,
16242
+ schemaPublication,
14348
16243
  schemaRole,
14349
16244
  schemaRoleUpdate,
16245
+ schemaSkill,
14350
16246
  schemaSubscribe,
14351
16247
  schemaSubscription,
14352
16248
  schemaSubscriptionCompute,
@@ -14358,6 +16254,7 @@ export {
14358
16254
  schemaUser,
14359
16255
  schemaVerification,
14360
16256
  schemaVerificationOrgInvite,
16257
+ schemaWorkExp,
14361
16258
  transactionSchema,
14362
16259
  useAppController,
14363
16260
  useAppRepo,
@@ -14381,6 +16278,8 @@ export {
14381
16278
  useJobPostController,
14382
16279
  useJobPostRepo,
14383
16280
  useJobPostService,
16281
+ useJobProfileCtrl,
16282
+ useJobProfileRepo,
14384
16283
  useLedgerBillingController,
14385
16284
  useLedgerBillingRepo,
14386
16285
  useMemberController,