@7365admin1/core 3.2.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.mjs CHANGED
@@ -35049,10 +35049,37 @@ function usePersonService() {
35049
35049
  session?.endSession();
35050
35050
  }
35051
35051
  }
35052
+ async function suspendResidentById(id) {
35053
+ const session = useAtlas53.getClient()?.startSession();
35054
+ if (!session) {
35055
+ throw new BadRequestError104("Database session not available.");
35056
+ }
35057
+ try {
35058
+ session.startTransaction();
35059
+ const person = await _getByUserId(id.toString());
35060
+ if (!person)
35061
+ throw new NotFoundError23("Person not found.");
35062
+ await _updateById(person._id, { status: "deleted" }, session);
35063
+ if (person.user) {
35064
+ await _updateUserFieldById(
35065
+ { _id: person.user.toString(), field: "status", value: "suspended" },
35066
+ session
35067
+ );
35068
+ }
35069
+ await session.commitTransaction();
35070
+ return "Resident suspended successfully.";
35071
+ } catch (error) {
35072
+ await session.abortTransaction();
35073
+ throw error;
35074
+ } finally {
35075
+ session.endSession();
35076
+ }
35077
+ }
35052
35078
  return {
35053
35079
  add,
35054
35080
  updateById,
35055
- reviewResidentPerson
35081
+ reviewResidentPerson,
35082
+ suspendResidentById
35056
35083
  };
35057
35084
  }
35058
35085
 
@@ -35072,7 +35099,8 @@ function usePersonController() {
35072
35099
  const {
35073
35100
  add: _add,
35074
35101
  updateById: _updateById,
35075
- reviewResidentPerson: _reviewResidentPerson
35102
+ reviewResidentPerson: _reviewResidentPerson,
35103
+ suspendResidentById: _suspendResidentById
35076
35104
  } = usePersonService();
35077
35105
  async function add(req, res, next) {
35078
35106
  const payload = { ...req.body };
@@ -35416,6 +35444,26 @@ function usePersonController() {
35416
35444
  const result = await _reviewResidentPerson(_id, req.body);
35417
35445
  res.status(200).json({ message: result });
35418
35446
  return;
35447
+ } catch (error2) {
35448
+ console.log("error", error2.message);
35449
+ console.log("error", error2);
35450
+ logger85.log({ level: "error", message: error2.message });
35451
+ next(error2);
35452
+ return;
35453
+ }
35454
+ }
35455
+ async function suspendResidentById(req, res, next) {
35456
+ const _id = req.params.id;
35457
+ const { error } = Joi60.string().hex().required().validate(_id);
35458
+ if (error) {
35459
+ logger85.log({ level: "error", message: error.message });
35460
+ next(new BadRequestError105(error.message));
35461
+ return;
35462
+ }
35463
+ try {
35464
+ const result = await _suspendResidentById(_id);
35465
+ res.status(200).json({ message: result });
35466
+ return;
35419
35467
  } catch (error2) {
35420
35468
  logger85.log({ level: "error", message: error2.message });
35421
35469
  next(error2);
@@ -35434,7 +35482,8 @@ function usePersonController() {
35434
35482
  getPeopleByPlateNumber,
35435
35483
  getPeopleByNRIC,
35436
35484
  getPersonByUserId,
35437
- reviewResidentPerson
35485
+ reviewResidentPerson,
35486
+ suspendResidentById
35438
35487
  };
35439
35488
  }
35440
35489
 
@@ -53411,7 +53460,7 @@ function MIncidentReport(value) {
53411
53460
  approvedByName: value.approvedByName ?? "",
53412
53461
  remarks: value.remarks ?? null,
53413
53462
  status: value.status ?? "pending",
53414
- platForm: value.platform ?? "",
53463
+ platform: value.platform ?? "",
53415
53464
  createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
53416
53465
  updatedAt: value.updatedAt,
53417
53466
  deletedAt: value.deletedAt
@@ -65324,6 +65373,26 @@ function MFormEntry(value) {
65324
65373
  deletedAt: value.deletedAt ?? null
65325
65374
  };
65326
65375
  }
65376
+ var residentFormEntry = Joi144.object({
65377
+ _id: Joi144.string().hex().optional().allow("", null),
65378
+ typeOfForm: Joi144.string().required(),
65379
+ unitNumber: Joi144.string().optional().allow(null, ""),
65380
+ fields: Joi144.object().pattern(
65381
+ Joi144.string(),
65382
+ Joi144.alternatives().try(
65383
+ Joi144.string(),
65384
+ Joi144.number(),
65385
+ Joi144.boolean(),
65386
+ Joi144.valid(null)
65387
+ )
65388
+ ).required(),
65389
+ status: Joi144.string().optional().allow("", null),
65390
+ org: Joi144.string().hex().optional().allow("", null),
65391
+ site: Joi144.string().hex().optional().allow("", null),
65392
+ createdAt: Joi144.date().optional().allow("", null),
65393
+ updatedAt: Joi144.date().optional().allow("", null),
65394
+ deletedAt: Joi144.date().optional().allow("", null)
65395
+ });
65327
65396
 
65328
65397
  // src/repositories/online-forms-v2.repository.ts
65329
65398
  import {
@@ -65531,13 +65600,38 @@ function useFormEntryRepo() {
65531
65600
  throw new Error(error.message);
65532
65601
  }
65533
65602
  }
65603
+ async function addResidentForm(value, session) {
65604
+ try {
65605
+ value.site = new ObjectId146(value.site);
65606
+ value.org = new ObjectId146(value.org);
65607
+ const res = await collection.insertOne(value, { session });
65608
+ delNamespace().then(() => {
65609
+ logger195.info(
65610
+ `Cache cleared for namespace: ${online_forms_namespace_collection}`
65611
+ );
65612
+ }).catch((err) => {
65613
+ logger195.error(
65614
+ `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
65615
+ err
65616
+ );
65617
+ });
65618
+ return res.insertedId;
65619
+ } catch (error) {
65620
+ const isDuplicated = error.message.includes("duplicate");
65621
+ if (isDuplicated) {
65622
+ throw new BadRequestError223("Online Form already exists.");
65623
+ }
65624
+ throw error;
65625
+ }
65626
+ }
65534
65627
  return {
65535
65628
  add,
65536
65629
  getAll,
65537
65630
  getFormEntryById,
65538
65631
  updateFormEntryById,
65539
65632
  createTextIndex,
65540
- deleteOnlineFormById
65633
+ deleteOnlineFormById,
65634
+ addResidentForm
65541
65635
  };
65542
65636
  }
65543
65637
 
@@ -65552,7 +65646,8 @@ function useFormEntryController() {
65552
65646
  getAll: _getAll,
65553
65647
  getFormEntryById: _getFormEntryById,
65554
65648
  updateFormEntryById: _updateFormEntryById,
65555
- deleteOnlineFormById: _deleteOnlineFormById
65649
+ deleteOnlineFormById: _deleteOnlineFormById,
65650
+ addResidentForm: _addResidentForm
65556
65651
  } = useFormEntryRepo();
65557
65652
  function toCamelCase(str) {
65558
65653
  return str.replace(/\s(.)/g, (_, char) => char.toUpperCase()).replace(/\s+/g, "").replace(/^(.)/, (_, char) => char.toLowerCase());
@@ -65731,13 +65826,35 @@ function useFormEntryController() {
65731
65826
  return;
65732
65827
  }
65733
65828
  }
65829
+ async function residentFormSubmission(req, res, next) {
65830
+ const payload = { ...req.body };
65831
+ const { error } = residentFormEntry.validate(payload, {
65832
+ abortEarly: false
65833
+ });
65834
+ if (error) {
65835
+ const messages = error.details.map((d) => d.message).join(", ");
65836
+ logger196.log({ level: "error", message: messages });
65837
+ next(new BadRequestError224(messages));
65838
+ return;
65839
+ }
65840
+ try {
65841
+ const data = await _addResidentForm(payload);
65842
+ res.status(201).json({ message: data });
65843
+ return;
65844
+ } catch (error2) {
65845
+ logger196.log({ level: "error", message: error2.message });
65846
+ next(error2);
65847
+ return;
65848
+ }
65849
+ }
65734
65850
  return {
65735
65851
  add,
65736
65852
  uploadFormEntrys,
65737
65853
  getAll,
65738
65854
  getFormEntryById,
65739
65855
  updateFormEntryById,
65740
- deleteFormEntryById
65856
+ deleteFormEntryById,
65857
+ residentFormSubmission
65741
65858
  };
65742
65859
  }
65743
65860
 
@@ -66136,6 +66253,7 @@ export {
66136
66253
  poolDashboardCollection,
66137
66254
  promoCodeSchema,
66138
66255
  remarksSchema,
66256
+ residentFormEntry,
66139
66257
  robotSchema,
66140
66258
  schema,
66141
66259
  schemaApprovedBy,