@eeplatform/core 1.0.1 → 1.0.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.js CHANGED
@@ -11478,9 +11478,9 @@ function useVerificationRepo() {
11478
11478
  }
11479
11479
  const namespace_collection = "verifications";
11480
11480
  const collection = db.collection(namespace_collection);
11481
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils2.useCache)();
11481
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils2.useCache)(namespace_collection);
11482
11482
  function delCachedData() {
11483
- delNamespace(namespace_collection).then(() => {
11483
+ delNamespace().then(() => {
11484
11484
  import_nodejs_utils2.logger.log({
11485
11485
  level: "info",
11486
11486
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -11568,7 +11568,7 @@ function useVerificationRepo() {
11568
11568
  return cached;
11569
11569
  }
11570
11570
  const data = await collection.findOne({ _id });
11571
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
11571
+ setCache(cacheKey, data, 300).then(() => {
11572
11572
  import_nodejs_utils2.logger.log({
11573
11573
  level: "info",
11574
11574
  message: `Cache set for verification by id: ${cacheKey}`
@@ -11648,7 +11648,7 @@ function useVerificationRepo() {
11648
11648
  ]).toArray();
11649
11649
  const length = await collection.countDocuments(query);
11650
11650
  const data = (0, import_nodejs_utils2.paginate)(items, page, limit, length);
11651
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
11651
+ setCache(cacheKey, data, 600).then(() => {
11652
11652
  import_nodejs_utils2.logger.log({
11653
11653
  level: "info",
11654
11654
  message: `Cache set for getVerifications: ${cacheKey}`
@@ -11679,7 +11679,7 @@ function useVerificationRepo() {
11679
11679
  return cached;
11680
11680
  }
11681
11681
  const data = await collection.find({ type }).toArray();
11682
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
11682
+ setCache(cacheKey, data, 600).then(() => {
11683
11683
  import_nodejs_utils2.logger.log({
11684
11684
  level: "info",
11685
11685
  message: `Cache set for verification by type: ${cacheKey}`
@@ -11804,10 +11804,12 @@ var MUser = class {
11804
11804
  this.createdAt = value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString();
11805
11805
  this.updatedAt = value.updatedAt ?? "";
11806
11806
  this.deletedAt = value.deletedAt ?? "";
11807
- try {
11808
- value.defaultOrg = new import_mongodb3.ObjectId(value.defaultOrg);
11809
- } catch (error) {
11810
- throw new Error("Invalid defaultOrg ID.");
11807
+ if (value.defaultOrg) {
11808
+ try {
11809
+ value.defaultOrg = new import_mongodb3.ObjectId(value.defaultOrg);
11810
+ } catch (error) {
11811
+ throw new Error("Invalid defaultOrg ID.");
11812
+ }
11811
11813
  }
11812
11814
  this.defaultOrg = value.defaultOrg;
11813
11815
  }
@@ -11822,9 +11824,9 @@ function useUserRepo() {
11822
11824
  }
11823
11825
  const namespace_collection = "users";
11824
11826
  const collection = db.collection(namespace_collection);
11825
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils3.useCache)();
11827
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils3.useCache)(namespace_collection);
11826
11828
  function delCachedData() {
11827
- delNamespace(namespace_collection).then(() => {
11829
+ delNamespace().then(() => {
11828
11830
  import_nodejs_utils3.logger.log({
11829
11831
  level: "info",
11830
11832
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -11886,7 +11888,7 @@ function useUserRepo() {
11886
11888
  }
11887
11889
  const result = await collection.findOne({ email });
11888
11890
  if (result) {
11889
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
11891
+ setCache(cacheKey, result, 300).then(() => {
11890
11892
  import_nodejs_utils3.logger.log({
11891
11893
  level: "info",
11892
11894
  message: `Cache set for user by email: ${cacheKey}`
@@ -11916,7 +11918,7 @@ function useUserRepo() {
11916
11918
  }
11917
11919
  const result = await collection.findOne({ referralCode });
11918
11920
  if (result) {
11919
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
11921
+ setCache(cacheKey, result, 300).then(() => {
11920
11922
  import_nodejs_utils3.logger.log({
11921
11923
  level: "info",
11922
11924
  message: `Cache set for user by referral code: ${cacheKey}`
@@ -11951,7 +11953,7 @@ function useUserRepo() {
11951
11953
  }
11952
11954
  const result = await collection.findOne({ _id });
11953
11955
  if (result) {
11954
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
11956
+ setCache(cacheKey, result, 300).then(() => {
11955
11957
  import_nodejs_utils3.logger.log({
11956
11958
  level: "info",
11957
11959
  message: `Cache set for user by id: ${cacheKey}`
@@ -12025,7 +12027,7 @@ function useUserRepo() {
12025
12027
  ]).toArray();
12026
12028
  const length = await collection.countDocuments(query);
12027
12029
  const data = (0, import_nodejs_utils3.paginate)(items, page, limit, length);
12028
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
12030
+ setCache(cacheKey, data, 600).then(() => {
12029
12031
  import_nodejs_utils3.logger.log({
12030
12032
  level: "info",
12031
12033
  message: `Cache set for getUsers: ${cacheKey}`
@@ -12239,9 +12241,9 @@ function useMemberRepo() {
12239
12241
  }
12240
12242
  const namespace_collection = "members";
12241
12243
  const collection = db.collection(namespace_collection);
12242
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils5.useCache)();
12244
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils5.useCache)(namespace_collection);
12243
12245
  function delCachedData() {
12244
- delNamespace(namespace_collection).then(() => {
12246
+ delNamespace().then(() => {
12245
12247
  import_nodejs_utils5.logger.log({
12246
12248
  level: "info",
12247
12249
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -12332,7 +12334,7 @@ function useMemberRepo() {
12332
12334
  return cached;
12333
12335
  }
12334
12336
  const data = await collection.findOne({ _id });
12335
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
12337
+ setCache(cacheKey, data, 300).then(() => {
12336
12338
  import_nodejs_utils5.logger.log({
12337
12339
  level: "info",
12338
12340
  message: `Cache set for member by id: ${cacheKey}`
@@ -12369,7 +12371,7 @@ function useMemberRepo() {
12369
12371
  return cached;
12370
12372
  }
12371
12373
  const data = await collection.findOne({ user });
12372
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
12374
+ setCache(cacheKey, data, 300).then(() => {
12373
12375
  import_nodejs_utils5.logger.log({
12374
12376
  level: "info",
12375
12377
  message: `Cache set for member by user ID: ${cacheKey}`
@@ -12422,7 +12424,7 @@ function useMemberRepo() {
12422
12424
  return cached;
12423
12425
  }
12424
12426
  const data = await collection.findOne(query);
12425
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
12427
+ setCache(cacheKey, data, 300).then(() => {
12426
12428
  import_nodejs_utils5.logger.log({
12427
12429
  level: "info",
12428
12430
  message: `Cache set for member by user ID: ${cacheKey}`
@@ -12526,7 +12528,7 @@ function useMemberRepo() {
12526
12528
  ]).toArray();
12527
12529
  const length = await collection.countDocuments(query);
12528
12530
  const data = (0, import_nodejs_utils5.paginate)(items, page, limit, length);
12529
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
12531
+ setCache(cacheKey, data, 600).then(() => {
12530
12532
  import_nodejs_utils5.logger.log({
12531
12533
  level: "info",
12532
12534
  message: `Cache set for getAll members: ${cacheKey}`
@@ -12561,7 +12563,7 @@ function useMemberRepo() {
12561
12563
  return cached;
12562
12564
  }
12563
12565
  const data = await collection.countDocuments({ org, status: "active" });
12564
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
12566
+ setCache(cacheKey, data, 300).then(() => {
12565
12567
  import_nodejs_utils5.logger.log({
12566
12568
  level: "info",
12567
12569
  message: `Cache set for countByOrg members: ${cacheKey}`
@@ -12598,7 +12600,7 @@ function useMemberRepo() {
12598
12600
  return cached;
12599
12601
  }
12600
12602
  const data = await collection.countDocuments({ user, status: "active" });
12601
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
12603
+ setCache(cacheKey, data, 300).then(() => {
12602
12604
  import_nodejs_utils5.logger.log({
12603
12605
  level: "info",
12604
12606
  message: `Cache set for countByUser members: ${cacheKey}`
@@ -12672,7 +12674,7 @@ function useMemberRepo() {
12672
12674
  ]).toArray();
12673
12675
  const length = await collection.countDocuments(query);
12674
12676
  const data = (0, import_nodejs_utils5.paginate)(items, page, limit, length);
12675
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
12677
+ setCache(cacheKey, data, 600).then(() => {
12676
12678
  import_nodejs_utils5.logger.log({
12677
12679
  level: "info",
12678
12680
  message: `Cache set for getOrgsByMembership members: ${cacheKey}`
@@ -12750,7 +12752,7 @@ function useMemberRepo() {
12750
12752
  ]).toArray();
12751
12753
  const length = await collection.countDocuments(query);
12752
12754
  const data = (0, import_nodejs_utils5.paginate)(items, page, limit, length);
12753
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
12755
+ setCache(cacheKey, data, 300).then(() => {
12754
12756
  import_nodejs_utils5.logger.log({
12755
12757
  level: "info",
12756
12758
  message: `Cache set for getOrgsByUserId members: ${cacheKey}`
@@ -12847,9 +12849,6 @@ function useVerificationService() {
12847
12849
  if (!metadata.app) {
12848
12850
  throw new import_nodejs_utils6.BadRequestError("App metadata is required.");
12849
12851
  }
12850
- if (!metadata.org || !metadata.orgName) {
12851
- throw new import_nodejs_utils6.BadRequestError("Organization metadata is required.");
12852
- }
12853
12852
  try {
12854
12853
  const user = await getUserByEmail(email);
12855
12854
  const dir = __dirname;
@@ -12861,7 +12860,7 @@ function useVerificationService() {
12861
12860
  context: {
12862
12861
  validity: VERIFICATION_USER_INVITE_DURATION,
12863
12862
  link: `${APP_MAIN}/verify/member-invite/${res2}`,
12864
- organization_name: metadata.orgName
12863
+ organization_name: metadata.app === "admin" ? "Admin" : metadata.orgName
12865
12864
  },
12866
12865
  filePath: filePath2
12867
12866
  });
@@ -13032,11 +13031,6 @@ function useVerificationService() {
13032
13031
  "App metadata is required for member invite."
13033
13032
  );
13034
13033
  }
13035
- if (!_id.metadata?.org || !_id.metadata?.orgName) {
13036
- throw new import_nodejs_utils6.BadRequestError(
13037
- "Organization metadata is required for member invite."
13038
- );
13039
- }
13040
13034
  if (!_id.metadata?.role || !_id.metadata?.roleName) {
13041
13035
  throw new import_nodejs_utils6.BadRequestError(
13042
13036
  "Role metadata is required for member invite."
@@ -13046,8 +13040,8 @@ function useVerificationService() {
13046
13040
  {
13047
13041
  user: user._id?.toString() ?? "",
13048
13042
  type: _id.metadata?.app,
13049
- org: _id.metadata?.org,
13050
- orgName: _id.metadata?.orgName,
13043
+ org: _id.metadata?.org ?? "",
13044
+ orgName: _id.metadata?.orgName ?? "",
13051
13045
  role: _id.metadata?.role,
13052
13046
  roleName: _id.metadata?.roleName,
13053
13047
  name: `${user.firstName} ${user.lastName}`
@@ -13166,8 +13160,8 @@ function useVerificationController() {
13166
13160
  app: import_joi2.default.string().required(),
13167
13161
  role: import_joi2.default.string().hex().required(),
13168
13162
  roleName: import_joi2.default.string().required(),
13169
- org: import_joi2.default.string().required(),
13170
- orgName: import_joi2.default.string().required()
13163
+ org: import_joi2.default.string().hex().optional().optional().allow("", null),
13164
+ orgName: import_joi2.default.string().optional().optional().allow("", null)
13171
13165
  });
13172
13166
  const { error } = validation.validate(req.body);
13173
13167
  if (error) {
@@ -13321,9 +13315,9 @@ function useTokenRepo() {
13321
13315
  }
13322
13316
  const namespace_collection = "tokens";
13323
13317
  const collection = db.collection(namespace_collection);
13324
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils8.useCache)();
13318
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils8.useCache)(namespace_collection);
13325
13319
  function delCachedData() {
13326
- delNamespace(namespace_collection).then(() => {
13320
+ delNamespace().then(() => {
13327
13321
  import_nodejs_utils8.logger.log({
13328
13322
  level: "info",
13329
13323
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -13362,7 +13356,7 @@ function useTokenRepo() {
13362
13356
  }
13363
13357
  const data = await collection.findOne({ token });
13364
13358
  if (data) {
13365
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
13359
+ setCache(cacheKey, data, 300).then(() => {
13366
13360
  import_nodejs_utils8.logger.log({
13367
13361
  level: "info",
13368
13362
  message: `Cache set for token: ${cacheKey}`
@@ -13421,9 +13415,9 @@ function useFileRepo() {
13421
13415
  }
13422
13416
  const namespace_collection = "files";
13423
13417
  const collection = db.collection(namespace_collection);
13424
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils9.useCache)();
13418
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils9.useCache)(namespace_collection);
13425
13419
  function delCachedData() {
13426
- delNamespace(namespace_collection).then(() => {
13420
+ delNamespace().then(() => {
13427
13421
  import_nodejs_utils9.logger.log({
13428
13422
  level: "info",
13429
13423
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -13471,7 +13465,7 @@ function useFileRepo() {
13471
13465
  return cached;
13472
13466
  }
13473
13467
  const data = await collection.find({ $and: [{ status: "draft" }, { status: null }] }).toArray();
13474
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
13468
+ setCache(cacheKey, data, 300).then(() => {
13475
13469
  import_nodejs_utils9.logger.log({
13476
13470
  level: "info",
13477
13471
  message: `Cache set for getAllDraftedFiles: ${cacheKey}`
@@ -13544,6 +13538,16 @@ var isPlainObject = (val) => {
13544
13538
  const prototype3 = getPrototypeOf(val);
13545
13539
  return (prototype3 === null || prototype3 === Object.prototype || Object.getPrototypeOf(prototype3) === null) && !(toStringTag in val) && !(iterator in val);
13546
13540
  };
13541
+ var isEmptyObject = (val) => {
13542
+ if (!isObject(val) || isBuffer(val)) {
13543
+ return false;
13544
+ }
13545
+ try {
13546
+ return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
13547
+ } catch (e) {
13548
+ return false;
13549
+ }
13550
+ };
13547
13551
  var isDate = kindOfTest("Date");
13548
13552
  var isFile = kindOfTest("File");
13549
13553
  var isBlob = kindOfTest("Blob");
@@ -13571,6 +13575,9 @@ function forEach(obj, fn, { allOwnKeys = false } = {}) {
13571
13575
  fn.call(null, obj[i], i, obj);
13572
13576
  }
13573
13577
  } else {
13578
+ if (isBuffer(obj)) {
13579
+ return;
13580
+ }
13574
13581
  const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
13575
13582
  const len = keys.length;
13576
13583
  let key;
@@ -13581,6 +13588,9 @@ function forEach(obj, fn, { allOwnKeys = false } = {}) {
13581
13588
  }
13582
13589
  }
13583
13590
  function findKey(obj, key) {
13591
+ if (isBuffer(obj)) {
13592
+ return null;
13593
+ }
13584
13594
  key = key.toLowerCase();
13585
13595
  const keys = Object.keys(obj);
13586
13596
  let i = keys.length;
@@ -13777,6 +13787,9 @@ var toJSONObject = (obj) => {
13777
13787
  if (stack.indexOf(source) >= 0) {
13778
13788
  return;
13779
13789
  }
13790
+ if (isBuffer(source)) {
13791
+ return source;
13792
+ }
13780
13793
  if (!("toJSON" in source)) {
13781
13794
  stack[i] = source;
13782
13795
  const target = isArray(source) ? [] : {};
@@ -13826,6 +13839,7 @@ var utils_default = {
13826
13839
  isBoolean,
13827
13840
  isObject,
13828
13841
  isPlainObject,
13842
+ isEmptyObject,
13829
13843
  isReadableStream,
13830
13844
  isRequest,
13831
13845
  isResponse,
@@ -14270,15 +14284,16 @@ var platform_default = {
14270
14284
 
14271
14285
  // node_modules/axios/lib/helpers/toURLEncodedForm.js
14272
14286
  function toURLEncodedForm(data, options) {
14273
- return toFormData_default(data, new platform_default.classes.URLSearchParams(), Object.assign({
14287
+ return toFormData_default(data, new platform_default.classes.URLSearchParams(), {
14274
14288
  visitor: function(value, key, path, helpers) {
14275
14289
  if (platform_default.isNode && utils_default.isBuffer(value)) {
14276
14290
  this.append(key, value.toString("base64"));
14277
14291
  return false;
14278
14292
  }
14279
14293
  return helpers.defaultVisitor.apply(this, arguments);
14280
- }
14281
- }, options));
14294
+ },
14295
+ ...options
14296
+ });
14282
14297
  }
14283
14298
 
14284
14299
  // node_modules/axios/lib/helpers/formDataToJSON.js
@@ -14791,7 +14806,7 @@ var import_follow_redirects = __toESM(require_follow_redirects(), 1);
14791
14806
  var import_zlib = __toESM(require("zlib"), 1);
14792
14807
 
14793
14808
  // node_modules/axios/lib/env/data.js
14794
- var VERSION = "1.10.0";
14809
+ var VERSION = "1.11.0";
14795
14810
 
14796
14811
  // node_modules/axios/lib/helpers/parseProtocol.js
14797
14812
  function parseProtocol(url2) {
@@ -15133,7 +15148,7 @@ function throttle(fn, freq) {
15133
15148
  clearTimeout(timer);
15134
15149
  timer = null;
15135
15150
  }
15136
- fn.apply(null, args);
15151
+ fn(...args);
15137
15152
  };
15138
15153
  const throttled = (...args) => {
15139
15154
  const now = Date.now();
@@ -15808,7 +15823,7 @@ function mergeConfig(config1, config2) {
15808
15823
  validateStatus: mergeDirectKeys,
15809
15824
  headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
15810
15825
  };
15811
- utils_default.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
15826
+ utils_default.forEach(Object.keys({ ...config1, ...config2 }), function computeConfigValue(prop) {
15812
15827
  const merge2 = mergeMap[prop] || mergeDeepProperties;
15813
15828
  const configValue = merge2(config1[prop], config2[prop], prop);
15814
15829
  utils_default.isUndefined(configValue) && merge2 !== mergeDirectKeys || (config3[prop] = configValue);
@@ -16522,8 +16537,8 @@ var Axios = class {
16522
16537
  let len;
16523
16538
  if (!synchronousRequestInterceptors) {
16524
16539
  const chain = [dispatchRequest.bind(this), void 0];
16525
- chain.unshift.apply(chain, requestInterceptorChain);
16526
- chain.push.apply(chain, responseInterceptorChain);
16540
+ chain.unshift(...requestInterceptorChain);
16541
+ chain.push(...responseInterceptorChain);
16527
16542
  len = chain.length;
16528
16543
  promise = Promise.resolve(config2);
16529
16544
  while (i < len) {
@@ -17497,9 +17512,9 @@ function useRoleRepo() {
17497
17512
  }
17498
17513
  const namespace_collection = "roles";
17499
17514
  const collection = db.collection(namespace_collection);
17500
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils11.useCache)();
17515
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils11.useCache)(namespace_collection);
17501
17516
  function delCachedData() {
17502
- delNamespace(namespace_collection).then(() => {
17517
+ delNamespace().then(() => {
17503
17518
  import_nodejs_utils11.logger.log({
17504
17519
  level: "info",
17505
17520
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -17572,7 +17587,7 @@ function useRoleRepo() {
17572
17587
  return cached;
17573
17588
  }
17574
17589
  const data = await collection.findOne({ user: value });
17575
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
17590
+ setCache(cacheKey, data, 300).then(() => {
17576
17591
  import_nodejs_utils11.logger.log({
17577
17592
  level: "info",
17578
17593
  message: `Cache set for role by user ID: ${cacheKey}`
@@ -17607,7 +17622,7 @@ function useRoleRepo() {
17607
17622
  return cached;
17608
17623
  }
17609
17624
  const data = await collection.findOne({ _id });
17610
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
17625
+ setCache(cacheKey, data, 300).then(() => {
17611
17626
  import_nodejs_utils11.logger.log({
17612
17627
  level: "info",
17613
17628
  message: `Cache set for role by id: ${cacheKey}`
@@ -17640,7 +17655,7 @@ function useRoleRepo() {
17640
17655
  return cached;
17641
17656
  }
17642
17657
  const data = await collection.findOne({ name });
17643
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
17658
+ setCache(cacheKey, data, 300).then(() => {
17644
17659
  import_nodejs_utils11.logger.log({
17645
17660
  level: "info",
17646
17661
  message: `Cache set for role by name: ${cacheKey}`
@@ -17714,7 +17729,7 @@ function useRoleRepo() {
17714
17729
  ]).toArray();
17715
17730
  const length = await collection.countDocuments(query);
17716
17731
  const data = (0, import_nodejs_utils11.paginate)(items, page, limit, length);
17717
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
17732
+ setCache(cacheKey, data, 600).then(() => {
17718
17733
  import_nodejs_utils11.logger.log({
17719
17734
  level: "info",
17720
17735
  message: `Cache set for getRoles: ${cacheKey}`
@@ -17980,9 +17995,6 @@ function useUserService() {
17980
17995
  throw new import_nodejs_utils12.BadRequestError("Invitation expired.");
17981
17996
  }
17982
17997
  const email = invitation.email;
17983
- if (!invitation.metadata.org) {
17984
- throw new import_nodejs_utils12.BadRequestError("Invitation does not have an organization.");
17985
- }
17986
17998
  const _user = await getUserByEmail(invitation.email);
17987
17999
  let userId = _user?._id ?? "";
17988
18000
  if (!_user) {
@@ -18007,8 +18019,8 @@ function useUserService() {
18007
18019
  role: invitation.metadata?.role,
18008
18020
  roleName: invitation.metadata?.roleName,
18009
18021
  type: invitation.metadata?.app,
18010
- org: invitation.metadata?.org,
18011
- orgName: invitation.metadata?.orgName
18022
+ org: invitation.metadata?.org ?? "",
18023
+ orgName: invitation.metadata?.orgName ?? ""
18012
18024
  },
18013
18025
  session
18014
18026
  );
@@ -18423,8 +18435,10 @@ function useUserController() {
18423
18435
  // src/services/auth.service.ts
18424
18436
  var import_nodejs_utils14 = require("@eeplatform/nodejs-utils");
18425
18437
  var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
18438
+ var import_uuid = require("uuid");
18426
18439
  function useAuthService() {
18427
18440
  const expiresIn = "1m";
18441
+ const { setCache, delCache } = (0, import_nodejs_utils14.useCache)("sessions");
18428
18442
  async function login({ email, password } = {}) {
18429
18443
  if (!email) {
18430
18444
  throw new import_nodejs_utils14.BadRequestError("Email is required");
@@ -18456,34 +18470,14 @@ function useAuthService() {
18456
18470
  if (!isPasswordValid) {
18457
18471
  throw new import_nodejs_utils14.BadRequestError("Invalid password");
18458
18472
  }
18459
- const metadata = { user: _user._id };
18460
- let refreshToken2;
18461
- try {
18462
- refreshToken2 = (0, import_nodejs_utils14.generateToken)({
18463
- secret: REFRESH_TOKEN_SECRET,
18464
- metadata,
18465
- options: { expiresIn: "7d" }
18466
- });
18467
- } catch (error) {
18468
- throw new import_nodejs_utils14.BadRequestError("Error generating refresh token");
18469
- }
18470
- let accessToken;
18471
- try {
18472
- accessToken = (0, import_nodejs_utils14.generateToken)({
18473
- secret: ACCESS_TOKEN_SECRET,
18474
- metadata,
18475
- options: { expiresIn }
18476
- });
18477
- } catch (error) {
18478
- throw new import_nodejs_utils14.BadRequestError("Error generating access token");
18479
- }
18480
- const user = _user._id ?? "";
18481
- try {
18482
- await useTokenRepo().createToken({ token: refreshToken2, user });
18483
- } catch (error) {
18484
- throw new import_nodejs_utils14.BadRequestError("Error creating refresh token");
18485
- }
18486
- return { accessToken, refreshToken: refreshToken2, id: _user._id };
18473
+ const sid = (0, import_uuid.v4)();
18474
+ const cacheKey = `sid:${sid}`;
18475
+ setCache(cacheKey, _user, 14400).then(() => {
18476
+ console.log("Session ID cached successfully");
18477
+ }).catch((error) => {
18478
+ console.error("Error caching session ID:", error);
18479
+ });
18480
+ return { sid, user: _user._id?.toString() ?? "" };
18487
18481
  }
18488
18482
  async function refreshToken(token) {
18489
18483
  let decoded;
@@ -18517,26 +18511,13 @@ function useAuthService() {
18517
18511
  }
18518
18512
  return accessToken;
18519
18513
  }
18520
- async function logout(token) {
18521
- let _token;
18522
- try {
18523
- _token = await useTokenRepo().getToken(token);
18524
- if (!_token) {
18525
- throw new import_nodejs_utils14.NotFoundError("Invalid token");
18526
- }
18527
- } catch (error) {
18528
- if (error instanceof import_nodejs_utils14.AppError) {
18529
- throw error;
18530
- } else {
18531
- throw new import_nodejs_utils14.InternalServerError(`${error}`);
18532
- }
18533
- }
18514
+ async function logout(sid) {
18534
18515
  try {
18535
- await useTokenRepo().deleteToken(token);
18516
+ await delCache(`sid:${sid}`);
18517
+ return "Session deleted successfully";
18536
18518
  } catch (error) {
18537
18519
  throw new import_nodejs_utils14.InternalServerError("Error deleting token");
18538
18520
  }
18539
- return "Logged out successfully";
18540
18521
  }
18541
18522
  return {
18542
18523
  login,
@@ -18560,16 +18541,26 @@ function useAuthController() {
18560
18541
  const { error } = validation.validate({ email, password });
18561
18542
  if (error) {
18562
18543
  next(new import_nodejs_utils15.BadRequestError(error.message));
18544
+ return;
18563
18545
  }
18564
18546
  try {
18565
- const token = await useAuthService().login({ email, password });
18566
- res.json(token);
18547
+ const session = await useAuthService().login({
18548
+ email,
18549
+ password
18550
+ });
18551
+ res.json(session);
18567
18552
  } catch (error2) {
18553
+ import_nodejs_utils15.logger.log({
18554
+ level: "error",
18555
+ message: `Error during login: ${error2.message}`
18556
+ });
18557
+ console.log(`Error during login: ${error2}`);
18568
18558
  if (error2 instanceof import_nodejs_utils15.AppError) {
18569
18559
  next(error2);
18570
18560
  } else {
18571
18561
  next(new import_nodejs_utils15.InternalServerError("An unexpected error occurred"));
18572
18562
  }
18563
+ return;
18573
18564
  }
18574
18565
  }
18575
18566
  async function refreshToken(req, res, next) {
@@ -18590,13 +18581,13 @@ function useAuthController() {
18590
18581
  }
18591
18582
  }
18592
18583
  async function logout(req, res, next) {
18593
- const token = req.params.id || "";
18594
- if (!token) {
18595
- next(new import_nodejs_utils15.BadRequestError("Token is required"));
18584
+ const sid = req.headers["authorization"] ?? "";
18585
+ if (!sid) {
18586
+ next(new import_nodejs_utils15.BadRequestError("Session ID is required"));
18596
18587
  return;
18597
18588
  }
18598
18589
  try {
18599
- await useAuthService().logout(token);
18590
+ await useAuthService().logout(sid);
18600
18591
  res.json({ message: "Logged out successfully" });
18601
18592
  } catch (error) {
18602
18593
  if (error instanceof import_nodejs_utils15.AppError) {
@@ -18992,9 +18983,9 @@ function useEntityRepo() {
18992
18983
  }
18993
18984
  const namespace_collection = "entities";
18994
18985
  const collection = db.collection(namespace_collection);
18995
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils19.useCache)();
18986
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils19.useCache)(namespace_collection);
18996
18987
  function delCachedData() {
18997
- delNamespace(namespace_collection).then(() => {
18988
+ delNamespace().then(() => {
18998
18989
  import_nodejs_utils19.logger.log({
18999
18990
  level: "info",
19000
18991
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -19074,7 +19065,7 @@ function useEntityRepo() {
19074
19065
  ]).toArray();
19075
19066
  const length = await collection.countDocuments(query);
19076
19067
  const data = (0, import_nodejs_utils19.paginate)(items, page, limit, length);
19077
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
19068
+ setCache(cacheKey, data, 600).then(() => {
19078
19069
  import_nodejs_utils19.logger.log({
19079
19070
  level: "info",
19080
19071
  message: `Cache set for getEntities: ${cacheKey}`
@@ -19351,9 +19342,9 @@ function useSubscriptionRepo() {
19351
19342
  }
19352
19343
  const namespace_collection = "subscriptions";
19353
19344
  const collection = db.collection(namespace_collection);
19354
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils22.useCache)();
19345
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils22.useCache)(namespace_collection);
19355
19346
  function delCachedData() {
19356
- delNamespace(namespace_collection).then(() => {
19347
+ delNamespace().then(() => {
19357
19348
  import_nodejs_utils22.logger.log({
19358
19349
  level: "info",
19359
19350
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -19419,7 +19410,7 @@ function useSubscriptionRepo() {
19419
19410
  }
19420
19411
  const data = await collection.findOne({ _id });
19421
19412
  if (data) {
19422
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
19413
+ setCache(cacheKey, data, 300).then(() => {
19423
19414
  import_nodejs_utils22.logger.log({
19424
19415
  level: "info",
19425
19416
  message: `Cache set for subscription by ID: ${cacheKey}`
@@ -19454,7 +19445,7 @@ function useSubscriptionRepo() {
19454
19445
  }
19455
19446
  const data = await collection.findOne({ user });
19456
19447
  if (data) {
19457
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
19448
+ setCache(cacheKey, data, 300).then(() => {
19458
19449
  import_nodejs_utils22.logger.log({
19459
19450
  level: "info",
19460
19451
  message: `Cache set for subscription by user ID: ${cacheKey}`
@@ -19514,7 +19505,7 @@ function useSubscriptionRepo() {
19514
19505
  }
19515
19506
  const data = await collection.findOne({ subscriptionId });
19516
19507
  if (data) {
19517
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
19508
+ setCache(cacheKey, data, 300).then(() => {
19518
19509
  import_nodejs_utils22.logger.log({
19519
19510
  level: "info",
19520
19511
  message: `Cache set for subscription by subscription ID: ${cacheKey}`
@@ -19570,7 +19561,7 @@ function useSubscriptionRepo() {
19570
19561
  ]).toArray();
19571
19562
  const length = await collection.countDocuments(query);
19572
19563
  const data = (0, import_nodejs_utils22.paginate)(items, page, limit, length);
19573
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
19564
+ setCache(cacheKey, data, 600).then(() => {
19574
19565
  import_nodejs_utils22.logger.log({
19575
19566
  level: "info",
19576
19567
  message: `Cache set for getSubscriptions: ${cacheKey}`
@@ -20039,7 +20030,7 @@ function useOrgRepo() {
20039
20030
  }
20040
20031
  const namespace_collection = "organizations";
20041
20032
  const collection = db.collection(namespace_collection);
20042
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils24.useCache)();
20033
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils24.useCache)(namespace_collection);
20043
20034
  async function createIndex() {
20044
20035
  try {
20045
20036
  await collection.createIndex([
@@ -20074,7 +20065,7 @@ function useOrgRepo() {
20074
20065
  }
20075
20066
  }
20076
20067
  function delCachedData() {
20077
- delNamespace(namespace_collection).then(() => {
20068
+ delNamespace().then(() => {
20078
20069
  import_nodejs_utils24.logger.log({
20079
20070
  level: "info",
20080
20071
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -20158,7 +20149,7 @@ function useOrgRepo() {
20158
20149
  ]).toArray();
20159
20150
  const length = await collection.countDocuments(query);
20160
20151
  const data = (0, import_nodejs_utils24.paginate)(items, page, limit, length);
20161
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
20152
+ setCache(cacheKey, data, 600).then(() => {
20162
20153
  import_nodejs_utils24.logger.log({
20163
20154
  level: "info",
20164
20155
  message: `Cache set for getAll organizations: ${cacheKey}`
@@ -20195,7 +20186,7 @@ function useOrgRepo() {
20195
20186
  if (!result) {
20196
20187
  throw new import_nodejs_utils24.BadRequestError("Organization not found.");
20197
20188
  }
20198
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
20189
+ setCache(cacheKey, result, 300).then(() => {
20199
20190
  import_nodejs_utils24.logger.log({
20200
20191
  level: "info",
20201
20192
  message: `Cache set for organization by id: ${cacheKey}`
@@ -20230,7 +20221,7 @@ function useOrgRepo() {
20230
20221
  if (!result) {
20231
20222
  throw new import_nodejs_utils24.BadRequestError("Organization not found.");
20232
20223
  }
20233
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
20224
+ setCache(cacheKey, result, 300).then(() => {
20234
20225
  import_nodejs_utils24.logger.log({
20235
20226
  level: "info",
20236
20227
  message: `Cache set for organization by name: ${cacheKey}`
@@ -20362,9 +20353,9 @@ function useAddressRepo() {
20362
20353
  }
20363
20354
  const namespace_collection = "addresses";
20364
20355
  const collection = db.collection(namespace_collection);
20365
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils26.useCache)();
20356
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils26.useCache)(namespace_collection);
20366
20357
  function delCachedData() {
20367
- delNamespace(namespace_collection).then(() => {
20358
+ delNamespace().then(() => {
20368
20359
  import_nodejs_utils26.logger.log({
20369
20360
  level: "info",
20370
20361
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -20440,7 +20431,7 @@ function useAddressRepo() {
20440
20431
  }
20441
20432
  const data = await collection.findOne({ user });
20442
20433
  if (data) {
20443
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
20434
+ setCache(cacheKey, data, 300).then(() => {
20444
20435
  import_nodejs_utils26.logger.log({
20445
20436
  level: "info",
20446
20437
  message: `Cache set for address by user ID: ${cacheKey}`
@@ -20475,7 +20466,7 @@ function useAddressRepo() {
20475
20466
  }
20476
20467
  const data = await collection.findOne({ org });
20477
20468
  if (data) {
20478
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
20469
+ setCache(cacheKey, data, 300).then(() => {
20479
20470
  import_nodejs_utils26.logger.log({
20480
20471
  level: "info",
20481
20472
  message: `Cache set for address by org ID: ${cacheKey}`
@@ -20561,9 +20552,9 @@ function usePromoCodeRepo() {
20561
20552
  }
20562
20553
  const namespace_collection = "promo-codes";
20563
20554
  const collection = db.collection(namespace_collection);
20564
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils28.useCache)();
20555
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils28.useCache)(namespace_collection);
20565
20556
  function delCachedData() {
20566
- delNamespace(namespace_collection).then(() => {
20557
+ delNamespace().then(() => {
20567
20558
  import_nodejs_utils28.logger.log({
20568
20559
  level: "info",
20569
20560
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -20643,7 +20634,7 @@ function usePromoCodeRepo() {
20643
20634
  }
20644
20635
  const data = await collection.findOne(query);
20645
20636
  if (data) {
20646
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
20637
+ setCache(cacheKey, data, 300).then(() => {
20647
20638
  import_nodejs_utils28.logger.log({
20648
20639
  level: "info",
20649
20640
  message: `Cache set for promo code by code: ${cacheKey}`
@@ -20685,7 +20676,7 @@ function usePromoCodeRepo() {
20685
20676
  }
20686
20677
  const data = await collection.findOne({ _id });
20687
20678
  if (data) {
20688
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
20679
+ setCache(cacheKey, data, 300).then(() => {
20689
20680
  import_nodejs_utils28.logger.log({
20690
20681
  level: "info",
20691
20682
  message: `Cache set for promo code by ID: ${cacheKey}`
@@ -20744,7 +20735,7 @@ function usePromoCodeRepo() {
20744
20735
  ]).toArray();
20745
20736
  const length = await collection.countDocuments(query);
20746
20737
  const data = (0, import_nodejs_utils28.paginate)(items, page, limit, length);
20747
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
20738
+ setCache(cacheKey, data, 600).then(() => {
20748
20739
  import_nodejs_utils28.logger.log({
20749
20740
  level: "info",
20750
20741
  message: `Cache set for getPromoCodes: ${cacheKey}`
@@ -21110,9 +21101,9 @@ function useCounterRepo() {
21110
21101
  }
21111
21102
  const namespace_collection = "counters";
21112
21103
  const { collection, createCounter } = useCounterModel(db);
21113
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils32.useCache)();
21104
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils32.useCache)(namespace_collection);
21114
21105
  function delCachedData() {
21115
- delNamespace(namespace_collection).then(() => {
21106
+ delNamespace().then(() => {
21116
21107
  import_nodejs_utils32.logger.log({
21117
21108
  level: "info",
21118
21109
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -21182,7 +21173,7 @@ function useCounterRepo() {
21182
21173
  }
21183
21174
  const data = await collection.findOne({ type });
21184
21175
  if (data) {
21185
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
21176
+ setCache(cacheKey, data, 300).then(() => {
21186
21177
  import_nodejs_utils32.logger.log({
21187
21178
  level: "info",
21188
21179
  message: `Cache set for counter by type: ${cacheKey}`
@@ -21375,9 +21366,9 @@ function usePriceRepo() {
21375
21366
  }
21376
21367
  const namespace_collection = "prices";
21377
21368
  const { collection, createPrice } = usePriceModel(db);
21378
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils35.useCache)();
21369
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils35.useCache)(namespace_collection);
21379
21370
  function delCachedData() {
21380
- delNamespace(namespace_collection).then(() => {
21371
+ delNamespace().then(() => {
21381
21372
  import_nodejs_utils35.logger.log({
21382
21373
  level: "info",
21383
21374
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -21447,7 +21438,7 @@ function usePriceRepo() {
21447
21438
  }
21448
21439
  const data = await collection.findOne({ name, type });
21449
21440
  if (data) {
21450
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
21441
+ setCache(cacheKey, data, 300).then(() => {
21451
21442
  import_nodejs_utils35.logger.log({
21452
21443
  level: "info",
21453
21444
  message: `Cache set for price by name and type: ${cacheKey}`
@@ -24700,9 +24691,9 @@ function useOrderRepo() {
24700
24691
  }
24701
24692
  const namespace_collection = "orders";
24702
24693
  const collection = db.collection(namespace_collection);
24703
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils49.useCache)();
24694
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils49.useCache)(namespace_collection);
24704
24695
  function delCachedData() {
24705
- delNamespace(namespace_collection).then(() => {
24696
+ delNamespace().then(() => {
24706
24697
  import_nodejs_utils49.logger.log({
24707
24698
  level: "info",
24708
24699
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -24789,7 +24780,7 @@ function useOrderRepo() {
24789
24780
  ]).toArray();
24790
24781
  const length = await collection.countDocuments(query);
24791
24782
  const data = (0, import_nodejs_utils49.paginate)(items, page, limit, length);
24792
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
24783
+ setCache(cacheKey, data, 600).then(() => {
24793
24784
  import_nodejs_utils49.logger.log({
24794
24785
  level: "info",
24795
24786
  message: `Cache set for getOrders: ${cacheKey}`
@@ -25339,7 +25330,7 @@ function useRegionRepo() {
25339
25330
  }
25340
25331
  const namespace_collection = "regions";
25341
25332
  const collection = db.collection(namespace_collection);
25342
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils56.useCache)();
25333
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils56.useCache)(namespace_collection);
25343
25334
  async function createIndex() {
25344
25335
  try {
25345
25336
  await collection.createIndex([
@@ -25376,7 +25367,7 @@ function useRegionRepo() {
25376
25367
  }
25377
25368
  }
25378
25369
  function delCachedData() {
25379
- delNamespace(namespace_collection).then(() => {
25370
+ delNamespace().then(() => {
25380
25371
  import_nodejs_utils56.logger.log({
25381
25372
  level: "info",
25382
25373
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -25454,7 +25445,7 @@ function useRegionRepo() {
25454
25445
  ]).toArray();
25455
25446
  const length = await collection.countDocuments(query);
25456
25447
  const data = (0, import_nodejs_utils56.paginate)(items, page, limit, length);
25457
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
25448
+ setCache(cacheKey, data, 600).then(() => {
25458
25449
  import_nodejs_utils56.logger.log({
25459
25450
  level: "info",
25460
25451
  message: `Cache set for getAll regions: ${cacheKey}`
@@ -25494,7 +25485,7 @@ function useRegionRepo() {
25494
25485
  if (!result) {
25495
25486
  throw new import_nodejs_utils56.BadRequestError("Region not found.");
25496
25487
  }
25497
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
25488
+ setCache(cacheKey, result, 300).then(() => {
25498
25489
  import_nodejs_utils56.logger.log({
25499
25490
  level: "info",
25500
25491
  message: `Cache set for region by id: ${cacheKey}`
@@ -25532,7 +25523,7 @@ function useRegionRepo() {
25532
25523
  if (!result) {
25533
25524
  throw new import_nodejs_utils56.BadRequestError("Region not found.");
25534
25525
  }
25535
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
25526
+ setCache(cacheKey, result, 300).then(() => {
25536
25527
  import_nodejs_utils56.logger.log({
25537
25528
  level: "info",
25538
25529
  message: `Cache set for region by name: ${cacheKey}`
@@ -25869,7 +25860,7 @@ function useDivisionRepo() {
25869
25860
  }
25870
25861
  const namespace_collection = "divisions";
25871
25862
  const collection = db.collection(namespace_collection);
25872
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils60.useCache)();
25863
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils60.useCache)(namespace_collection);
25873
25864
  async function createIndex() {
25874
25865
  try {
25875
25866
  await collection.createIndex([
@@ -25908,7 +25899,7 @@ function useDivisionRepo() {
25908
25899
  }
25909
25900
  }
25910
25901
  function delCachedData() {
25911
- delNamespace(namespace_collection).then(() => {
25902
+ delNamespace().then(() => {
25912
25903
  import_nodejs_utils60.logger.log({
25913
25904
  level: "info",
25914
25905
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -26002,7 +25993,7 @@ function useDivisionRepo() {
26002
25993
  ]).toArray();
26003
25994
  const length = await collection.countDocuments(query);
26004
25995
  const data = (0, import_nodejs_utils60.paginate)(items, page, limit, length);
26005
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
25996
+ setCache(cacheKey, data, 600).then(() => {
26006
25997
  import_nodejs_utils60.logger.log({
26007
25998
  level: "info",
26008
25999
  message: `Cache set for getAll divisions: ${cacheKey}`
@@ -26042,7 +26033,7 @@ function useDivisionRepo() {
26042
26033
  if (!result) {
26043
26034
  throw new import_nodejs_utils60.BadRequestError("Division not found.");
26044
26035
  }
26045
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
26036
+ setCache(cacheKey, result, 300).then(() => {
26046
26037
  import_nodejs_utils60.logger.log({
26047
26038
  level: "info",
26048
26039
  message: `Cache set for division by id: ${cacheKey}`
@@ -26080,7 +26071,7 @@ function useDivisionRepo() {
26080
26071
  if (!result) {
26081
26072
  throw new import_nodejs_utils60.BadRequestError("Division not found.");
26082
26073
  }
26083
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
26074
+ setCache(cacheKey, result, 300).then(() => {
26084
26075
  import_nodejs_utils60.logger.log({
26085
26076
  level: "info",
26086
26077
  message: `Cache set for division by name: ${cacheKey}`
@@ -26463,9 +26454,9 @@ function useSchoolRepo() {
26463
26454
  }
26464
26455
  const namespace_collection = "schools";
26465
26456
  const collection = db.collection(namespace_collection);
26466
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils63.useCache)();
26457
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils63.useCache)(namespace_collection);
26467
26458
  function delCachedData() {
26468
- delNamespace(namespace_collection).then(() => {
26459
+ delNamespace().then(() => {
26469
26460
  import_nodejs_utils63.logger.log({
26470
26461
  level: "info",
26471
26462
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -26524,8 +26515,8 @@ function useSchoolRepo() {
26524
26515
  limit = 20,
26525
26516
  sort = {},
26526
26517
  status = "active",
26527
- region = "",
26528
- division = "",
26518
+ org = "",
26519
+ app = "admin",
26529
26520
  search = ""
26530
26521
  } = {}) {
26531
26522
  page = Math.max(0, page - 1);
@@ -26543,20 +26534,12 @@ function useSchoolRepo() {
26543
26534
  query.$text = { $search: search };
26544
26535
  cacheKeyOptions.search = search;
26545
26536
  }
26546
- if (region) {
26547
- try {
26548
- query.region = new import_mongodb38.ObjectId(region);
26549
- cacheKeyOptions.region = region;
26550
- } catch (error) {
26551
- throw new import_nodejs_utils63.BadRequestError("Invalid region.");
26552
- }
26553
- }
26554
- if (division) {
26537
+ if (org) {
26555
26538
  try {
26556
- query.division = new import_mongodb38.ObjectId(division);
26557
- cacheKeyOptions.division = division;
26539
+ query[app] = new import_mongodb38.ObjectId(org);
26540
+ cacheKeyOptions[app] = org;
26558
26541
  } catch (error) {
26559
- throw new import_nodejs_utils63.BadRequestError("Invalid division.");
26542
+ throw new import_nodejs_utils63.BadRequestError("Invalid org.");
26560
26543
  }
26561
26544
  }
26562
26545
  try {
@@ -26573,7 +26556,7 @@ function useSchoolRepo() {
26573
26556
  ]).toArray();
26574
26557
  const length = await collection.countDocuments(query);
26575
26558
  const data = (0, import_nodejs_utils63.paginate)(items, page, limit, length);
26576
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
26559
+ setCache(cacheKey, data, 600).then(() => {
26577
26560
  import_nodejs_utils63.logger.log({
26578
26561
  level: "info",
26579
26562
  message: `Cache set for key ${cacheKey}`
@@ -26664,7 +26647,7 @@ function useSchoolRepo() {
26664
26647
  }
26665
26648
  try {
26666
26649
  const school = await collection.findOne({ createdBy, status: "pending" });
26667
- setCache(cacheKey, school, 600, namespace_collection).then(() => {
26650
+ setCache(cacheKey, school, 600).then(() => {
26668
26651
  import_nodejs_utils63.logger.log({
26669
26652
  level: "info",
26670
26653
  message: `Cache set for school by createdBy: ${cacheKey}`
@@ -26696,7 +26679,7 @@ function useSchoolRepo() {
26696
26679
  }
26697
26680
  try {
26698
26681
  const school = await collection.findOne({ _id, status: "pending" });
26699
- setCache(cacheKey, school, 600, namespace_collection).then(() => {
26682
+ setCache(cacheKey, school, 600).then(() => {
26700
26683
  import_nodejs_utils63.logger.log({
26701
26684
  level: "info",
26702
26685
  message: `Cache set for school by ID: ${cacheKey}`
@@ -26846,8 +26829,8 @@ function useSchoolController() {
26846
26829
  sort: import_joi32.default.string().optional().allow(null, ""),
26847
26830
  sortOrder: import_joi32.default.string().optional().allow(null, ""),
26848
26831
  status: import_joi32.default.string().optional().allow(null, ""),
26849
- region: import_joi32.default.string().hex().optional().allow(null, ""),
26850
- division: import_joi32.default.string().hex().optional().allow(null, ""),
26832
+ org: import_joi32.default.string().hex().optional().allow(null, ""),
26833
+ app: import_joi32.default.string().optional().allow(null, ""),
26851
26834
  search: import_joi32.default.string().optional().allow(null, "")
26852
26835
  });
26853
26836
  const { error } = validation.validate(req.query);
@@ -26867,8 +26850,8 @@ function useSchoolController() {
26867
26850
  });
26868
26851
  }
26869
26852
  const status = req.query.status ?? "active";
26870
- const region = req.query.region ?? "";
26871
- const division = req.query.division ?? "";
26853
+ const org = req.query.org ?? "";
26854
+ const app = req.query.app ?? "admin";
26872
26855
  const search = req.query.search ?? "";
26873
26856
  try {
26874
26857
  const schools = await _getAll({
@@ -26876,8 +26859,8 @@ function useSchoolController() {
26876
26859
  limit,
26877
26860
  sort: sortObj,
26878
26861
  status,
26879
- region,
26880
- division,
26862
+ org,
26863
+ app,
26881
26864
  search
26882
26865
  });
26883
26866
  res.status(200).json(schools);