@7365admin1/core 3.32.2-staging.1 → 3.32.2-staging.2

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
@@ -2622,6 +2622,8 @@ type TGetAttendancesQuery = {
2622
2622
  page?: number;
2623
2623
  limit?: number;
2624
2624
  search?: string;
2625
+ startDate?: string | Date;
2626
+ endDate?: string | Date;
2625
2627
  } & Pick<TAttendance, "site" | "serviceType">;
2626
2628
  type TGetAttendancesByUserQuery = Pick<TGetAttendancesQuery, "page" | "limit" | "search" | "site" | "serviceType"> & Pick<TAttendance, "user">;
2627
2629
  declare const attendanceSchema: Joi.ObjectSchema<any>;
@@ -2682,7 +2684,7 @@ declare function useAttendanceSettingsController(): {
2682
2684
  declare function useAttendanceRepository(): {
2683
2685
  createIndex: () => Promise<void>;
2684
2686
  checkInAttendance: (value: TAttendanceCheckIn, session?: ClientSession) => Promise<ObjectId>;
2685
- getAllAttendances: ({ page, limit, search, site, serviceType, }: TGetAttendancesQuery) => Promise<{}>;
2687
+ getAllAttendances: ({ page, limit, search, site, startDate, endDate, serviceType, }: TGetAttendancesQuery) => Promise<{}>;
2686
2688
  getAttendanceByUser: ({ page, limit, search, site, serviceType, user, }: TGetAttendancesByUserQuery) => Promise<{}>;
2687
2689
  getAttendanceById: (_id: string | ObjectId, session?: ClientSession) => Promise<{}>;
2688
2690
  getRawAttendanceById: (_id: string | ObjectId, session?: ClientSession) => Promise<TAttendance>;
package/dist/index.js CHANGED
@@ -32939,6 +32939,7 @@ function MAttendance(value) {
32939
32939
  // src/repositories/attendance.repository.ts
32940
32940
  var import_mongodb60 = require("mongodb");
32941
32941
  var import_node_server_utils103 = require("@7365admin1/node-server-utils");
32942
+ var import_moment = __toESM(require("moment"));
32942
32943
  function useAttendanceRepository() {
32943
32944
  const db = import_node_server_utils103.useAtlas.getDb();
32944
32945
  if (!db) {
@@ -32980,6 +32981,8 @@ function useAttendanceRepository() {
32980
32981
  limit = 10,
32981
32982
  search = "",
32982
32983
  site,
32984
+ startDate = "",
32985
+ endDate = "",
32983
32986
  serviceType
32984
32987
  }) {
32985
32988
  page = page > 0 ? page - 1 : 0;
@@ -32999,6 +33002,37 @@ function useAttendanceRepository() {
32999
33002
  if (search) {
33000
33003
  cacheOptions.search = search;
33001
33004
  }
33005
+ const singaporeTz = "Asia/Singapore";
33006
+ const normalizedStartDate = typeof startDate === "string" ? startDate : (0, import_moment.default)(startDate).tz(singaporeTz).format("YYYY-MM-DD");
33007
+ const normalizedEndDate = typeof endDate === "string" ? endDate : (0, import_moment.default)(endDate).tz(singaporeTz).format("YYYY-MM-DD");
33008
+ if (startDate && endDate) {
33009
+ const startOfDay = import_moment.default.tz(normalizedStartDate, "YYYY-MM-DD", singaporeTz).startOf("day").toDate();
33010
+ const endOfDay = import_moment.default.tz(normalizedEndDate, "YYYY-MM-DD", singaporeTz).endOf("day").toDate();
33011
+ query.$expr = {
33012
+ $and: [
33013
+ { $gte: [{ $toDate: "$checkIn.timestamp" }, startOfDay] },
33014
+ { $lte: [{ $toDate: "$checkIn.timestamp" }, endOfDay] }
33015
+ ]
33016
+ };
33017
+ cacheOptions.startDate = normalizedStartDate;
33018
+ cacheOptions.endDate = normalizedEndDate;
33019
+ } else if (startDate) {
33020
+ query.$expr = {
33021
+ $gte: [
33022
+ { $toDate: "$checkIn.timestamp" },
33023
+ import_moment.default.tz(normalizedStartDate, "YYYY-MM-DD", singaporeTz).startOf("day").toDate()
33024
+ ]
33025
+ };
33026
+ cacheOptions.startDate = normalizedStartDate;
33027
+ } else if (endDate) {
33028
+ query.$expr = {
33029
+ $lte: [
33030
+ { $toDate: "$checkIn.timestamp" },
33031
+ import_moment.default.tz(normalizedEndDate, "YYYY-MM-DD", singaporeTz).endOf("day").toDate()
33032
+ ]
33033
+ };
33034
+ cacheOptions.endDate = normalizedEndDate;
33035
+ }
33002
33036
  const cacheKey = (0, import_node_server_utils103.makeCacheKey)(namespace_collection, cacheOptions);
33003
33037
  const cachedData = await getCache(cacheKey);
33004
33038
  if (cachedData) {
@@ -33500,7 +33534,9 @@ function useAttendanceController() {
33500
33534
  limit: import_joi56.default.number().min(1).optional().allow("", null),
33501
33535
  search: import_joi56.default.string().optional().allow("", null),
33502
33536
  site: import_joi56.default.string().hex().required(),
33503
- serviceType: import_joi56.default.string().valid(...Object.values(AppServiceType)).required()
33537
+ serviceType: import_joi56.default.string().valid(...Object.values(AppServiceType)).required(),
33538
+ dateFrom: import_joi56.default.alternatives().try(import_joi56.default.date(), import_joi56.default.string()).optional().allow("", null),
33539
+ dateTo: import_joi56.default.alternatives().try(import_joi56.default.date(), import_joi56.default.string()).optional().allow("", null)
33504
33540
  });
33505
33541
  const { error } = validation.validate(query);
33506
33542
  if (error) {
@@ -33513,13 +33549,17 @@ function useAttendanceController() {
33513
33549
  const search = req.query.search ?? "";
33514
33550
  const site = req.params.site ?? "";
33515
33551
  const serviceType = req.query.serviceType ?? "";
33552
+ const startDate = req.query.dateFrom ?? "";
33553
+ const endDate = req.query.dateTo ?? "";
33516
33554
  try {
33517
33555
  const data = await _getAllAttendances({
33518
33556
  page,
33519
33557
  limit,
33520
33558
  search,
33521
33559
  site,
33522
- serviceType
33560
+ serviceType,
33561
+ startDate,
33562
+ endDate
33523
33563
  });
33524
33564
  res.json(data);
33525
33565
  return;
@@ -58769,7 +58809,7 @@ function useNfcPatrolLogController() {
58769
58809
  // src/repositories/new-dashboard.repo.ts
58770
58810
  var import_node_server_utils201 = require("@7365admin1/node-server-utils");
58771
58811
  var import_mongodb122 = require("mongodb");
58772
- var import_moment = __toESM(require("moment"));
58812
+ var import_moment2 = __toESM(require("moment"));
58773
58813
  var Period = /* @__PURE__ */ ((Period2) => {
58774
58814
  Period2["TODAY"] = "today";
58775
58815
  Period2["THIS_WEEK"] = "thisWeek";
@@ -58806,7 +58846,7 @@ function useNewDashboardRepo() {
58806
58846
  const dateWithoutTimezone = date.replace(/\s*\+\d{2}:\d{2}$/, "");
58807
58847
  date = new Date(dateWithoutTimezone);
58808
58848
  }
58809
- const singaporeMoment = import_moment.default.tz(date, "Asia/Singapore");
58849
+ const singaporeMoment = import_moment2.default.tz(date, "Asia/Singapore");
58810
58850
  singaporeMoment.set({
58811
58851
  hour: 23,
58812
58852
  minute: 59,
@@ -58816,7 +58856,7 @@ function useNewDashboardRepo() {
58816
58856
  return singaporeMoment.toDate();
58817
58857
  }
58818
58858
  function getDateRange(p) {
58819
- const now = (0, import_moment.default)().tz("Asia/Singapore");
58859
+ const now = (0, import_moment2.default)().tz("Asia/Singapore");
58820
58860
  if (p === "thisWeek" /* THIS_WEEK */) {
58821
58861
  return {
58822
58862
  $gte: now.clone().startOf("isoWeek").toDate(),
@@ -58834,7 +58874,7 @@ function useNewDashboardRepo() {
58834
58874
  $lte: now.clone().endOf("day").toDate()
58835
58875
  };
58836
58876
  }
58837
- function getSiteDayRange(date = import_moment.default.tz("Asia/Singapore")) {
58877
+ function getSiteDayRange(date = import_moment2.default.tz("Asia/Singapore")) {
58838
58878
  return {
58839
58879
  $gte: date.clone().startOf("day").toDate(),
58840
58880
  $lte: date.clone().endOf("day").toDate()
@@ -59105,8 +59145,8 @@ function useNewDashboardRepo() {
59105
59145
  const todayCompliance = tTotal > 0 ? tCompleted / tTotal * 100 : 0;
59106
59146
  let activePatrolItems = [];
59107
59147
  if (period === "today" /* TODAY */) {
59108
- const todayString = import_moment.default.tz("Asia/Singapore").format("YYYY-MM-DD");
59109
- const dayIndex = import_moment.default.tz("Asia/Singapore").day();
59148
+ const todayString = import_moment2.default.tz("Asia/Singapore").format("YYYY-MM-DD");
59149
+ const dayIndex = import_moment2.default.tz("Asia/Singapore").day();
59110
59150
  const repeatDay = dayIndex === 0 ? 7 : dayIndex;
59111
59151
  const routes = await db.collection("patrol.route").find({
59112
59152
  site: { $in: [siteIdObj, siteId] },
@@ -59158,12 +59198,12 @@ function useNewDashboardRepo() {
59158
59198
  status = "completed";
59159
59199
  }
59160
59200
  } else {
59161
- const routeTime = import_moment.default.tz(
59201
+ const routeTime = import_moment2.default.tz(
59162
59202
  `${todayString} ${startTime}`,
59163
59203
  "YYYY-MM-DD HH:mm",
59164
59204
  "Asia/Singapore"
59165
59205
  );
59166
- const nowSg = import_moment.default.tz("Asia/Singapore");
59206
+ const nowSg = import_moment2.default.tz("Asia/Singapore");
59167
59207
  const diffMinutes = nowSg.diff(routeTime, "minutes");
59168
59208
  if (diffMinutes >= 0) {
59169
59209
  if (diffMinutes <= 120) {
@@ -59211,8 +59251,8 @@ function useNewDashboardRepo() {
59211
59251
  if (log.status) {
59212
59252
  status = Array.isArray(log.status) ? log.status.join(", ") : log.status;
59213
59253
  }
59214
- const logTime = (0, import_moment.default)(log.createdAt).tz("Asia/Singapore").format("HH:mm");
59215
- const logDate = (0, import_moment.default)(log.createdAt).tz("Asia/Singapore").format("DD/MM/YYYY");
59254
+ const logTime = (0, import_moment2.default)(log.createdAt).tz("Asia/Singapore").format("HH:mm");
59255
+ const logDate = (0, import_moment2.default)(log.createdAt).tz("Asia/Singapore").format("DD/MM/YYYY");
59216
59256
  return {
59217
59257
  id: log._id.toString(),
59218
59258
  title: log.name,
@@ -59264,11 +59304,11 @@ function useNewDashboardRepo() {
59264
59304
  }
59265
59305
  async function getPropertyManagementDashboard(siteId, period = "today" /* TODAY */, type, facility) {
59266
59306
  const siteIdObj = (0, import_node_server_utils201.toObjectId)(siteId);
59267
- const startOfToday = import_moment.default.tz("Asia/Singapore").startOf("day").toDate();
59268
- const endOfToday = import_moment.default.tz("Asia/Singapore").endOf("day").toDate();
59307
+ const startOfToday = import_moment2.default.tz("Asia/Singapore").startOf("day").toDate();
59308
+ const endOfToday = import_moment2.default.tz("Asia/Singapore").endOf("day").toDate();
59269
59309
  const facilityTodayRange = getSiteDayRange();
59270
59310
  const facilityYesterdayRange = getSiteDayRange(
59271
- import_moment.default.tz("Asia/Singapore").subtract(1, "day")
59311
+ import_moment2.default.tz("Asia/Singapore").subtract(1, "day")
59272
59312
  );
59273
59313
  const facilityTodayStart = facilityTodayRange.$gte;
59274
59314
  const facilityTodayEnd = facilityTodayRange.$lte;
@@ -59280,13 +59320,13 @@ function useNewDashboardRepo() {
59280
59320
  };
59281
59321
  if (period === "thisWeek" /* THIS_WEEK */) {
59282
59322
  facilityPeriodRange = {
59283
- $gte: import_moment.default.tz("Asia/Singapore").startOf("isoWeek").toDate(),
59284
- $lte: import_moment.default.tz("Asia/Singapore").endOf("isoWeek").toDate()
59323
+ $gte: import_moment2.default.tz("Asia/Singapore").startOf("isoWeek").toDate(),
59324
+ $lte: import_moment2.default.tz("Asia/Singapore").endOf("isoWeek").toDate()
59285
59325
  };
59286
59326
  } else if (period === "thisMonth" /* THIS_MONTH */) {
59287
59327
  facilityPeriodRange = {
59288
- $gte: import_moment.default.tz("Asia/Singapore").startOf("month").toDate(),
59289
- $lte: import_moment.default.tz("Asia/Singapore").endOf("month").toDate()
59328
+ $gte: import_moment2.default.tz("Asia/Singapore").startOf("month").toDate(),
59329
+ $lte: import_moment2.default.tz("Asia/Singapore").endOf("month").toDate()
59290
59330
  };
59291
59331
  }
59292
59332
  const upcomingEvents = await db.collection(events_namespace_collection).find({
@@ -59918,28 +59958,28 @@ function useNewDashboardRepo() {
59918
59958
  let labels = [];
59919
59959
  let getIntervalIndex;
59920
59960
  if (period === "today" /* TODAY */) {
59921
- rangeStart = import_moment.default.tz("Asia/Singapore").startOf("day").toDate();
59922
- rangeEnd = import_moment.default.tz("Asia/Singapore").endOf("day").toDate();
59961
+ rangeStart = import_moment2.default.tz("Asia/Singapore").startOf("day").toDate();
59962
+ rangeEnd = import_moment2.default.tz("Asia/Singapore").endOf("day").toDate();
59923
59963
  labels = ["12 AM", "4 AM", "8 AM", "12 PM", "4 PM", "8 PM"];
59924
59964
  getIntervalIndex = (date) => {
59925
- const hour = (0, import_moment.default)(date).tz("Asia/Singapore").hour();
59965
+ const hour = (0, import_moment2.default)(date).tz("Asia/Singapore").hour();
59926
59966
  return Math.floor(hour / 4);
59927
59967
  };
59928
59968
  } else if (period === "thisWeek" /* THIS_WEEK */) {
59929
- rangeStart = import_moment.default.tz("Asia/Singapore").startOf("isoWeek").toDate();
59930
- rangeEnd = import_moment.default.tz("Asia/Singapore").endOf("isoWeek").toDate();
59969
+ rangeStart = import_moment2.default.tz("Asia/Singapore").startOf("isoWeek").toDate();
59970
+ rangeEnd = import_moment2.default.tz("Asia/Singapore").endOf("isoWeek").toDate();
59931
59971
  labels = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
59932
59972
  getIntervalIndex = (date) => {
59933
- const day = (0, import_moment.default)(date).tz("Asia/Singapore").isoWeekday();
59973
+ const day = (0, import_moment2.default)(date).tz("Asia/Singapore").isoWeekday();
59934
59974
  return day - 1;
59935
59975
  };
59936
59976
  } else if (period === "thisMonth" /* THIS_MONTH */) {
59937
- rangeStart = import_moment.default.tz("Asia/Singapore").startOf("month").toDate();
59938
- rangeEnd = import_moment.default.tz("Asia/Singapore").endOf("month").toDate();
59939
- const daysInMonth = import_moment.default.tz("Asia/Singapore").daysInMonth();
59977
+ rangeStart = import_moment2.default.tz("Asia/Singapore").startOf("month").toDate();
59978
+ rangeEnd = import_moment2.default.tz("Asia/Singapore").endOf("month").toDate();
59979
+ const daysInMonth = import_moment2.default.tz("Asia/Singapore").daysInMonth();
59940
59980
  labels = Array.from({ length: daysInMonth }, (_, i) => String(i + 1));
59941
59981
  getIntervalIndex = (date) => {
59942
- return (0, import_moment.default)(date).tz("Asia/Singapore").date() - 1;
59982
+ return (0, import_moment2.default)(date).tz("Asia/Singapore").date() - 1;
59943
59983
  };
59944
59984
  } else {
59945
59985
  throw new import_node_server_utils201.BadRequestError("Invalid period.");