@goweekdays/core 2.10.0 → 2.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -11980,10 +11980,15 @@ var import_mongodb29 = require("mongodb");
11980
11980
  var schemaJobPost = import_joi50.default.object({
11981
11981
  _id: import_joi50.default.string().hex().optional(),
11982
11982
  org: import_joi50.default.string().hex().required(),
11983
+ orgName: import_joi50.default.string().optional().allow("", null),
11983
11984
  title: import_joi50.default.string().trim().required(),
11984
11985
  setup: import_joi50.default.string().trim().required(),
11985
11986
  location: import_joi50.default.string().trim().required(),
11986
11987
  type: import_joi50.default.string().trim().required(),
11988
+ minSalary: import_joi50.default.number().optional(),
11989
+ maxSalary: import_joi50.default.number().optional(),
11990
+ currency: import_joi50.default.string().trim().optional(),
11991
+ payPeriod: import_joi50.default.string().trim().optional(),
11987
11992
  description: import_joi50.default.string().trim().required(),
11988
11993
  status: import_joi50.default.string().trim().optional().allow("", null),
11989
11994
  createdAt: import_joi50.default.date().optional(),
@@ -11996,6 +12001,10 @@ var schemaJobPostUpdate = import_joi50.default.object({
11996
12001
  setup: import_joi50.default.string().trim().required(),
11997
12002
  location: import_joi50.default.string().trim().required(),
11998
12003
  type: import_joi50.default.string().trim().required(),
12004
+ minSalary: import_joi50.default.number().optional(),
12005
+ maxSalary: import_joi50.default.number().optional(),
12006
+ currency: import_joi50.default.string().trim().optional(),
12007
+ payPeriod: import_joi50.default.string().trim().optional(),
11999
12008
  description: import_joi50.default.string().trim().required()
12000
12009
  });
12001
12010
  function modelJobPost(value) {
@@ -12018,21 +12027,26 @@ function modelJobPost(value) {
12018
12027
  return {
12019
12028
  _id: value._id,
12020
12029
  org: value.org,
12030
+ orgName: value.orgName ?? "",
12021
12031
  title: value.title,
12022
12032
  setup: value.setup,
12023
12033
  location: value.location,
12024
12034
  type: value.type,
12035
+ minSalary: value.minSalary,
12036
+ maxSalary: value.maxSalary ?? 0,
12037
+ currency: value.currency ?? "PHP",
12038
+ payPeriod: value.payPeriod ?? "monthly",
12025
12039
  description: value.description,
12026
12040
  status: value.status ?? "draft",
12027
12041
  createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
12028
- updatedAt: value.updatedAt,
12029
- deletedAt: value.deletedAt
12042
+ updatedAt: value.updatedAt ?? "",
12043
+ deletedAt: value.deletedAt ?? ""
12030
12044
  };
12031
12045
  }
12032
12046
 
12033
12047
  // src/resources/job-post/job.post.controller.ts
12034
- var import_joi52 = __toESM(require("joi"));
12035
- var import_utils69 = require("@goweekdays/utils");
12048
+ var import_joi53 = __toESM(require("joi"));
12049
+ var import_utils71 = require("@goweekdays/utils");
12036
12050
 
12037
12051
  // src/resources/job-post/job.post.repository.ts
12038
12052
  var import_utils67 = require("@goweekdays/utils");
@@ -12131,6 +12145,11 @@ function useJobPostRepo() {
12131
12145
  {
12132
12146
  $project: {
12133
12147
  _id: 1,
12148
+ orgName: 1,
12149
+ minSalary: 1,
12150
+ maxSalary: 1,
12151
+ currency: 1,
12152
+ payPeriod: 1,
12134
12153
  title: 1,
12135
12154
  setup: 1,
12136
12155
  location: 1,
@@ -12158,13 +12177,7 @@ function useJobPostRepo() {
12158
12177
  throw error;
12159
12178
  }
12160
12179
  }
12161
- async function getJobPostsByOrg({
12162
- search = "",
12163
- page = 1,
12164
- limit = 10,
12165
- org = "",
12166
- status = "active"
12167
- } = {}) {
12180
+ async function getJobPostsByOrg({ search = "", page = 1, limit = 10, org = "", status = "active" } = {}) {
12168
12181
  page = page > 0 ? page - 1 : 0;
12169
12182
  try {
12170
12183
  org = new import_mongodb30.ObjectId(org);
@@ -12355,53 +12368,310 @@ function useJobPostRepo() {
12355
12368
  }
12356
12369
 
12357
12370
  // src/resources/job-post/job.post.service.ts
12371
+ var import_utils70 = require("@goweekdays/utils");
12372
+ var import_joi52 = __toESM(require("joi"));
12373
+
12374
+ // src/resources/job-post/job.post.attr.repository.ts
12375
+ var import_utils69 = require("@goweekdays/utils");
12376
+
12377
+ // src/resources/job-post/job.post.attr.model.ts
12358
12378
  var import_utils68 = require("@goweekdays/utils");
12359
12379
  var import_joi51 = __toESM(require("joi"));
12380
+ var import_mongodb31 = require("mongodb");
12381
+ var schemaJobPostAttr = import_joi51.default.string().min(2).max(100).required();
12382
+ function modelJobPostAttr(value) {
12383
+ const { error } = schemaJobPostAttr.validate(value.name);
12384
+ if (error) {
12385
+ throw new import_utils68.BadRequestError(`Invalid job post attribute: ${error.message}`);
12386
+ }
12387
+ if (value._id && typeof value._id === "string") {
12388
+ try {
12389
+ value._id = new import_mongodb31.ObjectId(value._id);
12390
+ } catch (error2) {
12391
+ throw new import_utils68.BadRequestError(`Invalid job post attribute id: ${error2}`);
12392
+ }
12393
+ }
12394
+ return {
12395
+ _id: value._id,
12396
+ name: value.name,
12397
+ createdAt: value.createdAt ?? /* @__PURE__ */ new Date()
12398
+ };
12399
+ }
12400
+
12401
+ // src/resources/job-post/job.post.attr.repository.ts
12402
+ function useJobPostAttrRepo(namespace_collection) {
12403
+ const db = import_utils69.useAtlas.getDb();
12404
+ if (!db) {
12405
+ throw new import_utils69.BadRequestError("Unable to connect to server.");
12406
+ }
12407
+ const collection = db.collection(namespace_collection);
12408
+ const { getCache, setCache, delNamespace } = (0, import_utils69.useCache)(namespace_collection);
12409
+ function delCachedData() {
12410
+ delNamespace().then(() => {
12411
+ import_utils69.logger.log({
12412
+ level: "info",
12413
+ message: `Cache namespace cleared for ${namespace_collection}`
12414
+ });
12415
+ }).catch((err) => {
12416
+ import_utils69.logger.log({
12417
+ level: "error",
12418
+ message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
12419
+ });
12420
+ });
12421
+ }
12422
+ async function createIndexes() {
12423
+ try {
12424
+ await collection.createIndexes([
12425
+ { key: { name: 1 } },
12426
+ { key: { createdAt: 1 } },
12427
+ { key: { name: "text" } },
12428
+ { key: { name: 1 }, unique: true, name: "unique_location" }
12429
+ ]);
12430
+ return "Successfully created job post location indexes.";
12431
+ } catch (error) {
12432
+ throw new import_utils69.BadRequestError("Failed to create job post location indexes.");
12433
+ }
12434
+ }
12435
+ async function add(value, session) {
12436
+ try {
12437
+ value = modelJobPostAttr(value);
12438
+ const res = await collection.insertOne(value, { session });
12439
+ delCachedData();
12440
+ return res.insertedId;
12441
+ } catch (error) {
12442
+ import_utils69.logger.log({
12443
+ level: "error",
12444
+ message: error.message
12445
+ });
12446
+ throw new import_utils69.BadRequestError(
12447
+ `Failed to create job post location: ${error.message}`
12448
+ );
12449
+ }
12450
+ }
12451
+ async function getAll({ search = "", page = 1, limit = 10 } = {}) {
12452
+ page = page > 0 ? page - 1 : 0;
12453
+ const query = {};
12454
+ if (search) {
12455
+ query.$text = { $search: search };
12456
+ }
12457
+ const cacheKey = (0, import_utils69.makeCacheKey)(namespace_collection, {
12458
+ search,
12459
+ page,
12460
+ limit
12461
+ });
12462
+ import_utils69.logger.log({
12463
+ level: "info",
12464
+ message: `Cache key for getAll job post locations: ${cacheKey}`
12465
+ });
12466
+ try {
12467
+ const cached = await getCache(cacheKey);
12468
+ if (cached) {
12469
+ import_utils69.logger.log({
12470
+ level: "info",
12471
+ message: `Cache hit for getAll job post locations: ${cacheKey}`
12472
+ });
12473
+ return cached;
12474
+ }
12475
+ let items = await collection.aggregate([
12476
+ { $match: query },
12477
+ { $skip: page * limit },
12478
+ { $limit: limit }
12479
+ ]).toArray();
12480
+ if (items) {
12481
+ items = items.map((item) => item.name);
12482
+ }
12483
+ const length = await collection.countDocuments(query);
12484
+ const data = (0, import_utils69.paginate)(items, page, limit, length);
12485
+ setCache(cacheKey, data, 600).then(() => {
12486
+ import_utils69.logger.log({
12487
+ level: "info",
12488
+ message: `Cache set for getAll job post locations: ${cacheKey}`
12489
+ });
12490
+ }).catch((err) => {
12491
+ import_utils69.logger.log({
12492
+ level: "error",
12493
+ message: `Failed to set cache for getAll job post locations: ${err.message}`
12494
+ });
12495
+ });
12496
+ return data;
12497
+ } catch (error) {
12498
+ import_utils69.logger.log({ level: "error", message: `${error}` });
12499
+ throw error;
12500
+ }
12501
+ }
12502
+ async function getByName(name) {
12503
+ const cacheKey = (0, import_utils69.makeCacheKey)(namespace_collection, {
12504
+ name,
12505
+ tag: "by-name"
12506
+ });
12507
+ try {
12508
+ const cached = await getCache(cacheKey);
12509
+ if (cached) {
12510
+ import_utils69.logger.log({
12511
+ level: "info",
12512
+ message: `Cache hit for getById job post location: ${cacheKey}`
12513
+ });
12514
+ return cached;
12515
+ }
12516
+ const result = await collection.findOne({ name });
12517
+ setCache(cacheKey, result, 300).then(() => {
12518
+ import_utils69.logger.log({
12519
+ level: "info",
12520
+ message: `Cache set for job post by location: ${cacheKey}`
12521
+ });
12522
+ }).catch((err) => {
12523
+ import_utils69.logger.log({
12524
+ level: "error",
12525
+ message: `Failed to set cache for job post by location: ${err.message}`
12526
+ });
12527
+ });
12528
+ return result;
12529
+ } catch (error) {
12530
+ if (error instanceof import_utils69.AppError) {
12531
+ throw error;
12532
+ } else {
12533
+ throw new import_utils69.InternalServerError("Failed to get job post.");
12534
+ }
12535
+ }
12536
+ }
12537
+ return {
12538
+ createIndexes,
12539
+ delCachedData,
12540
+ add,
12541
+ getAll,
12542
+ getByName
12543
+ };
12544
+ }
12545
+
12546
+ // src/resources/job-post/job.post.service.ts
12360
12547
  function useJobPostService() {
12361
- const { deleteById: _deleteById } = useJobPostRepo();
12548
+ const {
12549
+ add: _add,
12550
+ deleteById: _deleteById,
12551
+ getById: _getById,
12552
+ updateStatusById: _updateStatusById
12553
+ } = useJobPostRepo();
12554
+ const { getById: getOrgById } = useOrgRepo();
12555
+ const { getByName: getLocationByName, add: addLocation } = useJobPostAttrRepo("job.post.locations");
12556
+ const { getByName: getJobTitleByName, add: addJobTitle } = useJobPostAttrRepo("job.post.titles");
12557
+ const { getByName: getCurrencyByName, add: addCurrency } = useJobPostAttrRepo(
12558
+ "job.post.currencies"
12559
+ );
12560
+ async function add(value) {
12561
+ const session = import_utils70.useAtlas.getClient()?.startSession();
12562
+ if (!session) {
12563
+ throw new import_utils70.InternalServerError("Failed to start database session.");
12564
+ }
12565
+ try {
12566
+ session.startTransaction();
12567
+ const org = await getOrgById(String(value.org));
12568
+ if (!org) {
12569
+ throw new import_utils70.BadRequestError("Organization not found.");
12570
+ }
12571
+ const location = await getLocationByName(value.location);
12572
+ if (!location) {
12573
+ await addLocation({ name: value.location }, session);
12574
+ }
12575
+ const jobTitle = await getJobTitleByName(value.title);
12576
+ if (!jobTitle) {
12577
+ await addJobTitle({ name: value.title }, session);
12578
+ }
12579
+ if (value.currency) {
12580
+ const currency = await getCurrencyByName(value.currency);
12581
+ if (!currency) {
12582
+ await addCurrency({ name: value.currency }, session);
12583
+ }
12584
+ }
12585
+ value.orgName = org.name;
12586
+ await _add(value, session);
12587
+ await session.commitTransaction();
12588
+ return "Successfully created job post.";
12589
+ } catch (error) {
12590
+ await session.abortTransaction();
12591
+ if (error instanceof import_utils70.AppError) {
12592
+ throw error;
12593
+ }
12594
+ throw new import_utils70.InternalServerError("Failed to create job post.");
12595
+ } finally {
12596
+ await session.endSession();
12597
+ }
12598
+ }
12362
12599
  async function deleteById(id) {
12363
- const { error } = import_joi51.default.string().hex().required().validate(id);
12600
+ const { error } = import_joi52.default.string().hex().required().validate(id);
12364
12601
  if (error) {
12365
- throw new import_utils68.BadRequestError(error.message);
12602
+ throw new import_utils70.BadRequestError(error.message);
12366
12603
  }
12367
12604
  try {
12368
12605
  await _deleteById(id);
12369
12606
  return "Successfully deleted job post.";
12370
12607
  } catch (error2) {
12371
- if (error2 instanceof import_utils68.AppError) {
12608
+ if (error2 instanceof import_utils70.AppError) {
12372
12609
  throw error2;
12373
12610
  } else {
12374
- throw new import_utils68.InternalServerError("Failed to delete job post.");
12611
+ throw new import_utils70.InternalServerError("Failed to delete job post.");
12612
+ }
12613
+ }
12614
+ }
12615
+ async function updateStatusById(id, newStatus) {
12616
+ const jobPost = await _getById(id);
12617
+ if (!jobPost) {
12618
+ throw new import_utils70.BadRequestError("Job post not found.");
12619
+ }
12620
+ const currentStatus = jobPost.status ?? "draft";
12621
+ const allowedTransitions = {
12622
+ draft: ["open", "in-review", "deleted"],
12623
+ open: ["paused", "closed"],
12624
+ paused: ["open", "in-review", "deleted"],
12625
+ "in-review": ["open"],
12626
+ closed: ["open", "in-review", "draft", "deleted"]
12627
+ };
12628
+ const allowed = allowedTransitions[currentStatus];
12629
+ if (!allowed || !allowed.includes(newStatus)) {
12630
+ throw new import_utils70.BadRequestError(
12631
+ `Cannot change status from "${currentStatus}" to "${newStatus}".`
12632
+ );
12633
+ }
12634
+ try {
12635
+ await _updateStatusById(id, newStatus);
12636
+ return "Successfully updated job post status.";
12637
+ } catch (error) {
12638
+ if (error instanceof import_utils70.AppError) {
12639
+ throw error;
12375
12640
  }
12641
+ throw new import_utils70.InternalServerError("Failed to update job post status.");
12376
12642
  }
12377
12643
  }
12378
12644
  return {
12379
- deleteById
12645
+ add,
12646
+ deleteById,
12647
+ updateStatusById
12380
12648
  };
12381
12649
  }
12382
12650
 
12383
12651
  // src/resources/job-post/job.post.controller.ts
12384
12652
  function useJobPostController() {
12385
12653
  const {
12386
- add: _add,
12387
12654
  getAll: _getAll,
12388
12655
  getJobPostsByOrg: _getJobPostsByOrg,
12389
12656
  getById: _getById,
12390
- updateById: _updateById,
12391
- updateStatusById: _updateStatusById
12657
+ updateById: _updateById
12392
12658
  } = useJobPostRepo();
12393
- const { deleteById: _deleteById } = useJobPostService();
12659
+ const {
12660
+ add: _add,
12661
+ deleteById: _deleteById,
12662
+ updateStatusById: _updateStatusById
12663
+ } = useJobPostService();
12394
12664
  async function add(req, res, next) {
12395
12665
  const value = req.body;
12396
12666
  const { error } = schemaJobPost.validate(value);
12397
12667
  if (error) {
12398
- next(new import_utils69.BadRequestError(error.message));
12399
- import_utils69.logger.info(`Controller: ${error.message}`);
12668
+ next(new import_utils71.BadRequestError(error.message));
12669
+ import_utils71.logger.info(`Controller: ${error.message}`);
12400
12670
  return;
12401
12671
  }
12402
12672
  try {
12403
- const result = await _add(value);
12404
- res.json({ message: "Successfully created job post.", data: { result } });
12673
+ const message = await _add(value);
12674
+ res.json({ message });
12405
12675
  return;
12406
12676
  } catch (error2) {
12407
12677
  next(error2);
@@ -12409,29 +12679,29 @@ function useJobPostController() {
12409
12679
  }
12410
12680
  async function getAll(req, res, next) {
12411
12681
  const query = req.query;
12412
- const validation = import_joi52.default.object({
12413
- page: import_joi52.default.number().min(1).optional().allow("", null),
12414
- limit: import_joi52.default.number().min(1).optional().allow("", null),
12415
- search: import_joi52.default.string().optional().allow("", null),
12416
- status: import_joi52.default.string().optional()
12682
+ const validation = import_joi53.default.object({
12683
+ page: import_joi53.default.number().min(1).optional().allow("", null),
12684
+ limit: import_joi53.default.number().min(1).optional().allow("", null),
12685
+ search: import_joi53.default.string().optional().allow("", null),
12686
+ status: import_joi53.default.string().optional()
12417
12687
  });
12418
12688
  const { error } = validation.validate(query);
12419
12689
  const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
12420
12690
  const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
12421
12691
  const search = req.query.search ?? "";
12422
- const status = req.query.status ?? "active";
12692
+ const status = req.query.status ?? "open";
12423
12693
  const isPageNumber = isFinite(page);
12424
12694
  if (!isPageNumber) {
12425
- next(new import_utils69.BadRequestError("Invalid page number."));
12695
+ next(new import_utils71.BadRequestError("Invalid page number."));
12426
12696
  return;
12427
12697
  }
12428
12698
  const isLimitNumber = isFinite(limit);
12429
12699
  if (!isLimitNumber) {
12430
- next(new import_utils69.BadRequestError("Invalid limit number."));
12700
+ next(new import_utils71.BadRequestError("Invalid limit number."));
12431
12701
  return;
12432
12702
  }
12433
12703
  if (error) {
12434
- next(new import_utils69.BadRequestError(error.message));
12704
+ next(new import_utils71.BadRequestError(error.message));
12435
12705
  return;
12436
12706
  }
12437
12707
  try {
@@ -12450,28 +12720,34 @@ function useJobPostController() {
12450
12720
  const org = req.params.org ?? "";
12451
12721
  const isPageNumber = isFinite(page);
12452
12722
  if (!isPageNumber) {
12453
- next(new import_utils69.BadRequestError("Invalid page number."));
12723
+ next(new import_utils71.BadRequestError("Invalid page number."));
12454
12724
  return;
12455
12725
  }
12456
12726
  const isLimitNumber = isFinite(limit);
12457
12727
  if (!isLimitNumber) {
12458
- next(new import_utils69.BadRequestError("Invalid limit number."));
12728
+ next(new import_utils71.BadRequestError("Invalid limit number."));
12459
12729
  return;
12460
12730
  }
12461
- const validation = import_joi52.default.object({
12462
- org: import_joi52.default.string().hex().required(),
12463
- page: import_joi52.default.number().min(1).optional().allow("", null),
12464
- limit: import_joi52.default.number().min(1).optional().allow("", null),
12465
- search: import_joi52.default.string().optional().allow("", null),
12466
- status: import_joi52.default.string().optional()
12731
+ const validation = import_joi53.default.object({
12732
+ org: import_joi53.default.string().hex().required(),
12733
+ page: import_joi53.default.number().min(1).optional().allow("", null),
12734
+ limit: import_joi53.default.number().min(1).optional().allow("", null),
12735
+ search: import_joi53.default.string().optional().allow("", null),
12736
+ status: import_joi53.default.string().optional()
12467
12737
  });
12468
12738
  const { error } = validation.validate({ org, page, limit, search, status });
12469
12739
  if (error) {
12470
- next(new import_utils69.BadRequestError(error.message));
12740
+ next(new import_utils71.BadRequestError(error.message));
12471
12741
  return;
12472
12742
  }
12473
12743
  try {
12474
- const jobPosts = await _getJobPostsByOrg({ org, page, limit, search, status });
12744
+ const jobPosts = await _getJobPostsByOrg({
12745
+ org,
12746
+ page,
12747
+ limit,
12748
+ search,
12749
+ status
12750
+ });
12475
12751
  res.json(jobPosts);
12476
12752
  return;
12477
12753
  } catch (error2) {
@@ -12480,12 +12756,12 @@ function useJobPostController() {
12480
12756
  }
12481
12757
  async function getById(req, res, next) {
12482
12758
  const id = req.params.id;
12483
- const validation = import_joi52.default.object({
12484
- id: import_joi52.default.string().hex().required()
12759
+ const validation = import_joi53.default.object({
12760
+ id: import_joi53.default.string().hex().required()
12485
12761
  });
12486
12762
  const { error } = validation.validate({ id });
12487
12763
  if (error) {
12488
- next(new import_utils69.BadRequestError(error.message));
12764
+ next(new import_utils71.BadRequestError(error.message));
12489
12765
  return;
12490
12766
  }
12491
12767
  try {
@@ -12501,7 +12777,7 @@ function useJobPostController() {
12501
12777
  const payload = req.body;
12502
12778
  const { error } = schemaJobPostUpdate.validate({ _id, ...payload });
12503
12779
  if (error) {
12504
- next(new import_utils69.BadRequestError(error.message));
12780
+ next(new import_utils71.BadRequestError(error.message));
12505
12781
  return;
12506
12782
  }
12507
12783
  try {
@@ -12515,7 +12791,7 @@ function useJobPostController() {
12515
12791
  async function deleteById(req, res, next) {
12516
12792
  const id = req.params.id;
12517
12793
  if (!id) {
12518
- next(new import_utils69.BadRequestError("Job Post ID is required."));
12794
+ next(new import_utils71.BadRequestError("Job Post ID is required."));
12519
12795
  return;
12520
12796
  }
12521
12797
  try {
@@ -12529,13 +12805,13 @@ function useJobPostController() {
12529
12805
  async function updateStatusById(req, res, next) {
12530
12806
  const id = req.params.id;
12531
12807
  const status = req.params.status;
12532
- const validation = import_joi52.default.object({
12533
- id: import_joi52.default.string().hex().required(),
12534
- status: import_joi52.default.string().valid("draft", "open", "paused", "in-review", "closed").required()
12808
+ const validation = import_joi53.default.object({
12809
+ id: import_joi53.default.string().hex().required(),
12810
+ status: import_joi53.default.string().valid("draft", "open", "paused", "in-review", "closed").required()
12535
12811
  });
12536
12812
  const { error } = validation.validate({ id, status });
12537
12813
  if (error) {
12538
- next(new import_utils69.BadRequestError(error.message));
12814
+ next(new import_utils71.BadRequestError(error.message));
12539
12815
  return;
12540
12816
  }
12541
12817
  try {
@@ -12546,6 +12822,110 @@ function useJobPostController() {
12546
12822
  next(error2);
12547
12823
  }
12548
12824
  }
12825
+ const { getAll: _getAllLocation } = useJobPostAttrRepo("job.post.locations");
12826
+ async function getLocations(req, res, next) {
12827
+ const query = req.query;
12828
+ const validation = import_joi53.default.object({
12829
+ page: import_joi53.default.number().min(1).optional().allow("", null),
12830
+ limit: import_joi53.default.number().min(1).optional().allow("", null),
12831
+ search: import_joi53.default.string().optional().allow("", null)
12832
+ });
12833
+ const { error } = validation.validate(query);
12834
+ const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
12835
+ const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
12836
+ const search = req.query.search ?? "";
12837
+ const isPageNumber = isFinite(page);
12838
+ if (!isPageNumber) {
12839
+ next(new import_utils71.BadRequestError("Invalid page number."));
12840
+ return;
12841
+ }
12842
+ const isLimitNumber = isFinite(limit);
12843
+ if (!isLimitNumber) {
12844
+ next(new import_utils71.BadRequestError("Invalid limit number."));
12845
+ return;
12846
+ }
12847
+ if (error) {
12848
+ next(new import_utils71.BadRequestError(error.message));
12849
+ return;
12850
+ }
12851
+ try {
12852
+ const locations = await _getAllLocation({ page, limit, search });
12853
+ res.json(locations);
12854
+ return;
12855
+ } catch (error2) {
12856
+ next(error2);
12857
+ }
12858
+ }
12859
+ const { getAll: _getAllJobTitles } = useJobPostAttrRepo("job.post.titles");
12860
+ async function getJobTitles(req, res, next) {
12861
+ const query = req.query;
12862
+ const validation = import_joi53.default.object({
12863
+ page: import_joi53.default.number().min(1).optional().allow("", null),
12864
+ limit: import_joi53.default.number().min(1).optional().allow("", null),
12865
+ search: import_joi53.default.string().optional().allow("", null)
12866
+ });
12867
+ const { error } = validation.validate(query);
12868
+ const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
12869
+ const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
12870
+ const search = req.query.search ?? "";
12871
+ const isPageNumber = isFinite(page);
12872
+ if (!isPageNumber) {
12873
+ next(new import_utils71.BadRequestError("Invalid page number."));
12874
+ return;
12875
+ }
12876
+ const isLimitNumber = isFinite(limit);
12877
+ if (!isLimitNumber) {
12878
+ next(new import_utils71.BadRequestError("Invalid limit number."));
12879
+ return;
12880
+ }
12881
+ if (error) {
12882
+ next(new import_utils71.BadRequestError(error.message));
12883
+ return;
12884
+ }
12885
+ try {
12886
+ const locations = await _getAllJobTitles({ page, limit, search });
12887
+ res.json(locations);
12888
+ return;
12889
+ } catch (error2) {
12890
+ next(error2);
12891
+ }
12892
+ }
12893
+ const { getAll: _getAllCurrencies } = useJobPostAttrRepo(
12894
+ "job.post.currencies"
12895
+ );
12896
+ async function getCurrencies(req, res, next) {
12897
+ const query = req.query;
12898
+ const validation = import_joi53.default.object({
12899
+ page: import_joi53.default.number().min(1).optional().allow("", null),
12900
+ limit: import_joi53.default.number().min(1).optional().allow("", null),
12901
+ search: import_joi53.default.string().optional().allow("", null)
12902
+ });
12903
+ const { error } = validation.validate(query);
12904
+ const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
12905
+ const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
12906
+ const search = req.query.search ?? "";
12907
+ const isPageNumber = isFinite(page);
12908
+ if (!isPageNumber) {
12909
+ next(new import_utils71.BadRequestError("Invalid page number."));
12910
+ return;
12911
+ }
12912
+ const isLimitNumber = isFinite(limit);
12913
+ if (!isLimitNumber) {
12914
+ next(new import_utils71.BadRequestError("Invalid limit number."));
12915
+ return;
12916
+ }
12917
+ if (error) {
12918
+ next(new import_utils71.BadRequestError(error.message));
12919
+ return;
12920
+ }
12921
+ try {
12922
+ const locations = await _getAllCurrencies({ page, limit, search });
12923
+ res.json(locations);
12924
+ return;
12925
+ } catch (error2) {
12926
+ next(error2);
12927
+ }
12928
+ }
12549
12929
  return {
12550
12930
  add,
12551
12931
  getAll,
@@ -12553,7 +12933,10 @@ function useJobPostController() {
12553
12933
  getById,
12554
12934
  updateById,
12555
12935
  deleteById,
12556
- updateStatusById
12936
+ updateStatusById,
12937
+ getLocations,
12938
+ getJobTitles,
12939
+ getCurrencies
12557
12940
  };
12558
12941
  }
12559
12942
  // Annotate the CommonJS export names for ESM import in node: