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

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
@@ -26986,7 +26986,8 @@ function useVehicleService() {
26986
26986
  throw new Error("Unable to start session for vehicle service.");
26987
26987
  }
26988
26988
  }
26989
- const [_vehiclePlateNumber] = value.plateNumber;
26989
+ const plateNumbers = Array.isArray(value.plateNumber) ? value.plateNumber : value.plateNumber ? [value.plateNumber] : [];
26990
+ const [_vehiclePlateNumber] = plateNumbers;
26990
26991
  const [existingPlateNumber, org] = await Promise.all([
26991
26992
  _getVehicleByPlateNumber(_vehiclePlateNumber),
26992
26993
  _getById(value.org)
@@ -27051,7 +27052,6 @@ function useVehicleService() {
27051
27052
  }
27052
27053
  }
27053
27054
  const owner = value.name;
27054
- const plateNumbers = value.plateNumber;
27055
27055
  try {
27056
27056
  if (!isExternalSession) {
27057
27057
  session.startTransaction();
@@ -27268,7 +27268,10 @@ function useVehicleService() {
27268
27268
  const dahuaResponse = await _addPlateNumber(dahuaPayload);
27269
27269
  if (dahuaResponse?.statusCode != 200) {
27270
27270
  console.log("dahuaResponse", dahuaResponse);
27271
- console.log("approveVehicleById dahuaResponse dahuaResponse?.statusCode != 200", dahuaResponse?.statusCode);
27271
+ console.log(
27272
+ "approveVehicleById dahuaResponse dahuaResponse?.statusCode != 200",
27273
+ dahuaResponse?.statusCode
27274
+ );
27272
27275
  throw new import_node_server_utils78.BadRequestError("Failed to add plate number to ANPR");
27273
27276
  }
27274
27277
  const responseData = dahuaResponse?.data.toString("utf-8");
@@ -27475,7 +27478,19 @@ function useVehicleService() {
27475
27478
  if (value.peopleId) {
27476
27479
  value.peopleId = new import_mongodb49.ObjectId(value.peopleId);
27477
27480
  }
27478
- const { name, plateNumber, start, end, recNo, type, unit, site, block, level, ...rest } = value;
27481
+ const {
27482
+ name,
27483
+ plateNumber,
27484
+ start,
27485
+ end,
27486
+ recNo,
27487
+ type,
27488
+ unit,
27489
+ site,
27490
+ block,
27491
+ level,
27492
+ ...rest
27493
+ } = value;
27479
27494
  if (_name != name || _plateNumber != plateNumber) {
27480
27495
  const startDahua = value.start ? formatDahuaDate(new Date(value.start)) : formatDahuaDate(new Date(_start));
27481
27496
  const endDahua = value.end ? formatDahuaDate(new Date(value.end)) : formatDahuaDate(new Date(_end));
@@ -27502,7 +27517,11 @@ function useVehicleService() {
27502
27517
  for (const camera of siteCameras) {
27503
27518
  const { host, username, password } = camera;
27504
27519
  if (_plateNumber != plateNumber) {
27505
- console.log("updateVehicleById _plateNumber != plateNumber", _plateNumber, plateNumber);
27520
+ console.log(
27521
+ "updateVehicleById _plateNumber != plateNumber",
27522
+ _plateNumber,
27523
+ plateNumber
27524
+ );
27506
27525
  const removePlateNumber = {
27507
27526
  host,
27508
27527
  username,
@@ -27549,7 +27568,11 @@ function useVehicleService() {
27549
27568
  );
27550
27569
  }
27551
27570
  } else {
27552
- console.log("updateVehicleById _plateNumber == plateNumber", _plateNumber, plateNumber);
27571
+ console.log(
27572
+ "updateVehicleById _plateNumber == plateNumber",
27573
+ _plateNumber,
27574
+ plateNumber
27575
+ );
27553
27576
  const dahuaPayload = {
27554
27577
  host,
27555
27578
  username,
@@ -32939,6 +32962,7 @@ function MAttendance(value) {
32939
32962
  // src/repositories/attendance.repository.ts
32940
32963
  var import_mongodb60 = require("mongodb");
32941
32964
  var import_node_server_utils103 = require("@7365admin1/node-server-utils");
32965
+ var import_moment = __toESM(require("moment"));
32942
32966
  function useAttendanceRepository() {
32943
32967
  const db = import_node_server_utils103.useAtlas.getDb();
32944
32968
  if (!db) {
@@ -32980,6 +33004,8 @@ function useAttendanceRepository() {
32980
33004
  limit = 10,
32981
33005
  search = "",
32982
33006
  site,
33007
+ startDate = "",
33008
+ endDate = "",
32983
33009
  serviceType
32984
33010
  }) {
32985
33011
  page = page > 0 ? page - 1 : 0;
@@ -32999,6 +33025,37 @@ function useAttendanceRepository() {
32999
33025
  if (search) {
33000
33026
  cacheOptions.search = search;
33001
33027
  }
33028
+ const singaporeTz = "Asia/Singapore";
33029
+ const normalizedStartDate = typeof startDate === "string" ? startDate : (0, import_moment.default)(startDate).tz(singaporeTz).format("YYYY-MM-DD");
33030
+ const normalizedEndDate = typeof endDate === "string" ? endDate : (0, import_moment.default)(endDate).tz(singaporeTz).format("YYYY-MM-DD");
33031
+ if (startDate && endDate) {
33032
+ const startOfDay = import_moment.default.tz(normalizedStartDate, "YYYY-MM-DD", singaporeTz).startOf("day").toDate();
33033
+ const endOfDay = import_moment.default.tz(normalizedEndDate, "YYYY-MM-DD", singaporeTz).endOf("day").toDate();
33034
+ query.$expr = {
33035
+ $and: [
33036
+ { $gte: [{ $toDate: "$checkIn.timestamp" }, startOfDay] },
33037
+ { $lte: [{ $toDate: "$checkIn.timestamp" }, endOfDay] }
33038
+ ]
33039
+ };
33040
+ cacheOptions.startDate = normalizedStartDate;
33041
+ cacheOptions.endDate = normalizedEndDate;
33042
+ } else if (startDate) {
33043
+ query.$expr = {
33044
+ $gte: [
33045
+ { $toDate: "$checkIn.timestamp" },
33046
+ import_moment.default.tz(normalizedStartDate, "YYYY-MM-DD", singaporeTz).startOf("day").toDate()
33047
+ ]
33048
+ };
33049
+ cacheOptions.startDate = normalizedStartDate;
33050
+ } else if (endDate) {
33051
+ query.$expr = {
33052
+ $lte: [
33053
+ { $toDate: "$checkIn.timestamp" },
33054
+ import_moment.default.tz(normalizedEndDate, "YYYY-MM-DD", singaporeTz).endOf("day").toDate()
33055
+ ]
33056
+ };
33057
+ cacheOptions.endDate = normalizedEndDate;
33058
+ }
33002
33059
  const cacheKey = (0, import_node_server_utils103.makeCacheKey)(namespace_collection, cacheOptions);
33003
33060
  const cachedData = await getCache(cacheKey);
33004
33061
  if (cachedData) {
@@ -33500,7 +33557,9 @@ function useAttendanceController() {
33500
33557
  limit: import_joi56.default.number().min(1).optional().allow("", null),
33501
33558
  search: import_joi56.default.string().optional().allow("", null),
33502
33559
  site: import_joi56.default.string().hex().required(),
33503
- serviceType: import_joi56.default.string().valid(...Object.values(AppServiceType)).required()
33560
+ serviceType: import_joi56.default.string().valid(...Object.values(AppServiceType)).required(),
33561
+ dateFrom: import_joi56.default.alternatives().try(import_joi56.default.date(), import_joi56.default.string()).optional().allow("", null),
33562
+ dateTo: import_joi56.default.alternatives().try(import_joi56.default.date(), import_joi56.default.string()).optional().allow("", null)
33504
33563
  });
33505
33564
  const { error } = validation.validate(query);
33506
33565
  if (error) {
@@ -33513,13 +33572,17 @@ function useAttendanceController() {
33513
33572
  const search = req.query.search ?? "";
33514
33573
  const site = req.params.site ?? "";
33515
33574
  const serviceType = req.query.serviceType ?? "";
33575
+ const startDate = req.query.dateFrom ?? "";
33576
+ const endDate = req.query.dateTo ?? "";
33516
33577
  try {
33517
33578
  const data = await _getAllAttendances({
33518
33579
  page,
33519
33580
  limit,
33520
33581
  search,
33521
33582
  site,
33522
- serviceType
33583
+ serviceType,
33584
+ startDate,
33585
+ endDate
33523
33586
  });
33524
33587
  res.json(data);
33525
33588
  return;
@@ -58769,7 +58832,7 @@ function useNfcPatrolLogController() {
58769
58832
  // src/repositories/new-dashboard.repo.ts
58770
58833
  var import_node_server_utils201 = require("@7365admin1/node-server-utils");
58771
58834
  var import_mongodb122 = require("mongodb");
58772
- var import_moment = __toESM(require("moment"));
58835
+ var import_moment2 = __toESM(require("moment"));
58773
58836
  var Period = /* @__PURE__ */ ((Period2) => {
58774
58837
  Period2["TODAY"] = "today";
58775
58838
  Period2["THIS_WEEK"] = "thisWeek";
@@ -58806,7 +58869,7 @@ function useNewDashboardRepo() {
58806
58869
  const dateWithoutTimezone = date.replace(/\s*\+\d{2}:\d{2}$/, "");
58807
58870
  date = new Date(dateWithoutTimezone);
58808
58871
  }
58809
- const singaporeMoment = import_moment.default.tz(date, "Asia/Singapore");
58872
+ const singaporeMoment = import_moment2.default.tz(date, "Asia/Singapore");
58810
58873
  singaporeMoment.set({
58811
58874
  hour: 23,
58812
58875
  minute: 59,
@@ -58816,7 +58879,7 @@ function useNewDashboardRepo() {
58816
58879
  return singaporeMoment.toDate();
58817
58880
  }
58818
58881
  function getDateRange(p) {
58819
- const now = (0, import_moment.default)().tz("Asia/Singapore");
58882
+ const now = (0, import_moment2.default)().tz("Asia/Singapore");
58820
58883
  if (p === "thisWeek" /* THIS_WEEK */) {
58821
58884
  return {
58822
58885
  $gte: now.clone().startOf("isoWeek").toDate(),
@@ -58834,7 +58897,7 @@ function useNewDashboardRepo() {
58834
58897
  $lte: now.clone().endOf("day").toDate()
58835
58898
  };
58836
58899
  }
58837
- function getSiteDayRange(date = import_moment.default.tz("Asia/Singapore")) {
58900
+ function getSiteDayRange(date = import_moment2.default.tz("Asia/Singapore")) {
58838
58901
  return {
58839
58902
  $gte: date.clone().startOf("day").toDate(),
58840
58903
  $lte: date.clone().endOf("day").toDate()
@@ -59105,8 +59168,8 @@ function useNewDashboardRepo() {
59105
59168
  const todayCompliance = tTotal > 0 ? tCompleted / tTotal * 100 : 0;
59106
59169
  let activePatrolItems = [];
59107
59170
  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();
59171
+ const todayString = import_moment2.default.tz("Asia/Singapore").format("YYYY-MM-DD");
59172
+ const dayIndex = import_moment2.default.tz("Asia/Singapore").day();
59110
59173
  const repeatDay = dayIndex === 0 ? 7 : dayIndex;
59111
59174
  const routes = await db.collection("patrol.route").find({
59112
59175
  site: { $in: [siteIdObj, siteId] },
@@ -59158,12 +59221,12 @@ function useNewDashboardRepo() {
59158
59221
  status = "completed";
59159
59222
  }
59160
59223
  } else {
59161
- const routeTime = import_moment.default.tz(
59224
+ const routeTime = import_moment2.default.tz(
59162
59225
  `${todayString} ${startTime}`,
59163
59226
  "YYYY-MM-DD HH:mm",
59164
59227
  "Asia/Singapore"
59165
59228
  );
59166
- const nowSg = import_moment.default.tz("Asia/Singapore");
59229
+ const nowSg = import_moment2.default.tz("Asia/Singapore");
59167
59230
  const diffMinutes = nowSg.diff(routeTime, "minutes");
59168
59231
  if (diffMinutes >= 0) {
59169
59232
  if (diffMinutes <= 120) {
@@ -59211,8 +59274,8 @@ function useNewDashboardRepo() {
59211
59274
  if (log.status) {
59212
59275
  status = Array.isArray(log.status) ? log.status.join(", ") : log.status;
59213
59276
  }
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");
59277
+ const logTime = (0, import_moment2.default)(log.createdAt).tz("Asia/Singapore").format("HH:mm");
59278
+ const logDate = (0, import_moment2.default)(log.createdAt).tz("Asia/Singapore").format("DD/MM/YYYY");
59216
59279
  return {
59217
59280
  id: log._id.toString(),
59218
59281
  title: log.name,
@@ -59264,11 +59327,11 @@ function useNewDashboardRepo() {
59264
59327
  }
59265
59328
  async function getPropertyManagementDashboard(siteId, period = "today" /* TODAY */, type, facility) {
59266
59329
  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();
59330
+ const startOfToday = import_moment2.default.tz("Asia/Singapore").startOf("day").toDate();
59331
+ const endOfToday = import_moment2.default.tz("Asia/Singapore").endOf("day").toDate();
59269
59332
  const facilityTodayRange = getSiteDayRange();
59270
59333
  const facilityYesterdayRange = getSiteDayRange(
59271
- import_moment.default.tz("Asia/Singapore").subtract(1, "day")
59334
+ import_moment2.default.tz("Asia/Singapore").subtract(1, "day")
59272
59335
  );
59273
59336
  const facilityTodayStart = facilityTodayRange.$gte;
59274
59337
  const facilityTodayEnd = facilityTodayRange.$lte;
@@ -59280,13 +59343,13 @@ function useNewDashboardRepo() {
59280
59343
  };
59281
59344
  if (period === "thisWeek" /* THIS_WEEK */) {
59282
59345
  facilityPeriodRange = {
59283
- $gte: import_moment.default.tz("Asia/Singapore").startOf("isoWeek").toDate(),
59284
- $lte: import_moment.default.tz("Asia/Singapore").endOf("isoWeek").toDate()
59346
+ $gte: import_moment2.default.tz("Asia/Singapore").startOf("isoWeek").toDate(),
59347
+ $lte: import_moment2.default.tz("Asia/Singapore").endOf("isoWeek").toDate()
59285
59348
  };
59286
59349
  } else if (period === "thisMonth" /* THIS_MONTH */) {
59287
59350
  facilityPeriodRange = {
59288
- $gte: import_moment.default.tz("Asia/Singapore").startOf("month").toDate(),
59289
- $lte: import_moment.default.tz("Asia/Singapore").endOf("month").toDate()
59351
+ $gte: import_moment2.default.tz("Asia/Singapore").startOf("month").toDate(),
59352
+ $lte: import_moment2.default.tz("Asia/Singapore").endOf("month").toDate()
59290
59353
  };
59291
59354
  }
59292
59355
  const upcomingEvents = await db.collection(events_namespace_collection).find({
@@ -59918,28 +59981,28 @@ function useNewDashboardRepo() {
59918
59981
  let labels = [];
59919
59982
  let getIntervalIndex;
59920
59983
  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();
59984
+ rangeStart = import_moment2.default.tz("Asia/Singapore").startOf("day").toDate();
59985
+ rangeEnd = import_moment2.default.tz("Asia/Singapore").endOf("day").toDate();
59923
59986
  labels = ["12 AM", "4 AM", "8 AM", "12 PM", "4 PM", "8 PM"];
59924
59987
  getIntervalIndex = (date) => {
59925
- const hour = (0, import_moment.default)(date).tz("Asia/Singapore").hour();
59988
+ const hour = (0, import_moment2.default)(date).tz("Asia/Singapore").hour();
59926
59989
  return Math.floor(hour / 4);
59927
59990
  };
59928
59991
  } 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();
59992
+ rangeStart = import_moment2.default.tz("Asia/Singapore").startOf("isoWeek").toDate();
59993
+ rangeEnd = import_moment2.default.tz("Asia/Singapore").endOf("isoWeek").toDate();
59931
59994
  labels = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
59932
59995
  getIntervalIndex = (date) => {
59933
- const day = (0, import_moment.default)(date).tz("Asia/Singapore").isoWeekday();
59996
+ const day = (0, import_moment2.default)(date).tz("Asia/Singapore").isoWeekday();
59934
59997
  return day - 1;
59935
59998
  };
59936
59999
  } 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();
60000
+ rangeStart = import_moment2.default.tz("Asia/Singapore").startOf("month").toDate();
60001
+ rangeEnd = import_moment2.default.tz("Asia/Singapore").endOf("month").toDate();
60002
+ const daysInMonth = import_moment2.default.tz("Asia/Singapore").daysInMonth();
59940
60003
  labels = Array.from({ length: daysInMonth }, (_, i) => String(i + 1));
59941
60004
  getIntervalIndex = (date) => {
59942
- return (0, import_moment.default)(date).tz("Asia/Singapore").date() - 1;
60005
+ return (0, import_moment2.default)(date).tz("Asia/Singapore").date() - 1;
59943
60006
  };
59944
60007
  } else {
59945
60008
  throw new import_node_server_utils201.BadRequestError("Invalid period.");