@7365admin1/core 3.1.0 → 3.3.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
@@ -6064,6 +6064,7 @@ __export(src_exports, {
6064
6064
  poolDashboardCollection: () => poolDashboardCollection,
6065
6065
  promoCodeSchema: () => promoCodeSchema,
6066
6066
  remarksSchema: () => remarksSchema,
6067
+ residentFormEntry: () => residentFormEntry,
6067
6068
  robotSchema: () => robotSchema,
6068
6069
  schema: () => schema,
6069
6070
  schemaApprovedBy: () => schemaApprovedBy,
@@ -25443,6 +25444,9 @@ function useBuildingUnitRepo() {
25443
25444
  }
25444
25445
  const collection = db.collection(building_units_namespace_collection);
25445
25446
  const visitorCollection = db.collection(visitors_namespace_collection);
25447
+ const buildingUnitCollection = db.collection(
25448
+ site_people_namespace_collection
25449
+ );
25446
25450
  const { getCache, setCache, delNamespace, delCache } = (0, import_node_server_utils76.useCache)(
25447
25451
  building_units_namespace_collection
25448
25452
  );
@@ -25524,10 +25528,8 @@ function useBuildingUnitRepo() {
25524
25528
  } catch (error2) {
25525
25529
  throw new import_node_server_utils76.BadRequestError("Invalid ID.");
25526
25530
  }
25527
- try {
25531
+ if (value.level) {
25528
25532
  value.level = new import_mongodb47.ObjectId(value.level);
25529
- } catch (error2) {
25530
- throw new import_node_server_utils76.BadRequestError("Invalid level ID.");
25531
25533
  }
25532
25534
  if (value.billing && Array.isArray(value.billing)) {
25533
25535
  value.billing = value.billing.map((billing) => {
@@ -25975,6 +25977,12 @@ function useBuildingUnitRepo() {
25975
25977
  throw new import_node_server_utils76.BadRequestError("Invalid ID.");
25976
25978
  }
25977
25979
  try {
25980
+ const existingResidents = await buildingUnitCollection.find({ unit: _id }).toArray();
25981
+ if (existingResidents && existingResidents.length > 0) {
25982
+ throw new import_node_server_utils76.BadRequestError(
25983
+ `Cannot delete unit: ${existingResidents.length} resident/s is currently assigned.`
25984
+ );
25985
+ }
25978
25986
  const res = await collection.updateOne(
25979
25987
  { _id },
25980
25988
  { $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } },
@@ -27803,24 +27811,30 @@ function useBuildingRepo() {
27803
27811
  }
27804
27812
  }
27805
27813
  async function updateById(_id, value, session) {
27806
- const { error } = schemaBuildingUpdateOptions.validate(value);
27807
- if (error) {
27808
- import_node_server_utils83.logger.info(`Building Repository: ${error.message}`);
27809
- throw new import_node_server_utils83.BadRequestError(error.message);
27810
- }
27811
27814
  try {
27812
- _id = new import_mongodb50.ObjectId(_id);
27813
- } catch (error2) {
27814
- throw new import_node_server_utils83.BadRequestError("Invalid ID.");
27815
- }
27816
- if (value.levels && Array.isArray(value.levels)) {
27815
+ const { error } = schemaBuildingUpdateOptions.validate(value);
27816
+ if (error) {
27817
+ import_node_server_utils83.logger.info(`Building Repository: ${error.message}`);
27818
+ throw new import_node_server_utils83.BadRequestError(error.message);
27819
+ }
27817
27820
  try {
27818
- value.levels = value.levels.map((lvl) => new import_mongodb50.ObjectId(lvl));
27819
- } catch {
27820
- throw new import_node_server_utils83.BadRequestError("Invalid level ID format.");
27821
+ _id = new import_mongodb50.ObjectId(_id);
27822
+ } catch (error2) {
27823
+ throw new import_node_server_utils83.BadRequestError("Invalid ID.");
27821
27824
  }
27822
- }
27823
- try {
27825
+ if (value.levels && Array.isArray(value.levels)) {
27826
+ try {
27827
+ value.levels = value.levels.map((lvl) => new import_mongodb50.ObjectId(lvl));
27828
+ } catch {
27829
+ throw new import_node_server_utils83.BadRequestError("Invalid level ID format.");
27830
+ }
27831
+ }
27832
+ if (value.name)
27833
+ await buildingUnitCollection.updateMany(
27834
+ { building: _id, status: "active" /* ACTIVE */ },
27835
+ { $set: { buildingName: value.name } },
27836
+ { session }
27837
+ );
27824
27838
  const res = await collection.updateOne(
27825
27839
  { _id },
27826
27840
  { $set: value },
@@ -27828,17 +27842,17 @@ function useBuildingRepo() {
27828
27842
  );
27829
27843
  delCachedData();
27830
27844
  return res;
27831
- } catch (error2) {
27845
+ } catch (error) {
27832
27846
  import_node_server_utils83.logger.log({
27833
27847
  level: "error",
27834
- message: error2.message
27848
+ message: error.message
27835
27849
  });
27836
- const isDuplicated = error2.message.includes("duplicate");
27850
+ const isDuplicated = error.message.includes("duplicate");
27837
27851
  if (isDuplicated) {
27838
27852
  throw new import_node_server_utils83.BadRequestError("Building already exists.");
27839
27853
  }
27840
- if (error2 instanceof import_node_server_utils83.AppError) {
27841
- throw error2;
27854
+ if (error instanceof import_node_server_utils83.AppError) {
27855
+ throw error;
27842
27856
  } else {
27843
27857
  throw new Error("Failed to update building.");
27844
27858
  }
@@ -28430,6 +28444,32 @@ function useBuildingLevelRepo() {
28430
28444
  const { delNamespace: delBuildingNamespace } = (0, import_node_server_utils86.useCache)(
28431
28445
  buildings_namespace_collection
28432
28446
  );
28447
+ async function createIndexes() {
28448
+ try {
28449
+ await collection.createIndexes([
28450
+ // Ensure name is unique per blockId
28451
+ {
28452
+ key: { blockId: 1, name: 1 },
28453
+ unique: true,
28454
+ name: "unique_name_per_blockId"
28455
+ },
28456
+ // Other useful indexes
28457
+ { key: { site: 1 }, name: "idx_site" },
28458
+ { key: { blockId: 1 }, name: "idx_blockId" },
28459
+ { key: { status: 1 }, name: "idx_status" },
28460
+ { key: { createdAt: 1 }, name: "idx_createdAt" },
28461
+ // Text index for search
28462
+ {
28463
+ key: {
28464
+ name: "text"
28465
+ },
28466
+ name: "text_search_index"
28467
+ }
28468
+ ]);
28469
+ } catch (error) {
28470
+ throw new Error("Failed to create indexes on building levels.");
28471
+ }
28472
+ }
28433
28473
  function delCachedData() {
28434
28474
  delNamespace().then(() => {
28435
28475
  import_node_server_utils86.logger.log({
@@ -28775,7 +28815,7 @@ function useBuildingLevelRepo() {
28775
28815
  }
28776
28816
  }
28777
28817
  return {
28778
- // createIndexes,
28818
+ createIndexes,
28779
28819
  add,
28780
28820
  getAll,
28781
28821
  getById,
@@ -35120,10 +35160,37 @@ function usePersonService() {
35120
35160
  session?.endSession();
35121
35161
  }
35122
35162
  }
35163
+ async function suspendResidentById(id) {
35164
+ const session = import_node_server_utils111.useAtlas.getClient()?.startSession();
35165
+ if (!session) {
35166
+ throw new import_node_server_utils111.BadRequestError("Database session not available.");
35167
+ }
35168
+ try {
35169
+ session.startTransaction();
35170
+ const person = await _getByUserId(id.toString());
35171
+ if (!person)
35172
+ throw new import_node_server_utils111.NotFoundError("Person not found.");
35173
+ await _updateById(person._id, { status: "deleted" }, session);
35174
+ if (person.user) {
35175
+ await _updateUserFieldById(
35176
+ { _id: person.user.toString(), field: "status", value: "suspended" },
35177
+ session
35178
+ );
35179
+ }
35180
+ await session.commitTransaction();
35181
+ return "Resident suspended successfully.";
35182
+ } catch (error) {
35183
+ await session.abortTransaction();
35184
+ throw error;
35185
+ } finally {
35186
+ session.endSession();
35187
+ }
35188
+ }
35123
35189
  return {
35124
35190
  add,
35125
35191
  updateById,
35126
- reviewResidentPerson
35192
+ reviewResidentPerson,
35193
+ suspendResidentById
35127
35194
  };
35128
35195
  }
35129
35196
 
@@ -35143,7 +35210,8 @@ function usePersonController() {
35143
35210
  const {
35144
35211
  add: _add,
35145
35212
  updateById: _updateById,
35146
- reviewResidentPerson: _reviewResidentPerson
35213
+ reviewResidentPerson: _reviewResidentPerson,
35214
+ suspendResidentById: _suspendResidentById
35147
35215
  } = usePersonService();
35148
35216
  async function add(req, res, next) {
35149
35217
  const payload = { ...req.body };
@@ -35487,6 +35555,26 @@ function usePersonController() {
35487
35555
  const result = await _reviewResidentPerson(_id, req.body);
35488
35556
  res.status(200).json({ message: result });
35489
35557
  return;
35558
+ } catch (error2) {
35559
+ console.log("error", error2.message);
35560
+ console.log("error", error2);
35561
+ import_node_server_utils112.logger.log({ level: "error", message: error2.message });
35562
+ next(error2);
35563
+ return;
35564
+ }
35565
+ }
35566
+ async function suspendResidentById(req, res, next) {
35567
+ const _id = req.params.id;
35568
+ const { error } = import_joi60.default.string().hex().required().validate(_id);
35569
+ if (error) {
35570
+ import_node_server_utils112.logger.log({ level: "error", message: error.message });
35571
+ next(new import_node_server_utils112.BadRequestError(error.message));
35572
+ return;
35573
+ }
35574
+ try {
35575
+ const result = await _suspendResidentById(_id);
35576
+ res.status(200).json({ message: result });
35577
+ return;
35490
35578
  } catch (error2) {
35491
35579
  import_node_server_utils112.logger.log({ level: "error", message: error2.message });
35492
35580
  next(error2);
@@ -35505,7 +35593,8 @@ function usePersonController() {
35505
35593
  getPeopleByPlateNumber,
35506
35594
  getPeopleByNRIC,
35507
35595
  getPersonByUserId,
35508
- reviewResidentPerson
35596
+ reviewResidentPerson,
35597
+ suspendResidentById
35509
35598
  };
35510
35599
  }
35511
35600
 
@@ -52947,9 +53036,9 @@ var affectedInjuredStatusSchema = import_joi101.default.object({
52947
53036
  contact: import_joi101.default.string().optional().allow(null, ""),
52948
53037
  nric: import_joi101.default.string().optional().allow(null, ""),
52949
53038
  remarks: import_joi101.default.string().optional().allow(null, ""),
52950
- block: import_joi101.default.number().optional().allow(null, ""),
52951
- level: import_joi101.default.string().optional().allow(null, ""),
52952
- unit: import_joi101.default.string().optional().allow(null, ""),
53039
+ block: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
53040
+ level: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
53041
+ unit: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
52953
53042
  incidentLocation: import_joi101.default.string().optional().allow(null, ""),
52954
53043
  isOther: import_joi101.default.boolean().optional().allow(null, ""),
52955
53044
  other: import_joi101.default.string().optional().allow(null, ""),
@@ -52957,9 +53046,9 @@ var affectedInjuredStatusSchema = import_joi101.default.object({
52957
53046
  });
52958
53047
  var anyoneDamageToPropertyStatusSchema = import_joi101.default.object({
52959
53048
  description: import_joi101.default.string().optional().allow(null, ""),
52960
- block: import_joi101.default.number().optional().allow(null, ""),
52961
- level: import_joi101.default.string().optional().allow(null, ""),
52962
- unit: import_joi101.default.string().optional().allow(null, ""),
53049
+ block: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
53050
+ level: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
53051
+ unit: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
52963
53052
  blkLevelUnit: import_joi101.default.string().optional().allow(null, ""),
52964
53053
  name: import_joi101.default.string().optional().allow(null, ""),
52965
53054
  contact: import_joi101.default.string().optional().allow(null, ""),
@@ -52982,9 +53071,9 @@ var schemaIncidentReport = import_joi101.default.object({
52982
53071
  submittedBy: import_joi101.default.string().optional().allow(null, "")
52983
53072
  }).required(),
52984
53073
  placeOfIncident: import_joi101.default.object({
52985
- block: import_joi101.default.number().optional().allow(null, ""),
52986
- level: import_joi101.default.string().optional().allow(null, ""),
52987
- unit: import_joi101.default.string().optional().allow(null, ""),
53074
+ block: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
53075
+ level: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
53076
+ unit: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
52988
53077
  other: import_joi101.default.string().allow(null, "").optional().allow(null, ""),
52989
53078
  isOther: import_joi101.default.boolean().required(),
52990
53079
  incidentLocation: import_joi101.default.string().optional().allow(null, "")
@@ -53063,9 +53152,9 @@ var schemaUpdateIncidentReport = import_joi101.default.object({
53063
53152
  submittedBy: import_joi101.default.string().optional().allow(null, "")
53064
53153
  }).allow(null, ""),
53065
53154
  placeOfIncident: import_joi101.default.object({
53066
- block: import_joi101.default.number().optional().allow(null, ""),
53067
- level: import_joi101.default.string().optional().allow(null, ""),
53068
- unit: import_joi101.default.string().optional().allow(null, ""),
53155
+ block: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
53156
+ level: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
53157
+ unit: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
53069
53158
  other: import_joi101.default.string().allow(null, "").optional().allow(null, ""),
53070
53159
  isOther: import_joi101.default.boolean().allow(null, ""),
53071
53160
  incidentLocation: import_joi101.default.string().optional().allow(null, "")
@@ -53173,6 +53262,82 @@ function MIncidentReport(value) {
53173
53262
  throw new Error("Invalid siteInfo.site ID.");
53174
53263
  }
53175
53264
  }
53265
+ const placeOfIncident = incidentInformation?.placeOfIncident;
53266
+ if (placeOfIncident) {
53267
+ if (placeOfIncident.block && typeof placeOfIncident.block === "string") {
53268
+ try {
53269
+ placeOfIncident.block = new import_mongodb109.ObjectId(placeOfIncident.block);
53270
+ } catch {
53271
+ throw new Error("Invalid placeOfIncident.block ID.");
53272
+ }
53273
+ }
53274
+ if (placeOfIncident.level && typeof placeOfIncident.level === "string") {
53275
+ try {
53276
+ placeOfIncident.level = new import_mongodb109.ObjectId(placeOfIncident.level);
53277
+ } catch {
53278
+ throw new Error("Invalid placeOfIncident.level ID.");
53279
+ }
53280
+ }
53281
+ if (placeOfIncident.unit && typeof placeOfIncident.unit === "string") {
53282
+ try {
53283
+ placeOfIncident.unit = new import_mongodb109.ObjectId(placeOfIncident.unit);
53284
+ } catch {
53285
+ throw new Error("Invalid placeOfIncident.unit ID.");
53286
+ }
53287
+ }
53288
+ }
53289
+ const affectedInjured = value.affectedEntities?.affectedInjured;
53290
+ if (Array.isArray(affectedInjured)) {
53291
+ affectedInjured.forEach((item) => {
53292
+ if (item.block && typeof item.block === "string") {
53293
+ try {
53294
+ item.block = new import_mongodb109.ObjectId(item.block);
53295
+ } catch {
53296
+ throw new Error("Invalid affectedInjured.block ID.");
53297
+ }
53298
+ }
53299
+ if (item.level && typeof item.level === "string") {
53300
+ try {
53301
+ item.level = new import_mongodb109.ObjectId(item.level);
53302
+ } catch {
53303
+ throw new Error("Invalid affectedInjured.level ID.");
53304
+ }
53305
+ }
53306
+ if (item.unit && typeof item.unit === "string") {
53307
+ try {
53308
+ item.unit = new import_mongodb109.ObjectId(item.unit);
53309
+ } catch {
53310
+ throw new Error("Invalid affectedInjured.unit ID.");
53311
+ }
53312
+ }
53313
+ });
53314
+ }
53315
+ const anyoneDamageToProperty = value.affectedEntities?.anyoneDamageToProperty;
53316
+ if (Array.isArray(anyoneDamageToProperty)) {
53317
+ anyoneDamageToProperty.forEach((item) => {
53318
+ if (item.block && typeof item.block === "string") {
53319
+ try {
53320
+ item.block = new import_mongodb109.ObjectId(item.block);
53321
+ } catch {
53322
+ throw new Error("Invalid anyoneDamageToProperty.block ID.");
53323
+ }
53324
+ }
53325
+ if (item.level && typeof item.level === "string") {
53326
+ try {
53327
+ item.level = new import_mongodb109.ObjectId(item.level);
53328
+ } catch {
53329
+ throw new Error("Invalid anyoneDamageToProperty.level ID.");
53330
+ }
53331
+ }
53332
+ if (item.unit && typeof item.unit === "string") {
53333
+ try {
53334
+ item.unit = new import_mongodb109.ObjectId(item.unit);
53335
+ } catch {
53336
+ throw new Error("Invalid anyoneDamageToProperty.unit ID.");
53337
+ }
53338
+ }
53339
+ });
53340
+ }
53176
53341
  if (incidentInformation?.incidentTypeAndTime?.dateOfIncident && typeof incidentInformation.incidentTypeAndTime.dateOfIncident !== "string") {
53177
53342
  incidentInformation.incidentTypeAndTime.dateOfIncident = incidentInformation.incidentTypeAndTime.dateOfIncident.toISOString();
53178
53343
  }
@@ -53193,7 +53358,7 @@ function MIncidentReport(value) {
53193
53358
  approvedByName: value.approvedByName ?? "",
53194
53359
  remarks: value.remarks ?? null,
53195
53360
  status: value.status ?? "pending",
53196
- platForm: value.platform ?? "",
53361
+ platform: value.platform ?? "",
53197
53362
  createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
53198
53363
  updatedAt: value.updatedAt,
53199
53364
  deletedAt: value.deletedAt
@@ -53508,6 +53673,82 @@ function useIncidentReportRepo() {
53508
53673
  throw new Error("Invalid siteInfo.site ID.");
53509
53674
  }
53510
53675
  }
53676
+ const placeOfIncident = incidentInformation?.placeOfIncident;
53677
+ if (placeOfIncident) {
53678
+ if (placeOfIncident.block && typeof placeOfIncident.block === "string") {
53679
+ try {
53680
+ placeOfIncident.block = new import_mongodb110.ObjectId(placeOfIncident.block);
53681
+ } catch {
53682
+ throw new Error("Invalid placeOfIncident.block ID.");
53683
+ }
53684
+ }
53685
+ if (placeOfIncident.level && typeof placeOfIncident.level === "string") {
53686
+ try {
53687
+ placeOfIncident.level = new import_mongodb110.ObjectId(placeOfIncident.level);
53688
+ } catch {
53689
+ throw new Error("Invalid placeOfIncident.level ID.");
53690
+ }
53691
+ }
53692
+ if (placeOfIncident.unit && typeof placeOfIncident.unit === "string") {
53693
+ try {
53694
+ placeOfIncident.unit = new import_mongodb110.ObjectId(placeOfIncident.unit);
53695
+ } catch {
53696
+ throw new Error("Invalid placeOfIncident.unit ID.");
53697
+ }
53698
+ }
53699
+ }
53700
+ const affectedInjured = value.affectedEntities?.affectedInjured;
53701
+ if (Array.isArray(affectedInjured)) {
53702
+ affectedInjured.forEach((item) => {
53703
+ if (item.block && typeof item.block === "string") {
53704
+ try {
53705
+ item.block = new import_mongodb110.ObjectId(item.block);
53706
+ } catch {
53707
+ throw new Error("Invalid affectedInjured.block ID.");
53708
+ }
53709
+ }
53710
+ if (item.level && typeof item.level === "string") {
53711
+ try {
53712
+ item.level = new import_mongodb110.ObjectId(item.level);
53713
+ } catch {
53714
+ throw new Error("Invalid affectedInjured.level ID.");
53715
+ }
53716
+ }
53717
+ if (item.unit && typeof item.unit === "string") {
53718
+ try {
53719
+ item.unit = new import_mongodb110.ObjectId(item.unit);
53720
+ } catch {
53721
+ throw new Error("Invalid affectedInjured.unit ID.");
53722
+ }
53723
+ }
53724
+ });
53725
+ }
53726
+ const anyoneDamageToProperty = value.affectedEntities?.anyoneDamageToProperty;
53727
+ if (Array.isArray(anyoneDamageToProperty)) {
53728
+ anyoneDamageToProperty.forEach((item) => {
53729
+ if (item.block && typeof item.block === "string") {
53730
+ try {
53731
+ item.block = new import_mongodb110.ObjectId(item.block);
53732
+ } catch {
53733
+ throw new Error("Invalid anyoneDamageToProperty.block ID.");
53734
+ }
53735
+ }
53736
+ if (item.level && typeof item.level === "string") {
53737
+ try {
53738
+ item.level = new import_mongodb110.ObjectId(item.level);
53739
+ } catch {
53740
+ throw new Error("Invalid anyoneDamageToProperty.level ID.");
53741
+ }
53742
+ }
53743
+ if (item.unit && typeof item.unit === "string") {
53744
+ try {
53745
+ item.unit = new import_mongodb110.ObjectId(item.unit);
53746
+ } catch {
53747
+ throw new Error("Invalid anyoneDamageToProperty.unit ID.");
53748
+ }
53749
+ }
53750
+ });
53751
+ }
53511
53752
  try {
53512
53753
  const res = await collection.updateOne(
53513
53754
  { _id },
@@ -64839,6 +65080,26 @@ function MFormEntry(value) {
64839
65080
  deletedAt: value.deletedAt ?? null
64840
65081
  };
64841
65082
  }
65083
+ var residentFormEntry = import_joi144.default.object({
65084
+ _id: import_joi144.default.string().hex().optional().allow("", null),
65085
+ typeOfForm: import_joi144.default.string().required(),
65086
+ unitNumber: import_joi144.default.string().optional().allow(null, ""),
65087
+ fields: import_joi144.default.object().pattern(
65088
+ import_joi144.default.string(),
65089
+ import_joi144.default.alternatives().try(
65090
+ import_joi144.default.string(),
65091
+ import_joi144.default.number(),
65092
+ import_joi144.default.boolean(),
65093
+ import_joi144.default.valid(null)
65094
+ )
65095
+ ).required(),
65096
+ status: import_joi144.default.string().optional().allow("", null),
65097
+ org: import_joi144.default.string().hex().optional().allow("", null),
65098
+ site: import_joi144.default.string().hex().optional().allow("", null),
65099
+ createdAt: import_joi144.default.date().optional().allow("", null),
65100
+ updatedAt: import_joi144.default.date().optional().allow("", null),
65101
+ deletedAt: import_joi144.default.date().optional().allow("", null)
65102
+ });
64842
65103
 
64843
65104
  // src/repositories/online-forms-v2.repository.ts
64844
65105
  var import_node_server_utils249 = require("@7365admin1/node-server-utils");
@@ -65037,13 +65298,38 @@ function useFormEntryRepo() {
65037
65298
  throw new Error(error.message);
65038
65299
  }
65039
65300
  }
65301
+ async function addResidentForm(value, session) {
65302
+ try {
65303
+ value.site = new import_mongodb146.ObjectId(value.site);
65304
+ value.org = new import_mongodb146.ObjectId(value.org);
65305
+ const res = await collection.insertOne(value, { session });
65306
+ delNamespace().then(() => {
65307
+ import_node_server_utils249.logger.info(
65308
+ `Cache cleared for namespace: ${online_forms_namespace_collection}`
65309
+ );
65310
+ }).catch((err) => {
65311
+ import_node_server_utils249.logger.error(
65312
+ `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
65313
+ err
65314
+ );
65315
+ });
65316
+ return res.insertedId;
65317
+ } catch (error) {
65318
+ const isDuplicated = error.message.includes("duplicate");
65319
+ if (isDuplicated) {
65320
+ throw new import_node_server_utils249.BadRequestError("Online Form already exists.");
65321
+ }
65322
+ throw error;
65323
+ }
65324
+ }
65040
65325
  return {
65041
65326
  add,
65042
65327
  getAll,
65043
65328
  getFormEntryById,
65044
65329
  updateFormEntryById,
65045
65330
  createTextIndex,
65046
- deleteOnlineFormById
65331
+ deleteOnlineFormById,
65332
+ addResidentForm
65047
65333
  };
65048
65334
  }
65049
65335
 
@@ -65058,7 +65344,8 @@ function useFormEntryController() {
65058
65344
  getAll: _getAll,
65059
65345
  getFormEntryById: _getFormEntryById,
65060
65346
  updateFormEntryById: _updateFormEntryById,
65061
- deleteOnlineFormById: _deleteOnlineFormById
65347
+ deleteOnlineFormById: _deleteOnlineFormById,
65348
+ addResidentForm: _addResidentForm
65062
65349
  } = useFormEntryRepo();
65063
65350
  function toCamelCase(str) {
65064
65351
  return str.replace(/\s(.)/g, (_, char) => char.toUpperCase()).replace(/\s+/g, "").replace(/^(.)/, (_, char) => char.toLowerCase());
@@ -65237,13 +65524,35 @@ function useFormEntryController() {
65237
65524
  return;
65238
65525
  }
65239
65526
  }
65527
+ async function residentFormSubmission(req, res, next) {
65528
+ const payload = { ...req.body };
65529
+ const { error } = residentFormEntry.validate(payload, {
65530
+ abortEarly: false
65531
+ });
65532
+ if (error) {
65533
+ const messages = error.details.map((d) => d.message).join(", ");
65534
+ import_node_server_utils250.logger.log({ level: "error", message: messages });
65535
+ next(new import_node_server_utils250.BadRequestError(messages));
65536
+ return;
65537
+ }
65538
+ try {
65539
+ const data = await _addResidentForm(payload);
65540
+ res.status(201).json({ message: data });
65541
+ return;
65542
+ } catch (error2) {
65543
+ import_node_server_utils250.logger.log({ level: "error", message: error2.message });
65544
+ next(error2);
65545
+ return;
65546
+ }
65547
+ }
65240
65548
  return {
65241
65549
  add,
65242
65550
  uploadFormEntrys,
65243
65551
  getAll,
65244
65552
  getFormEntryById,
65245
65553
  updateFormEntryById,
65246
- deleteFormEntryById
65554
+ deleteFormEntryById,
65555
+ residentFormSubmission
65247
65556
  };
65248
65557
  }
65249
65558
 
@@ -65643,6 +65952,7 @@ function useBuildingLevelController() {
65643
65952
  poolDashboardCollection,
65644
65953
  promoCodeSchema,
65645
65954
  remarksSchema,
65955
+ residentFormEntry,
65646
65956
  robotSchema,
65647
65957
  schema,
65648
65958
  schemaApprovedBy,