@7365admin1/core 2.66.0 → 2.67.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
@@ -33,6 +33,7 @@ __export(src_exports, {
33
33
  ANPRMode: () => ANPRMode,
34
34
  AccessTypeProps: () => AccessTypeProps,
35
35
  AppServiceType: () => AppServiceType,
36
+ BuildingLevelStatus: () => BuildingLevelStatus,
36
37
  BuildingStatus: () => BuildingStatus,
37
38
  BulletinOrder: () => BulletinOrder,
38
39
  BulletinRecipient: () => BulletinRecipient,
@@ -66,9 +67,11 @@ __export(src_exports, {
66
67
  MBillingConfiguration: () => MBillingConfiguration,
67
68
  MBillingItem: () => MBillingItem,
68
69
  MBuilding: () => MBuilding,
70
+ MBuildingLevel: () => MBuildingLevel,
69
71
  MBuildingUnit: () => MBuildingUnit,
70
72
  MBulletinBoard: () => MBulletinBoard,
71
73
  MBulletinVideo: () => MBulletinVideo,
74
+ MCategoryPreloved: () => MCategoryPreloved,
72
75
  MChat: () => MChat,
73
76
  MCustomer: () => MCustomer,
74
77
  MCustomerSite: () => MCustomerSite,
@@ -114,6 +117,7 @@ __export(src_exports, {
114
117
  MSiteFacility: () => MSiteFacility,
115
118
  MSiteFacilityBooking: () => MSiteFacilityBooking,
116
119
  MStatementOfAccount: () => MStatementOfAccount,
120
+ MSubcategoryPreloved: () => MSubcategoryPreloved,
117
121
  MSubscription: () => MSubscription,
118
122
  MUnitBilling: () => MUnitBilling,
119
123
  MUser: () => MUser,
@@ -161,6 +165,7 @@ __export(src_exports, {
161
165
  allowedNatures: () => allowedNatures,
162
166
  attendanceSchema: () => attendanceSchema,
163
167
  attendanceSettingsSchema: () => attendanceSettingsSchema,
168
+ building_level_namespace_collection: () => building_level_namespace_collection,
164
169
  building_units_namespace_collection: () => building_units_namespace_collection,
165
170
  buildings_namespace_collection: () => buildings_namespace_collection,
166
171
  bulletin_boards_namespace_collection: () => bulletin_boards_namespace_collection,
@@ -205,10 +210,12 @@ __export(src_exports, {
205
210
  schemaBillingConfiguration: () => schemaBillingConfiguration,
206
211
  schemaBillingItem: () => schemaBillingItem,
207
212
  schemaBuilding: () => schemaBuilding,
213
+ schemaBuildingLevel: () => schemaBuildingLevel,
208
214
  schemaBuildingUnit: () => schemaBuildingUnit,
209
215
  schemaBuildingUpdateOptions: () => schemaBuildingUpdateOptions,
210
216
  schemaBulletinBoard: () => schemaBulletinBoard,
211
217
  schemaBulletinVideo: () => schemaBulletinVideo,
218
+ schemaCategoryPreloved: () => schemaCategoryPreloved,
212
219
  schemaCustomerSite: () => schemaCustomerSite,
213
220
  schemaDocumentManagement: () => schemaDocumentManagement,
214
221
  schemaEntryPassSettings: () => schemaEntryPassSettings,
@@ -239,9 +246,11 @@ __export(src_exports, {
239
246
  schemaSiteFacility: () => schemaSiteFacility,
240
247
  schemaSiteFacilityBooking: () => schemaSiteFacilityBooking,
241
248
  schemaStatementOfAccount: () => schemaStatementOfAccount,
249
+ schemaSubcategoryPreloved: () => schemaSubcategoryPreloved,
242
250
  schemaUnitBilling: () => schemaUnitBilling,
243
251
  schemaUpdateBulletinBoard: () => schemaUpdateBulletinBoard,
244
252
  schemaUpdateBulletinVideo: () => schemaUpdateBulletinVideo,
253
+ schemaUpdateCategoryPreloved: () => schemaUpdateCategoryPreloved,
245
254
  schemaUpdateDocumentManagement: () => schemaUpdateDocumentManagement,
246
255
  schemaUpdateEntryPassSettings: () => schemaUpdateEntryPassSettings,
247
256
  schemaUpdateEventManagement: () => schemaUpdateEventManagement,
@@ -267,6 +276,7 @@ __export(src_exports, {
267
276
  schemaUpdateSiteFacilityBooking: () => schemaUpdateSiteFacilityBooking,
268
277
  schemaUpdateSiteUnitBilling: () => schemaUpdateSiteUnitBilling,
269
278
  schemaUpdateStatementOfAccount: () => schemaUpdateStatementOfAccount,
279
+ schemaUpdateSubcategoryPreloved: () => schemaUpdateSubcategoryPreloved,
270
280
  schemaUpdateVisTrans: () => schemaUpdateVisTrans,
271
281
  schemaVehicleTransaction: () => schemaVehicleTransaction,
272
282
  schemaVisitorTransaction: () => schemaVisitorTransaction,
@@ -292,6 +302,9 @@ __export(src_exports, {
292
302
  useAuthService: () => useAuthService,
293
303
  useAuthServiceV2: () => useAuthServiceV2,
294
304
  useBuildingController: () => useBuildingController,
305
+ useBuildingLevelController: () => useBuildingLevelController,
306
+ useBuildingLevelRepo: () => useBuildingLevelRepo,
307
+ useBuildingLevelService: () => useBuildingLevelService,
295
308
  useBuildingRepo: () => useBuildingRepo,
296
309
  useBuildingService: () => useBuildingService,
297
310
  useBuildingUnitController: () => useBuildingUnitController,
@@ -303,6 +316,8 @@ __export(src_exports, {
303
316
  useBulletinVideoController: () => useBulletinVideoController,
304
317
  useBulletinVideoRepo: () => useBulletinVideoRepo,
305
318
  useBulletinVideoService: () => useBulletinVideoService,
319
+ useCategoryPrelovedController: () => useCategoryPrelovedController,
320
+ useCategoryPrelovedRepo: () => useCategoryPrelovedRepo,
306
321
  useChatController: () => useChatController,
307
322
  useChatRepo: () => useChatRepo,
308
323
  useCounterModel: () => useCounterModel,
@@ -440,6 +455,8 @@ __export(src_exports, {
440
455
  useSiteUnitBillingService: () => useSiteUnitBillingService,
441
456
  useStatementOfAccountController: () => useStatementOfAccountController,
442
457
  useStatementOfAccountRepo: () => useStatementOfAccountRepo,
458
+ useSubcategoryPrelovedController: () => useSubcategoryPrelovedController,
459
+ useSubcategoryPrelovedRepo: () => useSubcategoryPrelovedRepo,
443
460
  useSubscriptionController: () => useSubscriptionController,
444
461
  useSubscriptionRepo: () => useSubscriptionRepo,
445
462
  useSubscriptionService: () => useSubscriptionService,
@@ -4599,7 +4616,7 @@ function useOrgRepo() {
4599
4616
  }
4600
4617
  async function createUniqueIndex() {
4601
4618
  try {
4602
- await collection.createIndex({ email: 1 }, { unique: true });
4619
+ await collection.createIndex({ email: 1 });
4603
4620
  } catch (error) {
4604
4621
  throw new import_node_server_utils17.InternalServerError("Failed to create unique index on name.");
4605
4622
  }
@@ -4791,7 +4808,6 @@ function useOrgRepo() {
4791
4808
  }
4792
4809
  async function getOrgsByEmail(email) {
4793
4810
  const cacheKey = (0, import_node_server_utils17.makeCacheKey)(namespace_collection, {
4794
- type: "many",
4795
4811
  email
4796
4812
  });
4797
4813
  const cachedData = await getCache(cacheKey);
@@ -31417,26 +31433,31 @@ var schemaDocumentManagement = import_joi74.default.object({
31417
31433
  _id: import_joi74.default.string().hex().optional().allow("", null),
31418
31434
  name: import_joi74.default.string().required(),
31419
31435
  type: import_joi74.default.string().optional().allow("", null),
31420
- attachment: import_joi74.default.string().required(),
31421
- status: import_joi74.default.string().required(),
31422
- createdBy: import_joi74.default.string().hex().required(),
31436
+ attachment: import_joi74.default.when("isFolder", { is: true, then: import_joi74.default.forbidden(), otherwise: import_joi74.default.string().optional().allow("", null) }),
31437
+ remarks: import_joi74.default.string().optional().allow("", null),
31438
+ isFolder: import_joi74.default.boolean().optional().default(false),
31423
31439
  org: import_joi74.default.string().hex().optional().allow("", null),
31424
31440
  site: import_joi74.default.string().hex().optional().allow("", null),
31441
+ parentId: import_joi74.default.string().hex().optional().allow("", null),
31442
+ createdBy: import_joi74.default.string().hex().required(),
31425
31443
  updatedBy: import_joi74.default.string().hex().optional().allow("", null),
31426
31444
  createdAt: import_joi74.default.date().optional().allow("", null),
31427
- updatedAt: import_joi74.default.date().optional().allow("", null)
31445
+ updatedAt: import_joi74.default.date().optional().allow("", null),
31446
+ status: import_joi74.default.string().optional().allow("", null).default("active")
31428
31447
  });
31429
31448
  var schemaUpdateDocumentManagement = import_joi74.default.object({
31430
31449
  _id: import_joi74.default.string().hex().required(),
31431
31450
  name: import_joi74.default.string().optional().allow("", null),
31432
31451
  type: import_joi74.default.string().optional().allow("", null),
31433
- attachment: import_joi74.default.string().optional(),
31434
- status: import_joi74.default.string().optional().allow("", null),
31452
+ attachment: import_joi74.default.when("isFolder", { is: true, then: import_joi74.default.forbidden(), otherwise: import_joi74.default.string().optional().allow("", null) }),
31453
+ remarks: import_joi74.default.string().optional().allow("", null),
31454
+ isFolder: import_joi74.default.boolean().optional(),
31435
31455
  org: import_joi74.default.string().hex().optional().allow("", null),
31436
31456
  site: import_joi74.default.string().hex().optional().allow("", null),
31457
+ parentId: import_joi74.default.string().hex().optional().allow("", null),
31437
31458
  updatedBy: import_joi74.default.string().hex().optional().allow("", null),
31438
- createdAt: import_joi74.default.date().optional().allow("", null),
31439
- updatedAt: import_joi74.default.date().optional().allow("", null)
31459
+ updatedAt: import_joi74.default.date().optional().allow("", null),
31460
+ status: import_joi74.default.string().optional().allow("", null)
31440
31461
  });
31441
31462
  function MDocumentManagement(value) {
31442
31463
  const { error } = schemaDocumentManagement.validate(value);
@@ -31464,18 +31485,31 @@ function MDocumentManagement(value) {
31464
31485
  throw new Error("Invalid site ID.");
31465
31486
  }
31466
31487
  }
31488
+ if (value.parentId && typeof value.parentId === "string") {
31489
+ try {
31490
+ value.parentId = new import_mongodb76.ObjectId(value.parentId);
31491
+ } catch (error2) {
31492
+ throw new Error("Invalid parentId.");
31493
+ }
31494
+ }
31495
+ if (value.isFolder) {
31496
+ value.attachment = void 0;
31497
+ }
31467
31498
  return {
31468
31499
  _id: value._id,
31469
31500
  name: value.name,
31470
31501
  type: value.type,
31471
31502
  attachment: value.attachment,
31472
- status: value.status,
31503
+ remarks: value.remarks ?? "",
31504
+ isFolder: value.isFolder ?? false,
31473
31505
  org: value.org,
31474
31506
  site: value.site,
31507
+ ...value.parentId ? { parentId: value.parentId } : {},
31475
31508
  createdBy: value.createdBy,
31476
31509
  updatedBy: value.updatedBy,
31477
31510
  createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
31478
- updatedAt: value.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString()
31511
+ updatedAt: value.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
31512
+ status: value.status ?? "active"
31479
31513
  };
31480
31514
  }
31481
31515
 
@@ -31490,11 +31524,22 @@ function useDocumentManagementRepo() {
31490
31524
  const namespace_collection = "documents";
31491
31525
  const collection = db.collection(namespace_collection);
31492
31526
  const { delNamespace, getCache, setCache } = (0, import_node_server_utils133.useCache)(namespace_collection);
31527
+ async function createIndex() {
31528
+ try {
31529
+ await collection.createIndexes([
31530
+ { key: { site: 1 } },
31531
+ { key: { isFolder: 1 } },
31532
+ { key: { parentId: 1 } }
31533
+ ]);
31534
+ } catch (error) {
31535
+ throw new import_node_server_utils133.InternalServerError("Failed to create index on document.");
31536
+ }
31537
+ }
31493
31538
  async function createTextIndex() {
31494
31539
  try {
31495
31540
  await collection.createIndex({
31496
31541
  name: "text",
31497
- type: "text"
31542
+ remarks: "text"
31498
31543
  });
31499
31544
  } catch (error) {
31500
31545
  throw new import_node_server_utils133.InternalServerError("Failed to create text index on document.");
@@ -31528,7 +31573,8 @@ function useDocumentManagementRepo() {
31528
31573
  sort = {},
31529
31574
  status = "active",
31530
31575
  org = "",
31531
- site = ""
31576
+ site = "",
31577
+ parentId = ""
31532
31578
  }) {
31533
31579
  page = page > 0 ? page - 1 : 0;
31534
31580
  try {
@@ -31547,14 +31593,24 @@ function useDocumentManagementRepo() {
31547
31593
  const query = {
31548
31594
  ...status ? { $and: [{ status }, { status: { $ne: "deleted" } }] } : { status: { $ne: "deleted" } }
31549
31595
  };
31550
- if (site) {
31551
- query.site = site;
31552
- cacheOptions.site = site;
31596
+ if (org) {
31597
+ query.org = new import_mongodb77.ObjectId(org);
31598
+ cacheOptions.org = org.toString();
31599
+ }
31600
+ if (parentId) {
31601
+ try {
31602
+ query.parentId = new import_mongodb77.ObjectId(parentId);
31603
+ cacheOptions.parentId = parentId.toString();
31604
+ } catch (error) {
31605
+ throw new import_node_server_utils133.BadRequestError("Invalid parentId format.");
31606
+ }
31607
+ } else {
31608
+ query.parentId = { $in: [null, ""] };
31553
31609
  }
31554
31610
  if (search) {
31555
31611
  query.$or = [
31556
31612
  { name: { $regex: search, $options: "i" } },
31557
- { type: { $regex: search, $options: "i" } }
31613
+ { remarks: { $regex: search, $options: "i" } }
31558
31614
  ];
31559
31615
  cacheOptions.search = search;
31560
31616
  }
@@ -31576,6 +31632,9 @@ function useDocumentManagementRepo() {
31576
31632
  type: 1,
31577
31633
  status: 1,
31578
31634
  attachment: 1,
31635
+ parentId: 1,
31636
+ isFolder: 1,
31637
+ remarks: 1,
31579
31638
  createdAt: 1,
31580
31639
  updatedAt: 1
31581
31640
  }
@@ -31747,6 +31806,7 @@ function useDocumentManagementRepo() {
31747
31806
  }
31748
31807
  }
31749
31808
  return {
31809
+ createIndex,
31750
31810
  createTextIndex,
31751
31811
  add,
31752
31812
  getAll,
@@ -31760,7 +31820,7 @@ function useDocumentManagementRepo() {
31760
31820
  // src/services/document-management.service.ts
31761
31821
  var import_node_server_utils134 = require("@7365admin1/node-server-utils");
31762
31822
  function useDocumentManagementService() {
31763
- const { add: _add, getAll: _getAll } = useDocumentManagementRepo();
31823
+ const { add: _add } = useDocumentManagementRepo();
31764
31824
  const { updateStatusById } = useFileRepo();
31765
31825
  async function createDocument(value) {
31766
31826
  const session = import_node_server_utils134.useAtlas.getClient()?.startSession();
@@ -31790,32 +31850,8 @@ function useDocumentManagementService() {
31790
31850
  session?.endSession();
31791
31851
  }
31792
31852
  }
31793
- async function getDocuments({
31794
- search,
31795
- page,
31796
- limit,
31797
- sort,
31798
- status,
31799
- org,
31800
- site
31801
- }) {
31802
- try {
31803
- return await _getAll({
31804
- search,
31805
- page,
31806
- limit,
31807
- sort,
31808
- status,
31809
- org,
31810
- site
31811
- });
31812
- } catch (error) {
31813
- throw error;
31814
- }
31815
- }
31816
31853
  return {
31817
- createDocument,
31818
- getDocuments
31854
+ createDocument
31819
31855
  };
31820
31856
  }
31821
31857
 
@@ -31823,8 +31859,9 @@ function useDocumentManagementService() {
31823
31859
  var import_node_server_utils135 = require("@7365admin1/node-server-utils");
31824
31860
  var import_joi75 = __toESM(require("joi"));
31825
31861
  function useDocumentManagementController() {
31826
- const { createDocument: _add, getDocuments: _getDocuments } = useDocumentManagementService();
31862
+ const { createDocument: _add } = useDocumentManagementService();
31827
31863
  const {
31864
+ getAll: _getDocuments,
31828
31865
  getDocumentById: _getDocumentById,
31829
31866
  updateDocumentById: _updateDocumentById,
31830
31867
  deleteDocumentById: _deleteDocumentById,
@@ -31842,8 +31879,12 @@ function useDocumentManagementController() {
31842
31879
  createdBy = req.body.createdBy;
31843
31880
  }
31844
31881
  const payload = { ...req.body, createdBy };
31845
- if (payload.attachment.length > 0) {
31882
+ if (payload.isFolder) {
31883
+ delete payload.attachment;
31884
+ } else if (Array.isArray(payload.attachment)) {
31846
31885
  payload.attachment = payload.attachment[0];
31886
+ } else if (!payload.attachment) {
31887
+ payload.attachment = "";
31847
31888
  }
31848
31889
  const { error } = schemaDocumentManagement.validate(payload, {
31849
31890
  abortEarly: false
@@ -31871,7 +31912,8 @@ function useDocumentManagementController() {
31871
31912
  limit: import_joi75.default.number().integer().min(1).max(100).allow("", null).default(10),
31872
31913
  status: import_joi75.default.string().required(),
31873
31914
  org: import_joi75.default.string().hex().optional().allow("", null),
31874
- site: import_joi75.default.string().hex().optional().allow("", null)
31915
+ site: import_joi75.default.string().hex().optional().allow("", null),
31916
+ parentId: import_joi75.default.string().hex().optional().allow("", null)
31875
31917
  });
31876
31918
  const query = { ...req.query };
31877
31919
  query.status = req.query.status;
@@ -31887,6 +31929,7 @@ function useDocumentManagementController() {
31887
31929
  const status = req.query.status ?? "active";
31888
31930
  const org = req.query.org ?? "";
31889
31931
  const site = req.query.site ?? "";
31932
+ const parentId = req.query.parentId ?? "";
31890
31933
  try {
31891
31934
  const data = await _getDocuments({
31892
31935
  search,
@@ -31894,7 +31937,8 @@ function useDocumentManagementController() {
31894
31937
  limit,
31895
31938
  status,
31896
31939
  org,
31897
- site
31940
+ site,
31941
+ parentId
31898
31942
  });
31899
31943
  res.json(data);
31900
31944
  return;
@@ -31950,8 +31994,12 @@ function useDocumentManagementController() {
31950
31994
  }
31951
31995
  const _id = req.params.id;
31952
31996
  const payload = { ...req.body, updatedBy };
31953
- if (payload.attachment.length > 0) {
31997
+ if (payload.isFolder) {
31998
+ delete payload.attachment;
31999
+ } else if (Array.isArray(payload.attachment)) {
31954
32000
  payload.attachment = payload.attachment[0];
32001
+ } else if (!payload.attachment) {
32002
+ payload.attachment = "";
31955
32003
  }
31956
32004
  const { error } = validation.validate({ _id, ...payload });
31957
32005
  if (error) {
@@ -54807,50 +54855,279 @@ function usePostPrelovedController() {
54807
54855
  };
54808
54856
  }
54809
54857
 
54810
- // src/models/online-forms-v2.model.ts
54858
+ // src/models/category-preloved.model.ts
54811
54859
  var import_joi134 = __toESM(require("joi"));
54812
54860
  var import_mongodb131 = require("mongodb");
54861
+ var schemaCategoryPreloved = import_joi134.default.object({
54862
+ name: import_joi134.default.string().required(),
54863
+ createdBy: import_joi134.default.string().hex().optional().allow("", null),
54864
+ site: import_joi134.default.string().hex().optional().allow("", null)
54865
+ });
54866
+ var schemaUpdateCategoryPreloved = import_joi134.default.object({
54867
+ name: import_joi134.default.string().optional().allow("", null),
54868
+ site: import_joi134.default.string().hex().optional().allow("", null)
54869
+ });
54870
+ function MCategoryPreloved(value) {
54871
+ const { error } = schemaCategoryPreloved.validate(value);
54872
+ if (error) {
54873
+ throw new Error(error.details[0].message);
54874
+ }
54875
+ if (value.createdBy && typeof value.createdBy === "string") {
54876
+ try {
54877
+ value.createdBy = new import_mongodb131.ObjectId(value.createdBy);
54878
+ } catch {
54879
+ throw new Error("Invalid createdBy ID.");
54880
+ }
54881
+ }
54882
+ if (value.site && typeof value.site === "string") {
54883
+ try {
54884
+ value.site = new import_mongodb131.ObjectId(value.site);
54885
+ } catch {
54886
+ throw new Error("Invalid site ID.");
54887
+ }
54888
+ }
54889
+ return {
54890
+ name: value.name ?? "",
54891
+ createdBy: value.createdBy ?? "",
54892
+ site: value.site ?? null,
54893
+ createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
54894
+ updatedAt: value.updatedAt ?? null
54895
+ };
54896
+ }
54897
+
54898
+ // src/repositories/category-preloved.repo.ts
54899
+ var import_node_server_utils234 = require("@7365admin1/node-server-utils");
54900
+ var import_mongodb132 = require("mongodb");
54901
+ function useCategoryPrelovedRepo() {
54902
+ const db = import_node_server_utils234.useAtlas.getDb();
54903
+ if (!db) {
54904
+ throw new import_node_server_utils234.InternalServerError("Unable to connect to server.");
54905
+ }
54906
+ const CATEGORY_COLLECTION = "category-preloved";
54907
+ const collection = db.collection(CATEGORY_COLLECTION);
54908
+ async function getAll({
54909
+ search = "",
54910
+ site
54911
+ } = {}) {
54912
+ if (site) {
54913
+ try {
54914
+ site = new import_mongodb132.ObjectId(site);
54915
+ } catch {
54916
+ throw new import_node_server_utils234.BadRequestError("Invalid site ID format.");
54917
+ }
54918
+ }
54919
+ const query = {
54920
+ ...site && { site },
54921
+ ...search && { name: { $regex: search, $options: "i" } }
54922
+ };
54923
+ try {
54924
+ return await collection.find(query).sort({ name: 1 }).toArray();
54925
+ } catch (error) {
54926
+ console.error("Error in category-preloved getAll:", error);
54927
+ throw error;
54928
+ }
54929
+ }
54930
+ return { getAll };
54931
+ }
54932
+
54933
+ // src/controllers/category-preloved.controller.ts
54934
+ var import_node_server_utils235 = require("@7365admin1/node-server-utils");
54935
+ var import_joi135 = __toESM(require("joi"));
54936
+ function useCategoryPrelovedController() {
54937
+ const { getAll: _getAll } = useCategoryPrelovedRepo();
54938
+ async function getAll(req, res, next) {
54939
+ const schema2 = import_joi135.default.object({
54940
+ search: import_joi135.default.string().optional().allow("", null),
54941
+ site: import_joi135.default.string().hex().length(24).optional().allow("", null)
54942
+ });
54943
+ const { error, value } = schema2.validate(req.query, { abortEarly: false });
54944
+ if (error) {
54945
+ const messages = error.details.map((d) => d.message).join(", ");
54946
+ import_node_server_utils235.logger.log({ level: "error", message: messages });
54947
+ next(new import_node_server_utils235.BadRequestError(messages));
54948
+ return;
54949
+ }
54950
+ try {
54951
+ const data = await _getAll(value);
54952
+ res.status(200).json({ data });
54953
+ return;
54954
+ } catch (error2) {
54955
+ import_node_server_utils235.logger.log({ level: "error", message: error2.message });
54956
+ next(error2);
54957
+ return;
54958
+ }
54959
+ }
54960
+ return { getAll };
54961
+ }
54962
+
54963
+ // src/models/subcategory-preloved.model.ts
54964
+ var import_joi136 = __toESM(require("joi"));
54965
+ var import_mongodb133 = require("mongodb");
54966
+ var schemaSubcategoryPreloved = import_joi136.default.object({
54967
+ name: import_joi136.default.string().required(),
54968
+ createdBy: import_joi136.default.string().hex().optional().allow("", null),
54969
+ site: import_joi136.default.string().hex().optional().allow("", null),
54970
+ category_id: import_joi136.default.string().hex().required()
54971
+ });
54972
+ var schemaUpdateSubcategoryPreloved = import_joi136.default.object({
54973
+ name: import_joi136.default.string().optional().allow("", null),
54974
+ site: import_joi136.default.string().hex().optional().allow("", null),
54975
+ category_id: import_joi136.default.string().hex().optional().allow("", null)
54976
+ });
54977
+ function MSubcategoryPreloved(value) {
54978
+ const { error } = schemaSubcategoryPreloved.validate(value);
54979
+ if (error) {
54980
+ throw new Error(error.details[0].message);
54981
+ }
54982
+ if (value.createdBy && typeof value.createdBy === "string") {
54983
+ try {
54984
+ value.createdBy = new import_mongodb133.ObjectId(value.createdBy);
54985
+ } catch {
54986
+ throw new Error("Invalid createdBy ID.");
54987
+ }
54988
+ }
54989
+ if (value.site && typeof value.site === "string") {
54990
+ try {
54991
+ value.site = new import_mongodb133.ObjectId(value.site);
54992
+ } catch {
54993
+ throw new Error("Invalid site ID.");
54994
+ }
54995
+ }
54996
+ if (value.category_id && typeof value.category_id === "string") {
54997
+ try {
54998
+ value.category_id = new import_mongodb133.ObjectId(value.category_id);
54999
+ } catch {
55000
+ throw new Error("Invalid category ID.");
55001
+ }
55002
+ }
55003
+ return {
55004
+ name: value.name ?? "",
55005
+ createdBy: value.createdBy ?? "",
55006
+ site: value.site ?? null,
55007
+ category_id: value.category_id ?? "",
55008
+ createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
55009
+ updatedAt: value.updatedAt ?? null
55010
+ };
55011
+ }
55012
+
55013
+ // src/repositories/subcategory-preloved.repo.ts
55014
+ var import_node_server_utils236 = require("@7365admin1/node-server-utils");
55015
+ var import_mongodb134 = require("mongodb");
55016
+ function useSubcategoryPrelovedRepo() {
55017
+ const db = import_node_server_utils236.useAtlas.getDb();
55018
+ if (!db) {
55019
+ throw new import_node_server_utils236.InternalServerError("Unable to connect to server.");
55020
+ }
55021
+ const SUBCATEGORY_COLLECTION = "subcategory-preloved";
55022
+ const collection = db.collection(SUBCATEGORY_COLLECTION);
55023
+ async function getAll({
55024
+ search = "",
55025
+ site,
55026
+ category_id
55027
+ } = {}) {
55028
+ if (site) {
55029
+ try {
55030
+ site = new import_mongodb134.ObjectId(site);
55031
+ } catch {
55032
+ throw new import_node_server_utils236.BadRequestError("Invalid site ID format.");
55033
+ }
55034
+ }
55035
+ if (category_id) {
55036
+ try {
55037
+ category_id = new import_mongodb134.ObjectId(category_id);
55038
+ } catch {
55039
+ throw new import_node_server_utils236.BadRequestError("Invalid category ID format.");
55040
+ }
55041
+ }
55042
+ const query = {
55043
+ ...site && { site },
55044
+ ...category_id && { category_id },
55045
+ ...search && { name: { $regex: search, $options: "i" } }
55046
+ };
55047
+ try {
55048
+ return await collection.find(query).sort({ name: 1 }).toArray();
55049
+ } catch (error) {
55050
+ throw error;
55051
+ }
55052
+ }
55053
+ return { getAll };
55054
+ }
55055
+
55056
+ // src/controllers/subcategory-preloved.controller.ts
55057
+ var import_node_server_utils237 = require("@7365admin1/node-server-utils");
55058
+ var import_joi137 = __toESM(require("joi"));
55059
+ function useSubcategoryPrelovedController() {
55060
+ const { getAll: _getAll } = useSubcategoryPrelovedRepo();
55061
+ async function getAll(req, res, next) {
55062
+ const schema2 = import_joi137.default.object({
55063
+ search: import_joi137.default.string().optional().allow("", null),
55064
+ site: import_joi137.default.string().hex().length(24).optional().allow("", null),
55065
+ category_id: import_joi137.default.string().hex().length(24).optional().allow("", null)
55066
+ });
55067
+ const { error, value } = schema2.validate(req.query, { abortEarly: false });
55068
+ if (error) {
55069
+ const messages = error.details.map((d) => d.message).join(", ");
55070
+ import_node_server_utils237.logger.log({ level: "error", message: messages });
55071
+ next(new import_node_server_utils237.BadRequestError(messages));
55072
+ return;
55073
+ }
55074
+ try {
55075
+ const data = await _getAll(value);
55076
+ res.status(200).json({ data });
55077
+ return;
55078
+ } catch (error2) {
55079
+ import_node_server_utils237.logger.log({ level: "error", message: error2.message });
55080
+ next(error2);
55081
+ return;
55082
+ }
55083
+ }
55084
+ return { getAll };
55085
+ }
55086
+
55087
+ // src/models/online-forms-v2.model.ts
55088
+ var import_joi138 = __toESM(require("joi"));
55089
+ var import_mongodb135 = require("mongodb");
54813
55090
  var FormEntryStatus = /* @__PURE__ */ ((FormEntryStatus2) => {
54814
55091
  FormEntryStatus2["ACTIVE"] = "active";
54815
55092
  FormEntryStatus2["INACTIVE"] = "inactive";
54816
55093
  FormEntryStatus2["DELETED"] = "deleted";
54817
55094
  return FormEntryStatus2;
54818
55095
  })(FormEntryStatus || {});
54819
- var schemaFormEntry = import_joi134.default.object({
54820
- _id: import_joi134.default.string().hex().optional().allow("", null),
54821
- formType: import_joi134.default.string().required(),
54822
- fields: import_joi134.default.object().pattern(
54823
- import_joi134.default.string(),
54824
- import_joi134.default.alternatives().try(
54825
- import_joi134.default.string(),
54826
- import_joi134.default.number(),
54827
- import_joi134.default.boolean(),
54828
- import_joi134.default.valid(null)
55096
+ var schemaFormEntry = import_joi138.default.object({
55097
+ _id: import_joi138.default.string().hex().optional().allow("", null),
55098
+ formType: import_joi138.default.string().required(),
55099
+ fields: import_joi138.default.object().pattern(
55100
+ import_joi138.default.string(),
55101
+ import_joi138.default.alternatives().try(
55102
+ import_joi138.default.string(),
55103
+ import_joi138.default.number(),
55104
+ import_joi138.default.boolean(),
55105
+ import_joi138.default.valid(null)
54829
55106
  )
54830
55107
  ).required(),
54831
- status: import_joi134.default.string().optional().allow("", null),
54832
- org: import_joi134.default.string().hex().optional().allow("", null),
54833
- site: import_joi134.default.string().hex().optional().allow("", null),
54834
- createdAt: import_joi134.default.date().optional().allow("", null),
54835
- updatedAt: import_joi134.default.date().optional().allow("", null),
54836
- deletedAt: import_joi134.default.date().optional().allow("", null)
55108
+ status: import_joi138.default.string().optional().allow("", null),
55109
+ org: import_joi138.default.string().hex().optional().allow("", null),
55110
+ site: import_joi138.default.string().hex().optional().allow("", null),
55111
+ createdAt: import_joi138.default.date().optional().allow("", null),
55112
+ updatedAt: import_joi138.default.date().optional().allow("", null),
55113
+ deletedAt: import_joi138.default.date().optional().allow("", null)
54837
55114
  });
54838
- var schemaUpdateFormEntry = import_joi134.default.object({
54839
- _id: import_joi134.default.string().hex().required(),
54840
- formType: import_joi134.default.string().optional().allow("", null),
54841
- fields: import_joi134.default.object().pattern(
54842
- import_joi134.default.string(),
54843
- import_joi134.default.alternatives().try(
54844
- import_joi134.default.string(),
54845
- import_joi134.default.number(),
54846
- import_joi134.default.boolean(),
54847
- import_joi134.default.valid(null)
55115
+ var schemaUpdateFormEntry = import_joi138.default.object({
55116
+ _id: import_joi138.default.string().hex().required(),
55117
+ formType: import_joi138.default.string().optional().allow("", null),
55118
+ fields: import_joi138.default.object().pattern(
55119
+ import_joi138.default.string(),
55120
+ import_joi138.default.alternatives().try(
55121
+ import_joi138.default.string(),
55122
+ import_joi138.default.number(),
55123
+ import_joi138.default.boolean(),
55124
+ import_joi138.default.valid(null)
54848
55125
  )
54849
55126
  ).optional(),
54850
- status: import_joi134.default.string().optional().allow("", null),
54851
- createdAt: import_joi134.default.date().optional().allow("", null),
54852
- updatedAt: import_joi134.default.date().optional().allow("", null),
54853
- deletedAt: import_joi134.default.date().optional().allow("", null)
55127
+ status: import_joi138.default.string().optional().allow("", null),
55128
+ createdAt: import_joi138.default.date().optional().allow("", null),
55129
+ updatedAt: import_joi138.default.date().optional().allow("", null),
55130
+ deletedAt: import_joi138.default.date().optional().allow("", null)
54854
55131
  });
54855
55132
  function MFormEntry(value) {
54856
55133
  const { error } = schemaFormEntry.validate(value);
@@ -54859,21 +55136,21 @@ function MFormEntry(value) {
54859
55136
  }
54860
55137
  if (value._id && typeof value._id === "string") {
54861
55138
  try {
54862
- value._id = new import_mongodb131.ObjectId(value._id);
55139
+ value._id = new import_mongodb135.ObjectId(value._id);
54863
55140
  } catch {
54864
55141
  throw new Error("Invalid ID.");
54865
55142
  }
54866
55143
  }
54867
55144
  if (value.org && typeof value.org === "string") {
54868
55145
  try {
54869
- value.org = new import_mongodb131.ObjectId(value.org);
55146
+ value.org = new import_mongodb135.ObjectId(value.org);
54870
55147
  } catch {
54871
55148
  throw new Error("Invalid org ID.");
54872
55149
  }
54873
55150
  }
54874
55151
  if (value.site && typeof value.site === "string") {
54875
55152
  try {
54876
- value.site = new import_mongodb131.ObjectId(value.site);
55153
+ value.site = new import_mongodb135.ObjectId(value.site);
54877
55154
  } catch {
54878
55155
  throw new Error("Invalid site ID.");
54879
55156
  }
@@ -54892,15 +55169,15 @@ function MFormEntry(value) {
54892
55169
  }
54893
55170
 
54894
55171
  // src/repositories/online-forms-v2.repository.ts
54895
- var import_node_server_utils234 = require("@7365admin1/node-server-utils");
55172
+ var import_node_server_utils238 = require("@7365admin1/node-server-utils");
54896
55173
  var online_forms_namespace_collection = "online-forms";
54897
55174
  function useFormEntryRepo() {
54898
- const db = import_node_server_utils234.useAtlas.getDb();
55175
+ const db = import_node_server_utils238.useAtlas.getDb();
54899
55176
  if (!db) {
54900
- throw new import_node_server_utils234.InternalServerError("Unable to connect to server.");
55177
+ throw new import_node_server_utils238.InternalServerError("Unable to connect to server.");
54901
55178
  }
54902
55179
  const collection = db.collection(online_forms_namespace_collection);
54903
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils234.useCache)(
55180
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils238.useCache)(
54904
55181
  online_forms_namespace_collection
54905
55182
  );
54906
55183
  async function createTextIndex() {
@@ -54909,7 +55186,7 @@ function useFormEntryRepo() {
54909
55186
  name: "text"
54910
55187
  });
54911
55188
  } catch (error) {
54912
- throw new import_node_server_utils234.InternalServerError(
55189
+ throw new import_node_server_utils238.InternalServerError(
54913
55190
  "Failed to create text index on online form."
54914
55191
  );
54915
55192
  }
@@ -54919,11 +55196,11 @@ function useFormEntryRepo() {
54919
55196
  value = MFormEntry(value);
54920
55197
  const res = await collection.insertOne(value, { session });
54921
55198
  delNamespace().then(() => {
54922
- import_node_server_utils234.logger.info(
55199
+ import_node_server_utils238.logger.info(
54923
55200
  `Cache cleared for namespace: ${online_forms_namespace_collection}`
54924
55201
  );
54925
55202
  }).catch((err) => {
54926
- import_node_server_utils234.logger.error(
55203
+ import_node_server_utils238.logger.error(
54927
55204
  `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
54928
55205
  err
54929
55206
  );
@@ -54932,7 +55209,7 @@ function useFormEntryRepo() {
54932
55209
  } catch (error) {
54933
55210
  const isDuplicated = error.message.includes("duplicate");
54934
55211
  if (isDuplicated) {
54935
- throw new import_node_server_utils234.BadRequestError("Online Form already exists.");
55212
+ throw new import_node_server_utils238.BadRequestError("Online Form already exists.");
54936
55213
  }
54937
55214
  throw error;
54938
55215
  }
@@ -54944,7 +55221,7 @@ function useFormEntryRepo() {
54944
55221
  }
54945
55222
 
54946
55223
  // src/controllers/online-forms-v2.controller.ts
54947
- var import_node_server_utils235 = require("@7365admin1/node-server-utils");
55224
+ var import_node_server_utils239 = require("@7365admin1/node-server-utils");
54948
55225
  var import_exceljs3 = __toESM(require("exceljs"));
54949
55226
  var import_fs6 = __toESM(require("fs"));
54950
55227
  function useFormEntryController() {
@@ -54962,14 +55239,14 @@ function useFormEntryController() {
54962
55239
  async function uploadFormEntrys(req, res, next) {
54963
55240
  try {
54964
55241
  if (!req.file) {
54965
- next(new import_node_server_utils235.BadRequestError("Excel file is required."));
55242
+ next(new import_node_server_utils239.BadRequestError("Excel file is required."));
54966
55243
  return;
54967
55244
  }
54968
55245
  const workbook = new import_exceljs3.default.Workbook();
54969
55246
  await workbook.xlsx.readFile(req.file.path);
54970
55247
  const worksheet = workbook.worksheets[0];
54971
55248
  if (!worksheet) {
54972
- next(new import_node_server_utils235.BadRequestError("No worksheet found in uploaded Excel file."));
55249
+ next(new import_node_server_utils239.BadRequestError("No worksheet found in uploaded Excel file."));
54973
55250
  return;
54974
55251
  }
54975
55252
  const headerRow = worksheet.getRow(1);
@@ -54990,8 +55267,8 @@ function useFormEntryController() {
54990
55267
  });
54991
55268
  if (error) {
54992
55269
  const messages = error.details.map((d) => d.message).join(", ");
54993
- import_node_server_utils235.logger.log({ level: "error", message: messages });
54994
- next(new import_node_server_utils235.BadRequestError(messages));
55270
+ import_node_server_utils239.logger.log({ level: "error", message: messages });
55271
+ next(new import_node_server_utils239.BadRequestError(messages));
54995
55272
  return;
54996
55273
  }
54997
55274
  const result = await _add(value);
@@ -54999,7 +55276,7 @@ function useFormEntryController() {
54999
55276
  import_fs6.default.unlink(req.file.path, () => {
55000
55277
  });
55001
55278
  } catch (error) {
55002
- import_node_server_utils235.logger.log({ level: "error", message: error.message });
55279
+ import_node_server_utils239.logger.log({ level: "error", message: error.message });
55003
55280
  next(error);
55004
55281
  }
55005
55282
  }
@@ -55007,11 +55284,282 @@ function useFormEntryController() {
55007
55284
  uploadFormEntrys
55008
55285
  };
55009
55286
  }
55287
+
55288
+ // src/models/building-level.model.ts
55289
+ var import_node_server_utils240 = require("@7365admin1/node-server-utils");
55290
+ var import_mongodb136 = require("mongodb");
55291
+ var import_joi139 = __toESM(require("joi"));
55292
+ var import_node_server_utils241 = require("@7365admin1/node-server-utils");
55293
+ var BuildingLevelStatus = /* @__PURE__ */ ((BuildingLevelStatus2) => {
55294
+ BuildingLevelStatus2["ACTIVE"] = "active";
55295
+ BuildingLevelStatus2["DELETED"] = "deleted";
55296
+ return BuildingLevelStatus2;
55297
+ })(BuildingLevelStatus || {});
55298
+ var schemaBuildingLevel = import_joi139.default.object({
55299
+ org: import_joi139.default.string().hex().optional(),
55300
+ site: import_joi139.default.string().hex().optional(),
55301
+ blockId: import_joi139.default.string().hex().optional(),
55302
+ name: import_joi139.default.string().optional(),
55303
+ status: import_joi139.default.string().valid(...Object.values(BuildingLevelStatus)).optional(),
55304
+ createdAt: import_joi139.default.date().optional(),
55305
+ updatedAt: import_joi139.default.date().optional().allow(null),
55306
+ deletedAt: import_joi139.default.date().optional().allow(null)
55307
+ });
55308
+ function MBuildingLevel(value) {
55309
+ const { error } = schemaBuildingLevel.validate(value);
55310
+ if (error) {
55311
+ import_node_server_utils241.logger.info(`Building Level Model: ${error.message}`);
55312
+ throw new import_node_server_utils240.BadRequestError(error.message);
55313
+ }
55314
+ if (value.org && typeof value.org === "string") {
55315
+ try {
55316
+ value.org = new import_mongodb136.ObjectId(value.org);
55317
+ } catch {
55318
+ throw new import_node_server_utils240.BadRequestError("Invalid org ID format");
55319
+ }
55320
+ }
55321
+ if (value.site && typeof value.site === "string") {
55322
+ try {
55323
+ value.site = new import_mongodb136.ObjectId(value.site);
55324
+ } catch {
55325
+ throw new import_node_server_utils240.BadRequestError("Invalid site ID format");
55326
+ }
55327
+ }
55328
+ if (value.blockId && typeof value.blockId === "string") {
55329
+ try {
55330
+ value.blockId = new import_mongodb136.ObjectId(value.blockId);
55331
+ } catch {
55332
+ throw new import_node_server_utils240.BadRequestError("Invalid block ID format");
55333
+ }
55334
+ }
55335
+ return {
55336
+ _id: new import_mongodb136.ObjectId(),
55337
+ org: value.org ?? void 0,
55338
+ site: value.site ?? void 0,
55339
+ blockId: value.blockId ?? void 0,
55340
+ name: value.name ?? "",
55341
+ status: value.status ?? "active" /* ACTIVE */,
55342
+ createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
55343
+ updatedAt: value.updatedAt ?? null,
55344
+ deletedAt: value.deletedAt ?? null
55345
+ };
55346
+ }
55347
+
55348
+ // src/repositories/building-level.repository.ts
55349
+ var import_node_server_utils242 = require("@7365admin1/node-server-utils");
55350
+ var building_level_namespace_collection = "building-levels";
55351
+ function useBuildingLevelRepo() {
55352
+ const db = import_node_server_utils242.useAtlas.getDb();
55353
+ if (!db) {
55354
+ throw new Error("Unable to connect to server.");
55355
+ }
55356
+ const collection = db.collection(building_level_namespace_collection);
55357
+ const { getCache, setCache, delNamespace, delCache } = (0, import_node_server_utils242.useCache)(
55358
+ building_level_namespace_collection
55359
+ );
55360
+ function delCachedData() {
55361
+ delNamespace().then(() => {
55362
+ import_node_server_utils242.logger.log({
55363
+ level: "info",
55364
+ message: `Cache namespace cleared for ${building_level_namespace_collection}`
55365
+ });
55366
+ }).catch((err) => {
55367
+ import_node_server_utils242.logger.log({
55368
+ level: "error",
55369
+ message: `Failed to clear cache namespace for ${building_level_namespace_collection}: ${err.message}`
55370
+ });
55371
+ });
55372
+ }
55373
+ async function add(value, session) {
55374
+ try {
55375
+ value = MBuildingLevel(value);
55376
+ const res = await collection.insertOne(value, { session });
55377
+ delCachedData();
55378
+ return res.insertedId;
55379
+ } catch (error) {
55380
+ import_node_server_utils242.logger.log({
55381
+ level: "error",
55382
+ message: error.message
55383
+ });
55384
+ const isDuplicated = error.message.includes("duplicate");
55385
+ if (isDuplicated) {
55386
+ throw new import_node_server_utils242.BadRequestError("Building unit already exists.");
55387
+ }
55388
+ if (error instanceof import_node_server_utils242.AppError) {
55389
+ throw error;
55390
+ } else {
55391
+ throw new Error("Failed to create building unit.");
55392
+ }
55393
+ }
55394
+ }
55395
+ async function getAll({
55396
+ search = "",
55397
+ page = 1,
55398
+ limit = 10,
55399
+ sort = {},
55400
+ site = "",
55401
+ status = "active"
55402
+ } = {}) {
55403
+ page = page > 0 ? page - 1 : 0;
55404
+ const query = {
55405
+ status,
55406
+ ...search && { $text: { $search: search } },
55407
+ ...site && { site: (0, import_node_server_utils242.toObjectId)(site) }
55408
+ };
55409
+ const cacheParams = {
55410
+ page,
55411
+ limit,
55412
+ sort: JSON.stringify(sort),
55413
+ ...search && { search },
55414
+ ...site && { site },
55415
+ ...status && { status }
55416
+ };
55417
+ const cacheKey = (0, import_node_server_utils242.makeCacheKey)(
55418
+ building_level_namespace_collection,
55419
+ cacheParams
55420
+ );
55421
+ import_node_server_utils242.logger.log({
55422
+ level: "info",
55423
+ message: `Cache key for getAll building units: ${cacheKey}`
55424
+ });
55425
+ try {
55426
+ const cached = await getCache(cacheKey);
55427
+ if (cached) {
55428
+ import_node_server_utils242.logger.log({
55429
+ level: "info",
55430
+ message: `Cache hit for getAll building units: ${cacheKey}`
55431
+ });
55432
+ return cached;
55433
+ }
55434
+ const sortStage = Object.keys(sort).length > 0 ? { $sort: sort } : { $sort: { latestDate: -1 } };
55435
+ const items = await collection.aggregate([
55436
+ { $match: query },
55437
+ {
55438
+ $addFields: {
55439
+ latestDate: { $max: ["$updatedAt", "$createdAt"] }
55440
+ }
55441
+ },
55442
+ sortStage,
55443
+ { $unset: "latestDate" },
55444
+ { $skip: page * limit },
55445
+ { $limit: limit }
55446
+ ]).toArray();
55447
+ const length = await collection.countDocuments(query);
55448
+ const data = (0, import_node_server_utils242.paginate)(items, page, limit, length);
55449
+ setCache(cacheKey, data, 600).then(() => {
55450
+ import_node_server_utils242.logger.log({
55451
+ level: "info",
55452
+ message: `Cache set for getAll building units: ${cacheKey}`
55453
+ });
55454
+ }).catch((err) => {
55455
+ import_node_server_utils242.logger.log({
55456
+ level: "error",
55457
+ message: `Failed to set cache for getAll building units: ${err.message}`
55458
+ });
55459
+ });
55460
+ return data;
55461
+ } catch (error) {
55462
+ console.log(error);
55463
+ import_node_server_utils242.logger.log({ level: "error", message: `${error}` });
55464
+ throw error;
55465
+ }
55466
+ }
55467
+ return {
55468
+ // createIndexes,
55469
+ add,
55470
+ getAll
55471
+ };
55472
+ }
55473
+
55474
+ // src/services/building-level.service.ts
55475
+ var import_node_server_utils243 = require("@7365admin1/node-server-utils");
55476
+ function useBuildingLevelService() {
55477
+ const { add: _add } = useBuildingLevelRepo();
55478
+ async function add(value) {
55479
+ const session = import_node_server_utils243.useAtlas.getClient()?.startSession();
55480
+ try {
55481
+ session?.startTransaction();
55482
+ await _add(value, session);
55483
+ await session?.commitTransaction();
55484
+ return "Successfully added building level.";
55485
+ } catch (error) {
55486
+ await session?.abortTransaction();
55487
+ throw error;
55488
+ } finally {
55489
+ session?.endSession();
55490
+ }
55491
+ }
55492
+ return {
55493
+ add
55494
+ };
55495
+ }
55496
+
55497
+ // src/controllers/building-level.controller.ts
55498
+ var import_node_server_utils244 = require("@7365admin1/node-server-utils");
55499
+ var import_joi140 = __toESM(require("joi"));
55500
+ function useBuildingLevelController() {
55501
+ const { add: _add } = useBuildingLevelService();
55502
+ const { getAll: _getAll } = useBuildingLevelRepo();
55503
+ async function add(req, res, next) {
55504
+ try {
55505
+ const { error, value } = schemaBuildingLevel.validate(req.body, {
55506
+ abortEarly: false
55507
+ });
55508
+ if (error) {
55509
+ const messages = error.details.map((d) => d.message).join(", ");
55510
+ import_node_server_utils244.logger.log({ level: "error", message: messages });
55511
+ next(new import_node_server_utils244.BadRequestError(messages));
55512
+ return;
55513
+ }
55514
+ const result = await _add(value);
55515
+ res.status(201).json(result);
55516
+ } catch (error) {
55517
+ next(error);
55518
+ }
55519
+ }
55520
+ async function getAll(req, res, next) {
55521
+ try {
55522
+ const validation = import_joi140.default.object({
55523
+ page: import_joi140.default.number().min(1).optional().default(1),
55524
+ limit: import_joi140.default.number().min(1).optional().default(20),
55525
+ search: import_joi140.default.string().optional().allow("", null),
55526
+ site: import_joi140.default.string().hex().length(24).optional().allow("", null),
55527
+ status: import_joi140.default.string().valid(...Object.values(BuildingLevelStatus)).default("active" /* ACTIVE */)
55528
+ });
55529
+ const { error, value } = validation.validate(req.query, {
55530
+ abortEarly: false
55531
+ });
55532
+ if (error) {
55533
+ const messages = error.details.map((d) => d.message);
55534
+ import_node_server_utils244.logger.log({ level: "error", message: messages.join(", ") });
55535
+ next(new import_node_server_utils244.BadRequestError(messages.join(", ")));
55536
+ return;
55537
+ }
55538
+ const { page, limit, status, site, search } = value;
55539
+ const result = await _getAll({
55540
+ page,
55541
+ limit,
55542
+ status,
55543
+ site,
55544
+ search
55545
+ });
55546
+ res.json(result);
55547
+ return;
55548
+ } catch (error) {
55549
+ next(error);
55550
+ }
55551
+ }
55552
+ return {
55553
+ add,
55554
+ getAll
55555
+ };
55556
+ }
55010
55557
  // Annotate the CommonJS export names for ESM import in node:
55011
55558
  0 && (module.exports = {
55012
55559
  ANPRMode,
55013
55560
  AccessTypeProps,
55014
55561
  AppServiceType,
55562
+ BuildingLevelStatus,
55015
55563
  BuildingStatus,
55016
55564
  BulletinOrder,
55017
55565
  BulletinRecipient,
@@ -55045,9 +55593,11 @@ function useFormEntryController() {
55045
55593
  MBillingConfiguration,
55046
55594
  MBillingItem,
55047
55595
  MBuilding,
55596
+ MBuildingLevel,
55048
55597
  MBuildingUnit,
55049
55598
  MBulletinBoard,
55050
55599
  MBulletinVideo,
55600
+ MCategoryPreloved,
55051
55601
  MChat,
55052
55602
  MCustomer,
55053
55603
  MCustomerSite,
@@ -55093,6 +55643,7 @@ function useFormEntryController() {
55093
55643
  MSiteFacility,
55094
55644
  MSiteFacilityBooking,
55095
55645
  MStatementOfAccount,
55646
+ MSubcategoryPreloved,
55096
55647
  MSubscription,
55097
55648
  MUnitBilling,
55098
55649
  MUser,
@@ -55140,6 +55691,7 @@ function useFormEntryController() {
55140
55691
  allowedNatures,
55141
55692
  attendanceSchema,
55142
55693
  attendanceSettingsSchema,
55694
+ building_level_namespace_collection,
55143
55695
  building_units_namespace_collection,
55144
55696
  buildings_namespace_collection,
55145
55697
  bulletin_boards_namespace_collection,
@@ -55184,10 +55736,12 @@ function useFormEntryController() {
55184
55736
  schemaBillingConfiguration,
55185
55737
  schemaBillingItem,
55186
55738
  schemaBuilding,
55739
+ schemaBuildingLevel,
55187
55740
  schemaBuildingUnit,
55188
55741
  schemaBuildingUpdateOptions,
55189
55742
  schemaBulletinBoard,
55190
55743
  schemaBulletinVideo,
55744
+ schemaCategoryPreloved,
55191
55745
  schemaCustomerSite,
55192
55746
  schemaDocumentManagement,
55193
55747
  schemaEntryPassSettings,
@@ -55218,9 +55772,11 @@ function useFormEntryController() {
55218
55772
  schemaSiteFacility,
55219
55773
  schemaSiteFacilityBooking,
55220
55774
  schemaStatementOfAccount,
55775
+ schemaSubcategoryPreloved,
55221
55776
  schemaUnitBilling,
55222
55777
  schemaUpdateBulletinBoard,
55223
55778
  schemaUpdateBulletinVideo,
55779
+ schemaUpdateCategoryPreloved,
55224
55780
  schemaUpdateDocumentManagement,
55225
55781
  schemaUpdateEntryPassSettings,
55226
55782
  schemaUpdateEventManagement,
@@ -55246,6 +55802,7 @@ function useFormEntryController() {
55246
55802
  schemaUpdateSiteFacilityBooking,
55247
55803
  schemaUpdateSiteUnitBilling,
55248
55804
  schemaUpdateStatementOfAccount,
55805
+ schemaUpdateSubcategoryPreloved,
55249
55806
  schemaUpdateVisTrans,
55250
55807
  schemaVehicleTransaction,
55251
55808
  schemaVisitorTransaction,
@@ -55271,6 +55828,9 @@ function useFormEntryController() {
55271
55828
  useAuthService,
55272
55829
  useAuthServiceV2,
55273
55830
  useBuildingController,
55831
+ useBuildingLevelController,
55832
+ useBuildingLevelRepo,
55833
+ useBuildingLevelService,
55274
55834
  useBuildingRepo,
55275
55835
  useBuildingService,
55276
55836
  useBuildingUnitController,
@@ -55282,6 +55842,8 @@ function useFormEntryController() {
55282
55842
  useBulletinVideoController,
55283
55843
  useBulletinVideoRepo,
55284
55844
  useBulletinVideoService,
55845
+ useCategoryPrelovedController,
55846
+ useCategoryPrelovedRepo,
55285
55847
  useChatController,
55286
55848
  useChatRepo,
55287
55849
  useCounterModel,
@@ -55419,6 +55981,8 @@ function useFormEntryController() {
55419
55981
  useSiteUnitBillingService,
55420
55982
  useStatementOfAccountController,
55421
55983
  useStatementOfAccountRepo,
55984
+ useSubcategoryPrelovedController,
55985
+ useSubcategoryPrelovedRepo,
55422
55986
  useSubscriptionController,
55423
55987
  useSubscriptionRepo,
55424
55988
  useSubscriptionService,