@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/CHANGELOG.md +6 -0
- package/dist/index.d.ts +50 -4
- package/dist/index.js +540 -128
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +683 -248
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -11585,9 +11585,9 @@ function useVerificationRepo() {
|
|
|
11585
11585
|
}
|
|
11586
11586
|
const namespace_collection = "verifications";
|
|
11587
11587
|
const collection = db.collection(namespace_collection);
|
|
11588
|
-
const { getCache, setCache, delNamespace } = useCache();
|
|
11588
|
+
const { getCache, setCache, delNamespace } = useCache(namespace_collection);
|
|
11589
11589
|
function delCachedData() {
|
|
11590
|
-
delNamespace(
|
|
11590
|
+
delNamespace().then(() => {
|
|
11591
11591
|
logger.log({
|
|
11592
11592
|
level: "info",
|
|
11593
11593
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -11675,7 +11675,7 @@ function useVerificationRepo() {
|
|
|
11675
11675
|
return cached;
|
|
11676
11676
|
}
|
|
11677
11677
|
const data = await collection.findOne({ _id });
|
|
11678
|
-
setCache(cacheKey, data, 300
|
|
11678
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
11679
11679
|
logger.log({
|
|
11680
11680
|
level: "info",
|
|
11681
11681
|
message: `Cache set for verification by id: ${cacheKey}`
|
|
@@ -11755,7 +11755,7 @@ function useVerificationRepo() {
|
|
|
11755
11755
|
]).toArray();
|
|
11756
11756
|
const length = await collection.countDocuments(query);
|
|
11757
11757
|
const data = paginate(items, page, limit, length);
|
|
11758
|
-
setCache(cacheKey, data, 600
|
|
11758
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
11759
11759
|
logger.log({
|
|
11760
11760
|
level: "info",
|
|
11761
11761
|
message: `Cache set for getVerifications: ${cacheKey}`
|
|
@@ -11786,7 +11786,7 @@ function useVerificationRepo() {
|
|
|
11786
11786
|
return cached;
|
|
11787
11787
|
}
|
|
11788
11788
|
const data = await collection.find({ type }).toArray();
|
|
11789
|
-
setCache(cacheKey, data, 600
|
|
11789
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
11790
11790
|
logger.log({
|
|
11791
11791
|
level: "info",
|
|
11792
11792
|
message: `Cache set for verification by type: ${cacheKey}`
|
|
@@ -11884,6 +11884,7 @@ var PAYPAL_CLIENT_SECRET = process.env.PAYPAL_CLIENT_SECRET ?? "";
|
|
|
11884
11884
|
var PAYPAL_API_URL = process.env.PAYPAL_API_URL ?? "https://api-m.sandbox.paypal.com";
|
|
11885
11885
|
var XENDIT_SECRET_KEY = process.env.XENDIT_SECRET_KEY ?? "";
|
|
11886
11886
|
var XENDIT_BASE_URL = process.env.XENDIT_BASE_URL ?? "https://api.xendit.co";
|
|
11887
|
+
var DOMAIN = process.env.DOMAIN || "localhost";
|
|
11887
11888
|
|
|
11888
11889
|
// src/repositories/user.repository.ts
|
|
11889
11890
|
import { ObjectId as ObjectId4 } from "mongodb";
|
|
@@ -11946,9 +11947,9 @@ function useUserRepo() {
|
|
|
11946
11947
|
}
|
|
11947
11948
|
const namespace_collection = "users";
|
|
11948
11949
|
const collection = db.collection(namespace_collection);
|
|
11949
|
-
const { getCache, setCache, delNamespace } = useCache2();
|
|
11950
|
+
const { getCache, setCache, delNamespace } = useCache2(namespace_collection);
|
|
11950
11951
|
function delCachedData() {
|
|
11951
|
-
delNamespace(
|
|
11952
|
+
delNamespace().then(() => {
|
|
11952
11953
|
logger2.log({
|
|
11953
11954
|
level: "info",
|
|
11954
11955
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -12010,7 +12011,7 @@ function useUserRepo() {
|
|
|
12010
12011
|
}
|
|
12011
12012
|
const result = await collection.findOne({ email });
|
|
12012
12013
|
if (result) {
|
|
12013
|
-
setCache(cacheKey, result, 300
|
|
12014
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
12014
12015
|
logger2.log({
|
|
12015
12016
|
level: "info",
|
|
12016
12017
|
message: `Cache set for user by email: ${cacheKey}`
|
|
@@ -12040,7 +12041,7 @@ function useUserRepo() {
|
|
|
12040
12041
|
}
|
|
12041
12042
|
const result = await collection.findOne({ referralCode });
|
|
12042
12043
|
if (result) {
|
|
12043
|
-
setCache(cacheKey, result, 300
|
|
12044
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
12044
12045
|
logger2.log({
|
|
12045
12046
|
level: "info",
|
|
12046
12047
|
message: `Cache set for user by referral code: ${cacheKey}`
|
|
@@ -12075,7 +12076,7 @@ function useUserRepo() {
|
|
|
12075
12076
|
}
|
|
12076
12077
|
const result = await collection.findOne({ _id });
|
|
12077
12078
|
if (result) {
|
|
12078
|
-
setCache(cacheKey, result, 300
|
|
12079
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
12079
12080
|
logger2.log({
|
|
12080
12081
|
level: "info",
|
|
12081
12082
|
message: `Cache set for user by id: ${cacheKey}`
|
|
@@ -12149,7 +12150,7 @@ function useUserRepo() {
|
|
|
12149
12150
|
]).toArray();
|
|
12150
12151
|
const length = await collection.countDocuments(query);
|
|
12151
12152
|
const data = paginate2(items, page, limit, length);
|
|
12152
|
-
setCache(cacheKey, data, 600
|
|
12153
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
12153
12154
|
logger2.log({
|
|
12154
12155
|
level: "info",
|
|
12155
12156
|
message: `Cache set for getUsers: ${cacheKey}`
|
|
@@ -12372,9 +12373,9 @@ function useMemberRepo() {
|
|
|
12372
12373
|
}
|
|
12373
12374
|
const namespace_collection = "members";
|
|
12374
12375
|
const collection = db.collection(namespace_collection);
|
|
12375
|
-
const { getCache, setCache, delNamespace } = useCache3();
|
|
12376
|
+
const { getCache, setCache, delNamespace } = useCache3(namespace_collection);
|
|
12376
12377
|
function delCachedData() {
|
|
12377
|
-
delNamespace(
|
|
12378
|
+
delNamespace().then(() => {
|
|
12378
12379
|
logger3.log({
|
|
12379
12380
|
level: "info",
|
|
12380
12381
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -12460,7 +12461,7 @@ function useMemberRepo() {
|
|
|
12460
12461
|
return cached;
|
|
12461
12462
|
}
|
|
12462
12463
|
const data = await collection.findOne({ _id });
|
|
12463
|
-
setCache(cacheKey, data, 300
|
|
12464
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12464
12465
|
logger3.log({
|
|
12465
12466
|
level: "info",
|
|
12466
12467
|
message: `Cache set for member by id: ${cacheKey}`
|
|
@@ -12497,7 +12498,7 @@ function useMemberRepo() {
|
|
|
12497
12498
|
return cached;
|
|
12498
12499
|
}
|
|
12499
12500
|
const data = await collection.findOne({ user });
|
|
12500
|
-
setCache(cacheKey, data, 300
|
|
12501
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12501
12502
|
logger3.log({
|
|
12502
12503
|
level: "info",
|
|
12503
12504
|
message: `Cache set for member by user ID: ${cacheKey}`
|
|
@@ -12550,7 +12551,7 @@ function useMemberRepo() {
|
|
|
12550
12551
|
return cached;
|
|
12551
12552
|
}
|
|
12552
12553
|
const data = await collection.findOne(query);
|
|
12553
|
-
setCache(cacheKey, data, 300
|
|
12554
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12554
12555
|
logger3.log({
|
|
12555
12556
|
level: "info",
|
|
12556
12557
|
message: `Cache set for member by user ID: ${cacheKey}`
|
|
@@ -12654,7 +12655,7 @@ function useMemberRepo() {
|
|
|
12654
12655
|
]).toArray();
|
|
12655
12656
|
const length = await collection.countDocuments(query);
|
|
12656
12657
|
const data = paginate3(items, page, limit, length);
|
|
12657
|
-
setCache(cacheKey, data, 600
|
|
12658
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
12658
12659
|
logger3.log({
|
|
12659
12660
|
level: "info",
|
|
12660
12661
|
message: `Cache set for getAll members: ${cacheKey}`
|
|
@@ -12689,7 +12690,7 @@ function useMemberRepo() {
|
|
|
12689
12690
|
return cached;
|
|
12690
12691
|
}
|
|
12691
12692
|
const data = await collection.countDocuments({ org, status: "active" });
|
|
12692
|
-
setCache(cacheKey, data, 300
|
|
12693
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12693
12694
|
logger3.log({
|
|
12694
12695
|
level: "info",
|
|
12695
12696
|
message: `Cache set for countByOrg members: ${cacheKey}`
|
|
@@ -12726,7 +12727,7 @@ function useMemberRepo() {
|
|
|
12726
12727
|
return cached;
|
|
12727
12728
|
}
|
|
12728
12729
|
const data = await collection.countDocuments({ user, status: "active" });
|
|
12729
|
-
setCache(cacheKey, data, 300
|
|
12730
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12730
12731
|
logger3.log({
|
|
12731
12732
|
level: "info",
|
|
12732
12733
|
message: `Cache set for countByUser members: ${cacheKey}`
|
|
@@ -12800,7 +12801,7 @@ function useMemberRepo() {
|
|
|
12800
12801
|
]).toArray();
|
|
12801
12802
|
const length = await collection.countDocuments(query);
|
|
12802
12803
|
const data = paginate3(items, page, limit, length);
|
|
12803
|
-
setCache(cacheKey, data, 600
|
|
12804
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
12804
12805
|
logger3.log({
|
|
12805
12806
|
level: "info",
|
|
12806
12807
|
message: `Cache set for getOrgsByMembership members: ${cacheKey}`
|
|
@@ -12878,7 +12879,7 @@ function useMemberRepo() {
|
|
|
12878
12879
|
]).toArray();
|
|
12879
12880
|
const length = await collection.countDocuments(query);
|
|
12880
12881
|
const data = paginate3(items, page, limit, length);
|
|
12881
|
-
setCache(cacheKey, data, 300
|
|
12882
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12882
12883
|
logger3.log({
|
|
12883
12884
|
level: "info",
|
|
12884
12885
|
message: `Cache set for getOrgsByUserId members: ${cacheKey}`
|
|
@@ -13444,7 +13445,13 @@ var MToken = class {
|
|
|
13444
13445
|
};
|
|
13445
13446
|
|
|
13446
13447
|
// src/repositories/token.repository.ts
|
|
13447
|
-
import {
|
|
13448
|
+
import {
|
|
13449
|
+
InternalServerError as InternalServerError6,
|
|
13450
|
+
logger as logger5,
|
|
13451
|
+
makeCacheKey as makeCacheKey4,
|
|
13452
|
+
useAtlas as useAtlas5,
|
|
13453
|
+
useCache as useCache4
|
|
13454
|
+
} from "@goweekdays/utils";
|
|
13448
13455
|
import { ObjectId as ObjectId8 } from "mongodb";
|
|
13449
13456
|
function useTokenRepo() {
|
|
13450
13457
|
const db = useAtlas5.getDb();
|
|
@@ -13453,9 +13460,9 @@ function useTokenRepo() {
|
|
|
13453
13460
|
}
|
|
13454
13461
|
const namespace_collection = "tokens";
|
|
13455
13462
|
const collection = db.collection(namespace_collection);
|
|
13456
|
-
const { getCache, setCache, delNamespace } = useCache4();
|
|
13463
|
+
const { getCache, setCache, delNamespace } = useCache4(namespace_collection);
|
|
13457
13464
|
function delCachedData() {
|
|
13458
|
-
delNamespace(
|
|
13465
|
+
delNamespace().then(() => {
|
|
13459
13466
|
logger5.log({
|
|
13460
13467
|
level: "info",
|
|
13461
13468
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -13494,7 +13501,7 @@ function useTokenRepo() {
|
|
|
13494
13501
|
}
|
|
13495
13502
|
const data = await collection.findOne({ token });
|
|
13496
13503
|
if (data) {
|
|
13497
|
-
setCache(cacheKey, data, 300
|
|
13504
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
13498
13505
|
logger5.log({
|
|
13499
13506
|
level: "info",
|
|
13500
13507
|
message: `Cache set for token: ${cacheKey}`
|
|
@@ -13570,9 +13577,9 @@ function useFileRepo() {
|
|
|
13570
13577
|
}
|
|
13571
13578
|
const namespace_collection = "files";
|
|
13572
13579
|
const collection = db.collection(namespace_collection);
|
|
13573
|
-
const { getCache, setCache, delNamespace } = useCache5();
|
|
13580
|
+
const { getCache, setCache, delNamespace } = useCache5(namespace_collection);
|
|
13574
13581
|
function delCachedData() {
|
|
13575
|
-
delNamespace(
|
|
13582
|
+
delNamespace().then(() => {
|
|
13576
13583
|
logger6.log({
|
|
13577
13584
|
level: "info",
|
|
13578
13585
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -13620,7 +13627,7 @@ function useFileRepo() {
|
|
|
13620
13627
|
return cached;
|
|
13621
13628
|
}
|
|
13622
13629
|
const data = await collection.find({ $and: [{ status: "draft" }, { status: null }] }).toArray();
|
|
13623
|
-
setCache(cacheKey, data, 300
|
|
13630
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
13624
13631
|
logger6.log({
|
|
13625
13632
|
level: "info",
|
|
13626
13633
|
message: `Cache set for getAllDraftedFiles: ${cacheKey}`
|
|
@@ -17654,9 +17661,9 @@ function useRoleRepo() {
|
|
|
17654
17661
|
}
|
|
17655
17662
|
const namespace_collection = "roles";
|
|
17656
17663
|
const collection = db.collection(namespace_collection);
|
|
17657
|
-
const { getCache, setCache, delNamespace } = useCache6();
|
|
17664
|
+
const { getCache, setCache, delNamespace } = useCache6(namespace_collection);
|
|
17658
17665
|
function delCachedData() {
|
|
17659
|
-
delNamespace(
|
|
17666
|
+
delNamespace().then(() => {
|
|
17660
17667
|
logger8.log({
|
|
17661
17668
|
level: "info",
|
|
17662
17669
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -17728,7 +17735,7 @@ function useRoleRepo() {
|
|
|
17728
17735
|
return cached;
|
|
17729
17736
|
}
|
|
17730
17737
|
const data = await collection.findOne({ user: value });
|
|
17731
|
-
setCache(cacheKey, data, 300
|
|
17738
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
17732
17739
|
logger8.log({
|
|
17733
17740
|
level: "info",
|
|
17734
17741
|
message: `Cache set for role by user ID: ${cacheKey}`
|
|
@@ -17763,7 +17770,7 @@ function useRoleRepo() {
|
|
|
17763
17770
|
return cached;
|
|
17764
17771
|
}
|
|
17765
17772
|
const data = await collection.findOne({ _id });
|
|
17766
|
-
setCache(cacheKey, data, 300
|
|
17773
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
17767
17774
|
logger8.log({
|
|
17768
17775
|
level: "info",
|
|
17769
17776
|
message: `Cache set for role by id: ${cacheKey}`
|
|
@@ -17796,7 +17803,7 @@ function useRoleRepo() {
|
|
|
17796
17803
|
return cached;
|
|
17797
17804
|
}
|
|
17798
17805
|
const data = await collection.findOne({ name });
|
|
17799
|
-
setCache(cacheKey, data, 300
|
|
17806
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
17800
17807
|
logger8.log({
|
|
17801
17808
|
level: "info",
|
|
17802
17809
|
message: `Cache set for role by name: ${cacheKey}`
|
|
@@ -17831,7 +17838,11 @@ function useRoleRepo() {
|
|
|
17831
17838
|
}
|
|
17832
17839
|
}
|
|
17833
17840
|
const query = { status: "active", org };
|
|
17834
|
-
const cacheKeyOptions = {
|
|
17841
|
+
const cacheKeyOptions = {
|
|
17842
|
+
status: "active",
|
|
17843
|
+
limit,
|
|
17844
|
+
page
|
|
17845
|
+
};
|
|
17835
17846
|
if (org) {
|
|
17836
17847
|
cacheKeyOptions.org = String(org);
|
|
17837
17848
|
}
|
|
@@ -17863,7 +17874,7 @@ function useRoleRepo() {
|
|
|
17863
17874
|
]).toArray();
|
|
17864
17875
|
const length = await collection.countDocuments(query);
|
|
17865
17876
|
const data = paginate4(items, page, limit, length);
|
|
17866
|
-
setCache(cacheKey, data, 600
|
|
17877
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
17867
17878
|
logger8.log({
|
|
17868
17879
|
level: "info",
|
|
17869
17880
|
message: `Cache set for getRoles: ${cacheKey}`
|
|
@@ -18027,9 +18038,9 @@ function useSocialRepo() {
|
|
|
18027
18038
|
}
|
|
18028
18039
|
const namespace_collection = "roles";
|
|
18029
18040
|
const collection = db.collection(namespace_collection);
|
|
18030
|
-
const { getCache, setCache, delNamespace } = useCache7();
|
|
18041
|
+
const { getCache, setCache, delNamespace } = useCache7(namespace_collection);
|
|
18031
18042
|
function delCachedData() {
|
|
18032
|
-
delNamespace(
|
|
18043
|
+
delNamespace().then(() => {
|
|
18033
18044
|
logger9.log({
|
|
18034
18045
|
level: "info",
|
|
18035
18046
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -18558,7 +18569,8 @@ function useUserController() {
|
|
|
18558
18569
|
const id = req.params.id || "";
|
|
18559
18570
|
const validation = Joi5.string().hex().validate(id);
|
|
18560
18571
|
if (validation.error) {
|
|
18561
|
-
|
|
18572
|
+
next(new BadRequestError13("Invalid id."));
|
|
18573
|
+
return;
|
|
18562
18574
|
}
|
|
18563
18575
|
try {
|
|
18564
18576
|
const user = await _getUserById(id);
|
|
@@ -18729,11 +18741,62 @@ import {
|
|
|
18729
18741
|
comparePassword,
|
|
18730
18742
|
generateToken,
|
|
18731
18743
|
InternalServerError as InternalServerError12,
|
|
18732
|
-
NotFoundError as NotFoundError3
|
|
18744
|
+
NotFoundError as NotFoundError3,
|
|
18745
|
+
useCache as useCache9
|
|
18733
18746
|
} from "@goweekdays/utils";
|
|
18734
18747
|
import jwt from "jsonwebtoken";
|
|
18748
|
+
|
|
18749
|
+
// node_modules/uuid/dist/esm-node/rng.js
|
|
18750
|
+
import crypto2 from "crypto";
|
|
18751
|
+
var rnds8Pool = new Uint8Array(256);
|
|
18752
|
+
var poolPtr = rnds8Pool.length;
|
|
18753
|
+
function rng() {
|
|
18754
|
+
if (poolPtr > rnds8Pool.length - 16) {
|
|
18755
|
+
crypto2.randomFillSync(rnds8Pool);
|
|
18756
|
+
poolPtr = 0;
|
|
18757
|
+
}
|
|
18758
|
+
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
18759
|
+
}
|
|
18760
|
+
|
|
18761
|
+
// node_modules/uuid/dist/esm-node/stringify.js
|
|
18762
|
+
var byteToHex = [];
|
|
18763
|
+
for (let i = 0; i < 256; ++i) {
|
|
18764
|
+
byteToHex.push((i + 256).toString(16).slice(1));
|
|
18765
|
+
}
|
|
18766
|
+
function unsafeStringify(arr, offset = 0) {
|
|
18767
|
+
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]];
|
|
18768
|
+
}
|
|
18769
|
+
|
|
18770
|
+
// node_modules/uuid/dist/esm-node/native.js
|
|
18771
|
+
import crypto3 from "crypto";
|
|
18772
|
+
var native_default = {
|
|
18773
|
+
randomUUID: crypto3.randomUUID
|
|
18774
|
+
};
|
|
18775
|
+
|
|
18776
|
+
// node_modules/uuid/dist/esm-node/v4.js
|
|
18777
|
+
function v4(options, buf, offset) {
|
|
18778
|
+
if (native_default.randomUUID && !buf && !options) {
|
|
18779
|
+
return native_default.randomUUID();
|
|
18780
|
+
}
|
|
18781
|
+
options = options || {};
|
|
18782
|
+
const rnds = options.random || (options.rng || rng)();
|
|
18783
|
+
rnds[6] = rnds[6] & 15 | 64;
|
|
18784
|
+
rnds[8] = rnds[8] & 63 | 128;
|
|
18785
|
+
if (buf) {
|
|
18786
|
+
offset = offset || 0;
|
|
18787
|
+
for (let i = 0; i < 16; ++i) {
|
|
18788
|
+
buf[offset + i] = rnds[i];
|
|
18789
|
+
}
|
|
18790
|
+
return buf;
|
|
18791
|
+
}
|
|
18792
|
+
return unsafeStringify(rnds);
|
|
18793
|
+
}
|
|
18794
|
+
var v4_default = v4;
|
|
18795
|
+
|
|
18796
|
+
// src/services/auth.service.ts
|
|
18735
18797
|
function useAuthService() {
|
|
18736
18798
|
const expiresIn = "1m";
|
|
18799
|
+
const { setCache } = useCache9("sessions");
|
|
18737
18800
|
async function login({ email, password } = {}) {
|
|
18738
18801
|
if (!email) {
|
|
18739
18802
|
throw new BadRequestError14("Email is required");
|
|
@@ -18765,34 +18828,14 @@ function useAuthService() {
|
|
|
18765
18828
|
if (!isPasswordValid) {
|
|
18766
18829
|
throw new BadRequestError14("Invalid password");
|
|
18767
18830
|
}
|
|
18768
|
-
const
|
|
18769
|
-
|
|
18770
|
-
|
|
18771
|
-
|
|
18772
|
-
|
|
18773
|
-
|
|
18774
|
-
|
|
18775
|
-
|
|
18776
|
-
} catch (error) {
|
|
18777
|
-
throw new BadRequestError14("Error generating refresh token");
|
|
18778
|
-
}
|
|
18779
|
-
let accessToken;
|
|
18780
|
-
try {
|
|
18781
|
-
accessToken = generateToken({
|
|
18782
|
-
secret: ACCESS_TOKEN_SECRET,
|
|
18783
|
-
metadata,
|
|
18784
|
-
options: { expiresIn }
|
|
18785
|
-
});
|
|
18786
|
-
} catch (error) {
|
|
18787
|
-
throw new BadRequestError14("Error generating access token");
|
|
18788
|
-
}
|
|
18789
|
-
const user = _user._id ?? "";
|
|
18790
|
-
try {
|
|
18791
|
-
await useTokenRepo().createToken({ token: refreshToken2, user });
|
|
18792
|
-
} catch (error) {
|
|
18793
|
-
throw new BadRequestError14("Error creating refresh token");
|
|
18794
|
-
}
|
|
18795
|
-
return { accessToken, refreshToken: refreshToken2, id: _user._id };
|
|
18831
|
+
const sid = v4_default();
|
|
18832
|
+
const cacheKey = `sid:${sid}`;
|
|
18833
|
+
setCache(cacheKey, _user, 14400).then(() => {
|
|
18834
|
+
console.log("Session ID cached successfully");
|
|
18835
|
+
}).catch((error) => {
|
|
18836
|
+
console.error("Error caching session ID:", error);
|
|
18837
|
+
});
|
|
18838
|
+
return { sid, user: _user._id?.toString() ?? "" };
|
|
18796
18839
|
}
|
|
18797
18840
|
async function refreshToken(token) {
|
|
18798
18841
|
let decoded;
|
|
@@ -18859,7 +18902,8 @@ import Joi6 from "joi";
|
|
|
18859
18902
|
import {
|
|
18860
18903
|
AppError as AppError6,
|
|
18861
18904
|
BadRequestError as BadRequestError15,
|
|
18862
|
-
InternalServerError as InternalServerError13
|
|
18905
|
+
InternalServerError as InternalServerError13,
|
|
18906
|
+
logger as logger11
|
|
18863
18907
|
} from "@goweekdays/utils";
|
|
18864
18908
|
function useAuthController() {
|
|
18865
18909
|
const { signUp: _signUp } = useVerificationService();
|
|
@@ -18873,16 +18917,32 @@ function useAuthController() {
|
|
|
18873
18917
|
const { error } = validation.validate({ email, password });
|
|
18874
18918
|
if (error) {
|
|
18875
18919
|
next(new BadRequestError15(error.message));
|
|
18920
|
+
return;
|
|
18876
18921
|
}
|
|
18877
18922
|
try {
|
|
18878
|
-
const
|
|
18879
|
-
|
|
18923
|
+
const session = await useAuthService().login({
|
|
18924
|
+
email,
|
|
18925
|
+
password
|
|
18926
|
+
});
|
|
18927
|
+
const cookieOptions = {
|
|
18928
|
+
domain: DOMAIN,
|
|
18929
|
+
secure: true,
|
|
18930
|
+
maxAge: 4 * 60 * 60 * 1e3
|
|
18931
|
+
};
|
|
18932
|
+
res.cookie("sid", session.sid, cookieOptions).cookie("user", session.user, cookieOptions).json({ message: "Login successful" });
|
|
18933
|
+
return;
|
|
18880
18934
|
} catch (error2) {
|
|
18935
|
+
logger11.log({
|
|
18936
|
+
level: "error",
|
|
18937
|
+
message: `Error during login: ${error2.message}`
|
|
18938
|
+
});
|
|
18939
|
+
console.log(`Error during login: ${error2}`);
|
|
18881
18940
|
if (error2 instanceof AppError6) {
|
|
18882
18941
|
next(error2);
|
|
18883
18942
|
} else {
|
|
18884
18943
|
next(new InternalServerError13("An unexpected error occurred"));
|
|
18885
18944
|
}
|
|
18945
|
+
return;
|
|
18886
18946
|
}
|
|
18887
18947
|
}
|
|
18888
18948
|
async function refreshToken(req, res, next) {
|
|
@@ -18984,7 +19044,7 @@ function useAuthController() {
|
|
|
18984
19044
|
}
|
|
18985
19045
|
|
|
18986
19046
|
// src/services/file.service.ts
|
|
18987
|
-
import { logger as
|
|
19047
|
+
import { logger as logger12, useS3 as useS32, useAtlas as useAtlas10 } from "@goweekdays/utils";
|
|
18988
19048
|
import cron from "node-cron";
|
|
18989
19049
|
function useFileService() {
|
|
18990
19050
|
const {
|
|
@@ -19045,12 +19105,12 @@ function useFileService() {
|
|
|
19045
19105
|
const file = files[index];
|
|
19046
19106
|
try {
|
|
19047
19107
|
await deleteFile(file._id.toString());
|
|
19048
|
-
await
|
|
19108
|
+
await logger12.log({
|
|
19049
19109
|
level: "info",
|
|
19050
19110
|
message: "Successfully deleted draft files."
|
|
19051
19111
|
});
|
|
19052
19112
|
} catch (error) {
|
|
19053
|
-
|
|
19113
|
+
logger12.log({
|
|
19054
19114
|
level: "info",
|
|
19055
19115
|
message: "Successfully deleted draft files."
|
|
19056
19116
|
});
|
|
@@ -19304,11 +19364,11 @@ import { ObjectId as ObjectId17 } from "mongodb";
|
|
|
19304
19364
|
import {
|
|
19305
19365
|
BadRequestError as BadRequestError18,
|
|
19306
19366
|
InternalServerError as InternalServerError16,
|
|
19307
|
-
logger as
|
|
19367
|
+
logger as logger13,
|
|
19308
19368
|
makeCacheKey as makeCacheKey9,
|
|
19309
19369
|
paginate as paginate5,
|
|
19310
19370
|
useAtlas as useAtlas11,
|
|
19311
|
-
useCache as
|
|
19371
|
+
useCache as useCache10
|
|
19312
19372
|
} from "@goweekdays/utils";
|
|
19313
19373
|
function useEntityRepo() {
|
|
19314
19374
|
const db = useAtlas11.getDb();
|
|
@@ -19317,15 +19377,15 @@ function useEntityRepo() {
|
|
|
19317
19377
|
}
|
|
19318
19378
|
const namespace_collection = "entities";
|
|
19319
19379
|
const collection = db.collection(namespace_collection);
|
|
19320
|
-
const { getCache, setCache, delNamespace } =
|
|
19380
|
+
const { getCache, setCache, delNamespace } = useCache10(namespace_collection);
|
|
19321
19381
|
function delCachedData() {
|
|
19322
|
-
delNamespace(
|
|
19323
|
-
|
|
19382
|
+
delNamespace().then(() => {
|
|
19383
|
+
logger13.log({
|
|
19324
19384
|
level: "info",
|
|
19325
19385
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
19326
19386
|
});
|
|
19327
19387
|
}).catch((err) => {
|
|
19328
|
-
|
|
19388
|
+
logger13.log({
|
|
19329
19389
|
level: "error",
|
|
19330
19390
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
19331
19391
|
});
|
|
@@ -19355,7 +19415,7 @@ function useEntityRepo() {
|
|
|
19355
19415
|
delCachedData();
|
|
19356
19416
|
return res.insertedId.toString();
|
|
19357
19417
|
} catch (error) {
|
|
19358
|
-
|
|
19418
|
+
logger13.log({ level: "error", message: `${error}` });
|
|
19359
19419
|
const isDuplicated = error.message.includes("duplicate");
|
|
19360
19420
|
if (isDuplicated) {
|
|
19361
19421
|
throw new BadRequestError18("Entity name already exists.");
|
|
@@ -19385,7 +19445,7 @@ function useEntityRepo() {
|
|
|
19385
19445
|
try {
|
|
19386
19446
|
const cached = await getCache(cacheKey);
|
|
19387
19447
|
if (cached) {
|
|
19388
|
-
|
|
19448
|
+
logger13.log({
|
|
19389
19449
|
level: "info",
|
|
19390
19450
|
message: `Cache hit for getEntities: ${cacheKey}`
|
|
19391
19451
|
});
|
|
@@ -19399,20 +19459,20 @@ function useEntityRepo() {
|
|
|
19399
19459
|
]).toArray();
|
|
19400
19460
|
const length = await collection.countDocuments(query);
|
|
19401
19461
|
const data = paginate5(items, page, limit, length);
|
|
19402
|
-
setCache(cacheKey, data, 600
|
|
19403
|
-
|
|
19462
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
19463
|
+
logger13.log({
|
|
19404
19464
|
level: "info",
|
|
19405
19465
|
message: `Cache set for getEntities: ${cacheKey}`
|
|
19406
19466
|
});
|
|
19407
19467
|
}).catch((err) => {
|
|
19408
|
-
|
|
19468
|
+
logger13.log({
|
|
19409
19469
|
level: "error",
|
|
19410
19470
|
message: `Failed to set cache for getEntities: ${err.message}`
|
|
19411
19471
|
});
|
|
19412
19472
|
});
|
|
19413
19473
|
return data;
|
|
19414
19474
|
} catch (error) {
|
|
19415
|
-
|
|
19475
|
+
logger13.log({ level: "error", message: `${error}` });
|
|
19416
19476
|
throw error;
|
|
19417
19477
|
}
|
|
19418
19478
|
}
|
|
@@ -19666,7 +19726,14 @@ function MSubscription(value) {
|
|
|
19666
19726
|
}
|
|
19667
19727
|
|
|
19668
19728
|
// src/repositories/subscription.repository.ts
|
|
19669
|
-
import {
|
|
19729
|
+
import {
|
|
19730
|
+
BadRequestError as BadRequestError21,
|
|
19731
|
+
logger as logger14,
|
|
19732
|
+
makeCacheKey as makeCacheKey10,
|
|
19733
|
+
paginate as paginate6,
|
|
19734
|
+
useAtlas as useAtlas12,
|
|
19735
|
+
useCache as useCache11
|
|
19736
|
+
} from "@goweekdays/utils";
|
|
19670
19737
|
import { ObjectId as ObjectId19 } from "mongodb";
|
|
19671
19738
|
import Joi11 from "joi";
|
|
19672
19739
|
function useSubscriptionRepo() {
|
|
@@ -19676,15 +19743,15 @@ function useSubscriptionRepo() {
|
|
|
19676
19743
|
}
|
|
19677
19744
|
const namespace_collection = "subscriptions";
|
|
19678
19745
|
const collection = db.collection(namespace_collection);
|
|
19679
|
-
const { getCache, setCache, delNamespace } =
|
|
19746
|
+
const { getCache, setCache, delNamespace } = useCache11(namespace_collection);
|
|
19680
19747
|
function delCachedData() {
|
|
19681
|
-
delNamespace(
|
|
19682
|
-
|
|
19748
|
+
delNamespace().then(() => {
|
|
19749
|
+
logger14.log({
|
|
19683
19750
|
level: "info",
|
|
19684
19751
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
19685
19752
|
});
|
|
19686
19753
|
}).catch((err) => {
|
|
19687
|
-
|
|
19754
|
+
logger14.log({
|
|
19688
19755
|
level: "error",
|
|
19689
19756
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
19690
19757
|
});
|
|
@@ -19736,7 +19803,7 @@ function useSubscriptionRepo() {
|
|
|
19736
19803
|
try {
|
|
19737
19804
|
const cached = await getCache(cacheKey);
|
|
19738
19805
|
if (cached) {
|
|
19739
|
-
|
|
19806
|
+
logger14.log({
|
|
19740
19807
|
level: "info",
|
|
19741
19808
|
message: `Cache hit for getById subscription: ${cacheKey}`
|
|
19742
19809
|
});
|
|
@@ -19744,13 +19811,13 @@ function useSubscriptionRepo() {
|
|
|
19744
19811
|
}
|
|
19745
19812
|
const data = await collection.findOne({ _id });
|
|
19746
19813
|
if (data) {
|
|
19747
|
-
setCache(cacheKey, data, 300
|
|
19748
|
-
|
|
19814
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
19815
|
+
logger14.log({
|
|
19749
19816
|
level: "info",
|
|
19750
19817
|
message: `Cache set for subscription by ID: ${cacheKey}`
|
|
19751
19818
|
});
|
|
19752
19819
|
}).catch((err) => {
|
|
19753
|
-
|
|
19820
|
+
logger14.log({
|
|
19754
19821
|
level: "error",
|
|
19755
19822
|
message: `Failed to set cache for subscription by ID: ${err.message}`
|
|
19756
19823
|
});
|
|
@@ -19771,7 +19838,7 @@ function useSubscriptionRepo() {
|
|
|
19771
19838
|
try {
|
|
19772
19839
|
const cached = await getCache(cacheKey);
|
|
19773
19840
|
if (cached) {
|
|
19774
|
-
|
|
19841
|
+
logger14.log({
|
|
19775
19842
|
level: "info",
|
|
19776
19843
|
message: `Cache hit for getByUserId subscription: ${cacheKey}`
|
|
19777
19844
|
});
|
|
@@ -19779,13 +19846,13 @@ function useSubscriptionRepo() {
|
|
|
19779
19846
|
}
|
|
19780
19847
|
const data = await collection.findOne({ user });
|
|
19781
19848
|
if (data) {
|
|
19782
|
-
setCache(cacheKey, data, 300
|
|
19783
|
-
|
|
19849
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
19850
|
+
logger14.log({
|
|
19784
19851
|
level: "info",
|
|
19785
19852
|
message: `Cache set for subscription by user ID: ${cacheKey}`
|
|
19786
19853
|
});
|
|
19787
19854
|
}).catch((err) => {
|
|
19788
|
-
|
|
19855
|
+
logger14.log({
|
|
19789
19856
|
level: "error",
|
|
19790
19857
|
message: `Failed to set cache for subscription by user ID: ${err.message}`
|
|
19791
19858
|
});
|
|
@@ -19831,7 +19898,7 @@ function useSubscriptionRepo() {
|
|
|
19831
19898
|
try {
|
|
19832
19899
|
const cached = await getCache(cacheKey);
|
|
19833
19900
|
if (cached) {
|
|
19834
|
-
|
|
19901
|
+
logger14.log({
|
|
19835
19902
|
level: "info",
|
|
19836
19903
|
message: `Cache hit for getBySubscriptionId: ${cacheKey}`
|
|
19837
19904
|
});
|
|
@@ -19839,13 +19906,13 @@ function useSubscriptionRepo() {
|
|
|
19839
19906
|
}
|
|
19840
19907
|
const data = await collection.findOne({ subscriptionId });
|
|
19841
19908
|
if (data) {
|
|
19842
|
-
setCache(cacheKey, data, 300
|
|
19843
|
-
|
|
19909
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
19910
|
+
logger14.log({
|
|
19844
19911
|
level: "info",
|
|
19845
19912
|
message: `Cache set for subscription by subscription ID: ${cacheKey}`
|
|
19846
19913
|
});
|
|
19847
19914
|
}).catch((err) => {
|
|
19848
|
-
|
|
19915
|
+
logger14.log({
|
|
19849
19916
|
level: "error",
|
|
19850
19917
|
message: `Failed to set cache for subscription by subscription ID: ${err.message}`
|
|
19851
19918
|
});
|
|
@@ -19881,7 +19948,7 @@ function useSubscriptionRepo() {
|
|
|
19881
19948
|
try {
|
|
19882
19949
|
const cached = await getCache(cacheKey);
|
|
19883
19950
|
if (cached) {
|
|
19884
|
-
|
|
19951
|
+
logger14.log({
|
|
19885
19952
|
level: "info",
|
|
19886
19953
|
message: `Cache hit for getSubscriptions: ${cacheKey}`
|
|
19887
19954
|
});
|
|
@@ -19895,20 +19962,20 @@ function useSubscriptionRepo() {
|
|
|
19895
19962
|
]).toArray();
|
|
19896
19963
|
const length = await collection.countDocuments(query);
|
|
19897
19964
|
const data = paginate6(items, page, limit, length);
|
|
19898
|
-
setCache(cacheKey, data, 600
|
|
19899
|
-
|
|
19965
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
19966
|
+
logger14.log({
|
|
19900
19967
|
level: "info",
|
|
19901
19968
|
message: `Cache set for getSubscriptions: ${cacheKey}`
|
|
19902
19969
|
});
|
|
19903
19970
|
}).catch((err) => {
|
|
19904
|
-
|
|
19971
|
+
logger14.log({
|
|
19905
19972
|
level: "error",
|
|
19906
19973
|
message: `Failed to set cache for getSubscriptions: ${err.message}`
|
|
19907
19974
|
});
|
|
19908
19975
|
});
|
|
19909
19976
|
return data;
|
|
19910
19977
|
} catch (error) {
|
|
19911
|
-
|
|
19978
|
+
logger14.log({ level: "error", message: `${error}` });
|
|
19912
19979
|
throw error;
|
|
19913
19980
|
}
|
|
19914
19981
|
}
|
|
@@ -20055,10 +20122,10 @@ function useSubscriptionRepo() {
|
|
|
20055
20122
|
},
|
|
20056
20123
|
{ session }
|
|
20057
20124
|
);
|
|
20058
|
-
|
|
20125
|
+
logger14.info(`${res.modifiedCount} subscription updated.`);
|
|
20059
20126
|
return "Successfully updated subscription.";
|
|
20060
20127
|
} catch (error2) {
|
|
20061
|
-
|
|
20128
|
+
logger14.error(`${error2}`);
|
|
20062
20129
|
throw new BadRequestError21("Failed to update subscription.");
|
|
20063
20130
|
}
|
|
20064
20131
|
}
|
|
@@ -20307,18 +20374,18 @@ function useSubscriptionRepo() {
|
|
|
20307
20374
|
}
|
|
20308
20375
|
|
|
20309
20376
|
// src/services/subscription.service.ts
|
|
20310
|
-
import { AppError as AppError9, BadRequestError as BadRequestError34, logger as
|
|
20377
|
+
import { AppError as AppError9, BadRequestError as BadRequestError34, logger as logger22, useAtlas as useAtlas20 } from "@goweekdays/utils";
|
|
20311
20378
|
|
|
20312
20379
|
// src/repositories/organization.repository.ts
|
|
20313
20380
|
import {
|
|
20314
20381
|
AppError as AppError8,
|
|
20315
20382
|
BadRequestError as BadRequestError23,
|
|
20316
20383
|
InternalServerError as InternalServerError17,
|
|
20317
|
-
logger as
|
|
20384
|
+
logger as logger15,
|
|
20318
20385
|
makeCacheKey as makeCacheKey11,
|
|
20319
20386
|
paginate as paginate7,
|
|
20320
20387
|
useAtlas as useAtlas13,
|
|
20321
|
-
useCache as
|
|
20388
|
+
useCache as useCache12
|
|
20322
20389
|
} from "@goweekdays/utils";
|
|
20323
20390
|
|
|
20324
20391
|
// src/models/organization.model.ts
|
|
@@ -20373,7 +20440,7 @@ function useOrgRepo() {
|
|
|
20373
20440
|
}
|
|
20374
20441
|
const namespace_collection = "organizations";
|
|
20375
20442
|
const collection = db.collection(namespace_collection);
|
|
20376
|
-
const { getCache, setCache, delNamespace } =
|
|
20443
|
+
const { getCache, setCache, delNamespace } = useCache12(namespace_collection);
|
|
20377
20444
|
async function createIndex() {
|
|
20378
20445
|
try {
|
|
20379
20446
|
await collection.createIndex([
|
|
@@ -20408,13 +20475,13 @@ function useOrgRepo() {
|
|
|
20408
20475
|
}
|
|
20409
20476
|
}
|
|
20410
20477
|
function delCachedData() {
|
|
20411
|
-
delNamespace(
|
|
20412
|
-
|
|
20478
|
+
delNamespace().then(() => {
|
|
20479
|
+
logger15.log({
|
|
20413
20480
|
level: "info",
|
|
20414
20481
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
20415
20482
|
});
|
|
20416
20483
|
}).catch((err) => {
|
|
20417
|
-
|
|
20484
|
+
logger15.log({
|
|
20418
20485
|
level: "error",
|
|
20419
20486
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
20420
20487
|
});
|
|
@@ -20427,7 +20494,7 @@ function useOrgRepo() {
|
|
|
20427
20494
|
delCachedData();
|
|
20428
20495
|
return res.insertedId;
|
|
20429
20496
|
} catch (error) {
|
|
20430
|
-
|
|
20497
|
+
logger15.log({
|
|
20431
20498
|
level: "error",
|
|
20432
20499
|
message: error.message
|
|
20433
20500
|
});
|
|
@@ -20462,14 +20529,14 @@ function useOrgRepo() {
|
|
|
20462
20529
|
sort: JSON.stringify(sort),
|
|
20463
20530
|
status
|
|
20464
20531
|
});
|
|
20465
|
-
|
|
20532
|
+
logger15.log({
|
|
20466
20533
|
level: "info",
|
|
20467
20534
|
message: `Cache key for getAll organizations: ${cacheKey}`
|
|
20468
20535
|
});
|
|
20469
20536
|
try {
|
|
20470
20537
|
const cached = await getCache(cacheKey);
|
|
20471
20538
|
if (cached) {
|
|
20472
|
-
|
|
20539
|
+
logger15.log({
|
|
20473
20540
|
level: "info",
|
|
20474
20541
|
message: `Cache hit for getAll organizations: ${cacheKey}`
|
|
20475
20542
|
});
|
|
@@ -20492,20 +20559,20 @@ function useOrgRepo() {
|
|
|
20492
20559
|
]).toArray();
|
|
20493
20560
|
const length = await collection.countDocuments(query);
|
|
20494
20561
|
const data = paginate7(items, page, limit, length);
|
|
20495
|
-
setCache(cacheKey, data, 600
|
|
20496
|
-
|
|
20562
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
20563
|
+
logger15.log({
|
|
20497
20564
|
level: "info",
|
|
20498
20565
|
message: `Cache set for getAll organizations: ${cacheKey}`
|
|
20499
20566
|
});
|
|
20500
20567
|
}).catch((err) => {
|
|
20501
|
-
|
|
20568
|
+
logger15.log({
|
|
20502
20569
|
level: "error",
|
|
20503
20570
|
message: `Failed to set cache for getAll organizations: ${err.message}`
|
|
20504
20571
|
});
|
|
20505
20572
|
});
|
|
20506
20573
|
return data;
|
|
20507
20574
|
} catch (error) {
|
|
20508
|
-
|
|
20575
|
+
logger15.log({ level: "error", message: `${error}` });
|
|
20509
20576
|
throw error;
|
|
20510
20577
|
}
|
|
20511
20578
|
}
|
|
@@ -20519,7 +20586,7 @@ function useOrgRepo() {
|
|
|
20519
20586
|
try {
|
|
20520
20587
|
const cached = await getCache(cacheKey);
|
|
20521
20588
|
if (cached) {
|
|
20522
|
-
|
|
20589
|
+
logger15.log({
|
|
20523
20590
|
level: "info",
|
|
20524
20591
|
message: `Cache hit for getById organization: ${cacheKey}`
|
|
20525
20592
|
});
|
|
@@ -20529,13 +20596,13 @@ function useOrgRepo() {
|
|
|
20529
20596
|
if (!result) {
|
|
20530
20597
|
throw new BadRequestError23("Organization not found.");
|
|
20531
20598
|
}
|
|
20532
|
-
setCache(cacheKey, result, 300
|
|
20533
|
-
|
|
20599
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
20600
|
+
logger15.log({
|
|
20534
20601
|
level: "info",
|
|
20535
20602
|
message: `Cache set for organization by id: ${cacheKey}`
|
|
20536
20603
|
});
|
|
20537
20604
|
}).catch((err) => {
|
|
20538
|
-
|
|
20605
|
+
logger15.log({
|
|
20539
20606
|
level: "error",
|
|
20540
20607
|
message: `Failed to set cache for organization by id: ${err.message}`
|
|
20541
20608
|
});
|
|
@@ -20554,7 +20621,7 @@ function useOrgRepo() {
|
|
|
20554
20621
|
try {
|
|
20555
20622
|
const cached = await getCache(cacheKey);
|
|
20556
20623
|
if (cached) {
|
|
20557
|
-
|
|
20624
|
+
logger15.log({
|
|
20558
20625
|
level: "info",
|
|
20559
20626
|
message: `Cache hit for getByName organization: ${cacheKey}`
|
|
20560
20627
|
});
|
|
@@ -20564,13 +20631,13 @@ function useOrgRepo() {
|
|
|
20564
20631
|
if (!result) {
|
|
20565
20632
|
throw new BadRequestError23("Organization not found.");
|
|
20566
20633
|
}
|
|
20567
|
-
setCache(cacheKey, result, 300
|
|
20568
|
-
|
|
20634
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
20635
|
+
logger15.log({
|
|
20569
20636
|
level: "info",
|
|
20570
20637
|
message: `Cache set for organization by name: ${cacheKey}`
|
|
20571
20638
|
});
|
|
20572
20639
|
}).catch((err) => {
|
|
20573
|
-
|
|
20640
|
+
logger15.log({
|
|
20574
20641
|
level: "error",
|
|
20575
20642
|
message: `Failed to set cache for organization by name: ${err.message}`
|
|
20576
20643
|
});
|
|
@@ -20640,7 +20707,13 @@ function useOrgRepo() {
|
|
|
20640
20707
|
}
|
|
20641
20708
|
|
|
20642
20709
|
// src/repositories/address.repository.ts
|
|
20643
|
-
import {
|
|
20710
|
+
import {
|
|
20711
|
+
BadRequestError as BadRequestError25,
|
|
20712
|
+
useAtlas as useAtlas14,
|
|
20713
|
+
useCache as useCache13,
|
|
20714
|
+
makeCacheKey as makeCacheKey12,
|
|
20715
|
+
logger as logger16
|
|
20716
|
+
} from "@goweekdays/utils";
|
|
20644
20717
|
|
|
20645
20718
|
// src/models/address.model.ts
|
|
20646
20719
|
import { BadRequestError as BadRequestError24 } from "@goweekdays/utils";
|
|
@@ -20696,15 +20769,15 @@ function useAddressRepo() {
|
|
|
20696
20769
|
}
|
|
20697
20770
|
const namespace_collection = "addresses";
|
|
20698
20771
|
const collection = db.collection(namespace_collection);
|
|
20699
|
-
const { getCache, setCache, delNamespace } =
|
|
20772
|
+
const { getCache, setCache, delNamespace } = useCache13(namespace_collection);
|
|
20700
20773
|
function delCachedData() {
|
|
20701
|
-
delNamespace(
|
|
20702
|
-
|
|
20774
|
+
delNamespace().then(() => {
|
|
20775
|
+
logger16.log({
|
|
20703
20776
|
level: "info",
|
|
20704
20777
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
20705
20778
|
});
|
|
20706
20779
|
}).catch((err) => {
|
|
20707
|
-
|
|
20780
|
+
logger16.log({
|
|
20708
20781
|
level: "error",
|
|
20709
20782
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
20710
20783
|
});
|
|
@@ -20766,7 +20839,7 @@ function useAddressRepo() {
|
|
|
20766
20839
|
try {
|
|
20767
20840
|
const cached = await getCache(cacheKey);
|
|
20768
20841
|
if (cached) {
|
|
20769
|
-
|
|
20842
|
+
logger16.log({
|
|
20770
20843
|
level: "info",
|
|
20771
20844
|
message: `Cache hit for getByUserId address: ${cacheKey}`
|
|
20772
20845
|
});
|
|
@@ -20774,13 +20847,13 @@ function useAddressRepo() {
|
|
|
20774
20847
|
}
|
|
20775
20848
|
const data = await collection.findOne({ user });
|
|
20776
20849
|
if (data) {
|
|
20777
|
-
setCache(cacheKey, data, 300
|
|
20778
|
-
|
|
20850
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
20851
|
+
logger16.log({
|
|
20779
20852
|
level: "info",
|
|
20780
20853
|
message: `Cache set for address by user ID: ${cacheKey}`
|
|
20781
20854
|
});
|
|
20782
20855
|
}).catch((err) => {
|
|
20783
|
-
|
|
20856
|
+
logger16.log({
|
|
20784
20857
|
level: "error",
|
|
20785
20858
|
message: `Failed to set cache for address by user ID: ${err.message}`
|
|
20786
20859
|
});
|
|
@@ -20801,7 +20874,7 @@ function useAddressRepo() {
|
|
|
20801
20874
|
try {
|
|
20802
20875
|
const cached = await getCache(cacheKey);
|
|
20803
20876
|
if (cached) {
|
|
20804
|
-
|
|
20877
|
+
logger16.log({
|
|
20805
20878
|
level: "info",
|
|
20806
20879
|
message: `Cache hit for getByOrgId address: ${cacheKey}`
|
|
20807
20880
|
});
|
|
@@ -20809,13 +20882,13 @@ function useAddressRepo() {
|
|
|
20809
20882
|
}
|
|
20810
20883
|
const data = await collection.findOne({ org });
|
|
20811
20884
|
if (data) {
|
|
20812
|
-
setCache(cacheKey, data, 300
|
|
20813
|
-
|
|
20885
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
20886
|
+
logger16.log({
|
|
20814
20887
|
level: "info",
|
|
20815
20888
|
message: `Cache set for address by org ID: ${cacheKey}`
|
|
20816
20889
|
});
|
|
20817
20890
|
}).catch((err) => {
|
|
20818
|
-
|
|
20891
|
+
logger16.log({
|
|
20819
20892
|
level: "error",
|
|
20820
20893
|
message: `Failed to set cache for address by org ID: ${err.message}`
|
|
20821
20894
|
});
|
|
@@ -20839,11 +20912,11 @@ function useAddressRepo() {
|
|
|
20839
20912
|
import {
|
|
20840
20913
|
BadRequestError as BadRequestError27,
|
|
20841
20914
|
InternalServerError as InternalServerError18,
|
|
20842
|
-
logger as
|
|
20915
|
+
logger as logger17,
|
|
20843
20916
|
makeCacheKey as makeCacheKey13,
|
|
20844
20917
|
paginate as paginate8,
|
|
20845
20918
|
useAtlas as useAtlas15,
|
|
20846
|
-
useCache as
|
|
20919
|
+
useCache as useCache14
|
|
20847
20920
|
} from "@goweekdays/utils";
|
|
20848
20921
|
|
|
20849
20922
|
// src/validations/promo-code.schema.ts
|
|
@@ -20903,15 +20976,15 @@ function usePromoCodeRepo() {
|
|
|
20903
20976
|
}
|
|
20904
20977
|
const namespace_collection = "promo-codes";
|
|
20905
20978
|
const collection = db.collection(namespace_collection);
|
|
20906
|
-
const { getCache, setCache, delNamespace } =
|
|
20979
|
+
const { getCache, setCache, delNamespace } = useCache14(namespace_collection);
|
|
20907
20980
|
function delCachedData() {
|
|
20908
|
-
delNamespace(
|
|
20909
|
-
|
|
20981
|
+
delNamespace().then(() => {
|
|
20982
|
+
logger17.log({
|
|
20910
20983
|
level: "info",
|
|
20911
20984
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
20912
20985
|
});
|
|
20913
20986
|
}).catch((err) => {
|
|
20914
|
-
|
|
20987
|
+
logger17.log({
|
|
20915
20988
|
level: "error",
|
|
20916
20989
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
20917
20990
|
});
|
|
@@ -20944,7 +21017,7 @@ function usePromoCodeRepo() {
|
|
|
20944
21017
|
await collection.insertOne(value);
|
|
20945
21018
|
delCachedData();
|
|
20946
21019
|
} catch (error) {
|
|
20947
|
-
|
|
21020
|
+
logger17.log({ level: "error", message: `${error}` });
|
|
20948
21021
|
const isDuplicated = error.message.includes("duplicate");
|
|
20949
21022
|
if (isDuplicated) {
|
|
20950
21023
|
throw new BadRequestError27("Promo code already exists.");
|
|
@@ -20969,11 +21042,15 @@ function usePromoCodeRepo() {
|
|
|
20969
21042
|
} else if (assigned === false) {
|
|
20970
21043
|
query.assignedTo = { $in: [null, ""] };
|
|
20971
21044
|
}
|
|
20972
|
-
const cacheKey = makeCacheKey13(namespace_collection, {
|
|
21045
|
+
const cacheKey = makeCacheKey13(namespace_collection, {
|
|
21046
|
+
code,
|
|
21047
|
+
type: type || "default",
|
|
21048
|
+
assigned: assigned?.toString() || "any"
|
|
21049
|
+
});
|
|
20973
21050
|
try {
|
|
20974
21051
|
const cached = await getCache(cacheKey);
|
|
20975
21052
|
if (cached) {
|
|
20976
|
-
|
|
21053
|
+
logger17.log({
|
|
20977
21054
|
level: "info",
|
|
20978
21055
|
message: `Cache hit for getByCode promo code: ${cacheKey}`
|
|
20979
21056
|
});
|
|
@@ -20981,13 +21058,13 @@ function usePromoCodeRepo() {
|
|
|
20981
21058
|
}
|
|
20982
21059
|
const data = await collection.findOne(query);
|
|
20983
21060
|
if (data) {
|
|
20984
|
-
setCache(cacheKey, data, 300
|
|
20985
|
-
|
|
21061
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
21062
|
+
logger17.log({
|
|
20986
21063
|
level: "info",
|
|
20987
21064
|
message: `Cache set for promo code by code: ${cacheKey}`
|
|
20988
21065
|
});
|
|
20989
21066
|
}).catch((err) => {
|
|
20990
|
-
|
|
21067
|
+
logger17.log({
|
|
20991
21068
|
level: "error",
|
|
20992
21069
|
message: `Failed to set cache for promo code by code: ${err.message}`
|
|
20993
21070
|
});
|
|
@@ -21015,7 +21092,7 @@ function usePromoCodeRepo() {
|
|
|
21015
21092
|
try {
|
|
21016
21093
|
const cached = await getCache(cacheKey);
|
|
21017
21094
|
if (cached) {
|
|
21018
|
-
|
|
21095
|
+
logger17.log({
|
|
21019
21096
|
level: "info",
|
|
21020
21097
|
message: `Cache hit for getById promo code: ${cacheKey}`
|
|
21021
21098
|
});
|
|
@@ -21023,13 +21100,13 @@ function usePromoCodeRepo() {
|
|
|
21023
21100
|
}
|
|
21024
21101
|
const data = await collection.findOne({ _id });
|
|
21025
21102
|
if (data) {
|
|
21026
|
-
setCache(cacheKey, data, 300
|
|
21027
|
-
|
|
21103
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
21104
|
+
logger17.log({
|
|
21028
21105
|
level: "info",
|
|
21029
21106
|
message: `Cache set for promo code by ID: ${cacheKey}`
|
|
21030
21107
|
});
|
|
21031
21108
|
}).catch((err) => {
|
|
21032
|
-
|
|
21109
|
+
logger17.log({
|
|
21033
21110
|
level: "error",
|
|
21034
21111
|
message: `Failed to set cache for promo code by ID: ${err.message}`
|
|
21035
21112
|
});
|
|
@@ -21068,7 +21145,7 @@ function usePromoCodeRepo() {
|
|
|
21068
21145
|
try {
|
|
21069
21146
|
const cached = await getCache(cacheKey);
|
|
21070
21147
|
if (cached) {
|
|
21071
|
-
|
|
21148
|
+
logger17.log({
|
|
21072
21149
|
level: "info",
|
|
21073
21150
|
message: `Cache hit for getPromoCodes: ${cacheKey}`
|
|
21074
21151
|
});
|
|
@@ -21082,20 +21159,20 @@ function usePromoCodeRepo() {
|
|
|
21082
21159
|
]).toArray();
|
|
21083
21160
|
const length = await collection.countDocuments(query);
|
|
21084
21161
|
const data = paginate8(items, page, limit, length);
|
|
21085
|
-
setCache(cacheKey, data, 600
|
|
21086
|
-
|
|
21162
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
21163
|
+
logger17.log({
|
|
21087
21164
|
level: "info",
|
|
21088
21165
|
message: `Cache set for getPromoCodes: ${cacheKey}`
|
|
21089
21166
|
});
|
|
21090
21167
|
}).catch((err) => {
|
|
21091
|
-
|
|
21168
|
+
logger17.log({
|
|
21092
21169
|
level: "error",
|
|
21093
21170
|
message: `Failed to set cache for getPromoCodes: ${err.message}`
|
|
21094
21171
|
});
|
|
21095
21172
|
});
|
|
21096
21173
|
return data;
|
|
21097
21174
|
} catch (error) {
|
|
21098
|
-
|
|
21175
|
+
logger17.log({ level: "error", message: `${error}` });
|
|
21099
21176
|
throw new InternalServerError18("Internal server error.");
|
|
21100
21177
|
}
|
|
21101
21178
|
}
|
|
@@ -21142,7 +21219,7 @@ import Joi16 from "joi";
|
|
|
21142
21219
|
import {
|
|
21143
21220
|
BadRequestError as BadRequestError29,
|
|
21144
21221
|
InternalServerError as InternalServerError19,
|
|
21145
|
-
logger as
|
|
21222
|
+
logger as logger18,
|
|
21146
21223
|
paginate as paginate9,
|
|
21147
21224
|
useAtlas as useAtlas16
|
|
21148
21225
|
} from "@goweekdays/utils";
|
|
@@ -21277,7 +21354,7 @@ function useInvoiceRepo() {
|
|
|
21277
21354
|
value = createInvoice(value);
|
|
21278
21355
|
await collection.insertOne(value, { session });
|
|
21279
21356
|
} catch (error) {
|
|
21280
|
-
|
|
21357
|
+
logger18.log({ level: "error", message: `${error}` });
|
|
21281
21358
|
const isDuplicated = error.message.includes("duplicate");
|
|
21282
21359
|
if (isDuplicated) {
|
|
21283
21360
|
throw new BadRequestError29("Invoice already exists.");
|
|
@@ -21410,7 +21487,7 @@ function useInvoiceRepo() {
|
|
|
21410
21487
|
}
|
|
21411
21488
|
|
|
21412
21489
|
// src/repositories/counter.repository.ts
|
|
21413
|
-
import { useAtlas as useAtlas17, useCache as
|
|
21490
|
+
import { useAtlas as useAtlas17, useCache as useCache15, makeCacheKey as makeCacheKey14, logger as logger19 } from "@goweekdays/utils";
|
|
21414
21491
|
|
|
21415
21492
|
// src/models/counter.model.ts
|
|
21416
21493
|
import { BadRequestError as BadRequestError30 } from "@goweekdays/utils";
|
|
@@ -21454,15 +21531,15 @@ function useCounterRepo() {
|
|
|
21454
21531
|
}
|
|
21455
21532
|
const namespace_collection = "counters";
|
|
21456
21533
|
const { collection, createCounter } = useCounterModel(db);
|
|
21457
|
-
const { getCache, setCache, delNamespace } =
|
|
21534
|
+
const { getCache, setCache, delNamespace } = useCache15(namespace_collection);
|
|
21458
21535
|
function delCachedData() {
|
|
21459
|
-
delNamespace(
|
|
21460
|
-
|
|
21536
|
+
delNamespace().then(() => {
|
|
21537
|
+
logger19.log({
|
|
21461
21538
|
level: "info",
|
|
21462
21539
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
21463
21540
|
});
|
|
21464
21541
|
}).catch((err) => {
|
|
21465
|
-
|
|
21542
|
+
logger19.log({
|
|
21466
21543
|
level: "error",
|
|
21467
21544
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
21468
21545
|
});
|
|
@@ -21518,7 +21595,7 @@ function useCounterRepo() {
|
|
|
21518
21595
|
try {
|
|
21519
21596
|
const cached = await getCache(cacheKey);
|
|
21520
21597
|
if (cached) {
|
|
21521
|
-
|
|
21598
|
+
logger19.log({
|
|
21522
21599
|
level: "info",
|
|
21523
21600
|
message: `Cache hit for getByType counter: ${cacheKey}`
|
|
21524
21601
|
});
|
|
@@ -21526,13 +21603,13 @@ function useCounterRepo() {
|
|
|
21526
21603
|
}
|
|
21527
21604
|
const data = await collection.findOne({ type });
|
|
21528
21605
|
if (data) {
|
|
21529
|
-
setCache(cacheKey, data, 300
|
|
21530
|
-
|
|
21606
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
21607
|
+
logger19.log({
|
|
21531
21608
|
level: "info",
|
|
21532
21609
|
message: `Cache set for counter by type: ${cacheKey}`
|
|
21533
21610
|
});
|
|
21534
21611
|
}).catch((err) => {
|
|
21535
|
-
|
|
21612
|
+
logger19.log({
|
|
21536
21613
|
level: "error",
|
|
21537
21614
|
message: `Failed to set cache for counter by type: ${err.message}`
|
|
21538
21615
|
});
|
|
@@ -21556,7 +21633,7 @@ function useCounterRepo() {
|
|
|
21556
21633
|
import {
|
|
21557
21634
|
BadRequestError as BadRequestError31,
|
|
21558
21635
|
InternalServerError as InternalServerError20,
|
|
21559
|
-
logger as
|
|
21636
|
+
logger as logger20,
|
|
21560
21637
|
paginate as paginate10,
|
|
21561
21638
|
useAtlas as useAtlas18
|
|
21562
21639
|
} from "@goweekdays/utils";
|
|
@@ -21601,7 +21678,7 @@ function usePaymentRepo() {
|
|
|
21601
21678
|
value = createPayment(value);
|
|
21602
21679
|
await collection.insertOne(value, { session });
|
|
21603
21680
|
} catch (error) {
|
|
21604
|
-
|
|
21681
|
+
logger20.log({ level: "error", message: `${error}` });
|
|
21605
21682
|
const isDuplicated = error.message.includes("duplicate");
|
|
21606
21683
|
if (isDuplicated) {
|
|
21607
21684
|
throw new BadRequestError31("Payment already exists.");
|
|
@@ -21646,7 +21723,7 @@ function usePaymentRepo() {
|
|
|
21646
21723
|
const length = await collection.countDocuments(query);
|
|
21647
21724
|
return paginate10(items, page, limit, length);
|
|
21648
21725
|
} catch (error) {
|
|
21649
|
-
|
|
21726
|
+
logger20.log({ level: "error", message: `${error}` });
|
|
21650
21727
|
throw new InternalServerError20("Internal server error.");
|
|
21651
21728
|
}
|
|
21652
21729
|
}
|
|
@@ -21672,7 +21749,7 @@ function usePaymentRepo() {
|
|
|
21672
21749
|
}
|
|
21673
21750
|
|
|
21674
21751
|
// src/repositories/price.repository.ts
|
|
21675
|
-
import { useAtlas as useAtlas19, useCache as
|
|
21752
|
+
import { useAtlas as useAtlas19, useCache as useCache16, makeCacheKey as makeCacheKey15, logger as logger21 } from "@goweekdays/utils";
|
|
21676
21753
|
|
|
21677
21754
|
// src/models/price.model.ts
|
|
21678
21755
|
import { BadRequestError as BadRequestError32 } from "@goweekdays/utils";
|
|
@@ -21725,15 +21802,15 @@ function usePriceRepo() {
|
|
|
21725
21802
|
}
|
|
21726
21803
|
const namespace_collection = "prices";
|
|
21727
21804
|
const { collection, createPrice } = usePriceModel(db);
|
|
21728
|
-
const { getCache, setCache, delNamespace } =
|
|
21805
|
+
const { getCache, setCache, delNamespace } = useCache16(namespace_collection);
|
|
21729
21806
|
function delCachedData() {
|
|
21730
|
-
delNamespace(
|
|
21731
|
-
|
|
21807
|
+
delNamespace().then(() => {
|
|
21808
|
+
logger21.log({
|
|
21732
21809
|
level: "info",
|
|
21733
21810
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
21734
21811
|
});
|
|
21735
21812
|
}).catch((err) => {
|
|
21736
|
-
|
|
21813
|
+
logger21.log({
|
|
21737
21814
|
level: "error",
|
|
21738
21815
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
21739
21816
|
});
|
|
@@ -21789,7 +21866,7 @@ function usePriceRepo() {
|
|
|
21789
21866
|
try {
|
|
21790
21867
|
const cached = await getCache(cacheKey);
|
|
21791
21868
|
if (cached) {
|
|
21792
|
-
|
|
21869
|
+
logger21.log({
|
|
21793
21870
|
level: "info",
|
|
21794
21871
|
message: `Cache hit for getByNameType price: ${cacheKey}`
|
|
21795
21872
|
});
|
|
@@ -21797,13 +21874,13 @@ function usePriceRepo() {
|
|
|
21797
21874
|
}
|
|
21798
21875
|
const data = await collection.findOne({ name, type });
|
|
21799
21876
|
if (data) {
|
|
21800
|
-
setCache(cacheKey, data, 300
|
|
21801
|
-
|
|
21877
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
21878
|
+
logger21.log({
|
|
21802
21879
|
level: "info",
|
|
21803
21880
|
message: `Cache set for price by name and type: ${cacheKey}`
|
|
21804
21881
|
});
|
|
21805
21882
|
}).catch((err) => {
|
|
21806
|
-
|
|
21883
|
+
logger21.log({
|
|
21807
21884
|
level: "error",
|
|
21808
21885
|
message: `Failed to set cache for price by name and type: ${err.message}`
|
|
21809
21886
|
});
|
|
@@ -22586,7 +22663,7 @@ function useSubscriptionService() {
|
|
|
22586
22663
|
while (true) {
|
|
22587
22664
|
const subscriptions = await getDueSubscriptions(batchSize);
|
|
22588
22665
|
if (subscriptions.length === 0) {
|
|
22589
|
-
|
|
22666
|
+
logger22.log({
|
|
22590
22667
|
level: "info",
|
|
22591
22668
|
message: "No more subscriptions to process."
|
|
22592
22669
|
});
|
|
@@ -22726,14 +22803,14 @@ function useSubscriptionService() {
|
|
|
22726
22803
|
);
|
|
22727
22804
|
await session?.commitTransaction();
|
|
22728
22805
|
}
|
|
22729
|
-
|
|
22806
|
+
logger22.log({
|
|
22730
22807
|
level: "info",
|
|
22731
22808
|
message: `Processed subscription ${sub._id} successfully.`
|
|
22732
22809
|
});
|
|
22733
22810
|
return;
|
|
22734
22811
|
} catch (error) {
|
|
22735
22812
|
await session?.abortTransaction();
|
|
22736
|
-
|
|
22813
|
+
logger22.log({
|
|
22737
22814
|
level: "error",
|
|
22738
22815
|
message: `Failed to process ${sub._id}: ${error}`
|
|
22739
22816
|
});
|
|
@@ -22745,7 +22822,7 @@ function useSubscriptionService() {
|
|
|
22745
22822
|
}
|
|
22746
22823
|
})
|
|
22747
22824
|
);
|
|
22748
|
-
|
|
22825
|
+
logger22.log({
|
|
22749
22826
|
level: "info",
|
|
22750
22827
|
message: "Processed a batch of subscriptions."
|
|
22751
22828
|
});
|
|
@@ -23042,7 +23119,7 @@ function useSubscriptionService() {
|
|
|
23042
23119
|
await session?.commitTransaction();
|
|
23043
23120
|
} catch (error2) {
|
|
23044
23121
|
await session?.abortTransaction();
|
|
23045
|
-
|
|
23122
|
+
logger22.log({
|
|
23046
23123
|
level: "error",
|
|
23047
23124
|
message: `Failed to update subscription seats: ${error2}`
|
|
23048
23125
|
});
|
|
@@ -23243,7 +23320,7 @@ function useSubscriptionService() {
|
|
|
23243
23320
|
await session?.commitTransaction();
|
|
23244
23321
|
} catch (error2) {
|
|
23245
23322
|
await session?.abortTransaction();
|
|
23246
|
-
|
|
23323
|
+
logger22.log({
|
|
23247
23324
|
level: "error",
|
|
23248
23325
|
message: `Failed to update subscription seats: ${error2}`
|
|
23249
23326
|
});
|
|
@@ -23344,7 +23421,7 @@ function useSubscriptionService() {
|
|
|
23344
23421
|
await session?.commitTransaction();
|
|
23345
23422
|
} catch (error) {
|
|
23346
23423
|
await session?.abortTransaction();
|
|
23347
|
-
|
|
23424
|
+
logger22.log({
|
|
23348
23425
|
level: "error",
|
|
23349
23426
|
message: `Failed to process subscription payment: ${error}`
|
|
23350
23427
|
});
|
|
@@ -23847,7 +23924,7 @@ function MPaymentMethod(value) {
|
|
|
23847
23924
|
import {
|
|
23848
23925
|
BadRequestError as BadRequestError37,
|
|
23849
23926
|
InternalServerError as InternalServerError21,
|
|
23850
|
-
logger as
|
|
23927
|
+
logger as logger23,
|
|
23851
23928
|
useAtlas as useAtlas21
|
|
23852
23929
|
} from "@goweekdays/utils";
|
|
23853
23930
|
import { ObjectId as ObjectId31 } from "mongodb";
|
|
@@ -23893,7 +23970,7 @@ function usePaymentMethodRepo() {
|
|
|
23893
23970
|
await collection.insertOne(value, { session });
|
|
23894
23971
|
return "Successfully added payment method.";
|
|
23895
23972
|
} catch (error) {
|
|
23896
|
-
|
|
23973
|
+
logger23.log({ level: "error", message: `${error}` });
|
|
23897
23974
|
const isDuplicated = error.message.includes("duplicate");
|
|
23898
23975
|
if (isDuplicated) {
|
|
23899
23976
|
throw new BadRequestError37("Payment method already exist.");
|
|
@@ -25066,11 +25143,11 @@ import {
|
|
|
25066
25143
|
AppError as AppError11,
|
|
25067
25144
|
BadRequestError as BadRequestError45,
|
|
25068
25145
|
InternalServerError as InternalServerError23,
|
|
25069
|
-
logger as
|
|
25146
|
+
logger as logger24,
|
|
25070
25147
|
makeCacheKey as makeCacheKey16,
|
|
25071
25148
|
paginate as paginate11,
|
|
25072
25149
|
useAtlas as useAtlas24,
|
|
25073
|
-
useCache as
|
|
25150
|
+
useCache as useCache17
|
|
25074
25151
|
} from "@goweekdays/utils";
|
|
25075
25152
|
import { ObjectId as ObjectId33 } from "mongodb";
|
|
25076
25153
|
function useOrderRepo() {
|
|
@@ -25080,15 +25157,15 @@ function useOrderRepo() {
|
|
|
25080
25157
|
}
|
|
25081
25158
|
const namespace_collection = "orders";
|
|
25082
25159
|
const collection = db.collection(namespace_collection);
|
|
25083
|
-
const { getCache, setCache, delNamespace } =
|
|
25160
|
+
const { getCache, setCache, delNamespace } = useCache17(namespace_collection);
|
|
25084
25161
|
function delCachedData() {
|
|
25085
|
-
delNamespace(
|
|
25086
|
-
|
|
25162
|
+
delNamespace().then(() => {
|
|
25163
|
+
logger24.log({
|
|
25087
25164
|
level: "info",
|
|
25088
25165
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
25089
25166
|
});
|
|
25090
25167
|
}).catch((err) => {
|
|
25091
|
-
|
|
25168
|
+
logger24.log({
|
|
25092
25169
|
level: "error",
|
|
25093
25170
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
25094
25171
|
});
|
|
@@ -25111,7 +25188,7 @@ function useOrderRepo() {
|
|
|
25111
25188
|
collection.insertOne(value, { session });
|
|
25112
25189
|
delCachedData();
|
|
25113
25190
|
} catch (error) {
|
|
25114
|
-
|
|
25191
|
+
logger24.log({ level: "error", message: `${error}` });
|
|
25115
25192
|
if (error instanceof AppError11) {
|
|
25116
25193
|
throw error;
|
|
25117
25194
|
}
|
|
@@ -25155,7 +25232,7 @@ function useOrderRepo() {
|
|
|
25155
25232
|
try {
|
|
25156
25233
|
const cached = await getCache(cacheKey);
|
|
25157
25234
|
if (cached) {
|
|
25158
|
-
|
|
25235
|
+
logger24.log({
|
|
25159
25236
|
level: "info",
|
|
25160
25237
|
message: `Cache hit for getOrders: ${cacheKey}`
|
|
25161
25238
|
});
|
|
@@ -25169,20 +25246,20 @@ function useOrderRepo() {
|
|
|
25169
25246
|
]).toArray();
|
|
25170
25247
|
const length = await collection.countDocuments(query);
|
|
25171
25248
|
const data = paginate11(items, page, limit, length);
|
|
25172
|
-
setCache(cacheKey, data, 600
|
|
25173
|
-
|
|
25249
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
25250
|
+
logger24.log({
|
|
25174
25251
|
level: "info",
|
|
25175
25252
|
message: `Cache set for getOrders: ${cacheKey}`
|
|
25176
25253
|
});
|
|
25177
25254
|
}).catch((err) => {
|
|
25178
|
-
|
|
25255
|
+
logger24.log({
|
|
25179
25256
|
level: "error",
|
|
25180
25257
|
message: `Failed to set cache for getOrders: ${err.message}`
|
|
25181
25258
|
});
|
|
25182
25259
|
});
|
|
25183
25260
|
return data;
|
|
25184
25261
|
} catch (error) {
|
|
25185
|
-
|
|
25262
|
+
logger24.log({ level: "error", message: `${error}` });
|
|
25186
25263
|
throw new InternalServerError23("Internal server error.");
|
|
25187
25264
|
}
|
|
25188
25265
|
}
|
|
@@ -25238,7 +25315,7 @@ function useOrderController() {
|
|
|
25238
25315
|
// src/services/invoice.service.ts
|
|
25239
25316
|
import {
|
|
25240
25317
|
BadRequestError as BadRequestError47,
|
|
25241
|
-
logger as
|
|
25318
|
+
logger as logger25,
|
|
25242
25319
|
NotFoundError as NotFoundError7,
|
|
25243
25320
|
useAtlas as useAtlas25
|
|
25244
25321
|
} from "@goweekdays/utils";
|
|
@@ -25260,7 +25337,7 @@ function useInvoiceService() {
|
|
|
25260
25337
|
while (true) {
|
|
25261
25338
|
const overdueInvoices = await getOverdueInvoices(BATCH_SIZE);
|
|
25262
25339
|
if (!overdueInvoices.length) {
|
|
25263
|
-
|
|
25340
|
+
logger25.log({
|
|
25264
25341
|
level: "info",
|
|
25265
25342
|
message: "No overdue invoices found."
|
|
25266
25343
|
});
|
|
@@ -25270,21 +25347,21 @@ function useInvoiceService() {
|
|
|
25270
25347
|
overdueInvoices.map(async (invoice) => {
|
|
25271
25348
|
const session = useAtlas25.getClient()?.startSession();
|
|
25272
25349
|
if (!session) {
|
|
25273
|
-
|
|
25350
|
+
logger25.log({
|
|
25274
25351
|
level: "error",
|
|
25275
25352
|
message: "Failed to start session."
|
|
25276
25353
|
});
|
|
25277
25354
|
return;
|
|
25278
25355
|
}
|
|
25279
25356
|
if (!invoice._id) {
|
|
25280
|
-
|
|
25357
|
+
logger25.log({
|
|
25281
25358
|
level: "error",
|
|
25282
25359
|
message: "Invoice ID is missing."
|
|
25283
25360
|
});
|
|
25284
25361
|
return;
|
|
25285
25362
|
}
|
|
25286
25363
|
if (!invoice.metadata?.subscriptionId) {
|
|
25287
|
-
|
|
25364
|
+
logger25.log({
|
|
25288
25365
|
level: "error",
|
|
25289
25366
|
message: "Subscription ID is missing."
|
|
25290
25367
|
});
|
|
@@ -25294,14 +25371,14 @@ function useInvoiceService() {
|
|
|
25294
25371
|
invoice.metadata.subscriptionId
|
|
25295
25372
|
).catch(() => null);
|
|
25296
25373
|
if (!subscription) {
|
|
25297
|
-
|
|
25374
|
+
logger25.log({
|
|
25298
25375
|
level: "error",
|
|
25299
25376
|
message: "Subscription not found."
|
|
25300
25377
|
});
|
|
25301
25378
|
return;
|
|
25302
25379
|
}
|
|
25303
25380
|
if (!subscription._id) {
|
|
25304
|
-
|
|
25381
|
+
logger25.log({
|
|
25305
25382
|
level: "error",
|
|
25306
25383
|
message: "Subscription ID is missing."
|
|
25307
25384
|
});
|
|
@@ -25381,7 +25458,7 @@ function useInvoiceService() {
|
|
|
25381
25458
|
return;
|
|
25382
25459
|
}
|
|
25383
25460
|
} catch (error) {
|
|
25384
|
-
|
|
25461
|
+
logger25.log({
|
|
25385
25462
|
level: "error",
|
|
25386
25463
|
message: String(error)
|
|
25387
25464
|
});
|
|
@@ -25391,7 +25468,7 @@ function useInvoiceService() {
|
|
|
25391
25468
|
}
|
|
25392
25469
|
})
|
|
25393
25470
|
);
|
|
25394
|
-
|
|
25471
|
+
logger25.log({
|
|
25395
25472
|
level: "info",
|
|
25396
25473
|
message: "Successfully processed overdue invoices."
|
|
25397
25474
|
});
|
|
@@ -25403,7 +25480,7 @@ function useInvoiceService() {
|
|
|
25403
25480
|
}
|
|
25404
25481
|
const session = useAtlas25.getClient()?.startSession();
|
|
25405
25482
|
if (!session) {
|
|
25406
|
-
|
|
25483
|
+
logger25.log({
|
|
25407
25484
|
level: "error",
|
|
25408
25485
|
message: "Failed to start session."
|
|
25409
25486
|
});
|
|
@@ -25472,7 +25549,7 @@ function useInvoiceService() {
|
|
|
25472
25549
|
return "Payment processed successfully.";
|
|
25473
25550
|
} catch (error) {
|
|
25474
25551
|
session.abortTransaction();
|
|
25475
|
-
|
|
25552
|
+
logger25.log({
|
|
25476
25553
|
level: "error",
|
|
25477
25554
|
message: String(error)
|
|
25478
25555
|
});
|
|
@@ -25671,11 +25748,364 @@ function usePriceController() {
|
|
|
25671
25748
|
};
|
|
25672
25749
|
}
|
|
25673
25750
|
|
|
25674
|
-
// src/
|
|
25751
|
+
// src/models/property.model.ts
|
|
25752
|
+
import { BadRequestError as BadRequestError51 } from "@goweekdays/utils";
|
|
25675
25753
|
import Joi28 from "joi";
|
|
25754
|
+
import { ObjectId as ObjectId34 } from "mongodb";
|
|
25755
|
+
var schemaProperty = Joi28.object({
|
|
25756
|
+
_id: Joi28.string().optional(),
|
|
25757
|
+
propertyName: Joi28.string().trim().required(),
|
|
25758
|
+
propertyType: Joi28.string().trim().required(),
|
|
25759
|
+
propertyDescription: Joi28.string().trim().required(),
|
|
25760
|
+
streetAddress: Joi28.string().trim().required(),
|
|
25761
|
+
barangay: Joi28.string().trim().required(),
|
|
25762
|
+
city: Joi28.string().trim().required(),
|
|
25763
|
+
province: Joi28.string().trim().required(),
|
|
25764
|
+
region: Joi28.string().trim().required(),
|
|
25765
|
+
zipCode: Joi28.string().trim().optional().allow(""),
|
|
25766
|
+
latitude: Joi28.string().trim().optional().allow(""),
|
|
25767
|
+
longitude: Joi28.string().trim().optional().allow(""),
|
|
25768
|
+
ownerId: Joi28.string().trim().optional().allow(""),
|
|
25769
|
+
managerName: Joi28.string().trim().optional().allow(""),
|
|
25770
|
+
managerEmail: Joi28.string().trim().email().optional().allow(""),
|
|
25771
|
+
managerPhone: Joi28.string().trim().optional().allow(""),
|
|
25772
|
+
amenities: Joi28.array().items(Joi28.string().trim()).optional(),
|
|
25773
|
+
numberOfFloors: Joi28.string().trim().required(),
|
|
25774
|
+
floorLabels: Joi28.string().optional().allow(""),
|
|
25775
|
+
coverPhoto: Joi28.object({
|
|
25776
|
+
name: Joi28.string().trim().optional().allow(""),
|
|
25777
|
+
size: Joi28.string().trim().optional().allow(""),
|
|
25778
|
+
type: Joi28.string().trim().optional().allow(""),
|
|
25779
|
+
webkitRelativePath: Joi28.string().trim().optional().allow("")
|
|
25780
|
+
}),
|
|
25781
|
+
photoGallery: Joi28.array().items(
|
|
25782
|
+
Joi28.object({
|
|
25783
|
+
name: Joi28.string().trim().optional().allow(""),
|
|
25784
|
+
size: Joi28.string().trim().optional().allow(""),
|
|
25785
|
+
type: Joi28.string().trim().optional().allow(""),
|
|
25786
|
+
webkitRelativePath: Joi28.string().trim().optional().allow("")
|
|
25787
|
+
})
|
|
25788
|
+
).required(),
|
|
25789
|
+
stayType: Joi28.string().trim().required(),
|
|
25790
|
+
createdAt: Joi28.date().optional(),
|
|
25791
|
+
updatedAt: Joi28.date().optional(),
|
|
25792
|
+
deletedAt: Joi28.date().optional()
|
|
25793
|
+
});
|
|
25794
|
+
function modelProperty(value) {
|
|
25795
|
+
const { error } = schemaProperty.validate(value);
|
|
25796
|
+
if (error) {
|
|
25797
|
+
throw new BadRequestError51(`Invalid property data: ${error.message}`);
|
|
25798
|
+
}
|
|
25799
|
+
if (!value._id) {
|
|
25800
|
+
try {
|
|
25801
|
+
value._id = new ObjectId34();
|
|
25802
|
+
} catch (error2) {
|
|
25803
|
+
throw new BadRequestError51("Invalid Property ID.");
|
|
25804
|
+
}
|
|
25805
|
+
}
|
|
25806
|
+
return {
|
|
25807
|
+
_id: value._id,
|
|
25808
|
+
propertyName: value.propertyName,
|
|
25809
|
+
propertyType: value.propertyType,
|
|
25810
|
+
propertyDescription: value.propertyDescription,
|
|
25811
|
+
streetAddress: value.streetAddress,
|
|
25812
|
+
barangay: value.barangay,
|
|
25813
|
+
city: value.city,
|
|
25814
|
+
province: value.province,
|
|
25815
|
+
region: value.region,
|
|
25816
|
+
zipCode: value.zipCode ?? "",
|
|
25817
|
+
latitude: value.latitude ?? "",
|
|
25818
|
+
longitude: value.longitude ?? "",
|
|
25819
|
+
ownerId: value.ownerId ?? "",
|
|
25820
|
+
managerName: value.managerName ?? "",
|
|
25821
|
+
managerEmail: value.managerEmail ?? "",
|
|
25822
|
+
managerPhone: value.managerPhone ?? "",
|
|
25823
|
+
amenities: value.amenities ?? [],
|
|
25824
|
+
numberOfFloors: value.numberOfFloors,
|
|
25825
|
+
floorLabels: value.floorLabels ?? "",
|
|
25826
|
+
coverPhoto: value.coverPhoto,
|
|
25827
|
+
photoGallery: value.photoGallery ?? [],
|
|
25828
|
+
stayType: value.stayType,
|
|
25829
|
+
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
25830
|
+
updatedAt: value.updatedAt,
|
|
25831
|
+
deletedAt: value.deletedAt
|
|
25832
|
+
};
|
|
25833
|
+
}
|
|
25834
|
+
|
|
25835
|
+
// src/repositories/property.repository.ts
|
|
25836
|
+
import {
|
|
25837
|
+
BadRequestError as BadRequestError52,
|
|
25838
|
+
useAtlas as useAtlas26,
|
|
25839
|
+
useCache as useCache18,
|
|
25840
|
+
makeCacheKey as makeCacheKey17,
|
|
25841
|
+
logger as logger26,
|
|
25842
|
+
InternalServerError as InternalServerError24
|
|
25843
|
+
} from "@goweekdays/utils";
|
|
25844
|
+
import { ObjectId as ObjectId35 } from "mongodb";
|
|
25845
|
+
function usePropertyRepo() {
|
|
25846
|
+
const db = useAtlas26.getDb();
|
|
25847
|
+
if (!db) {
|
|
25848
|
+
throw new BadRequestError52("Unable to connect to server.");
|
|
25849
|
+
}
|
|
25850
|
+
const namespace_collection = "properties";
|
|
25851
|
+
const collection = db.collection(namespace_collection);
|
|
25852
|
+
const { getCache, setCache, delNamespace } = useCache18(namespace_collection);
|
|
25853
|
+
function delCachedData() {
|
|
25854
|
+
delNamespace().then(() => {
|
|
25855
|
+
logger26.log({
|
|
25856
|
+
level: "info",
|
|
25857
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
25858
|
+
});
|
|
25859
|
+
}).catch((err) => {
|
|
25860
|
+
logger26.log({
|
|
25861
|
+
level: "error",
|
|
25862
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
25863
|
+
});
|
|
25864
|
+
});
|
|
25865
|
+
}
|
|
25866
|
+
async function createIndex() {
|
|
25867
|
+
try {
|
|
25868
|
+
await collection.createIndexes([
|
|
25869
|
+
{ key: { propertyName: 1 } },
|
|
25870
|
+
{ key: { propertyType: 1 } },
|
|
25871
|
+
{ key: { createdAt: 1 } },
|
|
25872
|
+
{
|
|
25873
|
+
key: {
|
|
25874
|
+
propertyName: "text",
|
|
25875
|
+
propertyType: "text",
|
|
25876
|
+
city: "text"
|
|
25877
|
+
},
|
|
25878
|
+
name: "propertyTextSearch"
|
|
25879
|
+
}
|
|
25880
|
+
]);
|
|
25881
|
+
} catch (error) {
|
|
25882
|
+
throw new BadRequestError52(
|
|
25883
|
+
`Failed to create index on properties: ${error.message}`
|
|
25884
|
+
);
|
|
25885
|
+
}
|
|
25886
|
+
}
|
|
25887
|
+
async function add(value, session) {
|
|
25888
|
+
try {
|
|
25889
|
+
value = modelProperty(value);
|
|
25890
|
+
const res = await collection.insertOne(value, { session });
|
|
25891
|
+
delCachedData();
|
|
25892
|
+
return res.insertedId;
|
|
25893
|
+
} catch (error) {
|
|
25894
|
+
throw new BadRequestError52(`Failed to create property: ${error.message}`);
|
|
25895
|
+
}
|
|
25896
|
+
}
|
|
25897
|
+
async function updateById(_id, value, session) {
|
|
25898
|
+
try {
|
|
25899
|
+
_id = new ObjectId35(_id);
|
|
25900
|
+
} catch (error) {
|
|
25901
|
+
throw new BadRequestError52("Invalid ID.");
|
|
25902
|
+
}
|
|
25903
|
+
try {
|
|
25904
|
+
const res = await collection.updateOne(
|
|
25905
|
+
{ _id },
|
|
25906
|
+
{ $set: { value, updatedAt: /* @__PURE__ */ new Date() } },
|
|
25907
|
+
{ session }
|
|
25908
|
+
);
|
|
25909
|
+
delCachedData();
|
|
25910
|
+
return res;
|
|
25911
|
+
} catch (error) {
|
|
25912
|
+
throw new InternalServerError24("Failed to update property.");
|
|
25913
|
+
}
|
|
25914
|
+
}
|
|
25915
|
+
async function deleteById(_id) {
|
|
25916
|
+
try {
|
|
25917
|
+
_id = new ObjectId35(_id);
|
|
25918
|
+
} catch (error) {
|
|
25919
|
+
throw new BadRequestError52("Invalid ID.");
|
|
25920
|
+
}
|
|
25921
|
+
try {
|
|
25922
|
+
const res = await collection.deleteOne({ _id });
|
|
25923
|
+
delCachedData();
|
|
25924
|
+
return res;
|
|
25925
|
+
} catch (error) {
|
|
25926
|
+
throw new InternalServerError24("Failed to delete property.");
|
|
25927
|
+
}
|
|
25928
|
+
}
|
|
25929
|
+
async function getAll() {
|
|
25930
|
+
const cacheKey = makeCacheKey17(namespace_collection, { action: "getAll" });
|
|
25931
|
+
try {
|
|
25932
|
+
const cached = await getCache(cacheKey);
|
|
25933
|
+
if (cached) {
|
|
25934
|
+
logger26.log({
|
|
25935
|
+
level: "info",
|
|
25936
|
+
message: `Cache hit for getAll: ${cacheKey}`
|
|
25937
|
+
});
|
|
25938
|
+
return cached;
|
|
25939
|
+
}
|
|
25940
|
+
const properties = await collection.find({}).toArray();
|
|
25941
|
+
setCache(cacheKey, properties, 300).then(() => {
|
|
25942
|
+
logger26.log({
|
|
25943
|
+
level: "info",
|
|
25944
|
+
message: `Cache set for getAll: ${cacheKey}`
|
|
25945
|
+
});
|
|
25946
|
+
}).catch((err) => {
|
|
25947
|
+
logger26.log({
|
|
25948
|
+
level: "error",
|
|
25949
|
+
message: `Failed to set cache: ${err.message}`
|
|
25950
|
+
});
|
|
25951
|
+
});
|
|
25952
|
+
return properties;
|
|
25953
|
+
} catch (error) {
|
|
25954
|
+
throw new InternalServerError24(
|
|
25955
|
+
`Failed to fetch properties: ${error.message}`
|
|
25956
|
+
);
|
|
25957
|
+
}
|
|
25958
|
+
}
|
|
25959
|
+
async function getById(_id) {
|
|
25960
|
+
try {
|
|
25961
|
+
_id = new ObjectId35(_id);
|
|
25962
|
+
} catch (error) {
|
|
25963
|
+
throw new BadRequestError52("Invalid ID.");
|
|
25964
|
+
}
|
|
25965
|
+
const cacheKey = makeCacheKey17(namespace_collection, { _id: String(_id) });
|
|
25966
|
+
try {
|
|
25967
|
+
const cached = await getCache(cacheKey);
|
|
25968
|
+
if (cached) {
|
|
25969
|
+
logger26.log({
|
|
25970
|
+
level: "info",
|
|
25971
|
+
message: `Cache hit for getById: ${cacheKey}`
|
|
25972
|
+
});
|
|
25973
|
+
return cached;
|
|
25974
|
+
}
|
|
25975
|
+
const property = await collection.findOne({});
|
|
25976
|
+
if (!property) {
|
|
25977
|
+
throw new BadRequestError52("Property not found.");
|
|
25978
|
+
}
|
|
25979
|
+
setCache(cacheKey, property, 300).then(() => {
|
|
25980
|
+
logger26.log({
|
|
25981
|
+
level: "info",
|
|
25982
|
+
message: `Cache set for getById: ${cacheKey}`
|
|
25983
|
+
});
|
|
25984
|
+
}).catch((err) => {
|
|
25985
|
+
logger26.log({
|
|
25986
|
+
level: "error",
|
|
25987
|
+
message: `Failed to set cache: ${err.message}`
|
|
25988
|
+
});
|
|
25989
|
+
});
|
|
25990
|
+
return property;
|
|
25991
|
+
} catch (error) {
|
|
25992
|
+
if (error instanceof BadRequestError52) {
|
|
25993
|
+
throw error;
|
|
25994
|
+
}
|
|
25995
|
+
throw new InternalServerError24(
|
|
25996
|
+
`Failed to fetch property: ${error.message}`
|
|
25997
|
+
);
|
|
25998
|
+
}
|
|
25999
|
+
}
|
|
26000
|
+
return {
|
|
26001
|
+
createIndex,
|
|
26002
|
+
add,
|
|
26003
|
+
deleteById,
|
|
26004
|
+
updateById,
|
|
26005
|
+
getAll,
|
|
26006
|
+
getById
|
|
26007
|
+
};
|
|
26008
|
+
}
|
|
26009
|
+
|
|
26010
|
+
// src/controllers/property.controller.ts
|
|
26011
|
+
import { BadRequestError as BadRequestError53 } from "@goweekdays/utils";
|
|
26012
|
+
import Joi29 from "joi";
|
|
26013
|
+
function usePropertyController() {
|
|
26014
|
+
const {
|
|
26015
|
+
add: _add,
|
|
26016
|
+
updateById: _updateById,
|
|
26017
|
+
getAll: _getAll,
|
|
26018
|
+
getById: _getById
|
|
26019
|
+
} = usePropertyRepo();
|
|
26020
|
+
async function add(req, res, next) {
|
|
26021
|
+
const value = req.body;
|
|
26022
|
+
const { error } = schemaProperty.validate(value);
|
|
26023
|
+
if (error) {
|
|
26024
|
+
next(new BadRequestError53(error.message));
|
|
26025
|
+
return;
|
|
26026
|
+
}
|
|
26027
|
+
try {
|
|
26028
|
+
const id = await _add(value);
|
|
26029
|
+
res.json({ message: "Successfully added property.", id });
|
|
26030
|
+
return;
|
|
26031
|
+
} catch (error2) {
|
|
26032
|
+
next(error2);
|
|
26033
|
+
}
|
|
26034
|
+
}
|
|
26035
|
+
async function updateById(req, res, next) {
|
|
26036
|
+
const _id = req.params.id ?? "";
|
|
26037
|
+
const value = { _id, ...req.body };
|
|
26038
|
+
const validation = Joi29.object({
|
|
26039
|
+
_id: Joi29.string().required(),
|
|
26040
|
+
name: Joi29.string().trim().required(),
|
|
26041
|
+
type: Joi29.string().trim().required(),
|
|
26042
|
+
description: Joi29.string().trim().required(),
|
|
26043
|
+
street: Joi29.string().trim().required(),
|
|
26044
|
+
barangay: Joi29.string().trim().required(),
|
|
26045
|
+
cityMunicipality: Joi29.string().trim().required(),
|
|
26046
|
+
province: Joi29.string().trim().required(),
|
|
26047
|
+
region: Joi29.string().trim().required(),
|
|
26048
|
+
zipCode: Joi29.string().trim().optional().allow(""),
|
|
26049
|
+
latitude: Joi29.string().trim().optional().allow(""),
|
|
26050
|
+
longitude: Joi29.string().trim().optional().allow(""),
|
|
26051
|
+
ownerId: Joi29.string().trim().optional().allow(""),
|
|
26052
|
+
ownerName: Joi29.string().trim().optional().allow(""),
|
|
26053
|
+
email: Joi29.string().trim().email().optional().allow(""),
|
|
26054
|
+
phone: Joi29.string().trim().optional().allow(""),
|
|
26055
|
+
amenities: Joi29.array().items(Joi29.string().trim()).optional(),
|
|
26056
|
+
floorNumber: Joi29.string().trim().required(),
|
|
26057
|
+
floorLabel: Joi29.string().optional().allow(""),
|
|
26058
|
+
coverPhoto: Joi29.string().trim().required(),
|
|
26059
|
+
photoGallery: Joi29.array().items(Joi29.string().trim()).required(),
|
|
26060
|
+
stayType: Joi29.string().trim().required()
|
|
26061
|
+
});
|
|
26062
|
+
const { error } = validation.validate(value);
|
|
26063
|
+
if (error) {
|
|
26064
|
+
throw new BadRequestError53(`Invalid property data: ${error.message}`);
|
|
26065
|
+
}
|
|
26066
|
+
try {
|
|
26067
|
+
const result = await _updateById(_id, req.body);
|
|
26068
|
+
res.json({ message: "Successfully updated property.", result });
|
|
26069
|
+
} catch (error2) {
|
|
26070
|
+
next(error2);
|
|
26071
|
+
}
|
|
26072
|
+
}
|
|
26073
|
+
async function getAll(req, res, next) {
|
|
26074
|
+
try {
|
|
26075
|
+
const properties = await _getAll();
|
|
26076
|
+
res.json(properties);
|
|
26077
|
+
return;
|
|
26078
|
+
} catch (error) {
|
|
26079
|
+
next(error);
|
|
26080
|
+
}
|
|
26081
|
+
}
|
|
26082
|
+
async function getById(req, res, next) {
|
|
26083
|
+
const { id } = req.params;
|
|
26084
|
+
if (!id) {
|
|
26085
|
+
next(new BadRequestError53("Property ID is required."));
|
|
26086
|
+
return;
|
|
26087
|
+
}
|
|
26088
|
+
try {
|
|
26089
|
+
const property = await _getById(id);
|
|
26090
|
+
res.json(property);
|
|
26091
|
+
return;
|
|
26092
|
+
} catch (error) {
|
|
26093
|
+
next(error);
|
|
26094
|
+
}
|
|
26095
|
+
}
|
|
26096
|
+
return {
|
|
26097
|
+
add,
|
|
26098
|
+
updateById,
|
|
26099
|
+
getAll,
|
|
26100
|
+
getById
|
|
26101
|
+
};
|
|
26102
|
+
}
|
|
26103
|
+
|
|
26104
|
+
// src/controllers/util.controller.ts
|
|
26105
|
+
import Joi30 from "joi";
|
|
25676
26106
|
|
|
25677
26107
|
// src/services/github.service.ts
|
|
25678
|
-
import { AppError as AppError12, BadRequestError as
|
|
26108
|
+
import { AppError as AppError12, BadRequestError as BadRequestError54 } from "@goweekdays/utils";
|
|
25679
26109
|
import { Octokit } from "@octokit/rest";
|
|
25680
26110
|
import _sodium from "libsodium-wrappers";
|
|
25681
26111
|
function useGitHubService() {
|
|
@@ -25689,23 +26119,23 @@ function useGitHubService() {
|
|
|
25689
26119
|
try {
|
|
25690
26120
|
const { data: repoData } = await octokit.repos.get({ owner, repo });
|
|
25691
26121
|
if (!repoData.permissions?.admin) {
|
|
25692
|
-
throw new
|
|
26122
|
+
throw new BadRequestError54(
|
|
25693
26123
|
"You do not have admin access to this repository."
|
|
25694
26124
|
);
|
|
25695
26125
|
}
|
|
25696
26126
|
} catch (error) {
|
|
25697
26127
|
if (error.status === 404) {
|
|
25698
|
-
throw new
|
|
26128
|
+
throw new BadRequestError54(
|
|
25699
26129
|
"Repository not found or you don't have access to it."
|
|
25700
26130
|
);
|
|
25701
26131
|
} else if (error.status === 401) {
|
|
25702
|
-
throw new
|
|
26132
|
+
throw new BadRequestError54(
|
|
25703
26133
|
"Invalid GitHub token or insufficient permissions."
|
|
25704
26134
|
);
|
|
25705
26135
|
} else if (error.message.includes("admin access")) {
|
|
25706
26136
|
throw error;
|
|
25707
26137
|
} else {
|
|
25708
|
-
throw new
|
|
26138
|
+
throw new BadRequestError54(
|
|
25709
26139
|
`Failed to check repository permissions: ${error.message}`
|
|
25710
26140
|
);
|
|
25711
26141
|
}
|
|
@@ -25754,7 +26184,7 @@ function useGitHubService() {
|
|
|
25754
26184
|
key_id: publicKeyRes.key_id
|
|
25755
26185
|
});
|
|
25756
26186
|
} catch (encryptionError) {
|
|
25757
|
-
throw new
|
|
26187
|
+
throw new BadRequestError54(
|
|
25758
26188
|
`Failed to encrypt secret '${key}': ${encryptionError.message}`
|
|
25759
26189
|
);
|
|
25760
26190
|
}
|
|
@@ -25787,19 +26217,19 @@ function useGitHubService() {
|
|
|
25787
26217
|
if (error instanceof AppError12)
|
|
25788
26218
|
throw error;
|
|
25789
26219
|
if (error.status === 422) {
|
|
25790
|
-
throw new
|
|
26220
|
+
throw new BadRequestError54(
|
|
25791
26221
|
`GitHub API validation error: ${error.message}`
|
|
25792
26222
|
);
|
|
25793
26223
|
} else if (error.status === 404) {
|
|
25794
|
-
throw new
|
|
26224
|
+
throw new BadRequestError54("Environment or repository not found.");
|
|
25795
26225
|
} else if (error.status === 403) {
|
|
25796
|
-
throw new
|
|
26226
|
+
throw new BadRequestError54(
|
|
25797
26227
|
"Forbidden: Insufficient permissions or rate limit exceeded."
|
|
25798
26228
|
);
|
|
25799
26229
|
} else if (error.message.includes("admin access") || error.message.includes("permissions")) {
|
|
25800
26230
|
throw error;
|
|
25801
26231
|
} else {
|
|
25802
|
-
throw new
|
|
26232
|
+
throw new BadRequestError54(
|
|
25803
26233
|
`Failed to set GitHub variables: ${error.message}`
|
|
25804
26234
|
);
|
|
25805
26235
|
}
|
|
@@ -25813,9 +26243,9 @@ function useGitHubService() {
|
|
|
25813
26243
|
// src/controllers/util.controller.ts
|
|
25814
26244
|
import {
|
|
25815
26245
|
AppError as AppError13,
|
|
25816
|
-
BadRequestError as
|
|
25817
|
-
InternalServerError as
|
|
25818
|
-
logger as
|
|
26246
|
+
BadRequestError as BadRequestError55,
|
|
26247
|
+
InternalServerError as InternalServerError25,
|
|
26248
|
+
logger as logger27
|
|
25819
26249
|
} from "@goweekdays/utils";
|
|
25820
26250
|
function useUtilController() {
|
|
25821
26251
|
async function healthCheck(req, res, next) {
|
|
@@ -25832,32 +26262,32 @@ function useUtilController() {
|
|
|
25832
26262
|
}
|
|
25833
26263
|
});
|
|
25834
26264
|
} catch (error) {
|
|
25835
|
-
|
|
25836
|
-
next(new
|
|
26265
|
+
logger27.error("Health check failed", { error: error.message });
|
|
26266
|
+
next(new InternalServerError25("Health check failed"));
|
|
25837
26267
|
}
|
|
25838
26268
|
}
|
|
25839
26269
|
async function setGitHubVariables(req, res, next) {
|
|
25840
26270
|
try {
|
|
25841
26271
|
const { githubToken, repoUrl, environment, type, keyValues } = req.body;
|
|
25842
|
-
const validation =
|
|
25843
|
-
githubToken:
|
|
26272
|
+
const validation = Joi30.object({
|
|
26273
|
+
githubToken: Joi30.string().required().messages({
|
|
25844
26274
|
"string.empty": "GitHub token is required",
|
|
25845
26275
|
"any.required": "GitHub token is required"
|
|
25846
26276
|
}),
|
|
25847
|
-
repoUrl:
|
|
26277
|
+
repoUrl: Joi30.string().uri().required().messages({
|
|
25848
26278
|
"string.empty": "Repository URL is required",
|
|
25849
26279
|
"string.uri": "Repository URL must be a valid URL",
|
|
25850
26280
|
"any.required": "Repository URL is required"
|
|
25851
26281
|
}),
|
|
25852
|
-
environment:
|
|
26282
|
+
environment: Joi30.string().required().messages({
|
|
25853
26283
|
"string.empty": "Environment name is required",
|
|
25854
26284
|
"any.required": "Environment name is required"
|
|
25855
26285
|
}),
|
|
25856
|
-
type:
|
|
26286
|
+
type: Joi30.string().valid("env", "secret").required().messages({
|
|
25857
26287
|
"any.only": 'Type must be either "env" or "secret"',
|
|
25858
26288
|
"any.required": "Type is required"
|
|
25859
26289
|
}),
|
|
25860
|
-
keyValues:
|
|
26290
|
+
keyValues: Joi30.string().required().messages({
|
|
25861
26291
|
"string.empty": "Key-value pairs are required",
|
|
25862
26292
|
"any.required": "Key-value pairs are required"
|
|
25863
26293
|
})
|
|
@@ -25870,13 +26300,13 @@ function useUtilController() {
|
|
|
25870
26300
|
keyValues
|
|
25871
26301
|
});
|
|
25872
26302
|
if (error) {
|
|
25873
|
-
next(new
|
|
26303
|
+
next(new BadRequestError55(error.message));
|
|
25874
26304
|
return;
|
|
25875
26305
|
}
|
|
25876
26306
|
const repoUrlPattern = /github\.com[:\/]([^\/]+)\/(.+)\.git$/;
|
|
25877
26307
|
if (!repoUrlPattern.test(repoUrl)) {
|
|
25878
26308
|
next(
|
|
25879
|
-
new
|
|
26309
|
+
new BadRequestError55(
|
|
25880
26310
|
"Invalid GitHub repository URL format. Expected format: https://github.com/owner/repo.git"
|
|
25881
26311
|
)
|
|
25882
26312
|
);
|
|
@@ -25888,7 +26318,7 @@ function useUtilController() {
|
|
|
25888
26318
|
);
|
|
25889
26319
|
if (invalidLines.length > 0) {
|
|
25890
26320
|
next(
|
|
25891
|
-
new
|
|
26321
|
+
new BadRequestError55(
|
|
25892
26322
|
"Invalid key-value format. Each pair should be in format: KEY=value. Pairs can be separated by newlines, spaces, or tabs."
|
|
25893
26323
|
)
|
|
25894
26324
|
);
|
|
@@ -25902,7 +26332,7 @@ function useUtilController() {
|
|
|
25902
26332
|
type,
|
|
25903
26333
|
keyValues
|
|
25904
26334
|
});
|
|
25905
|
-
|
|
26335
|
+
logger27.info(`GitHub variables set successfully`, {
|
|
25906
26336
|
repoUrl,
|
|
25907
26337
|
environment,
|
|
25908
26338
|
type,
|
|
@@ -25919,7 +26349,7 @@ function useUtilController() {
|
|
|
25919
26349
|
}
|
|
25920
26350
|
});
|
|
25921
26351
|
} catch (error) {
|
|
25922
|
-
|
|
26352
|
+
logger27.error("Failed to set GitHub variables", {
|
|
25923
26353
|
error: error.message,
|
|
25924
26354
|
stack: error.stack
|
|
25925
26355
|
});
|
|
@@ -25927,7 +26357,7 @@ function useUtilController() {
|
|
|
25927
26357
|
next(error);
|
|
25928
26358
|
} else {
|
|
25929
26359
|
next(
|
|
25930
|
-
new
|
|
26360
|
+
new InternalServerError25(
|
|
25931
26361
|
`Failed to set GitHub variables: ${error.message}`
|
|
25932
26362
|
)
|
|
25933
26363
|
);
|
|
@@ -25949,6 +26379,7 @@ export {
|
|
|
25949
26379
|
DEFAULT_USER_FIRST_NAME,
|
|
25950
26380
|
DEFAULT_USER_LAST_NAME,
|
|
25951
26381
|
DEFAULT_USER_PASSWORD,
|
|
26382
|
+
DOMAIN,
|
|
25952
26383
|
DirectDebitSchema,
|
|
25953
26384
|
EWalletPaymentSchema,
|
|
25954
26385
|
MAILER_EMAIL,
|
|
@@ -25993,7 +26424,9 @@ export {
|
|
|
25993
26424
|
XENDIT_SECRET_KEY,
|
|
25994
26425
|
addressSchema,
|
|
25995
26426
|
isDev,
|
|
26427
|
+
modelProperty,
|
|
25996
26428
|
schema,
|
|
26429
|
+
schemaProperty,
|
|
25997
26430
|
useAddressController,
|
|
25998
26431
|
useAddressRepo,
|
|
25999
26432
|
useAuthController,
|
|
@@ -26028,6 +26461,8 @@ export {
|
|
|
26028
26461
|
usePriceRepo,
|
|
26029
26462
|
usePromoCodeController,
|
|
26030
26463
|
usePromoCodeRepo,
|
|
26464
|
+
usePropertyController,
|
|
26465
|
+
usePropertyRepo,
|
|
26031
26466
|
useRoleController,
|
|
26032
26467
|
useRoleRepo,
|
|
26033
26468
|
useSubscriptionController,
|