@goweekdays/core 2.11.17 → 2.11.19

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @goweekdays/core
2
2
 
3
+ ## 2.11.19
4
+
5
+ ### Patch Changes
6
+
7
+ - dc8a6a1: Add getById and updateStatusById for job applications
8
+
9
+ ## 2.11.18
10
+
11
+ ### Patch Changes
12
+
13
+ - 0574284: Fix query return value
14
+
3
15
  ## 2.11.17
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1163,7 +1163,7 @@ type TJobPost = {
1163
1163
  _id?: ObjectId;
1164
1164
  org: ObjectId | string;
1165
1165
  orgName?: string;
1166
- company: ObjectId;
1166
+ company: ObjectId | string;
1167
1167
  companyName?: string;
1168
1168
  title: string;
1169
1169
  setup: string;
@@ -1276,6 +1276,63 @@ declare function useLedgerBillingController(): {
1276
1276
  getSummary: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1277
1277
  };
1278
1278
 
1279
+ type TJobApplicationMetadata = {
1280
+ resume?: string;
1281
+ resumeUrl?: string;
1282
+ portfolio?: string;
1283
+ portfolioUrl?: string;
1284
+ coverLetter?: string;
1285
+ coverLetterUrl?: string;
1286
+ };
1287
+ type TJobApplication = {
1288
+ _id?: ObjectId;
1289
+ post: ObjectId | string;
1290
+ jobTitle?: string;
1291
+ company?: ObjectId | string;
1292
+ companyName?: string;
1293
+ location?: string;
1294
+ user: ObjectId | string;
1295
+ name: string;
1296
+ email: string;
1297
+ contact?: string;
1298
+ metadata?: TJobApplicationMetadata;
1299
+ status?: string;
1300
+ createdAt?: Date | String;
1301
+ updatedAt?: Date | String;
1302
+ deletedAt?: Date | String;
1303
+ };
1304
+ declare const jobApplicationStatuses: string[];
1305
+ declare const schemaJobApplication: Joi.ObjectSchema<any>;
1306
+ declare function modelJobApplication(data: TJobApplication): TJobApplication;
1307
+
1308
+ declare function useJobApplicationRepo(): {
1309
+ createIndexes: () => Promise<string>;
1310
+ delCachedData: () => void;
1311
+ add: (data: TJobApplication) => Promise<ObjectId>;
1312
+ getAll: ({ page, limit, search, status, }?: {
1313
+ page?: number | undefined;
1314
+ limit?: number | undefined;
1315
+ search?: string | undefined;
1316
+ status?: string | undefined;
1317
+ }) => Promise<{
1318
+ items: any[];
1319
+ pages: number;
1320
+ pageRange: string;
1321
+ } | {
1322
+ data: TJobApplication[];
1323
+ total: number;
1324
+ }>;
1325
+ getById: (_id: string | ObjectId) => Promise<mongodb.WithId<bson.Document> | TJobApplication | null>;
1326
+ updateStatusById: (_id: string | ObjectId, status: string, session?: ClientSession) => Promise<string>;
1327
+ };
1328
+
1329
+ declare function useJobApplicationController(): {
1330
+ add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1331
+ getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1332
+ getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1333
+ updateStatusById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1334
+ };
1335
+
1279
1336
  declare const MONGO_URI: string;
1280
1337
  declare const MONGO_DB: string;
1281
1338
  declare const PORT: number;
@@ -1315,4 +1372,4 @@ declare const XENDIT_BASE_URL: string;
1315
1372
  declare const DOMAIN: string;
1316
1373
  declare const APP_ORG: string;
1317
1374
 
1318
- export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, APP_ORG, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, DOMAIN, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MBuilding, MBuildingUnit, MFile, MONGO_DB, MONGO_URI, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PAYPAL_WEBHOOK_ID, PORT, PaypalWebhookHeaders, REDIS_HOST, REDIS_PASSWORD, REDIS_PORT, REFRESH_TOKEN_EXPIRY, REFRESH_TOKEN_SECRET, SECRET_KEY, SPACES_ACCESS_KEY, SPACES_BUCKET, SPACES_ENDPOINT, SPACES_REGION, SPACES_SECRET_KEY, TApp, TBuilding, TBuildingUnit, TCounter, TFile, TJobPost, TLedgerBill, TMember, TOrg, TPermission, TPermissionGroup, TPlan, TPromo, TRole, TSubscribe, TSubscription, TSubscriptionTransaction, TUser, TVerification, TVerificationMetadata, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, currencies, isDev, ledgerBillStatuses, ledgerBillTypes, modelApp, modelJobPost, modelLedgerBill, modelMember, modelOrg, modelPermission, modelPermissionGroup, modelPlan, modelPromo, modelRole, modelSubscription, modelSubscriptionTransaction, modelUser, modelVerification, schemaApp, schemaAppUpdate, schemaBuilding, schemaBuildingUnit, schemaInviteMember, schemaJobPost, schemaJobPostUpdate, schemaLedgerBill, schemaLedgerBillingSummary, schemaMember, schemaMemberRole, schemaMemberStatus, schemaOrg, schemaOrgAdd, schemaOrgPilot, schemaOrgUpdate, schemaPermission, schemaPermissionGroup, schemaPermissionGroupUpdate, schemaPermissionUpdate, schemaPlan, schemaPromo, schemaRole, schemaRoleUpdate, schemaSubscribe, schemaSubscription, schemaSubscriptionCompute, schemaSubscriptionPromoCode, schemaSubscriptionSeats, schemaSubscriptionTransaction, schemaSubscriptionUpdate, schemaUpdateOptions, schemaUser, schemaVerification, schemaVerificationOrgInvite, transactionSchema, useAppController, useAppRepo, useAppService, useAuthController, useAuthService, useBuildingController, useBuildingRepo, useBuildingService, useBuildingUnitController, useBuildingUnitRepo, useBuildingUnitService, useCounterModel, useCounterRepo, useFileController, useFileRepo, useFileService, useGitHubService, useJobPostController, useJobPostRepo, useJobPostService, useLedgerBillingController, useLedgerBillingRepo, useMemberController, useMemberRepo, useOrgController, useOrgRepo, useOrgService, usePaypalService, usePermissionController, usePermissionGroupController, usePermissionGroupRepo, usePermissionGroupService, usePermissionRepo, usePermissionService, usePlanController, usePlanRepo, usePlanService, usePromoController, usePromoRepo, usePromoUsageRepo, useRoleController, useRoleRepo, useRoleService, useSubscriptionController, useSubscriptionRepo, useSubscriptionService, useSubscriptionTransactionController, useSubscriptionTransactionRepo, useUserController, useUserRepo, useUserService, useUtilController, useVerificationController, useVerificationRepo, useVerificationService };
1375
+ export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, APP_ORG, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, DOMAIN, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MBuilding, MBuildingUnit, MFile, MONGO_DB, MONGO_URI, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PAYPAL_WEBHOOK_ID, PORT, PaypalWebhookHeaders, REDIS_HOST, REDIS_PASSWORD, REDIS_PORT, REFRESH_TOKEN_EXPIRY, REFRESH_TOKEN_SECRET, SECRET_KEY, SPACES_ACCESS_KEY, SPACES_BUCKET, SPACES_ENDPOINT, SPACES_REGION, SPACES_SECRET_KEY, TApp, TBuilding, TBuildingUnit, TCounter, TFile, TJobApplication, TJobApplicationMetadata, TJobPost, TLedgerBill, TMember, TOrg, TPermission, TPermissionGroup, TPlan, TPromo, TRole, TSubscribe, TSubscription, TSubscriptionTransaction, TUser, TVerification, TVerificationMetadata, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, currencies, isDev, jobApplicationStatuses, ledgerBillStatuses, ledgerBillTypes, modelApp, modelJobApplication, modelJobPost, modelLedgerBill, modelMember, modelOrg, modelPermission, modelPermissionGroup, modelPlan, modelPromo, modelRole, modelSubscription, modelSubscriptionTransaction, modelUser, modelVerification, schemaApp, schemaAppUpdate, schemaBuilding, schemaBuildingUnit, schemaInviteMember, schemaJobApplication, schemaJobPost, schemaJobPostUpdate, schemaLedgerBill, schemaLedgerBillingSummary, schemaMember, schemaMemberRole, schemaMemberStatus, schemaOrg, schemaOrgAdd, schemaOrgPilot, schemaOrgUpdate, schemaPermission, schemaPermissionGroup, schemaPermissionGroupUpdate, schemaPermissionUpdate, schemaPlan, schemaPromo, schemaRole, schemaRoleUpdate, schemaSubscribe, schemaSubscription, schemaSubscriptionCompute, schemaSubscriptionPromoCode, schemaSubscriptionSeats, schemaSubscriptionTransaction, schemaSubscriptionUpdate, schemaUpdateOptions, schemaUser, schemaVerification, schemaVerificationOrgInvite, transactionSchema, useAppController, useAppRepo, useAppService, useAuthController, useAuthService, useBuildingController, useBuildingRepo, useBuildingService, useBuildingUnitController, useBuildingUnitRepo, useBuildingUnitService, useCounterModel, useCounterRepo, useFileController, useFileRepo, useFileService, useGitHubService, useJobApplicationController, useJobApplicationRepo, useJobPostController, useJobPostRepo, useJobPostService, useLedgerBillingController, useLedgerBillingRepo, useMemberController, useMemberRepo, useOrgController, useOrgRepo, useOrgService, usePaypalService, usePermissionController, usePermissionGroupController, usePermissionGroupRepo, usePermissionGroupService, usePermissionRepo, usePermissionService, usePlanController, usePlanRepo, usePlanService, usePromoController, usePromoRepo, usePromoUsageRepo, useRoleController, useRoleRepo, useRoleService, useSubscriptionController, useSubscriptionRepo, useSubscriptionService, useSubscriptionTransactionController, useSubscriptionTransactionRepo, useUserController, useUserRepo, useUserService, useUtilController, useVerificationController, useVerificationRepo, useVerificationService };
package/dist/index.js CHANGED
@@ -72,9 +72,11 @@ __export(src_exports, {
72
72
  XENDIT_SECRET_KEY: () => XENDIT_SECRET_KEY,
73
73
  currencies: () => currencies,
74
74
  isDev: () => isDev,
75
+ jobApplicationStatuses: () => jobApplicationStatuses,
75
76
  ledgerBillStatuses: () => ledgerBillStatuses,
76
77
  ledgerBillTypes: () => ledgerBillTypes,
77
78
  modelApp: () => modelApp,
79
+ modelJobApplication: () => modelJobApplication,
78
80
  modelJobPost: () => modelJobPost,
79
81
  modelLedgerBill: () => modelLedgerBill,
80
82
  modelMember: () => modelMember,
@@ -93,6 +95,7 @@ __export(src_exports, {
93
95
  schemaBuilding: () => schemaBuilding,
94
96
  schemaBuildingUnit: () => schemaBuildingUnit,
95
97
  schemaInviteMember: () => schemaInviteMember,
98
+ schemaJobApplication: () => schemaJobApplication,
96
99
  schemaJobPost: () => schemaJobPost,
97
100
  schemaJobPostUpdate: () => schemaJobPostUpdate,
98
101
  schemaLedgerBill: () => schemaLedgerBill,
@@ -141,6 +144,8 @@ __export(src_exports, {
141
144
  useFileRepo: () => useFileRepo,
142
145
  useFileService: () => useFileService,
143
146
  useGitHubService: () => useGitHubService,
147
+ useJobApplicationController: () => useJobApplicationController,
148
+ useJobApplicationRepo: () => useJobApplicationRepo,
144
149
  useJobPostController: () => useJobPostController,
145
150
  useJobPostRepo: () => useJobPostRepo,
146
151
  useJobPostService: () => useJobPostService,
@@ -12974,10 +12979,12 @@ function modelJobPost(value) {
12974
12979
  } catch (error2) {
12975
12980
  throw new import_utils66.BadRequestError("Invalid Org ID");
12976
12981
  }
12977
- try {
12978
- value.company = new import_mongodb29.ObjectId(value.company);
12979
- } catch (error2) {
12980
- throw new import_utils66.BadRequestError("Invalid Company ID");
12982
+ if (value.company && typeof value.company === "string" && value.company.length === 24) {
12983
+ try {
12984
+ value.company = new import_mongodb29.ObjectId(value.company);
12985
+ } catch (error2) {
12986
+ throw new import_utils66.BadRequestError("Invalid Company ID");
12987
+ }
12981
12988
  }
12982
12989
  return {
12983
12990
  _id: value._id,
@@ -13102,7 +13109,11 @@ function useJobPostRepo() {
13102
13109
  {
13103
13110
  $project: {
13104
13111
  _id: 1,
13112
+ org: 1,
13105
13113
  orgName: 1,
13114
+ company: 1,
13115
+ companyName: 1,
13116
+ description: 1,
13106
13117
  minSalary: 1,
13107
13118
  maxSalary: 1,
13108
13119
  currency: 1,
@@ -13896,6 +13907,463 @@ function useJobPostController() {
13896
13907
  getCurrencies
13897
13908
  };
13898
13909
  }
13910
+
13911
+ // src/resources/job-applications/job.applications.model.ts
13912
+ var import_utils72 = require("@goweekdays/utils");
13913
+ var import_joi54 = __toESM(require("joi"));
13914
+ var import_mongodb32 = require("mongodb");
13915
+ var jobApplicationStatuses = [
13916
+ "new",
13917
+ "shortlisted",
13918
+ "interview-scheduled",
13919
+ "interviewed",
13920
+ "offer-extended",
13921
+ "hired",
13922
+ "on-hold",
13923
+ "withdrawn",
13924
+ "rejected",
13925
+ // Agency specific
13926
+ "contacted",
13927
+ "endorsed",
13928
+ "client-interested",
13929
+ "pooled",
13930
+ // HR specific
13931
+ "under-review",
13932
+ "for-approval"
13933
+ ];
13934
+ var schemaJobApplication = import_joi54.default.object({
13935
+ post: import_joi54.default.string().required(),
13936
+ jobTitle: import_joi54.default.string().optional().allow(""),
13937
+ company: import_joi54.default.string().hex().optional().allow(""),
13938
+ companyName: import_joi54.default.string().optional().allow(""),
13939
+ location: import_joi54.default.string().optional().allow(""),
13940
+ user: import_joi54.default.string().required(),
13941
+ name: import_joi54.default.string().required(),
13942
+ email: import_joi54.default.string().email().required(),
13943
+ contact: import_joi54.default.string().optional().allow(""),
13944
+ metadata: import_joi54.default.object({
13945
+ resume: import_joi54.default.string().optional().allow(""),
13946
+ resumeUrl: import_joi54.default.string().uri().optional().allow(""),
13947
+ portfolio: import_joi54.default.string().optional().allow(""),
13948
+ portfolioUrl: import_joi54.default.string().uri().optional().allow(""),
13949
+ coverLetter: import_joi54.default.string().optional().allow(""),
13950
+ coverLetterUrl: import_joi54.default.string().uri().optional().allow("")
13951
+ }).optional()
13952
+ });
13953
+ function modelJobApplication(data) {
13954
+ const { error } = schemaJobApplication.validate(data);
13955
+ if (error) {
13956
+ throw new import_utils72.BadRequestError(`Invalid job application data: ${error.message}`);
13957
+ }
13958
+ if (data._id && typeof data._id === "string") {
13959
+ try {
13960
+ data._id = new import_mongodb32.ObjectId(data._id);
13961
+ } catch (error2) {
13962
+ throw new import_utils72.BadRequestError(`Invalid job application _id: ${data._id}`);
13963
+ }
13964
+ }
13965
+ try {
13966
+ data.post = new import_mongodb32.ObjectId(data.post);
13967
+ } catch (error2) {
13968
+ throw new import_utils72.BadRequestError(`Invalid job application post id: ${data.post}`);
13969
+ }
13970
+ try {
13971
+ data.user = new import_mongodb32.ObjectId(data.user);
13972
+ } catch (error2) {
13973
+ throw new import_utils72.BadRequestError(`Invalid job application user id: ${data.user}`);
13974
+ }
13975
+ if (data.company && typeof data.company === "string") {
13976
+ try {
13977
+ data.company = new import_mongodb32.ObjectId(data.company);
13978
+ } catch (error2) {
13979
+ throw new import_utils72.BadRequestError(
13980
+ `Invalid job application company id: ${data.company}`
13981
+ );
13982
+ }
13983
+ }
13984
+ return {
13985
+ _id: data._id,
13986
+ post: data.post,
13987
+ jobTitle: data.jobTitle,
13988
+ company: data.company,
13989
+ companyName: data.companyName ?? "",
13990
+ location: data.location ?? "",
13991
+ user: data.user,
13992
+ name: data.name,
13993
+ email: data.email,
13994
+ contact: data.contact ?? "",
13995
+ metadata: data.metadata ?? {},
13996
+ status: data.status ?? "new",
13997
+ createdAt: data.createdAt ?? /* @__PURE__ */ new Date(),
13998
+ updatedAt: data.updatedAt ?? "",
13999
+ deletedAt: data.deletedAt ?? ""
14000
+ };
14001
+ }
14002
+
14003
+ // src/resources/job-applications/job.application.repository.ts
14004
+ var import_utils73 = require("@goweekdays/utils");
14005
+ var import_mongodb33 = require("mongodb");
14006
+ var import_joi55 = __toESM(require("joi"));
14007
+ function useJobApplicationRepo() {
14008
+ const db = import_utils73.useAtlas.getDb();
14009
+ if (!db) {
14010
+ throw new import_utils73.BadRequestError("Unable to connect to server.");
14011
+ }
14012
+ const namespace_collection = "job.applications";
14013
+ const collection = db.collection(namespace_collection);
14014
+ const { getCache, setCache, delNamespace } = (0, import_utils73.useCache)(namespace_collection);
14015
+ function delCachedData() {
14016
+ delNamespace().then(() => {
14017
+ import_utils73.logger.log({
14018
+ level: "info",
14019
+ message: `Cache namespace cleared for ${namespace_collection}`
14020
+ });
14021
+ }).catch((err) => {
14022
+ import_utils73.logger.log({
14023
+ level: "error",
14024
+ message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
14025
+ });
14026
+ });
14027
+ }
14028
+ async function createIndexes() {
14029
+ try {
14030
+ await collection.createIndexes([
14031
+ { key: { jobTitle: 1 } },
14032
+ { key: { company: 1 } },
14033
+ { key: { companyName: 1 } },
14034
+ { key: { location: 1 } },
14035
+ { key: { user: 1 } },
14036
+ { key: { email: 1 } },
14037
+ {
14038
+ key: {
14039
+ jobTitle: "text",
14040
+ company: "text",
14041
+ companyName: "text",
14042
+ location: "text",
14043
+ name: "text"
14044
+ },
14045
+ name: "job_application_text_search"
14046
+ }
14047
+ ]);
14048
+ return "Successfully created job application indexes.";
14049
+ } catch (error) {
14050
+ throw new import_utils73.BadRequestError("Failed to create job application indexes.");
14051
+ }
14052
+ }
14053
+ async function add(data) {
14054
+ const { error } = schemaJobApplication.validate(data);
14055
+ if (error) {
14056
+ throw new import_utils73.BadRequestError(
14057
+ `Invalid job application data: ${error.message}`
14058
+ );
14059
+ }
14060
+ try {
14061
+ data = modelJobApplication(data);
14062
+ const res = await collection.insertOne(data);
14063
+ delCachedData();
14064
+ return res.insertedId;
14065
+ } catch (error2) {
14066
+ if (error2 instanceof import_utils73.AppError) {
14067
+ throw error2;
14068
+ }
14069
+ throw new import_utils73.BadRequestError(
14070
+ `Failed to create job application: ${error2.message}`
14071
+ );
14072
+ }
14073
+ }
14074
+ async function getAll({
14075
+ page = 1,
14076
+ limit = 10,
14077
+ search = "",
14078
+ status = "new"
14079
+ } = {}) {
14080
+ page = page > 0 ? page - 1 : 0;
14081
+ const query = { status };
14082
+ const cacheKeyOptions = {
14083
+ page,
14084
+ limit,
14085
+ status,
14086
+ tag: "getAll"
14087
+ };
14088
+ if (search) {
14089
+ query.$text = { $search: search };
14090
+ cacheKeyOptions.search = search;
14091
+ }
14092
+ const cacheKey = (0, import_utils73.makeCacheKey)(namespace_collection, cacheKeyOptions);
14093
+ const cachedData = await getCache(cacheKey);
14094
+ if (cachedData) {
14095
+ return cachedData;
14096
+ }
14097
+ try {
14098
+ const items = await collection.aggregate([
14099
+ { $match: query },
14100
+ { $skip: page * limit },
14101
+ { $limit: limit }
14102
+ ]).toArray();
14103
+ const length = await collection.countDocuments(query);
14104
+ const data = (0, import_utils73.paginate)(items, page, limit, length);
14105
+ setCache(cacheKey, data).then(() => {
14106
+ import_utils73.logger.log({
14107
+ level: "info",
14108
+ message: `Cache set for getAll job applications: ${cacheKey}`
14109
+ });
14110
+ }).catch((err) => {
14111
+ import_utils73.logger.log({
14112
+ level: "error",
14113
+ message: `Failed to set cache for getAll job applications: ${cacheKey}, error: ${err.message}`
14114
+ });
14115
+ });
14116
+ return data;
14117
+ } catch (error) {
14118
+ if (error instanceof import_utils73.AppError) {
14119
+ throw error;
14120
+ }
14121
+ throw new import_utils73.BadRequestError(
14122
+ `Failed to get job applications: ${error.message}`
14123
+ );
14124
+ }
14125
+ }
14126
+ async function getById(_id) {
14127
+ const { error } = import_joi55.default.string().hex().length(24).validate(_id);
14128
+ if (error) {
14129
+ throw new import_utils73.BadRequestError(`Invalid job application id: ${_id}`);
14130
+ }
14131
+ try {
14132
+ _id = new import_mongodb33.ObjectId(_id);
14133
+ } catch (error2) {
14134
+ throw new import_utils73.BadRequestError(`Invalid job application id: ${_id}`);
14135
+ }
14136
+ try {
14137
+ const cacheKey = (0, import_utils73.makeCacheKey)(namespace_collection, {
14138
+ _id,
14139
+ tag: "getById"
14140
+ });
14141
+ const cachedData = await getCache(cacheKey);
14142
+ if (cachedData) {
14143
+ return cachedData;
14144
+ }
14145
+ const data = await collection.findOne({ _id });
14146
+ setCache(cacheKey, data).then(() => {
14147
+ import_utils73.logger.log({
14148
+ level: "info",
14149
+ message: `Cache set for getById job application: ${cacheKey}`
14150
+ });
14151
+ }).catch((err) => {
14152
+ import_utils73.logger.log({
14153
+ level: "error",
14154
+ message: `Failed to set cache for getById job application: ${cacheKey}, error: ${err.message}`
14155
+ });
14156
+ });
14157
+ return data;
14158
+ } catch (error2) {
14159
+ if (error2 instanceof import_utils73.AppError) {
14160
+ throw error2;
14161
+ }
14162
+ throw new import_utils73.BadRequestError(
14163
+ `Failed to get job application: ${error2.message}`
14164
+ );
14165
+ }
14166
+ }
14167
+ async function updateStatusById(_id, status, session) {
14168
+ const { error } = import_joi55.default.object({
14169
+ _id: import_joi55.default.string().hex().length(24).required(),
14170
+ status: import_joi55.default.string().valid(...jobApplicationStatuses).required()
14171
+ }).validate({ _id, status });
14172
+ if (error) {
14173
+ throw new import_utils73.BadRequestError(`Invalid job application id: ${_id}`);
14174
+ }
14175
+ try {
14176
+ _id = new import_mongodb33.ObjectId(_id);
14177
+ } catch (error2) {
14178
+ throw new import_utils73.BadRequestError(`Invalid job application id: ${_id}`);
14179
+ }
14180
+ try {
14181
+ await collection.updateOne(
14182
+ { _id },
14183
+ { $set: { status, updatedAt: /* @__PURE__ */ new Date() } },
14184
+ { session }
14185
+ );
14186
+ delCachedData();
14187
+ return "Successfully updated job application status.";
14188
+ } catch (error2) {
14189
+ if (error2 instanceof import_utils73.AppError) {
14190
+ throw error2;
14191
+ }
14192
+ throw new import_utils73.BadRequestError(
14193
+ `Failed to update job application status: ${error2.message}`
14194
+ );
14195
+ }
14196
+ }
14197
+ return {
14198
+ createIndexes,
14199
+ delCachedData,
14200
+ add,
14201
+ getAll,
14202
+ getById,
14203
+ updateStatusById
14204
+ };
14205
+ }
14206
+
14207
+ // src/resources/job-applications/job.application.controller.ts
14208
+ var import_utils75 = require("@goweekdays/utils");
14209
+ var import_joi57 = __toESM(require("joi"));
14210
+
14211
+ // src/resources/job-applications/job.application.service.ts
14212
+ var import_joi56 = __toESM(require("joi"));
14213
+ var import_utils74 = require("@goweekdays/utils");
14214
+ function useJobApplicationService() {
14215
+ const { getById, updateStatusById: _updateStatusById } = useJobApplicationRepo();
14216
+ async function updateStatusById(id, status) {
14217
+ const { error } = import_joi56.default.object({
14218
+ id: import_joi56.default.string().hex().length(24).required(),
14219
+ status: import_joi56.default.string().valid(...jobApplicationStatuses).required()
14220
+ }).validate({ id, status });
14221
+ if (error) {
14222
+ throw new import_utils74.BadRequestError(`Invalid parameters: ${error.message}`);
14223
+ }
14224
+ try {
14225
+ const application = await getById(id);
14226
+ if (!application) {
14227
+ throw new import_utils74.BadRequestError(`Job application not found with id: ${id}`);
14228
+ }
14229
+ if (application.status === status) {
14230
+ throw new import_utils74.BadRequestError(
14231
+ `Job application already has status: ${status}`
14232
+ );
14233
+ }
14234
+ await _updateStatusById(id, status);
14235
+ return `Successfully updated job application status to: ${status}`;
14236
+ } catch (error2) {
14237
+ if (error2 instanceof import_utils74.AppError) {
14238
+ throw error2;
14239
+ }
14240
+ throw new import_utils74.BadRequestError(
14241
+ `Failed to update job application status: ${error2.message}`
14242
+ );
14243
+ }
14244
+ }
14245
+ return {
14246
+ updateStatusById
14247
+ };
14248
+ }
14249
+
14250
+ // src/resources/job-applications/job.application.controller.ts
14251
+ function useJobApplicationController() {
14252
+ const {
14253
+ add: _add,
14254
+ getAll: _getAll,
14255
+ getById: _getById
14256
+ } = useJobApplicationRepo();
14257
+ async function add(req, res, next) {
14258
+ const { error } = schemaJobApplication.validate(req.body);
14259
+ if (error) {
14260
+ next(
14261
+ new import_utils75.BadRequestError(`Invalid job application data: ${error.message}`)
14262
+ );
14263
+ return;
14264
+ }
14265
+ try {
14266
+ const message = await _add(req.body);
14267
+ res.json({ message });
14268
+ return;
14269
+ } catch (error2) {
14270
+ if (error2 instanceof import_utils75.AppError) {
14271
+ next(error2);
14272
+ return;
14273
+ }
14274
+ next(
14275
+ new import_utils75.BadRequestError(
14276
+ `Failed to create job application: ${error2.message}`
14277
+ )
14278
+ );
14279
+ }
14280
+ }
14281
+ async function getAll(req, res, next) {
14282
+ const validation = import_joi57.default.object({
14283
+ page: import_joi57.default.number().integer().min(1).optional(),
14284
+ limit: import_joi57.default.number().integer().min(1).max(100).optional(),
14285
+ search: import_joi57.default.string().optional().allow(""),
14286
+ status: import_joi57.default.string().valid(...jobApplicationStatuses).optional()
14287
+ });
14288
+ const { error } = validation.validate(req.query);
14289
+ if (error) {
14290
+ next(new import_utils75.BadRequestError(`Invalid query parameters: ${error.message}`));
14291
+ return;
14292
+ }
14293
+ const page = req.query.page ? parseInt(req.query.page) : 1;
14294
+ const limit = req.query.limit ? parseInt(req.query.limit) : 10;
14295
+ const search = req.query.search ? req.query.search : "";
14296
+ const status = req.query.status ? req.query.status : "new";
14297
+ try {
14298
+ const data = await _getAll({ page, limit, search, status });
14299
+ res.json(data);
14300
+ return;
14301
+ } catch (error2) {
14302
+ if (error2 instanceof import_utils75.AppError) {
14303
+ next(error2);
14304
+ return;
14305
+ }
14306
+ next(
14307
+ new import_utils75.BadRequestError(`Failed to get job applications: ${error2.message}`)
14308
+ );
14309
+ }
14310
+ }
14311
+ async function getById(req, res, next) {
14312
+ const id = req.params.id ?? "";
14313
+ const { error } = import_joi57.default.string().hex().length(24).required().validate(id);
14314
+ if (error) {
14315
+ next(new import_utils75.BadRequestError(`Invalid job application id: ${id}`));
14316
+ return;
14317
+ }
14318
+ try {
14319
+ const data = await _getById(id);
14320
+ res.json(data);
14321
+ return;
14322
+ } catch (error2) {
14323
+ if (error2 instanceof import_utils75.AppError) {
14324
+ next(error2);
14325
+ return;
14326
+ }
14327
+ next(
14328
+ new import_utils75.BadRequestError(`Failed to get job application: ${error2.message}`)
14329
+ );
14330
+ }
14331
+ }
14332
+ const { updateStatusById: _updateStatusById } = useJobApplicationService();
14333
+ async function updateStatusById(req, res, next) {
14334
+ const id = req.params.id ?? "";
14335
+ const status = req.body.status ?? "";
14336
+ const { error } = import_joi57.default.object({
14337
+ id: import_joi57.default.string().hex().length(24).required(),
14338
+ status: import_joi57.default.string().valid(...jobApplicationStatuses).required()
14339
+ }).validate({ id, status });
14340
+ if (error) {
14341
+ next(new import_utils75.BadRequestError(`Invalid parameters: ${error.message}`));
14342
+ return;
14343
+ }
14344
+ try {
14345
+ const message = await _updateStatusById(id, status);
14346
+ res.json({ message });
14347
+ return;
14348
+ } catch (error2) {
14349
+ if (error2 instanceof import_utils75.AppError) {
14350
+ next(error2);
14351
+ return;
14352
+ }
14353
+ next(
14354
+ new import_utils75.BadRequestError(
14355
+ `Failed to update job application status: ${error2.message}`
14356
+ )
14357
+ );
14358
+ }
14359
+ }
14360
+ return {
14361
+ add,
14362
+ getAll,
14363
+ getById,
14364
+ updateStatusById
14365
+ };
14366
+ }
13899
14367
  // Annotate the CommonJS export names for ESM import in node:
13900
14368
  0 && (module.exports = {
13901
14369
  ACCESS_TOKEN_EXPIRY,
@@ -13940,9 +14408,11 @@ function useJobPostController() {
13940
14408
  XENDIT_SECRET_KEY,
13941
14409
  currencies,
13942
14410
  isDev,
14411
+ jobApplicationStatuses,
13943
14412
  ledgerBillStatuses,
13944
14413
  ledgerBillTypes,
13945
14414
  modelApp,
14415
+ modelJobApplication,
13946
14416
  modelJobPost,
13947
14417
  modelLedgerBill,
13948
14418
  modelMember,
@@ -13961,6 +14431,7 @@ function useJobPostController() {
13961
14431
  schemaBuilding,
13962
14432
  schemaBuildingUnit,
13963
14433
  schemaInviteMember,
14434
+ schemaJobApplication,
13964
14435
  schemaJobPost,
13965
14436
  schemaJobPostUpdate,
13966
14437
  schemaLedgerBill,
@@ -14009,6 +14480,8 @@ function useJobPostController() {
14009
14480
  useFileRepo,
14010
14481
  useFileService,
14011
14482
  useGitHubService,
14483
+ useJobApplicationController,
14484
+ useJobApplicationRepo,
14012
14485
  useJobPostController,
14013
14486
  useJobPostRepo,
14014
14487
  useJobPostService,