@eeplatform/core 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.ts +6 -7
- package/dist/index.js +163 -180
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +334 -349
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -2
package/dist/index.mjs
CHANGED
|
@@ -11368,9 +11368,9 @@ function useVerificationRepo() {
|
|
|
11368
11368
|
}
|
|
11369
11369
|
const namespace_collection = "verifications";
|
|
11370
11370
|
const collection = db.collection(namespace_collection);
|
|
11371
|
-
const { getCache, setCache, delNamespace } = useCache();
|
|
11371
|
+
const { getCache, setCache, delNamespace } = useCache(namespace_collection);
|
|
11372
11372
|
function delCachedData() {
|
|
11373
|
-
delNamespace(
|
|
11373
|
+
delNamespace().then(() => {
|
|
11374
11374
|
logger.log({
|
|
11375
11375
|
level: "info",
|
|
11376
11376
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -11458,7 +11458,7 @@ function useVerificationRepo() {
|
|
|
11458
11458
|
return cached;
|
|
11459
11459
|
}
|
|
11460
11460
|
const data = await collection.findOne({ _id });
|
|
11461
|
-
setCache(cacheKey, data, 300
|
|
11461
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
11462
11462
|
logger.log({
|
|
11463
11463
|
level: "info",
|
|
11464
11464
|
message: `Cache set for verification by id: ${cacheKey}`
|
|
@@ -11538,7 +11538,7 @@ function useVerificationRepo() {
|
|
|
11538
11538
|
]).toArray();
|
|
11539
11539
|
const length = await collection.countDocuments(query);
|
|
11540
11540
|
const data = paginate(items, page, limit, length);
|
|
11541
|
-
setCache(cacheKey, data, 600
|
|
11541
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
11542
11542
|
logger.log({
|
|
11543
11543
|
level: "info",
|
|
11544
11544
|
message: `Cache set for getVerifications: ${cacheKey}`
|
|
@@ -11569,7 +11569,7 @@ function useVerificationRepo() {
|
|
|
11569
11569
|
return cached;
|
|
11570
11570
|
}
|
|
11571
11571
|
const data = await collection.find({ type }).toArray();
|
|
11572
|
-
setCache(cacheKey, data, 600
|
|
11572
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
11573
11573
|
logger.log({
|
|
11574
11574
|
level: "info",
|
|
11575
11575
|
message: `Cache set for verification by type: ${cacheKey}`
|
|
@@ -11703,10 +11703,12 @@ var MUser = class {
|
|
|
11703
11703
|
this.createdAt = value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
11704
11704
|
this.updatedAt = value.updatedAt ?? "";
|
|
11705
11705
|
this.deletedAt = value.deletedAt ?? "";
|
|
11706
|
-
|
|
11707
|
-
|
|
11708
|
-
|
|
11709
|
-
|
|
11706
|
+
if (value.defaultOrg) {
|
|
11707
|
+
try {
|
|
11708
|
+
value.defaultOrg = new ObjectId3(value.defaultOrg);
|
|
11709
|
+
} catch (error) {
|
|
11710
|
+
throw new Error("Invalid defaultOrg ID.");
|
|
11711
|
+
}
|
|
11710
11712
|
}
|
|
11711
11713
|
this.defaultOrg = value.defaultOrg;
|
|
11712
11714
|
}
|
|
@@ -11729,9 +11731,9 @@ function useUserRepo() {
|
|
|
11729
11731
|
}
|
|
11730
11732
|
const namespace_collection = "users";
|
|
11731
11733
|
const collection = db.collection(namespace_collection);
|
|
11732
|
-
const { getCache, setCache, delNamespace } = useCache2();
|
|
11734
|
+
const { getCache, setCache, delNamespace } = useCache2(namespace_collection);
|
|
11733
11735
|
function delCachedData() {
|
|
11734
|
-
delNamespace(
|
|
11736
|
+
delNamespace().then(() => {
|
|
11735
11737
|
logger2.log({
|
|
11736
11738
|
level: "info",
|
|
11737
11739
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -11793,7 +11795,7 @@ function useUserRepo() {
|
|
|
11793
11795
|
}
|
|
11794
11796
|
const result = await collection.findOne({ email });
|
|
11795
11797
|
if (result) {
|
|
11796
|
-
setCache(cacheKey, result, 300
|
|
11798
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
11797
11799
|
logger2.log({
|
|
11798
11800
|
level: "info",
|
|
11799
11801
|
message: `Cache set for user by email: ${cacheKey}`
|
|
@@ -11823,7 +11825,7 @@ function useUserRepo() {
|
|
|
11823
11825
|
}
|
|
11824
11826
|
const result = await collection.findOne({ referralCode });
|
|
11825
11827
|
if (result) {
|
|
11826
|
-
setCache(cacheKey, result, 300
|
|
11828
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
11827
11829
|
logger2.log({
|
|
11828
11830
|
level: "info",
|
|
11829
11831
|
message: `Cache set for user by referral code: ${cacheKey}`
|
|
@@ -11858,7 +11860,7 @@ function useUserRepo() {
|
|
|
11858
11860
|
}
|
|
11859
11861
|
const result = await collection.findOne({ _id });
|
|
11860
11862
|
if (result) {
|
|
11861
|
-
setCache(cacheKey, result, 300
|
|
11863
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
11862
11864
|
logger2.log({
|
|
11863
11865
|
level: "info",
|
|
11864
11866
|
message: `Cache set for user by id: ${cacheKey}`
|
|
@@ -11932,7 +11934,7 @@ function useUserRepo() {
|
|
|
11932
11934
|
]).toArray();
|
|
11933
11935
|
const length = await collection.countDocuments(query);
|
|
11934
11936
|
const data = paginate2(items, page, limit, length);
|
|
11935
|
-
setCache(cacheKey, data, 600
|
|
11937
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
11936
11938
|
logger2.log({
|
|
11937
11939
|
level: "info",
|
|
11938
11940
|
message: `Cache set for getUsers: ${cacheKey}`
|
|
@@ -12155,9 +12157,9 @@ function useMemberRepo() {
|
|
|
12155
12157
|
}
|
|
12156
12158
|
const namespace_collection = "members";
|
|
12157
12159
|
const collection = db.collection(namespace_collection);
|
|
12158
|
-
const { getCache, setCache, delNamespace } = useCache3();
|
|
12160
|
+
const { getCache, setCache, delNamespace } = useCache3(namespace_collection);
|
|
12159
12161
|
function delCachedData() {
|
|
12160
|
-
delNamespace(
|
|
12162
|
+
delNamespace().then(() => {
|
|
12161
12163
|
logger3.log({
|
|
12162
12164
|
level: "info",
|
|
12163
12165
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -12248,7 +12250,7 @@ function useMemberRepo() {
|
|
|
12248
12250
|
return cached;
|
|
12249
12251
|
}
|
|
12250
12252
|
const data = await collection.findOne({ _id });
|
|
12251
|
-
setCache(cacheKey, data, 300
|
|
12253
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12252
12254
|
logger3.log({
|
|
12253
12255
|
level: "info",
|
|
12254
12256
|
message: `Cache set for member by id: ${cacheKey}`
|
|
@@ -12285,7 +12287,7 @@ function useMemberRepo() {
|
|
|
12285
12287
|
return cached;
|
|
12286
12288
|
}
|
|
12287
12289
|
const data = await collection.findOne({ user });
|
|
12288
|
-
setCache(cacheKey, data, 300
|
|
12290
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12289
12291
|
logger3.log({
|
|
12290
12292
|
level: "info",
|
|
12291
12293
|
message: `Cache set for member by user ID: ${cacheKey}`
|
|
@@ -12338,7 +12340,7 @@ function useMemberRepo() {
|
|
|
12338
12340
|
return cached;
|
|
12339
12341
|
}
|
|
12340
12342
|
const data = await collection.findOne(query);
|
|
12341
|
-
setCache(cacheKey, data, 300
|
|
12343
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12342
12344
|
logger3.log({
|
|
12343
12345
|
level: "info",
|
|
12344
12346
|
message: `Cache set for member by user ID: ${cacheKey}`
|
|
@@ -12442,7 +12444,7 @@ function useMemberRepo() {
|
|
|
12442
12444
|
]).toArray();
|
|
12443
12445
|
const length = await collection.countDocuments(query);
|
|
12444
12446
|
const data = paginate3(items, page, limit, length);
|
|
12445
|
-
setCache(cacheKey, data, 600
|
|
12447
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
12446
12448
|
logger3.log({
|
|
12447
12449
|
level: "info",
|
|
12448
12450
|
message: `Cache set for getAll members: ${cacheKey}`
|
|
@@ -12477,7 +12479,7 @@ function useMemberRepo() {
|
|
|
12477
12479
|
return cached;
|
|
12478
12480
|
}
|
|
12479
12481
|
const data = await collection.countDocuments({ org, status: "active" });
|
|
12480
|
-
setCache(cacheKey, data, 300
|
|
12482
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12481
12483
|
logger3.log({
|
|
12482
12484
|
level: "info",
|
|
12483
12485
|
message: `Cache set for countByOrg members: ${cacheKey}`
|
|
@@ -12514,7 +12516,7 @@ function useMemberRepo() {
|
|
|
12514
12516
|
return cached;
|
|
12515
12517
|
}
|
|
12516
12518
|
const data = await collection.countDocuments({ user, status: "active" });
|
|
12517
|
-
setCache(cacheKey, data, 300
|
|
12519
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12518
12520
|
logger3.log({
|
|
12519
12521
|
level: "info",
|
|
12520
12522
|
message: `Cache set for countByUser members: ${cacheKey}`
|
|
@@ -12588,7 +12590,7 @@ function useMemberRepo() {
|
|
|
12588
12590
|
]).toArray();
|
|
12589
12591
|
const length = await collection.countDocuments(query);
|
|
12590
12592
|
const data = paginate3(items, page, limit, length);
|
|
12591
|
-
setCache(cacheKey, data, 600
|
|
12593
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
12592
12594
|
logger3.log({
|
|
12593
12595
|
level: "info",
|
|
12594
12596
|
message: `Cache set for getOrgsByMembership members: ${cacheKey}`
|
|
@@ -12666,7 +12668,7 @@ function useMemberRepo() {
|
|
|
12666
12668
|
]).toArray();
|
|
12667
12669
|
const length = await collection.countDocuments(query);
|
|
12668
12670
|
const data = paginate3(items, page, limit, length);
|
|
12669
|
-
setCache(cacheKey, data, 300
|
|
12671
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12670
12672
|
logger3.log({
|
|
12671
12673
|
level: "info",
|
|
12672
12674
|
message: `Cache set for getOrgsByUserId members: ${cacheKey}`
|
|
@@ -12763,9 +12765,6 @@ function useVerificationService() {
|
|
|
12763
12765
|
if (!metadata.app) {
|
|
12764
12766
|
throw new BadRequestError6("App metadata is required.");
|
|
12765
12767
|
}
|
|
12766
|
-
if (!metadata.org || !metadata.orgName) {
|
|
12767
|
-
throw new BadRequestError6("Organization metadata is required.");
|
|
12768
|
-
}
|
|
12769
12768
|
try {
|
|
12770
12769
|
const user = await getUserByEmail(email);
|
|
12771
12770
|
const dir = __dirname;
|
|
@@ -12777,7 +12776,7 @@ function useVerificationService() {
|
|
|
12777
12776
|
context: {
|
|
12778
12777
|
validity: VERIFICATION_USER_INVITE_DURATION,
|
|
12779
12778
|
link: `${APP_MAIN}/verify/member-invite/${res2}`,
|
|
12780
|
-
organization_name: metadata.orgName
|
|
12779
|
+
organization_name: metadata.app === "admin" ? "Admin" : metadata.orgName
|
|
12781
12780
|
},
|
|
12782
12781
|
filePath: filePath2
|
|
12783
12782
|
});
|
|
@@ -12948,11 +12947,6 @@ function useVerificationService() {
|
|
|
12948
12947
|
"App metadata is required for member invite."
|
|
12949
12948
|
);
|
|
12950
12949
|
}
|
|
12951
|
-
if (!_id.metadata?.org || !_id.metadata?.orgName) {
|
|
12952
|
-
throw new BadRequestError6(
|
|
12953
|
-
"Organization metadata is required for member invite."
|
|
12954
|
-
);
|
|
12955
|
-
}
|
|
12956
12950
|
if (!_id.metadata?.role || !_id.metadata?.roleName) {
|
|
12957
12951
|
throw new BadRequestError6(
|
|
12958
12952
|
"Role metadata is required for member invite."
|
|
@@ -12962,8 +12956,8 @@ function useVerificationService() {
|
|
|
12962
12956
|
{
|
|
12963
12957
|
user: user._id?.toString() ?? "",
|
|
12964
12958
|
type: _id.metadata?.app,
|
|
12965
|
-
org: _id.metadata?.org,
|
|
12966
|
-
orgName: _id.metadata?.orgName,
|
|
12959
|
+
org: _id.metadata?.org ?? "",
|
|
12960
|
+
orgName: _id.metadata?.orgName ?? "",
|
|
12967
12961
|
role: _id.metadata?.role,
|
|
12968
12962
|
roleName: _id.metadata?.roleName,
|
|
12969
12963
|
name: `${user.firstName} ${user.lastName}`
|
|
@@ -13086,8 +13080,8 @@ function useVerificationController() {
|
|
|
13086
13080
|
app: Joi2.string().required(),
|
|
13087
13081
|
role: Joi2.string().hex().required(),
|
|
13088
13082
|
roleName: Joi2.string().required(),
|
|
13089
|
-
org: Joi2.string().
|
|
13090
|
-
orgName: Joi2.string().
|
|
13083
|
+
org: Joi2.string().hex().optional().optional().allow("", null),
|
|
13084
|
+
orgName: Joi2.string().optional().optional().allow("", null)
|
|
13091
13085
|
});
|
|
13092
13086
|
const { error } = validation.validate(req.body);
|
|
13093
13087
|
if (error) {
|
|
@@ -13247,9 +13241,9 @@ function useTokenRepo() {
|
|
|
13247
13241
|
}
|
|
13248
13242
|
const namespace_collection = "tokens";
|
|
13249
13243
|
const collection = db.collection(namespace_collection);
|
|
13250
|
-
const { getCache, setCache, delNamespace } = useCache4();
|
|
13244
|
+
const { getCache, setCache, delNamespace } = useCache4(namespace_collection);
|
|
13251
13245
|
function delCachedData() {
|
|
13252
|
-
delNamespace(
|
|
13246
|
+
delNamespace().then(() => {
|
|
13253
13247
|
logger5.log({
|
|
13254
13248
|
level: "info",
|
|
13255
13249
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -13288,7 +13282,7 @@ function useTokenRepo() {
|
|
|
13288
13282
|
}
|
|
13289
13283
|
const data = await collection.findOne({ token });
|
|
13290
13284
|
if (data) {
|
|
13291
|
-
setCache(cacheKey, data, 300
|
|
13285
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
13292
13286
|
logger5.log({
|
|
13293
13287
|
level: "info",
|
|
13294
13288
|
message: `Cache set for token: ${cacheKey}`
|
|
@@ -13364,9 +13358,9 @@ function useFileRepo() {
|
|
|
13364
13358
|
}
|
|
13365
13359
|
const namespace_collection = "files";
|
|
13366
13360
|
const collection = db.collection(namespace_collection);
|
|
13367
|
-
const { getCache, setCache, delNamespace } = useCache5();
|
|
13361
|
+
const { getCache, setCache, delNamespace } = useCache5(namespace_collection);
|
|
13368
13362
|
function delCachedData() {
|
|
13369
|
-
delNamespace(
|
|
13363
|
+
delNamespace().then(() => {
|
|
13370
13364
|
logger6.log({
|
|
13371
13365
|
level: "info",
|
|
13372
13366
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -13414,7 +13408,7 @@ function useFileRepo() {
|
|
|
13414
13408
|
return cached;
|
|
13415
13409
|
}
|
|
13416
13410
|
const data = await collection.find({ $and: [{ status: "draft" }, { status: null }] }).toArray();
|
|
13417
|
-
setCache(cacheKey, data, 300
|
|
13411
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
13418
13412
|
logger6.log({
|
|
13419
13413
|
level: "info",
|
|
13420
13414
|
message: `Cache set for getAllDraftedFiles: ${cacheKey}`
|
|
@@ -13487,6 +13481,16 @@ var isPlainObject = (val) => {
|
|
|
13487
13481
|
const prototype3 = getPrototypeOf(val);
|
|
13488
13482
|
return (prototype3 === null || prototype3 === Object.prototype || Object.getPrototypeOf(prototype3) === null) && !(toStringTag in val) && !(iterator in val);
|
|
13489
13483
|
};
|
|
13484
|
+
var isEmptyObject = (val) => {
|
|
13485
|
+
if (!isObject(val) || isBuffer(val)) {
|
|
13486
|
+
return false;
|
|
13487
|
+
}
|
|
13488
|
+
try {
|
|
13489
|
+
return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
|
|
13490
|
+
} catch (e) {
|
|
13491
|
+
return false;
|
|
13492
|
+
}
|
|
13493
|
+
};
|
|
13490
13494
|
var isDate = kindOfTest("Date");
|
|
13491
13495
|
var isFile = kindOfTest("File");
|
|
13492
13496
|
var isBlob = kindOfTest("Blob");
|
|
@@ -13514,6 +13518,9 @@ function forEach(obj, fn, { allOwnKeys = false } = {}) {
|
|
|
13514
13518
|
fn.call(null, obj[i], i, obj);
|
|
13515
13519
|
}
|
|
13516
13520
|
} else {
|
|
13521
|
+
if (isBuffer(obj)) {
|
|
13522
|
+
return;
|
|
13523
|
+
}
|
|
13517
13524
|
const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
|
13518
13525
|
const len = keys.length;
|
|
13519
13526
|
let key;
|
|
@@ -13524,6 +13531,9 @@ function forEach(obj, fn, { allOwnKeys = false } = {}) {
|
|
|
13524
13531
|
}
|
|
13525
13532
|
}
|
|
13526
13533
|
function findKey(obj, key) {
|
|
13534
|
+
if (isBuffer(obj)) {
|
|
13535
|
+
return null;
|
|
13536
|
+
}
|
|
13527
13537
|
key = key.toLowerCase();
|
|
13528
13538
|
const keys = Object.keys(obj);
|
|
13529
13539
|
let i = keys.length;
|
|
@@ -13720,6 +13730,9 @@ var toJSONObject = (obj) => {
|
|
|
13720
13730
|
if (stack.indexOf(source) >= 0) {
|
|
13721
13731
|
return;
|
|
13722
13732
|
}
|
|
13733
|
+
if (isBuffer(source)) {
|
|
13734
|
+
return source;
|
|
13735
|
+
}
|
|
13723
13736
|
if (!("toJSON" in source)) {
|
|
13724
13737
|
stack[i] = source;
|
|
13725
13738
|
const target = isArray(source) ? [] : {};
|
|
@@ -13769,6 +13782,7 @@ var utils_default = {
|
|
|
13769
13782
|
isBoolean,
|
|
13770
13783
|
isObject,
|
|
13771
13784
|
isPlainObject,
|
|
13785
|
+
isEmptyObject,
|
|
13772
13786
|
isReadableStream,
|
|
13773
13787
|
isRequest,
|
|
13774
13788
|
isResponse,
|
|
@@ -14213,15 +14227,16 @@ var platform_default = {
|
|
|
14213
14227
|
|
|
14214
14228
|
// node_modules/axios/lib/helpers/toURLEncodedForm.js
|
|
14215
14229
|
function toURLEncodedForm(data, options) {
|
|
14216
|
-
return toFormData_default(data, new platform_default.classes.URLSearchParams(),
|
|
14230
|
+
return toFormData_default(data, new platform_default.classes.URLSearchParams(), {
|
|
14217
14231
|
visitor: function(value, key, path, helpers) {
|
|
14218
14232
|
if (platform_default.isNode && utils_default.isBuffer(value)) {
|
|
14219
14233
|
this.append(key, value.toString("base64"));
|
|
14220
14234
|
return false;
|
|
14221
14235
|
}
|
|
14222
14236
|
return helpers.defaultVisitor.apply(this, arguments);
|
|
14223
|
-
}
|
|
14224
|
-
|
|
14237
|
+
},
|
|
14238
|
+
...options
|
|
14239
|
+
});
|
|
14225
14240
|
}
|
|
14226
14241
|
|
|
14227
14242
|
// node_modules/axios/lib/helpers/formDataToJSON.js
|
|
@@ -14734,7 +14749,7 @@ import util2 from "util";
|
|
|
14734
14749
|
import zlib from "zlib";
|
|
14735
14750
|
|
|
14736
14751
|
// node_modules/axios/lib/env/data.js
|
|
14737
|
-
var VERSION = "1.
|
|
14752
|
+
var VERSION = "1.11.0";
|
|
14738
14753
|
|
|
14739
14754
|
// node_modules/axios/lib/helpers/parseProtocol.js
|
|
14740
14755
|
function parseProtocol(url2) {
|
|
@@ -15076,7 +15091,7 @@ function throttle(fn, freq) {
|
|
|
15076
15091
|
clearTimeout(timer);
|
|
15077
15092
|
timer = null;
|
|
15078
15093
|
}
|
|
15079
|
-
fn
|
|
15094
|
+
fn(...args);
|
|
15080
15095
|
};
|
|
15081
15096
|
const throttled = (...args) => {
|
|
15082
15097
|
const now = Date.now();
|
|
@@ -15751,7 +15766,7 @@ function mergeConfig(config1, config2) {
|
|
|
15751
15766
|
validateStatus: mergeDirectKeys,
|
|
15752
15767
|
headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
|
|
15753
15768
|
};
|
|
15754
|
-
utils_default.forEach(Object.keys(
|
|
15769
|
+
utils_default.forEach(Object.keys({ ...config1, ...config2 }), function computeConfigValue(prop) {
|
|
15755
15770
|
const merge2 = mergeMap[prop] || mergeDeepProperties;
|
|
15756
15771
|
const configValue = merge2(config1[prop], config2[prop], prop);
|
|
15757
15772
|
utils_default.isUndefined(configValue) && merge2 !== mergeDirectKeys || (config3[prop] = configValue);
|
|
@@ -16465,8 +16480,8 @@ var Axios = class {
|
|
|
16465
16480
|
let len;
|
|
16466
16481
|
if (!synchronousRequestInterceptors) {
|
|
16467
16482
|
const chain = [dispatchRequest.bind(this), void 0];
|
|
16468
|
-
chain.unshift
|
|
16469
|
-
chain.push
|
|
16483
|
+
chain.unshift(...requestInterceptorChain);
|
|
16484
|
+
chain.push(...responseInterceptorChain);
|
|
16470
16485
|
len = chain.length;
|
|
16471
16486
|
promise = Promise.resolve(config2);
|
|
16472
16487
|
while (i < len) {
|
|
@@ -17448,9 +17463,9 @@ function useRoleRepo() {
|
|
|
17448
17463
|
}
|
|
17449
17464
|
const namespace_collection = "roles";
|
|
17450
17465
|
const collection = db.collection(namespace_collection);
|
|
17451
|
-
const { getCache, setCache, delNamespace } = useCache6();
|
|
17466
|
+
const { getCache, setCache, delNamespace } = useCache6(namespace_collection);
|
|
17452
17467
|
function delCachedData() {
|
|
17453
|
-
delNamespace(
|
|
17468
|
+
delNamespace().then(() => {
|
|
17454
17469
|
logger8.log({
|
|
17455
17470
|
level: "info",
|
|
17456
17471
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -17523,7 +17538,7 @@ function useRoleRepo() {
|
|
|
17523
17538
|
return cached;
|
|
17524
17539
|
}
|
|
17525
17540
|
const data = await collection.findOne({ user: value });
|
|
17526
|
-
setCache(cacheKey, data, 300
|
|
17541
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
17527
17542
|
logger8.log({
|
|
17528
17543
|
level: "info",
|
|
17529
17544
|
message: `Cache set for role by user ID: ${cacheKey}`
|
|
@@ -17558,7 +17573,7 @@ function useRoleRepo() {
|
|
|
17558
17573
|
return cached;
|
|
17559
17574
|
}
|
|
17560
17575
|
const data = await collection.findOne({ _id });
|
|
17561
|
-
setCache(cacheKey, data, 300
|
|
17576
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
17562
17577
|
logger8.log({
|
|
17563
17578
|
level: "info",
|
|
17564
17579
|
message: `Cache set for role by id: ${cacheKey}`
|
|
@@ -17591,7 +17606,7 @@ function useRoleRepo() {
|
|
|
17591
17606
|
return cached;
|
|
17592
17607
|
}
|
|
17593
17608
|
const data = await collection.findOne({ name });
|
|
17594
|
-
setCache(cacheKey, data, 300
|
|
17609
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
17595
17610
|
logger8.log({
|
|
17596
17611
|
level: "info",
|
|
17597
17612
|
message: `Cache set for role by name: ${cacheKey}`
|
|
@@ -17665,7 +17680,7 @@ function useRoleRepo() {
|
|
|
17665
17680
|
]).toArray();
|
|
17666
17681
|
const length = await collection.countDocuments(query);
|
|
17667
17682
|
const data = paginate4(items, page, limit, length);
|
|
17668
|
-
setCache(cacheKey, data, 600
|
|
17683
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
17669
17684
|
logger8.log({
|
|
17670
17685
|
level: "info",
|
|
17671
17686
|
message: `Cache set for getRoles: ${cacheKey}`
|
|
@@ -17931,9 +17946,6 @@ function useUserService() {
|
|
|
17931
17946
|
throw new BadRequestError11("Invitation expired.");
|
|
17932
17947
|
}
|
|
17933
17948
|
const email = invitation.email;
|
|
17934
|
-
if (!invitation.metadata.org) {
|
|
17935
|
-
throw new BadRequestError11("Invitation does not have an organization.");
|
|
17936
|
-
}
|
|
17937
17949
|
const _user = await getUserByEmail(invitation.email);
|
|
17938
17950
|
let userId = _user?._id ?? "";
|
|
17939
17951
|
if (!_user) {
|
|
@@ -17958,8 +17970,8 @@ function useUserService() {
|
|
|
17958
17970
|
role: invitation.metadata?.role,
|
|
17959
17971
|
roleName: invitation.metadata?.roleName,
|
|
17960
17972
|
type: invitation.metadata?.app,
|
|
17961
|
-
org: invitation.metadata?.org,
|
|
17962
|
-
orgName: invitation.metadata?.orgName
|
|
17973
|
+
org: invitation.metadata?.org ?? "",
|
|
17974
|
+
orgName: invitation.metadata?.orgName ?? ""
|
|
17963
17975
|
},
|
|
17964
17976
|
session
|
|
17965
17977
|
);
|
|
@@ -18382,11 +18394,14 @@ import {
|
|
|
18382
18394
|
comparePassword,
|
|
18383
18395
|
generateToken,
|
|
18384
18396
|
InternalServerError as InternalServerError11,
|
|
18385
|
-
NotFoundError as NotFoundError3
|
|
18397
|
+
NotFoundError as NotFoundError3,
|
|
18398
|
+
useCache as useCache8
|
|
18386
18399
|
} from "@eeplatform/nodejs-utils";
|
|
18387
18400
|
import jwt from "jsonwebtoken";
|
|
18401
|
+
import { v4 as uuidv4 } from "uuid";
|
|
18388
18402
|
function useAuthService() {
|
|
18389
18403
|
const expiresIn = "1m";
|
|
18404
|
+
const { setCache, delCache } = useCache8("sessions");
|
|
18390
18405
|
async function login({ email, password } = {}) {
|
|
18391
18406
|
if (!email) {
|
|
18392
18407
|
throw new BadRequestError13("Email is required");
|
|
@@ -18418,34 +18433,14 @@ function useAuthService() {
|
|
|
18418
18433
|
if (!isPasswordValid) {
|
|
18419
18434
|
throw new BadRequestError13("Invalid password");
|
|
18420
18435
|
}
|
|
18421
|
-
const
|
|
18422
|
-
|
|
18423
|
-
|
|
18424
|
-
|
|
18425
|
-
|
|
18426
|
-
|
|
18427
|
-
|
|
18428
|
-
|
|
18429
|
-
} catch (error) {
|
|
18430
|
-
throw new BadRequestError13("Error generating refresh token");
|
|
18431
|
-
}
|
|
18432
|
-
let accessToken;
|
|
18433
|
-
try {
|
|
18434
|
-
accessToken = generateToken({
|
|
18435
|
-
secret: ACCESS_TOKEN_SECRET,
|
|
18436
|
-
metadata,
|
|
18437
|
-
options: { expiresIn }
|
|
18438
|
-
});
|
|
18439
|
-
} catch (error) {
|
|
18440
|
-
throw new BadRequestError13("Error generating access token");
|
|
18441
|
-
}
|
|
18442
|
-
const user = _user._id ?? "";
|
|
18443
|
-
try {
|
|
18444
|
-
await useTokenRepo().createToken({ token: refreshToken2, user });
|
|
18445
|
-
} catch (error) {
|
|
18446
|
-
throw new BadRequestError13("Error creating refresh token");
|
|
18447
|
-
}
|
|
18448
|
-
return { accessToken, refreshToken: refreshToken2, id: _user._id };
|
|
18436
|
+
const sid = uuidv4();
|
|
18437
|
+
const cacheKey = `sid:${sid}`;
|
|
18438
|
+
setCache(cacheKey, _user, 14400).then(() => {
|
|
18439
|
+
console.log("Session ID cached successfully");
|
|
18440
|
+
}).catch((error) => {
|
|
18441
|
+
console.error("Error caching session ID:", error);
|
|
18442
|
+
});
|
|
18443
|
+
return { sid, user: _user._id?.toString() ?? "" };
|
|
18449
18444
|
}
|
|
18450
18445
|
async function refreshToken(token) {
|
|
18451
18446
|
let decoded;
|
|
@@ -18479,26 +18474,13 @@ function useAuthService() {
|
|
|
18479
18474
|
}
|
|
18480
18475
|
return accessToken;
|
|
18481
18476
|
}
|
|
18482
|
-
async function logout(
|
|
18483
|
-
let _token;
|
|
18484
|
-
try {
|
|
18485
|
-
_token = await useTokenRepo().getToken(token);
|
|
18486
|
-
if (!_token) {
|
|
18487
|
-
throw new NotFoundError3("Invalid token");
|
|
18488
|
-
}
|
|
18489
|
-
} catch (error) {
|
|
18490
|
-
if (error instanceof AppError5) {
|
|
18491
|
-
throw error;
|
|
18492
|
-
} else {
|
|
18493
|
-
throw new InternalServerError11(`${error}`);
|
|
18494
|
-
}
|
|
18495
|
-
}
|
|
18477
|
+
async function logout(sid) {
|
|
18496
18478
|
try {
|
|
18497
|
-
await
|
|
18479
|
+
await delCache(`sid:${sid}`);
|
|
18480
|
+
return "Session deleted successfully";
|
|
18498
18481
|
} catch (error) {
|
|
18499
18482
|
throw new InternalServerError11("Error deleting token");
|
|
18500
18483
|
}
|
|
18501
|
-
return "Logged out successfully";
|
|
18502
18484
|
}
|
|
18503
18485
|
return {
|
|
18504
18486
|
login,
|
|
@@ -18512,7 +18494,8 @@ import Joi5 from "joi";
|
|
|
18512
18494
|
import {
|
|
18513
18495
|
AppError as AppError6,
|
|
18514
18496
|
BadRequestError as BadRequestError14,
|
|
18515
|
-
InternalServerError as InternalServerError12
|
|
18497
|
+
InternalServerError as InternalServerError12,
|
|
18498
|
+
logger as logger10
|
|
18516
18499
|
} from "@eeplatform/nodejs-utils";
|
|
18517
18500
|
function useAuthController() {
|
|
18518
18501
|
const { signUp: _signUp } = useVerificationService();
|
|
@@ -18526,16 +18509,26 @@ function useAuthController() {
|
|
|
18526
18509
|
const { error } = validation.validate({ email, password });
|
|
18527
18510
|
if (error) {
|
|
18528
18511
|
next(new BadRequestError14(error.message));
|
|
18512
|
+
return;
|
|
18529
18513
|
}
|
|
18530
18514
|
try {
|
|
18531
|
-
const
|
|
18532
|
-
|
|
18515
|
+
const session = await useAuthService().login({
|
|
18516
|
+
email,
|
|
18517
|
+
password
|
|
18518
|
+
});
|
|
18519
|
+
res.json(session);
|
|
18533
18520
|
} catch (error2) {
|
|
18521
|
+
logger10.log({
|
|
18522
|
+
level: "error",
|
|
18523
|
+
message: `Error during login: ${error2.message}`
|
|
18524
|
+
});
|
|
18525
|
+
console.log(`Error during login: ${error2}`);
|
|
18534
18526
|
if (error2 instanceof AppError6) {
|
|
18535
18527
|
next(error2);
|
|
18536
18528
|
} else {
|
|
18537
18529
|
next(new InternalServerError12("An unexpected error occurred"));
|
|
18538
18530
|
}
|
|
18531
|
+
return;
|
|
18539
18532
|
}
|
|
18540
18533
|
}
|
|
18541
18534
|
async function refreshToken(req, res, next) {
|
|
@@ -18556,13 +18549,13 @@ function useAuthController() {
|
|
|
18556
18549
|
}
|
|
18557
18550
|
}
|
|
18558
18551
|
async function logout(req, res, next) {
|
|
18559
|
-
const
|
|
18560
|
-
if (!
|
|
18561
|
-
next(new BadRequestError14("
|
|
18552
|
+
const sid = req.headers["authorization"] ?? "";
|
|
18553
|
+
if (!sid) {
|
|
18554
|
+
next(new BadRequestError14("Session ID is required"));
|
|
18562
18555
|
return;
|
|
18563
18556
|
}
|
|
18564
18557
|
try {
|
|
18565
|
-
await useAuthService().logout(
|
|
18558
|
+
await useAuthService().logout(sid);
|
|
18566
18559
|
res.json({ message: "Logged out successfully" });
|
|
18567
18560
|
} catch (error) {
|
|
18568
18561
|
if (error instanceof AppError6) {
|
|
@@ -18637,7 +18630,7 @@ function useAuthController() {
|
|
|
18637
18630
|
}
|
|
18638
18631
|
|
|
18639
18632
|
// src/services/file.service.ts
|
|
18640
|
-
import { logger as
|
|
18633
|
+
import { logger as logger11, useS3 as useS32, useAtlas as useAtlas9 } from "@eeplatform/nodejs-utils";
|
|
18641
18634
|
import cron from "node-cron";
|
|
18642
18635
|
function useFileService() {
|
|
18643
18636
|
const {
|
|
@@ -18698,12 +18691,12 @@ function useFileService() {
|
|
|
18698
18691
|
const file = files[index];
|
|
18699
18692
|
try {
|
|
18700
18693
|
await deleteFile(file._id.toString());
|
|
18701
|
-
await
|
|
18694
|
+
await logger11.log({
|
|
18702
18695
|
level: "info",
|
|
18703
18696
|
message: "Successfully deleted draft files."
|
|
18704
18697
|
});
|
|
18705
18698
|
} catch (error) {
|
|
18706
|
-
|
|
18699
|
+
logger11.log({
|
|
18707
18700
|
level: "info",
|
|
18708
18701
|
message: "Successfully deleted draft files."
|
|
18709
18702
|
});
|
|
@@ -18957,11 +18950,11 @@ import { ObjectId as ObjectId16 } from "mongodb";
|
|
|
18957
18950
|
import {
|
|
18958
18951
|
BadRequestError as BadRequestError17,
|
|
18959
18952
|
InternalServerError as InternalServerError15,
|
|
18960
|
-
logger as
|
|
18953
|
+
logger as logger12,
|
|
18961
18954
|
makeCacheKey as makeCacheKey8,
|
|
18962
18955
|
paginate as paginate5,
|
|
18963
18956
|
useAtlas as useAtlas10,
|
|
18964
|
-
useCache as
|
|
18957
|
+
useCache as useCache9
|
|
18965
18958
|
} from "@eeplatform/nodejs-utils";
|
|
18966
18959
|
function useEntityRepo() {
|
|
18967
18960
|
const db = useAtlas10.getDb();
|
|
@@ -18970,15 +18963,15 @@ function useEntityRepo() {
|
|
|
18970
18963
|
}
|
|
18971
18964
|
const namespace_collection = "entities";
|
|
18972
18965
|
const collection = db.collection(namespace_collection);
|
|
18973
|
-
const { getCache, setCache, delNamespace } =
|
|
18966
|
+
const { getCache, setCache, delNamespace } = useCache9(namespace_collection);
|
|
18974
18967
|
function delCachedData() {
|
|
18975
|
-
delNamespace(
|
|
18976
|
-
|
|
18968
|
+
delNamespace().then(() => {
|
|
18969
|
+
logger12.log({
|
|
18977
18970
|
level: "info",
|
|
18978
18971
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
18979
18972
|
});
|
|
18980
18973
|
}).catch((err) => {
|
|
18981
|
-
|
|
18974
|
+
logger12.log({
|
|
18982
18975
|
level: "error",
|
|
18983
18976
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
18984
18977
|
});
|
|
@@ -19008,7 +19001,7 @@ function useEntityRepo() {
|
|
|
19008
19001
|
delCachedData();
|
|
19009
19002
|
return res.insertedId.toString();
|
|
19010
19003
|
} catch (error) {
|
|
19011
|
-
|
|
19004
|
+
logger12.log({ level: "error", message: `${error}` });
|
|
19012
19005
|
const isDuplicated = error.message.includes("duplicate");
|
|
19013
19006
|
if (isDuplicated) {
|
|
19014
19007
|
throw new BadRequestError17("Entity name already exists.");
|
|
@@ -19038,7 +19031,7 @@ function useEntityRepo() {
|
|
|
19038
19031
|
try {
|
|
19039
19032
|
const cached = await getCache(cacheKey);
|
|
19040
19033
|
if (cached) {
|
|
19041
|
-
|
|
19034
|
+
logger12.log({
|
|
19042
19035
|
level: "info",
|
|
19043
19036
|
message: `Cache hit for getEntities: ${cacheKey}`
|
|
19044
19037
|
});
|
|
@@ -19052,20 +19045,20 @@ function useEntityRepo() {
|
|
|
19052
19045
|
]).toArray();
|
|
19053
19046
|
const length = await collection.countDocuments(query);
|
|
19054
19047
|
const data = paginate5(items, page, limit, length);
|
|
19055
|
-
setCache(cacheKey, data, 600
|
|
19056
|
-
|
|
19048
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
19049
|
+
logger12.log({
|
|
19057
19050
|
level: "info",
|
|
19058
19051
|
message: `Cache set for getEntities: ${cacheKey}`
|
|
19059
19052
|
});
|
|
19060
19053
|
}).catch((err) => {
|
|
19061
|
-
|
|
19054
|
+
logger12.log({
|
|
19062
19055
|
level: "error",
|
|
19063
19056
|
message: `Failed to set cache for getEntities: ${err.message}`
|
|
19064
19057
|
});
|
|
19065
19058
|
});
|
|
19066
19059
|
return data;
|
|
19067
19060
|
} catch (error) {
|
|
19068
|
-
|
|
19061
|
+
logger12.log({ level: "error", message: `${error}` });
|
|
19069
19062
|
throw error;
|
|
19070
19063
|
}
|
|
19071
19064
|
}
|
|
@@ -19321,11 +19314,11 @@ function MSubscription(value) {
|
|
|
19321
19314
|
// src/repositories/subscription.repository.ts
|
|
19322
19315
|
import {
|
|
19323
19316
|
BadRequestError as BadRequestError20,
|
|
19324
|
-
logger as
|
|
19317
|
+
logger as logger13,
|
|
19325
19318
|
makeCacheKey as makeCacheKey9,
|
|
19326
19319
|
paginate as paginate6,
|
|
19327
19320
|
useAtlas as useAtlas11,
|
|
19328
|
-
useCache as
|
|
19321
|
+
useCache as useCache10
|
|
19329
19322
|
} from "@eeplatform/nodejs-utils";
|
|
19330
19323
|
import { ObjectId as ObjectId18 } from "mongodb";
|
|
19331
19324
|
import Joi10 from "joi";
|
|
@@ -19336,15 +19329,15 @@ function useSubscriptionRepo() {
|
|
|
19336
19329
|
}
|
|
19337
19330
|
const namespace_collection = "subscriptions";
|
|
19338
19331
|
const collection = db.collection(namespace_collection);
|
|
19339
|
-
const { getCache, setCache, delNamespace } =
|
|
19332
|
+
const { getCache, setCache, delNamespace } = useCache10(namespace_collection);
|
|
19340
19333
|
function delCachedData() {
|
|
19341
|
-
delNamespace(
|
|
19342
|
-
|
|
19334
|
+
delNamespace().then(() => {
|
|
19335
|
+
logger13.log({
|
|
19343
19336
|
level: "info",
|
|
19344
19337
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
19345
19338
|
});
|
|
19346
19339
|
}).catch((err) => {
|
|
19347
|
-
|
|
19340
|
+
logger13.log({
|
|
19348
19341
|
level: "error",
|
|
19349
19342
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
19350
19343
|
});
|
|
@@ -19396,7 +19389,7 @@ function useSubscriptionRepo() {
|
|
|
19396
19389
|
try {
|
|
19397
19390
|
const cached = await getCache(cacheKey);
|
|
19398
19391
|
if (cached) {
|
|
19399
|
-
|
|
19392
|
+
logger13.log({
|
|
19400
19393
|
level: "info",
|
|
19401
19394
|
message: `Cache hit for getById subscription: ${cacheKey}`
|
|
19402
19395
|
});
|
|
@@ -19404,13 +19397,13 @@ function useSubscriptionRepo() {
|
|
|
19404
19397
|
}
|
|
19405
19398
|
const data = await collection.findOne({ _id });
|
|
19406
19399
|
if (data) {
|
|
19407
|
-
setCache(cacheKey, data, 300
|
|
19408
|
-
|
|
19400
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
19401
|
+
logger13.log({
|
|
19409
19402
|
level: "info",
|
|
19410
19403
|
message: `Cache set for subscription by ID: ${cacheKey}`
|
|
19411
19404
|
});
|
|
19412
19405
|
}).catch((err) => {
|
|
19413
|
-
|
|
19406
|
+
logger13.log({
|
|
19414
19407
|
level: "error",
|
|
19415
19408
|
message: `Failed to set cache for subscription by ID: ${err.message}`
|
|
19416
19409
|
});
|
|
@@ -19431,7 +19424,7 @@ function useSubscriptionRepo() {
|
|
|
19431
19424
|
try {
|
|
19432
19425
|
const cached = await getCache(cacheKey);
|
|
19433
19426
|
if (cached) {
|
|
19434
|
-
|
|
19427
|
+
logger13.log({
|
|
19435
19428
|
level: "info",
|
|
19436
19429
|
message: `Cache hit for getByUserId subscription: ${cacheKey}`
|
|
19437
19430
|
});
|
|
@@ -19439,13 +19432,13 @@ function useSubscriptionRepo() {
|
|
|
19439
19432
|
}
|
|
19440
19433
|
const data = await collection.findOne({ user });
|
|
19441
19434
|
if (data) {
|
|
19442
|
-
setCache(cacheKey, data, 300
|
|
19443
|
-
|
|
19435
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
19436
|
+
logger13.log({
|
|
19444
19437
|
level: "info",
|
|
19445
19438
|
message: `Cache set for subscription by user ID: ${cacheKey}`
|
|
19446
19439
|
});
|
|
19447
19440
|
}).catch((err) => {
|
|
19448
|
-
|
|
19441
|
+
logger13.log({
|
|
19449
19442
|
level: "error",
|
|
19450
19443
|
message: `Failed to set cache for subscription by user ID: ${err.message}`
|
|
19451
19444
|
});
|
|
@@ -19491,7 +19484,7 @@ function useSubscriptionRepo() {
|
|
|
19491
19484
|
try {
|
|
19492
19485
|
const cached = await getCache(cacheKey);
|
|
19493
19486
|
if (cached) {
|
|
19494
|
-
|
|
19487
|
+
logger13.log({
|
|
19495
19488
|
level: "info",
|
|
19496
19489
|
message: `Cache hit for getBySubscriptionId: ${cacheKey}`
|
|
19497
19490
|
});
|
|
@@ -19499,13 +19492,13 @@ function useSubscriptionRepo() {
|
|
|
19499
19492
|
}
|
|
19500
19493
|
const data = await collection.findOne({ subscriptionId });
|
|
19501
19494
|
if (data) {
|
|
19502
|
-
setCache(cacheKey, data, 300
|
|
19503
|
-
|
|
19495
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
19496
|
+
logger13.log({
|
|
19504
19497
|
level: "info",
|
|
19505
19498
|
message: `Cache set for subscription by subscription ID: ${cacheKey}`
|
|
19506
19499
|
});
|
|
19507
19500
|
}).catch((err) => {
|
|
19508
|
-
|
|
19501
|
+
logger13.log({
|
|
19509
19502
|
level: "error",
|
|
19510
19503
|
message: `Failed to set cache for subscription by subscription ID: ${err.message}`
|
|
19511
19504
|
});
|
|
@@ -19541,7 +19534,7 @@ function useSubscriptionRepo() {
|
|
|
19541
19534
|
try {
|
|
19542
19535
|
const cached = await getCache(cacheKey);
|
|
19543
19536
|
if (cached) {
|
|
19544
|
-
|
|
19537
|
+
logger13.log({
|
|
19545
19538
|
level: "info",
|
|
19546
19539
|
message: `Cache hit for getSubscriptions: ${cacheKey}`
|
|
19547
19540
|
});
|
|
@@ -19555,20 +19548,20 @@ function useSubscriptionRepo() {
|
|
|
19555
19548
|
]).toArray();
|
|
19556
19549
|
const length = await collection.countDocuments(query);
|
|
19557
19550
|
const data = paginate6(items, page, limit, length);
|
|
19558
|
-
setCache(cacheKey, data, 600
|
|
19559
|
-
|
|
19551
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
19552
|
+
logger13.log({
|
|
19560
19553
|
level: "info",
|
|
19561
19554
|
message: `Cache set for getSubscriptions: ${cacheKey}`
|
|
19562
19555
|
});
|
|
19563
19556
|
}).catch((err) => {
|
|
19564
|
-
|
|
19557
|
+
logger13.log({
|
|
19565
19558
|
level: "error",
|
|
19566
19559
|
message: `Failed to set cache for getSubscriptions: ${err.message}`
|
|
19567
19560
|
});
|
|
19568
19561
|
});
|
|
19569
19562
|
return data;
|
|
19570
19563
|
} catch (error) {
|
|
19571
|
-
|
|
19564
|
+
logger13.log({ level: "error", message: `${error}` });
|
|
19572
19565
|
throw error;
|
|
19573
19566
|
}
|
|
19574
19567
|
}
|
|
@@ -19715,10 +19708,10 @@ function useSubscriptionRepo() {
|
|
|
19715
19708
|
},
|
|
19716
19709
|
{ session }
|
|
19717
19710
|
);
|
|
19718
|
-
|
|
19711
|
+
logger13.info(`${res.modifiedCount} subscription updated.`);
|
|
19719
19712
|
return "Successfully updated subscription.";
|
|
19720
19713
|
} catch (error2) {
|
|
19721
|
-
|
|
19714
|
+
logger13.error(`${error2}`);
|
|
19722
19715
|
throw new BadRequestError20("Failed to update subscription.");
|
|
19723
19716
|
}
|
|
19724
19717
|
}
|
|
@@ -19970,7 +19963,7 @@ function useSubscriptionRepo() {
|
|
|
19970
19963
|
import {
|
|
19971
19964
|
AppError as AppError9,
|
|
19972
19965
|
BadRequestError as BadRequestError33,
|
|
19973
|
-
logger as
|
|
19966
|
+
logger as logger21,
|
|
19974
19967
|
useAtlas as useAtlas19
|
|
19975
19968
|
} from "@eeplatform/nodejs-utils";
|
|
19976
19969
|
|
|
@@ -19979,11 +19972,11 @@ import {
|
|
|
19979
19972
|
AppError as AppError8,
|
|
19980
19973
|
BadRequestError as BadRequestError22,
|
|
19981
19974
|
InternalServerError as InternalServerError16,
|
|
19982
|
-
logger as
|
|
19975
|
+
logger as logger14,
|
|
19983
19976
|
makeCacheKey as makeCacheKey10,
|
|
19984
19977
|
paginate as paginate7,
|
|
19985
19978
|
useAtlas as useAtlas12,
|
|
19986
|
-
useCache as
|
|
19979
|
+
useCache as useCache11
|
|
19987
19980
|
} from "@eeplatform/nodejs-utils";
|
|
19988
19981
|
|
|
19989
19982
|
// src/models/organization.model.ts
|
|
@@ -20038,7 +20031,7 @@ function useOrgRepo() {
|
|
|
20038
20031
|
}
|
|
20039
20032
|
const namespace_collection = "organizations";
|
|
20040
20033
|
const collection = db.collection(namespace_collection);
|
|
20041
|
-
const { getCache, setCache, delNamespace } =
|
|
20034
|
+
const { getCache, setCache, delNamespace } = useCache11(namespace_collection);
|
|
20042
20035
|
async function createIndex() {
|
|
20043
20036
|
try {
|
|
20044
20037
|
await collection.createIndex([
|
|
@@ -20073,13 +20066,13 @@ function useOrgRepo() {
|
|
|
20073
20066
|
}
|
|
20074
20067
|
}
|
|
20075
20068
|
function delCachedData() {
|
|
20076
|
-
delNamespace(
|
|
20077
|
-
|
|
20069
|
+
delNamespace().then(() => {
|
|
20070
|
+
logger14.log({
|
|
20078
20071
|
level: "info",
|
|
20079
20072
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
20080
20073
|
});
|
|
20081
20074
|
}).catch((err) => {
|
|
20082
|
-
|
|
20075
|
+
logger14.log({
|
|
20083
20076
|
level: "error",
|
|
20084
20077
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
20085
20078
|
});
|
|
@@ -20092,7 +20085,7 @@ function useOrgRepo() {
|
|
|
20092
20085
|
delCachedData();
|
|
20093
20086
|
return res.insertedId;
|
|
20094
20087
|
} catch (error) {
|
|
20095
|
-
|
|
20088
|
+
logger14.log({
|
|
20096
20089
|
level: "error",
|
|
20097
20090
|
message: error.message
|
|
20098
20091
|
});
|
|
@@ -20127,14 +20120,14 @@ function useOrgRepo() {
|
|
|
20127
20120
|
sort: JSON.stringify(sort),
|
|
20128
20121
|
status
|
|
20129
20122
|
});
|
|
20130
|
-
|
|
20123
|
+
logger14.log({
|
|
20131
20124
|
level: "info",
|
|
20132
20125
|
message: `Cache key for getAll organizations: ${cacheKey}`
|
|
20133
20126
|
});
|
|
20134
20127
|
try {
|
|
20135
20128
|
const cached = await getCache(cacheKey);
|
|
20136
20129
|
if (cached) {
|
|
20137
|
-
|
|
20130
|
+
logger14.log({
|
|
20138
20131
|
level: "info",
|
|
20139
20132
|
message: `Cache hit for getAll organizations: ${cacheKey}`
|
|
20140
20133
|
});
|
|
@@ -20157,20 +20150,20 @@ function useOrgRepo() {
|
|
|
20157
20150
|
]).toArray();
|
|
20158
20151
|
const length = await collection.countDocuments(query);
|
|
20159
20152
|
const data = paginate7(items, page, limit, length);
|
|
20160
|
-
setCache(cacheKey, data, 600
|
|
20161
|
-
|
|
20153
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
20154
|
+
logger14.log({
|
|
20162
20155
|
level: "info",
|
|
20163
20156
|
message: `Cache set for getAll organizations: ${cacheKey}`
|
|
20164
20157
|
});
|
|
20165
20158
|
}).catch((err) => {
|
|
20166
|
-
|
|
20159
|
+
logger14.log({
|
|
20167
20160
|
level: "error",
|
|
20168
20161
|
message: `Failed to set cache for getAll organizations: ${err.message}`
|
|
20169
20162
|
});
|
|
20170
20163
|
});
|
|
20171
20164
|
return data;
|
|
20172
20165
|
} catch (error) {
|
|
20173
|
-
|
|
20166
|
+
logger14.log({ level: "error", message: `${error}` });
|
|
20174
20167
|
throw error;
|
|
20175
20168
|
}
|
|
20176
20169
|
}
|
|
@@ -20184,7 +20177,7 @@ function useOrgRepo() {
|
|
|
20184
20177
|
try {
|
|
20185
20178
|
const cached = await getCache(cacheKey);
|
|
20186
20179
|
if (cached) {
|
|
20187
|
-
|
|
20180
|
+
logger14.log({
|
|
20188
20181
|
level: "info",
|
|
20189
20182
|
message: `Cache hit for getById organization: ${cacheKey}`
|
|
20190
20183
|
});
|
|
@@ -20194,13 +20187,13 @@ function useOrgRepo() {
|
|
|
20194
20187
|
if (!result) {
|
|
20195
20188
|
throw new BadRequestError22("Organization not found.");
|
|
20196
20189
|
}
|
|
20197
|
-
setCache(cacheKey, result, 300
|
|
20198
|
-
|
|
20190
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
20191
|
+
logger14.log({
|
|
20199
20192
|
level: "info",
|
|
20200
20193
|
message: `Cache set for organization by id: ${cacheKey}`
|
|
20201
20194
|
});
|
|
20202
20195
|
}).catch((err) => {
|
|
20203
|
-
|
|
20196
|
+
logger14.log({
|
|
20204
20197
|
level: "error",
|
|
20205
20198
|
message: `Failed to set cache for organization by id: ${err.message}`
|
|
20206
20199
|
});
|
|
@@ -20219,7 +20212,7 @@ function useOrgRepo() {
|
|
|
20219
20212
|
try {
|
|
20220
20213
|
const cached = await getCache(cacheKey);
|
|
20221
20214
|
if (cached) {
|
|
20222
|
-
|
|
20215
|
+
logger14.log({
|
|
20223
20216
|
level: "info",
|
|
20224
20217
|
message: `Cache hit for getByName organization: ${cacheKey}`
|
|
20225
20218
|
});
|
|
@@ -20229,13 +20222,13 @@ function useOrgRepo() {
|
|
|
20229
20222
|
if (!result) {
|
|
20230
20223
|
throw new BadRequestError22("Organization not found.");
|
|
20231
20224
|
}
|
|
20232
|
-
setCache(cacheKey, result, 300
|
|
20233
|
-
|
|
20225
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
20226
|
+
logger14.log({
|
|
20234
20227
|
level: "info",
|
|
20235
20228
|
message: `Cache set for organization by name: ${cacheKey}`
|
|
20236
20229
|
});
|
|
20237
20230
|
}).catch((err) => {
|
|
20238
|
-
|
|
20231
|
+
logger14.log({
|
|
20239
20232
|
level: "error",
|
|
20240
20233
|
message: `Failed to set cache for organization by name: ${err.message}`
|
|
20241
20234
|
});
|
|
@@ -20308,9 +20301,9 @@ function useOrgRepo() {
|
|
|
20308
20301
|
import {
|
|
20309
20302
|
BadRequestError as BadRequestError24,
|
|
20310
20303
|
useAtlas as useAtlas13,
|
|
20311
|
-
useCache as
|
|
20304
|
+
useCache as useCache12,
|
|
20312
20305
|
makeCacheKey as makeCacheKey11,
|
|
20313
|
-
logger as
|
|
20306
|
+
logger as logger15
|
|
20314
20307
|
} from "@eeplatform/nodejs-utils";
|
|
20315
20308
|
|
|
20316
20309
|
// src/models/address.model.ts
|
|
@@ -20367,15 +20360,15 @@ function useAddressRepo() {
|
|
|
20367
20360
|
}
|
|
20368
20361
|
const namespace_collection = "addresses";
|
|
20369
20362
|
const collection = db.collection(namespace_collection);
|
|
20370
|
-
const { getCache, setCache, delNamespace } =
|
|
20363
|
+
const { getCache, setCache, delNamespace } = useCache12(namespace_collection);
|
|
20371
20364
|
function delCachedData() {
|
|
20372
|
-
delNamespace(
|
|
20373
|
-
|
|
20365
|
+
delNamespace().then(() => {
|
|
20366
|
+
logger15.log({
|
|
20374
20367
|
level: "info",
|
|
20375
20368
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
20376
20369
|
});
|
|
20377
20370
|
}).catch((err) => {
|
|
20378
|
-
|
|
20371
|
+
logger15.log({
|
|
20379
20372
|
level: "error",
|
|
20380
20373
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
20381
20374
|
});
|
|
@@ -20437,7 +20430,7 @@ function useAddressRepo() {
|
|
|
20437
20430
|
try {
|
|
20438
20431
|
const cached = await getCache(cacheKey);
|
|
20439
20432
|
if (cached) {
|
|
20440
|
-
|
|
20433
|
+
logger15.log({
|
|
20441
20434
|
level: "info",
|
|
20442
20435
|
message: `Cache hit for getByUserId address: ${cacheKey}`
|
|
20443
20436
|
});
|
|
@@ -20445,13 +20438,13 @@ function useAddressRepo() {
|
|
|
20445
20438
|
}
|
|
20446
20439
|
const data = await collection.findOne({ user });
|
|
20447
20440
|
if (data) {
|
|
20448
|
-
setCache(cacheKey, data, 300
|
|
20449
|
-
|
|
20441
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
20442
|
+
logger15.log({
|
|
20450
20443
|
level: "info",
|
|
20451
20444
|
message: `Cache set for address by user ID: ${cacheKey}`
|
|
20452
20445
|
});
|
|
20453
20446
|
}).catch((err) => {
|
|
20454
|
-
|
|
20447
|
+
logger15.log({
|
|
20455
20448
|
level: "error",
|
|
20456
20449
|
message: `Failed to set cache for address by user ID: ${err.message}`
|
|
20457
20450
|
});
|
|
@@ -20472,7 +20465,7 @@ function useAddressRepo() {
|
|
|
20472
20465
|
try {
|
|
20473
20466
|
const cached = await getCache(cacheKey);
|
|
20474
20467
|
if (cached) {
|
|
20475
|
-
|
|
20468
|
+
logger15.log({
|
|
20476
20469
|
level: "info",
|
|
20477
20470
|
message: `Cache hit for getByOrgId address: ${cacheKey}`
|
|
20478
20471
|
});
|
|
@@ -20480,13 +20473,13 @@ function useAddressRepo() {
|
|
|
20480
20473
|
}
|
|
20481
20474
|
const data = await collection.findOne({ org });
|
|
20482
20475
|
if (data) {
|
|
20483
|
-
setCache(cacheKey, data, 300
|
|
20484
|
-
|
|
20476
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
20477
|
+
logger15.log({
|
|
20485
20478
|
level: "info",
|
|
20486
20479
|
message: `Cache set for address by org ID: ${cacheKey}`
|
|
20487
20480
|
});
|
|
20488
20481
|
}).catch((err) => {
|
|
20489
|
-
|
|
20482
|
+
logger15.log({
|
|
20490
20483
|
level: "error",
|
|
20491
20484
|
message: `Failed to set cache for address by org ID: ${err.message}`
|
|
20492
20485
|
});
|
|
@@ -20510,11 +20503,11 @@ function useAddressRepo() {
|
|
|
20510
20503
|
import {
|
|
20511
20504
|
BadRequestError as BadRequestError26,
|
|
20512
20505
|
InternalServerError as InternalServerError17,
|
|
20513
|
-
logger as
|
|
20506
|
+
logger as logger16,
|
|
20514
20507
|
makeCacheKey as makeCacheKey12,
|
|
20515
20508
|
paginate as paginate8,
|
|
20516
20509
|
useAtlas as useAtlas14,
|
|
20517
|
-
useCache as
|
|
20510
|
+
useCache as useCache13
|
|
20518
20511
|
} from "@eeplatform/nodejs-utils";
|
|
20519
20512
|
|
|
20520
20513
|
// src/validations/promo-code.schema.ts
|
|
@@ -20574,15 +20567,15 @@ function usePromoCodeRepo() {
|
|
|
20574
20567
|
}
|
|
20575
20568
|
const namespace_collection = "promo-codes";
|
|
20576
20569
|
const collection = db.collection(namespace_collection);
|
|
20577
|
-
const { getCache, setCache, delNamespace } =
|
|
20570
|
+
const { getCache, setCache, delNamespace } = useCache13(namespace_collection);
|
|
20578
20571
|
function delCachedData() {
|
|
20579
|
-
delNamespace(
|
|
20580
|
-
|
|
20572
|
+
delNamespace().then(() => {
|
|
20573
|
+
logger16.log({
|
|
20581
20574
|
level: "info",
|
|
20582
20575
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
20583
20576
|
});
|
|
20584
20577
|
}).catch((err) => {
|
|
20585
|
-
|
|
20578
|
+
logger16.log({
|
|
20586
20579
|
level: "error",
|
|
20587
20580
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
20588
20581
|
});
|
|
@@ -20615,7 +20608,7 @@ function usePromoCodeRepo() {
|
|
|
20615
20608
|
await collection.insertOne(value);
|
|
20616
20609
|
delCachedData();
|
|
20617
20610
|
} catch (error) {
|
|
20618
|
-
|
|
20611
|
+
logger16.log({ level: "error", message: `${error}` });
|
|
20619
20612
|
const isDuplicated = error.message.includes("duplicate");
|
|
20620
20613
|
if (isDuplicated) {
|
|
20621
20614
|
throw new BadRequestError26("Promo code already exists.");
|
|
@@ -20648,7 +20641,7 @@ function usePromoCodeRepo() {
|
|
|
20648
20641
|
try {
|
|
20649
20642
|
const cached = await getCache(cacheKey);
|
|
20650
20643
|
if (cached) {
|
|
20651
|
-
|
|
20644
|
+
logger16.log({
|
|
20652
20645
|
level: "info",
|
|
20653
20646
|
message: `Cache hit for getByCode promo code: ${cacheKey}`
|
|
20654
20647
|
});
|
|
@@ -20656,13 +20649,13 @@ function usePromoCodeRepo() {
|
|
|
20656
20649
|
}
|
|
20657
20650
|
const data = await collection.findOne(query);
|
|
20658
20651
|
if (data) {
|
|
20659
|
-
setCache(cacheKey, data, 300
|
|
20660
|
-
|
|
20652
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
20653
|
+
logger16.log({
|
|
20661
20654
|
level: "info",
|
|
20662
20655
|
message: `Cache set for promo code by code: ${cacheKey}`
|
|
20663
20656
|
});
|
|
20664
20657
|
}).catch((err) => {
|
|
20665
|
-
|
|
20658
|
+
logger16.log({
|
|
20666
20659
|
level: "error",
|
|
20667
20660
|
message: `Failed to set cache for promo code by code: ${err.message}`
|
|
20668
20661
|
});
|
|
@@ -20690,7 +20683,7 @@ function usePromoCodeRepo() {
|
|
|
20690
20683
|
try {
|
|
20691
20684
|
const cached = await getCache(cacheKey);
|
|
20692
20685
|
if (cached) {
|
|
20693
|
-
|
|
20686
|
+
logger16.log({
|
|
20694
20687
|
level: "info",
|
|
20695
20688
|
message: `Cache hit for getById promo code: ${cacheKey}`
|
|
20696
20689
|
});
|
|
@@ -20698,13 +20691,13 @@ function usePromoCodeRepo() {
|
|
|
20698
20691
|
}
|
|
20699
20692
|
const data = await collection.findOne({ _id });
|
|
20700
20693
|
if (data) {
|
|
20701
|
-
setCache(cacheKey, data, 300
|
|
20702
|
-
|
|
20694
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
20695
|
+
logger16.log({
|
|
20703
20696
|
level: "info",
|
|
20704
20697
|
message: `Cache set for promo code by ID: ${cacheKey}`
|
|
20705
20698
|
});
|
|
20706
20699
|
}).catch((err) => {
|
|
20707
|
-
|
|
20700
|
+
logger16.log({
|
|
20708
20701
|
level: "error",
|
|
20709
20702
|
message: `Failed to set cache for promo code by ID: ${err.message}`
|
|
20710
20703
|
});
|
|
@@ -20743,7 +20736,7 @@ function usePromoCodeRepo() {
|
|
|
20743
20736
|
try {
|
|
20744
20737
|
const cached = await getCache(cacheKey);
|
|
20745
20738
|
if (cached) {
|
|
20746
|
-
|
|
20739
|
+
logger16.log({
|
|
20747
20740
|
level: "info",
|
|
20748
20741
|
message: `Cache hit for getPromoCodes: ${cacheKey}`
|
|
20749
20742
|
});
|
|
@@ -20757,20 +20750,20 @@ function usePromoCodeRepo() {
|
|
|
20757
20750
|
]).toArray();
|
|
20758
20751
|
const length = await collection.countDocuments(query);
|
|
20759
20752
|
const data = paginate8(items, page, limit, length);
|
|
20760
|
-
setCache(cacheKey, data, 600
|
|
20761
|
-
|
|
20753
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
20754
|
+
logger16.log({
|
|
20762
20755
|
level: "info",
|
|
20763
20756
|
message: `Cache set for getPromoCodes: ${cacheKey}`
|
|
20764
20757
|
});
|
|
20765
20758
|
}).catch((err) => {
|
|
20766
|
-
|
|
20759
|
+
logger16.log({
|
|
20767
20760
|
level: "error",
|
|
20768
20761
|
message: `Failed to set cache for getPromoCodes: ${err.message}`
|
|
20769
20762
|
});
|
|
20770
20763
|
});
|
|
20771
20764
|
return data;
|
|
20772
20765
|
} catch (error) {
|
|
20773
|
-
|
|
20766
|
+
logger16.log({ level: "error", message: `${error}` });
|
|
20774
20767
|
throw new InternalServerError17("Internal server error.");
|
|
20775
20768
|
}
|
|
20776
20769
|
}
|
|
@@ -20817,7 +20810,7 @@ import Joi15 from "joi";
|
|
|
20817
20810
|
import {
|
|
20818
20811
|
BadRequestError as BadRequestError28,
|
|
20819
20812
|
InternalServerError as InternalServerError18,
|
|
20820
|
-
logger as
|
|
20813
|
+
logger as logger17,
|
|
20821
20814
|
paginate as paginate9,
|
|
20822
20815
|
useAtlas as useAtlas15
|
|
20823
20816
|
} from "@eeplatform/nodejs-utils";
|
|
@@ -20952,7 +20945,7 @@ function useInvoiceRepo() {
|
|
|
20952
20945
|
value = createInvoice(value);
|
|
20953
20946
|
await collection.insertOne(value, { session });
|
|
20954
20947
|
} catch (error) {
|
|
20955
|
-
|
|
20948
|
+
logger17.log({ level: "error", message: `${error}` });
|
|
20956
20949
|
const isDuplicated = error.message.includes("duplicate");
|
|
20957
20950
|
if (isDuplicated) {
|
|
20958
20951
|
throw new BadRequestError28("Invoice already exists.");
|
|
@@ -21087,9 +21080,9 @@ function useInvoiceRepo() {
|
|
|
21087
21080
|
// src/repositories/counter.repository.ts
|
|
21088
21081
|
import {
|
|
21089
21082
|
useAtlas as useAtlas16,
|
|
21090
|
-
useCache as
|
|
21083
|
+
useCache as useCache14,
|
|
21091
21084
|
makeCacheKey as makeCacheKey13,
|
|
21092
|
-
logger as
|
|
21085
|
+
logger as logger18
|
|
21093
21086
|
} from "@eeplatform/nodejs-utils";
|
|
21094
21087
|
|
|
21095
21088
|
// src/models/counter.model.ts
|
|
@@ -21134,15 +21127,15 @@ function useCounterRepo() {
|
|
|
21134
21127
|
}
|
|
21135
21128
|
const namespace_collection = "counters";
|
|
21136
21129
|
const { collection, createCounter } = useCounterModel(db);
|
|
21137
|
-
const { getCache, setCache, delNamespace } =
|
|
21130
|
+
const { getCache, setCache, delNamespace } = useCache14(namespace_collection);
|
|
21138
21131
|
function delCachedData() {
|
|
21139
|
-
delNamespace(
|
|
21140
|
-
|
|
21132
|
+
delNamespace().then(() => {
|
|
21133
|
+
logger18.log({
|
|
21141
21134
|
level: "info",
|
|
21142
21135
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
21143
21136
|
});
|
|
21144
21137
|
}).catch((err) => {
|
|
21145
|
-
|
|
21138
|
+
logger18.log({
|
|
21146
21139
|
level: "error",
|
|
21147
21140
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
21148
21141
|
});
|
|
@@ -21198,7 +21191,7 @@ function useCounterRepo() {
|
|
|
21198
21191
|
try {
|
|
21199
21192
|
const cached = await getCache(cacheKey);
|
|
21200
21193
|
if (cached) {
|
|
21201
|
-
|
|
21194
|
+
logger18.log({
|
|
21202
21195
|
level: "info",
|
|
21203
21196
|
message: `Cache hit for getByType counter: ${cacheKey}`
|
|
21204
21197
|
});
|
|
@@ -21206,13 +21199,13 @@ function useCounterRepo() {
|
|
|
21206
21199
|
}
|
|
21207
21200
|
const data = await collection.findOne({ type });
|
|
21208
21201
|
if (data) {
|
|
21209
|
-
setCache(cacheKey, data, 300
|
|
21210
|
-
|
|
21202
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
21203
|
+
logger18.log({
|
|
21211
21204
|
level: "info",
|
|
21212
21205
|
message: `Cache set for counter by type: ${cacheKey}`
|
|
21213
21206
|
});
|
|
21214
21207
|
}).catch((err) => {
|
|
21215
|
-
|
|
21208
|
+
logger18.log({
|
|
21216
21209
|
level: "error",
|
|
21217
21210
|
message: `Failed to set cache for counter by type: ${err.message}`
|
|
21218
21211
|
});
|
|
@@ -21236,7 +21229,7 @@ function useCounterRepo() {
|
|
|
21236
21229
|
import {
|
|
21237
21230
|
BadRequestError as BadRequestError30,
|
|
21238
21231
|
InternalServerError as InternalServerError19,
|
|
21239
|
-
logger as
|
|
21232
|
+
logger as logger19,
|
|
21240
21233
|
paginate as paginate10,
|
|
21241
21234
|
useAtlas as useAtlas17
|
|
21242
21235
|
} from "@eeplatform/nodejs-utils";
|
|
@@ -21281,7 +21274,7 @@ function usePaymentRepo() {
|
|
|
21281
21274
|
value = createPayment(value);
|
|
21282
21275
|
await collection.insertOne(value, { session });
|
|
21283
21276
|
} catch (error) {
|
|
21284
|
-
|
|
21277
|
+
logger19.log({ level: "error", message: `${error}` });
|
|
21285
21278
|
const isDuplicated = error.message.includes("duplicate");
|
|
21286
21279
|
if (isDuplicated) {
|
|
21287
21280
|
throw new BadRequestError30("Payment already exists.");
|
|
@@ -21326,7 +21319,7 @@ function usePaymentRepo() {
|
|
|
21326
21319
|
const length = await collection.countDocuments(query);
|
|
21327
21320
|
return paginate10(items, page, limit, length);
|
|
21328
21321
|
} catch (error) {
|
|
21329
|
-
|
|
21322
|
+
logger19.log({ level: "error", message: `${error}` });
|
|
21330
21323
|
throw new InternalServerError19("Internal server error.");
|
|
21331
21324
|
}
|
|
21332
21325
|
}
|
|
@@ -21354,9 +21347,9 @@ function usePaymentRepo() {
|
|
|
21354
21347
|
// src/repositories/price.repository.ts
|
|
21355
21348
|
import {
|
|
21356
21349
|
useAtlas as useAtlas18,
|
|
21357
|
-
useCache as
|
|
21350
|
+
useCache as useCache15,
|
|
21358
21351
|
makeCacheKey as makeCacheKey14,
|
|
21359
|
-
logger as
|
|
21352
|
+
logger as logger20
|
|
21360
21353
|
} from "@eeplatform/nodejs-utils";
|
|
21361
21354
|
|
|
21362
21355
|
// src/models/price.model.ts
|
|
@@ -21410,15 +21403,15 @@ function usePriceRepo() {
|
|
|
21410
21403
|
}
|
|
21411
21404
|
const namespace_collection = "prices";
|
|
21412
21405
|
const { collection, createPrice } = usePriceModel(db);
|
|
21413
|
-
const { getCache, setCache, delNamespace } =
|
|
21406
|
+
const { getCache, setCache, delNamespace } = useCache15(namespace_collection);
|
|
21414
21407
|
function delCachedData() {
|
|
21415
|
-
delNamespace(
|
|
21416
|
-
|
|
21408
|
+
delNamespace().then(() => {
|
|
21409
|
+
logger20.log({
|
|
21417
21410
|
level: "info",
|
|
21418
21411
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
21419
21412
|
});
|
|
21420
21413
|
}).catch((err) => {
|
|
21421
|
-
|
|
21414
|
+
logger20.log({
|
|
21422
21415
|
level: "error",
|
|
21423
21416
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
21424
21417
|
});
|
|
@@ -21474,7 +21467,7 @@ function usePriceRepo() {
|
|
|
21474
21467
|
try {
|
|
21475
21468
|
const cached = await getCache(cacheKey);
|
|
21476
21469
|
if (cached) {
|
|
21477
|
-
|
|
21470
|
+
logger20.log({
|
|
21478
21471
|
level: "info",
|
|
21479
21472
|
message: `Cache hit for getByNameType price: ${cacheKey}`
|
|
21480
21473
|
});
|
|
@@ -21482,13 +21475,13 @@ function usePriceRepo() {
|
|
|
21482
21475
|
}
|
|
21483
21476
|
const data = await collection.findOne({ name, type });
|
|
21484
21477
|
if (data) {
|
|
21485
|
-
setCache(cacheKey, data, 300
|
|
21486
|
-
|
|
21478
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
21479
|
+
logger20.log({
|
|
21487
21480
|
level: "info",
|
|
21488
21481
|
message: `Cache set for price by name and type: ${cacheKey}`
|
|
21489
21482
|
});
|
|
21490
21483
|
}).catch((err) => {
|
|
21491
|
-
|
|
21484
|
+
logger20.log({
|
|
21492
21485
|
level: "error",
|
|
21493
21486
|
message: `Failed to set cache for price by name and type: ${err.message}`
|
|
21494
21487
|
});
|
|
@@ -22260,7 +22253,7 @@ function useSubscriptionService() {
|
|
|
22260
22253
|
while (true) {
|
|
22261
22254
|
const subscriptions = await getDueSubscriptions(batchSize);
|
|
22262
22255
|
if (subscriptions.length === 0) {
|
|
22263
|
-
|
|
22256
|
+
logger21.log({
|
|
22264
22257
|
level: "info",
|
|
22265
22258
|
message: "No more subscriptions to process."
|
|
22266
22259
|
});
|
|
@@ -22400,14 +22393,14 @@ function useSubscriptionService() {
|
|
|
22400
22393
|
);
|
|
22401
22394
|
await session?.commitTransaction();
|
|
22402
22395
|
}
|
|
22403
|
-
|
|
22396
|
+
logger21.log({
|
|
22404
22397
|
level: "info",
|
|
22405
22398
|
message: `Processed subscription ${sub._id} successfully.`
|
|
22406
22399
|
});
|
|
22407
22400
|
return;
|
|
22408
22401
|
} catch (error) {
|
|
22409
22402
|
await session?.abortTransaction();
|
|
22410
|
-
|
|
22403
|
+
logger21.log({
|
|
22411
22404
|
level: "error",
|
|
22412
22405
|
message: `Failed to process ${sub._id}: ${error}`
|
|
22413
22406
|
});
|
|
@@ -22419,7 +22412,7 @@ function useSubscriptionService() {
|
|
|
22419
22412
|
}
|
|
22420
22413
|
})
|
|
22421
22414
|
);
|
|
22422
|
-
|
|
22415
|
+
logger21.log({
|
|
22423
22416
|
level: "info",
|
|
22424
22417
|
message: "Processed a batch of subscriptions."
|
|
22425
22418
|
});
|
|
@@ -22716,7 +22709,7 @@ function useSubscriptionService() {
|
|
|
22716
22709
|
await session?.commitTransaction();
|
|
22717
22710
|
} catch (error2) {
|
|
22718
22711
|
await session?.abortTransaction();
|
|
22719
|
-
|
|
22712
|
+
logger21.log({
|
|
22720
22713
|
level: "error",
|
|
22721
22714
|
message: `Failed to update subscription seats: ${error2}`
|
|
22722
22715
|
});
|
|
@@ -22917,7 +22910,7 @@ function useSubscriptionService() {
|
|
|
22917
22910
|
await session?.commitTransaction();
|
|
22918
22911
|
} catch (error2) {
|
|
22919
22912
|
await session?.abortTransaction();
|
|
22920
|
-
|
|
22913
|
+
logger21.log({
|
|
22921
22914
|
level: "error",
|
|
22922
22915
|
message: `Failed to update subscription seats: ${error2}`
|
|
22923
22916
|
});
|
|
@@ -23018,7 +23011,7 @@ function useSubscriptionService() {
|
|
|
23018
23011
|
await session?.commitTransaction();
|
|
23019
23012
|
} catch (error) {
|
|
23020
23013
|
await session?.abortTransaction();
|
|
23021
|
-
|
|
23014
|
+
logger21.log({
|
|
23022
23015
|
level: "error",
|
|
23023
23016
|
message: `Failed to process subscription payment: ${error}`
|
|
23024
23017
|
});
|
|
@@ -23521,7 +23514,7 @@ function MPaymentMethod(value) {
|
|
|
23521
23514
|
import {
|
|
23522
23515
|
BadRequestError as BadRequestError36,
|
|
23523
23516
|
InternalServerError as InternalServerError20,
|
|
23524
|
-
logger as
|
|
23517
|
+
logger as logger22,
|
|
23525
23518
|
useAtlas as useAtlas20
|
|
23526
23519
|
} from "@eeplatform/nodejs-utils";
|
|
23527
23520
|
import { ObjectId as ObjectId30 } from "mongodb";
|
|
@@ -23567,7 +23560,7 @@ function usePaymentMethodRepo() {
|
|
|
23567
23560
|
await collection.insertOne(value, { session });
|
|
23568
23561
|
return "Successfully added payment method.";
|
|
23569
23562
|
} catch (error) {
|
|
23570
|
-
|
|
23563
|
+
logger22.log({ level: "error", message: `${error}` });
|
|
23571
23564
|
const isDuplicated = error.message.includes("duplicate");
|
|
23572
23565
|
if (isDuplicated) {
|
|
23573
23566
|
throw new BadRequestError36("Payment method already exist.");
|
|
@@ -24740,11 +24733,11 @@ import {
|
|
|
24740
24733
|
AppError as AppError11,
|
|
24741
24734
|
BadRequestError as BadRequestError44,
|
|
24742
24735
|
InternalServerError as InternalServerError22,
|
|
24743
|
-
logger as
|
|
24736
|
+
logger as logger23,
|
|
24744
24737
|
makeCacheKey as makeCacheKey15,
|
|
24745
24738
|
paginate as paginate11,
|
|
24746
24739
|
useAtlas as useAtlas23,
|
|
24747
|
-
useCache as
|
|
24740
|
+
useCache as useCache16
|
|
24748
24741
|
} from "@eeplatform/nodejs-utils";
|
|
24749
24742
|
import { ObjectId as ObjectId32 } from "mongodb";
|
|
24750
24743
|
function useOrderRepo() {
|
|
@@ -24754,15 +24747,15 @@ function useOrderRepo() {
|
|
|
24754
24747
|
}
|
|
24755
24748
|
const namespace_collection = "orders";
|
|
24756
24749
|
const collection = db.collection(namespace_collection);
|
|
24757
|
-
const { getCache, setCache, delNamespace } =
|
|
24750
|
+
const { getCache, setCache, delNamespace } = useCache16(namespace_collection);
|
|
24758
24751
|
function delCachedData() {
|
|
24759
|
-
delNamespace(
|
|
24760
|
-
|
|
24752
|
+
delNamespace().then(() => {
|
|
24753
|
+
logger23.log({
|
|
24761
24754
|
level: "info",
|
|
24762
24755
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
24763
24756
|
});
|
|
24764
24757
|
}).catch((err) => {
|
|
24765
|
-
|
|
24758
|
+
logger23.log({
|
|
24766
24759
|
level: "error",
|
|
24767
24760
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
24768
24761
|
});
|
|
@@ -24785,7 +24778,7 @@ function useOrderRepo() {
|
|
|
24785
24778
|
collection.insertOne(value, { session });
|
|
24786
24779
|
delCachedData();
|
|
24787
24780
|
} catch (error) {
|
|
24788
|
-
|
|
24781
|
+
logger23.log({ level: "error", message: `${error}` });
|
|
24789
24782
|
if (error instanceof AppError11) {
|
|
24790
24783
|
throw error;
|
|
24791
24784
|
}
|
|
@@ -24829,7 +24822,7 @@ function useOrderRepo() {
|
|
|
24829
24822
|
try {
|
|
24830
24823
|
const cached = await getCache(cacheKey);
|
|
24831
24824
|
if (cached) {
|
|
24832
|
-
|
|
24825
|
+
logger23.log({
|
|
24833
24826
|
level: "info",
|
|
24834
24827
|
message: `Cache hit for getOrders: ${cacheKey}`
|
|
24835
24828
|
});
|
|
@@ -24843,20 +24836,20 @@ function useOrderRepo() {
|
|
|
24843
24836
|
]).toArray();
|
|
24844
24837
|
const length = await collection.countDocuments(query);
|
|
24845
24838
|
const data = paginate11(items, page, limit, length);
|
|
24846
|
-
setCache(cacheKey, data, 600
|
|
24847
|
-
|
|
24839
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
24840
|
+
logger23.log({
|
|
24848
24841
|
level: "info",
|
|
24849
24842
|
message: `Cache set for getOrders: ${cacheKey}`
|
|
24850
24843
|
});
|
|
24851
24844
|
}).catch((err) => {
|
|
24852
|
-
|
|
24845
|
+
logger23.log({
|
|
24853
24846
|
level: "error",
|
|
24854
24847
|
message: `Failed to set cache for getOrders: ${err.message}`
|
|
24855
24848
|
});
|
|
24856
24849
|
});
|
|
24857
24850
|
return data;
|
|
24858
24851
|
} catch (error) {
|
|
24859
|
-
|
|
24852
|
+
logger23.log({ level: "error", message: `${error}` });
|
|
24860
24853
|
throw new InternalServerError22("Internal server error.");
|
|
24861
24854
|
}
|
|
24862
24855
|
}
|
|
@@ -24912,7 +24905,7 @@ function useOrderController() {
|
|
|
24912
24905
|
// src/services/invoice.service.ts
|
|
24913
24906
|
import {
|
|
24914
24907
|
BadRequestError as BadRequestError46,
|
|
24915
|
-
logger as
|
|
24908
|
+
logger as logger24,
|
|
24916
24909
|
NotFoundError as NotFoundError7,
|
|
24917
24910
|
useAtlas as useAtlas24
|
|
24918
24911
|
} from "@eeplatform/nodejs-utils";
|
|
@@ -24934,7 +24927,7 @@ function useInvoiceService() {
|
|
|
24934
24927
|
while (true) {
|
|
24935
24928
|
const overdueInvoices = await getOverdueInvoices(BATCH_SIZE);
|
|
24936
24929
|
if (!overdueInvoices.length) {
|
|
24937
|
-
|
|
24930
|
+
logger24.log({
|
|
24938
24931
|
level: "info",
|
|
24939
24932
|
message: "No overdue invoices found."
|
|
24940
24933
|
});
|
|
@@ -24944,21 +24937,21 @@ function useInvoiceService() {
|
|
|
24944
24937
|
overdueInvoices.map(async (invoice) => {
|
|
24945
24938
|
const session = useAtlas24.getClient()?.startSession();
|
|
24946
24939
|
if (!session) {
|
|
24947
|
-
|
|
24940
|
+
logger24.log({
|
|
24948
24941
|
level: "error",
|
|
24949
24942
|
message: "Failed to start session."
|
|
24950
24943
|
});
|
|
24951
24944
|
return;
|
|
24952
24945
|
}
|
|
24953
24946
|
if (!invoice._id) {
|
|
24954
|
-
|
|
24947
|
+
logger24.log({
|
|
24955
24948
|
level: "error",
|
|
24956
24949
|
message: "Invoice ID is missing."
|
|
24957
24950
|
});
|
|
24958
24951
|
return;
|
|
24959
24952
|
}
|
|
24960
24953
|
if (!invoice.metadata?.subscriptionId) {
|
|
24961
|
-
|
|
24954
|
+
logger24.log({
|
|
24962
24955
|
level: "error",
|
|
24963
24956
|
message: "Subscription ID is missing."
|
|
24964
24957
|
});
|
|
@@ -24968,14 +24961,14 @@ function useInvoiceService() {
|
|
|
24968
24961
|
invoice.metadata.subscriptionId
|
|
24969
24962
|
).catch(() => null);
|
|
24970
24963
|
if (!subscription) {
|
|
24971
|
-
|
|
24964
|
+
logger24.log({
|
|
24972
24965
|
level: "error",
|
|
24973
24966
|
message: "Subscription not found."
|
|
24974
24967
|
});
|
|
24975
24968
|
return;
|
|
24976
24969
|
}
|
|
24977
24970
|
if (!subscription._id) {
|
|
24978
|
-
|
|
24971
|
+
logger24.log({
|
|
24979
24972
|
level: "error",
|
|
24980
24973
|
message: "Subscription ID is missing."
|
|
24981
24974
|
});
|
|
@@ -25055,7 +25048,7 @@ function useInvoiceService() {
|
|
|
25055
25048
|
return;
|
|
25056
25049
|
}
|
|
25057
25050
|
} catch (error) {
|
|
25058
|
-
|
|
25051
|
+
logger24.log({
|
|
25059
25052
|
level: "error",
|
|
25060
25053
|
message: String(error)
|
|
25061
25054
|
});
|
|
@@ -25065,7 +25058,7 @@ function useInvoiceService() {
|
|
|
25065
25058
|
}
|
|
25066
25059
|
})
|
|
25067
25060
|
);
|
|
25068
|
-
|
|
25061
|
+
logger24.log({
|
|
25069
25062
|
level: "info",
|
|
25070
25063
|
message: "Successfully processed overdue invoices."
|
|
25071
25064
|
});
|
|
@@ -25077,7 +25070,7 @@ function useInvoiceService() {
|
|
|
25077
25070
|
}
|
|
25078
25071
|
const session = useAtlas24.getClient()?.startSession();
|
|
25079
25072
|
if (!session) {
|
|
25080
|
-
|
|
25073
|
+
logger24.log({
|
|
25081
25074
|
level: "error",
|
|
25082
25075
|
message: "Failed to start session."
|
|
25083
25076
|
});
|
|
@@ -25146,7 +25139,7 @@ function useInvoiceService() {
|
|
|
25146
25139
|
return "Payment processed successfully.";
|
|
25147
25140
|
} catch (error) {
|
|
25148
25141
|
session.abortTransaction();
|
|
25149
|
-
|
|
25142
|
+
logger24.log({
|
|
25150
25143
|
level: "error",
|
|
25151
25144
|
message: String(error)
|
|
25152
25145
|
});
|
|
@@ -25393,11 +25386,11 @@ import {
|
|
|
25393
25386
|
AppError as AppError12,
|
|
25394
25387
|
BadRequestError as BadRequestError51,
|
|
25395
25388
|
InternalServerError as InternalServerError23,
|
|
25396
|
-
logger as
|
|
25389
|
+
logger as logger25,
|
|
25397
25390
|
makeCacheKey as makeCacheKey16,
|
|
25398
25391
|
paginate as paginate12,
|
|
25399
25392
|
useAtlas as useAtlas25,
|
|
25400
|
-
useCache as
|
|
25393
|
+
useCache as useCache17
|
|
25401
25394
|
} from "@eeplatform/nodejs-utils";
|
|
25402
25395
|
import { ObjectId as ObjectId34 } from "mongodb";
|
|
25403
25396
|
function useRegionRepo() {
|
|
@@ -25407,7 +25400,7 @@ function useRegionRepo() {
|
|
|
25407
25400
|
}
|
|
25408
25401
|
const namespace_collection = "regions";
|
|
25409
25402
|
const collection = db.collection(namespace_collection);
|
|
25410
|
-
const { getCache, setCache, delNamespace } =
|
|
25403
|
+
const { getCache, setCache, delNamespace } = useCache17(namespace_collection);
|
|
25411
25404
|
async function createIndex() {
|
|
25412
25405
|
try {
|
|
25413
25406
|
await collection.createIndex([
|
|
@@ -25444,13 +25437,13 @@ function useRegionRepo() {
|
|
|
25444
25437
|
}
|
|
25445
25438
|
}
|
|
25446
25439
|
function delCachedData() {
|
|
25447
|
-
delNamespace(
|
|
25448
|
-
|
|
25440
|
+
delNamespace().then(() => {
|
|
25441
|
+
logger25.log({
|
|
25449
25442
|
level: "info",
|
|
25450
25443
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
25451
25444
|
});
|
|
25452
25445
|
}).catch((err) => {
|
|
25453
|
-
|
|
25446
|
+
logger25.log({
|
|
25454
25447
|
level: "error",
|
|
25455
25448
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
25456
25449
|
});
|
|
@@ -25463,7 +25456,7 @@ function useRegionRepo() {
|
|
|
25463
25456
|
delCachedData();
|
|
25464
25457
|
return res.insertedId;
|
|
25465
25458
|
} catch (error) {
|
|
25466
|
-
|
|
25459
|
+
logger25.log({
|
|
25467
25460
|
level: "error",
|
|
25468
25461
|
message: error.message
|
|
25469
25462
|
});
|
|
@@ -25491,14 +25484,14 @@ function useRegionRepo() {
|
|
|
25491
25484
|
limit,
|
|
25492
25485
|
sort: JSON.stringify(sort)
|
|
25493
25486
|
});
|
|
25494
|
-
|
|
25487
|
+
logger25.log({
|
|
25495
25488
|
level: "info",
|
|
25496
25489
|
message: `Cache key for getAll regions: ${cacheKey}`
|
|
25497
25490
|
});
|
|
25498
25491
|
try {
|
|
25499
25492
|
const cached = await getCache(cacheKey);
|
|
25500
25493
|
if (cached) {
|
|
25501
|
-
|
|
25494
|
+
logger25.log({
|
|
25502
25495
|
level: "info",
|
|
25503
25496
|
message: `Cache hit for getAll regions: ${cacheKey}`
|
|
25504
25497
|
});
|
|
@@ -25522,20 +25515,20 @@ function useRegionRepo() {
|
|
|
25522
25515
|
]).toArray();
|
|
25523
25516
|
const length = await collection.countDocuments(query);
|
|
25524
25517
|
const data = paginate12(items, page, limit, length);
|
|
25525
|
-
setCache(cacheKey, data, 600
|
|
25526
|
-
|
|
25518
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
25519
|
+
logger25.log({
|
|
25527
25520
|
level: "info",
|
|
25528
25521
|
message: `Cache set for getAll regions: ${cacheKey}`
|
|
25529
25522
|
});
|
|
25530
25523
|
}).catch((err) => {
|
|
25531
|
-
|
|
25524
|
+
logger25.log({
|
|
25532
25525
|
level: "error",
|
|
25533
25526
|
message: `Failed to set cache for getAll regions: ${err.message}`
|
|
25534
25527
|
});
|
|
25535
25528
|
});
|
|
25536
25529
|
return data;
|
|
25537
25530
|
} catch (error) {
|
|
25538
|
-
|
|
25531
|
+
logger25.log({ level: "error", message: `${error}` });
|
|
25539
25532
|
throw error;
|
|
25540
25533
|
}
|
|
25541
25534
|
}
|
|
@@ -25549,7 +25542,7 @@ function useRegionRepo() {
|
|
|
25549
25542
|
try {
|
|
25550
25543
|
const cached = await getCache(cacheKey);
|
|
25551
25544
|
if (cached) {
|
|
25552
|
-
|
|
25545
|
+
logger25.log({
|
|
25553
25546
|
level: "info",
|
|
25554
25547
|
message: `Cache hit for getById region: ${cacheKey}`
|
|
25555
25548
|
});
|
|
@@ -25562,13 +25555,13 @@ function useRegionRepo() {
|
|
|
25562
25555
|
if (!result) {
|
|
25563
25556
|
throw new BadRequestError51("Region not found.");
|
|
25564
25557
|
}
|
|
25565
|
-
setCache(cacheKey, result, 300
|
|
25566
|
-
|
|
25558
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
25559
|
+
logger25.log({
|
|
25567
25560
|
level: "info",
|
|
25568
25561
|
message: `Cache set for region by id: ${cacheKey}`
|
|
25569
25562
|
});
|
|
25570
25563
|
}).catch((err) => {
|
|
25571
|
-
|
|
25564
|
+
logger25.log({
|
|
25572
25565
|
level: "error",
|
|
25573
25566
|
message: `Failed to set cache for region by id: ${err.message}`
|
|
25574
25567
|
});
|
|
@@ -25587,7 +25580,7 @@ function useRegionRepo() {
|
|
|
25587
25580
|
try {
|
|
25588
25581
|
const cached = await getCache(cacheKey);
|
|
25589
25582
|
if (cached) {
|
|
25590
|
-
|
|
25583
|
+
logger25.log({
|
|
25591
25584
|
level: "info",
|
|
25592
25585
|
message: `Cache hit for getByName region: ${cacheKey}`
|
|
25593
25586
|
});
|
|
@@ -25600,13 +25593,13 @@ function useRegionRepo() {
|
|
|
25600
25593
|
if (!result) {
|
|
25601
25594
|
throw new BadRequestError51("Region not found.");
|
|
25602
25595
|
}
|
|
25603
|
-
setCache(cacheKey, result, 300
|
|
25604
|
-
|
|
25596
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
25597
|
+
logger25.log({
|
|
25605
25598
|
level: "info",
|
|
25606
25599
|
message: `Cache set for region by name: ${cacheKey}`
|
|
25607
25600
|
});
|
|
25608
25601
|
}).catch((err) => {
|
|
25609
|
-
|
|
25602
|
+
logger25.log({
|
|
25610
25603
|
level: "error",
|
|
25611
25604
|
message: `Failed to set cache for region by name: ${err.message}`
|
|
25612
25605
|
});
|
|
@@ -25932,11 +25925,11 @@ import {
|
|
|
25932
25925
|
AppError as AppError13,
|
|
25933
25926
|
BadRequestError as BadRequestError54,
|
|
25934
25927
|
InternalServerError as InternalServerError24,
|
|
25935
|
-
logger as
|
|
25928
|
+
logger as logger26,
|
|
25936
25929
|
makeCacheKey as makeCacheKey17,
|
|
25937
25930
|
paginate as paginate13,
|
|
25938
25931
|
useAtlas as useAtlas27,
|
|
25939
|
-
useCache as
|
|
25932
|
+
useCache as useCache18
|
|
25940
25933
|
} from "@eeplatform/nodejs-utils";
|
|
25941
25934
|
import { ObjectId as ObjectId36 } from "mongodb";
|
|
25942
25935
|
function useDivisionRepo() {
|
|
@@ -25946,7 +25939,7 @@ function useDivisionRepo() {
|
|
|
25946
25939
|
}
|
|
25947
25940
|
const namespace_collection = "divisions";
|
|
25948
25941
|
const collection = db.collection(namespace_collection);
|
|
25949
|
-
const { getCache, setCache, delNamespace } =
|
|
25942
|
+
const { getCache, setCache, delNamespace } = useCache18(namespace_collection);
|
|
25950
25943
|
async function createIndex() {
|
|
25951
25944
|
try {
|
|
25952
25945
|
await collection.createIndex([
|
|
@@ -25985,13 +25978,13 @@ function useDivisionRepo() {
|
|
|
25985
25978
|
}
|
|
25986
25979
|
}
|
|
25987
25980
|
function delCachedData() {
|
|
25988
|
-
delNamespace(
|
|
25989
|
-
|
|
25981
|
+
delNamespace().then(() => {
|
|
25982
|
+
logger26.log({
|
|
25990
25983
|
level: "info",
|
|
25991
25984
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
25992
25985
|
});
|
|
25993
25986
|
}).catch((err) => {
|
|
25994
|
-
|
|
25987
|
+
logger26.log({
|
|
25995
25988
|
level: "error",
|
|
25996
25989
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
25997
25990
|
});
|
|
@@ -26004,7 +25997,7 @@ function useDivisionRepo() {
|
|
|
26004
25997
|
delCachedData();
|
|
26005
25998
|
return res.insertedId;
|
|
26006
25999
|
} catch (error) {
|
|
26007
|
-
|
|
26000
|
+
logger26.log({
|
|
26008
26001
|
level: "error",
|
|
26009
26002
|
message: error.message
|
|
26010
26003
|
});
|
|
@@ -26046,14 +26039,14 @@ function useDivisionRepo() {
|
|
|
26046
26039
|
sort: JSON.stringify(sort),
|
|
26047
26040
|
region
|
|
26048
26041
|
});
|
|
26049
|
-
|
|
26042
|
+
logger26.log({
|
|
26050
26043
|
level: "info",
|
|
26051
26044
|
message: `Cache key for getAll divisions: ${cacheKey}`
|
|
26052
26045
|
});
|
|
26053
26046
|
try {
|
|
26054
26047
|
const cached = await getCache(cacheKey);
|
|
26055
26048
|
if (cached) {
|
|
26056
|
-
|
|
26049
|
+
logger26.log({
|
|
26057
26050
|
level: "info",
|
|
26058
26051
|
message: `Cache hit for getAll divisions: ${cacheKey}`
|
|
26059
26052
|
});
|
|
@@ -26079,20 +26072,20 @@ function useDivisionRepo() {
|
|
|
26079
26072
|
]).toArray();
|
|
26080
26073
|
const length = await collection.countDocuments(query);
|
|
26081
26074
|
const data = paginate13(items, page, limit, length);
|
|
26082
|
-
setCache(cacheKey, data, 600
|
|
26083
|
-
|
|
26075
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
26076
|
+
logger26.log({
|
|
26084
26077
|
level: "info",
|
|
26085
26078
|
message: `Cache set for getAll divisions: ${cacheKey}`
|
|
26086
26079
|
});
|
|
26087
26080
|
}).catch((err) => {
|
|
26088
|
-
|
|
26081
|
+
logger26.log({
|
|
26089
26082
|
level: "error",
|
|
26090
26083
|
message: `Failed to set cache for getAll divisions: ${err.message}`
|
|
26091
26084
|
});
|
|
26092
26085
|
});
|
|
26093
26086
|
return data;
|
|
26094
26087
|
} catch (error) {
|
|
26095
|
-
|
|
26088
|
+
logger26.log({ level: "error", message: `${error}` });
|
|
26096
26089
|
throw error;
|
|
26097
26090
|
}
|
|
26098
26091
|
}
|
|
@@ -26106,7 +26099,7 @@ function useDivisionRepo() {
|
|
|
26106
26099
|
try {
|
|
26107
26100
|
const cached = await getCache(cacheKey);
|
|
26108
26101
|
if (cached) {
|
|
26109
|
-
|
|
26102
|
+
logger26.log({
|
|
26110
26103
|
level: "info",
|
|
26111
26104
|
message: `Cache hit for getById division: ${cacheKey}`
|
|
26112
26105
|
});
|
|
@@ -26119,13 +26112,13 @@ function useDivisionRepo() {
|
|
|
26119
26112
|
if (!result) {
|
|
26120
26113
|
throw new BadRequestError54("Division not found.");
|
|
26121
26114
|
}
|
|
26122
|
-
setCache(cacheKey, result, 300
|
|
26123
|
-
|
|
26115
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
26116
|
+
logger26.log({
|
|
26124
26117
|
level: "info",
|
|
26125
26118
|
message: `Cache set for division by id: ${cacheKey}`
|
|
26126
26119
|
});
|
|
26127
26120
|
}).catch((err) => {
|
|
26128
|
-
|
|
26121
|
+
logger26.log({
|
|
26129
26122
|
level: "error",
|
|
26130
26123
|
message: `Failed to set cache for division by id: ${err.message}`
|
|
26131
26124
|
});
|
|
@@ -26144,7 +26137,7 @@ function useDivisionRepo() {
|
|
|
26144
26137
|
try {
|
|
26145
26138
|
const cached = await getCache(cacheKey);
|
|
26146
26139
|
if (cached) {
|
|
26147
|
-
|
|
26140
|
+
logger26.log({
|
|
26148
26141
|
level: "info",
|
|
26149
26142
|
message: `Cache hit for getByName division: ${cacheKey}`
|
|
26150
26143
|
});
|
|
@@ -26157,13 +26150,13 @@ function useDivisionRepo() {
|
|
|
26157
26150
|
if (!result) {
|
|
26158
26151
|
throw new BadRequestError54("Division not found.");
|
|
26159
26152
|
}
|
|
26160
|
-
setCache(cacheKey, result, 300
|
|
26161
|
-
|
|
26153
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
26154
|
+
logger26.log({
|
|
26162
26155
|
level: "info",
|
|
26163
26156
|
message: `Cache set for division by name: ${cacheKey}`
|
|
26164
26157
|
});
|
|
26165
26158
|
}).catch((err) => {
|
|
26166
|
-
|
|
26159
|
+
logger26.log({
|
|
26167
26160
|
level: "error",
|
|
26168
26161
|
message: `Failed to set cache for division by name: ${err.message}`
|
|
26169
26162
|
});
|
|
@@ -26533,11 +26526,11 @@ function MSchool(value) {
|
|
|
26533
26526
|
// src/repositories/school.repository.ts
|
|
26534
26527
|
import {
|
|
26535
26528
|
BadRequestError as BadRequestError56,
|
|
26536
|
-
logger as
|
|
26529
|
+
logger as logger27,
|
|
26537
26530
|
makeCacheKey as makeCacheKey18,
|
|
26538
26531
|
paginate as paginate14,
|
|
26539
26532
|
useAtlas as useAtlas29,
|
|
26540
|
-
useCache as
|
|
26533
|
+
useCache as useCache19
|
|
26541
26534
|
} from "@eeplatform/nodejs-utils";
|
|
26542
26535
|
import { ObjectId as ObjectId38 } from "mongodb";
|
|
26543
26536
|
function useSchoolRepo() {
|
|
@@ -26547,15 +26540,15 @@ function useSchoolRepo() {
|
|
|
26547
26540
|
}
|
|
26548
26541
|
const namespace_collection = "schools";
|
|
26549
26542
|
const collection = db.collection(namespace_collection);
|
|
26550
|
-
const { getCache, setCache, delNamespace } =
|
|
26543
|
+
const { getCache, setCache, delNamespace } = useCache19(namespace_collection);
|
|
26551
26544
|
function delCachedData() {
|
|
26552
|
-
delNamespace(
|
|
26553
|
-
|
|
26545
|
+
delNamespace().then(() => {
|
|
26546
|
+
logger27.log({
|
|
26554
26547
|
level: "info",
|
|
26555
26548
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
26556
26549
|
});
|
|
26557
26550
|
}).catch((err) => {
|
|
26558
|
-
|
|
26551
|
+
logger27.log({
|
|
26559
26552
|
level: "error",
|
|
26560
26553
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
26561
26554
|
});
|
|
@@ -26592,7 +26585,7 @@ function useSchoolRepo() {
|
|
|
26592
26585
|
delCachedData();
|
|
26593
26586
|
return res.insertedId;
|
|
26594
26587
|
} catch (error) {
|
|
26595
|
-
|
|
26588
|
+
logger27.log({
|
|
26596
26589
|
level: "error",
|
|
26597
26590
|
message: `Failed to add school: ${error}`
|
|
26598
26591
|
});
|
|
@@ -26608,8 +26601,8 @@ function useSchoolRepo() {
|
|
|
26608
26601
|
limit = 20,
|
|
26609
26602
|
sort = {},
|
|
26610
26603
|
status = "active",
|
|
26611
|
-
|
|
26612
|
-
|
|
26604
|
+
org = "",
|
|
26605
|
+
app = "admin",
|
|
26613
26606
|
search = ""
|
|
26614
26607
|
} = {}) {
|
|
26615
26608
|
page = Math.max(0, page - 1);
|
|
@@ -26627,20 +26620,12 @@ function useSchoolRepo() {
|
|
|
26627
26620
|
query.$text = { $search: search };
|
|
26628
26621
|
cacheKeyOptions.search = search;
|
|
26629
26622
|
}
|
|
26630
|
-
if (
|
|
26631
|
-
try {
|
|
26632
|
-
query.region = new ObjectId38(region);
|
|
26633
|
-
cacheKeyOptions.region = region;
|
|
26634
|
-
} catch (error) {
|
|
26635
|
-
throw new BadRequestError56("Invalid region.");
|
|
26636
|
-
}
|
|
26637
|
-
}
|
|
26638
|
-
if (division) {
|
|
26623
|
+
if (org) {
|
|
26639
26624
|
try {
|
|
26640
|
-
query
|
|
26641
|
-
cacheKeyOptions
|
|
26625
|
+
query[app] = new ObjectId38(org);
|
|
26626
|
+
cacheKeyOptions[app] = org;
|
|
26642
26627
|
} catch (error) {
|
|
26643
|
-
throw new BadRequestError56("Invalid
|
|
26628
|
+
throw new BadRequestError56("Invalid org.");
|
|
26644
26629
|
}
|
|
26645
26630
|
}
|
|
26646
26631
|
try {
|
|
@@ -26657,20 +26642,20 @@ function useSchoolRepo() {
|
|
|
26657
26642
|
]).toArray();
|
|
26658
26643
|
const length = await collection.countDocuments(query);
|
|
26659
26644
|
const data = paginate14(items, page, limit, length);
|
|
26660
|
-
setCache(cacheKey, data, 600
|
|
26661
|
-
|
|
26645
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
26646
|
+
logger27.log({
|
|
26662
26647
|
level: "info",
|
|
26663
26648
|
message: `Cache set for key ${cacheKey}`
|
|
26664
26649
|
});
|
|
26665
26650
|
}).catch((err) => {
|
|
26666
|
-
|
|
26651
|
+
logger27.log({
|
|
26667
26652
|
level: "error",
|
|
26668
26653
|
message: `Failed to set cache for key ${cacheKey}: ${err.message}`
|
|
26669
26654
|
});
|
|
26670
26655
|
});
|
|
26671
26656
|
return data;
|
|
26672
26657
|
} catch (error) {
|
|
26673
|
-
|
|
26658
|
+
logger27.log({
|
|
26674
26659
|
level: "error",
|
|
26675
26660
|
message: `Failed to get all schools: ${error}`
|
|
26676
26661
|
});
|
|
@@ -26748,13 +26733,13 @@ function useSchoolRepo() {
|
|
|
26748
26733
|
}
|
|
26749
26734
|
try {
|
|
26750
26735
|
const school = await collection.findOne({ createdBy, status: "pending" });
|
|
26751
|
-
setCache(cacheKey, school, 600
|
|
26752
|
-
|
|
26736
|
+
setCache(cacheKey, school, 600).then(() => {
|
|
26737
|
+
logger27.log({
|
|
26753
26738
|
level: "info",
|
|
26754
26739
|
message: `Cache set for school by createdBy: ${cacheKey}`
|
|
26755
26740
|
});
|
|
26756
26741
|
}).catch((err) => {
|
|
26757
|
-
|
|
26742
|
+
logger27.log({
|
|
26758
26743
|
level: "error",
|
|
26759
26744
|
message: `Failed to set cache for school by createdBy: ${err.message}`
|
|
26760
26745
|
});
|
|
@@ -26780,13 +26765,13 @@ function useSchoolRepo() {
|
|
|
26780
26765
|
}
|
|
26781
26766
|
try {
|
|
26782
26767
|
const school = await collection.findOne({ _id, status: "pending" });
|
|
26783
|
-
setCache(cacheKey, school, 600
|
|
26784
|
-
|
|
26768
|
+
setCache(cacheKey, school, 600).then(() => {
|
|
26769
|
+
logger27.log({
|
|
26785
26770
|
level: "info",
|
|
26786
26771
|
message: `Cache set for school by ID: ${cacheKey}`
|
|
26787
26772
|
});
|
|
26788
26773
|
}).catch((err) => {
|
|
26789
|
-
|
|
26774
|
+
logger27.log({
|
|
26790
26775
|
level: "error",
|
|
26791
26776
|
message: `Failed to set cache for school by ID: ${err.message}`
|
|
26792
26777
|
});
|
|
@@ -26808,7 +26793,7 @@ function useSchoolRepo() {
|
|
|
26808
26793
|
}
|
|
26809
26794
|
|
|
26810
26795
|
// src/services/school.service.ts
|
|
26811
|
-
import { BadRequestError as BadRequestError57, useAtlas as useAtlas30, logger as
|
|
26796
|
+
import { BadRequestError as BadRequestError57, useAtlas as useAtlas30, logger as logger28 } from "@eeplatform/nodejs-utils";
|
|
26812
26797
|
function useSchoolService() {
|
|
26813
26798
|
const { add, getPendingByCreatedBy, updateStatusById, getPendingById } = useSchoolRepo();
|
|
26814
26799
|
const { addRole } = useRoleRepo();
|
|
@@ -26881,7 +26866,7 @@ function useSchoolService() {
|
|
|
26881
26866
|
await session.commitTransaction();
|
|
26882
26867
|
return "School registration has been approved.";
|
|
26883
26868
|
} catch (error) {
|
|
26884
|
-
|
|
26869
|
+
logger28.log({
|
|
26885
26870
|
level: "error",
|
|
26886
26871
|
message: `Error approving school registration: ${error.message}`
|
|
26887
26872
|
});
|
|
@@ -26930,8 +26915,8 @@ function useSchoolController() {
|
|
|
26930
26915
|
sort: Joi32.string().optional().allow(null, ""),
|
|
26931
26916
|
sortOrder: Joi32.string().optional().allow(null, ""),
|
|
26932
26917
|
status: Joi32.string().optional().allow(null, ""),
|
|
26933
|
-
|
|
26934
|
-
|
|
26918
|
+
org: Joi32.string().hex().optional().allow(null, ""),
|
|
26919
|
+
app: Joi32.string().optional().allow(null, ""),
|
|
26935
26920
|
search: Joi32.string().optional().allow(null, "")
|
|
26936
26921
|
});
|
|
26937
26922
|
const { error } = validation.validate(req.query);
|
|
@@ -26951,8 +26936,8 @@ function useSchoolController() {
|
|
|
26951
26936
|
});
|
|
26952
26937
|
}
|
|
26953
26938
|
const status = req.query.status ?? "active";
|
|
26954
|
-
const
|
|
26955
|
-
const
|
|
26939
|
+
const org = req.query.org ?? "";
|
|
26940
|
+
const app = req.query.app ?? "admin";
|
|
26956
26941
|
const search = req.query.search ?? "";
|
|
26957
26942
|
try {
|
|
26958
26943
|
const schools = await _getAll({
|
|
@@ -26960,8 +26945,8 @@ function useSchoolController() {
|
|
|
26960
26945
|
limit,
|
|
26961
26946
|
sort: sortObj,
|
|
26962
26947
|
status,
|
|
26963
|
-
|
|
26964
|
-
|
|
26948
|
+
org,
|
|
26949
|
+
app,
|
|
26965
26950
|
search
|
|
26966
26951
|
});
|
|
26967
26952
|
res.status(200).json(schools);
|