@eeplatform/basic-edu 1.8.5 → 1.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +102 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +102 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2875,7 +2875,7 @@ var learnerInfoSchema = Joi5.object({
|
|
|
2875
2875
|
});
|
|
2876
2876
|
var schemaUpdateStatus = Joi5.object({
|
|
2877
2877
|
_id: Joi5.string().hex().length(24).required(),
|
|
2878
|
-
status: Joi5.string().valid("pending", "accepted", "rejected").required()
|
|
2878
|
+
status: Joi5.string().valid("pending", "accepted", "rejected", "cancelled").required()
|
|
2879
2879
|
});
|
|
2880
2880
|
var gradeLevels = [
|
|
2881
2881
|
"K1",
|
|
@@ -4337,6 +4337,51 @@ function useProgramScreeningRepo() {
|
|
|
4337
4337
|
}
|
|
4338
4338
|
}
|
|
4339
4339
|
}
|
|
4340
|
+
async function getByApplicantId(_id) {
|
|
4341
|
+
try {
|
|
4342
|
+
_id = new ObjectId10(_id);
|
|
4343
|
+
} catch (error) {
|
|
4344
|
+
throw new BadRequestError14("Invalid ID.");
|
|
4345
|
+
}
|
|
4346
|
+
const cacheKey = makeCacheKey6(namespace_collection, {
|
|
4347
|
+
applicant: String(_id)
|
|
4348
|
+
});
|
|
4349
|
+
try {
|
|
4350
|
+
const cached = await getCache(cacheKey);
|
|
4351
|
+
if (cached) {
|
|
4352
|
+
logger11.log({
|
|
4353
|
+
level: "info",
|
|
4354
|
+
message: `Cache hit for getById program screening: ${cacheKey}`
|
|
4355
|
+
});
|
|
4356
|
+
return cached;
|
|
4357
|
+
}
|
|
4358
|
+
const result = await collection.findOne({
|
|
4359
|
+
applicant: _id,
|
|
4360
|
+
status: { $ne: "deleted" }
|
|
4361
|
+
});
|
|
4362
|
+
if (!result) {
|
|
4363
|
+
throw new BadRequestError14("Program screening not found.");
|
|
4364
|
+
}
|
|
4365
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
4366
|
+
logger11.log({
|
|
4367
|
+
level: "info",
|
|
4368
|
+
message: `Cache set for program screening by id: ${cacheKey}`
|
|
4369
|
+
});
|
|
4370
|
+
}).catch((err) => {
|
|
4371
|
+
logger11.log({
|
|
4372
|
+
level: "error",
|
|
4373
|
+
message: `Failed to set cache for program screening by id: ${err.message}`
|
|
4374
|
+
});
|
|
4375
|
+
});
|
|
4376
|
+
return result;
|
|
4377
|
+
} catch (error) {
|
|
4378
|
+
if (error instanceof AppError7) {
|
|
4379
|
+
throw error;
|
|
4380
|
+
} else {
|
|
4381
|
+
throw new InternalServerError5("Failed to get program screening.");
|
|
4382
|
+
}
|
|
4383
|
+
}
|
|
4384
|
+
}
|
|
4340
4385
|
async function getByCode(code, school) {
|
|
4341
4386
|
try {
|
|
4342
4387
|
school = new ObjectId10(school);
|
|
@@ -4460,6 +4505,26 @@ function useProgramScreeningRepo() {
|
|
|
4460
4505
|
);
|
|
4461
4506
|
}
|
|
4462
4507
|
}
|
|
4508
|
+
async function updateStatusByApplicantId(_id, status, session) {
|
|
4509
|
+
try {
|
|
4510
|
+
_id = new ObjectId10(_id);
|
|
4511
|
+
} catch (error) {
|
|
4512
|
+
throw new BadRequestError14("Invalid ID.");
|
|
4513
|
+
}
|
|
4514
|
+
try {
|
|
4515
|
+
await collection.updateOne(
|
|
4516
|
+
{ applicant: _id },
|
|
4517
|
+
{ $set: { status, updatedAt: /* @__PURE__ */ new Date() } },
|
|
4518
|
+
{ session }
|
|
4519
|
+
);
|
|
4520
|
+
delCachedData();
|
|
4521
|
+
return "Successfully updated program screening status.";
|
|
4522
|
+
} catch (error) {
|
|
4523
|
+
throw new InternalServerError5(
|
|
4524
|
+
"Failed to update program screening status."
|
|
4525
|
+
);
|
|
4526
|
+
}
|
|
4527
|
+
}
|
|
4463
4528
|
return {
|
|
4464
4529
|
createIndexes,
|
|
4465
4530
|
add,
|
|
@@ -4468,7 +4533,9 @@ function useProgramScreeningRepo() {
|
|
|
4468
4533
|
getByCode,
|
|
4469
4534
|
updateFieldById,
|
|
4470
4535
|
deleteById,
|
|
4471
|
-
updateById
|
|
4536
|
+
updateById,
|
|
4537
|
+
updateStatusByApplicantId,
|
|
4538
|
+
getByApplicantId
|
|
4472
4539
|
};
|
|
4473
4540
|
}
|
|
4474
4541
|
|
|
@@ -5364,7 +5431,11 @@ function useEnrollmentService() {
|
|
|
5364
5431
|
getById: _getById,
|
|
5365
5432
|
updateStatusById: _updateStatusById
|
|
5366
5433
|
} = useEnrollmentRepo();
|
|
5367
|
-
const {
|
|
5434
|
+
const {
|
|
5435
|
+
add: addProgramScreening,
|
|
5436
|
+
updateStatusByApplicantId,
|
|
5437
|
+
getByApplicantId
|
|
5438
|
+
} = useProgramScreeningRepo();
|
|
5368
5439
|
const { getById: getProgramById } = useProgramRepo();
|
|
5369
5440
|
async function add(value) {
|
|
5370
5441
|
const session = useAtlas10.getClient()?.startSession();
|
|
@@ -5479,9 +5550,26 @@ function useEnrollmentService() {
|
|
|
5479
5550
|
const session = client.startSession();
|
|
5480
5551
|
try {
|
|
5481
5552
|
session.startTransaction();
|
|
5482
|
-
const enrollment = await _getById(_id
|
|
5553
|
+
const enrollment = await _getById(_id);
|
|
5483
5554
|
if (!enrollment) {
|
|
5484
|
-
throw new NotFoundError("Enrollment not found
|
|
5555
|
+
throw new NotFoundError("Enrollment not found.");
|
|
5556
|
+
}
|
|
5557
|
+
if (status === "accepted" && enrollment.status == "rejected") {
|
|
5558
|
+
throw new BadRequestError19("Rejected enrollments cannot be accepted.");
|
|
5559
|
+
}
|
|
5560
|
+
if (status === "accepted" && enrollment.status == "accepted") {
|
|
5561
|
+
throw new BadRequestError19("Enrollment is already accepted.");
|
|
5562
|
+
}
|
|
5563
|
+
if (status === "rejected" && enrollment.status == "rejected") {
|
|
5564
|
+
throw new BadRequestError19("Enrollment is already rejected.");
|
|
5565
|
+
}
|
|
5566
|
+
if (status === "rejected" && enrollment.status == "accepted") {
|
|
5567
|
+
throw new BadRequestError19("Accepted enrollments cannot be rejected.");
|
|
5568
|
+
}
|
|
5569
|
+
if (status === "withdrawn" && enrollment.status !== "screening") {
|
|
5570
|
+
throw new BadRequestError19(
|
|
5571
|
+
"Only enrollments in screening status can be withdrawn."
|
|
5572
|
+
);
|
|
5485
5573
|
}
|
|
5486
5574
|
const result = await _updateStatusById(_id, status, session);
|
|
5487
5575
|
if (result.modifiedCount === 0) {
|
|
@@ -5519,8 +5607,17 @@ function useEnrollmentService() {
|
|
|
5519
5607
|
await incrementById(counterId, session);
|
|
5520
5608
|
}
|
|
5521
5609
|
enrollment.specialProgram = enrollment.specialProgram?.toString();
|
|
5610
|
+
enrollment.createdBy = enrollment.createdBy?.toString();
|
|
5522
5611
|
await addLearner(enrollment, session);
|
|
5523
5612
|
}
|
|
5613
|
+
const programScreening = await getByApplicantId(_id);
|
|
5614
|
+
if (programScreening) {
|
|
5615
|
+
if (["cancelled", "withdrawn"].includes(status)) {
|
|
5616
|
+
await updateStatusByApplicantId(_id, "cancelled", session);
|
|
5617
|
+
} else {
|
|
5618
|
+
await updateStatusByApplicantId(_id, status, session);
|
|
5619
|
+
}
|
|
5620
|
+
}
|
|
5524
5621
|
await session.commitTransaction();
|
|
5525
5622
|
return "Enrollment accepted successfully";
|
|
5526
5623
|
} catch (error2) {
|