@goweekdays/core 2.11.18 → 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 +6 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +191 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +191 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1308,7 +1308,7 @@ declare function modelJobApplication(data: TJobApplication): TJobApplication;
|
|
|
1308
1308
|
declare function useJobApplicationRepo(): {
|
|
1309
1309
|
createIndexes: () => Promise<string>;
|
|
1310
1310
|
delCachedData: () => void;
|
|
1311
|
-
add: (data: TJobApplication) => Promise<
|
|
1311
|
+
add: (data: TJobApplication) => Promise<ObjectId>;
|
|
1312
1312
|
getAll: ({ page, limit, search, status, }?: {
|
|
1313
1313
|
page?: number | undefined;
|
|
1314
1314
|
limit?: number | undefined;
|
|
@@ -1322,11 +1322,15 @@ declare function useJobApplicationRepo(): {
|
|
|
1322
1322
|
data: TJobApplication[];
|
|
1323
1323
|
total: number;
|
|
1324
1324
|
}>;
|
|
1325
|
+
getById: (_id: string | ObjectId) => Promise<mongodb.WithId<bson.Document> | TJobApplication | null>;
|
|
1326
|
+
updateStatusById: (_id: string | ObjectId, status: string, session?: ClientSession) => Promise<string>;
|
|
1325
1327
|
};
|
|
1326
1328
|
|
|
1327
1329
|
declare function useJobApplicationController(): {
|
|
1328
1330
|
add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1329
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>;
|
|
1330
1334
|
};
|
|
1331
1335
|
|
|
1332
1336
|
declare const MONGO_URI: string;
|
package/dist/index.js
CHANGED
|
@@ -13967,6 +13967,11 @@ function modelJobApplication(data) {
|
|
|
13967
13967
|
} catch (error2) {
|
|
13968
13968
|
throw new import_utils72.BadRequestError(`Invalid job application post id: ${data.post}`);
|
|
13969
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
|
+
}
|
|
13970
13975
|
if (data.company && typeof data.company === "string") {
|
|
13971
13976
|
try {
|
|
13972
13977
|
data.company = new import_mongodb32.ObjectId(data.company);
|
|
@@ -13997,6 +14002,8 @@ function modelJobApplication(data) {
|
|
|
13997
14002
|
|
|
13998
14003
|
// src/resources/job-applications/job.application.repository.ts
|
|
13999
14004
|
var import_utils73 = require("@goweekdays/utils");
|
|
14005
|
+
var import_mongodb33 = require("mongodb");
|
|
14006
|
+
var import_joi55 = __toESM(require("joi"));
|
|
14000
14007
|
function useJobApplicationRepo() {
|
|
14001
14008
|
const db = import_utils73.useAtlas.getDb();
|
|
14002
14009
|
if (!db) {
|
|
@@ -14116,24 +14123,142 @@ function useJobApplicationRepo() {
|
|
|
14116
14123
|
);
|
|
14117
14124
|
}
|
|
14118
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
|
+
}
|
|
14119
14197
|
return {
|
|
14120
14198
|
createIndexes,
|
|
14121
14199
|
delCachedData,
|
|
14122
14200
|
add,
|
|
14123
|
-
getAll
|
|
14201
|
+
getAll,
|
|
14202
|
+
getById,
|
|
14203
|
+
updateStatusById
|
|
14124
14204
|
};
|
|
14125
14205
|
}
|
|
14126
14206
|
|
|
14127
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"));
|
|
14128
14213
|
var import_utils74 = require("@goweekdays/utils");
|
|
14129
|
-
|
|
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
|
|
14130
14251
|
function useJobApplicationController() {
|
|
14131
|
-
const {
|
|
14252
|
+
const {
|
|
14253
|
+
add: _add,
|
|
14254
|
+
getAll: _getAll,
|
|
14255
|
+
getById: _getById
|
|
14256
|
+
} = useJobApplicationRepo();
|
|
14132
14257
|
async function add(req, res, next) {
|
|
14133
14258
|
const { error } = schemaJobApplication.validate(req.body);
|
|
14134
14259
|
if (error) {
|
|
14135
14260
|
next(
|
|
14136
|
-
new
|
|
14261
|
+
new import_utils75.BadRequestError(`Invalid job application data: ${error.message}`)
|
|
14137
14262
|
);
|
|
14138
14263
|
return;
|
|
14139
14264
|
}
|
|
@@ -14142,27 +14267,27 @@ function useJobApplicationController() {
|
|
|
14142
14267
|
res.json({ message });
|
|
14143
14268
|
return;
|
|
14144
14269
|
} catch (error2) {
|
|
14145
|
-
if (error2 instanceof
|
|
14270
|
+
if (error2 instanceof import_utils75.AppError) {
|
|
14146
14271
|
next(error2);
|
|
14147
14272
|
return;
|
|
14148
14273
|
}
|
|
14149
14274
|
next(
|
|
14150
|
-
new
|
|
14275
|
+
new import_utils75.BadRequestError(
|
|
14151
14276
|
`Failed to create job application: ${error2.message}`
|
|
14152
14277
|
)
|
|
14153
14278
|
);
|
|
14154
14279
|
}
|
|
14155
14280
|
}
|
|
14156
14281
|
async function getAll(req, res, next) {
|
|
14157
|
-
const validation =
|
|
14158
|
-
page:
|
|
14159
|
-
limit:
|
|
14160
|
-
search:
|
|
14161
|
-
status:
|
|
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()
|
|
14162
14287
|
});
|
|
14163
14288
|
const { error } = validation.validate(req.query);
|
|
14164
14289
|
if (error) {
|
|
14165
|
-
next(new
|
|
14290
|
+
next(new import_utils75.BadRequestError(`Invalid query parameters: ${error.message}`));
|
|
14166
14291
|
return;
|
|
14167
14292
|
}
|
|
14168
14293
|
const page = req.query.page ? parseInt(req.query.page) : 1;
|
|
@@ -14174,18 +14299,69 @@ function useJobApplicationController() {
|
|
|
14174
14299
|
res.json(data);
|
|
14175
14300
|
return;
|
|
14176
14301
|
} catch (error2) {
|
|
14177
|
-
if (error2 instanceof
|
|
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) {
|
|
14178
14350
|
next(error2);
|
|
14179
14351
|
return;
|
|
14180
14352
|
}
|
|
14181
14353
|
next(
|
|
14182
|
-
new
|
|
14354
|
+
new import_utils75.BadRequestError(
|
|
14355
|
+
`Failed to update job application status: ${error2.message}`
|
|
14356
|
+
)
|
|
14183
14357
|
);
|
|
14184
14358
|
}
|
|
14185
14359
|
}
|
|
14186
14360
|
return {
|
|
14187
14361
|
add,
|
|
14188
|
-
getAll
|
|
14362
|
+
getAll,
|
|
14363
|
+
getById,
|
|
14364
|
+
updateStatusById
|
|
14189
14365
|
};
|
|
14190
14366
|
}
|
|
14191
14367
|
// Annotate the CommonJS export names for ESM import in node:
|