@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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @iservice365/core
2
2
 
3
+ ## 2.31.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4acecf5: get all changes
8
+
3
9
  ## 2.30.2
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -2479,6 +2479,14 @@ declare function MPerson(value: TPerson): {
2479
2479
  deletedAt: string | Date | undefined;
2480
2480
  };
2481
2481
 
2482
+ declare enum KeyStatus {
2483
+ AVAILABLE = "Available",
2484
+ RETURNED = "Returned",
2485
+ LOST = "Lost",
2486
+ DAMAGED = "Damaged",
2487
+ IN_USE = "In Use"
2488
+ }
2489
+
2482
2490
  declare enum VisitorSort {
2483
2491
  CREATED_AT = "createdAt",
2484
2492
  NAME = "name",
@@ -2491,6 +2499,8 @@ declare enum VisitorStatus {
2491
2499
  }
2492
2500
  type TKeyRef = {
2493
2501
  keyId: string | ObjectId;
2502
+ status?: KeyStatus;
2503
+ remarks?: string;
2494
2504
  };
2495
2505
  type TVisitorTransaction = {
2496
2506
  _id?: ObjectId;
@@ -2768,6 +2778,7 @@ declare function usePersonController(): {
2768
2778
  getCompany: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2769
2779
  getPeopleByPlateNumber: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2770
2780
  getPeopleByNRIC: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2781
+ getPersonByUserId: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2771
2782
  };
2772
2783
 
2773
2784
  type TRobotMetadata = {
@@ -4016,6 +4027,22 @@ declare function useSiteUnitBillingRepo(): {
4016
4027
  dateTo?: string | undefined;
4017
4028
  unitId: string;
4018
4029
  }, session?: ClientSession) => Promise<bson.Document[]>;
4030
+ getResidentUserBilling: ({ search, page, limit, sort, status, site, paymentStatus, month, year, unitId, }: {
4031
+ search?: string | undefined;
4032
+ page?: number | undefined;
4033
+ limit?: number | undefined;
4034
+ sort?: Record<string, any> | undefined;
4035
+ status: string;
4036
+ site?: string | undefined;
4037
+ paymentStatus?: string | undefined;
4038
+ month?: string | undefined;
4039
+ year?: string | undefined;
4040
+ unitId: string;
4041
+ }, session?: ClientSession) => Promise<{
4042
+ items: any[];
4043
+ pages: number;
4044
+ pageRange: string;
4045
+ }>;
4019
4046
  };
4020
4047
 
4021
4048
  declare function useSiteUnitBillingService(): {
@@ -4029,6 +4056,7 @@ declare function useSiteUnitBillingController(): {
4029
4056
  getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
4030
4057
  updateById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
4031
4058
  deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
4059
+ getResidentUserBilling: (req: Request, res: Response, next: NextFunction) => Promise<void>;
4032
4060
  };
4033
4061
 
4034
4062
  interface AssignCardConfig {
package/dist/index.js CHANGED
@@ -13360,12 +13360,16 @@ var schemaUpdateVisTrans = import_joi36.default.object({
13360
13360
  expiredAt: import_joi36.default.date().iso().optional().allow(null, ""),
13361
13361
  visitorPass: import_joi36.default.array().items(
13362
13362
  import_joi36.default.object({
13363
- keyId: import_joi36.default.string().hex().length(24).required()
13363
+ keyId: import_joi36.default.string().hex().length(24).required(),
13364
+ status: import_joi36.default.string().optional().allow(null, ""),
13365
+ remarks: import_joi36.default.string().optional().allow(null, "")
13364
13366
  })
13365
13367
  ).optional().allow(null),
13366
13368
  passKeys: import_joi36.default.array().items(
13367
13369
  import_joi36.default.object({
13368
- keyId: import_joi36.default.string().hex().length(24).required()
13370
+ keyId: import_joi36.default.string().hex().length(24).required(),
13371
+ status: import_joi36.default.string().optional().allow(null, ""),
13372
+ remarks: import_joi36.default.string().optional().allow(null, "")
13369
13373
  })
13370
13374
  ).optional().allow(null),
13371
13375
  checkInRemarks: import_joi36.default.string().optional().allow("", null),
@@ -21700,8 +21704,8 @@ var KeyRepo = class {
21700
21704
  static async updateKeyById(keyId, key, site, session, isChild) {
21701
21705
  try {
21702
21706
  keyId = new import_mongodb57.ObjectId(keyId);
21703
- site = new import_mongodb57.ObjectId(site);
21704
- key.updatedAt = /* @__PURE__ */ new Date();
21707
+ if (site)
21708
+ site = new import_mongodb57.ObjectId(site);
21705
21709
  if (key.updatedBy)
21706
21710
  key.updatedBy = await convertObjectIdUtil(key.updatedBy);
21707
21711
  if (!key.status)
@@ -21711,7 +21715,8 @@ var KeyRepo = class {
21711
21715
  }
21712
21716
  try {
21713
21717
  key.updatedAt = /* @__PURE__ */ new Date();
21714
- let find = { _id: keyId, site };
21718
+ const query = { _id: keyId, ...site && { site } };
21719
+ let find = query;
21715
21720
  if (isChild)
21716
21721
  find = { parentId: keyId, site };
21717
21722
  const result = await this.collection().updateMany(
@@ -21863,7 +21868,7 @@ function useVisitorTransactionService() {
21863
21868
  if (member.visitorPass && Array.isArray(member.visitorPass) && member.visitorPass.length > 0) {
21864
21869
  for (const vp of member.visitorPass) {
21865
21870
  try {
21866
- const updatePayload = { status: "Not returned" /* NOT_RETURNED */ };
21871
+ const updatePayload = { status: "In Use" /* IN_USE */ };
21867
21872
  const visitorPassId = typeof vp === "string" || vp instanceof import_mongodb58.ObjectId ? vp : vp.keyId;
21868
21873
  await KeyRepo.updateKeyById(
21869
21874
  visitorPassId,
@@ -21878,7 +21883,7 @@ function useVisitorTransactionService() {
21878
21883
  if (member.passKeys && Array.isArray(member.passKeys) && member.passKeys.length > 0) {
21879
21884
  for (const pk of member.passKeys) {
21880
21885
  try {
21881
- const updatePayload = { status: "Not returned" /* NOT_RETURNED */ };
21886
+ const updatePayload = { status: "In Use" /* IN_USE */ };
21882
21887
  const passKeyId = typeof pk === "string" || pk instanceof import_mongodb58.ObjectId ? pk : pk.keyId;
21883
21888
  await KeyRepo.updateKeyById(
21884
21889
  passKeyId,
@@ -21994,7 +21999,7 @@ function useVisitorTransactionService() {
21994
21999
  if (value.visitorPass && Array.isArray(value.visitorPass) && value.visitorPass.length > 0) {
21995
22000
  for (const vp of value.visitorPass) {
21996
22001
  try {
21997
- const updatePayload = { status: "Not returned" /* NOT_RETURNED */ };
22002
+ const updatePayload = { status: "In Use" /* IN_USE */ };
21998
22003
  const visitorPassId = typeof vp === "string" || vp instanceof import_mongodb58.ObjectId ? vp : vp.keyId;
21999
22004
  await KeyRepo.updateKeyById(
22000
22005
  visitorPassId,
@@ -22009,7 +22014,7 @@ function useVisitorTransactionService() {
22009
22014
  if (value.passKeys && Array.isArray(value.passKeys) && value.passKeys.length > 0) {
22010
22015
  for (const pk of value.passKeys) {
22011
22016
  try {
22012
- const updatePayload = { status: "Not returned" /* NOT_RETURNED */ };
22017
+ const updatePayload = { status: "In Use" /* IN_USE */ };
22013
22018
  const passKeyId = typeof pk === "string" || pk instanceof import_mongodb58.ObjectId ? pk : pk.keyId;
22014
22019
  await KeyRepo.updateKeyById(
22015
22020
  passKeyId,
@@ -22035,6 +22040,52 @@ function useVisitorTransactionService() {
22035
22040
  const session = import_node_server_utils101.useAtlas.getClient()?.startSession();
22036
22041
  session?.startTransaction();
22037
22042
  try {
22043
+ if (Array.isArray(value.visitorPass) && value.visitorPass.length > 0) {
22044
+ const keptVisitorPass = [];
22045
+ for (const vp of value.visitorPass) {
22046
+ const updatePayload = {
22047
+ ...vp.status && { status: vp.status },
22048
+ ...vp.remarks && { remarks: vp.remarks }
22049
+ };
22050
+ const visitorPassId = typeof vp === "string" || vp instanceof import_mongodb58.ObjectId ? vp : vp.keyId;
22051
+ await KeyRepo.updateKeyById(
22052
+ visitorPassId,
22053
+ updatePayload,
22054
+ value.site
22055
+ );
22056
+ if (typeof vp !== "string" && !(vp instanceof import_mongodb58.ObjectId)) {
22057
+ keptVisitorPass.push({
22058
+ keyId: new import_mongodb58.ObjectId(visitorPassId)
22059
+ });
22060
+ }
22061
+ }
22062
+ value.visitorPass = keptVisitorPass;
22063
+ }
22064
+ if (value.passKeys && Array.isArray(value.passKeys) && value.passKeys.length > 0) {
22065
+ const keptPassKeys = [];
22066
+ for (const pk of value.passKeys) {
22067
+ try {
22068
+ const updatePayload = {
22069
+ ...pk.status && { status: pk.status },
22070
+ ...pk.remarks && { remarks: pk.remarks }
22071
+ };
22072
+ const passKeyId = typeof pk === "string" || pk instanceof import_mongodb58.ObjectId ? pk : pk.keyId;
22073
+ await KeyRepo.updateKeyById(
22074
+ passKeyId,
22075
+ updatePayload,
22076
+ value.site
22077
+ );
22078
+ if (typeof pk !== "string" && !(pk instanceof import_mongodb58.ObjectId)) {
22079
+ keptPassKeys.push({
22080
+ keyId: new import_mongodb58.ObjectId(passKeyId)
22081
+ });
22082
+ }
22083
+ } catch (error) {
22084
+ throw error;
22085
+ }
22086
+ }
22087
+ value.passKeys = keptPassKeys;
22088
+ }
22038
22089
  await _updateVisitorTansactionById(id, value, session);
22039
22090
  await session?.commitTransaction();
22040
22091
  return "Successfully updated visitor transaction.";
@@ -23013,7 +23064,8 @@ function usePersonController() {
23013
23064
  getPeopleByUnit: _getPeopleByUnit,
23014
23065
  getCompany: _getCompany,
23015
23066
  getPeopleByPlateNumber: _getPeopleByPlateNumber,
23016
- getPeopleByNRIC: _getPeopleByNRIC
23067
+ getPeopleByNRIC: _getPeopleByNRIC,
23068
+ getByUserId: _getByUserId
23017
23069
  } = usePersonRepo();
23018
23070
  const { add: _add, updateById: _updateById } = usePersonService();
23019
23071
  async function add(req, res, next) {
@@ -23312,6 +23364,25 @@ function usePersonController() {
23312
23364
  return;
23313
23365
  }
23314
23366
  }
23367
+ async function getPersonByUserId(req, res, next) {
23368
+ const validation = import_joi58.default.string().required();
23369
+ const userId = req.params.userId;
23370
+ const { error } = validation.validate(userId);
23371
+ if (error) {
23372
+ import_node_server_utils107.logger.log({ level: "error", message: error.message });
23373
+ next(new import_node_server_utils107.BadRequestError(error.message));
23374
+ return;
23375
+ }
23376
+ try {
23377
+ const data = await _getByUserId(userId);
23378
+ res.json(data);
23379
+ return;
23380
+ } catch (error2) {
23381
+ import_node_server_utils107.logger.log({ level: "error", message: error2.message });
23382
+ next(error2);
23383
+ return;
23384
+ }
23385
+ }
23315
23386
  return {
23316
23387
  add,
23317
23388
  getAll,
@@ -23322,7 +23393,8 @@ function usePersonController() {
23322
23393
  getPeopleByUnit,
23323
23394
  getCompany,
23324
23395
  getPeopleByPlateNumber,
23325
- getPeopleByNRIC
23396
+ getPeopleByNRIC,
23397
+ getPersonByUserId
23326
23398
  };
23327
23399
  }
23328
23400
 
@@ -30875,6 +30947,95 @@ function useSiteUnitBillingRepo() {
30875
30947
  throw error;
30876
30948
  }
30877
30949
  }
30950
+ async function getResidentUserBilling({
30951
+ search = "",
30952
+ page = 1,
30953
+ limit = 10,
30954
+ sort = {},
30955
+ status = "active",
30956
+ site = "",
30957
+ paymentStatus = "awaiting_payment",
30958
+ month,
30959
+ year,
30960
+ unitId
30961
+ }, session) {
30962
+ page = page > 0 ? page - 1 : 0;
30963
+ let dateExpr = {};
30964
+ if (month && year) {
30965
+ const monthNum = parseInt(month, 10);
30966
+ const yearNum = parseInt(year, 10);
30967
+ const startDate = new Date(yearNum, monthNum - 1, 1);
30968
+ const endDate = new Date(yearNum, monthNum, 1);
30969
+ dateExpr.createdAt = {
30970
+ $gte: startDate,
30971
+ $lt: endDate
30972
+ };
30973
+ }
30974
+ const unitSearchRegex = search ? search.trim().replace(/\s+/g, "").replace(/\//g, "\\s*/\\s*") : null;
30975
+ const query = {
30976
+ paymentStatus,
30977
+ status,
30978
+ ...search && {
30979
+ $or: [
30980
+ { unitOwner: { $regex: search, $options: "i" } },
30981
+ { billName: { $regex: search, $options: "i" } },
30982
+ { unit: { $regex: unitSearchRegex, $options: "i" } },
30983
+ {
30984
+ $expr: {
30985
+ $regexMatch: {
30986
+ input: { $toString: "$amountPaid" },
30987
+ regex: search,
30988
+ options: "i"
30989
+ }
30990
+ }
30991
+ }
30992
+ ]
30993
+ },
30994
+ ...import_mongodb86.ObjectId.isValid(site) && { site: new import_mongodb86.ObjectId(site) },
30995
+ ...dateExpr,
30996
+ ...import_mongodb86.ObjectId.isValid(unitId) && { unitId: new import_mongodb86.ObjectId(unitId) }
30997
+ };
30998
+ sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
30999
+ try {
31000
+ const basePipeline = [
31001
+ { $match: query },
31002
+ { $sort: sort },
31003
+ { $skip: page * limit },
31004
+ { $limit: limit },
31005
+ {
31006
+ $lookup: {
31007
+ from: "site.billing.items",
31008
+ localField: "billItem",
31009
+ foreignField: "_id",
31010
+ pipeline: [
31011
+ {
31012
+ $project: {
31013
+ _id: 1,
31014
+ totalAmount: 1
31015
+ }
31016
+ }
31017
+ ],
31018
+ as: "billDetails"
31019
+ }
31020
+ },
31021
+ {
31022
+ $unwind: {
31023
+ path: "$billDetails",
31024
+ preserveNullAndEmptyArrays: true
31025
+ }
31026
+ }
31027
+ ];
31028
+ const [items, countResult] = await Promise.all([
31029
+ collection.aggregate(basePipeline, { session }).toArray(),
31030
+ collection.aggregate([{ $match: query }, { $count: "total" }], { session }).toArray()
31031
+ ]);
31032
+ const totalCount = countResult[0]?.total || 0;
31033
+ const data = (0, import_node_server_utils149.paginate)(items, page, limit, totalCount);
31034
+ return data;
31035
+ } catch (error) {
31036
+ throw error;
31037
+ }
31038
+ }
30878
31039
  function delCachedData() {
30879
31040
  delNamespace().then(() => {
30880
31041
  import_node_server_utils149.logger.log({
@@ -30906,7 +31067,8 @@ function useSiteUnitBillingRepo() {
30906
31067
  getById,
30907
31068
  updateById,
30908
31069
  deleteById,
30909
- getUnitBillingBySite
31070
+ getUnitBillingBySite,
31071
+ getResidentUserBilling
30910
31072
  };
30911
31073
  }
30912
31074
 
@@ -31093,7 +31255,8 @@ function useSiteUnitBillingController() {
31093
31255
  getAll: _getAll,
31094
31256
  updateById: _updateById,
31095
31257
  deleteById: _deleteById,
31096
- getById: _getById
31258
+ getById: _getById,
31259
+ getResidentUserBilling: _getResidentUserBilling
31097
31260
  } = useSiteUnitBillingRepo();
31098
31261
  async function add(req, res, next) {
31099
31262
  const data = { ...req.body };
@@ -31234,12 +31397,64 @@ function useSiteUnitBillingController() {
31234
31397
  return;
31235
31398
  }
31236
31399
  }
31400
+ async function getResidentUserBilling(req, res, next) {
31401
+ const validation = import_joi84.default.object({
31402
+ page: import_joi84.default.number().integer().min(1).allow("", null).default(1),
31403
+ limit: import_joi84.default.number().integer().min(1).max(100).allow("", null).default(10),
31404
+ status: import_joi84.default.string().optional().allow(null, ""),
31405
+ search: import_joi84.default.string().optional().allow(null, ""),
31406
+ site: import_joi84.default.string().required(),
31407
+ paymentStatus: import_joi84.default.string().optional().allow(null, ""),
31408
+ month: import_joi84.default.string().optional().allow(null, ""),
31409
+ year: import_joi84.default.string().optional().allow(null, ""),
31410
+ unitId: import_joi84.default.string().optional().allow(null, "")
31411
+ });
31412
+ const query = { ...req.query };
31413
+ const { error } = validation.validate(query, {
31414
+ abortEarly: false
31415
+ });
31416
+ if (error) {
31417
+ const messages = error.details.map((d) => d.message).join(", ");
31418
+ import_node_server_utils151.logger.log({ level: "error", message: messages });
31419
+ next(new import_node_server_utils151.BadRequestError(messages));
31420
+ return;
31421
+ }
31422
+ const search = req.query.search ?? "";
31423
+ const page = parseInt(req.query.page ?? "1");
31424
+ const limit = parseInt(req.query.limit ?? "10");
31425
+ const status = req.query.status ?? "active";
31426
+ const site = req.query.site;
31427
+ const paymentStatus = req.query.paymentStatus ?? "awaiting_payment";
31428
+ const month = req.query.month ?? "";
31429
+ const year = req.query.year ?? "";
31430
+ const unitId = req.query.unitId ?? "";
31431
+ try {
31432
+ const data = await _getResidentUserBilling({
31433
+ search,
31434
+ page,
31435
+ limit,
31436
+ status,
31437
+ site,
31438
+ paymentStatus,
31439
+ month,
31440
+ year,
31441
+ unitId
31442
+ });
31443
+ res.status(200).json(data);
31444
+ return;
31445
+ } catch (error2) {
31446
+ import_node_server_utils151.logger.log({ level: "error", message: error2.message });
31447
+ next(error2);
31448
+ return;
31449
+ }
31450
+ }
31237
31451
  return {
31238
31452
  add,
31239
31453
  getAll,
31240
31454
  getById,
31241
31455
  updateById,
31242
- deleteById
31456
+ deleteById,
31457
+ getResidentUserBilling
31243
31458
  };
31244
31459
  }
31245
31460