@7365admin1/core 2.44.0 → 2.45.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
@@ -2606,7 +2606,8 @@ function useUserRepo() {
2606
2606
  "dateOfBirth",
2607
2607
  "profile",
2608
2608
  "gender",
2609
- "defaultOrg"
2609
+ "defaultOrg",
2610
+ "status"
2610
2611
  ];
2611
2612
  if (!allowedFields.includes(field)) {
2612
2613
  throw new BadRequestError9(
@@ -16558,10 +16559,13 @@ function useVehicleService() {
16558
16559
  pullVehicleByRecNo: _pullVehicleByRecNo
16559
16560
  } = usePersonRepo();
16560
16561
  const { getUnitByBlockLevelUnitNumber: _getUnitByBlockLevelUnitNumber } = useBuildingUnitRepo();
16561
- async function add(value) {
16562
- const session = useAtlas35.getClient()?.startSession();
16562
+ async function add(value, session) {
16563
+ const isExternalSession = !!session;
16563
16564
  if (!session) {
16564
- throw new Error("Unable to start session for vehicle service.");
16565
+ session = await useAtlas35.getClient()?.startSession();
16566
+ if (!session) {
16567
+ throw new Error("Unable to start session for vehicle service.");
16568
+ }
16565
16569
  }
16566
16570
  const [_vehiclePlateNumber] = value.plateNumber;
16567
16571
  const [existingPlateNumber, org] = await Promise.all([
@@ -16618,7 +16622,9 @@ function useVehicleService() {
16618
16622
  const owner = value.name;
16619
16623
  const plateNumbers = value.plateNumber;
16620
16624
  try {
16621
- session.startTransaction();
16625
+ if (!isExternalSession) {
16626
+ session.startTransaction();
16627
+ }
16622
16628
  let message = "Vehicle plate number needs approval from property management.";
16623
16629
  let siteCameras = [];
16624
16630
  if (value.status && value.status !== "pending" /* PENDING */) {
@@ -16716,14 +16722,20 @@ function useVehicleService() {
16716
16722
  }
16717
16723
  await _add(vehicleValue, session);
16718
16724
  }
16719
- await session.commitTransaction();
16725
+ if (!isExternalSession) {
16726
+ await session.commitTransaction();
16727
+ }
16720
16728
  return message;
16721
16729
  } catch (error) {
16722
16730
  logger54.error("Error in vehicle service add:", error);
16723
- await session.abortTransaction();
16731
+ if (!isExternalSession) {
16732
+ await session.abortTransaction();
16733
+ }
16724
16734
  throw error;
16725
16735
  } finally {
16726
- session.endSession();
16736
+ if (!isExternalSession) {
16737
+ session.endSession();
16738
+ }
16727
16739
  }
16728
16740
  }
16729
16741
  async function deleteVehicle(_id, recno, site, type, bypass = false) {
@@ -23994,6 +24006,7 @@ function usePersonService() {
23994
24006
  const { updateStatusById } = useFileRepo();
23995
24007
  const { getById: getOrgById } = useOrgRepo();
23996
24008
  const { getSiteById } = useSiteRepo();
24009
+ const { add: addVehicle } = useVehicleService();
23997
24010
  async function add(value) {
23998
24011
  const session = useAtlas52.getClient()?.startSession();
23999
24012
  if (!session) {
@@ -24027,7 +24040,7 @@ function usePersonService() {
24027
24040
  email: value.email,
24028
24041
  password: hashedPassword,
24029
24042
  name: value.name,
24030
- status: value.platform == "mobile" ? "deleted" : "active",
24043
+ status: value.platform == "mobile" ? "pending" : "active",
24031
24044
  defaultOrg: value.org?.toString() || ""
24032
24045
  };
24033
24046
  const userId = await addUser(user, session);
@@ -24148,6 +24161,9 @@ function usePersonService() {
24148
24161
  const session = useAtlas52.getClient()?.startSession();
24149
24162
  session?.startTransaction();
24150
24163
  try {
24164
+ const person = await _getById(id.toString());
24165
+ if (!person)
24166
+ throw new BadRequestError101("Person not found.");
24151
24167
  if (value.approvedBy) {
24152
24168
  const approvedBy = await getUserById(value.approvedBy.id);
24153
24169
  if (!approvedBy || !approvedBy.name)
@@ -24155,9 +24171,51 @@ function usePersonService() {
24155
24171
  value.approvedBy.name = approvedBy.name;
24156
24172
  value.approvedBy.id = approvedBy._id;
24157
24173
  }
24174
+ const vehicle = {
24175
+ plateNumber: person.plateNumber || "",
24176
+ type: "whitelist",
24177
+ category: person.type || "",
24178
+ name: person.name,
24179
+ phoneNumber: person.contact,
24180
+ org: person.org.toString(),
24181
+ site: person.site.toString(),
24182
+ block: person.block,
24183
+ level: person.level,
24184
+ unit: person.unit.toString(),
24185
+ nric: person.nric,
24186
+ status: "active",
24187
+ peopleId: person._id?.toString()
24188
+ };
24189
+ const reviewStatus = value.status;
24190
+ if (reviewStatus === "approved") {
24191
+ value.status = "active";
24192
+ }
24158
24193
  await _reviewResidentPerson(id, value, session);
24194
+ if (person.user) {
24195
+ let userStatus;
24196
+ switch (reviewStatus) {
24197
+ case "approved":
24198
+ userStatus = "active";
24199
+ if (person.plateNumber && person.plateNumber.trim() !== "") {
24200
+ await addVehicle(vehicle, session);
24201
+ }
24202
+ break;
24203
+ case "resubmit":
24204
+ userStatus = "resubmit";
24205
+ break;
24206
+ case "rejected":
24207
+ userStatus = "rejected";
24208
+ break;
24209
+ default:
24210
+ throw new Error("Invalid review status");
24211
+ }
24212
+ await _updateUserFieldById(
24213
+ { _id: person.user.toString(), field: "status", value: userStatus },
24214
+ session
24215
+ );
24216
+ }
24159
24217
  await session?.commitTransaction();
24160
- return `Successfully ${value.status} person`;
24218
+ return `Successfully ${reviewStatus} person`;
24161
24219
  } catch (error) {
24162
24220
  await session?.abortTransaction();
24163
24221
  throw error;
@@ -29823,21 +29881,23 @@ function useBulletinBoardController() {
29823
29881
  }
29824
29882
  }
29825
29883
  async function getBulletinBoardById(req, res, next) {
29826
- const validation = Joi76.string().hex().required();
29827
- const _id = req.params.id;
29828
- const { error } = validation.validate(_id);
29829
- if (error) {
29830
- logger106.log({ level: "error", message: error.message });
29831
- next(new BadRequestError127(error.message));
29832
- return;
29833
- }
29834
29884
  try {
29885
+ const schema2 = Joi76.object({
29886
+ _id: Joi76.string().hex().length(24).required()
29887
+ });
29888
+ const { error, value } = schema2.validate({ _id: req.params.id });
29889
+ if (error) {
29890
+ logger106.log({ level: "error", message: error.message });
29891
+ next(new BadRequestError127(error.message));
29892
+ return;
29893
+ }
29894
+ const { _id } = value;
29835
29895
  const data = await _getBulletinBoardById(_id);
29836
29896
  res.status(200).json(data);
29837
29897
  return;
29838
- } catch (error2) {
29839
- logger106.log({ level: "error", message: error2.message });
29840
- next(error2);
29898
+ } catch (error) {
29899
+ logger106.log({ level: "error", message: error.message });
29900
+ next(error);
29841
29901
  return;
29842
29902
  }
29843
29903
  }
@@ -31171,7 +31231,7 @@ var schemaEventManagement = Joi81.object({
31171
31231
  site: Joi81.string().required(),
31172
31232
  title: Joi81.string().required(),
31173
31233
  description: Joi81.string().optional().allow(""),
31174
- dateTime: Joi81.alternatives().try(Joi81.string(), Joi81.date()).required(),
31234
+ dateTime: Joi81.date().iso().required(),
31175
31235
  status: Joi81.string().optional().default("planned"),
31176
31236
  type: Joi81.string().optional().default("TASK")
31177
31237
  });
@@ -31179,7 +31239,7 @@ var schemaUpdateEventManagement = Joi81.object({
31179
31239
  _id: Joi81.string().hex().required(),
31180
31240
  title: Joi81.string().optional().allow(null, ""),
31181
31241
  description: Joi81.string().optional().allow(null, ""),
31182
- dateTime: Joi81.alternatives().try(Joi81.string(), Joi81.date()).optional().allow(null, ""),
31242
+ dateTime: Joi81.date().iso().optional().allow(null, ""),
31183
31243
  status: Joi81.string().optional().allow(null, ""),
31184
31244
  type: Joi81.string().optional().allow(null, "")
31185
31245
  });
@@ -31203,10 +31263,10 @@ function MEventManagement(value) {
31203
31263
  site: value.site,
31204
31264
  title: value.title,
31205
31265
  description: value.description ?? "",
31206
- dateTime: value.dateTime,
31266
+ dateTime: new Date(value.dateTime),
31207
31267
  status: value.status ?? "planned",
31208
31268
  type: value.type ?? "TASK",
31209
- createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
31269
+ createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
31210
31270
  updatedAt: value.updatedAt,
31211
31271
  deletedAt: value.deletedAt
31212
31272
  };
@@ -31393,7 +31453,7 @@ function useEventManagementRepo() {
31393
31453
  }
31394
31454
  }
31395
31455
  async function updateEventManagementById(_id, value, session) {
31396
- value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
31456
+ value.updatedAt = /* @__PURE__ */ new Date();
31397
31457
  try {
31398
31458
  _id = new ObjectId85(_id);
31399
31459
  } catch (error) {
@@ -31439,8 +31499,7 @@ function useEventManagementRepo() {
31439
31499
  try {
31440
31500
  const updateValue = {
31441
31501
  status: "deleted",
31442
- updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
31443
- deletedAt: (/* @__PURE__ */ new Date()).toISOString()
31502
+ deletedAt: /* @__PURE__ */ new Date()
31444
31503
  };
31445
31504
  const res = await collection.updateOne({ _id }, { $set: updateValue });
31446
31505
  if (res.modifiedCount === 0) {
@@ -31533,7 +31592,12 @@ function useEventManagementService() {
31533
31592
  const session = useAtlas73.getClient()?.startSession();
31534
31593
  session?.startTransaction();
31535
31594
  try {
31536
- await _updateEventManagementById(id, value, session);
31595
+ const updatedValue = {
31596
+ ...value.dateTime && { dateTime: new Date(value.dateTime) },
31597
+ ...value.title && { title: value.title },
31598
+ ...value.description && { description: value.description }
31599
+ };
31600
+ await _updateEventManagementById(id, updatedValue, session);
31537
31601
  await session?.commitTransaction();
31538
31602
  return "Successfully updated event.";
31539
31603
  } catch (error) {
@@ -33062,7 +33126,7 @@ var minifyXml = (xml) => {
33062
33126
  };
33063
33127
  var readTemplate = (name, params) => {
33064
33128
  const template = fs2.readFileSync(
33065
- path2.join(__dirname, `../src/public/xml-templates/${name}.xml`),
33129
+ path2.join(__dirname, `../dist/public/xml-templates/${name}.xml`),
33066
33130
  "utf-8"
33067
33131
  );
33068
33132
  if (!params)
@@ -37500,6 +37564,17 @@ function useOccurrenceBookController() {
37500
37564
  // src/models/bulletin-video.model.ts
37501
37565
  import { ObjectId as ObjectId95 } from "mongodb";
37502
37566
  import Joi90 from "joi";
37567
+ var BulletinVideoSort = /* @__PURE__ */ ((BulletinVideoSort2) => {
37568
+ BulletinVideoSort2["CREATED_AT"] = "createdAt";
37569
+ BulletinVideoSort2["NAME"] = "name";
37570
+ BulletinVideoSort2["ID"] = "_id";
37571
+ return BulletinVideoSort2;
37572
+ })(BulletinVideoSort || {});
37573
+ var BulletinVideoOrder = /* @__PURE__ */ ((BulletinVideoOrder2) => {
37574
+ BulletinVideoOrder2["ASC"] = "asc";
37575
+ BulletinVideoOrder2["DESC"] = "desc";
37576
+ return BulletinVideoOrder2;
37577
+ })(BulletinVideoOrder || {});
37503
37578
  var schemaBulletinVideo = Joi90.object({
37504
37579
  site: Joi90.string().hex().required(),
37505
37580
  title: Joi90.string().optional().allow(null, ""),
@@ -37837,39 +37912,35 @@ function useBulletinVideoController() {
37837
37912
  deleteBulletinVideoById: _deleteBulletinVideoById
37838
37913
  } = useBulletinVideoRepo();
37839
37914
  async function add(req, res, next) {
37840
- const payload = { ...req.body };
37841
- const { error } = schemaBulletinVideo.validate(payload, {
37842
- abortEarly: false
37843
- });
37844
- if (error) {
37845
- const messages = error.details.map((d) => d.message).join(", ");
37846
- logger127.log({ level: "error", message: messages });
37847
- next(new BadRequestError150(messages));
37848
- return;
37849
- }
37850
37915
  try {
37851
- const data = await _add(payload);
37916
+ const { error, value } = schemaBulletinVideo.validate(req.body, {
37917
+ abortEarly: false
37918
+ });
37919
+ if (error) {
37920
+ const messages = error.details.map((d) => d.message).join(", ");
37921
+ logger127.log({ level: "error", message: messages });
37922
+ next(new BadRequestError150(messages));
37923
+ return;
37924
+ }
37925
+ const data = await _add(value);
37852
37926
  res.status(201).json(data);
37853
37927
  return;
37854
- } catch (error2) {
37855
- logger127.log({ level: "error", message: error2.message });
37856
- next(error2);
37928
+ } catch (error) {
37929
+ logger127.log({ level: "error", message: error.message });
37930
+ next(error);
37857
37931
  return;
37858
37932
  }
37859
37933
  }
37860
37934
  async function getAll(req, res, next) {
37861
- const allowedFields = ["createdAt", "name"];
37862
- const allowedOrder = ["asc", "desc"];
37863
37935
  const validation = Joi91.object({
37864
37936
  search: Joi91.string().optional().allow("", null),
37865
37937
  page: Joi91.number().integer().min(1).allow("", null).default(1),
37866
37938
  limit: Joi91.number().integer().min(1).max(100).allow("", null).default(10),
37867
- sort: Joi91.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("", ...allowedFields),
37868
- order: Joi91.string().pattern(/^(asc|desc)(,(asc|desc))*$/).optional().allow("", ...allowedOrder),
37869
- site: Joi91.string().hex().required()
37939
+ sort: Joi91.string().valid(...Object.values(BulletinVideoSort)).default("_id" /* ID */),
37940
+ order: Joi91.string().valid(...Object.values(BulletinVideoOrder)).default("desc" /* DESC */),
37941
+ site: Joi91.string().hex().length(24).required()
37870
37942
  });
37871
- const query = { ...req.query };
37872
- const { error } = validation.validate(query, {
37943
+ const { error, value } = validation.validate(req.query, {
37873
37944
  abortEarly: false
37874
37945
  });
37875
37946
  if (error) {
@@ -37878,19 +37949,10 @@ function useBulletinVideoController() {
37878
37949
  next(new BadRequestError150(messages));
37879
37950
  return;
37880
37951
  }
37881
- const search = req.query.search ?? "";
37882
- const page = parseInt(req.query.page ?? "1");
37883
- const limit = parseInt(req.query.limit ?? "10");
37884
- const site = req.query.site ?? "";
37885
- const sortObj = {};
37886
- const sortFields = String(req.query.sort).split(",");
37887
- const sortOrders = String(req.query.order).split(",");
37888
- sortFields.forEach((field, index) => {
37889
- if (allowedFields.includes(field)) {
37890
- const order = sortOrders[index] === "asc" ? 1 : -1;
37891
- sortObj[field] = order;
37892
- }
37893
- });
37952
+ const { search, page, limit, site, sort, order } = value;
37953
+ const sortObj = {
37954
+ [sort ?? "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
37955
+ };
37894
37956
  try {
37895
37957
  const data = await _getAll({
37896
37958
  search,
@@ -37908,21 +37970,23 @@ function useBulletinVideoController() {
37908
37970
  }
37909
37971
  }
37910
37972
  async function getBulletinVideoById(req, res, next) {
37911
- const validation = Joi91.string().hex().required();
37912
- const _id = req.params.id;
37913
- const { error } = validation.validate(_id);
37914
- if (error) {
37915
- logger127.log({ level: "error", message: error.message });
37916
- next(new BadRequestError150(error.message));
37917
- return;
37918
- }
37919
37973
  try {
37974
+ const schema2 = Joi91.object({
37975
+ _id: Joi91.string().hex().length(24).required()
37976
+ });
37977
+ const { error, value } = schema2.validate({ _id: req.params.id });
37978
+ if (error) {
37979
+ logger127.log({ level: "error", message: error.message });
37980
+ next(new BadRequestError150(error.message));
37981
+ return;
37982
+ }
37983
+ const { _id } = value;
37920
37984
  const data = await _getBulletinVideoById(_id);
37921
37985
  res.status(200).json(data);
37922
37986
  return;
37923
- } catch (error2) {
37924
- logger127.log({ level: "error", message: error2.message });
37925
- next(error2);
37987
+ } catch (error) {
37988
+ logger127.log({ level: "error", message: error.message });
37989
+ next(error);
37926
37990
  return;
37927
37991
  }
37928
37992
  }
@@ -37949,21 +38013,23 @@ function useBulletinVideoController() {
37949
38013
  }
37950
38014
  }
37951
38015
  async function deleteBulletinVideoById(req, res, next) {
37952
- const validation = Joi91.string().hex().required();
37953
- const _id = req.params.id;
37954
- const { error } = validation.validate(_id);
37955
- if (error) {
37956
- logger127.log({ level: "error", message: error.message });
37957
- next(new BadRequestError150(error.message));
37958
- return;
37959
- }
37960
38016
  try {
38017
+ const schema2 = Joi91.object({
38018
+ _id: Joi91.string().hex().length(24).required()
38019
+ });
38020
+ const { error, value } = schema2.validate({ _id: req.params.id });
38021
+ if (error) {
38022
+ logger127.log({ level: "error", message: error.message });
38023
+ next(new BadRequestError150(error.message));
38024
+ return;
38025
+ }
38026
+ const { _id } = value;
37961
38027
  await _deleteBulletinVideoById(_id);
37962
38028
  res.status(200).json({ message: "Successfully deleted bulletin video." });
37963
38029
  return;
37964
- } catch (error2) {
37965
- logger127.log({ level: "error", message: error2.message });
37966
- next(error2);
38030
+ } catch (error) {
38031
+ logger127.log({ level: "error", message: error.message });
38032
+ next(error);
37967
38033
  return;
37968
38034
  }
37969
38035
  }
@@ -50386,6 +50452,8 @@ export {
50386
50452
  BulletinRecipient,
50387
50453
  BulletinSort,
50388
50454
  BulletinStatus,
50455
+ BulletinVideoOrder,
50456
+ BulletinVideoSort,
50389
50457
  CameraType,
50390
50458
  DEVICE_STATUS,
50391
50459
  DOBStatus,