@eeplatform/core 1.1.0 → 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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @eeplatform/core
2
2
 
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c8913cd: Building management - update and delete feature
8
+
3
9
  ## 1.1.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -2456,6 +2456,7 @@ type TBuildingUnit = {
2456
2456
  deletedAt?: Date | string;
2457
2457
  };
2458
2458
  declare const schemaBuildingUnit: Joi.ObjectSchema<any>;
2459
+ declare const schemaUpdateOptions: Joi.ObjectSchema<any>;
2459
2460
  declare function MBuilding(value: TBuilding): {
2460
2461
  _id: ObjectId | undefined;
2461
2462
  school: ObjectId;
@@ -2499,7 +2500,13 @@ declare function useBuildingRepo(): {
2499
2500
  school?: string | undefined;
2500
2501
  status?: string | undefined;
2501
2502
  }) => Promise<Record<string, any>>;
2502
- getById: (_id: string | ObjectId) => Promise<TBuilding>;
2503
+ getById: (_id: string | ObjectId) => Promise<TBuilding | null>;
2504
+ updateById: (_id: ObjectId | string, value: {
2505
+ name: string;
2506
+ serial: string;
2507
+ levels: number;
2508
+ }, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
2509
+ deleteById: (_id: string | ObjectId, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
2503
2510
  };
2504
2511
 
2505
2512
  declare function useBuildingUnitRepo(): {
@@ -2515,18 +2522,35 @@ declare function useBuildingUnitRepo(): {
2515
2522
  status?: string | undefined;
2516
2523
  }) => Promise<Record<string, any>>;
2517
2524
  getById: (_id: string | ObjectId) => Promise<TBuildingUnit>;
2525
+ getByBuildingLevel: (building: string | ObjectId, level: number) => Promise<TBuildingUnit | null>;
2526
+ updateById: (_id: string | ObjectId, value: {
2527
+ name?: string | undefined;
2528
+ building?: string | undefined;
2529
+ level?: number | undefined;
2530
+ category?: string | undefined;
2531
+ type?: string | undefined;
2532
+ seating_capacity?: number | undefined;
2533
+ standing_capacity?: number | undefined;
2534
+ area?: number | undefined;
2535
+ }, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
2536
+ getByBuilding: (building: string | ObjectId) => Promise<TBuildingUnit | null>;
2537
+ deleteById: (_id: string | ObjectId, session?: ClientSession) => Promise<string>;
2518
2538
  };
2519
2539
 
2520
2540
  declare function useBuildingController(): {
2521
2541
  createBuilding: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2522
2542
  getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2523
2543
  getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2544
+ updateById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2545
+ deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2524
2546
  };
2525
2547
 
2526
2548
  declare function useBuildingUnitController(): {
2527
2549
  add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2528
2550
  getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2529
2551
  getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2552
+ updateById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2553
+ deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2530
2554
  };
2531
2555
 
2532
2556
  declare const MONGO_URI: string;
@@ -2565,4 +2589,4 @@ declare const PAYPAL_API_URL: string;
2565
2589
  declare const XENDIT_SECRET_KEY: string;
2566
2590
  declare const XENDIT_BASE_URL: string;
2567
2591
 
2568
- export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, CardPayment, CardPaymentSchema, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, DirectDebit, DirectDebitSchema, EWalletPayment, EWalletPaymentSchema, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MAddress, MBuilding, MBuildingUnit, MDivision, MEntity, MFile, MMember, MONGO_DB, MONGO_URI, MOrder, MOrg, MPaymentMethod, MPromoCode, MRegion, MRole, MSchool, MSubscription, MToken, MUser, MUserRole, MVerification, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PORT, REDIS_HOST, REDIS_PASSWORD, REDIS_PORT, REFRESH_TOKEN_EXPIRY, REFRESH_TOKEN_SECRET, SECRET_KEY, SPACES_ACCESS_KEY, SPACES_BUCKET, SPACES_ENDPOINT, SPACES_REGION, SPACES_SECRET_KEY, TAddress, TBillingRecipient, TBuilding, TBuildingUnit, TCounter, TDivision, TEntity, TFile, TInvoice, TMember, TMiniRole, TOrder, TOrderMetadata, TOrg, TPayment, TPaymentMethod$1 as TPaymentMethod, TPaymentMethodType, TPrice, TPriceType, TPromoCode, TPromoTier, TRegion, TRole, TSchool, TSubscription, TToken, TUser, TUserRole, TVerification, TVerificationMetadata, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, addressSchema, isDev, schema, schemaBuilding, schemaBuildingUnit, schemaDivision, schemaRegion, schemaSchool, useAddressController, useAddressRepo, useAuthController, useAuthService, useBuildingController, useBuildingRepo, useBuildingUnitController, useBuildingUnitRepo, useCounterModel, useCounterRepo, useDivisionController, useDivisionRepo, useDivisionService, useEntityController, useEntityRepo, useFileController, useFileRepo, useFileService, useInvoiceController, useInvoiceModel, useInvoiceRepo, useInvoiceService, useMemberController, useMemberRepo, useOrderController, useOrderRepo, useOrgController, useOrgRepo, useOrgService, usePaymentController, usePaymentMethodController, usePaymentMethodRepo, usePaymentMethodService, usePaymentModel, usePaymentRepo, usePaypalService, usePriceController, usePriceModel, usePriceRepo, usePromoCodeController, usePromoCodeRepo, useRegionController, useRegionRepo, useRegionService, useRoleController, useRoleRepo, useSchoolController, useSchoolRepo, useSchoolService, useSubscriptionController, useSubscriptionRepo, useSubscriptionService, useTokenRepo, useUserController, useUserRepo, useUserService, useVerificationController, useVerificationRepo, useVerificationService, useXenditService, validateCardPayment, validateDirectDebit, validateEWalletPayment };
2592
+ export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, CardPayment, CardPaymentSchema, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, DirectDebit, DirectDebitSchema, EWalletPayment, EWalletPaymentSchema, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MAddress, MBuilding, MBuildingUnit, MDivision, MEntity, MFile, MMember, MONGO_DB, MONGO_URI, MOrder, MOrg, MPaymentMethod, MPromoCode, MRegion, MRole, MSchool, MSubscription, MToken, MUser, MUserRole, MVerification, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PORT, REDIS_HOST, REDIS_PASSWORD, REDIS_PORT, REFRESH_TOKEN_EXPIRY, REFRESH_TOKEN_SECRET, SECRET_KEY, SPACES_ACCESS_KEY, SPACES_BUCKET, SPACES_ENDPOINT, SPACES_REGION, SPACES_SECRET_KEY, TAddress, TBillingRecipient, TBuilding, TBuildingUnit, TCounter, TDivision, TEntity, TFile, TInvoice, TMember, TMiniRole, TOrder, TOrderMetadata, TOrg, TPayment, TPaymentMethod$1 as TPaymentMethod, TPaymentMethodType, TPrice, TPriceType, TPromoCode, TPromoTier, TRegion, TRole, TSchool, TSubscription, TToken, TUser, TUserRole, TVerification, TVerificationMetadata, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, addressSchema, isDev, schema, schemaBuilding, schemaBuildingUnit, schemaDivision, schemaRegion, schemaSchool, schemaUpdateOptions, useAddressController, useAddressRepo, useAuthController, useAuthService, useBuildingController, useBuildingRepo, useBuildingUnitController, useBuildingUnitRepo, useCounterModel, useCounterRepo, useDivisionController, useDivisionRepo, useDivisionService, useEntityController, useEntityRepo, useFileController, useFileRepo, useFileService, useInvoiceController, useInvoiceModel, useInvoiceRepo, useInvoiceService, useMemberController, useMemberRepo, useOrderController, useOrderRepo, useOrgController, useOrgRepo, useOrgService, usePaymentController, usePaymentMethodController, usePaymentMethodRepo, usePaymentMethodService, usePaymentModel, usePaymentRepo, usePaypalService, usePriceController, usePriceModel, usePriceRepo, usePromoCodeController, usePromoCodeRepo, useRegionController, useRegionRepo, useRegionService, useRoleController, useRoleRepo, useSchoolController, useSchoolRepo, useSchoolService, useSubscriptionController, useSubscriptionRepo, useSubscriptionService, useTokenRepo, useUserController, useUserRepo, useUserService, useVerificationController, useVerificationRepo, useVerificationService, useXenditService, validateCardPayment, validateDirectDebit, validateEWalletPayment };
package/dist/index.js CHANGED
@@ -11389,6 +11389,7 @@ __export(src_exports, {
11389
11389
  schemaDivision: () => schemaDivision,
11390
11390
  schemaRegion: () => schemaRegion,
11391
11391
  schemaSchool: () => schemaSchool,
11392
+ schemaUpdateOptions: () => schemaUpdateOptions,
11392
11393
  useAddressController: () => useAddressController,
11393
11394
  useAddressRepo: () => useAddressRepo,
11394
11395
  useAuthController: () => useAuthController,
@@ -26987,6 +26988,16 @@ var schemaBuildingUnit = import_joi33.default.object({
26987
26988
  area: import_joi33.default.number().positive().required(),
26988
26989
  status: import_joi33.default.string().optional().allow("", null)
26989
26990
  });
26991
+ var schemaUpdateOptions = import_joi33.default.object({
26992
+ name: import_joi33.default.string().optional().allow("", null),
26993
+ building: import_joi33.default.string().hex().optional().allow("", null),
26994
+ level: import_joi33.default.number().integer().min(1).optional().allow("", null),
26995
+ category: import_joi33.default.string().optional().allow("", null),
26996
+ type: import_joi33.default.string().optional().allow("", null),
26997
+ seating_capacity: import_joi33.default.number().integer().min(0).optional().allow("", null),
26998
+ standing_capacity: import_joi33.default.number().integer().min(0).optional().allow("", null),
26999
+ area: import_joi33.default.number().positive().optional().allow("", null)
27000
+ });
26990
27001
  function MBuilding(value) {
26991
27002
  const { error } = schemaBuilding.validate(value);
26992
27003
  if (error) {
@@ -27114,6 +27125,32 @@ function useBuildingRepo() {
27114
27125
  }
27115
27126
  }
27116
27127
  }
27128
+ async function updateById(_id, value, session) {
27129
+ try {
27130
+ _id = new import_mongodb40.ObjectId(_id);
27131
+ } catch (error) {
27132
+ throw new import_nodejs_utils67.BadRequestError("Invalid ID.");
27133
+ }
27134
+ try {
27135
+ const res = await collection.updateOne(
27136
+ { _id },
27137
+ { $set: value },
27138
+ { session }
27139
+ );
27140
+ delCachedData();
27141
+ return res;
27142
+ } catch (error) {
27143
+ import_nodejs_utils67.logger.log({
27144
+ level: "error",
27145
+ message: error.message
27146
+ });
27147
+ if (error instanceof import_nodejs_utils67.AppError) {
27148
+ throw error;
27149
+ } else {
27150
+ throw new Error("Failed to update building.");
27151
+ }
27152
+ }
27153
+ }
27117
27154
  async function getAll({
27118
27155
  search = "",
27119
27156
  page = 1,
@@ -27204,12 +27241,8 @@ function useBuildingRepo() {
27204
27241
  return cached;
27205
27242
  }
27206
27243
  const result = await collection.findOne({
27207
- _id,
27208
- deletedAt: { $in: ["", null] }
27244
+ _id
27209
27245
  });
27210
- if (!result) {
27211
- throw new import_nodejs_utils67.BadRequestError("Building not found.");
27212
- }
27213
27246
  setCache(cacheKey, result, 300).then(() => {
27214
27247
  import_nodejs_utils67.logger.log({
27215
27248
  level: "info",
@@ -27230,6 +27263,31 @@ function useBuildingRepo() {
27230
27263
  }
27231
27264
  }
27232
27265
  }
27266
+ async function deleteById(_id, session) {
27267
+ try {
27268
+ _id = new import_mongodb40.ObjectId(_id);
27269
+ } catch (error) {
27270
+ throw new import_nodejs_utils67.BadRequestError("Invalid ID.");
27271
+ }
27272
+ try {
27273
+ const res = await collection.updateOne(
27274
+ { _id },
27275
+ { $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } }
27276
+ );
27277
+ delCachedData();
27278
+ return res;
27279
+ } catch (error) {
27280
+ import_nodejs_utils67.logger.log({
27281
+ level: "error",
27282
+ message: error.message
27283
+ });
27284
+ if (error instanceof import_nodejs_utils67.AppError) {
27285
+ throw error;
27286
+ } else {
27287
+ throw new import_nodejs_utils67.InternalServerError("Failed to delete building.");
27288
+ }
27289
+ }
27290
+ }
27233
27291
  function delCachedData() {
27234
27292
  delNamespace().then(() => {
27235
27293
  import_nodejs_utils67.logger.log({
@@ -27248,7 +27306,9 @@ function useBuildingRepo() {
27248
27306
  createTextIndex,
27249
27307
  add,
27250
27308
  getAll,
27251
- getById
27309
+ getById,
27310
+ updateById,
27311
+ deleteById
27252
27312
  };
27253
27313
  }
27254
27314
 
@@ -27314,6 +27374,36 @@ function useBuildingUnitRepo() {
27314
27374
  }
27315
27375
  }
27316
27376
  }
27377
+ async function updateById(_id, value, session) {
27378
+ const { error } = schemaUpdateOptions.validate(value);
27379
+ if (error) {
27380
+ throw new import_nodejs_utils68.BadRequestError(error.message);
27381
+ }
27382
+ try {
27383
+ _id = new import_mongodb41.ObjectId(_id);
27384
+ } catch (error2) {
27385
+ throw new import_nodejs_utils68.BadRequestError("Invalid ID.");
27386
+ }
27387
+ try {
27388
+ const res = await collection.updateOne(
27389
+ { _id },
27390
+ { $set: value },
27391
+ { session }
27392
+ );
27393
+ delCachedData();
27394
+ return res;
27395
+ } catch (error2) {
27396
+ import_nodejs_utils68.logger.log({
27397
+ level: "error",
27398
+ message: error2.message
27399
+ });
27400
+ if (error2 instanceof import_nodejs_utils68.AppError) {
27401
+ throw error2;
27402
+ } else {
27403
+ throw new Error("Failed to create building unit.");
27404
+ }
27405
+ }
27406
+ }
27317
27407
  async function getAll({
27318
27408
  search = "",
27319
27409
  page = 1,
@@ -27441,19 +27531,188 @@ function useBuildingUnitRepo() {
27441
27531
  }
27442
27532
  }
27443
27533
  }
27534
+ async function getByBuildingLevel(building, level) {
27535
+ try {
27536
+ building = new import_mongodb41.ObjectId(building);
27537
+ } catch (error) {
27538
+ throw new import_nodejs_utils68.BadRequestError("Invalid building ID.");
27539
+ }
27540
+ const cacheKey = (0, import_nodejs_utils68.makeCacheKey)(namespace_collection, {
27541
+ building: String(building),
27542
+ level
27543
+ });
27544
+ try {
27545
+ const cached = await getCache(cacheKey);
27546
+ if (cached) {
27547
+ import_nodejs_utils68.logger.log({
27548
+ level: "info",
27549
+ message: `Cache hit for getById building unit: ${cacheKey}`
27550
+ });
27551
+ return cached;
27552
+ }
27553
+ const result = await collection.findOne({
27554
+ building,
27555
+ level,
27556
+ status: "active"
27557
+ });
27558
+ setCache(cacheKey, result, 300).then(() => {
27559
+ import_nodejs_utils68.logger.log({
27560
+ level: "info",
27561
+ message: `Cache set for building unit by id: ${cacheKey}`
27562
+ });
27563
+ }).catch((err) => {
27564
+ import_nodejs_utils68.logger.log({
27565
+ level: "error",
27566
+ message: `Failed to set cache for building unit by id: ${err.message}`
27567
+ });
27568
+ });
27569
+ return result;
27570
+ } catch (error) {
27571
+ if (error instanceof import_nodejs_utils68.AppError) {
27572
+ throw error;
27573
+ } else {
27574
+ throw new import_nodejs_utils68.InternalServerError("Failed to get building unit.");
27575
+ }
27576
+ }
27577
+ }
27578
+ async function getByBuilding(building) {
27579
+ try {
27580
+ building = new import_mongodb41.ObjectId(building);
27581
+ } catch (error) {
27582
+ throw new import_nodejs_utils68.BadRequestError("Invalid building ID.");
27583
+ }
27584
+ const cacheKey = (0, import_nodejs_utils68.makeCacheKey)(namespace_collection, {
27585
+ building: String(building)
27586
+ });
27587
+ try {
27588
+ const cached = await getCache(cacheKey);
27589
+ if (cached) {
27590
+ import_nodejs_utils68.logger.log({
27591
+ level: "info",
27592
+ message: `Cache hit for getById building unit: ${cacheKey}`
27593
+ });
27594
+ return cached;
27595
+ }
27596
+ const result = await collection.findOne({
27597
+ building,
27598
+ status: "active"
27599
+ });
27600
+ setCache(cacheKey, result, 300).then(() => {
27601
+ import_nodejs_utils68.logger.log({
27602
+ level: "info",
27603
+ message: `Cache set for building unit by id: ${cacheKey}`
27604
+ });
27605
+ }).catch((err) => {
27606
+ import_nodejs_utils68.logger.log({
27607
+ level: "error",
27608
+ message: `Failed to set cache for building unit by id: ${err.message}`
27609
+ });
27610
+ });
27611
+ return result;
27612
+ } catch (error) {
27613
+ if (error instanceof import_nodejs_utils68.AppError) {
27614
+ throw error;
27615
+ } else {
27616
+ throw new import_nodejs_utils68.InternalServerError("Failed to get building unit.");
27617
+ }
27618
+ }
27619
+ }
27620
+ async function deleteById(_id, session) {
27621
+ try {
27622
+ _id = new import_mongodb41.ObjectId(_id);
27623
+ } catch (error) {
27624
+ throw new import_nodejs_utils68.BadRequestError("Invalid ID.");
27625
+ }
27626
+ try {
27627
+ const res = await collection.updateOne(
27628
+ { _id },
27629
+ { $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } },
27630
+ { session }
27631
+ );
27632
+ delCachedData();
27633
+ return "Room/Facility deleted successfully.";
27634
+ } catch (error) {
27635
+ import_nodejs_utils68.logger.log({
27636
+ level: "error",
27637
+ message: error.message
27638
+ });
27639
+ if (error instanceof import_nodejs_utils68.AppError) {
27640
+ throw error;
27641
+ } else {
27642
+ throw new Error("Failed to deleted room/facility.");
27643
+ }
27644
+ }
27645
+ }
27444
27646
  return {
27445
27647
  createIndex,
27446
27648
  add,
27447
27649
  getAll,
27448
- getById
27650
+ getById,
27651
+ getByBuildingLevel,
27652
+ updateById,
27653
+ getByBuilding,
27654
+ deleteById
27449
27655
  };
27450
27656
  }
27451
27657
 
27452
27658
  // src/controllers/building.controller.ts
27453
- var import_nodejs_utils69 = require("@eeplatform/nodejs-utils");
27659
+ var import_nodejs_utils70 = require("@eeplatform/nodejs-utils");
27454
27660
  var import_joi34 = __toESM(require("joi"));
27661
+
27662
+ // src/services/building.service.ts
27663
+ var import_nodejs_utils69 = require("@eeplatform/nodejs-utils");
27664
+ function useBuildingService() {
27665
+ const {
27666
+ updateById: _updateById,
27667
+ getById: _getById,
27668
+ deleteById: _deleteById
27669
+ } = useBuildingRepo();
27670
+ const { getByBuildingLevel, getByBuilding } = useBuildingUnitRepo();
27671
+ async function updateById(id, data) {
27672
+ data.levels = Number(data.levels);
27673
+ try {
27674
+ const building = await _getById(id);
27675
+ if (!building) {
27676
+ throw new import_nodejs_utils69.NotFoundError("Building not found.");
27677
+ }
27678
+ if (data.levels < building.levels) {
27679
+ const unit = await getByBuildingLevel(id, building.levels);
27680
+ if (unit) {
27681
+ throw new import_nodejs_utils69.BadRequestError(
27682
+ "Cannot reduce floors, there are existing building units at higher floors."
27683
+ );
27684
+ }
27685
+ }
27686
+ const result = await _updateById(id, data);
27687
+ return result;
27688
+ } catch (error) {
27689
+ throw error;
27690
+ }
27691
+ }
27692
+ async function deleteById(id) {
27693
+ const building = await getByBuilding(id);
27694
+ if (building) {
27695
+ throw new import_nodejs_utils69.BadRequestError(
27696
+ "Cannot delete building with existing room/facility. Please delete room/facility first."
27697
+ );
27698
+ }
27699
+ try {
27700
+ await _deleteById(id);
27701
+ return "Building deleted successfully.";
27702
+ } catch (error) {
27703
+ throw error;
27704
+ }
27705
+ }
27706
+ return {
27707
+ updateById,
27708
+ deleteById
27709
+ };
27710
+ }
27711
+
27712
+ // src/controllers/building.controller.ts
27455
27713
  function useBuildingController() {
27456
27714
  const { getAll: _getAll, getById: _getById, add: _add } = useBuildingRepo();
27715
+ const { updateById: _updateById, deleteById: _deleteById } = useBuildingService();
27457
27716
  async function createBuilding(req, res, next) {
27458
27717
  const value = req.body;
27459
27718
  const validation = import_joi34.default.object({
@@ -27465,8 +27724,8 @@ function useBuildingController() {
27465
27724
  });
27466
27725
  const { error } = validation.validate(value);
27467
27726
  if (error) {
27468
- next(new import_nodejs_utils69.BadRequestError(error.message));
27469
- import_nodejs_utils69.logger.info(`Controller: ${error.message}`);
27727
+ next(new import_nodejs_utils70.BadRequestError(error.message));
27728
+ import_nodejs_utils70.logger.info(`Controller: ${error.message}`);
27470
27729
  return;
27471
27730
  }
27472
27731
  try {
@@ -27477,6 +27736,31 @@ function useBuildingController() {
27477
27736
  next(error2);
27478
27737
  }
27479
27738
  }
27739
+ async function updateById(req, res, next) {
27740
+ const value = req.body;
27741
+ const id = req.params.id ?? "";
27742
+ const validation = import_joi34.default.object({
27743
+ id: import_joi34.default.string().hex().required(),
27744
+ value: import_joi34.default.object({
27745
+ name: import_joi34.default.string().required(),
27746
+ serial: import_joi34.default.string().optional().allow("", null),
27747
+ levels: import_joi34.default.number().integer().min(1).required()
27748
+ })
27749
+ });
27750
+ const { error } = validation.validate({ id, value });
27751
+ if (error) {
27752
+ next(new import_nodejs_utils70.BadRequestError(error.message));
27753
+ import_nodejs_utils70.logger.info(`Controller: ${error.message}`);
27754
+ return;
27755
+ }
27756
+ try {
27757
+ const result = await _updateById(id, value);
27758
+ res.json(result);
27759
+ return;
27760
+ } catch (error2) {
27761
+ next(error2);
27762
+ }
27763
+ }
27480
27764
  async function getAll(req, res, next) {
27481
27765
  const query = req.query;
27482
27766
  const validation = import_joi34.default.object({
@@ -27488,7 +27772,7 @@ function useBuildingController() {
27488
27772
  });
27489
27773
  const { error } = validation.validate(query);
27490
27774
  if (error) {
27491
- next(new import_nodejs_utils69.BadRequestError(error.message));
27775
+ next(new import_nodejs_utils70.BadRequestError(error.message));
27492
27776
  return;
27493
27777
  }
27494
27778
  const page = parseInt(req.query.page) ?? 1;
@@ -27527,7 +27811,7 @@ function useBuildingController() {
27527
27811
  });
27528
27812
  const { error } = validation.validate({ id });
27529
27813
  if (error) {
27530
- next(new import_nodejs_utils69.BadRequestError(error.message));
27814
+ next(new import_nodejs_utils70.BadRequestError(error.message));
27531
27815
  return;
27532
27816
  }
27533
27817
  try {
@@ -27541,23 +27825,43 @@ function useBuildingController() {
27541
27825
  next(error2);
27542
27826
  }
27543
27827
  }
27828
+ async function deleteById(req, res, next) {
27829
+ const id = req.params.id;
27830
+ const validation = import_joi34.default.object({
27831
+ id: import_joi34.default.string().hex().required()
27832
+ });
27833
+ const { error } = validation.validate({ id });
27834
+ if (error) {
27835
+ next(new import_nodejs_utils70.BadRequestError(error.message));
27836
+ return;
27837
+ }
27838
+ try {
27839
+ const message = await _deleteById(id);
27840
+ res.json(message);
27841
+ return;
27842
+ } catch (error2) {
27843
+ next(error2);
27844
+ }
27845
+ }
27544
27846
  return {
27545
27847
  createBuilding,
27546
27848
  getAll,
27547
- getById
27849
+ getById,
27850
+ updateById,
27851
+ deleteById
27548
27852
  };
27549
27853
  }
27550
27854
 
27551
27855
  // src/controllers/building-unit.controller.ts
27552
- var import_nodejs_utils71 = require("@eeplatform/nodejs-utils");
27856
+ var import_nodejs_utils72 = require("@eeplatform/nodejs-utils");
27553
27857
  var import_joi35 = __toESM(require("joi"));
27554
27858
 
27555
27859
  // src/services/building-unit.service.ts
27556
- var import_nodejs_utils70 = require("@eeplatform/nodejs-utils");
27860
+ var import_nodejs_utils71 = require("@eeplatform/nodejs-utils");
27557
27861
  function useBuildingUnitService() {
27558
27862
  const { add: _add } = useBuildingUnitRepo();
27559
27863
  async function add(value) {
27560
- const session = import_nodejs_utils70.useAtlas.getClient()?.startSession();
27864
+ const session = import_nodejs_utils71.useAtlas.getClient()?.startSession();
27561
27865
  if (!session) {
27562
27866
  throw new Error("Unable to start session for building unit service.");
27563
27867
  }
@@ -27582,7 +27886,12 @@ function useBuildingUnitService() {
27582
27886
 
27583
27887
  // src/controllers/building-unit.controller.ts
27584
27888
  function useBuildingUnitController() {
27585
- const { getAll: _getAll, getById: _getById } = useBuildingUnitRepo();
27889
+ const {
27890
+ getAll: _getAll,
27891
+ getById: _getById,
27892
+ updateById: _updateById,
27893
+ deleteById: _deleteById
27894
+ } = useBuildingUnitRepo();
27586
27895
  const { add: _add } = useBuildingUnitService();
27587
27896
  async function add(req, res, next) {
27588
27897
  const data = req.body;
@@ -27606,7 +27915,7 @@ function useBuildingUnitController() {
27606
27915
  });
27607
27916
  const { error } = validation.validate(data);
27608
27917
  if (error) {
27609
- next(new import_nodejs_utils71.BadRequestError(error.message));
27918
+ next(new import_nodejs_utils72.BadRequestError(error.message));
27610
27919
  return;
27611
27920
  }
27612
27921
  try {
@@ -27619,6 +27928,28 @@ function useBuildingUnitController() {
27619
27928
  next(error2);
27620
27929
  }
27621
27930
  }
27931
+ async function updateById(req, res, next) {
27932
+ const data = req.body;
27933
+ const id = req.params.id ?? "";
27934
+ const validation = import_joi35.default.object({
27935
+ id: import_joi35.default.string().hex().required(),
27936
+ value: schemaUpdateOptions
27937
+ });
27938
+ const { error } = validation.validate({ id, value: data });
27939
+ if (error) {
27940
+ next(new import_nodejs_utils72.BadRequestError(error.message));
27941
+ return;
27942
+ }
27943
+ try {
27944
+ const buildingUnit = await _updateById(id, data);
27945
+ res.json({
27946
+ message: "Building unit updated successfully.",
27947
+ data: { buildingUnit }
27948
+ });
27949
+ } catch (error2) {
27950
+ next(error2);
27951
+ }
27952
+ }
27622
27953
  async function getAll(req, res, next) {
27623
27954
  const query = req.query;
27624
27955
  const validation = import_joi35.default.object({
@@ -27631,7 +27962,7 @@ function useBuildingUnitController() {
27631
27962
  });
27632
27963
  const { error } = validation.validate(query);
27633
27964
  if (error) {
27634
- next(new import_nodejs_utils71.BadRequestError(error.message));
27965
+ next(new import_nodejs_utils72.BadRequestError(error.message));
27635
27966
  return;
27636
27967
  }
27637
27968
  const page = parseInt(req.query.page) ?? 1;
@@ -27672,7 +28003,7 @@ function useBuildingUnitController() {
27672
28003
  });
27673
28004
  const { error } = validation.validate({ id });
27674
28005
  if (error) {
27675
- next(new import_nodejs_utils71.BadRequestError(error.message));
28006
+ next(new import_nodejs_utils72.BadRequestError(error.message));
27676
28007
  return;
27677
28008
  }
27678
28009
  try {
@@ -27686,10 +28017,30 @@ function useBuildingUnitController() {
27686
28017
  next(error2);
27687
28018
  }
27688
28019
  }
28020
+ async function deleteById(req, res, next) {
28021
+ const id = req.params.id;
28022
+ const validation = import_joi35.default.object({
28023
+ id: import_joi35.default.string().hex().required()
28024
+ });
28025
+ const { error } = validation.validate({ id });
28026
+ if (error) {
28027
+ next(new import_nodejs_utils72.BadRequestError(error.message));
28028
+ return;
28029
+ }
28030
+ try {
28031
+ const message = await _deleteById(id);
28032
+ res.json({ message });
28033
+ return;
28034
+ } catch (error2) {
28035
+ next(error2);
28036
+ }
28037
+ }
27689
28038
  return {
27690
28039
  add,
27691
28040
  getAll,
27692
- getById
28041
+ getById,
28042
+ updateById,
28043
+ deleteById
27693
28044
  };
27694
28045
  }
27695
28046
  // Annotate the CommonJS export names for ESM import in node:
@@ -27758,6 +28109,7 @@ function useBuildingUnitController() {
27758
28109
  schemaDivision,
27759
28110
  schemaRegion,
27760
28111
  schemaSchool,
28112
+ schemaUpdateOptions,
27761
28113
  useAddressController,
27762
28114
  useAddressRepo,
27763
28115
  useAuthController,