@eeplatform/basic-edu 1.1.1 → 1.2.0

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/dist/index.js CHANGED
@@ -1345,17 +1345,18 @@ var src_exports = {};
1345
1345
  __export(src_exports, {
1346
1346
  MAsset: () => MAsset,
1347
1347
  MCurriculum: () => MCurriculum,
1348
- MDivision: () => MDivision,
1349
1348
  MEnrollment: () => MEnrollment,
1350
1349
  MGradeLevel: () => MGradeLevel,
1351
1350
  MPlantilla: () => MPlantilla,
1352
- MRegion: () => MRegion,
1353
- MSchool: () => MSchool,
1354
1351
  MStockCard: () => MStockCard,
1352
+ modelDivision: () => modelDivision,
1353
+ modelRegion: () => modelRegion,
1354
+ modelSchool: () => modelSchool,
1355
1355
  schemaAsset: () => schemaAsset,
1356
1356
  schemaAssetUpdateOption: () => schemaAssetUpdateOption,
1357
1357
  schemaCurriculum: () => schemaCurriculum,
1358
1358
  schemaDivision: () => schemaDivision,
1359
+ schemaDivisionUpdate: () => schemaDivisionUpdate,
1359
1360
  schemaEnrollment: () => schemaEnrollment,
1360
1361
  schemaGradeLevel: () => schemaGradeLevel,
1361
1362
  schemaPlantilla: () => schemaPlantilla,
@@ -3581,19 +3582,18 @@ var import_mongodb7 = require("mongodb");
3581
3582
  var schemaRegion = import_joi7.default.object({
3582
3583
  _id: import_joi7.default.string().hex().optional().allow(null, ""),
3583
3584
  name: import_joi7.default.string().min(1).max(100).required(),
3584
- code: import_joi7.default.string().length(10).required(),
3585
3585
  createdAt: import_joi7.default.string().isoDate().optional(),
3586
3586
  updatedAt: import_joi7.default.string().isoDate().optional(),
3587
3587
  deletedAt: import_joi7.default.string().isoDate().optional().allow(null, "")
3588
3588
  });
3589
- function MRegion(value) {
3589
+ function modelRegion(value) {
3590
3590
  const { error } = schemaRegion.validate(value);
3591
3591
  if (error) {
3592
3592
  throw new import_nodejs_utils11.BadRequestError(`Invalid region data: ${error.message}`);
3593
3593
  }
3594
3594
  if (value._id && typeof value._id === "string") {
3595
3595
  try {
3596
- value._id = new import_mongodb7.ObjectId(value._id);
3596
+ value._id = import_mongodb7.ObjectId.createFromTime(value._id);
3597
3597
  } catch (error2) {
3598
3598
  throw new Error("Invalid _id.");
3599
3599
  }
@@ -3601,7 +3601,7 @@ function MRegion(value) {
3601
3601
  return {
3602
3602
  _id: value._id,
3603
3603
  name: value.name,
3604
- code: value.code,
3604
+ status: "active",
3605
3605
  createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
3606
3606
  updatedAt: value.updatedAt ?? "",
3607
3607
  deletedAt: value.deletedAt ?? ""
@@ -3616,18 +3616,16 @@ function useRegionRepo() {
3616
3616
  if (!db) {
3617
3617
  throw new Error("Unable to connect to server.");
3618
3618
  }
3619
- const namespace_collection = "regions";
3619
+ const namespace_collection = "deped.regions";
3620
3620
  const collection = db.collection(namespace_collection);
3621
3621
  const { getCache, setCache, delNamespace } = (0, import_nodejs_utils12.useCache)(namespace_collection);
3622
3622
  async function createIndexes() {
3623
3623
  try {
3624
3624
  await collection.createIndexes([
3625
3625
  { key: { name: 1 } },
3626
- { key: { code: 1 } },
3627
3626
  { key: { createdAt: 1 } },
3628
3627
  { key: { name: "text" } },
3629
- { key: { code: 1 }, unique: true, name: "unique_code" },
3630
- { key: { name: 1 }, unique: true, name: "unique_name" }
3628
+ { key: { name: 1, status: 1 }, unique: true, name: "unique_region" }
3631
3629
  ]);
3632
3630
  } catch (error) {
3633
3631
  throw new Error("Failed to create index on regions.");
@@ -3648,7 +3646,7 @@ function useRegionRepo() {
3648
3646
  }
3649
3647
  async function add(value, session) {
3650
3648
  try {
3651
- value = MRegion(value);
3649
+ value = modelRegion(value);
3652
3650
  const res = await collection.insertOne(value, { session });
3653
3651
  delCachedData();
3654
3652
  return res.insertedId;
@@ -3668,19 +3666,30 @@ function useRegionRepo() {
3668
3666
  }
3669
3667
  }
3670
3668
  }
3671
- async function getAll({ search = "", page = 1, limit = 10, sort = {} } = {}) {
3669
+ async function getAll({
3670
+ search = "",
3671
+ page = 1,
3672
+ limit = 10,
3673
+ sort = {},
3674
+ status = "active"
3675
+ } = {}) {
3672
3676
  page = page > 0 ? page - 1 : 0;
3673
- const query = { deletedAt: { $in: ["", null] } };
3677
+ const query = {
3678
+ deletedAt: { $in: ["", null] },
3679
+ status
3680
+ };
3674
3681
  sort = Object.keys(sort).length > 0 ? sort : { _id: 1 };
3675
- if (search) {
3676
- query.$text = { $search: search };
3677
- }
3678
- const cacheKey = (0, import_nodejs_utils12.makeCacheKey)(namespace_collection, {
3679
- search,
3682
+ const cacheKeyOptions = {
3683
+ status,
3680
3684
  page,
3681
3685
  limit,
3682
3686
  sort: JSON.stringify(sort)
3683
- });
3687
+ };
3688
+ if (search) {
3689
+ query.$text = { $search: search };
3690
+ cacheKeyOptions.search = search;
3691
+ }
3692
+ const cacheKey = (0, import_nodejs_utils12.makeCacheKey)(namespace_collection, cacheKeyOptions);
3684
3693
  import_nodejs_utils12.logger.log({
3685
3694
  level: "info",
3686
3695
  message: `Cache key for getAll regions: ${cacheKey}`
@@ -3698,17 +3707,7 @@ function useRegionRepo() {
3698
3707
  { $match: query },
3699
3708
  { $sort: sort },
3700
3709
  { $skip: page * limit },
3701
- { $limit: limit },
3702
- {
3703
- $project: {
3704
- _id: 1,
3705
- name: 1,
3706
- director: 1,
3707
- directorName: 1,
3708
- createdAt: 1,
3709
- updatedAt: 1
3710
- }
3711
- }
3710
+ { $limit: limit }
3712
3711
  ]).toArray();
3713
3712
  const length = await collection.countDocuments(query);
3714
3713
  const data = (0, import_nodejs_utils12.paginate)(items, page, limit, length);
@@ -3843,7 +3842,7 @@ function useRegionRepo() {
3843
3842
  try {
3844
3843
  await collection.updateOne(
3845
3844
  { _id },
3846
- { $set: { deletedAt: (/* @__PURE__ */ new Date()).toISOString() } }
3845
+ { $set: { status: "deleted", deletedAt: (/* @__PURE__ */ new Date()).toISOString() } }
3847
3846
  );
3848
3847
  delCachedData();
3849
3848
  return "Successfully deleted region.";
@@ -3882,10 +3881,10 @@ function useRegionController() {
3882
3881
  return;
3883
3882
  }
3884
3883
  try {
3885
- const regionId = await _add(value);
3884
+ const data = await _add(value);
3886
3885
  res.json({
3887
3886
  message: "Successfully created region.",
3888
- data: { regionId }
3887
+ data
3889
3888
  });
3890
3889
  return;
3891
3890
  } catch (error2) {
@@ -3897,12 +3896,14 @@ function useRegionController() {
3897
3896
  const validation = import_joi8.default.object({
3898
3897
  page: import_joi8.default.number().min(1).optional().allow("", null),
3899
3898
  limit: import_joi8.default.number().min(1).optional().allow("", null),
3900
- search: import_joi8.default.string().optional().allow("", null)
3899
+ search: import_joi8.default.string().optional().allow("", null),
3900
+ status: import_joi8.default.string().optional().allow("", null)
3901
3901
  });
3902
3902
  const { error } = validation.validate(query);
3903
3903
  const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
3904
3904
  const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
3905
3905
  const search = req.query.search ?? "";
3906
+ const status = req.query.status ?? "active";
3906
3907
  const isPageNumber = isFinite(page);
3907
3908
  if (!isPageNumber) {
3908
3909
  next(new import_nodejs_utils13.BadRequestError("Invalid page number."));
@@ -3918,8 +3919,8 @@ function useRegionController() {
3918
3919
  return;
3919
3920
  }
3920
3921
  try {
3921
- const regions = await _getAll({ page, limit, search });
3922
- res.json(regions);
3922
+ const data = await _getAll({ page, limit, search, status });
3923
+ res.json(data);
3923
3924
  return;
3924
3925
  } catch (error2) {
3925
3926
  next(error2);
@@ -3936,10 +3937,10 @@ function useRegionController() {
3936
3937
  return;
3937
3938
  }
3938
3939
  try {
3939
- const region = await _getById(id);
3940
+ const data = await _getById(id);
3940
3941
  res.json({
3941
3942
  message: "Successfully retrieved region.",
3942
- data: { region }
3943
+ data
3943
3944
  });
3944
3945
  return;
3945
3946
  } catch (error2) {
@@ -3957,10 +3958,10 @@ function useRegionController() {
3957
3958
  return;
3958
3959
  }
3959
3960
  try {
3960
- const region = await _getByName(name);
3961
+ const data = await _getByName(name);
3961
3962
  res.json({
3962
3963
  message: "Successfully retrieved region.",
3963
- data: { region }
3964
+ data
3964
3965
  });
3965
3966
  return;
3966
3967
  } catch (error2) {
@@ -4023,47 +4024,42 @@ var import_mongodb9 = require("mongodb");
4023
4024
  var schemaDivision = import_joi9.default.object({
4024
4025
  _id: import_joi9.default.string().hex().optional().allow(null, ""),
4025
4026
  name: import_joi9.default.string().min(1).max(100).required(),
4026
- region: import_joi9.default.string().hex().optional().allow(null, ""),
4027
- regionName: import_joi9.default.string().min(1).max(100).optional().allow(null, ""),
4027
+ region: import_joi9.default.string().hex().required(),
4028
+ regionName: import_joi9.default.string().min(1).max(100).required(),
4028
4029
  superintendent: import_joi9.default.string().hex().optional().allow(null, ""),
4029
4030
  superintendentName: import_joi9.default.string().min(1).max(100).optional().allow(null, ""),
4030
4031
  createdAt: import_joi9.default.string().isoDate().optional(),
4031
4032
  updatedAt: import_joi9.default.string().isoDate().optional(),
4032
4033
  deletedAt: import_joi9.default.string().isoDate().optional().allow(null, "")
4033
4034
  });
4034
- function MDivision(value) {
4035
+ var schemaDivisionUpdate = import_joi9.default.object({
4036
+ _id: import_joi9.default.string().hex().optional().allow(null, ""),
4037
+ name: import_joi9.default.string().min(1).max(100).required(),
4038
+ region: import_joi9.default.string().hex().required(),
4039
+ regionName: import_joi9.default.string().min(1).max(100).required(),
4040
+ superintendent: import_joi9.default.string().hex().optional().allow(null, ""),
4041
+ superintendentName: import_joi9.default.string().min(1).max(100).optional().allow(null, "")
4042
+ });
4043
+ function modelDivision(value) {
4035
4044
  const { error } = schemaDivision.validate(value);
4036
4045
  if (error) {
4037
- throw new import_nodejs_utils14.BadRequestError(`Invalid division data: ${error.message}`);
4046
+ throw new import_nodejs_utils14.BadRequestError(`Invalid sdo data: ${error.message}`);
4038
4047
  }
4039
4048
  if (value._id && typeof value._id === "string") {
4040
4049
  try {
4041
- value._id = new import_mongodb9.ObjectId(value._id);
4050
+ value._id = import_mongodb9.ObjectId.createFromTime(value._id);
4042
4051
  } catch (error2) {
4043
4052
  throw new Error("Invalid _id.");
4044
4053
  }
4045
4054
  }
4046
- if (value.region && typeof value.region === "string") {
4047
- try {
4048
- value.region = new import_mongodb9.ObjectId(value.region);
4049
- } catch (error2) {
4050
- throw new Error("Invalid region.");
4051
- }
4052
- }
4053
- if (value.superintendent && typeof value.superintendent === "string") {
4054
- try {
4055
- value.superintendent = new import_mongodb9.ObjectId(value.superintendent);
4056
- } catch (error2) {
4057
- throw new Error("Invalid superintendent.");
4058
- }
4059
- }
4060
4055
  return {
4061
4056
  _id: value._id,
4062
4057
  name: value.name,
4063
- region: value.region ?? "",
4058
+ region: value.region,
4064
4059
  regionName: value.regionName ?? "",
4065
- superintendent: value.superintendent ?? "",
4060
+ superintendent: value.superintendent,
4066
4061
  superintendentName: value.superintendentName ?? "",
4062
+ status: value.status ?? "active",
4067
4063
  createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4068
4064
  updatedAt: value.updatedAt ?? "",
4069
4065
  deletedAt: value.deletedAt ?? ""
@@ -4078,46 +4074,25 @@ function useDivisionRepo() {
4078
4074
  if (!db) {
4079
4075
  throw new Error("Unable to connect to server.");
4080
4076
  }
4081
- const namespace_collection = "divisions";
4077
+ const namespace_collection = "deped.divisions";
4082
4078
  const collection = db.collection(namespace_collection);
4083
4079
  const { getCache, setCache, delNamespace } = (0, import_nodejs_utils15.useCache)(namespace_collection);
4084
- async function createIndex() {
4080
+ async function createIndexes() {
4085
4081
  try {
4086
- await collection.createIndex([
4087
- { name: 1 },
4088
- { region: 1 },
4089
- { superintendent: 1 },
4090
- { createdAt: 1 }
4082
+ await collection.createIndexes([
4083
+ { key: { name: 1 } },
4084
+ { key: { createdAt: 1 } },
4085
+ { key: { name: "text", regionName: "text" } },
4086
+ {
4087
+ key: { name: 1, region: 1, status: 1 },
4088
+ unique: true,
4089
+ name: "unique_division"
4090
+ }
4091
4091
  ]);
4092
4092
  } catch (error) {
4093
4093
  throw new Error("Failed to create index on divisions.");
4094
4094
  }
4095
4095
  }
4096
- async function createTextIndex() {
4097
- try {
4098
- await collection.createIndex({
4099
- name: "text",
4100
- regionName: "text",
4101
- superintendentName: "text"
4102
- });
4103
- } catch (error) {
4104
- throw new Error(
4105
- "Failed to create text index on division name and superintendent name."
4106
- );
4107
- }
4108
- }
4109
- async function createUniqueIndex() {
4110
- try {
4111
- await collection.createIndex(
4112
- {
4113
- name: 1
4114
- },
4115
- { unique: true }
4116
- );
4117
- } catch (error) {
4118
- throw new Error("Failed to create unique index on division name.");
4119
- }
4120
- }
4121
4096
  function delCachedData() {
4122
4097
  delNamespace().then(() => {
4123
4098
  import_nodejs_utils15.logger.log({
@@ -4133,7 +4108,7 @@ function useDivisionRepo() {
4133
4108
  }
4134
4109
  async function add(value, session) {
4135
4110
  try {
4136
- value = MDivision(value);
4111
+ value = modelDivision(value);
4137
4112
  const res = await collection.insertOne(value, { session });
4138
4113
  delCachedData();
4139
4114
  return res.insertedId;
@@ -4158,28 +4133,25 @@ function useDivisionRepo() {
4158
4133
  page = 1,
4159
4134
  limit = 10,
4160
4135
  sort = {},
4161
- region = ""
4136
+ status = "active"
4162
4137
  } = {}) {
4163
4138
  page = page > 0 ? page - 1 : 0;
4164
- const query = { deletedAt: { $in: ["", null] } };
4165
- sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
4139
+ const query = {
4140
+ deletedAt: { $in: ["", null] },
4141
+ status
4142
+ };
4143
+ sort = Object.keys(sort).length > 0 ? sort : { _id: 1 };
4144
+ const cacheKeyOptions = {
4145
+ status,
4146
+ page,
4147
+ limit,
4148
+ sort: JSON.stringify(sort)
4149
+ };
4166
4150
  if (search) {
4167
4151
  query.$text = { $search: search };
4152
+ cacheKeyOptions.search = search;
4168
4153
  }
4169
- if (region) {
4170
- try {
4171
- query.region = new import_mongodb10.ObjectId(region);
4172
- } catch (error) {
4173
- throw new import_nodejs_utils15.BadRequestError("Invalid region ID.");
4174
- }
4175
- }
4176
- const cacheKey = (0, import_nodejs_utils15.makeCacheKey)(namespace_collection, {
4177
- search,
4178
- page,
4179
- limit,
4180
- sort: JSON.stringify(sort),
4181
- region
4182
- });
4154
+ const cacheKey = (0, import_nodejs_utils15.makeCacheKey)(namespace_collection, cacheKeyOptions);
4183
4155
  import_nodejs_utils15.logger.log({
4184
4156
  level: "info",
4185
4157
  message: `Cache key for getAll divisions: ${cacheKey}`
@@ -4197,19 +4169,7 @@ function useDivisionRepo() {
4197
4169
  { $match: query },
4198
4170
  { $sort: sort },
4199
4171
  { $skip: page * limit },
4200
- { $limit: limit },
4201
- {
4202
- $project: {
4203
- _id: 1,
4204
- name: 1,
4205
- region: 1,
4206
- regionName: 1,
4207
- superintendent: 1,
4208
- superintendentName: 1,
4209
- createdAt: 1,
4210
- updatedAt: 1
4211
- }
4212
- }
4172
+ { $limit: limit }
4213
4173
  ]).toArray();
4214
4174
  const length = await collection.countDocuments(query);
4215
4175
  const data = (0, import_nodejs_utils15.paginate)(items, page, limit, length);
@@ -4312,13 +4272,7 @@ function useDivisionRepo() {
4312
4272
  }
4313
4273
  }
4314
4274
  async function updateFieldById({ _id, field, value } = {}, session) {
4315
- const allowedFields = [
4316
- "name",
4317
- "region",
4318
- "regionName",
4319
- "superintendent",
4320
- "superintendentName"
4321
- ];
4275
+ const allowedFields = ["name"];
4322
4276
  if (!allowedFields.includes(field)) {
4323
4277
  throw new import_nodejs_utils15.BadRequestError(
4324
4278
  `Field "${field}" is not allowed to be updated.`
@@ -4341,6 +4295,27 @@ function useDivisionRepo() {
4341
4295
  throw new import_nodejs_utils15.InternalServerError(`Failed to update division ${field}.`);
4342
4296
  }
4343
4297
  }
4298
+ async function updateById(_id, options, session) {
4299
+ const { error } = schemaDivisionUpdate.validate({
4300
+ _id: String(_id),
4301
+ ...options
4302
+ });
4303
+ if (error) {
4304
+ throw new import_nodejs_utils15.BadRequestError(`Invalid division data: ${error.message}`);
4305
+ }
4306
+ try {
4307
+ _id = new import_mongodb10.ObjectId(_id);
4308
+ } catch (error2) {
4309
+ throw new import_nodejs_utils15.BadRequestError("Invalid ID.");
4310
+ }
4311
+ try {
4312
+ await collection.updateOne({ _id }, { $set: options }, { session });
4313
+ delCachedData();
4314
+ return `Successfully updated division.`;
4315
+ } catch (error2) {
4316
+ throw new import_nodejs_utils15.InternalServerError(`Failed to update division.`);
4317
+ }
4318
+ }
4344
4319
  async function deleteById(_id) {
4345
4320
  try {
4346
4321
  _id = new import_mongodb10.ObjectId(_id);
@@ -4350,7 +4325,7 @@ function useDivisionRepo() {
4350
4325
  try {
4351
4326
  await collection.updateOne(
4352
4327
  { _id },
4353
- { $set: { deletedAt: (/* @__PURE__ */ new Date()).toISOString() } }
4328
+ { $set: { status: "deleted", deletedAt: (/* @__PURE__ */ new Date()).toISOString() } }
4354
4329
  );
4355
4330
  delCachedData();
4356
4331
  return "Successfully deleted division.";
@@ -4359,13 +4334,12 @@ function useDivisionRepo() {
4359
4334
  }
4360
4335
  }
4361
4336
  return {
4362
- createIndex,
4363
- createTextIndex,
4364
- createUniqueIndex,
4337
+ createIndexes,
4365
4338
  add,
4366
4339
  getAll,
4367
4340
  getById,
4368
4341
  updateFieldById,
4342
+ updateById,
4369
4343
  deleteById,
4370
4344
  getByName
4371
4345
  };
@@ -4414,33 +4388,27 @@ function useDivisionService() {
4414
4388
  var import_nodejs_utils17 = require("@eeplatform/nodejs-utils");
4415
4389
  var import_joi10 = __toESM(require("joi"));
4416
4390
  function useDivisionController() {
4391
+ const { add: _add } = useDivisionService();
4417
4392
  const {
4418
4393
  getAll: _getAll,
4419
4394
  getById: _getById,
4420
4395
  getByName: _getByName,
4421
4396
  updateFieldById: _updateFieldById,
4397
+ updateById: _updateById,
4422
4398
  deleteById: _deleteById
4423
4399
  } = useDivisionRepo();
4424
- const { add: _createDivision } = useDivisionService();
4425
- async function createDivision(req, res, next) {
4400
+ async function add(req, res, next) {
4426
4401
  const value = req.body;
4427
- const validation = import_joi10.default.object({
4428
- name: import_joi10.default.string().min(1).max(100).required(),
4429
- region: import_joi10.default.string().hex().optional().allow("", null),
4430
- regionName: import_joi10.default.string().min(1).max(100).optional().allow("", null),
4431
- superintendent: import_joi10.default.string().hex().optional().allow("", null),
4432
- superintendentName: import_joi10.default.string().min(1).max(100).optional().allow("", null)
4433
- });
4434
- const { error } = validation.validate(value);
4402
+ const { error } = schemaDivision.validate(value);
4435
4403
  if (error) {
4436
4404
  next(new import_nodejs_utils17.BadRequestError(error.message));
4437
4405
  return;
4438
4406
  }
4439
4407
  try {
4440
- const divisionId = await _createDivision(value);
4408
+ const data = await _add(value);
4441
4409
  res.json({
4442
4410
  message: "Successfully created division.",
4443
- data: { divisionId }
4411
+ data
4444
4412
  });
4445
4413
  return;
4446
4414
  } catch (error2) {
@@ -4453,13 +4421,13 @@ function useDivisionController() {
4453
4421
  page: import_joi10.default.number().min(1).optional().allow("", null),
4454
4422
  limit: import_joi10.default.number().min(1).optional().allow("", null),
4455
4423
  search: import_joi10.default.string().optional().allow("", null),
4456
- region: import_joi10.default.string().hex().optional().allow("", null)
4424
+ status: import_joi10.default.string().optional().allow("", null)
4457
4425
  });
4458
4426
  const { error } = validation.validate(query);
4459
4427
  const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
4460
4428
  const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
4461
4429
  const search = req.query.search ?? "";
4462
- const region = req.query.region ?? "";
4430
+ const status = req.query.status ?? "active";
4463
4431
  const isPageNumber = isFinite(page);
4464
4432
  if (!isPageNumber) {
4465
4433
  next(new import_nodejs_utils17.BadRequestError("Invalid page number."));
@@ -4475,8 +4443,8 @@ function useDivisionController() {
4475
4443
  return;
4476
4444
  }
4477
4445
  try {
4478
- const divisions = await _getAll({ page, limit, search, region });
4479
- res.json(divisions);
4446
+ const data = await _getAll({ page, limit, search, status });
4447
+ res.json(data);
4480
4448
  return;
4481
4449
  } catch (error2) {
4482
4450
  next(error2);
@@ -4494,7 +4462,10 @@ function useDivisionController() {
4494
4462
  }
4495
4463
  try {
4496
4464
  const data = await _getById(id);
4497
- res.json(data);
4465
+ res.json({
4466
+ message: "Successfully retrieved division.",
4467
+ data
4468
+ });
4498
4469
  return;
4499
4470
  } catch (error2) {
4500
4471
  next(error2);
@@ -4511,10 +4482,10 @@ function useDivisionController() {
4511
4482
  return;
4512
4483
  }
4513
4484
  try {
4514
- const division = await _getByName(name);
4485
+ const data = await _getByName(name);
4515
4486
  res.json({
4516
4487
  message: "Successfully retrieved division.",
4517
- data: { division }
4488
+ data
4518
4489
  });
4519
4490
  return;
4520
4491
  } catch (error2) {
@@ -4526,13 +4497,7 @@ function useDivisionController() {
4526
4497
  const { field, value } = req.body;
4527
4498
  const validation = import_joi10.default.object({
4528
4499
  _id: import_joi10.default.string().hex().required(),
4529
- field: import_joi10.default.string().valid(
4530
- "name",
4531
- "region",
4532
- "regionName",
4533
- "superintendent",
4534
- "superintendentName"
4535
- ).required(),
4500
+ field: import_joi10.default.string().valid("name", "director", "directorName").required(),
4536
4501
  value: import_joi10.default.string().required()
4537
4502
  });
4538
4503
  const { error } = validation.validate({ _id, field, value });
@@ -4548,7 +4513,23 @@ function useDivisionController() {
4548
4513
  next(error2);
4549
4514
  }
4550
4515
  }
4551
- async function deleteDivision(req, res, next) {
4516
+ async function updateById(req, res, next) {
4517
+ const _id = req.params.id;
4518
+ const payload = req.body;
4519
+ const { error } = schemaDivisionUpdate.validate({ _id, ...payload });
4520
+ if (error) {
4521
+ next(new import_nodejs_utils17.BadRequestError(error.message));
4522
+ return;
4523
+ }
4524
+ try {
4525
+ const message = await _updateById(_id, payload);
4526
+ res.json({ message });
4527
+ return;
4528
+ } catch (error2) {
4529
+ next(error2);
4530
+ }
4531
+ }
4532
+ async function deleteById(req, res, next) {
4552
4533
  const _id = req.params.id;
4553
4534
  const validation = import_joi10.default.object({
4554
4535
  _id: import_joi10.default.string().hex().required()
@@ -4567,203 +4548,173 @@ function useDivisionController() {
4567
4548
  }
4568
4549
  }
4569
4550
  return {
4570
- createDivision,
4551
+ add,
4571
4552
  getAll,
4572
4553
  getById,
4573
4554
  getByName,
4574
4555
  updateField,
4575
- deleteDivision
4556
+ updateById,
4557
+ deleteById
4576
4558
  };
4577
4559
  }
4578
4560
 
4579
4561
  // src/resources/school/school.model.ts
4562
+ var import_nodejs_utils18 = require("@eeplatform/nodejs-utils");
4580
4563
  var import_joi11 = __toESM(require("joi"));
4581
4564
  var import_mongodb11 = require("mongodb");
4582
4565
  var schemaSchool = import_joi11.default.object({
4583
- _id: import_joi11.default.string().hex().optional().allow("", null),
4584
- id: import_joi11.default.string().optional().allow("", null),
4585
- name: import_joi11.default.string().optional().allow("", null),
4586
- country: import_joi11.default.string().optional().allow("", null),
4587
- address: import_joi11.default.string().optional().allow("", null),
4588
- continuedAddress: import_joi11.default.string().optional().allow("", null),
4589
- city: import_joi11.default.string().required().allow("", null),
4590
- province: import_joi11.default.string().required().allow("", null),
4591
- district: import_joi11.default.string().optional().allow("", null),
4592
- postalCode: import_joi11.default.string().required().allow("", null),
4593
- courses: import_joi11.default.array().items(import_joi11.default.string()).optional(),
4594
- principalName: import_joi11.default.string().required().allow("", null),
4595
- principalEmail: import_joi11.default.string().email().optional().allow("", null),
4596
- principalNumber: import_joi11.default.string().optional().allow("", null),
4597
- region: import_joi11.default.string().hex().required(),
4598
- regionName: import_joi11.default.string().optional().allow("", null),
4599
- division: import_joi11.default.string().hex().required(),
4600
- divisionName: import_joi11.default.string().optional().allow("", null),
4601
- status: import_joi11.default.string().optional().allow(null, ""),
4602
- createdAt: import_joi11.default.date().optional().allow("", null),
4603
- updatedAt: import_joi11.default.date().optional().allow("", null),
4604
- createdBy: import_joi11.default.string().hex().optional().allow("", null)
4566
+ _id: import_joi11.default.string().hex().optional().allow(null, ""),
4567
+ id: import_joi11.default.string().min(1).max(50).required(),
4568
+ name: import_joi11.default.string().min(1).max(100).required(),
4569
+ region: import_joi11.default.string().hex().optional().allow(null, ""),
4570
+ regionName: import_joi11.default.string().min(1).max(100).optional().allow(null, ""),
4571
+ division: import_joi11.default.string().hex().optional().allow(null, ""),
4572
+ divisionName: import_joi11.default.string().min(1).max(100).optional().allow(null, ""),
4573
+ principal: import_joi11.default.string().hex().optional().allow(null, ""),
4574
+ principalName: import_joi11.default.string().min(1).max(100).optional().allow(null, ""),
4575
+ street: import_joi11.default.string().max(200).optional().allow(null, ""),
4576
+ barangay: import_joi11.default.string().max(200).optional().allow(null, ""),
4577
+ city: import_joi11.default.string().max(100).optional().allow(null, ""),
4578
+ province: import_joi11.default.string().max(100).optional().allow(null, ""),
4579
+ postalCode: import_joi11.default.string().max(20).optional().allow(null, ""),
4580
+ contactNumber: import_joi11.default.string().max(20).optional().allow(null, ""),
4581
+ email: import_joi11.default.string().email().max(100).optional().allow(null, ""),
4582
+ createdBy: import_joi11.default.string().optional().allow(null, ""),
4583
+ createdAt: import_joi11.default.string().isoDate().optional().allow(null, ""),
4584
+ updatedAt: import_joi11.default.string().isoDate().optional().allow(null, ""),
4585
+ deletedAt: import_joi11.default.string().isoDate().optional().allow(null, "")
4605
4586
  });
4606
- function MSchool(value) {
4587
+ function modelSchool(value) {
4607
4588
  const { error } = schemaSchool.validate(value);
4608
4589
  if (error) {
4609
- throw new Error(`Validation error: ${error.message}`);
4590
+ throw new import_nodejs_utils18.BadRequestError(`Invalid sdo data: ${error.message}`);
4610
4591
  }
4611
- if (value._id) {
4592
+ if (value._id && typeof value._id === "string") {
4612
4593
  try {
4613
- value._id = new import_mongodb11.ObjectId(value._id);
4594
+ value._id = import_mongodb11.ObjectId.createFromTime(value._id);
4614
4595
  } catch (error2) {
4615
4596
  throw new Error("Invalid _id.");
4616
4597
  }
4617
4598
  }
4618
- if (value.region) {
4619
- try {
4620
- value.region = new import_mongodb11.ObjectId(value.region);
4621
- } catch (error2) {
4622
- throw new Error("Invalid region.");
4623
- }
4624
- }
4625
- if (value.division) {
4626
- try {
4627
- value.division = new import_mongodb11.ObjectId(value.division);
4628
- } catch (error2) {
4629
- throw new Error("Invalid division.");
4630
- }
4631
- }
4632
- if (value.createdBy) {
4633
- try {
4634
- value.createdBy = new import_mongodb11.ObjectId(value.createdBy);
4635
- } catch (error2) {
4636
- throw new Error("Invalid createdBy.");
4637
- }
4638
- }
4639
4599
  return {
4640
- _id: value._id ? value._id : new import_mongodb11.ObjectId(),
4600
+ _id: value._id,
4641
4601
  id: value.id,
4642
4602
  name: value.name,
4643
- country: value.country ?? "",
4644
- address: value.address ?? "",
4645
- continuedAddress: value.continuedAddress ?? "",
4646
- city: value.city ?? "",
4647
- province: value.province ?? "",
4648
- postalCode: value.postalCode ?? "",
4649
- courses: value.courses || [],
4650
- principalName: value.principalName ?? "",
4651
- principalEmail: value.principalEmail ?? "",
4652
- principalNumber: value.principalNumber ?? "",
4653
4603
  region: value.region,
4654
4604
  regionName: value.regionName ?? "",
4655
4605
  division: value.division,
4656
4606
  divisionName: value.divisionName ?? "",
4607
+ principal: value.principal,
4608
+ principalName: value.principalName ?? "",
4609
+ status: value.status ?? "active",
4610
+ street: value.street ?? "",
4611
+ barangay: value.barangay ?? "",
4612
+ city: value.city ?? "",
4613
+ province: value.province ?? "",
4614
+ postalCode: value.postalCode ?? "",
4615
+ contactNumber: value.contactNumber ?? "",
4616
+ email: value.email ?? "",
4617
+ createdBy: value.createdBy ?? "",
4657
4618
  createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4658
4619
  updatedAt: value.updatedAt ?? "",
4659
- status: value.status ?? "pending",
4660
- createdBy: value.createdBy ?? ""
4620
+ deletedAt: value.deletedAt ?? ""
4661
4621
  };
4662
4622
  }
4663
4623
 
4664
4624
  // src/resources/school/school.repository.ts
4665
- var import_nodejs_utils18 = require("@eeplatform/nodejs-utils");
4625
+ var import_nodejs_utils19 = require("@eeplatform/nodejs-utils");
4666
4626
  var import_mongodb12 = require("mongodb");
4667
4627
  function useSchoolRepo() {
4668
- const db = import_nodejs_utils18.useAtlas.getDb();
4628
+ const db = import_nodejs_utils19.useAtlas.getDb();
4669
4629
  if (!db) {
4670
- throw new import_nodejs_utils18.BadRequestError("Unable to connect to server.");
4630
+ throw new Error("Unable to connect to server.");
4671
4631
  }
4672
- const namespace_collection = "schools";
4632
+ const namespace_collection = "deped.schools";
4673
4633
  const collection = db.collection(namespace_collection);
4674
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils18.useCache)(namespace_collection);
4634
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils19.useCache)(namespace_collection);
4635
+ async function createIndexes() {
4636
+ try {
4637
+ await collection.createIndexes([
4638
+ { key: { name: 1 } },
4639
+ { key: { createdAt: 1 } },
4640
+ { key: { name: "text" } },
4641
+ { key: { name: 1 }, unique: true, name: "unique_name" }
4642
+ ]);
4643
+ } catch (error) {
4644
+ throw new Error("Failed to create index on schools.");
4645
+ }
4646
+ }
4675
4647
  function delCachedData() {
4676
4648
  delNamespace().then(() => {
4677
- import_nodejs_utils18.logger.log({
4649
+ import_nodejs_utils19.logger.log({
4678
4650
  level: "info",
4679
4651
  message: `Cache namespace cleared for ${namespace_collection}`
4680
4652
  });
4681
4653
  }).catch((err) => {
4682
- import_nodejs_utils18.logger.log({
4654
+ import_nodejs_utils19.logger.log({
4683
4655
  level: "error",
4684
4656
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
4685
4657
  });
4686
4658
  });
4687
4659
  }
4688
- async function createIndex() {
4689
- try {
4690
- await collection.createIndexes([
4691
- { key: { name: 1 } },
4692
- { key: { id: 1 }, unique: true },
4693
- { key: { region: 1 } },
4694
- { key: { division: 1 } },
4695
- {
4696
- key: {
4697
- name: "text",
4698
- address: "text",
4699
- continuedAddress: "text",
4700
- city: "text",
4701
- province: "text",
4702
- postalCode: "text",
4703
- regionName: "text",
4704
- divisionName: "text"
4705
- }
4706
- }
4707
- ]);
4708
- } catch (error) {
4709
- throw new import_nodejs_utils18.BadRequestError("Failed to create index on school.");
4710
- }
4711
- }
4712
4660
  async function add(value, session) {
4713
4661
  try {
4714
- value = MSchool(value);
4662
+ value = modelSchool(value);
4715
4663
  const res = await collection.insertOne(value, { session });
4716
4664
  delCachedData();
4717
4665
  return res.insertedId;
4718
4666
  } catch (error) {
4719
- import_nodejs_utils18.logger.log({
4667
+ import_nodejs_utils19.logger.log({
4720
4668
  level: "error",
4721
- message: `Failed to add school: ${error}`
4669
+ message: error.message
4722
4670
  });
4723
- const isDuplicated = error.message.includes("duplicate");
4724
- if (isDuplicated) {
4725
- throw new import_nodejs_utils18.BadRequestError("School already exist.");
4671
+ if (error instanceof import_nodejs_utils19.AppError) {
4672
+ throw error;
4673
+ } else {
4674
+ const isDuplicated = error.message.includes("duplicate");
4675
+ if (isDuplicated) {
4676
+ throw new import_nodejs_utils19.BadRequestError("School already exists.");
4677
+ }
4678
+ throw new Error("Failed to create school.");
4726
4679
  }
4727
- throw error;
4728
4680
  }
4729
4681
  }
4730
4682
  async function getAll({
4683
+ search = "",
4731
4684
  page = 1,
4732
- limit = 20,
4685
+ limit = 10,
4733
4686
  sort = {},
4734
- status = "active",
4735
- org = "",
4736
- app = "admin",
4737
- search = ""
4687
+ status = "active"
4738
4688
  } = {}) {
4739
- page = Math.max(0, page - 1);
4740
- if (sort && Object.keys(sort).length === 0) {
4741
- sort = { name: 1 };
4742
- }
4743
- const query = { status };
4689
+ page = page > 0 ? page - 1 : 0;
4690
+ const query = {
4691
+ deletedAt: { $in: ["", null] },
4692
+ status
4693
+ };
4694
+ sort = Object.keys(sort).length > 0 ? sort : { _id: 1 };
4744
4695
  const cacheKeyOptions = {
4696
+ status,
4745
4697
  page,
4746
4698
  limit,
4747
- sort: JSON.stringify(sort),
4748
- status
4699
+ sort: JSON.stringify(sort)
4749
4700
  };
4750
4701
  if (search) {
4751
4702
  query.$text = { $search: search };
4752
4703
  cacheKeyOptions.search = search;
4753
4704
  }
4754
- if (org) {
4755
- try {
4756
- query[app] = new import_mongodb12.ObjectId(org);
4757
- cacheKeyOptions[app] = org;
4758
- } catch (error) {
4759
- throw new import_nodejs_utils18.BadRequestError("Invalid org.");
4760
- }
4761
- }
4705
+ const cacheKey = (0, import_nodejs_utils19.makeCacheKey)(namespace_collection, cacheKeyOptions);
4706
+ import_nodejs_utils19.logger.log({
4707
+ level: "info",
4708
+ message: `Cache key for getAll schools: ${cacheKey}`
4709
+ });
4762
4710
  try {
4763
- const cacheKey = (0, import_nodejs_utils18.makeCacheKey)(namespace_collection, cacheKeyOptions);
4764
- const cachedData = await getCache(cacheKey);
4765
- if (cachedData) {
4766
- return cachedData;
4711
+ const cached = await getCache(cacheKey);
4712
+ if (cached) {
4713
+ import_nodejs_utils19.logger.log({
4714
+ level: "info",
4715
+ message: `Cache hit for getAll schools: ${cacheKey}`
4716
+ });
4717
+ return cached;
4767
4718
  }
4768
4719
  const items = await collection.aggregate([
4769
4720
  { $match: query },
@@ -4772,159 +4723,232 @@ function useSchoolRepo() {
4772
4723
  { $limit: limit }
4773
4724
  ]).toArray();
4774
4725
  const length = await collection.countDocuments(query);
4775
- const data = (0, import_nodejs_utils18.paginate)(items, page, limit, length);
4726
+ const data = (0, import_nodejs_utils19.paginate)(items, page, limit, length);
4776
4727
  setCache(cacheKey, data, 600).then(() => {
4777
- import_nodejs_utils18.logger.log({
4728
+ import_nodejs_utils19.logger.log({
4778
4729
  level: "info",
4779
- message: `Cache set for key ${cacheKey}`
4730
+ message: `Cache set for getAll schools: ${cacheKey}`
4780
4731
  });
4781
4732
  }).catch((err) => {
4782
- import_nodejs_utils18.logger.log({
4733
+ import_nodejs_utils19.logger.log({
4783
4734
  level: "error",
4784
- message: `Failed to set cache for key ${cacheKey}: ${err.message}`
4735
+ message: `Failed to set cache for getAll schools: ${err.message}`
4785
4736
  });
4786
4737
  });
4787
4738
  return data;
4788
4739
  } catch (error) {
4789
- import_nodejs_utils18.logger.log({
4790
- level: "error",
4791
- message: `Failed to get all schools: ${error}`
4792
- });
4740
+ import_nodejs_utils19.logger.log({ level: "error", message: `${error}` });
4793
4741
  throw error;
4794
4742
  }
4795
4743
  }
4796
- async function updateStatusById(_id, status, session) {
4744
+ async function getById(_id, status) {
4797
4745
  try {
4798
4746
  _id = new import_mongodb12.ObjectId(_id);
4799
4747
  } catch (error) {
4800
- throw new import_nodejs_utils18.BadRequestError("Invalid school ID.");
4748
+ throw new import_nodejs_utils19.BadRequestError("Invalid ID.");
4801
4749
  }
4802
- const result = await collection.updateOne(
4803
- { _id },
4804
- { $set: { status, updatedAt: /* @__PURE__ */ new Date() } },
4805
- { session }
4806
- );
4807
- delCachedData();
4808
- return result;
4809
- }
4810
- async function updateFieldById({ _id, field, value } = {}, session) {
4811
- const allowedFields = [
4812
- "name",
4813
- "country",
4814
- "address",
4815
- "continuedAddress",
4816
- "city",
4817
- "province",
4818
- "postalCode",
4819
- "courses",
4820
- "email",
4821
- "principalName",
4822
- "principalEmail",
4823
- "principalNumber",
4824
- "region",
4825
- "regionName",
4826
- "division",
4827
- "divisionName"
4828
- ];
4829
- if (!allowedFields.includes(field)) {
4830
- throw new import_nodejs_utils18.BadRequestError(
4831
- `Field "${field}" is not allowed to be updated.`
4832
- );
4833
- }
4834
- try {
4835
- _id = new import_mongodb12.ObjectId(_id);
4836
- } catch (error) {
4837
- throw new import_nodejs_utils18.BadRequestError("Invalid ID.");
4750
+ const query = { _id };
4751
+ const cacheKeyOptions = {
4752
+ _id: String(_id),
4753
+ deletedAt: { $in: ["", null] }
4754
+ };
4755
+ if (status) {
4756
+ query.status = status;
4757
+ cacheKeyOptions.status = status;
4838
4758
  }
4759
+ const cacheKey = (0, import_nodejs_utils19.makeCacheKey)(namespace_collection, cacheKeyOptions);
4839
4760
  try {
4840
- const result = await collection.updateOne(
4841
- { _id },
4842
- { $set: { [field]: value } },
4843
- { session }
4844
- );
4845
- delCachedData();
4761
+ const cached = await getCache(cacheKey);
4762
+ if (cached) {
4763
+ import_nodejs_utils19.logger.log({
4764
+ level: "info",
4765
+ message: `Cache hit for getById school: ${cacheKey}`
4766
+ });
4767
+ return cached;
4768
+ }
4769
+ const result = await collection.findOne(query);
4770
+ if (!result) {
4771
+ throw new import_nodejs_utils19.BadRequestError("School not found.");
4772
+ }
4773
+ setCache(cacheKey, result, 300).then(() => {
4774
+ import_nodejs_utils19.logger.log({
4775
+ level: "info",
4776
+ message: `Cache set for school by id: ${cacheKey}`
4777
+ });
4778
+ }).catch((err) => {
4779
+ import_nodejs_utils19.logger.log({
4780
+ level: "error",
4781
+ message: `Failed to set cache for school by id: ${err.message}`
4782
+ });
4783
+ });
4846
4784
  return result;
4847
4785
  } catch (error) {
4848
- throw new import_nodejs_utils18.BadRequestError(`Failed to update school ${field}.`);
4786
+ if (error instanceof import_nodejs_utils19.AppError) {
4787
+ throw error;
4788
+ } else {
4789
+ throw new import_nodejs_utils19.InternalServerError("Failed to get school.");
4790
+ }
4849
4791
  }
4850
4792
  }
4851
4793
  async function getPendingByCreatedBy(createdBy) {
4852
4794
  try {
4853
4795
  createdBy = new import_mongodb12.ObjectId(createdBy);
4854
4796
  } catch (error) {
4855
- throw new import_nodejs_utils18.BadRequestError("Invalid createdBy ID.");
4856
- }
4857
- const cacheKey = (0, import_nodejs_utils18.makeCacheKey)(namespace_collection, {
4858
- createdBy,
4859
- status: "pending"
4860
- });
4861
- const cachedData = await getCache(cacheKey);
4862
- if (cachedData) {
4863
- return cachedData;
4797
+ throw new import_nodejs_utils19.BadRequestError("Invalid ID.");
4864
4798
  }
4799
+ const cacheKey = (0, import_nodejs_utils19.makeCacheKey)(namespace_collection, { createdBy });
4865
4800
  try {
4866
- const school = await collection.findOne({ createdBy, status: "pending" });
4867
- setCache(cacheKey, school, 600).then(() => {
4868
- import_nodejs_utils18.logger.log({
4801
+ const cached = await getCache(cacheKey);
4802
+ if (cached) {
4803
+ import_nodejs_utils19.logger.log({
4869
4804
  level: "info",
4870
- message: `Cache set for school by createdBy: ${cacheKey}`
4805
+ message: `Cache hit for getById school: ${cacheKey}`
4806
+ });
4807
+ return cached;
4808
+ }
4809
+ const result = await collection.findOne({
4810
+ createdBy,
4811
+ status: "pending"
4812
+ });
4813
+ if (!result) {
4814
+ throw new import_nodejs_utils19.BadRequestError("School not found.");
4815
+ }
4816
+ setCache(cacheKey, result, 300).then(() => {
4817
+ import_nodejs_utils19.logger.log({
4818
+ level: "info",
4819
+ message: `Cache set for school by id: ${cacheKey}`
4871
4820
  });
4872
4821
  }).catch((err) => {
4873
- import_nodejs_utils18.logger.log({
4822
+ import_nodejs_utils19.logger.log({
4874
4823
  level: "error",
4875
- message: `Failed to set cache for school by createdBy: ${err.message}`
4824
+ message: `Failed to set cache for school by id: ${err.message}`
4876
4825
  });
4877
4826
  });
4878
- return school;
4827
+ return result;
4879
4828
  } catch (error) {
4880
- throw error;
4829
+ if (error instanceof import_nodejs_utils19.AppError) {
4830
+ throw error;
4831
+ } else {
4832
+ throw new import_nodejs_utils19.InternalServerError("Failed to get school.");
4833
+ }
4881
4834
  }
4882
4835
  }
4883
- async function getPendingById(_id) {
4884
- try {
4885
- _id = new import_mongodb12.ObjectId(_id);
4886
- } catch (error) {
4887
- throw new import_nodejs_utils18.BadRequestError("Invalid ID.");
4888
- }
4889
- const cacheKey = (0, import_nodejs_utils18.makeCacheKey)(namespace_collection, {
4890
- _id,
4891
- status: "pending"
4892
- });
4893
- const cachedData = await getCache(cacheKey);
4894
- if (cachedData) {
4895
- return cachedData;
4896
- }
4836
+ async function getByName(name) {
4837
+ const cacheKey = (0, import_nodejs_utils19.makeCacheKey)(namespace_collection, { name });
4897
4838
  try {
4898
- const school = await collection.findOne({ _id, status: "pending" });
4899
- setCache(cacheKey, school, 600).then(() => {
4900
- import_nodejs_utils18.logger.log({
4839
+ const cached = await getCache(cacheKey);
4840
+ if (cached) {
4841
+ import_nodejs_utils19.logger.log({
4901
4842
  level: "info",
4902
- message: `Cache set for school by ID: ${cacheKey}`
4843
+ message: `Cache hit for getByName school: ${cacheKey}`
4844
+ });
4845
+ return cached;
4846
+ }
4847
+ const result = await collection.findOne({
4848
+ name,
4849
+ deletedAt: { $in: ["", null] }
4850
+ });
4851
+ if (!result) {
4852
+ throw new import_nodejs_utils19.BadRequestError("School not found.");
4853
+ }
4854
+ setCache(cacheKey, result, 300).then(() => {
4855
+ import_nodejs_utils19.logger.log({
4856
+ level: "info",
4857
+ message: `Cache set for school by name: ${cacheKey}`
4903
4858
  });
4904
4859
  }).catch((err) => {
4905
- import_nodejs_utils18.logger.log({
4860
+ import_nodejs_utils19.logger.log({
4906
4861
  level: "error",
4907
- message: `Failed to set cache for school by ID: ${err.message}`
4862
+ message: `Failed to set cache for school by name: ${err.message}`
4908
4863
  });
4909
4864
  });
4910
- return school;
4865
+ return result;
4911
4866
  } catch (error) {
4912
- throw error;
4867
+ if (error instanceof import_nodejs_utils19.AppError) {
4868
+ throw error;
4869
+ } else {
4870
+ throw new import_nodejs_utils19.InternalServerError("Failed to get school.");
4871
+ }
4872
+ }
4873
+ }
4874
+ async function updateStatusById(_id, status, session) {
4875
+ try {
4876
+ _id = new import_mongodb12.ObjectId(_id);
4877
+ } catch (error) {
4878
+ throw new import_nodejs_utils19.BadRequestError("Invalid ID.");
4879
+ }
4880
+ try {
4881
+ await collection.updateOne(
4882
+ { _id },
4883
+ { $set: { status, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
4884
+ { session }
4885
+ );
4886
+ delCachedData();
4887
+ return `Successfully updated school status to ${status}.`;
4888
+ } catch (error) {
4889
+ if (error instanceof import_nodejs_utils19.AppError) {
4890
+ throw error;
4891
+ } else {
4892
+ throw new import_nodejs_utils19.InternalServerError("Failed to update school status.");
4893
+ }
4894
+ }
4895
+ }
4896
+ async function updateFieldById({ _id, field, value } = {}, session) {
4897
+ const allowedFields = ["name"];
4898
+ if (!allowedFields.includes(field)) {
4899
+ throw new import_nodejs_utils19.BadRequestError(
4900
+ `Field "${field}" is not allowed to be updated.`
4901
+ );
4902
+ }
4903
+ try {
4904
+ _id = new import_mongodb12.ObjectId(_id);
4905
+ } catch (error) {
4906
+ throw new import_nodejs_utils19.BadRequestError("Invalid ID.");
4907
+ }
4908
+ try {
4909
+ await collection.updateOne(
4910
+ { _id, deletedAt: { $in: ["", null] } },
4911
+ { $set: { [field]: value, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
4912
+ { session }
4913
+ );
4914
+ delCachedData();
4915
+ return `Successfully updated school ${field}.`;
4916
+ } catch (error) {
4917
+ throw new import_nodejs_utils19.InternalServerError(`Failed to update school ${field}.`);
4918
+ }
4919
+ }
4920
+ async function deleteById(_id) {
4921
+ try {
4922
+ _id = new import_mongodb12.ObjectId(_id);
4923
+ } catch (error) {
4924
+ throw new import_nodejs_utils19.BadRequestError("Invalid ID.");
4925
+ }
4926
+ try {
4927
+ await collection.updateOne(
4928
+ { _id },
4929
+ { $set: { deletedAt: (/* @__PURE__ */ new Date()).toISOString() } }
4930
+ );
4931
+ delCachedData();
4932
+ return "Successfully deleted school.";
4933
+ } catch (error) {
4934
+ throw new import_nodejs_utils19.InternalServerError("Failed to delete school.");
4913
4935
  }
4914
4936
  }
4915
4937
  return {
4916
- createIndex,
4938
+ createIndexes,
4917
4939
  add,
4918
4940
  getAll,
4941
+ getById,
4942
+ getPendingByCreatedBy,
4919
4943
  updateStatusById,
4920
4944
  updateFieldById,
4921
- getPendingByCreatedBy,
4922
- getPendingById
4945
+ deleteById,
4946
+ getByName
4923
4947
  };
4924
4948
  }
4925
4949
 
4926
4950
  // src/resources/school/school.service.ts
4927
- var import_nodejs_utils19 = require("@eeplatform/nodejs-utils");
4951
+ var import_nodejs_utils20 = require("@eeplatform/nodejs-utils");
4928
4952
  var import_core2 = require("@eeplatform/core");
4929
4953
 
4930
4954
  // node_modules/xlsx/xlsx.mjs
@@ -36293,7 +36317,7 @@ function useSchoolService() {
36293
36317
  add: addSchool,
36294
36318
  getPendingByCreatedBy,
36295
36319
  updateStatusById,
36296
- getPendingById
36320
+ getById
36297
36321
  } = useSchoolRepo();
36298
36322
  const { addRole } = (0, import_core2.useRoleRepo)();
36299
36323
  const { getUserById } = (0, import_core2.useUserRepo)();
@@ -36301,11 +36325,11 @@ function useSchoolService() {
36301
36325
  async function register(value) {
36302
36326
  const { error } = schemaSchool.validate(value);
36303
36327
  if (error) {
36304
- throw new import_nodejs_utils19.BadRequestError(error.message);
36328
+ throw new import_nodejs_utils20.BadRequestError(error.message);
36305
36329
  }
36306
36330
  const existingSchool = await getPendingByCreatedBy(value.createdBy ?? "");
36307
36331
  if (existingSchool) {
36308
- throw new import_nodejs_utils19.BadRequestError(
36332
+ throw new import_nodejs_utils20.BadRequestError(
36309
36333
  "You already have a pending school registration."
36310
36334
  );
36311
36335
  }
@@ -36318,11 +36342,11 @@ function useSchoolService() {
36318
36342
  }
36319
36343
  }
36320
36344
  async function approve(id) {
36321
- const school = await getPendingById(id);
36345
+ const school = await getById(id, "pending");
36322
36346
  if (!school) {
36323
- throw new import_nodejs_utils19.BadRequestError("School registration not found.");
36347
+ throw new import_nodejs_utils20.BadRequestError("School registration not found.");
36324
36348
  }
36325
- const session = import_nodejs_utils19.useAtlas.getClient()?.startSession();
36349
+ const session = import_nodejs_utils20.useAtlas.getClient()?.startSession();
36326
36350
  if (!session) {
36327
36351
  throw new Error("Unable to start session for school service.");
36328
36352
  }
@@ -36344,11 +36368,11 @@ function useSchoolService() {
36344
36368
  session
36345
36369
  );
36346
36370
  if (!school.createdBy) {
36347
- throw new import_nodejs_utils19.BadRequestError("School must have a creator.");
36371
+ throw new import_nodejs_utils20.BadRequestError("School must have a creator.");
36348
36372
  }
36349
36373
  const user = await getUserById(school.createdBy ?? "");
36350
36374
  if (!user) {
36351
- throw new import_nodejs_utils19.BadRequestError("User not found for the school creator.");
36375
+ throw new import_nodejs_utils20.BadRequestError("User not found for the school creator.");
36352
36376
  }
36353
36377
  await addMember(
36354
36378
  {
@@ -36365,7 +36389,7 @@ function useSchoolService() {
36365
36389
  await session.commitTransaction();
36366
36390
  return "School registration has been approved.";
36367
36391
  } catch (error) {
36368
- import_nodejs_utils19.logger.log({
36392
+ import_nodejs_utils20.logger.log({
36369
36393
  level: "error",
36370
36394
  message: `Error approving school registration: ${error.message}`
36371
36395
  });
@@ -36378,9 +36402,9 @@ function useSchoolService() {
36378
36402
  async function add(value) {
36379
36403
  const { error } = schemaSchool.validate(value);
36380
36404
  if (error) {
36381
- throw new import_nodejs_utils19.BadRequestError(error.message);
36405
+ throw new import_nodejs_utils20.BadRequestError(error.message);
36382
36406
  }
36383
- const session = import_nodejs_utils19.useAtlas.getClient()?.startSession();
36407
+ const session = import_nodejs_utils20.useAtlas.getClient()?.startSession();
36384
36408
  if (!session) {
36385
36409
  throw new Error("Unable to start session for school service.");
36386
36410
  }
@@ -36402,11 +36426,11 @@ function useSchoolService() {
36402
36426
  session
36403
36427
  );
36404
36428
  if (!value.createdBy) {
36405
- throw new import_nodejs_utils19.BadRequestError("School must have a creator.");
36429
+ throw new import_nodejs_utils20.BadRequestError("School must have a creator.");
36406
36430
  }
36407
36431
  const user = await getUserById(value.createdBy ?? "");
36408
36432
  if (!user) {
36409
- throw new import_nodejs_utils19.BadRequestError("User not found for the school creator.");
36433
+ throw new import_nodejs_utils20.BadRequestError("User not found for the school creator.");
36410
36434
  }
36411
36435
  await addMember(
36412
36436
  {
@@ -36423,7 +36447,7 @@ function useSchoolService() {
36423
36447
  await session.commitTransaction();
36424
36448
  return "School has been added and activated successfully.";
36425
36449
  } catch (error2) {
36426
- import_nodejs_utils19.logger.log({
36450
+ import_nodejs_utils20.logger.log({
36427
36451
  level: "error",
36428
36452
  message: `Error adding school: ${error2.message}`
36429
36453
  });
@@ -36436,7 +36460,7 @@ function useSchoolService() {
36436
36460
  async function addBulk(file, region, division) {
36437
36461
  const MAX_SIZE = 16 * 1024 * 1024;
36438
36462
  if (file.size > MAX_SIZE) {
36439
- throw new import_nodejs_utils19.BadRequestError(
36463
+ throw new import_nodejs_utils20.BadRequestError(
36440
36464
  "File size exceeds 16MB limit. Please use a smaller file to ensure transaction compatibility."
36441
36465
  );
36442
36466
  }
@@ -36460,18 +36484,18 @@ function useSchoolService() {
36460
36484
  transformHeader: (header) => header.trim()
36461
36485
  });
36462
36486
  if (parseResult.errors.length > 0) {
36463
- throw new import_nodejs_utils19.BadRequestError(
36487
+ throw new import_nodejs_utils20.BadRequestError(
36464
36488
  `CSV parsing error: ${parseResult.errors[0].message}`
36465
36489
  );
36466
36490
  }
36467
36491
  schools = parseResult.data;
36468
36492
  } else {
36469
- throw new import_nodejs_utils19.BadRequestError(
36493
+ throw new import_nodejs_utils20.BadRequestError(
36470
36494
  "Unsupported file type. Please upload an Excel (.xlsx, .xls) or CSV (.csv) file."
36471
36495
  );
36472
36496
  }
36473
36497
  if (!schools || schools.length === 0) {
36474
- throw new import_nodejs_utils19.BadRequestError("No data found in the uploaded file.");
36498
+ throw new import_nodejs_utils20.BadRequestError("No data found in the uploaded file.");
36475
36499
  }
36476
36500
  const errors = [];
36477
36501
  for (let i = 0; i < schools.length; i++) {
@@ -36496,21 +36520,17 @@ function useSchoolService() {
36496
36520
  const school = {
36497
36521
  id: schoolId.trim(),
36498
36522
  name: schoolName.trim(),
36499
- country: "Philippines",
36500
- // Default country
36501
- address: district.trim(),
36502
- // Use district as address
36503
- continuedAddress: "",
36523
+ street: district.trim(),
36524
+ // Use district as street
36525
+ barangay: "",
36504
36526
  city: district.trim(),
36505
36527
  // Use district as city
36506
36528
  province: "",
36507
36529
  // Will need to be set based on region/division
36508
36530
  postalCode: "",
36509
- courses: [],
36510
- // Empty array for courses
36511
36531
  principalName: "",
36512
- principalEmail: "",
36513
- principalNumber: "",
36532
+ email: "",
36533
+ contactNumber: "",
36514
36534
  region,
36515
36535
  regionName: "",
36516
36536
  // Will be populated from region lookup
@@ -36532,31 +36552,31 @@ function useSchoolService() {
36532
36552
  }
36533
36553
  }
36534
36554
  if (errors.length > 0) {
36535
- throw new import_nodejs_utils19.BadRequestError(
36555
+ throw new import_nodejs_utils20.BadRequestError(
36536
36556
  `Validation errors found:
36537
36557
  ${errors.slice(0, 10).join("\n")}${errors.length > 10 ? `
36538
36558
  ... and ${errors.length - 10} more errors` : ""}`
36539
36559
  );
36540
36560
  }
36541
36561
  if (validatedSchools.length === 0) {
36542
- throw new import_nodejs_utils19.BadRequestError(
36562
+ throw new import_nodejs_utils20.BadRequestError(
36543
36563
  "No valid school records found after validation."
36544
36564
  );
36545
36565
  }
36546
36566
  if (totalSize > MAX_SIZE) {
36547
- throw new import_nodejs_utils19.BadRequestError(
36567
+ throw new import_nodejs_utils20.BadRequestError(
36548
36568
  `Data payload (${Math.round(
36549
36569
  totalSize / 1024 / 1024
36550
36570
  )}MB) exceeds MongoDB transaction limit of 16MB. Please reduce the number of records or split into smaller files.`
36551
36571
  );
36552
36572
  }
36553
36573
  } catch (error) {
36554
- if (error instanceof import_nodejs_utils19.BadRequestError) {
36574
+ if (error instanceof import_nodejs_utils20.BadRequestError) {
36555
36575
  throw error;
36556
36576
  }
36557
- throw new import_nodejs_utils19.BadRequestError(`File processing error: ${error.message}`);
36577
+ throw new import_nodejs_utils20.BadRequestError(`File processing error: ${error.message}`);
36558
36578
  }
36559
- const session = import_nodejs_utils19.useAtlas.getClient()?.startSession();
36579
+ const session = import_nodejs_utils20.useAtlas.getClient()?.startSession();
36560
36580
  if (!session) {
36561
36581
  throw new Error("Unable to start session for bulk school upload.");
36562
36582
  }
@@ -36599,7 +36619,7 @@ ${errors.slice(0, 10).join("\n")}${errors.length > 10 ? `
36599
36619
  }
36600
36620
  };
36601
36621
  } catch (error) {
36602
- import_nodejs_utils19.logger.log({
36622
+ import_nodejs_utils20.logger.log({
36603
36623
  level: "error",
36604
36624
  message: `Error in bulk school upload: ${error.message}`
36605
36625
  });
@@ -36618,7 +36638,7 @@ ${errors.slice(0, 10).join("\n")}${errors.length > 10 ? `
36618
36638
  }
36619
36639
 
36620
36640
  // src/resources/school/school.controller.ts
36621
- var import_nodejs_utils20 = require("@eeplatform/nodejs-utils");
36641
+ var import_nodejs_utils21 = require("@eeplatform/nodejs-utils");
36622
36642
  var import_joi12 = __toESM(require("joi"));
36623
36643
  function useSchoolController() {
36624
36644
  const {
@@ -36636,7 +36656,7 @@ function useSchoolController() {
36636
36656
  const payload = req.body;
36637
36657
  const { error } = schemaSchool.validate(payload);
36638
36658
  if (error) {
36639
- next(new import_nodejs_utils20.BadRequestError(`Validation error: ${error.message}`));
36659
+ next(new import_nodejs_utils21.BadRequestError(`Validation error: ${error.message}`));
36640
36660
  return;
36641
36661
  }
36642
36662
  try {
@@ -36661,7 +36681,7 @@ function useSchoolController() {
36661
36681
  });
36662
36682
  const { error } = validation.validate(req.query);
36663
36683
  if (error) {
36664
- next(new import_nodejs_utils20.BadRequestError(`Validation error: ${error.message}`));
36684
+ next(new import_nodejs_utils21.BadRequestError(`Validation error: ${error.message}`));
36665
36685
  return;
36666
36686
  }
36667
36687
  const page = parseInt(req.query.page) ?? 1;
@@ -36676,8 +36696,6 @@ function useSchoolController() {
36676
36696
  });
36677
36697
  }
36678
36698
  const status = req.query.status ?? "active";
36679
- const org = req.query.org ?? "";
36680
- const app = req.query.app ?? "admin";
36681
36699
  const search = req.query.search ?? "";
36682
36700
  try {
36683
36701
  const schools = await _getAll({
@@ -36685,8 +36703,6 @@ function useSchoolController() {
36685
36703
  limit,
36686
36704
  sort: sortObj,
36687
36705
  status,
36688
- org,
36689
- app,
36690
36706
  search
36691
36707
  });
36692
36708
  res.status(200).json(schools);
@@ -36700,7 +36716,7 @@ function useSchoolController() {
36700
36716
  const validation = import_joi12.default.string().hex().required();
36701
36717
  const { error } = validation.validate(createdBy);
36702
36718
  if (error) {
36703
- next(new import_nodejs_utils20.BadRequestError(`Validation error: ${error.message}`));
36719
+ next(new import_nodejs_utils21.BadRequestError(`Validation error: ${error.message}`));
36704
36720
  return;
36705
36721
  }
36706
36722
  try {
@@ -36720,7 +36736,7 @@ function useSchoolController() {
36720
36736
  });
36721
36737
  const { error } = validation.validate({ id: schoolId, status });
36722
36738
  if (error) {
36723
- next(new import_nodejs_utils20.BadRequestError(`Validation error: ${error.message}`));
36739
+ next(new import_nodejs_utils21.BadRequestError(`Validation error: ${error.message}`));
36724
36740
  return;
36725
36741
  }
36726
36742
  try {
@@ -36735,7 +36751,7 @@ function useSchoolController() {
36735
36751
  const payload = req.body;
36736
36752
  const { error } = schemaSchool.validate(payload);
36737
36753
  if (error) {
36738
- next(new import_nodejs_utils20.BadRequestError(`Validation error: ${error.message}`));
36754
+ next(new import_nodejs_utils21.BadRequestError(`Validation error: ${error.message}`));
36739
36755
  return;
36740
36756
  }
36741
36757
  try {
@@ -36754,7 +36770,7 @@ function useSchoolController() {
36754
36770
  });
36755
36771
  const { error } = validation.validate({ id: schoolId });
36756
36772
  if (error) {
36757
- next(new import_nodejs_utils20.BadRequestError(`Validation error: ${error.message}`));
36773
+ next(new import_nodejs_utils21.BadRequestError(`Validation error: ${error.message}`));
36758
36774
  return;
36759
36775
  }
36760
36776
  try {
@@ -36777,7 +36793,7 @@ function useSchoolController() {
36777
36793
  });
36778
36794
  const { error } = validation.validate({ region, division });
36779
36795
  if (error) {
36780
- next(new import_nodejs_utils20.BadRequestError(`Validation error: ${error.message}`));
36796
+ next(new import_nodejs_utils21.BadRequestError(`Validation error: ${error.message}`));
36781
36797
  return;
36782
36798
  }
36783
36799
  try {
@@ -36801,7 +36817,7 @@ function useSchoolController() {
36801
36817
  }
36802
36818
 
36803
36819
  // src/resources/asset/asset.model.ts
36804
- var import_nodejs_utils21 = require("@eeplatform/nodejs-utils");
36820
+ var import_nodejs_utils22 = require("@eeplatform/nodejs-utils");
36805
36821
  var import_joi13 = __toESM(require("joi"));
36806
36822
  var import_mongodb13 = require("mongodb");
36807
36823
  var schemaAsset = import_joi13.default.object({
@@ -36849,19 +36865,19 @@ var schemaAssetUpdateOption = import_joi13.default.object({
36849
36865
  function MAsset(value) {
36850
36866
  const { error } = schemaAsset.validate(value);
36851
36867
  if (error) {
36852
- throw new import_nodejs_utils21.BadRequestError(error.message);
36868
+ throw new import_nodejs_utils22.BadRequestError(error.message);
36853
36869
  }
36854
36870
  if (value._id && typeof value._id === "string") {
36855
36871
  try {
36856
36872
  value._id = new import_mongodb13.ObjectId();
36857
36873
  } catch (error2) {
36858
- throw new import_nodejs_utils21.BadRequestError("Invalid ID.");
36874
+ throw new import_nodejs_utils22.BadRequestError("Invalid ID.");
36859
36875
  }
36860
36876
  }
36861
36877
  try {
36862
36878
  value.school = new import_mongodb13.ObjectId(value.school);
36863
36879
  } catch (error2) {
36864
- throw new import_nodejs_utils21.BadRequestError("Invalid school ID.");
36880
+ throw new import_nodejs_utils22.BadRequestError("Invalid school ID.");
36865
36881
  }
36866
36882
  value.createdAt = value.createdAt ? new Date(value.createdAt) : /* @__PURE__ */ new Date();
36867
36883
  value.updatedAt = value.updatedAt ? new Date(value.updatedAt) : "";
@@ -36891,24 +36907,24 @@ function MAsset(value) {
36891
36907
  }
36892
36908
 
36893
36909
  // src/resources/asset/asset.repository.ts
36894
- var import_nodejs_utils22 = require("@eeplatform/nodejs-utils");
36910
+ var import_nodejs_utils23 = require("@eeplatform/nodejs-utils");
36895
36911
  var import_mongodb14 = require("mongodb");
36896
36912
  function useAssetRepo() {
36897
- const db = import_nodejs_utils22.useAtlas.getDb();
36913
+ const db = import_nodejs_utils23.useAtlas.getDb();
36898
36914
  if (!db) {
36899
- throw new import_nodejs_utils22.BadRequestError("Unable to connect to server.");
36915
+ throw new import_nodejs_utils23.BadRequestError("Unable to connect to server.");
36900
36916
  }
36901
36917
  const namespace_collection = "school.assets";
36902
36918
  const collection = db.collection(namespace_collection);
36903
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils22.useCache)(namespace_collection);
36919
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils23.useCache)(namespace_collection);
36904
36920
  function delCachedData() {
36905
36921
  delNamespace().then(() => {
36906
- import_nodejs_utils22.logger.log({
36922
+ import_nodejs_utils23.logger.log({
36907
36923
  level: "info",
36908
36924
  message: `Cache namespace cleared for ${namespace_collection}`
36909
36925
  });
36910
36926
  }).catch((err) => {
36911
- import_nodejs_utils22.logger.log({
36927
+ import_nodejs_utils23.logger.log({
36912
36928
  level: "error",
36913
36929
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
36914
36930
  });
@@ -36922,7 +36938,7 @@ function useAssetRepo() {
36922
36938
  { key: { name: "text" } }
36923
36939
  ]);
36924
36940
  } catch (error) {
36925
- throw new import_nodejs_utils22.BadRequestError("Failed to create index on asset.");
36941
+ throw new import_nodejs_utils23.BadRequestError("Failed to create index on asset.");
36926
36942
  }
36927
36943
  }
36928
36944
  async function add(value) {
@@ -36932,18 +36948,18 @@ function useAssetRepo() {
36932
36948
  delCachedData();
36933
36949
  return res.insertedId;
36934
36950
  } catch (error) {
36935
- throw new import_nodejs_utils22.BadRequestError("Failed to create asset item.");
36951
+ throw new import_nodejs_utils23.BadRequestError("Failed to create asset item.");
36936
36952
  }
36937
36953
  }
36938
36954
  async function updateById(_id, value, session) {
36939
36955
  const { error } = schemaAssetUpdateOption.validate(value);
36940
36956
  if (error) {
36941
- throw new import_nodejs_utils22.BadRequestError(error.message);
36957
+ throw new import_nodejs_utils23.BadRequestError(error.message);
36942
36958
  }
36943
36959
  try {
36944
36960
  _id = new import_mongodb14.ObjectId(_id);
36945
36961
  } catch (error2) {
36946
- throw new import_nodejs_utils22.BadRequestError("Invalid ID.");
36962
+ throw new import_nodejs_utils23.BadRequestError("Invalid ID.");
36947
36963
  }
36948
36964
  try {
36949
36965
  const res = await collection.updateOne(
@@ -36956,14 +36972,14 @@ function useAssetRepo() {
36956
36972
  }
36957
36973
  return "Successfully updated asset item.";
36958
36974
  } catch (error2) {
36959
- throw new import_nodejs_utils22.BadRequestError("Failed to update asset item.");
36975
+ throw new import_nodejs_utils23.BadRequestError("Failed to update asset item.");
36960
36976
  }
36961
36977
  }
36962
36978
  async function deleteById(_id) {
36963
36979
  try {
36964
36980
  _id = new import_mongodb14.ObjectId(_id);
36965
36981
  } catch (error) {
36966
- throw new import_nodejs_utils22.BadRequestError("Invalid ID.");
36982
+ throw new import_nodejs_utils23.BadRequestError("Invalid ID.");
36967
36983
  }
36968
36984
  try {
36969
36985
  const res = await collection.deleteOne({ _id });
@@ -36973,16 +36989,16 @@ function useAssetRepo() {
36973
36989
  }
36974
36990
  return "Successfully deleted asset item.";
36975
36991
  } catch (error) {
36976
- throw new import_nodejs_utils22.BadRequestError("Failed to delete asset item.");
36992
+ throw new import_nodejs_utils23.BadRequestError("Failed to delete asset item.");
36977
36993
  }
36978
36994
  }
36979
36995
  async function getById(_id) {
36980
36996
  try {
36981
36997
  _id = new import_mongodb14.ObjectId(_id);
36982
36998
  } catch (error) {
36983
- throw new import_nodejs_utils22.BadRequestError("Invalid ID.");
36999
+ throw new import_nodejs_utils23.BadRequestError("Invalid ID.");
36984
37000
  }
36985
- const cacheKey = (0, import_nodejs_utils22.makeCacheKey)(namespace_collection, { _id: String(_id) });
37001
+ const cacheKey = (0, import_nodejs_utils23.makeCacheKey)(namespace_collection, { _id: String(_id) });
36986
37002
  const cachedData = await getCache(cacheKey);
36987
37003
  if (cachedData) {
36988
37004
  return cachedData;
@@ -36990,25 +37006,25 @@ function useAssetRepo() {
36990
37006
  try {
36991
37007
  const res = await collection.findOne({ _id });
36992
37008
  if (!res) {
36993
- throw new import_nodejs_utils22.BadRequestError("Asset item not found.");
37009
+ throw new import_nodejs_utils23.BadRequestError("Asset item not found.");
36994
37010
  }
36995
37011
  setCache(cacheKey, res).then(() => {
36996
- import_nodejs_utils22.logger.log({
37012
+ import_nodejs_utils23.logger.log({
36997
37013
  level: "info",
36998
37014
  message: `Cache set for asset item by ID: ${cacheKey}`
36999
37015
  });
37000
37016
  }).catch((err) => {
37001
- import_nodejs_utils22.logger.log({
37017
+ import_nodejs_utils23.logger.log({
37002
37018
  level: "error",
37003
37019
  message: `Failed to set cache for asset item by ID: ${cacheKey} - ${err.message}`
37004
37020
  });
37005
37021
  });
37006
37022
  return res;
37007
37023
  } catch (error) {
37008
- if (error instanceof import_nodejs_utils22.BadRequestError) {
37024
+ if (error instanceof import_nodejs_utils23.BadRequestError) {
37009
37025
  throw error;
37010
37026
  }
37011
- throw new import_nodejs_utils22.BadRequestError("Failed to retrieve asset item.");
37027
+ throw new import_nodejs_utils23.BadRequestError("Failed to retrieve asset item.");
37012
37028
  }
37013
37029
  }
37014
37030
  async function getAll({
@@ -37024,7 +37040,7 @@ function useAssetRepo() {
37024
37040
  try {
37025
37041
  school = new import_mongodb14.ObjectId(school);
37026
37042
  } catch (error) {
37027
- throw new import_nodejs_utils22.BadRequestError("Invalid school ID.");
37043
+ throw new import_nodejs_utils23.BadRequestError("Invalid school ID.");
37028
37044
  }
37029
37045
  const query = {
37030
37046
  school,
@@ -37044,10 +37060,10 @@ function useAssetRepo() {
37044
37060
  cacheKeyOptions.search = search;
37045
37061
  }
37046
37062
  try {
37047
- const cacheKey = (0, import_nodejs_utils22.makeCacheKey)(namespace_collection, cacheKeyOptions);
37063
+ const cacheKey = (0, import_nodejs_utils23.makeCacheKey)(namespace_collection, cacheKeyOptions);
37048
37064
  const cached = await getCache(cacheKey);
37049
37065
  if (cached) {
37050
- import_nodejs_utils22.logger.log({
37066
+ import_nodejs_utils23.logger.log({
37051
37067
  level: "info",
37052
37068
  message: `Cache hit for getAll asset items: ${cacheKey}`
37053
37069
  });
@@ -37066,14 +37082,14 @@ function useAssetRepo() {
37066
37082
  }
37067
37083
  ]).toArray();
37068
37084
  const length = await collection.countDocuments(query);
37069
- const data = (0, import_nodejs_utils22.paginate)(items, page, limit, length);
37085
+ const data = (0, import_nodejs_utils23.paginate)(items, page, limit, length);
37070
37086
  setCache(cacheKey, data, 500).then(() => {
37071
- import_nodejs_utils22.logger.log({
37087
+ import_nodejs_utils23.logger.log({
37072
37088
  level: "info",
37073
37089
  message: `Cache set for getAll asset items: ${cacheKey}`
37074
37090
  });
37075
37091
  }).catch((err) => {
37076
- import_nodejs_utils22.logger.log({
37092
+ import_nodejs_utils23.logger.log({
37077
37093
  level: "error",
37078
37094
  message: `Failed to set cache for getAll asset items: ${err.message}`
37079
37095
  });
@@ -37081,16 +37097,16 @@ function useAssetRepo() {
37081
37097
  return data;
37082
37098
  } catch (error) {
37083
37099
  console.log("Error in getAll:", error);
37084
- throw new import_nodejs_utils22.BadRequestError("Failed to retrieve asset items.");
37100
+ throw new import_nodejs_utils23.BadRequestError("Failed to retrieve asset items.");
37085
37101
  }
37086
37102
  }
37087
37103
  async function getCategories(school, asset_type) {
37088
37104
  try {
37089
37105
  school = new import_mongodb14.ObjectId(school);
37090
37106
  } catch (error) {
37091
- throw new import_nodejs_utils22.BadRequestError("Invalid school ID.");
37107
+ throw new import_nodejs_utils23.BadRequestError("Invalid school ID.");
37092
37108
  }
37093
- const cacheKey = (0, import_nodejs_utils22.makeCacheKey)(namespace_collection, {
37109
+ const cacheKey = (0, import_nodejs_utils23.makeCacheKey)(namespace_collection, {
37094
37110
  school,
37095
37111
  asset_type,
37096
37112
  type: "category-as-options"
@@ -37123,31 +37139,31 @@ function useAssetRepo() {
37123
37139
  { $sort: { title: 1 } }
37124
37140
  ]).toArray();
37125
37141
  setCache(cacheKey, categories).then(() => {
37126
- import_nodejs_utils22.logger.log({
37142
+ import_nodejs_utils23.logger.log({
37127
37143
  level: "info",
37128
37144
  message: `Cache set for getCategoriesBySchool: ${cacheKey}`
37129
37145
  });
37130
37146
  }).catch((err) => {
37131
- import_nodejs_utils22.logger.log({
37147
+ import_nodejs_utils23.logger.log({
37132
37148
  level: "error",
37133
37149
  message: `Failed to set cache for getCategoriesBySchool: ${err.message}`
37134
37150
  });
37135
37151
  });
37136
37152
  return categories;
37137
37153
  } catch (error) {
37138
- if (error instanceof import_nodejs_utils22.BadRequestError) {
37154
+ if (error instanceof import_nodejs_utils23.BadRequestError) {
37139
37155
  throw error;
37140
37156
  }
37141
- throw new import_nodejs_utils22.BadRequestError("Failed to retrieve asset categories.");
37157
+ throw new import_nodejs_utils23.BadRequestError("Failed to retrieve asset categories.");
37142
37158
  }
37143
37159
  }
37144
37160
  async function getTypes(school, asset_type) {
37145
37161
  try {
37146
37162
  school = new import_mongodb14.ObjectId(school);
37147
37163
  } catch (error) {
37148
- throw new import_nodejs_utils22.BadRequestError("Invalid school ID.");
37164
+ throw new import_nodejs_utils23.BadRequestError("Invalid school ID.");
37149
37165
  }
37150
- const cacheKey = (0, import_nodejs_utils22.makeCacheKey)(namespace_collection, {
37166
+ const cacheKey = (0, import_nodejs_utils23.makeCacheKey)(namespace_collection, {
37151
37167
  school,
37152
37168
  asset_type,
37153
37169
  type: "types-as-options"
@@ -37183,31 +37199,31 @@ function useAssetRepo() {
37183
37199
  { $sort: { title: 1 } }
37184
37200
  ]).toArray();
37185
37201
  setCache(cacheKey, categories).then(() => {
37186
- import_nodejs_utils22.logger.log({
37202
+ import_nodejs_utils23.logger.log({
37187
37203
  level: "info",
37188
37204
  message: `Cache set for getCategoriesBySchool: ${cacheKey}`
37189
37205
  });
37190
37206
  }).catch((err) => {
37191
- import_nodejs_utils22.logger.log({
37207
+ import_nodejs_utils23.logger.log({
37192
37208
  level: "error",
37193
37209
  message: `Failed to set cache for getCategoriesBySchool: ${err.message}`
37194
37210
  });
37195
37211
  });
37196
37212
  return categories;
37197
37213
  } catch (error) {
37198
- if (error instanceof import_nodejs_utils22.BadRequestError) {
37214
+ if (error instanceof import_nodejs_utils23.BadRequestError) {
37199
37215
  throw error;
37200
37216
  }
37201
- throw new import_nodejs_utils22.BadRequestError("Failed to retrieve asset categories.");
37217
+ throw new import_nodejs_utils23.BadRequestError("Failed to retrieve asset categories.");
37202
37218
  }
37203
37219
  }
37204
37220
  async function getUnitsBySchool(school) {
37205
37221
  try {
37206
37222
  school = new import_mongodb14.ObjectId(school);
37207
37223
  } catch (error) {
37208
- throw new import_nodejs_utils22.BadRequestError("Invalid school ID.");
37224
+ throw new import_nodejs_utils23.BadRequestError("Invalid school ID.");
37209
37225
  }
37210
- const cacheKey = (0, import_nodejs_utils22.makeCacheKey)(namespace_collection, {
37226
+ const cacheKey = (0, import_nodejs_utils23.makeCacheKey)(namespace_collection, {
37211
37227
  school,
37212
37228
  type: "unit-as-options"
37213
37229
  });
@@ -37239,12 +37255,12 @@ function useAssetRepo() {
37239
37255
  { $sort: { title: 1 } }
37240
37256
  ]).toArray();
37241
37257
  setCache(cacheKey, categories).then(() => {
37242
- import_nodejs_utils22.logger.log({
37258
+ import_nodejs_utils23.logger.log({
37243
37259
  level: "info",
37244
37260
  message: `Cache set for getUnitBy: ${cacheKey}`
37245
37261
  });
37246
37262
  }).catch((err) => {
37247
- import_nodejs_utils22.logger.log({
37263
+ import_nodejs_utils23.logger.log({
37248
37264
  level: "error",
37249
37265
  message: `Failed to set cache for getUnitBy: ${err.message}`
37250
37266
  });
@@ -37252,10 +37268,10 @@ function useAssetRepo() {
37252
37268
  return categories;
37253
37269
  } catch (error) {
37254
37270
  console.log(error);
37255
- if (error instanceof import_nodejs_utils22.BadRequestError) {
37271
+ if (error instanceof import_nodejs_utils23.BadRequestError) {
37256
37272
  throw error;
37257
37273
  }
37258
- throw new import_nodejs_utils22.BadRequestError(
37274
+ throw new import_nodejs_utils23.BadRequestError(
37259
37275
  "Failed to retrieve asset unit of measurements."
37260
37276
  );
37261
37277
  }
@@ -37274,7 +37290,7 @@ function useAssetRepo() {
37274
37290
  }
37275
37291
 
37276
37292
  // src/resources/asset/asset.controller.ts
37277
- var import_nodejs_utils23 = require("@eeplatform/nodejs-utils");
37293
+ var import_nodejs_utils24 = require("@eeplatform/nodejs-utils");
37278
37294
  var import_joi14 = __toESM(require("joi"));
37279
37295
  function useAssetController() {
37280
37296
  const {
@@ -37291,7 +37307,7 @@ function useAssetController() {
37291
37307
  const value = req.body;
37292
37308
  const { error } = schemaAsset.validate(value);
37293
37309
  if (error) {
37294
- next(new import_nodejs_utils23.BadRequestError(error.message));
37310
+ next(new import_nodejs_utils24.BadRequestError(error.message));
37295
37311
  return;
37296
37312
  }
37297
37313
  try {
@@ -37320,16 +37336,16 @@ function useAssetController() {
37320
37336
  const asset_type = req.query.asset_type ?? "supply";
37321
37337
  const isPageNumber = isFinite(page);
37322
37338
  if (!isPageNumber) {
37323
- next(new import_nodejs_utils23.BadRequestError("Invalid page number."));
37339
+ next(new import_nodejs_utils24.BadRequestError("Invalid page number."));
37324
37340
  return;
37325
37341
  }
37326
37342
  const isLimitNumber = isFinite(limit);
37327
37343
  if (!isLimitNumber) {
37328
- next(new import_nodejs_utils23.BadRequestError("Invalid limit number."));
37344
+ next(new import_nodejs_utils24.BadRequestError("Invalid limit number."));
37329
37345
  return;
37330
37346
  }
37331
37347
  if (error) {
37332
- next(new import_nodejs_utils23.BadRequestError(error.message));
37348
+ next(new import_nodejs_utils24.BadRequestError(error.message));
37333
37349
  return;
37334
37350
  }
37335
37351
  try {
@@ -37352,7 +37368,7 @@ function useAssetController() {
37352
37368
  const validation = import_joi14.default.string().hex().required();
37353
37369
  const { error } = validation.validate(id);
37354
37370
  if (error) {
37355
- next(new import_nodejs_utils23.BadRequestError(error.message));
37371
+ next(new import_nodejs_utils24.BadRequestError(error.message));
37356
37372
  return;
37357
37373
  }
37358
37374
  try {
@@ -37367,7 +37383,7 @@ function useAssetController() {
37367
37383
  const validation = import_joi14.default.string().hex().required();
37368
37384
  const { error } = validation.validate(id);
37369
37385
  if (error) {
37370
- next(new import_nodejs_utils23.BadRequestError(error.message));
37386
+ next(new import_nodejs_utils24.BadRequestError(error.message));
37371
37387
  return;
37372
37388
  }
37373
37389
  try {
@@ -37382,7 +37398,7 @@ function useAssetController() {
37382
37398
  const value = req.body;
37383
37399
  const { error } = schemaAssetUpdateOption.validate(value);
37384
37400
  if (error) {
37385
- next(new import_nodejs_utils23.BadRequestError(error.message));
37401
+ next(new import_nodejs_utils24.BadRequestError(error.message));
37386
37402
  return;
37387
37403
  }
37388
37404
  try {
@@ -37398,7 +37414,7 @@ function useAssetController() {
37398
37414
  const validation = import_joi14.default.string().hex().required();
37399
37415
  const { error } = validation.validate(school);
37400
37416
  if (error) {
37401
- next(new import_nodejs_utils23.BadRequestError(error.message));
37417
+ next(new import_nodejs_utils24.BadRequestError(error.message));
37402
37418
  return;
37403
37419
  }
37404
37420
  try {
@@ -37414,7 +37430,7 @@ function useAssetController() {
37414
37430
  const validation = import_joi14.default.string().hex().required();
37415
37431
  const { error } = validation.validate(school);
37416
37432
  if (error) {
37417
- next(new import_nodejs_utils23.BadRequestError(error.message));
37433
+ next(new import_nodejs_utils24.BadRequestError(error.message));
37418
37434
  return;
37419
37435
  }
37420
37436
  try {
@@ -37429,7 +37445,7 @@ function useAssetController() {
37429
37445
  const validation = import_joi14.default.string().hex().required();
37430
37446
  const { error } = validation.validate(school);
37431
37447
  if (error) {
37432
- next(new import_nodejs_utils23.BadRequestError(error.message));
37448
+ next(new import_nodejs_utils24.BadRequestError(error.message));
37433
37449
  return;
37434
37450
  }
37435
37451
  try {
@@ -37452,7 +37468,7 @@ function useAssetController() {
37452
37468
  }
37453
37469
 
37454
37470
  // src/resources/stock-card/stock-card.model.ts
37455
- var import_nodejs_utils24 = require("@eeplatform/nodejs-utils");
37471
+ var import_nodejs_utils25 = require("@eeplatform/nodejs-utils");
37456
37472
  var import_joi15 = __toESM(require("joi"));
37457
37473
  var import_mongodb15 = require("mongodb");
37458
37474
  var schemaStockCard = import_joi15.default.object({
@@ -37477,24 +37493,24 @@ var schemaStockCard = import_joi15.default.object({
37477
37493
  function MStockCard(value) {
37478
37494
  const { error } = schemaStockCard.validate(value);
37479
37495
  if (error) {
37480
- throw new import_nodejs_utils24.BadRequestError(`Invalid stock card data: ${error.message}`);
37496
+ throw new import_nodejs_utils25.BadRequestError(`Invalid stock card data: ${error.message}`);
37481
37497
  }
37482
37498
  if (value._id && typeof value._id === "string") {
37483
37499
  try {
37484
37500
  value._id = new import_mongodb15.ObjectId(value._id);
37485
37501
  } catch (err) {
37486
- throw new import_nodejs_utils24.BadRequestError("Invalid stock card ID.");
37502
+ throw new import_nodejs_utils25.BadRequestError("Invalid stock card ID.");
37487
37503
  }
37488
37504
  }
37489
37505
  try {
37490
37506
  value.item = new import_mongodb15.ObjectId(value.item);
37491
37507
  } catch (err) {
37492
- throw new import_nodejs_utils24.BadRequestError("Invalid item ID.");
37508
+ throw new import_nodejs_utils25.BadRequestError("Invalid item ID.");
37493
37509
  }
37494
37510
  try {
37495
37511
  value.school = new import_mongodb15.ObjectId(value.school);
37496
37512
  } catch (err) {
37497
- throw new import_nodejs_utils24.BadRequestError("Invalid school ID.");
37513
+ throw new import_nodejs_utils25.BadRequestError("Invalid school ID.");
37498
37514
  }
37499
37515
  return {
37500
37516
  _id: value._id ?? void 0,
@@ -37518,24 +37534,24 @@ function MStockCard(value) {
37518
37534
  }
37519
37535
 
37520
37536
  // src/resources/stock-card/stock-card.repository.ts
37521
- var import_nodejs_utils25 = require("@eeplatform/nodejs-utils");
37537
+ var import_nodejs_utils26 = require("@eeplatform/nodejs-utils");
37522
37538
  var import_mongodb16 = require("mongodb");
37523
37539
  function useStockCardRepository() {
37524
- const db = import_nodejs_utils25.useAtlas.getDb();
37540
+ const db = import_nodejs_utils26.useAtlas.getDb();
37525
37541
  if (!db) {
37526
- throw new import_nodejs_utils25.BadRequestError("Unable to connect to server.");
37542
+ throw new import_nodejs_utils26.BadRequestError("Unable to connect to server.");
37527
37543
  }
37528
37544
  const namespace_collection = "school.assets.stock-cards";
37529
37545
  const collection = db.collection(namespace_collection);
37530
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils25.useCache)(namespace_collection);
37546
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils26.useCache)(namespace_collection);
37531
37547
  function delCachedData() {
37532
37548
  delNamespace().then(() => {
37533
- import_nodejs_utils25.logger.log({
37549
+ import_nodejs_utils26.logger.log({
37534
37550
  level: "info",
37535
37551
  message: `Cache namespace cleared for ${namespace_collection}`
37536
37552
  });
37537
37553
  }).catch((err) => {
37538
- import_nodejs_utils25.logger.log({
37554
+ import_nodejs_utils26.logger.log({
37539
37555
  level: "error",
37540
37556
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
37541
37557
  });
@@ -37548,7 +37564,7 @@ function useStockCardRepository() {
37548
37564
  { key: { item: 1 } }
37549
37565
  ]);
37550
37566
  } catch (error) {
37551
- throw new import_nodejs_utils25.BadRequestError("Failed to create index on stock card.");
37567
+ throw new import_nodejs_utils26.BadRequestError("Failed to create index on stock card.");
37552
37568
  }
37553
37569
  }
37554
37570
  async function add(value, session) {
@@ -37558,16 +37574,16 @@ function useStockCardRepository() {
37558
37574
  delCachedData();
37559
37575
  return res.insertedId;
37560
37576
  } catch (error) {
37561
- throw new import_nodejs_utils25.BadRequestError("Failed to create stock card.");
37577
+ throw new import_nodejs_utils26.BadRequestError("Failed to create stock card.");
37562
37578
  }
37563
37579
  }
37564
37580
  async function getById(_id) {
37565
37581
  try {
37566
37582
  _id = new import_mongodb16.ObjectId(_id);
37567
37583
  } catch (error) {
37568
- throw new import_nodejs_utils25.BadRequestError("Invalid ID.");
37584
+ throw new import_nodejs_utils26.BadRequestError("Invalid ID.");
37569
37585
  }
37570
- const cacheKey = (0, import_nodejs_utils25.makeCacheKey)(namespace_collection, { _id: String(_id) });
37586
+ const cacheKey = (0, import_nodejs_utils26.makeCacheKey)(namespace_collection, { _id: String(_id) });
37571
37587
  const cachedData = await getCache(cacheKey);
37572
37588
  if (cachedData) {
37573
37589
  return cachedData;
@@ -37575,25 +37591,25 @@ function useStockCardRepository() {
37575
37591
  try {
37576
37592
  const res = await collection.findOne({ _id });
37577
37593
  if (!res) {
37578
- throw new import_nodejs_utils25.BadRequestError("Asset item not found.");
37594
+ throw new import_nodejs_utils26.BadRequestError("Asset item not found.");
37579
37595
  }
37580
37596
  setCache(cacheKey, res).then(() => {
37581
- import_nodejs_utils25.logger.log({
37597
+ import_nodejs_utils26.logger.log({
37582
37598
  level: "info",
37583
37599
  message: `Cache set for stock card by ID: ${cacheKey}`
37584
37600
  });
37585
37601
  }).catch((err) => {
37586
- import_nodejs_utils25.logger.log({
37602
+ import_nodejs_utils26.logger.log({
37587
37603
  level: "error",
37588
37604
  message: `Failed to set cache for stock card by ID: ${cacheKey} - ${err.message}`
37589
37605
  });
37590
37606
  });
37591
37607
  return res;
37592
37608
  } catch (error) {
37593
- if (error instanceof import_nodejs_utils25.BadRequestError) {
37609
+ if (error instanceof import_nodejs_utils26.BadRequestError) {
37594
37610
  throw error;
37595
37611
  }
37596
- throw new import_nodejs_utils25.BadRequestError("Failed to retrieve stock card.");
37612
+ throw new import_nodejs_utils26.BadRequestError("Failed to retrieve stock card.");
37597
37613
  }
37598
37614
  }
37599
37615
  async function getAll({ page = 1, limit = 20, school = "", sort = { _id: 1 }, id = "" } = {}) {
@@ -37601,12 +37617,12 @@ function useStockCardRepository() {
37601
37617
  try {
37602
37618
  school = new import_mongodb16.ObjectId(school);
37603
37619
  } catch (error) {
37604
- throw new import_nodejs_utils25.BadRequestError("Invalid school ID.");
37620
+ throw new import_nodejs_utils26.BadRequestError("Invalid school ID.");
37605
37621
  }
37606
37622
  try {
37607
37623
  id = new import_mongodb16.ObjectId(id);
37608
37624
  } catch (error) {
37609
- throw new import_nodejs_utils25.BadRequestError("Invalid ID.");
37625
+ throw new import_nodejs_utils26.BadRequestError("Invalid ID.");
37610
37626
  }
37611
37627
  const query = {
37612
37628
  school,
@@ -37620,10 +37636,10 @@ function useStockCardRepository() {
37620
37636
  item: id
37621
37637
  };
37622
37638
  try {
37623
- const cacheKey = (0, import_nodejs_utils25.makeCacheKey)(namespace_collection, cacheKeyOptions);
37639
+ const cacheKey = (0, import_nodejs_utils26.makeCacheKey)(namespace_collection, cacheKeyOptions);
37624
37640
  const cached = await getCache(cacheKey);
37625
37641
  if (cached) {
37626
- import_nodejs_utils25.logger.log({
37642
+ import_nodejs_utils26.logger.log({
37627
37643
  level: "info",
37628
37644
  message: `Cache hit for getAll stock cards: ${cacheKey}`
37629
37645
  });
@@ -37642,14 +37658,14 @@ function useStockCardRepository() {
37642
37658
  }
37643
37659
  ]).toArray();
37644
37660
  const length = await collection.countDocuments(query);
37645
- const data = (0, import_nodejs_utils25.paginate)(items, page, limit, length);
37661
+ const data = (0, import_nodejs_utils26.paginate)(items, page, limit, length);
37646
37662
  setCache(cacheKey, data, 500).then(() => {
37647
- import_nodejs_utils25.logger.log({
37663
+ import_nodejs_utils26.logger.log({
37648
37664
  level: "info",
37649
37665
  message: `Cache set for getAll stock cards: ${cacheKey}`
37650
37666
  });
37651
37667
  }).catch((err) => {
37652
- import_nodejs_utils25.logger.log({
37668
+ import_nodejs_utils26.logger.log({
37653
37669
  level: "error",
37654
37670
  message: `Failed to set cache for getAll stock cards: ${err.message}`
37655
37671
  });
@@ -37657,16 +37673,16 @@ function useStockCardRepository() {
37657
37673
  return data;
37658
37674
  } catch (error) {
37659
37675
  console.log("Error in getAll:", error);
37660
- throw new import_nodejs_utils25.BadRequestError("Failed to retrieve stock cards.");
37676
+ throw new import_nodejs_utils26.BadRequestError("Failed to retrieve stock cards.");
37661
37677
  }
37662
37678
  }
37663
37679
  async function getSuppliers(school) {
37664
37680
  try {
37665
37681
  school = new import_mongodb16.ObjectId(school);
37666
37682
  } catch (error) {
37667
- throw new import_nodejs_utils25.BadRequestError("Invalid school ID.");
37683
+ throw new import_nodejs_utils26.BadRequestError("Invalid school ID.");
37668
37684
  }
37669
- const cacheKey = (0, import_nodejs_utils25.makeCacheKey)(namespace_collection, {
37685
+ const cacheKey = (0, import_nodejs_utils26.makeCacheKey)(namespace_collection, {
37670
37686
  school,
37671
37687
  type: "supplier-as-options"
37672
37688
  });
@@ -37698,22 +37714,22 @@ function useStockCardRepository() {
37698
37714
  { $sort: { title: 1 } }
37699
37715
  ]).toArray();
37700
37716
  setCache(cacheKey, suppliers).then(() => {
37701
- import_nodejs_utils25.logger.log({
37717
+ import_nodejs_utils26.logger.log({
37702
37718
  level: "info",
37703
37719
  message: `Cache set for getSuppliersBySchool: ${cacheKey}`
37704
37720
  });
37705
37721
  }).catch((err) => {
37706
- import_nodejs_utils25.logger.log({
37722
+ import_nodejs_utils26.logger.log({
37707
37723
  level: "error",
37708
37724
  message: `Failed to set cache for getSuppliersBySchool: ${err.message}`
37709
37725
  });
37710
37726
  });
37711
37727
  return suppliers;
37712
37728
  } catch (error) {
37713
- if (error instanceof import_nodejs_utils25.BadRequestError) {
37729
+ if (error instanceof import_nodejs_utils26.BadRequestError) {
37714
37730
  throw error;
37715
37731
  }
37716
- throw new import_nodejs_utils25.BadRequestError("Failed to retrieve asset suppliers.");
37732
+ throw new import_nodejs_utils26.BadRequestError("Failed to retrieve asset suppliers.");
37717
37733
  }
37718
37734
  }
37719
37735
  return {
@@ -37726,20 +37742,20 @@ function useStockCardRepository() {
37726
37742
  }
37727
37743
 
37728
37744
  // src/resources/stock-card/stock-card.service.ts
37729
- var import_nodejs_utils26 = require("@eeplatform/nodejs-utils");
37745
+ var import_nodejs_utils27 = require("@eeplatform/nodejs-utils");
37730
37746
  function useStockCardService() {
37731
37747
  const { add: _add, getById: _getById } = useStockCardRepository();
37732
37748
  const { getById: _getAssetById, updateById: updateAssetById } = useAssetRepo();
37733
37749
  async function add(data) {
37734
- const session = import_nodejs_utils26.useAtlas.getClient()?.startSession();
37750
+ const session = import_nodejs_utils27.useAtlas.getClient()?.startSession();
37735
37751
  if (!session) {
37736
- throw new import_nodejs_utils26.BadRequestError("Unable to start database session.");
37752
+ throw new import_nodejs_utils27.BadRequestError("Unable to start database session.");
37737
37753
  }
37738
37754
  session.startTransaction();
37739
37755
  try {
37740
37756
  const asset = await _getAssetById(data.item);
37741
37757
  if (!asset) {
37742
- throw new import_nodejs_utils26.NotFoundError("Asset not found.");
37758
+ throw new import_nodejs_utils27.NotFoundError("Asset not found.");
37743
37759
  }
37744
37760
  data.balance = (asset.qty ?? 0) + data.qty;
37745
37761
  await _add(data, session);
@@ -37748,7 +37764,7 @@ function useStockCardService() {
37748
37764
  return "Successfully added stock card.";
37749
37765
  } catch (error) {
37750
37766
  await session.abortTransaction();
37751
- throw new import_nodejs_utils26.BadRequestError("Failed to add stock card.");
37767
+ throw new import_nodejs_utils27.BadRequestError("Failed to add stock card.");
37752
37768
  } finally {
37753
37769
  session.endSession();
37754
37770
  }
@@ -37759,7 +37775,7 @@ function useStockCardService() {
37759
37775
  }
37760
37776
 
37761
37777
  // src/resources/stock-card/stock-card.controller.ts
37762
- var import_nodejs_utils27 = require("@eeplatform/nodejs-utils");
37778
+ var import_nodejs_utils28 = require("@eeplatform/nodejs-utils");
37763
37779
  var import_joi16 = __toESM(require("joi"));
37764
37780
  function useStockCardController() {
37765
37781
  const {
@@ -37772,7 +37788,7 @@ function useStockCardController() {
37772
37788
  const value = req.body;
37773
37789
  const { error } = schemaStockCard.validate(value);
37774
37790
  if (error) {
37775
- next(new import_nodejs_utils27.BadRequestError(error.message));
37791
+ next(new import_nodejs_utils28.BadRequestError(error.message));
37776
37792
  return;
37777
37793
  }
37778
37794
  try {
@@ -37797,16 +37813,16 @@ function useStockCardController() {
37797
37813
  const id = req.query.id ?? "supply";
37798
37814
  const isPageNumber = isFinite(page);
37799
37815
  if (!isPageNumber) {
37800
- next(new import_nodejs_utils27.BadRequestError("Invalid page number."));
37816
+ next(new import_nodejs_utils28.BadRequestError("Invalid page number."));
37801
37817
  return;
37802
37818
  }
37803
37819
  const isLimitNumber = isFinite(limit);
37804
37820
  if (!isLimitNumber) {
37805
- next(new import_nodejs_utils27.BadRequestError("Invalid limit number."));
37821
+ next(new import_nodejs_utils28.BadRequestError("Invalid limit number."));
37806
37822
  return;
37807
37823
  }
37808
37824
  if (error) {
37809
- next(new import_nodejs_utils27.BadRequestError(error.message));
37825
+ next(new import_nodejs_utils28.BadRequestError(error.message));
37810
37826
  return;
37811
37827
  }
37812
37828
  try {
@@ -37827,7 +37843,7 @@ function useStockCardController() {
37827
37843
  const validation = import_joi16.default.string().hex().required();
37828
37844
  const { error } = validation.validate(id);
37829
37845
  if (error) {
37830
- next(new import_nodejs_utils27.BadRequestError(error.message));
37846
+ next(new import_nodejs_utils28.BadRequestError(error.message));
37831
37847
  return;
37832
37848
  }
37833
37849
  try {
@@ -37842,7 +37858,7 @@ function useStockCardController() {
37842
37858
  const validation = import_joi16.default.string().hex().required();
37843
37859
  const { error } = validation.validate(school);
37844
37860
  if (error) {
37845
- next(new import_nodejs_utils27.BadRequestError(error.message));
37861
+ next(new import_nodejs_utils28.BadRequestError(error.message));
37846
37862
  return;
37847
37863
  }
37848
37864
  try {
@@ -37861,7 +37877,7 @@ function useStockCardController() {
37861
37877
  }
37862
37878
 
37863
37879
  // src/resources/plantilla/plantilla.model.ts
37864
- var import_nodejs_utils28 = require("@eeplatform/nodejs-utils");
37880
+ var import_nodejs_utils29 = require("@eeplatform/nodejs-utils");
37865
37881
  var import_joi17 = __toESM(require("joi"));
37866
37882
  var import_mongodb17 = require("mongodb");
37867
37883
  var schemaPlantilla = import_joi17.default.object({
@@ -37890,13 +37906,13 @@ var schemaPlantilla = import_joi17.default.object({
37890
37906
  function MPlantilla(data) {
37891
37907
  const { error } = schemaPlantilla.validate(data);
37892
37908
  if (error) {
37893
- throw new import_nodejs_utils28.BadRequestError(error.message);
37909
+ throw new import_nodejs_utils29.BadRequestError(error.message);
37894
37910
  }
37895
37911
  if (data._id && typeof data._id === "string") {
37896
37912
  try {
37897
37913
  data._id = new import_mongodb17.ObjectId(data._id);
37898
37914
  } catch (error2) {
37899
- throw new import_nodejs_utils28.BadRequestError("Invalid _id.");
37915
+ throw new import_nodejs_utils29.BadRequestError("Invalid _id.");
37900
37916
  }
37901
37917
  }
37902
37918
  return {
@@ -37925,16 +37941,16 @@ function MPlantilla(data) {
37925
37941
  }
37926
37942
 
37927
37943
  // src/resources/plantilla/plantilla.repository.ts
37928
- var import_nodejs_utils29 = require("@eeplatform/nodejs-utils");
37944
+ var import_nodejs_utils30 = require("@eeplatform/nodejs-utils");
37929
37945
  var import_mongodb18 = require("mongodb");
37930
37946
  function usePlantillaRepo() {
37931
- const db = import_nodejs_utils29.useAtlas.getDb();
37947
+ const db = import_nodejs_utils30.useAtlas.getDb();
37932
37948
  if (!db) {
37933
37949
  throw new Error("Unable to connect to server.");
37934
37950
  }
37935
37951
  const namespace_collection = "plantillas";
37936
37952
  const collection = db.collection(namespace_collection);
37937
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils29.useCache)(namespace_collection);
37953
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils30.useCache)(namespace_collection);
37938
37954
  async function createIndexes() {
37939
37955
  try {
37940
37956
  await collection.createIndexes([
@@ -37956,16 +37972,16 @@ function usePlantillaRepo() {
37956
37972
  }
37957
37973
  return res.insertedId;
37958
37974
  } catch (error) {
37959
- import_nodejs_utils29.logger.log({
37975
+ import_nodejs_utils30.logger.log({
37960
37976
  level: "error",
37961
37977
  message: error.message
37962
37978
  });
37963
- if (error instanceof import_nodejs_utils29.AppError) {
37979
+ if (error instanceof import_nodejs_utils30.AppError) {
37964
37980
  throw error;
37965
37981
  } else {
37966
37982
  const isDuplicated = error.message.includes("duplicate");
37967
37983
  if (isDuplicated) {
37968
- throw new import_nodejs_utils29.BadRequestError("Plantilla already exists.");
37984
+ throw new import_nodejs_utils30.BadRequestError("Plantilla already exists.");
37969
37985
  }
37970
37986
  throw new Error("Failed to create plantilla.");
37971
37987
  }
@@ -37975,7 +37991,7 @@ function usePlantillaRepo() {
37975
37991
  try {
37976
37992
  _id = new import_mongodb18.ObjectId(_id);
37977
37993
  } catch (error) {
37978
- throw new import_nodejs_utils29.BadRequestError("Invalid ID.");
37994
+ throw new import_nodejs_utils30.BadRequestError("Invalid ID.");
37979
37995
  }
37980
37996
  value.updatedAt = /* @__PURE__ */ new Date();
37981
37997
  try {
@@ -37987,11 +38003,11 @@ function usePlantillaRepo() {
37987
38003
  delCachedData();
37988
38004
  return res;
37989
38005
  } catch (error) {
37990
- import_nodejs_utils29.logger.log({
38006
+ import_nodejs_utils30.logger.log({
37991
38007
  level: "error",
37992
38008
  message: error.message
37993
38009
  });
37994
- if (error instanceof import_nodejs_utils29.AppError) {
38010
+ if (error instanceof import_nodejs_utils30.AppError) {
37995
38011
  throw error;
37996
38012
  } else {
37997
38013
  throw new Error("Failed to update plantilla.");
@@ -38018,7 +38034,7 @@ function usePlantillaRepo() {
38018
38034
  try {
38019
38035
  query.org = new import_mongodb18.ObjectId(org);
38020
38036
  } catch (error) {
38021
- throw new import_nodejs_utils29.BadRequestError("Invalid org ID.");
38037
+ throw new import_nodejs_utils30.BadRequestError("Invalid org ID.");
38022
38038
  }
38023
38039
  }
38024
38040
  const cacheParams = {
@@ -38032,15 +38048,15 @@ function usePlantillaRepo() {
38032
38048
  cacheParams.org = org;
38033
38049
  if (status !== "active")
38034
38050
  cacheParams.status = status;
38035
- const cacheKey = (0, import_nodejs_utils29.makeCacheKey)(namespace_collection, cacheParams);
38036
- import_nodejs_utils29.logger.log({
38051
+ const cacheKey = (0, import_nodejs_utils30.makeCacheKey)(namespace_collection, cacheParams);
38052
+ import_nodejs_utils30.logger.log({
38037
38053
  level: "info",
38038
38054
  message: `Cache key for getAll plantillas: ${cacheKey}`
38039
38055
  });
38040
38056
  try {
38041
38057
  const cached = await getCache(cacheKey);
38042
38058
  if (cached) {
38043
- import_nodejs_utils29.logger.log({
38059
+ import_nodejs_utils30.logger.log({
38044
38060
  level: "info",
38045
38061
  message: `Cache hit for getAll plantillas: ${cacheKey}`
38046
38062
  });
@@ -38053,21 +38069,21 @@ function usePlantillaRepo() {
38053
38069
  { $limit: limit }
38054
38070
  ]).toArray();
38055
38071
  const length = await collection.countDocuments(query);
38056
- const data = (0, import_nodejs_utils29.paginate)(items, page, limit, length);
38072
+ const data = (0, import_nodejs_utils30.paginate)(items, page, limit, length);
38057
38073
  setCache(cacheKey, data, 600).then(() => {
38058
- import_nodejs_utils29.logger.log({
38074
+ import_nodejs_utils30.logger.log({
38059
38075
  level: "info",
38060
38076
  message: `Cache set for getAll plantillas: ${cacheKey}`
38061
38077
  });
38062
38078
  }).catch((err) => {
38063
- import_nodejs_utils29.logger.log({
38079
+ import_nodejs_utils30.logger.log({
38064
38080
  level: "error",
38065
38081
  message: `Failed to set cache for getAll plantillas: ${err.message}`
38066
38082
  });
38067
38083
  });
38068
38084
  return data;
38069
38085
  } catch (error) {
38070
- import_nodejs_utils29.logger.log({ level: "error", message: `${error}` });
38086
+ import_nodejs_utils30.logger.log({ level: "error", message: `${error}` });
38071
38087
  throw error;
38072
38088
  }
38073
38089
  }
@@ -38075,13 +38091,13 @@ function usePlantillaRepo() {
38075
38091
  try {
38076
38092
  _id = new import_mongodb18.ObjectId(_id);
38077
38093
  } catch (error) {
38078
- throw new import_nodejs_utils29.BadRequestError("Invalid ID.");
38094
+ throw new import_nodejs_utils30.BadRequestError("Invalid ID.");
38079
38095
  }
38080
- const cacheKey = (0, import_nodejs_utils29.makeCacheKey)(namespace_collection, { _id: String(_id) });
38096
+ const cacheKey = (0, import_nodejs_utils30.makeCacheKey)(namespace_collection, { _id: String(_id) });
38081
38097
  try {
38082
38098
  const cached = await getCache(cacheKey);
38083
38099
  if (cached) {
38084
- import_nodejs_utils29.logger.log({
38100
+ import_nodejs_utils30.logger.log({
38085
38101
  level: "info",
38086
38102
  message: `Cache hit for getById plantilla: ${cacheKey}`
38087
38103
  });
@@ -38091,22 +38107,22 @@ function usePlantillaRepo() {
38091
38107
  _id
38092
38108
  });
38093
38109
  setCache(cacheKey, result, 300).then(() => {
38094
- import_nodejs_utils29.logger.log({
38110
+ import_nodejs_utils30.logger.log({
38095
38111
  level: "info",
38096
38112
  message: `Cache set for plantilla by id: ${cacheKey}`
38097
38113
  });
38098
38114
  }).catch((err) => {
38099
- import_nodejs_utils29.logger.log({
38115
+ import_nodejs_utils30.logger.log({
38100
38116
  level: "error",
38101
38117
  message: `Failed to set cache for plantilla by id: ${err.message}`
38102
38118
  });
38103
38119
  });
38104
38120
  return result;
38105
38121
  } catch (error) {
38106
- if (error instanceof import_nodejs_utils29.AppError) {
38122
+ if (error instanceof import_nodejs_utils30.AppError) {
38107
38123
  throw error;
38108
38124
  } else {
38109
- throw new import_nodejs_utils29.InternalServerError("Failed to get plantilla.");
38125
+ throw new import_nodejs_utils30.InternalServerError("Failed to get plantilla.");
38110
38126
  }
38111
38127
  }
38112
38128
  }
@@ -38114,7 +38130,7 @@ function usePlantillaRepo() {
38114
38130
  try {
38115
38131
  _id = new import_mongodb18.ObjectId(_id);
38116
38132
  } catch (error) {
38117
- throw new import_nodejs_utils29.BadRequestError("Invalid ID.");
38133
+ throw new import_nodejs_utils30.BadRequestError("Invalid ID.");
38118
38134
  }
38119
38135
  try {
38120
38136
  const res = await collection.updateOne(
@@ -38124,25 +38140,25 @@ function usePlantillaRepo() {
38124
38140
  delCachedData();
38125
38141
  return res;
38126
38142
  } catch (error) {
38127
- import_nodejs_utils29.logger.log({
38143
+ import_nodejs_utils30.logger.log({
38128
38144
  level: "error",
38129
38145
  message: error.message
38130
38146
  });
38131
- if (error instanceof import_nodejs_utils29.AppError) {
38147
+ if (error instanceof import_nodejs_utils30.AppError) {
38132
38148
  throw error;
38133
38149
  } else {
38134
- throw new import_nodejs_utils29.InternalServerError("Failed to delete plantilla.");
38150
+ throw new import_nodejs_utils30.InternalServerError("Failed to delete plantilla.");
38135
38151
  }
38136
38152
  }
38137
38153
  }
38138
38154
  function delCachedData() {
38139
38155
  delNamespace().then(() => {
38140
- import_nodejs_utils29.logger.log({
38156
+ import_nodejs_utils30.logger.log({
38141
38157
  level: "info",
38142
38158
  message: `Cache namespace cleared for ${namespace_collection}`
38143
38159
  });
38144
38160
  }).catch((err) => {
38145
- import_nodejs_utils29.logger.log({
38161
+ import_nodejs_utils30.logger.log({
38146
38162
  level: "error",
38147
38163
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
38148
38164
  });
@@ -38160,12 +38176,12 @@ function usePlantillaRepo() {
38160
38176
  }
38161
38177
 
38162
38178
  // src/resources/plantilla/plantilla.service.ts
38163
- var import_nodejs_utils30 = require("@eeplatform/nodejs-utils");
38179
+ var import_nodejs_utils31 = require("@eeplatform/nodejs-utils");
38164
38180
  var Papa2 = __toESM(require_papaparse());
38165
38181
  function usePlantillaService() {
38166
38182
  const { add: addPlantilla, delCachedData } = usePlantillaRepo();
38167
38183
  async function addBulk(file, region, division) {
38168
- import_nodejs_utils30.logger.log({
38184
+ import_nodejs_utils31.logger.log({
38169
38185
  level: "info",
38170
38186
  message: `Starting plantilla bulk upload. File: ${file.originalname}, Size: ${file.size} bytes`
38171
38187
  });
@@ -38174,7 +38190,7 @@ function usePlantillaService() {
38174
38190
  let totalSize = 0;
38175
38191
  let validatedPlantillas = [];
38176
38192
  if (!file.buffer) {
38177
- throw new import_nodejs_utils30.BadRequestError("File buffer is empty or corrupted");
38193
+ throw new import_nodejs_utils31.BadRequestError("File buffer is empty or corrupted");
38178
38194
  }
38179
38195
  try {
38180
38196
  const fileExtension = file.originalname.split(".").pop()?.toLowerCase();
@@ -38189,7 +38205,7 @@ function usePlantillaService() {
38189
38205
  }
38190
38206
  });
38191
38207
  if (parseResult.errors.length > 0) {
38192
- throw new import_nodejs_utils30.BadRequestError(
38208
+ throw new import_nodejs_utils31.BadRequestError(
38193
38209
  `CSV parsing errors: ${parseResult.errors.map((e) => e.message).join(", ")}`
38194
38210
  );
38195
38211
  }
@@ -38204,7 +38220,7 @@ function usePlantillaService() {
38204
38220
  defval: ""
38205
38221
  });
38206
38222
  if (plantillas.length === 0) {
38207
- throw new import_nodejs_utils30.BadRequestError("Excel file is empty.");
38223
+ throw new import_nodejs_utils31.BadRequestError("Excel file is empty.");
38208
38224
  }
38209
38225
  const headers = plantillas[0];
38210
38226
  const normalizedHeaders = headers.map(
@@ -38218,12 +38234,12 @@ function usePlantillaService() {
38218
38234
  return obj;
38219
38235
  });
38220
38236
  } else {
38221
- throw new import_nodejs_utils30.BadRequestError(
38237
+ throw new import_nodejs_utils31.BadRequestError(
38222
38238
  "Unsupported file type. Please upload an Excel (.xlsx, .xls) or CSV (.csv) file."
38223
38239
  );
38224
38240
  }
38225
38241
  if (!plantillas || plantillas.length === 0) {
38226
- throw new import_nodejs_utils30.BadRequestError("No data found in the uploaded file.");
38242
+ throw new import_nodejs_utils31.BadRequestError("No data found in the uploaded file.");
38227
38243
  }
38228
38244
  const errors = [];
38229
38245
  for (let i = 0; i < plantillas.length; i++) {
@@ -38292,35 +38308,35 @@ function usePlantillaService() {
38292
38308
  }
38293
38309
  }
38294
38310
  if (errors.length > 0) {
38295
- throw new import_nodejs_utils30.BadRequestError(
38311
+ throw new import_nodejs_utils31.BadRequestError(
38296
38312
  `Validation errors found:
38297
38313
  ${errors.slice(0, 10).join("\n")}${errors.length > 10 ? `
38298
38314
  ... and ${errors.length - 10} more errors` : ""}`
38299
38315
  );
38300
38316
  }
38301
38317
  if (validatedPlantillas.length === 0) {
38302
- throw new import_nodejs_utils30.BadRequestError(
38318
+ throw new import_nodejs_utils31.BadRequestError(
38303
38319
  "No valid plantilla records found after validation."
38304
38320
  );
38305
38321
  }
38306
38322
  if (totalSize > MAX_SIZE) {
38307
- throw new import_nodejs_utils30.BadRequestError(
38323
+ throw new import_nodejs_utils31.BadRequestError(
38308
38324
  `Data payload (${Math.round(
38309
38325
  totalSize / 1024 / 1024
38310
38326
  )}MB) exceeds MongoDB transaction limit of 16MB. Please reduce the number of records or split into smaller files.`
38311
38327
  );
38312
38328
  }
38313
38329
  } catch (error) {
38314
- if (error instanceof import_nodejs_utils30.BadRequestError) {
38330
+ if (error instanceof import_nodejs_utils31.BadRequestError) {
38315
38331
  throw error;
38316
38332
  }
38317
- throw new import_nodejs_utils30.BadRequestError(`File processing error: ${error.message}`);
38333
+ throw new import_nodejs_utils31.BadRequestError(`File processing error: ${error.message}`);
38318
38334
  }
38319
- const session = import_nodejs_utils30.useAtlas.getClient()?.startSession();
38335
+ const session = import_nodejs_utils31.useAtlas.getClient()?.startSession();
38320
38336
  if (!session) {
38321
38337
  throw new Error("Unable to start session for bulk plantilla upload.");
38322
38338
  }
38323
- import_nodejs_utils30.logger.log({
38339
+ import_nodejs_utils31.logger.log({
38324
38340
  level: "info",
38325
38341
  message: `Starting bulk plantilla upload with ${validatedPlantillas.length} records`
38326
38342
  });
@@ -38350,7 +38366,7 @@ ${errors.slice(0, 10).join("\n")}${errors.length > 10 ? `
38350
38366
  }
38351
38367
  };
38352
38368
  } catch (error) {
38353
- import_nodejs_utils30.logger.log({
38369
+ import_nodejs_utils31.logger.log({
38354
38370
  level: "error",
38355
38371
  message: `Error in bulk plantilla upload: ${error.message}`
38356
38372
  });
@@ -38366,7 +38382,7 @@ ${errors.slice(0, 10).join("\n")}${errors.length > 10 ? `
38366
38382
  }
38367
38383
 
38368
38384
  // src/resources/plantilla/plantilla.controller.ts
38369
- var import_nodejs_utils31 = require("@eeplatform/nodejs-utils");
38385
+ var import_nodejs_utils32 = require("@eeplatform/nodejs-utils");
38370
38386
  var import_joi18 = __toESM(require("joi"));
38371
38387
  function usePlantillaController() {
38372
38388
  const {
@@ -38387,7 +38403,7 @@ function usePlantillaController() {
38387
38403
  });
38388
38404
  const { error } = validation.validate(value);
38389
38405
  if (error) {
38390
- next(new import_nodejs_utils31.BadRequestError(error.message));
38406
+ next(new import_nodejs_utils32.BadRequestError(error.message));
38391
38407
  return;
38392
38408
  }
38393
38409
  try {
@@ -38405,12 +38421,12 @@ function usePlantillaController() {
38405
38421
  const org = req.query.org ?? "";
38406
38422
  const isPageNumber = isFinite(page);
38407
38423
  if (!isPageNumber) {
38408
- next(new import_nodejs_utils31.BadRequestError("Invalid page number."));
38424
+ next(new import_nodejs_utils32.BadRequestError("Invalid page number."));
38409
38425
  return;
38410
38426
  }
38411
38427
  const isLimitNumber = isFinite(limit);
38412
38428
  if (!isLimitNumber) {
38413
- next(new import_nodejs_utils31.BadRequestError("Invalid limit number."));
38429
+ next(new import_nodejs_utils32.BadRequestError("Invalid limit number."));
38414
38430
  return;
38415
38431
  }
38416
38432
  const validation = import_joi18.default.object({
@@ -38421,7 +38437,7 @@ function usePlantillaController() {
38421
38437
  });
38422
38438
  const { error } = validation.validate({ page, limit, search, org });
38423
38439
  if (error) {
38424
- next(new import_nodejs_utils31.BadRequestError(error.message));
38440
+ next(new import_nodejs_utils32.BadRequestError(error.message));
38425
38441
  return;
38426
38442
  }
38427
38443
  try {
@@ -38444,13 +38460,13 @@ function usePlantillaController() {
38444
38460
  });
38445
38461
  const { error } = validation.validate({ id });
38446
38462
  if (error) {
38447
- next(new import_nodejs_utils31.BadRequestError(error.message));
38463
+ next(new import_nodejs_utils32.BadRequestError(error.message));
38448
38464
  return;
38449
38465
  }
38450
38466
  try {
38451
38467
  const plantilla = await _getPlantillaById(id);
38452
38468
  if (!plantilla) {
38453
- next(new import_nodejs_utils31.BadRequestError("Plantilla not found."));
38469
+ next(new import_nodejs_utils32.BadRequestError("Plantilla not found."));
38454
38470
  return;
38455
38471
  }
38456
38472
  res.json(plantilla);
@@ -38471,13 +38487,13 @@ function usePlantillaController() {
38471
38487
  });
38472
38488
  const { error } = validation.validate({ id, ...value });
38473
38489
  if (error) {
38474
- next(new import_nodejs_utils31.BadRequestError(error.message));
38490
+ next(new import_nodejs_utils32.BadRequestError(error.message));
38475
38491
  return;
38476
38492
  }
38477
38493
  try {
38478
38494
  const result = await _updatePlantillaById(id, value);
38479
38495
  if (result.matchedCount === 0) {
38480
- next(new import_nodejs_utils31.BadRequestError("Plantilla not found."));
38496
+ next(new import_nodejs_utils32.BadRequestError("Plantilla not found."));
38481
38497
  return;
38482
38498
  }
38483
38499
  res.json({ message: "Plantilla updated successfully" });
@@ -38493,13 +38509,13 @@ function usePlantillaController() {
38493
38509
  });
38494
38510
  const { error } = validation.validate({ id });
38495
38511
  if (error) {
38496
- next(new import_nodejs_utils31.BadRequestError(error.message));
38512
+ next(new import_nodejs_utils32.BadRequestError(error.message));
38497
38513
  return;
38498
38514
  }
38499
38515
  try {
38500
38516
  const result = await _deletePlantillaById(id);
38501
38517
  if (result.matchedCount === 0) {
38502
- next(new import_nodejs_utils31.BadRequestError("Plantilla not found."));
38518
+ next(new import_nodejs_utils32.BadRequestError("Plantilla not found."));
38503
38519
  return;
38504
38520
  }
38505
38521
  res.json({ message: "Plantilla deleted successfully" });
@@ -38520,12 +38536,12 @@ function usePlantillaController() {
38520
38536
  });
38521
38537
  const { error } = validation.validate({ region, division });
38522
38538
  if (error) {
38523
- next(new import_nodejs_utils31.BadRequestError(`Validation error: ${error.message}`));
38539
+ next(new import_nodejs_utils32.BadRequestError(`Validation error: ${error.message}`));
38524
38540
  return;
38525
38541
  }
38526
38542
  if (!region && !division) {
38527
38543
  next(
38528
- new import_nodejs_utils31.BadRequestError(
38544
+ new import_nodejs_utils32.BadRequestError(
38529
38545
  "At least one of region or division must be provided"
38530
38546
  )
38531
38547
  );
@@ -38557,17 +38573,18 @@ dotenv.config();
38557
38573
  0 && (module.exports = {
38558
38574
  MAsset,
38559
38575
  MCurriculum,
38560
- MDivision,
38561
38576
  MEnrollment,
38562
38577
  MGradeLevel,
38563
38578
  MPlantilla,
38564
- MRegion,
38565
- MSchool,
38566
38579
  MStockCard,
38580
+ modelDivision,
38581
+ modelRegion,
38582
+ modelSchool,
38567
38583
  schemaAsset,
38568
38584
  schemaAssetUpdateOption,
38569
38585
  schemaCurriculum,
38570
38586
  schemaDivision,
38587
+ schemaDivisionUpdate,
38571
38588
  schemaEnrollment,
38572
38589
  schemaGradeLevel,
38573
38590
  schemaPlantilla,