@7365admin1/core 2.30.2 → 2.31.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
@@ -13158,12 +13158,16 @@ var schemaUpdateVisTrans = Joi36.object({
13158
13158
  expiredAt: Joi36.date().iso().optional().allow(null, ""),
13159
13159
  visitorPass: Joi36.array().items(
13160
13160
  Joi36.object({
13161
- keyId: Joi36.string().hex().length(24).required()
13161
+ keyId: Joi36.string().hex().length(24).required(),
13162
+ status: Joi36.string().optional().allow(null, ""),
13163
+ remarks: Joi36.string().optional().allow(null, "")
13162
13164
  })
13163
13165
  ).optional().allow(null),
13164
13166
  passKeys: Joi36.array().items(
13165
13167
  Joi36.object({
13166
- keyId: Joi36.string().hex().length(24).required()
13168
+ keyId: Joi36.string().hex().length(24).required(),
13169
+ status: Joi36.string().optional().allow(null, ""),
13170
+ remarks: Joi36.string().optional().allow(null, "")
13167
13171
  })
13168
13172
  ).optional().allow(null),
13169
13173
  checkInRemarks: Joi36.string().optional().allow("", null),
@@ -21598,8 +21602,8 @@ var KeyRepo = class {
21598
21602
  static async updateKeyById(keyId, key, site, session, isChild) {
21599
21603
  try {
21600
21604
  keyId = new ObjectId57(keyId);
21601
- site = new ObjectId57(site);
21602
- key.updatedAt = /* @__PURE__ */ new Date();
21605
+ if (site)
21606
+ site = new ObjectId57(site);
21603
21607
  if (key.updatedBy)
21604
21608
  key.updatedBy = await convertObjectIdUtil(key.updatedBy);
21605
21609
  if (!key.status)
@@ -21609,7 +21613,8 @@ var KeyRepo = class {
21609
21613
  }
21610
21614
  try {
21611
21615
  key.updatedAt = /* @__PURE__ */ new Date();
21612
- let find = { _id: keyId, site };
21616
+ const query = { _id: keyId, ...site && { site } };
21617
+ let find = query;
21613
21618
  if (isChild)
21614
21619
  find = { parentId: keyId, site };
21615
21620
  const result = await this.collection().updateMany(
@@ -21761,7 +21766,7 @@ function useVisitorTransactionService() {
21761
21766
  if (member.visitorPass && Array.isArray(member.visitorPass) && member.visitorPass.length > 0) {
21762
21767
  for (const vp of member.visitorPass) {
21763
21768
  try {
21764
- const updatePayload = { status: "Not returned" /* NOT_RETURNED */ };
21769
+ const updatePayload = { status: "In Use" /* IN_USE */ };
21765
21770
  const visitorPassId = typeof vp === "string" || vp instanceof ObjectId58 ? vp : vp.keyId;
21766
21771
  await KeyRepo.updateKeyById(
21767
21772
  visitorPassId,
@@ -21776,7 +21781,7 @@ function useVisitorTransactionService() {
21776
21781
  if (member.passKeys && Array.isArray(member.passKeys) && member.passKeys.length > 0) {
21777
21782
  for (const pk of member.passKeys) {
21778
21783
  try {
21779
- const updatePayload = { status: "Not returned" /* NOT_RETURNED */ };
21784
+ const updatePayload = { status: "In Use" /* IN_USE */ };
21780
21785
  const passKeyId = typeof pk === "string" || pk instanceof ObjectId58 ? pk : pk.keyId;
21781
21786
  await KeyRepo.updateKeyById(
21782
21787
  passKeyId,
@@ -21892,7 +21897,7 @@ function useVisitorTransactionService() {
21892
21897
  if (value.visitorPass && Array.isArray(value.visitorPass) && value.visitorPass.length > 0) {
21893
21898
  for (const vp of value.visitorPass) {
21894
21899
  try {
21895
- const updatePayload = { status: "Not returned" /* NOT_RETURNED */ };
21900
+ const updatePayload = { status: "In Use" /* IN_USE */ };
21896
21901
  const visitorPassId = typeof vp === "string" || vp instanceof ObjectId58 ? vp : vp.keyId;
21897
21902
  await KeyRepo.updateKeyById(
21898
21903
  visitorPassId,
@@ -21907,7 +21912,7 @@ function useVisitorTransactionService() {
21907
21912
  if (value.passKeys && Array.isArray(value.passKeys) && value.passKeys.length > 0) {
21908
21913
  for (const pk of value.passKeys) {
21909
21914
  try {
21910
- const updatePayload = { status: "Not returned" /* NOT_RETURNED */ };
21915
+ const updatePayload = { status: "In Use" /* IN_USE */ };
21911
21916
  const passKeyId = typeof pk === "string" || pk instanceof ObjectId58 ? pk : pk.keyId;
21912
21917
  await KeyRepo.updateKeyById(
21913
21918
  passKeyId,
@@ -21933,6 +21938,52 @@ function useVisitorTransactionService() {
21933
21938
  const session = useAtlas48.getClient()?.startSession();
21934
21939
  session?.startTransaction();
21935
21940
  try {
21941
+ if (Array.isArray(value.visitorPass) && value.visitorPass.length > 0) {
21942
+ const keptVisitorPass = [];
21943
+ for (const vp of value.visitorPass) {
21944
+ const updatePayload = {
21945
+ ...vp.status && { status: vp.status },
21946
+ ...vp.remarks && { remarks: vp.remarks }
21947
+ };
21948
+ const visitorPassId = typeof vp === "string" || vp instanceof ObjectId58 ? vp : vp.keyId;
21949
+ await KeyRepo.updateKeyById(
21950
+ visitorPassId,
21951
+ updatePayload,
21952
+ value.site
21953
+ );
21954
+ if (typeof vp !== "string" && !(vp instanceof ObjectId58)) {
21955
+ keptVisitorPass.push({
21956
+ keyId: new ObjectId58(visitorPassId)
21957
+ });
21958
+ }
21959
+ }
21960
+ value.visitorPass = keptVisitorPass;
21961
+ }
21962
+ if (value.passKeys && Array.isArray(value.passKeys) && value.passKeys.length > 0) {
21963
+ const keptPassKeys = [];
21964
+ for (const pk of value.passKeys) {
21965
+ try {
21966
+ const updatePayload = {
21967
+ ...pk.status && { status: pk.status },
21968
+ ...pk.remarks && { remarks: pk.remarks }
21969
+ };
21970
+ const passKeyId = typeof pk === "string" || pk instanceof ObjectId58 ? pk : pk.keyId;
21971
+ await KeyRepo.updateKeyById(
21972
+ passKeyId,
21973
+ updatePayload,
21974
+ value.site
21975
+ );
21976
+ if (typeof pk !== "string" && !(pk instanceof ObjectId58)) {
21977
+ keptPassKeys.push({
21978
+ keyId: new ObjectId58(passKeyId)
21979
+ });
21980
+ }
21981
+ } catch (error) {
21982
+ throw error;
21983
+ }
21984
+ }
21985
+ value.passKeys = keptPassKeys;
21986
+ }
21936
21987
  await _updateVisitorTansactionById(id, value, session);
21937
21988
  await session?.commitTransaction();
21938
21989
  return "Successfully updated visitor transaction.";
@@ -22925,7 +22976,8 @@ function usePersonController() {
22925
22976
  getPeopleByUnit: _getPeopleByUnit,
22926
22977
  getCompany: _getCompany,
22927
22978
  getPeopleByPlateNumber: _getPeopleByPlateNumber,
22928
- getPeopleByNRIC: _getPeopleByNRIC
22979
+ getPeopleByNRIC: _getPeopleByNRIC,
22980
+ getByUserId: _getByUserId
22929
22981
  } = usePersonRepo();
22930
22982
  const { add: _add, updateById: _updateById } = usePersonService();
22931
22983
  async function add(req, res, next) {
@@ -23224,6 +23276,25 @@ function usePersonController() {
23224
23276
  return;
23225
23277
  }
23226
23278
  }
23279
+ async function getPersonByUserId(req, res, next) {
23280
+ const validation = Joi58.string().required();
23281
+ const userId = req.params.userId;
23282
+ const { error } = validation.validate(userId);
23283
+ if (error) {
23284
+ logger82.log({ level: "error", message: error.message });
23285
+ next(new BadRequestError101(error.message));
23286
+ return;
23287
+ }
23288
+ try {
23289
+ const data = await _getByUserId(userId);
23290
+ res.json(data);
23291
+ return;
23292
+ } catch (error2) {
23293
+ logger82.log({ level: "error", message: error2.message });
23294
+ next(error2);
23295
+ return;
23296
+ }
23297
+ }
23227
23298
  return {
23228
23299
  add,
23229
23300
  getAll,
@@ -23234,7 +23305,8 @@ function usePersonController() {
23234
23305
  getPeopleByUnit,
23235
23306
  getCompany,
23236
23307
  getPeopleByPlateNumber,
23237
- getPeopleByNRIC
23308
+ getPeopleByNRIC,
23309
+ getPersonByUserId
23238
23310
  };
23239
23311
  }
23240
23312
 
@@ -30921,6 +30993,95 @@ function useSiteUnitBillingRepo() {
30921
30993
  throw error;
30922
30994
  }
30923
30995
  }
30996
+ async function getResidentUserBilling({
30997
+ search = "",
30998
+ page = 1,
30999
+ limit = 10,
31000
+ sort = {},
31001
+ status = "active",
31002
+ site = "",
31003
+ paymentStatus = "awaiting_payment",
31004
+ month,
31005
+ year,
31006
+ unitId
31007
+ }, session) {
31008
+ page = page > 0 ? page - 1 : 0;
31009
+ let dateExpr = {};
31010
+ if (month && year) {
31011
+ const monthNum = parseInt(month, 10);
31012
+ const yearNum = parseInt(year, 10);
31013
+ const startDate = new Date(yearNum, monthNum - 1, 1);
31014
+ const endDate = new Date(yearNum, monthNum, 1);
31015
+ dateExpr.createdAt = {
31016
+ $gte: startDate,
31017
+ $lt: endDate
31018
+ };
31019
+ }
31020
+ const unitSearchRegex = search ? search.trim().replace(/\s+/g, "").replace(/\//g, "\\s*/\\s*") : null;
31021
+ const query = {
31022
+ paymentStatus,
31023
+ status,
31024
+ ...search && {
31025
+ $or: [
31026
+ { unitOwner: { $regex: search, $options: "i" } },
31027
+ { billName: { $regex: search, $options: "i" } },
31028
+ { unit: { $regex: unitSearchRegex, $options: "i" } },
31029
+ {
31030
+ $expr: {
31031
+ $regexMatch: {
31032
+ input: { $toString: "$amountPaid" },
31033
+ regex: search,
31034
+ options: "i"
31035
+ }
31036
+ }
31037
+ }
31038
+ ]
31039
+ },
31040
+ ...ObjectId86.isValid(site) && { site: new ObjectId86(site) },
31041
+ ...dateExpr,
31042
+ ...ObjectId86.isValid(unitId) && { unitId: new ObjectId86(unitId) }
31043
+ };
31044
+ sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
31045
+ try {
31046
+ const basePipeline = [
31047
+ { $match: query },
31048
+ { $sort: sort },
31049
+ { $skip: page * limit },
31050
+ { $limit: limit },
31051
+ {
31052
+ $lookup: {
31053
+ from: "site.billing.items",
31054
+ localField: "billItem",
31055
+ foreignField: "_id",
31056
+ pipeline: [
31057
+ {
31058
+ $project: {
31059
+ _id: 1,
31060
+ totalAmount: 1
31061
+ }
31062
+ }
31063
+ ],
31064
+ as: "billDetails"
31065
+ }
31066
+ },
31067
+ {
31068
+ $unwind: {
31069
+ path: "$billDetails",
31070
+ preserveNullAndEmptyArrays: true
31071
+ }
31072
+ }
31073
+ ];
31074
+ const [items, countResult] = await Promise.all([
31075
+ collection.aggregate(basePipeline, { session }).toArray(),
31076
+ collection.aggregate([{ $match: query }, { $count: "total" }], { session }).toArray()
31077
+ ]);
31078
+ const totalCount = countResult[0]?.total || 0;
31079
+ const data = paginate37(items, page, limit, totalCount);
31080
+ return data;
31081
+ } catch (error) {
31082
+ throw error;
31083
+ }
31084
+ }
30924
31085
  function delCachedData() {
30925
31086
  delNamespace().then(() => {
30926
31087
  logger117.log({
@@ -30952,7 +31113,8 @@ function useSiteUnitBillingRepo() {
30952
31113
  getById,
30953
31114
  updateById,
30954
31115
  deleteById,
30955
- getUnitBillingBySite
31116
+ getUnitBillingBySite,
31117
+ getResidentUserBilling
30956
31118
  };
30957
31119
  }
30958
31120
 
@@ -31143,7 +31305,8 @@ function useSiteUnitBillingController() {
31143
31305
  getAll: _getAll,
31144
31306
  updateById: _updateById,
31145
31307
  deleteById: _deleteById,
31146
- getById: _getById
31308
+ getById: _getById,
31309
+ getResidentUserBilling: _getResidentUserBilling
31147
31310
  } = useSiteUnitBillingRepo();
31148
31311
  async function add(req, res, next) {
31149
31312
  const data = { ...req.body };
@@ -31284,12 +31447,64 @@ function useSiteUnitBillingController() {
31284
31447
  return;
31285
31448
  }
31286
31449
  }
31450
+ async function getResidentUserBilling(req, res, next) {
31451
+ const validation = Joi84.object({
31452
+ page: Joi84.number().integer().min(1).allow("", null).default(1),
31453
+ limit: Joi84.number().integer().min(1).max(100).allow("", null).default(10),
31454
+ status: Joi84.string().optional().allow(null, ""),
31455
+ search: Joi84.string().optional().allow(null, ""),
31456
+ site: Joi84.string().required(),
31457
+ paymentStatus: Joi84.string().optional().allow(null, ""),
31458
+ month: Joi84.string().optional().allow(null, ""),
31459
+ year: Joi84.string().optional().allow(null, ""),
31460
+ unitId: Joi84.string().optional().allow(null, "")
31461
+ });
31462
+ const query = { ...req.query };
31463
+ const { error } = validation.validate(query, {
31464
+ abortEarly: false
31465
+ });
31466
+ if (error) {
31467
+ const messages = error.details.map((d) => d.message).join(", ");
31468
+ logger119.log({ level: "error", message: messages });
31469
+ next(new BadRequestError140(messages));
31470
+ return;
31471
+ }
31472
+ const search = req.query.search ?? "";
31473
+ const page = parseInt(req.query.page ?? "1");
31474
+ const limit = parseInt(req.query.limit ?? "10");
31475
+ const status = req.query.status ?? "active";
31476
+ const site = req.query.site;
31477
+ const paymentStatus = req.query.paymentStatus ?? "awaiting_payment";
31478
+ const month = req.query.month ?? "";
31479
+ const year = req.query.year ?? "";
31480
+ const unitId = req.query.unitId ?? "";
31481
+ try {
31482
+ const data = await _getResidentUserBilling({
31483
+ search,
31484
+ page,
31485
+ limit,
31486
+ status,
31487
+ site,
31488
+ paymentStatus,
31489
+ month,
31490
+ year,
31491
+ unitId
31492
+ });
31493
+ res.status(200).json(data);
31494
+ return;
31495
+ } catch (error2) {
31496
+ logger119.log({ level: "error", message: error2.message });
31497
+ next(error2);
31498
+ return;
31499
+ }
31500
+ }
31287
31501
  return {
31288
31502
  add,
31289
31503
  getAll,
31290
31504
  getById,
31291
31505
  updateById,
31292
- deleteById
31506
+ deleteById,
31507
+ getResidentUserBilling
31293
31508
  };
31294
31509
  }
31295
31510