@7365admin1/core 3.34.2 → 3.34.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.mjs CHANGED
@@ -8747,6 +8747,9 @@ var MAILER_TRANSPORT_SECURE = process.env.MAILER_TRANSPORT_SECURE === "true";
8747
8747
  var MAILER_EMAIL = process.env.MAILER_EMAIL ?? "default@gmail.com";
8748
8748
  var MAILER_PASSWORD = process.env.MAILER_PASSWORD ?? "password";
8749
8749
  var MAILER_FROM_EMAIL = process.env.MAILER_FROM_EMAIL || void 0;
8750
+ var MANPOWER_ALERT_DAILY_LIMIT = Number(
8751
+ process.env.MANPOWER_ALERT_DAILY_LIMIT ?? 50
8752
+ );
8750
8753
  var ACCESS_TOKEN_SECRET = process.env.ACCESS_TOKEN_SECRET ?? "access_token_secret";
8751
8754
  var REFRESH_TOKEN_SECRET = process.env.REFRESH_TOKEN_SECRET ?? "refresh_token_secret";
8752
8755
  var ACCESS_TOKEN_EXPIRY = process.env.ACCESS_TOKEN_EXPIRY ?? "15s";
@@ -63976,6 +63979,7 @@ function useManpowerSitesCtrl() {
63976
63979
  import {
63977
63980
  useAtlas as useAtlas111,
63978
63981
  useMailer as useMailer4,
63982
+ useCache as useCache67,
63979
63983
  compileHandlebar as compileHandlebar4,
63980
63984
  getDirectory as getDirectory4,
63981
63985
  logger as logger178
@@ -64006,7 +64010,16 @@ var createManpowerRemarksDaily = async () => {
64006
64010
  serviceProviderId: servideProvider._id,
64007
64011
  status: "active"
64008
64012
  }).toArray();
64013
+ const existingToday = await remarks.find({ createdAtSGT: nowSGT.format("DD-MM-YYYY") }).project({ siteId: 1 }).toArray();
64014
+ const skipSiteIds = new Set(
64015
+ existingToday.map((doc) => doc.siteId.toString())
64016
+ );
64009
64017
  for (const site of remark) {
64018
+ const siteKey = site.siteId.toString();
64019
+ if (skipSiteIds.has(siteKey)) {
64020
+ continue;
64021
+ }
64022
+ skipSiteIds.add(siteKey);
64010
64023
  const existingRemark = await settings.findOne({
64011
64024
  siteId: site.siteId,
64012
64025
  enabled: true
@@ -64073,7 +64086,7 @@ var createManpowerRemarksDaily = async () => {
64073
64086
  }
64074
64087
  }
64075
64088
  if (items.length > 0) {
64076
- await remarks.insertMany(items);
64089
+ await remarks.insertMany(items, { ordered: false });
64077
64090
  }
64078
64091
  console.log("Daily manpower remarks created successfully.");
64079
64092
  } catch (error) {
@@ -64137,12 +64150,30 @@ var updateRemarksisAcknowledged = async () => {
64137
64150
  },
64138
64151
  { $set: { "remarks.2.remark.isAcknowledged": false } }
64139
64152
  );
64153
+ const { getCache, setCache } = useCache67("manpower-alerts");
64154
+ const capKey = `manpower-alert-count:${nowSGT}`;
64155
+ let sentToday = await getCache(capKey) ?? 0;
64156
+ const emailedSites = /* @__PURE__ */ new Set();
64140
64157
  for (const id of updatedIds) {
64141
64158
  const doc = await remarks.findOne({ _id: id });
64159
+ const docSiteKey = doc?.siteId?.toString() ?? "";
64160
+ if (emailedSites.has(docSiteKey)) {
64161
+ continue;
64162
+ }
64142
64163
  const setting = await settings.findOne(
64143
64164
  { siteId: new ObjectId131(doc?.siteId) },
64144
64165
  { projection: { emails: 1 } }
64145
64166
  );
64167
+ if (!setting?.emails?.length) {
64168
+ continue;
64169
+ }
64170
+ if (sentToday >= MANPOWER_ALERT_DAILY_LIMIT) {
64171
+ logger178.log({
64172
+ level: "warn",
64173
+ message: `Manpower alert daily limit (${MANPOWER_ALERT_DAILY_LIMIT}) reached, skipping remaining alerts for ${nowSGT}`
64174
+ });
64175
+ break;
64176
+ }
64146
64177
  const payload = {
64147
64178
  startDate: doc?.createdAtSGT,
64148
64179
  endDate: doc?.createdAtSGT,
@@ -64183,6 +64214,9 @@ var updateRemarksisAcknowledged = async () => {
64183
64214
  expected,
64184
64215
  status: newStatus
64185
64216
  });
64217
+ emailedSites.add(docSiteKey);
64218
+ sentToday++;
64219
+ await setCache(capKey, sentToday, 86400);
64186
64220
  }
64187
64221
  } catch (error) {
64188
64222
  console.error("Error updating remarks:", error);
@@ -65741,7 +65775,7 @@ import {
65741
65775
  comparePassword as comparePassword3,
65742
65776
  InternalServerError as InternalServerError72,
65743
65777
  NotFoundError as NotFoundError55,
65744
- useCache as useCache68
65778
+ useCache as useCache69
65745
65779
  } from "@7365admin1/node-server-utils";
65746
65780
  import { v4 as uuidv42 } from "uuid";
65747
65781
 
@@ -65755,7 +65789,7 @@ import {
65755
65789
  paginate as paginate60,
65756
65790
  NotFoundError as NotFoundError54,
65757
65791
  AppError as AppError29,
65758
- useCache as useCache67,
65792
+ useCache as useCache68,
65759
65793
  makeCacheKey as makeCacheKey65,
65760
65794
  toObjectId as toObjectId20
65761
65795
  } from "@7365admin1/node-server-utils";
@@ -65769,7 +65803,7 @@ function useUserRepoV2() {
65769
65803
  }
65770
65804
  const namespace_collection = "users";
65771
65805
  const collection = db.collection(namespace_collection);
65772
- const { delNamespace, setCache, getCache, delCache } = useCache67(namespace_collection);
65806
+ const { delNamespace, setCache, getCache, delCache } = useCache68(namespace_collection);
65773
65807
  async function createIndex() {
65774
65808
  try {
65775
65809
  await collection.createIndexes([{ key: { email: 1 } }]);
@@ -66216,7 +66250,7 @@ function useUserRepoV2() {
66216
66250
  function useAuthServiceV2() {
66217
66251
  const { getUserByEmail, getUserById: _getUserById } = useUserRepoV2();
66218
66252
  const expiresIn = "15m";
66219
- const { setCache, delCache } = useCache68("sessions");
66253
+ const { setCache, delCache } = useCache69("sessions");
66220
66254
  const { getByUserIdType } = useMemberRepo();
66221
66255
  async function login({
66222
66256
  email,
@@ -66989,7 +67023,7 @@ import {
66989
67023
  InternalServerError as InternalServerError74,
66990
67024
  useAtlas as useAtlas118,
66991
67025
  logger as logger187,
66992
- useCache as useCache69
67026
+ useCache as useCache70
66993
67027
  } from "@7365admin1/node-server-utils";
66994
67028
  function useRoleRepoV2() {
66995
67029
  const db = useAtlas118.getDb();
@@ -67026,7 +67060,7 @@ function useRoleRepoV2() {
67026
67060
  throw new InternalServerError74("Failed to create unique index on role.");
67027
67061
  }
67028
67062
  }
67029
- const { delNamespace } = useCache69(namespace_collection);
67063
+ const { delNamespace } = useCache70(namespace_collection);
67030
67064
  async function addRole(value, session) {
67031
67065
  value = new MRoleV2(value);
67032
67066
  try {
@@ -69298,7 +69332,7 @@ function useChatPrelovedController() {
69298
69332
 
69299
69333
  // src/events/chat-preloved.event.ts
69300
69334
  import Joi144 from "joi";
69301
- import { logger as logger194, useCache as useCache70 } from "@7365admin1/node-server-utils";
69335
+ import { logger as logger194, useCache as useCache71 } from "@7365admin1/node-server-utils";
69302
69336
  function parseSid(cookieHeader) {
69303
69337
  const match = cookieHeader.match(/(?:^|;\s*)sid=([^;]*)/);
69304
69338
  return match ? decodeURIComponent(match[1]) : null;
@@ -69342,7 +69376,7 @@ function chatPrelovedEvents(io) {
69342
69376
  if (!sid) {
69343
69377
  return next(new Error("Unauthorized"));
69344
69378
  }
69345
- const { getCache } = useCache70("sessions");
69379
+ const { getCache } = useCache71("sessions");
69346
69380
  const sessionData = await getCache(`sid:${sid}`);
69347
69381
  if (!sessionData) {
69348
69382
  return next(new Error("Session expired or invalid"));
@@ -69891,7 +69925,7 @@ import {
69891
69925
  NotFoundError as NotFoundError63,
69892
69926
  paginate as paginate64,
69893
69927
  useAtlas as useAtlas130,
69894
- useCache as useCache71
69928
+ useCache as useCache72
69895
69929
  } from "@7365admin1/node-server-utils";
69896
69930
  import { ObjectId as ObjectId153 } from "mongodb";
69897
69931
  var online_forms_namespace_collection = "online-forms";
@@ -69901,7 +69935,7 @@ function useFormEntryRepo() {
69901
69935
  throw new InternalServerError84("Unable to connect to server.");
69902
69936
  }
69903
69937
  const collection = db.collection(online_forms_namespace_collection);
69904
- const { delNamespace, getCache, setCache } = useCache71(
69938
+ const { delNamespace, getCache, setCache } = useCache72(
69905
69939
  online_forms_namespace_collection
69906
69940
  );
69907
69941
  const { getUserById } = useUserRepo();