@7365admin1/core 3.9.0 → 3.10.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
+ ## 3.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - da700a5: release changes for preloved api, push notification, tec.
8
+
3
9
  ## 3.9.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -6096,31 +6096,34 @@ declare function useNewDashboardRepo(): {
6096
6096
  workOrder: number;
6097
6097
  taskCompleted: number;
6098
6098
  }[]>;
6099
- getServiceTodayTaskSchedule: ({ site, serviceType, page, limit, }: {
6099
+ getServiceTodayTaskSchedule: ({ site, serviceType, page, limit, period, }: {
6100
6100
  site: string | ObjectId;
6101
6101
  serviceType: TAppServiceType;
6102
6102
  page?: number | undefined;
6103
6103
  limit?: number | undefined;
6104
+ period?: Period | undefined;
6104
6105
  }) => Promise<{
6105
6106
  items: any[];
6106
6107
  pages: number;
6107
6108
  pageRange: string;
6108
6109
  }>;
6109
- getServiceStaffAttendance: ({ site, serviceType, page, limit, }: {
6110
+ getServiceStaffAttendance: ({ site, serviceType, page, limit, period, }: {
6110
6111
  site: string | ObjectId;
6111
6112
  serviceType: TAppServiceType;
6112
6113
  page?: number | undefined;
6113
6114
  limit?: number | undefined;
6115
+ period?: Period | undefined;
6114
6116
  }) => Promise<{
6115
6117
  items: any[];
6116
6118
  pages: number;
6117
6119
  pageRange: string;
6118
6120
  }>;
6119
- getServiceRecentFeedbacks: ({ site, serviceType, page, limit, }: {
6121
+ getServiceRecentFeedbacks: ({ site, serviceType, page, limit, period, }: {
6120
6122
  site: string | ObjectId;
6121
6123
  serviceType: TAppServiceType;
6122
6124
  page?: number | undefined;
6123
6125
  limit?: number | undefined;
6126
+ period?: Period | undefined;
6124
6127
  }) => Promise<{
6125
6128
  items: any[];
6126
6129
  pages: number;
@@ -7375,11 +7378,13 @@ declare function MBidPreloved(value: TBidPreloved): {
7375
7378
 
7376
7379
  declare function useBidPrelovedRepo(): {
7377
7380
  add: (value: TBidPreloved, session?: any) => Promise<string | ObjectId>;
7381
+ getById: (_id: string | ObjectId) => Promise<mongodb.WithId<TBidPreloved>>;
7378
7382
  updateStatus: (_id: string | ObjectId, status: BidStatus) => Promise<string>;
7379
7383
  };
7380
7384
 
7381
7385
  declare function useBidPrelovedController(): {
7382
7386
  add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
7387
+ getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
7383
7388
  updateStatus: (req: Request, res: Response, next: NextFunction) => Promise<void>;
7384
7389
  };
7385
7390
 
@@ -7467,7 +7472,7 @@ declare function useFormEntryRepo(): {
7467
7472
  createTextIndex: () => Promise<void>;
7468
7473
  deleteOnlineFormById: (_id: string | ObjectId, session?: ClientSession) => Promise<number>;
7469
7474
  addResidentForm: (value: residentFormEntry, session?: ClientSession) => Promise<ObjectId>;
7470
- residentForm: ({ userId, site, org }: {
7475
+ residentForm: ({ userId, site, org, }: {
7471
7476
  userId: string;
7472
7477
  site: string | ObjectId;
7473
7478
  org: string | ObjectId;
package/dist/index.js CHANGED
@@ -33692,7 +33692,7 @@ async function send(userIds, title, body, data, isForMAMobileApp = false, appSlu
33692
33692
  if (isForMAMobileApp) {
33693
33693
  tokens = await PushTokenRepo.findTokensByUserIds(userIds, appSlug);
33694
33694
  } else {
33695
- tokens = await PushTokenRepo.findTokensByUserIds(userIds);
33695
+ tokens = await PushTokenRepo.findTokensByUserIds(userIds, appSlug);
33696
33696
  }
33697
33697
  if (!tokens.length)
33698
33698
  return;
@@ -33740,6 +33740,37 @@ var NotificationService = class {
33740
33740
  "iservice365-resident-mobile-app"
33741
33741
  );
33742
33742
  }
33743
+ static async onlineFormRequestStatusUpdated(payload) {
33744
+ let screen = "";
33745
+ let params = {};
33746
+ if (payload.status === "pending" || payload.status === "resubmission") {
33747
+ screen = "/(user)/(online-forms)/form-fill";
33748
+ params = {
33749
+ id: payload.onlineFormId.toString(),
33750
+ submissionStatus: payload.status ?? ""
33751
+ };
33752
+ } else {
33753
+ screen = "/(user)/(online-forms)/submission-detail";
33754
+ params = {
33755
+ id: payload.onlineFormId.toString(),
33756
+ status: payload.status ?? ""
33757
+ };
33758
+ }
33759
+ await send(
33760
+ toStringArray(payload.to),
33761
+ "Online Form",
33762
+ `Your online form has been updated to ${payload.status}.`,
33763
+ {
33764
+ onlineFormId: payload.onlineFormId.toString(),
33765
+ status: payload.status,
33766
+ module: "onlineForm",
33767
+ screen,
33768
+ params: JSON.stringify(params)
33769
+ },
33770
+ false,
33771
+ "iservice365-resident-mobile-app"
33772
+ );
33773
+ }
33743
33774
  static async bulletinBoardCreatedForMA(payload) {
33744
33775
  await send(
33745
33776
  toStringArray(payload.to),
@@ -57770,7 +57801,8 @@ function useNewDashboardRepo() {
57770
57801
  site,
57771
57802
  serviceType,
57772
57803
  page = 1,
57773
- limit = 10
57804
+ limit = 10,
57805
+ period = "today" /* TODAY */
57774
57806
  }) {
57775
57807
  page = page > 0 ? page - 1 : 0;
57776
57808
  const cacheOptions = { serviceType, page, limit };
@@ -57780,9 +57812,7 @@ function useNewDashboardRepo() {
57780
57812
  } catch {
57781
57813
  throw new import_node_server_utils199.BadRequestError("Invalid site ID format.");
57782
57814
  }
57783
- const todayStart = import_moment.default.tz("Asia/Singapore").startOf("day").toDate();
57784
- const todayEnd = import_moment.default.tz("Asia/Singapore").endOf("day").toDate();
57785
- const todayRange = { $gte: todayStart, $lte: todayEnd };
57815
+ const todayRange = getDateRange(period);
57786
57816
  try {
57787
57817
  const [items, countResult] = await Promise.all([
57788
57818
  areaChecklistCollection.aggregate([
@@ -57858,7 +57888,8 @@ function useNewDashboardRepo() {
57858
57888
  site,
57859
57889
  serviceType,
57860
57890
  page = 1,
57861
- limit = 10
57891
+ limit = 10,
57892
+ period = "today" /* TODAY */
57862
57893
  }) {
57863
57894
  page = page > 0 ? page - 1 : 0;
57864
57895
  const cacheOptions = { serviceType, page, limit };
@@ -57868,8 +57899,9 @@ function useNewDashboardRepo() {
57868
57899
  } catch {
57869
57900
  throw new import_node_server_utils199.BadRequestError("Invalid site ID format.");
57870
57901
  }
57871
- const todayStart = import_moment.default.tz("Asia/Singapore").startOf("day").toDate();
57872
- const todayEnd = import_moment.default.tz("Asia/Singapore").endOf("day").toDate();
57902
+ const periodRange = getDateRange(period);
57903
+ const todayStart = periodRange.$gte;
57904
+ const todayEnd = periodRange.$lte;
57873
57905
  const todayStartStr = todayStart.toISOString();
57874
57906
  const todayEndStr = todayEnd.toISOString();
57875
57907
  try {
@@ -57986,7 +58018,8 @@ function useNewDashboardRepo() {
57986
58018
  site,
57987
58019
  serviceType,
57988
58020
  page = 1,
57989
- limit = 10
58021
+ limit = 10,
58022
+ period = "today" /* TODAY */
57990
58023
  }) {
57991
58024
  page = page > 0 ? page - 1 : 0;
57992
58025
  const cacheOptions = { serviceType, page, limit };
@@ -57997,10 +58030,14 @@ function useNewDashboardRepo() {
57997
58030
  throw new import_node_server_utils199.BadRequestError("Invalid site ID format.");
57998
58031
  }
57999
58032
  const workOrderService = workOrderServiceMap[serviceType] ?? serviceType;
58033
+ const matchQuery = { site, service: workOrderService };
58034
+ if (period) {
58035
+ matchQuery.createdAt = getDateRange(period);
58036
+ }
58000
58037
  try {
58001
58038
  const [items, length] = await Promise.all([
58002
58039
  feedbackCollection.aggregate([
58003
- { $match: { site, service: workOrderService } },
58040
+ { $match: matchQuery },
58004
58041
  { $sort: { createdAt: -1, _id: -1 } },
58005
58042
  {
58006
58043
  $lookup: {
@@ -58023,7 +58060,7 @@ function useNewDashboardRepo() {
58023
58060
  { $skip: page * limit },
58024
58061
  { $limit: limit }
58025
58062
  ]).toArray(),
58026
- feedbackCollection.countDocuments({ site, service: workOrderService })
58063
+ feedbackCollection.countDocuments(matchQuery)
58027
58064
  ]);
58028
58065
  const data = (0, import_node_server_utils199.paginate)(items, page, limit, length);
58029
58066
  return data;
@@ -58183,6 +58220,7 @@ function useNewDashboardController() {
58183
58220
  const validation = import_joi112.default.object({
58184
58221
  site: import_joi112.default.string().hex().required(),
58185
58222
  serviceType: import_joi112.default.string().valid(...Object.values(AppServiceType)).required(),
58223
+ period: import_joi112.default.string().valid(...Object.values(Period)).default("today" /* TODAY */),
58186
58224
  page: import_joi112.default.number().min(1).optional().allow("", null),
58187
58225
  limit: import_joi112.default.number().min(1).optional().allow("", null)
58188
58226
  });
@@ -58194,12 +58232,14 @@ function useNewDashboardController() {
58194
58232
  }
58195
58233
  const site = req.params.site;
58196
58234
  const serviceType = req.params.serviceType;
58235
+ const period = req.query.period;
58197
58236
  const page = parseInt(req.query.page) ?? 1;
58198
58237
  const limit = parseInt(req.query.limit) ?? 10;
58199
58238
  try {
58200
58239
  const data = await _getServiceTodayTaskSchedule({
58201
58240
  site,
58202
58241
  serviceType,
58242
+ period,
58203
58243
  page,
58204
58244
  limit
58205
58245
  });
@@ -58216,6 +58256,7 @@ function useNewDashboardController() {
58216
58256
  const validation = import_joi112.default.object({
58217
58257
  site: import_joi112.default.string().hex().required(),
58218
58258
  serviceType: import_joi112.default.string().valid(...Object.values(AppServiceType)).required(),
58259
+ period: import_joi112.default.string().valid(...Object.values(Period)).default("today" /* TODAY */),
58219
58260
  page: import_joi112.default.number().min(1).optional().allow("", null),
58220
58261
  limit: import_joi112.default.number().min(1).optional().allow("", null)
58221
58262
  });
@@ -58227,12 +58268,14 @@ function useNewDashboardController() {
58227
58268
  }
58228
58269
  const site = req.params.site;
58229
58270
  const serviceType = req.params.serviceType;
58271
+ const period = req.query.period;
58230
58272
  const page = parseInt(req.query.page) ?? 1;
58231
58273
  const limit = parseInt(req.query.limit) ?? 10;
58232
58274
  try {
58233
58275
  const data = await _getServiceStaffAttendance({
58234
58276
  site,
58235
58277
  serviceType,
58278
+ period,
58236
58279
  page,
58237
58280
  limit
58238
58281
  });
@@ -58249,6 +58292,7 @@ function useNewDashboardController() {
58249
58292
  const validation = import_joi112.default.object({
58250
58293
  site: import_joi112.default.string().hex().required(),
58251
58294
  serviceType: import_joi112.default.string().valid(...Object.values(AppServiceType)).required(),
58295
+ period: import_joi112.default.string().valid(...Object.values(Period)).default("today" /* TODAY */),
58252
58296
  page: import_joi112.default.number().min(1).optional().allow("", null),
58253
58297
  limit: import_joi112.default.number().min(1).optional().allow("", null)
58254
58298
  });
@@ -58260,12 +58304,14 @@ function useNewDashboardController() {
58260
58304
  }
58261
58305
  const site = req.params.site;
58262
58306
  const serviceType = req.params.serviceType;
58307
+ const period = req.query.period;
58263
58308
  const page = parseInt(req.query.page) ?? 1;
58264
58309
  const limit = parseInt(req.query.limit) ?? 10;
58265
58310
  try {
58266
58311
  const data = await _getServiceRecentFeedbacks({
58267
58312
  site,
58268
58313
  serviceType,
58314
+ period,
58269
58315
  page,
58270
58316
  limit
58271
58317
  });
@@ -66798,14 +66844,26 @@ function useBidPrelovedRepo() {
66798
66844
  throw new import_node_server_utils250.InternalServerError("Unable to update bid.");
66799
66845
  return "Bid updated successfully.";
66800
66846
  }
66801
- return { add, updateStatus };
66847
+ async function getById(_id) {
66848
+ if (typeof _id === "string")
66849
+ _id = new import_mongodb150.ObjectId(_id);
66850
+ const result = await collection.findOne({ _id });
66851
+ if (!result)
66852
+ throw new import_node_server_utils250.NotFoundError("Bid not found.");
66853
+ return result;
66854
+ }
66855
+ return { add, getById, updateStatus };
66802
66856
  }
66803
66857
 
66804
66858
  // src/controllers/bid-preloved.controller.ts
66805
66859
  var import_node_server_utils251 = require("@7365admin1/node-server-utils");
66806
66860
  var import_joi146 = __toESM(require("joi"));
66807
66861
  function useBidPrelovedController() {
66808
- const { add: _add, updateStatus: _updateStatus } = useBidPrelovedRepo();
66862
+ const {
66863
+ add: _add,
66864
+ getById: _getById,
66865
+ updateStatus: _updateStatus
66866
+ } = useBidPrelovedRepo();
66809
66867
  async function add(req, res, next) {
66810
66868
  const { error, value } = schemaBidPreloved.validate(req.body, {
66811
66869
  abortEarly: false
@@ -66852,7 +66910,25 @@ function useBidPrelovedController() {
66852
66910
  next(error);
66853
66911
  }
66854
66912
  }
66855
- return { add, updateStatus };
66913
+ async function getById(req, res, next) {
66914
+ const paramsSchema = import_joi146.default.object({
66915
+ id: import_joi146.default.string().hex().length(24).required()
66916
+ });
66917
+ const { error, value: params } = paramsSchema.validate(req.params);
66918
+ if (error) {
66919
+ import_node_server_utils251.logger.log({ level: "error", message: error.message });
66920
+ next(new import_node_server_utils251.BadRequestError(error.message));
66921
+ return;
66922
+ }
66923
+ try {
66924
+ const data = await _getById(params.id);
66925
+ res.status(200).json(data);
66926
+ } catch (error2) {
66927
+ import_node_server_utils251.logger.log({ level: "error", message: error2.message });
66928
+ next(error2);
66929
+ }
66930
+ }
66931
+ return { add, getById, updateStatus };
66856
66932
  }
66857
66933
 
66858
66934
  // src/models/online-forms-v2.model.ts
@@ -66996,6 +67072,7 @@ function useFormEntryRepo() {
66996
67072
  const { delNamespace, getCache, setCache } = (0, import_node_server_utils252.useCache)(
66997
67073
  online_forms_namespace_collection
66998
67074
  );
67075
+ const { getUserById } = useUserRepo();
66999
67076
  async function createTextIndex() {
67000
67077
  try {
67001
67078
  await collection.createIndex({
@@ -67149,6 +67226,26 @@ function useFormEntryRepo() {
67149
67226
  if (res.modifiedCount === 0) {
67150
67227
  throw new import_node_server_utils252.InternalServerError("Unable to update online form.");
67151
67228
  }
67229
+ const onlineFormRequest = await collection.findOne({ _id });
67230
+ if (!onlineFormRequest) {
67231
+ throw new import_node_server_utils252.NotFoundError("Online form not found.");
67232
+ }
67233
+ const user = await getUserById(onlineFormRequest.userId.toString());
67234
+ if (!user || !user._id) {
67235
+ throw new import_node_server_utils252.NotFoundError("User not found.");
67236
+ }
67237
+ const userId = user._id.toString();
67238
+ await NotificationService.onlineFormRequestStatusUpdated({
67239
+ to: userId,
67240
+ onlineFormId: onlineFormRequest._id,
67241
+ // typeOfForm: onlineFormRequest.typeOfForm,
67242
+ // unitNumber: onlineFormRequest.unitNumber,
67243
+ status: onlineFormRequest.status
67244
+ // createdAt: onlineFormRequest.createdAt ?? "",
67245
+ // fields: onlineFormRequest.fields ?? {},
67246
+ // remarks: onlineFormRequest.remarks ?? "",
67247
+ // managementValuesJson: onlineFormRequest.managementValues ?? {},
67248
+ });
67152
67249
  delNamespace().then(() => {
67153
67250
  import_node_server_utils252.logger.info(
67154
67251
  `Cache cleared for namespace: ${online_forms_namespace_collection}`
@@ -67185,7 +67282,9 @@ function useFormEntryRepo() {
67185
67282
  throw new import_node_server_utils252.InternalServerError("Unable to delete online form.");
67186
67283
  }
67187
67284
  delNamespace().then(() => {
67188
- import_node_server_utils252.logger.info(`Cache cleared for namespace: ${online_forms_namespace_collection}`);
67285
+ import_node_server_utils252.logger.info(
67286
+ `Cache cleared for namespace: ${online_forms_namespace_collection}`
67287
+ );
67189
67288
  }).catch((err) => {
67190
67289
  import_node_server_utils252.logger.error(
67191
67290
  `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
@@ -67222,7 +67321,11 @@ function useFormEntryRepo() {
67222
67321
  throw error;
67223
67322
  }
67224
67323
  }
67225
- async function residentForm({ userId, site, org }) {
67324
+ async function residentForm({
67325
+ userId,
67326
+ site,
67327
+ org
67328
+ }) {
67226
67329
  try {
67227
67330
  const user = new import_mongodb152.ObjectId(userId);
67228
67331
  const siteId = new import_mongodb152.ObjectId(site);