@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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @eeplatform/basic-edu
2
2
 
3
+ ## 1.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 944df9d: Add count reset in enrollment acceptance business logic
8
+
3
9
  ## 1.4.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -750,6 +750,7 @@ declare function useBasicEduCountRepo(): {
750
750
  getById: (_id: string | ObjectId, status?: string) => Promise<TBasicEduCount | null>;
751
751
  incrementById: (_id: string | ObjectId, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
752
752
  getByName: (name: string, session?: ClientSession) => Promise<TBasicEduCount | null>;
753
+ resetById: (_id: string | ObjectId, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
753
754
  };
754
755
 
755
756
  export { MAsset, MCurriculum, MGradeLevel, MLearner, MPlantilla, MStockCard, TAddress, TAddressInformation, TAsset, TBasicEduCount, TCurriculum, TCurriculumSubject, TDivision, TGradeLevel, TLearner, TLearnerInfo, TLearningModality, TParentGuardianInfo, TPersonContact, TPlantilla, TRegion, TReturningLearnerInfo, TSchool, TSeniorHighInformation, TStockCard, modelBasicEduCount, modelDivision, modelRegion, modelSchool, schemaAsset, schemaAssetUpdateOption, schemaBasicEduCount, schemaCurriculum, schemaDivision, schemaDivisionUpdate, schemaEnrollment, schemaGradeLevel, schemaPlantilla, schemaRegion, schemaSchool, schemaSchoolUpdate, schemaStockCard, schemaUpdateStatus, useAssetController, useAssetRepo, useBasicEduCountRepo, useCurriculumController, useCurriculumRepo, useDivisionController, useDivisionRepo, useDivisionService, useEnrollmentController, useEnrollmentRepo, useEnrollmentService, useGradeLevelController, useGradeLevelRepo, useLearnerController, useLearnerRepo, usePlantillaController, usePlantillaRepo, usePlantillaService, useRegionController, useRegionRepo, useSchoolController, useSchoolRepo, useSchoolService, useStockCardController, useStockCardRepository, useStockCardService };
package/dist/index.js CHANGED
@@ -2814,12 +2814,31 @@ function useBasicEduCountRepo() {
2814
2814
  throw new Error("Failed to increment counter status.");
2815
2815
  }
2816
2816
  }
2817
+ async function resetById(_id, session) {
2818
+ try {
2819
+ _id = new import_mongodb6.ObjectId(_id);
2820
+ } catch (error) {
2821
+ throw new import_nodejs_utils9.BadRequestError("Invalid ID.");
2822
+ }
2823
+ try {
2824
+ const result = await collection.updateOne(
2825
+ { _id },
2826
+ { $set: { updatedAt: /* @__PURE__ */ new Date(), count: 0 } },
2827
+ { session }
2828
+ );
2829
+ delCachedData();
2830
+ return result;
2831
+ } catch (error) {
2832
+ throw new Error("Failed to reset counter to zero.");
2833
+ }
2834
+ }
2817
2835
  return {
2818
2836
  createIndexes,
2819
2837
  add,
2820
2838
  getById,
2821
2839
  incrementById,
2822
- getByName
2840
+ getByName,
2841
+ resetById
2823
2842
  };
2824
2843
  }
2825
2844
 
@@ -2895,7 +2914,7 @@ function useEnrollmentService() {
2895
2914
  }
2896
2915
  }
2897
2916
  const { add: addLearner } = useLearnerRepo();
2898
- const { getByName, incrementById } = useBasicEduCountRepo();
2917
+ const { getByName, incrementById, resetById } = useBasicEduCountRepo();
2899
2918
  function padNumber(num) {
2900
2919
  const str = String(num);
2901
2920
  const pad = 4 - str.length;
@@ -2939,10 +2958,20 @@ function useEnrollmentService() {
2939
2958
  "Failed to retrieve enrollment counter"
2940
2959
  );
2941
2960
  }
2961
+ const counterId = String(counter._id);
2962
+ if (counter.updatedAt) {
2963
+ const countUpdatedAtYear = new Date(
2964
+ counter.updatedAt
2965
+ ).getFullYear();
2966
+ const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
2967
+ if (countUpdatedAtYear < currentYear) {
2968
+ counter.count = 0;
2969
+ await resetById(counterId, session);
2970
+ }
2971
+ }
2942
2972
  const newCount = padNumber(counter.count + 1);
2943
2973
  const lrn = `${enrollment.schoolId}-${(/* @__PURE__ */ new Date()).getFullYear().toString().slice(2, 4)}-${newCount}`;
2944
2974
  enrollment.learnerInfo.lrn = lrn;
2945
- const counterId = String(counter._id);
2946
2975
  await incrementById(counterId, session);
2947
2976
  }
2948
2977
  await addLearner(enrollment, session);