@goweekdays/core 1.2.2 → 1.2.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
@@ -11551,6 +11551,7 @@ __export(src_exports, {
11551
11551
  DEFAULT_USER_FIRST_NAME: () => DEFAULT_USER_FIRST_NAME,
11552
11552
  DEFAULT_USER_LAST_NAME: () => DEFAULT_USER_LAST_NAME,
11553
11553
  DEFAULT_USER_PASSWORD: () => DEFAULT_USER_PASSWORD,
11554
+ DOMAIN: () => DOMAIN,
11554
11555
  DirectDebitSchema: () => DirectDebitSchema,
11555
11556
  EWalletPaymentSchema: () => EWalletPaymentSchema,
11556
11557
  MAILER_EMAIL: () => MAILER_EMAIL,
@@ -11595,7 +11596,9 @@ __export(src_exports, {
11595
11596
  XENDIT_SECRET_KEY: () => XENDIT_SECRET_KEY,
11596
11597
  addressSchema: () => addressSchema,
11597
11598
  isDev: () => isDev,
11599
+ modelProperty: () => modelProperty,
11598
11600
  schema: () => schema,
11601
+ schemaProperty: () => schemaProperty,
11599
11602
  useAddressController: () => useAddressController,
11600
11603
  useAddressRepo: () => useAddressRepo,
11601
11604
  useAuthController: () => useAuthController,
@@ -11630,6 +11633,8 @@ __export(src_exports, {
11630
11633
  usePriceRepo: () => usePriceRepo,
11631
11634
  usePromoCodeController: () => usePromoCodeController,
11632
11635
  usePromoCodeRepo: () => usePromoCodeRepo,
11636
+ usePropertyController: () => usePropertyController,
11637
+ usePropertyRepo: () => usePropertyRepo,
11633
11638
  useRoleController: () => useRoleController,
11634
11639
  useRoleRepo: () => useRoleRepo,
11635
11640
  useSubscriptionController: () => useSubscriptionController,
@@ -11683,9 +11688,9 @@ function useVerificationRepo() {
11683
11688
  }
11684
11689
  const namespace_collection = "verifications";
11685
11690
  const collection = db.collection(namespace_collection);
11686
- const { getCache, setCache, delNamespace } = (0, import_utils2.useCache)();
11691
+ const { getCache, setCache, delNamespace } = (0, import_utils2.useCache)(namespace_collection);
11687
11692
  function delCachedData() {
11688
- delNamespace(namespace_collection).then(() => {
11693
+ delNamespace().then(() => {
11689
11694
  import_utils2.logger.log({
11690
11695
  level: "info",
11691
11696
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -11773,7 +11778,7 @@ function useVerificationRepo() {
11773
11778
  return cached;
11774
11779
  }
11775
11780
  const data = await collection.findOne({ _id });
11776
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
11781
+ setCache(cacheKey, data, 300).then(() => {
11777
11782
  import_utils2.logger.log({
11778
11783
  level: "info",
11779
11784
  message: `Cache set for verification by id: ${cacheKey}`
@@ -11853,7 +11858,7 @@ function useVerificationRepo() {
11853
11858
  ]).toArray();
11854
11859
  const length = await collection.countDocuments(query);
11855
11860
  const data = (0, import_utils2.paginate)(items, page, limit, length);
11856
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
11861
+ setCache(cacheKey, data, 600).then(() => {
11857
11862
  import_utils2.logger.log({
11858
11863
  level: "info",
11859
11864
  message: `Cache set for getVerifications: ${cacheKey}`
@@ -11884,7 +11889,7 @@ function useVerificationRepo() {
11884
11889
  return cached;
11885
11890
  }
11886
11891
  const data = await collection.find({ type }).toArray();
11887
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
11892
+ setCache(cacheKey, data, 600).then(() => {
11888
11893
  import_utils2.logger.log({
11889
11894
  level: "info",
11890
11895
  message: `Cache set for verification by type: ${cacheKey}`
@@ -11973,6 +11978,7 @@ var PAYPAL_CLIENT_SECRET = process.env.PAYPAL_CLIENT_SECRET ?? "";
11973
11978
  var PAYPAL_API_URL = process.env.PAYPAL_API_URL ?? "https://api-m.sandbox.paypal.com";
11974
11979
  var XENDIT_SECRET_KEY = process.env.XENDIT_SECRET_KEY ?? "";
11975
11980
  var XENDIT_BASE_URL = process.env.XENDIT_BASE_URL ?? "https://api.xendit.co";
11981
+ var DOMAIN = process.env.DOMAIN || "localhost";
11976
11982
 
11977
11983
  // src/repositories/user.repository.ts
11978
11984
  var import_mongodb4 = require("mongodb");
@@ -12027,9 +12033,9 @@ function useUserRepo() {
12027
12033
  }
12028
12034
  const namespace_collection = "users";
12029
12035
  const collection = db.collection(namespace_collection);
12030
- const { getCache, setCache, delNamespace } = (0, import_utils3.useCache)();
12036
+ const { getCache, setCache, delNamespace } = (0, import_utils3.useCache)(namespace_collection);
12031
12037
  function delCachedData() {
12032
- delNamespace(namespace_collection).then(() => {
12038
+ delNamespace().then(() => {
12033
12039
  import_utils3.logger.log({
12034
12040
  level: "info",
12035
12041
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -12091,7 +12097,7 @@ function useUserRepo() {
12091
12097
  }
12092
12098
  const result = await collection.findOne({ email });
12093
12099
  if (result) {
12094
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
12100
+ setCache(cacheKey, result, 300).then(() => {
12095
12101
  import_utils3.logger.log({
12096
12102
  level: "info",
12097
12103
  message: `Cache set for user by email: ${cacheKey}`
@@ -12121,7 +12127,7 @@ function useUserRepo() {
12121
12127
  }
12122
12128
  const result = await collection.findOne({ referralCode });
12123
12129
  if (result) {
12124
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
12130
+ setCache(cacheKey, result, 300).then(() => {
12125
12131
  import_utils3.logger.log({
12126
12132
  level: "info",
12127
12133
  message: `Cache set for user by referral code: ${cacheKey}`
@@ -12156,7 +12162,7 @@ function useUserRepo() {
12156
12162
  }
12157
12163
  const result = await collection.findOne({ _id });
12158
12164
  if (result) {
12159
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
12165
+ setCache(cacheKey, result, 300).then(() => {
12160
12166
  import_utils3.logger.log({
12161
12167
  level: "info",
12162
12168
  message: `Cache set for user by id: ${cacheKey}`
@@ -12230,7 +12236,7 @@ function useUserRepo() {
12230
12236
  ]).toArray();
12231
12237
  const length = await collection.countDocuments(query);
12232
12238
  const data = (0, import_utils3.paginate)(items, page, limit, length);
12233
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
12239
+ setCache(cacheKey, data, 600).then(() => {
12234
12240
  import_utils3.logger.log({
12235
12241
  level: "info",
12236
12242
  message: `Cache set for getUsers: ${cacheKey}`
@@ -12444,9 +12450,9 @@ function useMemberRepo() {
12444
12450
  }
12445
12451
  const namespace_collection = "members";
12446
12452
  const collection = db.collection(namespace_collection);
12447
- const { getCache, setCache, delNamespace } = (0, import_utils5.useCache)();
12453
+ const { getCache, setCache, delNamespace } = (0, import_utils5.useCache)(namespace_collection);
12448
12454
  function delCachedData() {
12449
- delNamespace(namespace_collection).then(() => {
12455
+ delNamespace().then(() => {
12450
12456
  import_utils5.logger.log({
12451
12457
  level: "info",
12452
12458
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -12532,7 +12538,7 @@ function useMemberRepo() {
12532
12538
  return cached;
12533
12539
  }
12534
12540
  const data = await collection.findOne({ _id });
12535
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
12541
+ setCache(cacheKey, data, 300).then(() => {
12536
12542
  import_utils5.logger.log({
12537
12543
  level: "info",
12538
12544
  message: `Cache set for member by id: ${cacheKey}`
@@ -12569,7 +12575,7 @@ function useMemberRepo() {
12569
12575
  return cached;
12570
12576
  }
12571
12577
  const data = await collection.findOne({ user });
12572
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
12578
+ setCache(cacheKey, data, 300).then(() => {
12573
12579
  import_utils5.logger.log({
12574
12580
  level: "info",
12575
12581
  message: `Cache set for member by user ID: ${cacheKey}`
@@ -12622,7 +12628,7 @@ function useMemberRepo() {
12622
12628
  return cached;
12623
12629
  }
12624
12630
  const data = await collection.findOne(query);
12625
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
12631
+ setCache(cacheKey, data, 300).then(() => {
12626
12632
  import_utils5.logger.log({
12627
12633
  level: "info",
12628
12634
  message: `Cache set for member by user ID: ${cacheKey}`
@@ -12726,7 +12732,7 @@ function useMemberRepo() {
12726
12732
  ]).toArray();
12727
12733
  const length = await collection.countDocuments(query);
12728
12734
  const data = (0, import_utils5.paginate)(items, page, limit, length);
12729
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
12735
+ setCache(cacheKey, data, 600).then(() => {
12730
12736
  import_utils5.logger.log({
12731
12737
  level: "info",
12732
12738
  message: `Cache set for getAll members: ${cacheKey}`
@@ -12761,7 +12767,7 @@ function useMemberRepo() {
12761
12767
  return cached;
12762
12768
  }
12763
12769
  const data = await collection.countDocuments({ org, status: "active" });
12764
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
12770
+ setCache(cacheKey, data, 300).then(() => {
12765
12771
  import_utils5.logger.log({
12766
12772
  level: "info",
12767
12773
  message: `Cache set for countByOrg members: ${cacheKey}`
@@ -12798,7 +12804,7 @@ function useMemberRepo() {
12798
12804
  return cached;
12799
12805
  }
12800
12806
  const data = await collection.countDocuments({ user, status: "active" });
12801
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
12807
+ setCache(cacheKey, data, 300).then(() => {
12802
12808
  import_utils5.logger.log({
12803
12809
  level: "info",
12804
12810
  message: `Cache set for countByUser members: ${cacheKey}`
@@ -12872,7 +12878,7 @@ function useMemberRepo() {
12872
12878
  ]).toArray();
12873
12879
  const length = await collection.countDocuments(query);
12874
12880
  const data = (0, import_utils5.paginate)(items, page, limit, length);
12875
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
12881
+ setCache(cacheKey, data, 600).then(() => {
12876
12882
  import_utils5.logger.log({
12877
12883
  level: "info",
12878
12884
  message: `Cache set for getOrgsByMembership members: ${cacheKey}`
@@ -12950,7 +12956,7 @@ function useMemberRepo() {
12950
12956
  ]).toArray();
12951
12957
  const length = await collection.countDocuments(query);
12952
12958
  const data = (0, import_utils5.paginate)(items, page, limit, length);
12953
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
12959
+ setCache(cacheKey, data, 300).then(() => {
12954
12960
  import_utils5.logger.log({
12955
12961
  level: "info",
12956
12962
  message: `Cache set for getOrgsByUserId members: ${cacheKey}`
@@ -13521,9 +13527,9 @@ function useTokenRepo() {
13521
13527
  }
13522
13528
  const namespace_collection = "tokens";
13523
13529
  const collection = db.collection(namespace_collection);
13524
- const { getCache, setCache, delNamespace } = (0, import_utils8.useCache)();
13530
+ const { getCache, setCache, delNamespace } = (0, import_utils8.useCache)(namespace_collection);
13525
13531
  function delCachedData() {
13526
- delNamespace(namespace_collection).then(() => {
13532
+ delNamespace().then(() => {
13527
13533
  import_utils8.logger.log({
13528
13534
  level: "info",
13529
13535
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -13562,7 +13568,7 @@ function useTokenRepo() {
13562
13568
  }
13563
13569
  const data = await collection.findOne({ token });
13564
13570
  if (data) {
13565
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
13571
+ setCache(cacheKey, data, 300).then(() => {
13566
13572
  import_utils8.logger.log({
13567
13573
  level: "info",
13568
13574
  message: `Cache set for token: ${cacheKey}`
@@ -13621,9 +13627,9 @@ function useFileRepo() {
13621
13627
  }
13622
13628
  const namespace_collection = "files";
13623
13629
  const collection = db.collection(namespace_collection);
13624
- const { getCache, setCache, delNamespace } = (0, import_utils9.useCache)();
13630
+ const { getCache, setCache, delNamespace } = (0, import_utils9.useCache)(namespace_collection);
13625
13631
  function delCachedData() {
13626
- delNamespace(namespace_collection).then(() => {
13632
+ delNamespace().then(() => {
13627
13633
  import_utils9.logger.log({
13628
13634
  level: "info",
13629
13635
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -13671,7 +13677,7 @@ function useFileRepo() {
13671
13677
  return cached;
13672
13678
  }
13673
13679
  const data = await collection.find({ $and: [{ status: "draft" }, { status: null }] }).toArray();
13674
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
13680
+ setCache(cacheKey, data, 300).then(() => {
13675
13681
  import_utils9.logger.log({
13676
13682
  level: "info",
13677
13683
  message: `Cache set for getAllDraftedFiles: ${cacheKey}`
@@ -17697,9 +17703,9 @@ function useRoleRepo() {
17697
17703
  }
17698
17704
  const namespace_collection = "roles";
17699
17705
  const collection = db.collection(namespace_collection);
17700
- const { getCache, setCache, delNamespace } = (0, import_utils37.useCache)();
17706
+ const { getCache, setCache, delNamespace } = (0, import_utils37.useCache)(namespace_collection);
17701
17707
  function delCachedData() {
17702
- delNamespace(namespace_collection).then(() => {
17708
+ delNamespace().then(() => {
17703
17709
  import_utils37.logger.log({
17704
17710
  level: "info",
17705
17711
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -17771,7 +17777,7 @@ function useRoleRepo() {
17771
17777
  return cached;
17772
17778
  }
17773
17779
  const data = await collection.findOne({ user: value });
17774
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
17780
+ setCache(cacheKey, data, 300).then(() => {
17775
17781
  import_utils37.logger.log({
17776
17782
  level: "info",
17777
17783
  message: `Cache set for role by user ID: ${cacheKey}`
@@ -17806,7 +17812,7 @@ function useRoleRepo() {
17806
17812
  return cached;
17807
17813
  }
17808
17814
  const data = await collection.findOne({ _id });
17809
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
17815
+ setCache(cacheKey, data, 300).then(() => {
17810
17816
  import_utils37.logger.log({
17811
17817
  level: "info",
17812
17818
  message: `Cache set for role by id: ${cacheKey}`
@@ -17839,7 +17845,7 @@ function useRoleRepo() {
17839
17845
  return cached;
17840
17846
  }
17841
17847
  const data = await collection.findOne({ name });
17842
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
17848
+ setCache(cacheKey, data, 300).then(() => {
17843
17849
  import_utils37.logger.log({
17844
17850
  level: "info",
17845
17851
  message: `Cache set for role by name: ${cacheKey}`
@@ -17874,7 +17880,11 @@ function useRoleRepo() {
17874
17880
  }
17875
17881
  }
17876
17882
  const query = { status: "active", org };
17877
- const cacheKeyOptions = { status: "active", limit, page };
17883
+ const cacheKeyOptions = {
17884
+ status: "active",
17885
+ limit,
17886
+ page
17887
+ };
17878
17888
  if (org) {
17879
17889
  cacheKeyOptions.org = String(org);
17880
17890
  }
@@ -17906,7 +17916,7 @@ function useRoleRepo() {
17906
17916
  ]).toArray();
17907
17917
  const length = await collection.countDocuments(query);
17908
17918
  const data = (0, import_utils37.paginate)(items, page, limit, length);
17909
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
17919
+ setCache(cacheKey, data, 600).then(() => {
17910
17920
  import_utils37.logger.log({
17911
17921
  level: "info",
17912
17922
  message: `Cache set for getRoles: ${cacheKey}`
@@ -18064,9 +18074,9 @@ function useSocialRepo() {
18064
18074
  }
18065
18075
  const namespace_collection = "roles";
18066
18076
  const collection = db.collection(namespace_collection);
18067
- const { getCache, setCache, delNamespace } = (0, import_utils39.useCache)();
18077
+ const { getCache, setCache, delNamespace } = (0, import_utils39.useCache)(namespace_collection);
18068
18078
  function delCachedData() {
18069
- delNamespace(namespace_collection).then(() => {
18079
+ delNamespace().then(() => {
18070
18080
  import_utils39.logger.log({
18071
18081
  level: "info",
18072
18082
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -18591,7 +18601,8 @@ function useUserController() {
18591
18601
  const id = req.params.id || "";
18592
18602
  const validation = import_joi5.default.string().hex().validate(id);
18593
18603
  if (validation.error) {
18594
- throw new import_utils41.BadRequestError("Invalid id.");
18604
+ next(new import_utils41.BadRequestError("Invalid id."));
18605
+ return;
18595
18606
  }
18596
18607
  try {
18597
18608
  const user = await _getUserById(id);
@@ -18758,8 +18769,58 @@ function useUserController() {
18758
18769
  // src/services/auth.service.ts
18759
18770
  var import_utils42 = require("@goweekdays/utils");
18760
18771
  var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
18772
+
18773
+ // node_modules/uuid/dist/esm-node/rng.js
18774
+ var import_crypto2 = __toESM(require("crypto"));
18775
+ var rnds8Pool = new Uint8Array(256);
18776
+ var poolPtr = rnds8Pool.length;
18777
+ function rng() {
18778
+ if (poolPtr > rnds8Pool.length - 16) {
18779
+ import_crypto2.default.randomFillSync(rnds8Pool);
18780
+ poolPtr = 0;
18781
+ }
18782
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
18783
+ }
18784
+
18785
+ // node_modules/uuid/dist/esm-node/stringify.js
18786
+ var byteToHex = [];
18787
+ for (let i = 0; i < 256; ++i) {
18788
+ byteToHex.push((i + 256).toString(16).slice(1));
18789
+ }
18790
+ function unsafeStringify(arr, offset = 0) {
18791
+ return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
18792
+ }
18793
+
18794
+ // node_modules/uuid/dist/esm-node/native.js
18795
+ var import_crypto3 = __toESM(require("crypto"));
18796
+ var native_default = {
18797
+ randomUUID: import_crypto3.default.randomUUID
18798
+ };
18799
+
18800
+ // node_modules/uuid/dist/esm-node/v4.js
18801
+ function v4(options, buf, offset) {
18802
+ if (native_default.randomUUID && !buf && !options) {
18803
+ return native_default.randomUUID();
18804
+ }
18805
+ options = options || {};
18806
+ const rnds = options.random || (options.rng || rng)();
18807
+ rnds[6] = rnds[6] & 15 | 64;
18808
+ rnds[8] = rnds[8] & 63 | 128;
18809
+ if (buf) {
18810
+ offset = offset || 0;
18811
+ for (let i = 0; i < 16; ++i) {
18812
+ buf[offset + i] = rnds[i];
18813
+ }
18814
+ return buf;
18815
+ }
18816
+ return unsafeStringify(rnds);
18817
+ }
18818
+ var v4_default = v4;
18819
+
18820
+ // src/services/auth.service.ts
18761
18821
  function useAuthService() {
18762
18822
  const expiresIn = "1m";
18823
+ const { setCache } = (0, import_utils42.useCache)("sessions");
18763
18824
  async function login({ email, password } = {}) {
18764
18825
  if (!email) {
18765
18826
  throw new import_utils42.BadRequestError("Email is required");
@@ -18791,34 +18852,14 @@ function useAuthService() {
18791
18852
  if (!isPasswordValid) {
18792
18853
  throw new import_utils42.BadRequestError("Invalid password");
18793
18854
  }
18794
- const metadata = { user: _user._id };
18795
- let refreshToken2;
18796
- try {
18797
- refreshToken2 = (0, import_utils42.generateToken)({
18798
- secret: REFRESH_TOKEN_SECRET,
18799
- metadata,
18800
- options: { expiresIn: "7d" }
18801
- });
18802
- } catch (error) {
18803
- throw new import_utils42.BadRequestError("Error generating refresh token");
18804
- }
18805
- let accessToken;
18806
- try {
18807
- accessToken = (0, import_utils42.generateToken)({
18808
- secret: ACCESS_TOKEN_SECRET,
18809
- metadata,
18810
- options: { expiresIn }
18811
- });
18812
- } catch (error) {
18813
- throw new import_utils42.BadRequestError("Error generating access token");
18814
- }
18815
- const user = _user._id ?? "";
18816
- try {
18817
- await useTokenRepo().createToken({ token: refreshToken2, user });
18818
- } catch (error) {
18819
- throw new import_utils42.BadRequestError("Error creating refresh token");
18820
- }
18821
- return { accessToken, refreshToken: refreshToken2, id: _user._id };
18855
+ const sid = v4_default();
18856
+ const cacheKey = `sid:${sid}`;
18857
+ setCache(cacheKey, _user, 14400).then(() => {
18858
+ console.log("Session ID cached successfully");
18859
+ }).catch((error) => {
18860
+ console.error("Error caching session ID:", error);
18861
+ });
18862
+ return { sid, user: _user._id?.toString() ?? "" };
18822
18863
  }
18823
18864
  async function refreshToken(token) {
18824
18865
  let decoded;
@@ -18895,16 +18936,32 @@ function useAuthController() {
18895
18936
  const { error } = validation.validate({ email, password });
18896
18937
  if (error) {
18897
18938
  next(new import_utils43.BadRequestError(error.message));
18939
+ return;
18898
18940
  }
18899
18941
  try {
18900
- const token = await useAuthService().login({ email, password });
18901
- res.json(token);
18942
+ const session = await useAuthService().login({
18943
+ email,
18944
+ password
18945
+ });
18946
+ const cookieOptions = {
18947
+ domain: DOMAIN,
18948
+ secure: true,
18949
+ maxAge: 4 * 60 * 60 * 1e3
18950
+ };
18951
+ res.cookie("sid", session.sid, cookieOptions).cookie("user", session.user, cookieOptions).json({ message: "Login successful" });
18952
+ return;
18902
18953
  } catch (error2) {
18954
+ import_utils43.logger.log({
18955
+ level: "error",
18956
+ message: `Error during login: ${error2.message}`
18957
+ });
18958
+ console.log(`Error during login: ${error2}`);
18903
18959
  if (error2 instanceof import_utils43.AppError) {
18904
18960
  next(error2);
18905
18961
  } else {
18906
18962
  next(new import_utils43.InternalServerError("An unexpected error occurred"));
18907
18963
  }
18964
+ return;
18908
18965
  }
18909
18966
  }
18910
18967
  async function refreshToken(req, res, next) {
@@ -19327,9 +19384,9 @@ function useEntityRepo() {
19327
19384
  }
19328
19385
  const namespace_collection = "entities";
19329
19386
  const collection = db.collection(namespace_collection);
19330
- const { getCache, setCache, delNamespace } = (0, import_utils47.useCache)();
19387
+ const { getCache, setCache, delNamespace } = (0, import_utils47.useCache)(namespace_collection);
19331
19388
  function delCachedData() {
19332
- delNamespace(namespace_collection).then(() => {
19389
+ delNamespace().then(() => {
19333
19390
  import_utils47.logger.log({
19334
19391
  level: "info",
19335
19392
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -19409,7 +19466,7 @@ function useEntityRepo() {
19409
19466
  ]).toArray();
19410
19467
  const length = await collection.countDocuments(query);
19411
19468
  const data = (0, import_utils47.paginate)(items, page, limit, length);
19412
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
19469
+ setCache(cacheKey, data, 600).then(() => {
19413
19470
  import_utils47.logger.log({
19414
19471
  level: "info",
19415
19472
  message: `Cache set for getEntities: ${cacheKey}`
@@ -19686,9 +19743,9 @@ function useSubscriptionRepo() {
19686
19743
  }
19687
19744
  const namespace_collection = "subscriptions";
19688
19745
  const collection = db.collection(namespace_collection);
19689
- const { getCache, setCache, delNamespace } = (0, import_utils50.useCache)();
19746
+ const { getCache, setCache, delNamespace } = (0, import_utils50.useCache)(namespace_collection);
19690
19747
  function delCachedData() {
19691
- delNamespace(namespace_collection).then(() => {
19748
+ delNamespace().then(() => {
19692
19749
  import_utils50.logger.log({
19693
19750
  level: "info",
19694
19751
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -19754,7 +19811,7 @@ function useSubscriptionRepo() {
19754
19811
  }
19755
19812
  const data = await collection.findOne({ _id });
19756
19813
  if (data) {
19757
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
19814
+ setCache(cacheKey, data, 300).then(() => {
19758
19815
  import_utils50.logger.log({
19759
19816
  level: "info",
19760
19817
  message: `Cache set for subscription by ID: ${cacheKey}`
@@ -19789,7 +19846,7 @@ function useSubscriptionRepo() {
19789
19846
  }
19790
19847
  const data = await collection.findOne({ user });
19791
19848
  if (data) {
19792
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
19849
+ setCache(cacheKey, data, 300).then(() => {
19793
19850
  import_utils50.logger.log({
19794
19851
  level: "info",
19795
19852
  message: `Cache set for subscription by user ID: ${cacheKey}`
@@ -19849,7 +19906,7 @@ function useSubscriptionRepo() {
19849
19906
  }
19850
19907
  const data = await collection.findOne({ subscriptionId });
19851
19908
  if (data) {
19852
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
19909
+ setCache(cacheKey, data, 300).then(() => {
19853
19910
  import_utils50.logger.log({
19854
19911
  level: "info",
19855
19912
  message: `Cache set for subscription by subscription ID: ${cacheKey}`
@@ -19905,7 +19962,7 @@ function useSubscriptionRepo() {
19905
19962
  ]).toArray();
19906
19963
  const length = await collection.countDocuments(query);
19907
19964
  const data = (0, import_utils50.paginate)(items, page, limit, length);
19908
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
19965
+ setCache(cacheKey, data, 600).then(() => {
19909
19966
  import_utils50.logger.log({
19910
19967
  level: "info",
19911
19968
  message: `Cache set for getSubscriptions: ${cacheKey}`
@@ -20374,7 +20431,7 @@ function useOrgRepo() {
20374
20431
  }
20375
20432
  const namespace_collection = "organizations";
20376
20433
  const collection = db.collection(namespace_collection);
20377
- const { getCache, setCache, delNamespace } = (0, import_utils52.useCache)();
20434
+ const { getCache, setCache, delNamespace } = (0, import_utils52.useCache)(namespace_collection);
20378
20435
  async function createIndex() {
20379
20436
  try {
20380
20437
  await collection.createIndex([
@@ -20409,7 +20466,7 @@ function useOrgRepo() {
20409
20466
  }
20410
20467
  }
20411
20468
  function delCachedData() {
20412
- delNamespace(namespace_collection).then(() => {
20469
+ delNamespace().then(() => {
20413
20470
  import_utils52.logger.log({
20414
20471
  level: "info",
20415
20472
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -20493,7 +20550,7 @@ function useOrgRepo() {
20493
20550
  ]).toArray();
20494
20551
  const length = await collection.countDocuments(query);
20495
20552
  const data = (0, import_utils52.paginate)(items, page, limit, length);
20496
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
20553
+ setCache(cacheKey, data, 600).then(() => {
20497
20554
  import_utils52.logger.log({
20498
20555
  level: "info",
20499
20556
  message: `Cache set for getAll organizations: ${cacheKey}`
@@ -20530,7 +20587,7 @@ function useOrgRepo() {
20530
20587
  if (!result) {
20531
20588
  throw new import_utils52.BadRequestError("Organization not found.");
20532
20589
  }
20533
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
20590
+ setCache(cacheKey, result, 300).then(() => {
20534
20591
  import_utils52.logger.log({
20535
20592
  level: "info",
20536
20593
  message: `Cache set for organization by id: ${cacheKey}`
@@ -20565,7 +20622,7 @@ function useOrgRepo() {
20565
20622
  if (!result) {
20566
20623
  throw new import_utils52.BadRequestError("Organization not found.");
20567
20624
  }
20568
- setCache(cacheKey, result, 300, namespace_collection).then(() => {
20625
+ setCache(cacheKey, result, 300).then(() => {
20569
20626
  import_utils52.logger.log({
20570
20627
  level: "info",
20571
20628
  message: `Cache set for organization by name: ${cacheKey}`
@@ -20697,9 +20754,9 @@ function useAddressRepo() {
20697
20754
  }
20698
20755
  const namespace_collection = "addresses";
20699
20756
  const collection = db.collection(namespace_collection);
20700
- const { getCache, setCache, delNamespace } = (0, import_utils54.useCache)();
20757
+ const { getCache, setCache, delNamespace } = (0, import_utils54.useCache)(namespace_collection);
20701
20758
  function delCachedData() {
20702
- delNamespace(namespace_collection).then(() => {
20759
+ delNamespace().then(() => {
20703
20760
  import_utils54.logger.log({
20704
20761
  level: "info",
20705
20762
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -20775,7 +20832,7 @@ function useAddressRepo() {
20775
20832
  }
20776
20833
  const data = await collection.findOne({ user });
20777
20834
  if (data) {
20778
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
20835
+ setCache(cacheKey, data, 300).then(() => {
20779
20836
  import_utils54.logger.log({
20780
20837
  level: "info",
20781
20838
  message: `Cache set for address by user ID: ${cacheKey}`
@@ -20810,7 +20867,7 @@ function useAddressRepo() {
20810
20867
  }
20811
20868
  const data = await collection.findOne({ org });
20812
20869
  if (data) {
20813
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
20870
+ setCache(cacheKey, data, 300).then(() => {
20814
20871
  import_utils54.logger.log({
20815
20872
  level: "info",
20816
20873
  message: `Cache set for address by org ID: ${cacheKey}`
@@ -20896,9 +20953,9 @@ function usePromoCodeRepo() {
20896
20953
  }
20897
20954
  const namespace_collection = "promo-codes";
20898
20955
  const collection = db.collection(namespace_collection);
20899
- const { getCache, setCache, delNamespace } = (0, import_utils56.useCache)();
20956
+ const { getCache, setCache, delNamespace } = (0, import_utils56.useCache)(namespace_collection);
20900
20957
  function delCachedData() {
20901
- delNamespace(namespace_collection).then(() => {
20958
+ delNamespace().then(() => {
20902
20959
  import_utils56.logger.log({
20903
20960
  level: "info",
20904
20961
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -20962,7 +21019,11 @@ function usePromoCodeRepo() {
20962
21019
  } else if (assigned === false) {
20963
21020
  query.assignedTo = { $in: [null, ""] };
20964
21021
  }
20965
- const cacheKey = (0, import_utils56.makeCacheKey)(namespace_collection, { code, type: type || "default", assigned: assigned?.toString() || "any" });
21022
+ const cacheKey = (0, import_utils56.makeCacheKey)(namespace_collection, {
21023
+ code,
21024
+ type: type || "default",
21025
+ assigned: assigned?.toString() || "any"
21026
+ });
20966
21027
  try {
20967
21028
  const cached = await getCache(cacheKey);
20968
21029
  if (cached) {
@@ -20974,7 +21035,7 @@ function usePromoCodeRepo() {
20974
21035
  }
20975
21036
  const data = await collection.findOne(query);
20976
21037
  if (data) {
20977
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
21038
+ setCache(cacheKey, data, 300).then(() => {
20978
21039
  import_utils56.logger.log({
20979
21040
  level: "info",
20980
21041
  message: `Cache set for promo code by code: ${cacheKey}`
@@ -21016,7 +21077,7 @@ function usePromoCodeRepo() {
21016
21077
  }
21017
21078
  const data = await collection.findOne({ _id });
21018
21079
  if (data) {
21019
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
21080
+ setCache(cacheKey, data, 300).then(() => {
21020
21081
  import_utils56.logger.log({
21021
21082
  level: "info",
21022
21083
  message: `Cache set for promo code by ID: ${cacheKey}`
@@ -21075,7 +21136,7 @@ function usePromoCodeRepo() {
21075
21136
  ]).toArray();
21076
21137
  const length = await collection.countDocuments(query);
21077
21138
  const data = (0, import_utils56.paginate)(items, page, limit, length);
21078
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
21139
+ setCache(cacheKey, data, 600).then(() => {
21079
21140
  import_utils56.logger.log({
21080
21141
  level: "info",
21081
21142
  message: `Cache set for getPromoCodes: ${cacheKey}`
@@ -21441,9 +21502,9 @@ function useCounterRepo() {
21441
21502
  }
21442
21503
  const namespace_collection = "counters";
21443
21504
  const { collection, createCounter } = useCounterModel(db);
21444
- const { getCache, setCache, delNamespace } = (0, import_utils60.useCache)();
21505
+ const { getCache, setCache, delNamespace } = (0, import_utils60.useCache)(namespace_collection);
21445
21506
  function delCachedData() {
21446
- delNamespace(namespace_collection).then(() => {
21507
+ delNamespace().then(() => {
21447
21508
  import_utils60.logger.log({
21448
21509
  level: "info",
21449
21510
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -21513,7 +21574,7 @@ function useCounterRepo() {
21513
21574
  }
21514
21575
  const data = await collection.findOne({ type });
21515
21576
  if (data) {
21516
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
21577
+ setCache(cacheKey, data, 300).then(() => {
21517
21578
  import_utils60.logger.log({
21518
21579
  level: "info",
21519
21580
  message: `Cache set for counter by type: ${cacheKey}`
@@ -21706,9 +21767,9 @@ function usePriceRepo() {
21706
21767
  }
21707
21768
  const namespace_collection = "prices";
21708
21769
  const { collection, createPrice } = usePriceModel(db);
21709
- const { getCache, setCache, delNamespace } = (0, import_utils63.useCache)();
21770
+ const { getCache, setCache, delNamespace } = (0, import_utils63.useCache)(namespace_collection);
21710
21771
  function delCachedData() {
21711
- delNamespace(namespace_collection).then(() => {
21772
+ delNamespace().then(() => {
21712
21773
  import_utils63.logger.log({
21713
21774
  level: "info",
21714
21775
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -21778,7 +21839,7 @@ function usePriceRepo() {
21778
21839
  }
21779
21840
  const data = await collection.findOne({ name, type });
21780
21841
  if (data) {
21781
- setCache(cacheKey, data, 300, namespace_collection).then(() => {
21842
+ setCache(cacheKey, data, 300).then(() => {
21782
21843
  import_utils63.logger.log({
21783
21844
  level: "info",
21784
21845
  message: `Cache set for price by name and type: ${cacheKey}`
@@ -25042,9 +25103,9 @@ function useOrderRepo() {
25042
25103
  }
25043
25104
  const namespace_collection = "orders";
25044
25105
  const collection = db.collection(namespace_collection);
25045
- const { getCache, setCache, delNamespace } = (0, import_utils77.useCache)();
25106
+ const { getCache, setCache, delNamespace } = (0, import_utils77.useCache)(namespace_collection);
25046
25107
  function delCachedData() {
25047
- delNamespace(namespace_collection).then(() => {
25108
+ delNamespace().then(() => {
25048
25109
  import_utils77.logger.log({
25049
25110
  level: "info",
25050
25111
  message: `Cache namespace cleared for ${namespace_collection}`
@@ -25131,7 +25192,7 @@ function useOrderRepo() {
25131
25192
  ]).toArray();
25132
25193
  const length = await collection.countDocuments(query);
25133
25194
  const data = (0, import_utils77.paginate)(items, page, limit, length);
25134
- setCache(cacheKey, data, 600, namespace_collection).then(() => {
25195
+ setCache(cacheKey, data, 600).then(() => {
25135
25196
  import_utils77.logger.log({
25136
25197
  level: "info",
25137
25198
  message: `Cache set for getOrders: ${cacheKey}`
@@ -25628,11 +25689,357 @@ function usePriceController() {
25628
25689
  };
25629
25690
  }
25630
25691
 
25631
- // src/controllers/util.controller.ts
25692
+ // src/models/property.model.ts
25693
+ var import_utils83 = require("@goweekdays/utils");
25632
25694
  var import_joi28 = __toESM(require("joi"));
25695
+ var import_mongodb34 = require("mongodb");
25696
+ var schemaProperty = import_joi28.default.object({
25697
+ _id: import_joi28.default.string().optional(),
25698
+ propertyName: import_joi28.default.string().trim().required(),
25699
+ propertyType: import_joi28.default.string().trim().required(),
25700
+ propertyDescription: import_joi28.default.string().trim().required(),
25701
+ streetAddress: import_joi28.default.string().trim().required(),
25702
+ barangay: import_joi28.default.string().trim().required(),
25703
+ city: import_joi28.default.string().trim().required(),
25704
+ province: import_joi28.default.string().trim().required(),
25705
+ region: import_joi28.default.string().trim().required(),
25706
+ zipCode: import_joi28.default.string().trim().optional().allow(""),
25707
+ latitude: import_joi28.default.string().trim().optional().allow(""),
25708
+ longitude: import_joi28.default.string().trim().optional().allow(""),
25709
+ ownerId: import_joi28.default.string().trim().optional().allow(""),
25710
+ managerName: import_joi28.default.string().trim().optional().allow(""),
25711
+ managerEmail: import_joi28.default.string().trim().email().optional().allow(""),
25712
+ managerPhone: import_joi28.default.string().trim().optional().allow(""),
25713
+ amenities: import_joi28.default.array().items(import_joi28.default.string().trim()).optional(),
25714
+ numberOfFloors: import_joi28.default.string().trim().required(),
25715
+ floorLabels: import_joi28.default.string().optional().allow(""),
25716
+ coverPhoto: import_joi28.default.object({
25717
+ name: import_joi28.default.string().trim().optional().allow(""),
25718
+ size: import_joi28.default.string().trim().optional().allow(""),
25719
+ type: import_joi28.default.string().trim().optional().allow(""),
25720
+ webkitRelativePath: import_joi28.default.string().trim().optional().allow("")
25721
+ }),
25722
+ photoGallery: import_joi28.default.array().items(
25723
+ import_joi28.default.object({
25724
+ name: import_joi28.default.string().trim().optional().allow(""),
25725
+ size: import_joi28.default.string().trim().optional().allow(""),
25726
+ type: import_joi28.default.string().trim().optional().allow(""),
25727
+ webkitRelativePath: import_joi28.default.string().trim().optional().allow("")
25728
+ })
25729
+ ).required(),
25730
+ stayType: import_joi28.default.string().trim().required(),
25731
+ createdAt: import_joi28.default.date().optional(),
25732
+ updatedAt: import_joi28.default.date().optional(),
25733
+ deletedAt: import_joi28.default.date().optional()
25734
+ });
25735
+ function modelProperty(value) {
25736
+ const { error } = schemaProperty.validate(value);
25737
+ if (error) {
25738
+ throw new import_utils83.BadRequestError(`Invalid property data: ${error.message}`);
25739
+ }
25740
+ if (!value._id) {
25741
+ try {
25742
+ value._id = new import_mongodb34.ObjectId();
25743
+ } catch (error2) {
25744
+ throw new import_utils83.BadRequestError("Invalid Property ID.");
25745
+ }
25746
+ }
25747
+ return {
25748
+ _id: value._id,
25749
+ propertyName: value.propertyName,
25750
+ propertyType: value.propertyType,
25751
+ propertyDescription: value.propertyDescription,
25752
+ streetAddress: value.streetAddress,
25753
+ barangay: value.barangay,
25754
+ city: value.city,
25755
+ province: value.province,
25756
+ region: value.region,
25757
+ zipCode: value.zipCode ?? "",
25758
+ latitude: value.latitude ?? "",
25759
+ longitude: value.longitude ?? "",
25760
+ ownerId: value.ownerId ?? "",
25761
+ managerName: value.managerName ?? "",
25762
+ managerEmail: value.managerEmail ?? "",
25763
+ managerPhone: value.managerPhone ?? "",
25764
+ amenities: value.amenities ?? [],
25765
+ numberOfFloors: value.numberOfFloors,
25766
+ floorLabels: value.floorLabels ?? "",
25767
+ coverPhoto: value.coverPhoto,
25768
+ photoGallery: value.photoGallery ?? [],
25769
+ stayType: value.stayType,
25770
+ createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
25771
+ updatedAt: value.updatedAt,
25772
+ deletedAt: value.deletedAt
25773
+ };
25774
+ }
25775
+
25776
+ // src/repositories/property.repository.ts
25777
+ var import_utils84 = require("@goweekdays/utils");
25778
+ var import_mongodb35 = require("mongodb");
25779
+ function usePropertyRepo() {
25780
+ const db = import_utils84.useAtlas.getDb();
25781
+ if (!db) {
25782
+ throw new import_utils84.BadRequestError("Unable to connect to server.");
25783
+ }
25784
+ const namespace_collection = "properties";
25785
+ const collection = db.collection(namespace_collection);
25786
+ const { getCache, setCache, delNamespace } = (0, import_utils84.useCache)(namespace_collection);
25787
+ function delCachedData() {
25788
+ delNamespace().then(() => {
25789
+ import_utils84.logger.log({
25790
+ level: "info",
25791
+ message: `Cache namespace cleared for ${namespace_collection}`
25792
+ });
25793
+ }).catch((err) => {
25794
+ import_utils84.logger.log({
25795
+ level: "error",
25796
+ message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
25797
+ });
25798
+ });
25799
+ }
25800
+ async function createIndex() {
25801
+ try {
25802
+ await collection.createIndexes([
25803
+ { key: { propertyName: 1 } },
25804
+ { key: { propertyType: 1 } },
25805
+ { key: { createdAt: 1 } },
25806
+ {
25807
+ key: {
25808
+ propertyName: "text",
25809
+ propertyType: "text",
25810
+ city: "text"
25811
+ },
25812
+ name: "propertyTextSearch"
25813
+ }
25814
+ ]);
25815
+ } catch (error) {
25816
+ throw new import_utils84.BadRequestError(
25817
+ `Failed to create index on properties: ${error.message}`
25818
+ );
25819
+ }
25820
+ }
25821
+ async function add(value, session) {
25822
+ try {
25823
+ value = modelProperty(value);
25824
+ const res = await collection.insertOne(value, { session });
25825
+ delCachedData();
25826
+ return res.insertedId;
25827
+ } catch (error) {
25828
+ throw new import_utils84.BadRequestError(`Failed to create property: ${error.message}`);
25829
+ }
25830
+ }
25831
+ async function updateById(_id, value, session) {
25832
+ try {
25833
+ _id = new import_mongodb35.ObjectId(_id);
25834
+ } catch (error) {
25835
+ throw new import_utils84.BadRequestError("Invalid ID.");
25836
+ }
25837
+ try {
25838
+ const res = await collection.updateOne(
25839
+ { _id },
25840
+ { $set: { value, updatedAt: /* @__PURE__ */ new Date() } },
25841
+ { session }
25842
+ );
25843
+ delCachedData();
25844
+ return res;
25845
+ } catch (error) {
25846
+ throw new import_utils84.InternalServerError("Failed to update property.");
25847
+ }
25848
+ }
25849
+ async function deleteById(_id) {
25850
+ try {
25851
+ _id = new import_mongodb35.ObjectId(_id);
25852
+ } catch (error) {
25853
+ throw new import_utils84.BadRequestError("Invalid ID.");
25854
+ }
25855
+ try {
25856
+ const res = await collection.deleteOne({ _id });
25857
+ delCachedData();
25858
+ return res;
25859
+ } catch (error) {
25860
+ throw new import_utils84.InternalServerError("Failed to delete property.");
25861
+ }
25862
+ }
25863
+ async function getAll() {
25864
+ const cacheKey = (0, import_utils84.makeCacheKey)(namespace_collection, { action: "getAll" });
25865
+ try {
25866
+ const cached = await getCache(cacheKey);
25867
+ if (cached) {
25868
+ import_utils84.logger.log({
25869
+ level: "info",
25870
+ message: `Cache hit for getAll: ${cacheKey}`
25871
+ });
25872
+ return cached;
25873
+ }
25874
+ const properties = await collection.find({}).toArray();
25875
+ setCache(cacheKey, properties, 300).then(() => {
25876
+ import_utils84.logger.log({
25877
+ level: "info",
25878
+ message: `Cache set for getAll: ${cacheKey}`
25879
+ });
25880
+ }).catch((err) => {
25881
+ import_utils84.logger.log({
25882
+ level: "error",
25883
+ message: `Failed to set cache: ${err.message}`
25884
+ });
25885
+ });
25886
+ return properties;
25887
+ } catch (error) {
25888
+ throw new import_utils84.InternalServerError(
25889
+ `Failed to fetch properties: ${error.message}`
25890
+ );
25891
+ }
25892
+ }
25893
+ async function getById(_id) {
25894
+ try {
25895
+ _id = new import_mongodb35.ObjectId(_id);
25896
+ } catch (error) {
25897
+ throw new import_utils84.BadRequestError("Invalid ID.");
25898
+ }
25899
+ const cacheKey = (0, import_utils84.makeCacheKey)(namespace_collection, { _id: String(_id) });
25900
+ try {
25901
+ const cached = await getCache(cacheKey);
25902
+ if (cached) {
25903
+ import_utils84.logger.log({
25904
+ level: "info",
25905
+ message: `Cache hit for getById: ${cacheKey}`
25906
+ });
25907
+ return cached;
25908
+ }
25909
+ const property = await collection.findOne({});
25910
+ if (!property) {
25911
+ throw new import_utils84.BadRequestError("Property not found.");
25912
+ }
25913
+ setCache(cacheKey, property, 300).then(() => {
25914
+ import_utils84.logger.log({
25915
+ level: "info",
25916
+ message: `Cache set for getById: ${cacheKey}`
25917
+ });
25918
+ }).catch((err) => {
25919
+ import_utils84.logger.log({
25920
+ level: "error",
25921
+ message: `Failed to set cache: ${err.message}`
25922
+ });
25923
+ });
25924
+ return property;
25925
+ } catch (error) {
25926
+ if (error instanceof import_utils84.BadRequestError) {
25927
+ throw error;
25928
+ }
25929
+ throw new import_utils84.InternalServerError(
25930
+ `Failed to fetch property: ${error.message}`
25931
+ );
25932
+ }
25933
+ }
25934
+ return {
25935
+ createIndex,
25936
+ add,
25937
+ deleteById,
25938
+ updateById,
25939
+ getAll,
25940
+ getById
25941
+ };
25942
+ }
25943
+
25944
+ // src/controllers/property.controller.ts
25945
+ var import_utils85 = require("@goweekdays/utils");
25946
+ var import_joi29 = __toESM(require("joi"));
25947
+ function usePropertyController() {
25948
+ const {
25949
+ add: _add,
25950
+ updateById: _updateById,
25951
+ getAll: _getAll,
25952
+ getById: _getById
25953
+ } = usePropertyRepo();
25954
+ async function add(req, res, next) {
25955
+ const value = req.body;
25956
+ const { error } = schemaProperty.validate(value);
25957
+ if (error) {
25958
+ next(new import_utils85.BadRequestError(error.message));
25959
+ return;
25960
+ }
25961
+ try {
25962
+ const id = await _add(value);
25963
+ res.json({ message: "Successfully added property.", id });
25964
+ return;
25965
+ } catch (error2) {
25966
+ next(error2);
25967
+ }
25968
+ }
25969
+ async function updateById(req, res, next) {
25970
+ const _id = req.params.id ?? "";
25971
+ const value = { _id, ...req.body };
25972
+ const validation = import_joi29.default.object({
25973
+ _id: import_joi29.default.string().required(),
25974
+ name: import_joi29.default.string().trim().required(),
25975
+ type: import_joi29.default.string().trim().required(),
25976
+ description: import_joi29.default.string().trim().required(),
25977
+ street: import_joi29.default.string().trim().required(),
25978
+ barangay: import_joi29.default.string().trim().required(),
25979
+ cityMunicipality: import_joi29.default.string().trim().required(),
25980
+ province: import_joi29.default.string().trim().required(),
25981
+ region: import_joi29.default.string().trim().required(),
25982
+ zipCode: import_joi29.default.string().trim().optional().allow(""),
25983
+ latitude: import_joi29.default.string().trim().optional().allow(""),
25984
+ longitude: import_joi29.default.string().trim().optional().allow(""),
25985
+ ownerId: import_joi29.default.string().trim().optional().allow(""),
25986
+ ownerName: import_joi29.default.string().trim().optional().allow(""),
25987
+ email: import_joi29.default.string().trim().email().optional().allow(""),
25988
+ phone: import_joi29.default.string().trim().optional().allow(""),
25989
+ amenities: import_joi29.default.array().items(import_joi29.default.string().trim()).optional(),
25990
+ floorNumber: import_joi29.default.string().trim().required(),
25991
+ floorLabel: import_joi29.default.string().optional().allow(""),
25992
+ coverPhoto: import_joi29.default.string().trim().required(),
25993
+ photoGallery: import_joi29.default.array().items(import_joi29.default.string().trim()).required(),
25994
+ stayType: import_joi29.default.string().trim().required()
25995
+ });
25996
+ const { error } = validation.validate(value);
25997
+ if (error) {
25998
+ throw new import_utils85.BadRequestError(`Invalid property data: ${error.message}`);
25999
+ }
26000
+ try {
26001
+ const result = await _updateById(_id, req.body);
26002
+ res.json({ message: "Successfully updated property.", result });
26003
+ } catch (error2) {
26004
+ next(error2);
26005
+ }
26006
+ }
26007
+ async function getAll(req, res, next) {
26008
+ try {
26009
+ const properties = await _getAll();
26010
+ res.json(properties);
26011
+ return;
26012
+ } catch (error) {
26013
+ next(error);
26014
+ }
26015
+ }
26016
+ async function getById(req, res, next) {
26017
+ const { id } = req.params;
26018
+ if (!id) {
26019
+ next(new import_utils85.BadRequestError("Property ID is required."));
26020
+ return;
26021
+ }
26022
+ try {
26023
+ const property = await _getById(id);
26024
+ res.json(property);
26025
+ return;
26026
+ } catch (error) {
26027
+ next(error);
26028
+ }
26029
+ }
26030
+ return {
26031
+ add,
26032
+ updateById,
26033
+ getAll,
26034
+ getById
26035
+ };
26036
+ }
26037
+
26038
+ // src/controllers/util.controller.ts
26039
+ var import_joi30 = __toESM(require("joi"));
25633
26040
 
25634
26041
  // src/services/github.service.ts
25635
- var import_utils83 = require("@goweekdays/utils");
26042
+ var import_utils86 = require("@goweekdays/utils");
25636
26043
  var import_rest = require("@octokit/rest");
25637
26044
  var import_libsodium_wrappers = __toESM(require("libsodium-wrappers"));
25638
26045
  function useGitHubService() {
@@ -25646,23 +26053,23 @@ function useGitHubService() {
25646
26053
  try {
25647
26054
  const { data: repoData } = await octokit.repos.get({ owner, repo });
25648
26055
  if (!repoData.permissions?.admin) {
25649
- throw new import_utils83.BadRequestError(
26056
+ throw new import_utils86.BadRequestError(
25650
26057
  "You do not have admin access to this repository."
25651
26058
  );
25652
26059
  }
25653
26060
  } catch (error) {
25654
26061
  if (error.status === 404) {
25655
- throw new import_utils83.BadRequestError(
26062
+ throw new import_utils86.BadRequestError(
25656
26063
  "Repository not found or you don't have access to it."
25657
26064
  );
25658
26065
  } else if (error.status === 401) {
25659
- throw new import_utils83.BadRequestError(
26066
+ throw new import_utils86.BadRequestError(
25660
26067
  "Invalid GitHub token or insufficient permissions."
25661
26068
  );
25662
26069
  } else if (error.message.includes("admin access")) {
25663
26070
  throw error;
25664
26071
  } else {
25665
- throw new import_utils83.BadRequestError(
26072
+ throw new import_utils86.BadRequestError(
25666
26073
  `Failed to check repository permissions: ${error.message}`
25667
26074
  );
25668
26075
  }
@@ -25711,7 +26118,7 @@ function useGitHubService() {
25711
26118
  key_id: publicKeyRes.key_id
25712
26119
  });
25713
26120
  } catch (encryptionError) {
25714
- throw new import_utils83.BadRequestError(
26121
+ throw new import_utils86.BadRequestError(
25715
26122
  `Failed to encrypt secret '${key}': ${encryptionError.message}`
25716
26123
  );
25717
26124
  }
@@ -25741,22 +26148,22 @@ function useGitHubService() {
25741
26148
  }
25742
26149
  return `Successfully set ${lines.length} ${type} variables/secrets in environment '${environment}'`;
25743
26150
  } catch (error) {
25744
- if (error instanceof import_utils83.AppError)
26151
+ if (error instanceof import_utils86.AppError)
25745
26152
  throw error;
25746
26153
  if (error.status === 422) {
25747
- throw new import_utils83.BadRequestError(
26154
+ throw new import_utils86.BadRequestError(
25748
26155
  `GitHub API validation error: ${error.message}`
25749
26156
  );
25750
26157
  } else if (error.status === 404) {
25751
- throw new import_utils83.BadRequestError("Environment or repository not found.");
26158
+ throw new import_utils86.BadRequestError("Environment or repository not found.");
25752
26159
  } else if (error.status === 403) {
25753
- throw new import_utils83.BadRequestError(
26160
+ throw new import_utils86.BadRequestError(
25754
26161
  "Forbidden: Insufficient permissions or rate limit exceeded."
25755
26162
  );
25756
26163
  } else if (error.message.includes("admin access") || error.message.includes("permissions")) {
25757
26164
  throw error;
25758
26165
  } else {
25759
- throw new import_utils83.BadRequestError(
26166
+ throw new import_utils86.BadRequestError(
25760
26167
  `Failed to set GitHub variables: ${error.message}`
25761
26168
  );
25762
26169
  }
@@ -25768,7 +26175,7 @@ function useGitHubService() {
25768
26175
  }
25769
26176
 
25770
26177
  // src/controllers/util.controller.ts
25771
- var import_utils84 = require("@goweekdays/utils");
26178
+ var import_utils87 = require("@goweekdays/utils");
25772
26179
  function useUtilController() {
25773
26180
  async function healthCheck(req, res, next) {
25774
26181
  try {
@@ -25784,32 +26191,32 @@ function useUtilController() {
25784
26191
  }
25785
26192
  });
25786
26193
  } catch (error) {
25787
- import_utils84.logger.error("Health check failed", { error: error.message });
25788
- next(new import_utils84.InternalServerError("Health check failed"));
26194
+ import_utils87.logger.error("Health check failed", { error: error.message });
26195
+ next(new import_utils87.InternalServerError("Health check failed"));
25789
26196
  }
25790
26197
  }
25791
26198
  async function setGitHubVariables(req, res, next) {
25792
26199
  try {
25793
26200
  const { githubToken, repoUrl, environment, type, keyValues } = req.body;
25794
- const validation = import_joi28.default.object({
25795
- githubToken: import_joi28.default.string().required().messages({
26201
+ const validation = import_joi30.default.object({
26202
+ githubToken: import_joi30.default.string().required().messages({
25796
26203
  "string.empty": "GitHub token is required",
25797
26204
  "any.required": "GitHub token is required"
25798
26205
  }),
25799
- repoUrl: import_joi28.default.string().uri().required().messages({
26206
+ repoUrl: import_joi30.default.string().uri().required().messages({
25800
26207
  "string.empty": "Repository URL is required",
25801
26208
  "string.uri": "Repository URL must be a valid URL",
25802
26209
  "any.required": "Repository URL is required"
25803
26210
  }),
25804
- environment: import_joi28.default.string().required().messages({
26211
+ environment: import_joi30.default.string().required().messages({
25805
26212
  "string.empty": "Environment name is required",
25806
26213
  "any.required": "Environment name is required"
25807
26214
  }),
25808
- type: import_joi28.default.string().valid("env", "secret").required().messages({
26215
+ type: import_joi30.default.string().valid("env", "secret").required().messages({
25809
26216
  "any.only": 'Type must be either "env" or "secret"',
25810
26217
  "any.required": "Type is required"
25811
26218
  }),
25812
- keyValues: import_joi28.default.string().required().messages({
26219
+ keyValues: import_joi30.default.string().required().messages({
25813
26220
  "string.empty": "Key-value pairs are required",
25814
26221
  "any.required": "Key-value pairs are required"
25815
26222
  })
@@ -25822,13 +26229,13 @@ function useUtilController() {
25822
26229
  keyValues
25823
26230
  });
25824
26231
  if (error) {
25825
- next(new import_utils84.BadRequestError(error.message));
26232
+ next(new import_utils87.BadRequestError(error.message));
25826
26233
  return;
25827
26234
  }
25828
26235
  const repoUrlPattern = /github\.com[:\/]([^\/]+)\/(.+)\.git$/;
25829
26236
  if (!repoUrlPattern.test(repoUrl)) {
25830
26237
  next(
25831
- new import_utils84.BadRequestError(
26238
+ new import_utils87.BadRequestError(
25832
26239
  "Invalid GitHub repository URL format. Expected format: https://github.com/owner/repo.git"
25833
26240
  )
25834
26241
  );
@@ -25840,7 +26247,7 @@ function useUtilController() {
25840
26247
  );
25841
26248
  if (invalidLines.length > 0) {
25842
26249
  next(
25843
- new import_utils84.BadRequestError(
26250
+ new import_utils87.BadRequestError(
25844
26251
  "Invalid key-value format. Each pair should be in format: KEY=value. Pairs can be separated by newlines, spaces, or tabs."
25845
26252
  )
25846
26253
  );
@@ -25854,7 +26261,7 @@ function useUtilController() {
25854
26261
  type,
25855
26262
  keyValues
25856
26263
  });
25857
- import_utils84.logger.info(`GitHub variables set successfully`, {
26264
+ import_utils87.logger.info(`GitHub variables set successfully`, {
25858
26265
  repoUrl,
25859
26266
  environment,
25860
26267
  type,
@@ -25871,15 +26278,15 @@ function useUtilController() {
25871
26278
  }
25872
26279
  });
25873
26280
  } catch (error) {
25874
- import_utils84.logger.error("Failed to set GitHub variables", {
26281
+ import_utils87.logger.error("Failed to set GitHub variables", {
25875
26282
  error: error.message,
25876
26283
  stack: error.stack
25877
26284
  });
25878
- if (error instanceof import_utils84.AppError) {
26285
+ if (error instanceof import_utils87.AppError) {
25879
26286
  next(error);
25880
26287
  } else {
25881
26288
  next(
25882
- new import_utils84.InternalServerError(
26289
+ new import_utils87.InternalServerError(
25883
26290
  `Failed to set GitHub variables: ${error.message}`
25884
26291
  )
25885
26292
  );
@@ -25902,6 +26309,7 @@ function useUtilController() {
25902
26309
  DEFAULT_USER_FIRST_NAME,
25903
26310
  DEFAULT_USER_LAST_NAME,
25904
26311
  DEFAULT_USER_PASSWORD,
26312
+ DOMAIN,
25905
26313
  DirectDebitSchema,
25906
26314
  EWalletPaymentSchema,
25907
26315
  MAILER_EMAIL,
@@ -25946,7 +26354,9 @@ function useUtilController() {
25946
26354
  XENDIT_SECRET_KEY,
25947
26355
  addressSchema,
25948
26356
  isDev,
26357
+ modelProperty,
25949
26358
  schema,
26359
+ schemaProperty,
25950
26360
  useAddressController,
25951
26361
  useAddressRepo,
25952
26362
  useAuthController,
@@ -25981,6 +26391,8 @@ function useUtilController() {
25981
26391
  usePriceRepo,
25982
26392
  usePromoCodeController,
25983
26393
  usePromoCodeRepo,
26394
+ usePropertyController,
26395
+ usePropertyRepo,
25984
26396
  useRoleController,
25985
26397
  useRoleRepo,
25986
26398
  useSubscriptionController,