@eeplatform/basic-edu 1.4.0 → 1.4.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/CHANGELOG.md +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +32 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2799,12 +2799,31 @@ function useBasicEduCountRepo() {
|
|
|
2799
2799
|
throw new Error("Failed to increment counter status.");
|
|
2800
2800
|
}
|
|
2801
2801
|
}
|
|
2802
|
+
async function resetById(_id, session) {
|
|
2803
|
+
try {
|
|
2804
|
+
_id = new ObjectId6(_id);
|
|
2805
|
+
} catch (error) {
|
|
2806
|
+
throw new BadRequestError9("Invalid ID.");
|
|
2807
|
+
}
|
|
2808
|
+
try {
|
|
2809
|
+
const result = await collection.updateOne(
|
|
2810
|
+
{ _id },
|
|
2811
|
+
{ $set: { updatedAt: /* @__PURE__ */ new Date(), count: 0 } },
|
|
2812
|
+
{ session }
|
|
2813
|
+
);
|
|
2814
|
+
delCachedData();
|
|
2815
|
+
return result;
|
|
2816
|
+
} catch (error) {
|
|
2817
|
+
throw new Error("Failed to reset counter to zero.");
|
|
2818
|
+
}
|
|
2819
|
+
}
|
|
2802
2820
|
return {
|
|
2803
2821
|
createIndexes,
|
|
2804
2822
|
add,
|
|
2805
2823
|
getById,
|
|
2806
2824
|
incrementById,
|
|
2807
|
-
getByName
|
|
2825
|
+
getByName,
|
|
2826
|
+
resetById
|
|
2808
2827
|
};
|
|
2809
2828
|
}
|
|
2810
2829
|
|
|
@@ -2880,7 +2899,7 @@ function useEnrollmentService() {
|
|
|
2880
2899
|
}
|
|
2881
2900
|
}
|
|
2882
2901
|
const { add: addLearner } = useLearnerRepo();
|
|
2883
|
-
const { getByName, incrementById } = useBasicEduCountRepo();
|
|
2902
|
+
const { getByName, incrementById, resetById } = useBasicEduCountRepo();
|
|
2884
2903
|
function padNumber(num) {
|
|
2885
2904
|
const str = String(num);
|
|
2886
2905
|
const pad = 4 - str.length;
|
|
@@ -2924,10 +2943,20 @@ function useEnrollmentService() {
|
|
|
2924
2943
|
"Failed to retrieve enrollment counter"
|
|
2925
2944
|
);
|
|
2926
2945
|
}
|
|
2946
|
+
const counterId = String(counter._id);
|
|
2947
|
+
if (counter.updatedAt) {
|
|
2948
|
+
const countUpdatedAtYear = new Date(
|
|
2949
|
+
counter.updatedAt
|
|
2950
|
+
).getFullYear();
|
|
2951
|
+
const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
|
|
2952
|
+
if (countUpdatedAtYear < currentYear) {
|
|
2953
|
+
counter.count = 0;
|
|
2954
|
+
await resetById(counterId, session);
|
|
2955
|
+
}
|
|
2956
|
+
}
|
|
2927
2957
|
const newCount = padNumber(counter.count + 1);
|
|
2928
2958
|
const lrn = `${enrollment.schoolId}-${(/* @__PURE__ */ new Date()).getFullYear().toString().slice(2, 4)}-${newCount}`;
|
|
2929
2959
|
enrollment.learnerInfo.lrn = lrn;
|
|
2930
|
-
const counterId = String(counter._id);
|
|
2931
2960
|
await incrementById(counterId, session);
|
|
2932
2961
|
}
|
|
2933
2962
|
await addLearner(enrollment, session);
|