@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @eeplatform/basic-edu
|
|
2
2
|
|
|
3
|
+
## 1.8.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 24c7ff6: Fix enrollment status update
|
|
8
|
+
|
|
9
|
+
## 1.8.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 41403d6: Enrollment management - fix enrollment status update
|
|
14
|
+
|
|
3
15
|
## 1.8.5
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1636,6 +1636,8 @@ declare function useProgramScreeningRepo(): {
|
|
|
1636
1636
|
}, session?: ClientSession) => Promise<string>;
|
|
1637
1637
|
deleteById: (_id: string | ObjectId) => Promise<string>;
|
|
1638
1638
|
updateById: (_id: string | ObjectId, value: Pick<TProgramScreening, "specialProgram" | "specialProgramName" | "status">) => Promise<string>;
|
|
1639
|
+
updateStatusByApplicantId: (_id: string | ObjectId, status: string, session?: ClientSession) => Promise<string>;
|
|
1640
|
+
getByApplicantId: (_id: string | ObjectId) => Promise<TProgramScreening>;
|
|
1639
1641
|
};
|
|
1640
1642
|
|
|
1641
1643
|
declare function useProgramScreeningController(): {
|
package/dist/index.js
CHANGED
|
@@ -2968,7 +2968,7 @@ var learnerInfoSchema = import_joi5.default.object({
|
|
|
2968
2968
|
});
|
|
2969
2969
|
var schemaUpdateStatus = import_joi5.default.object({
|
|
2970
2970
|
_id: import_joi5.default.string().hex().length(24).required(),
|
|
2971
|
-
status: import_joi5.default.string().valid("pending", "accepted", "rejected").required()
|
|
2971
|
+
status: import_joi5.default.string().valid("pending", "accepted", "rejected", "cancelled").required()
|
|
2972
2972
|
});
|
|
2973
2973
|
var gradeLevels = [
|
|
2974
2974
|
"K1",
|
|
@@ -4390,6 +4390,51 @@ function useProgramScreeningRepo() {
|
|
|
4390
4390
|
}
|
|
4391
4391
|
}
|
|
4392
4392
|
}
|
|
4393
|
+
async function getByApplicantId(_id) {
|
|
4394
|
+
try {
|
|
4395
|
+
_id = new import_mongodb10.ObjectId(_id);
|
|
4396
|
+
} catch (error) {
|
|
4397
|
+
throw new import_nodejs_utils15.BadRequestError("Invalid ID.");
|
|
4398
|
+
}
|
|
4399
|
+
const cacheKey = (0, import_nodejs_utils15.makeCacheKey)(namespace_collection, {
|
|
4400
|
+
applicant: String(_id)
|
|
4401
|
+
});
|
|
4402
|
+
try {
|
|
4403
|
+
const cached = await getCache(cacheKey);
|
|
4404
|
+
if (cached) {
|
|
4405
|
+
import_nodejs_utils15.logger.log({
|
|
4406
|
+
level: "info",
|
|
4407
|
+
message: `Cache hit for getById program screening: ${cacheKey}`
|
|
4408
|
+
});
|
|
4409
|
+
return cached;
|
|
4410
|
+
}
|
|
4411
|
+
const result = await collection.findOne({
|
|
4412
|
+
applicant: _id,
|
|
4413
|
+
status: { $ne: "deleted" }
|
|
4414
|
+
});
|
|
4415
|
+
if (!result) {
|
|
4416
|
+
throw new import_nodejs_utils15.BadRequestError("Program screening not found.");
|
|
4417
|
+
}
|
|
4418
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
4419
|
+
import_nodejs_utils15.logger.log({
|
|
4420
|
+
level: "info",
|
|
4421
|
+
message: `Cache set for program screening by id: ${cacheKey}`
|
|
4422
|
+
});
|
|
4423
|
+
}).catch((err) => {
|
|
4424
|
+
import_nodejs_utils15.logger.log({
|
|
4425
|
+
level: "error",
|
|
4426
|
+
message: `Failed to set cache for program screening by id: ${err.message}`
|
|
4427
|
+
});
|
|
4428
|
+
});
|
|
4429
|
+
return result;
|
|
4430
|
+
} catch (error) {
|
|
4431
|
+
if (error instanceof import_nodejs_utils15.AppError) {
|
|
4432
|
+
throw error;
|
|
4433
|
+
} else {
|
|
4434
|
+
throw new import_nodejs_utils15.InternalServerError("Failed to get program screening.");
|
|
4435
|
+
}
|
|
4436
|
+
}
|
|
4437
|
+
}
|
|
4393
4438
|
async function getByCode(code, school) {
|
|
4394
4439
|
try {
|
|
4395
4440
|
school = new import_mongodb10.ObjectId(school);
|
|
@@ -4513,6 +4558,26 @@ function useProgramScreeningRepo() {
|
|
|
4513
4558
|
);
|
|
4514
4559
|
}
|
|
4515
4560
|
}
|
|
4561
|
+
async function updateStatusByApplicantId(_id, status, session) {
|
|
4562
|
+
try {
|
|
4563
|
+
_id = new import_mongodb10.ObjectId(_id);
|
|
4564
|
+
} catch (error) {
|
|
4565
|
+
throw new import_nodejs_utils15.BadRequestError("Invalid ID.");
|
|
4566
|
+
}
|
|
4567
|
+
try {
|
|
4568
|
+
await collection.updateOne(
|
|
4569
|
+
{ applicant: _id },
|
|
4570
|
+
{ $set: { status, updatedAt: /* @__PURE__ */ new Date() } },
|
|
4571
|
+
{ session }
|
|
4572
|
+
);
|
|
4573
|
+
delCachedData();
|
|
4574
|
+
return "Successfully updated program screening status.";
|
|
4575
|
+
} catch (error) {
|
|
4576
|
+
throw new import_nodejs_utils15.InternalServerError(
|
|
4577
|
+
"Failed to update program screening status."
|
|
4578
|
+
);
|
|
4579
|
+
}
|
|
4580
|
+
}
|
|
4516
4581
|
return {
|
|
4517
4582
|
createIndexes,
|
|
4518
4583
|
add,
|
|
@@ -4521,7 +4586,9 @@ function useProgramScreeningRepo() {
|
|
|
4521
4586
|
getByCode,
|
|
4522
4587
|
updateFieldById,
|
|
4523
4588
|
deleteById,
|
|
4524
|
-
updateById
|
|
4589
|
+
updateById,
|
|
4590
|
+
updateStatusByApplicantId,
|
|
4591
|
+
getByApplicantId
|
|
4525
4592
|
};
|
|
4526
4593
|
}
|
|
4527
4594
|
|
|
@@ -5408,7 +5475,11 @@ function useEnrollmentService() {
|
|
|
5408
5475
|
getById: _getById,
|
|
5409
5476
|
updateStatusById: _updateStatusById
|
|
5410
5477
|
} = useEnrollmentRepo();
|
|
5411
|
-
const {
|
|
5478
|
+
const {
|
|
5479
|
+
add: addProgramScreening,
|
|
5480
|
+
updateStatusByApplicantId,
|
|
5481
|
+
getByApplicantId
|
|
5482
|
+
} = useProgramScreeningRepo();
|
|
5412
5483
|
const { getById: getProgramById } = useProgramRepo();
|
|
5413
5484
|
async function add(value) {
|
|
5414
5485
|
const session = import_nodejs_utils21.useAtlas.getClient()?.startSession();
|
|
@@ -5523,9 +5594,26 @@ function useEnrollmentService() {
|
|
|
5523
5594
|
const session = client.startSession();
|
|
5524
5595
|
try {
|
|
5525
5596
|
session.startTransaction();
|
|
5526
|
-
const enrollment = await _getById(_id
|
|
5597
|
+
const enrollment = await _getById(_id);
|
|
5527
5598
|
if (!enrollment) {
|
|
5528
|
-
throw new import_nodejs_utils21.NotFoundError("Enrollment not found
|
|
5599
|
+
throw new import_nodejs_utils21.NotFoundError("Enrollment not found.");
|
|
5600
|
+
}
|
|
5601
|
+
if (status === "accepted" && enrollment.status == "rejected") {
|
|
5602
|
+
throw new import_nodejs_utils21.BadRequestError("Rejected enrollments cannot be accepted.");
|
|
5603
|
+
}
|
|
5604
|
+
if (status === "accepted" && enrollment.status == "accepted") {
|
|
5605
|
+
throw new import_nodejs_utils21.BadRequestError("Enrollment is already accepted.");
|
|
5606
|
+
}
|
|
5607
|
+
if (status === "rejected" && enrollment.status == "rejected") {
|
|
5608
|
+
throw new import_nodejs_utils21.BadRequestError("Enrollment is already rejected.");
|
|
5609
|
+
}
|
|
5610
|
+
if (status === "rejected" && enrollment.status == "accepted") {
|
|
5611
|
+
throw new import_nodejs_utils21.BadRequestError("Accepted enrollments cannot be rejected.");
|
|
5612
|
+
}
|
|
5613
|
+
if (status === "withdrawn" && enrollment.status !== "screening") {
|
|
5614
|
+
throw new import_nodejs_utils21.BadRequestError(
|
|
5615
|
+
"Only enrollments in screening status can be withdrawn."
|
|
5616
|
+
);
|
|
5529
5617
|
}
|
|
5530
5618
|
const result = await _updateStatusById(_id, status, session);
|
|
5531
5619
|
if (result.modifiedCount === 0) {
|
|
@@ -5563,8 +5651,17 @@ function useEnrollmentService() {
|
|
|
5563
5651
|
await incrementById(counterId, session);
|
|
5564
5652
|
}
|
|
5565
5653
|
enrollment.specialProgram = enrollment.specialProgram?.toString();
|
|
5654
|
+
enrollment.createdBy = enrollment.createdBy?.toString();
|
|
5566
5655
|
await addLearner(enrollment, session);
|
|
5567
5656
|
}
|
|
5657
|
+
const programScreening = await getByApplicantId(_id);
|
|
5658
|
+
if (programScreening) {
|
|
5659
|
+
if (["cancelled", "withdrawn"].includes(status)) {
|
|
5660
|
+
await updateStatusByApplicantId(_id, "cancelled", session);
|
|
5661
|
+
} else {
|
|
5662
|
+
await updateStatusByApplicantId(_id, status, session);
|
|
5663
|
+
}
|
|
5664
|
+
}
|
|
5568
5665
|
await session.commitTransaction();
|
|
5569
5666
|
return "Enrollment accepted successfully";
|
|
5570
5667
|
} catch (error2) {
|