@7365admin1/core 3.34.4-staging.18 → 3.34.4-staging.19

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.d.ts CHANGED
@@ -2625,7 +2625,7 @@ type TGetAttendancesQuery = {
2625
2625
  startDate?: string | Date;
2626
2626
  endDate?: string | Date;
2627
2627
  } & Pick<TAttendance, "site" | "serviceType">;
2628
- type TGetAttendancesByUserQuery = Pick<TGetAttendancesQuery, "page" | "limit" | "search" | "site" | "serviceType"> & Pick<TAttendance, "user">;
2628
+ type TGetAttendancesByUserQuery = Pick<TGetAttendancesQuery, "page" | "limit" | "search" | "site" | "serviceType" | "startDate" | "endDate"> & Pick<TAttendance, "user">;
2629
2629
  declare const attendanceSchema: Joi.ObjectSchema<any>;
2630
2630
  declare function MAttendance(value: TAttendance): {
2631
2631
  site: string | ObjectId;
@@ -2685,7 +2685,7 @@ declare function useAttendanceRepository(): {
2685
2685
  createIndex: () => Promise<void>;
2686
2686
  checkInAttendance: (value: TAttendanceCheckIn, session?: ClientSession) => Promise<ObjectId>;
2687
2687
  getAllAttendances: ({ page, limit, search, site, startDate, endDate, serviceType, }: TGetAttendancesQuery) => Promise<{}>;
2688
- getAttendanceByUser: ({ page, limit, search, site, serviceType, user, }: TGetAttendancesByUserQuery) => Promise<{}>;
2688
+ getAttendanceByUser: ({ page, limit, search, site, startDate, endDate, serviceType, user, }: TGetAttendancesByUserQuery) => Promise<{}>;
2689
2689
  getAttendanceById: (_id: string | ObjectId, session?: ClientSession) => Promise<{}>;
2690
2690
  getRawAttendanceById: (_id: string | ObjectId, session?: ClientSession) => Promise<TAttendance>;
2691
2691
  checkOutAttendance: (_id: string | ObjectId, value: TAttendanceCheckOut, session?: ClientSession) => Promise<number>;
package/dist/index.js CHANGED
@@ -33211,6 +33211,8 @@ function useAttendanceRepository() {
33211
33211
  limit = 10,
33212
33212
  search = "",
33213
33213
  site,
33214
+ startDate = "",
33215
+ endDate = "",
33214
33216
  serviceType,
33215
33217
  user
33216
33218
  }) {
@@ -33238,6 +33240,37 @@ function useAttendanceRepository() {
33238
33240
  if (search) {
33239
33241
  cacheOptions.search = search;
33240
33242
  }
33243
+ const singaporeTz = "Asia/Singapore";
33244
+ const normalizedStartDate = typeof startDate === "string" ? startDate : (0, import_moment.default)(startDate).tz(singaporeTz).format("YYYY-MM-DD");
33245
+ const normalizedEndDate = typeof endDate === "string" ? endDate : (0, import_moment.default)(endDate).tz(singaporeTz).format("YYYY-MM-DD");
33246
+ if (startDate && endDate) {
33247
+ const startOfDay = import_moment.default.tz(normalizedStartDate, "YYYY-MM-DD", singaporeTz).startOf("day").toDate();
33248
+ const endOfDay = import_moment.default.tz(normalizedEndDate, "YYYY-MM-DD", singaporeTz).endOf("day").toDate();
33249
+ query.$expr = {
33250
+ $and: [
33251
+ { $gte: [{ $toDate: "$checkIn.timestamp" }, startOfDay] },
33252
+ { $lte: [{ $toDate: "$checkIn.timestamp" }, endOfDay] }
33253
+ ]
33254
+ };
33255
+ cacheOptions.startDate = normalizedStartDate;
33256
+ cacheOptions.endDate = normalizedEndDate;
33257
+ } else if (startDate) {
33258
+ query.$expr = {
33259
+ $gte: [
33260
+ { $toDate: "$checkIn.timestamp" },
33261
+ import_moment.default.tz(normalizedStartDate, "YYYY-MM-DD", singaporeTz).startOf("day").toDate()
33262
+ ]
33263
+ };
33264
+ cacheOptions.startDate = normalizedStartDate;
33265
+ } else if (endDate) {
33266
+ query.$expr = {
33267
+ $lte: [
33268
+ { $toDate: "$checkIn.timestamp" },
33269
+ import_moment.default.tz(normalizedEndDate, "YYYY-MM-DD", singaporeTz).endOf("day").toDate()
33270
+ ]
33271
+ };
33272
+ cacheOptions.endDate = normalizedEndDate;
33273
+ }
33241
33274
  const cacheKey = (0, import_node_server_utils103.makeCacheKey)(namespace_collection, cacheOptions);
33242
33275
  const cachedData = await getCache(cacheKey);
33243
33276
  if (cachedData) {
@@ -33683,6 +33716,8 @@ function useAttendanceController() {
33683
33716
  search: import_joi56.default.string().optional().allow("", null),
33684
33717
  site: import_joi56.default.string().hex().required(),
33685
33718
  serviceType: import_joi56.default.string().valid(...Object.values(AppServiceType)).required(),
33719
+ dateFrom: import_joi56.default.alternatives().try(import_joi56.default.date(), import_joi56.default.string()).optional().allow("", null),
33720
+ dateTo: import_joi56.default.alternatives().try(import_joi56.default.date(), import_joi56.default.string()).optional().allow("", null),
33686
33721
  user: import_joi56.default.string().hex().required()
33687
33722
  });
33688
33723
  const { error } = validation.validate(query);
@@ -33696,6 +33731,8 @@ function useAttendanceController() {
33696
33731
  const search = req.query.search ?? "";
33697
33732
  const site = req.params.site ?? "";
33698
33733
  const serviceType = req.query.serviceType ?? "";
33734
+ const startDate = req.query.dateFrom ?? "";
33735
+ const endDate = req.query.dateTo ?? "";
33699
33736
  try {
33700
33737
  const data = await _getAttendanceByUser({
33701
33738
  page,
@@ -33703,7 +33740,9 @@ function useAttendanceController() {
33703
33740
  search,
33704
33741
  site,
33705
33742
  serviceType,
33706
- user
33743
+ user,
33744
+ startDate,
33745
+ endDate
33707
33746
  });
33708
33747
  res.json(data);
33709
33748
  return;