@eeplatform/core 1.0.2 → 1.1.0
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 +117 -5
- package/dist/index.js +899 -146
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1078 -315
- 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}`
|
|
@@ -11731,9 +11731,9 @@ function useUserRepo() {
|
|
|
11731
11731
|
}
|
|
11732
11732
|
const namespace_collection = "users";
|
|
11733
11733
|
const collection = db.collection(namespace_collection);
|
|
11734
|
-
const { getCache, setCache, delNamespace } = useCache2();
|
|
11734
|
+
const { getCache, setCache, delNamespace } = useCache2(namespace_collection);
|
|
11735
11735
|
function delCachedData() {
|
|
11736
|
-
delNamespace(
|
|
11736
|
+
delNamespace().then(() => {
|
|
11737
11737
|
logger2.log({
|
|
11738
11738
|
level: "info",
|
|
11739
11739
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -11795,7 +11795,7 @@ function useUserRepo() {
|
|
|
11795
11795
|
}
|
|
11796
11796
|
const result = await collection.findOne({ email });
|
|
11797
11797
|
if (result) {
|
|
11798
|
-
setCache(cacheKey, result, 300
|
|
11798
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
11799
11799
|
logger2.log({
|
|
11800
11800
|
level: "info",
|
|
11801
11801
|
message: `Cache set for user by email: ${cacheKey}`
|
|
@@ -11825,7 +11825,7 @@ function useUserRepo() {
|
|
|
11825
11825
|
}
|
|
11826
11826
|
const result = await collection.findOne({ referralCode });
|
|
11827
11827
|
if (result) {
|
|
11828
|
-
setCache(cacheKey, result, 300
|
|
11828
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
11829
11829
|
logger2.log({
|
|
11830
11830
|
level: "info",
|
|
11831
11831
|
message: `Cache set for user by referral code: ${cacheKey}`
|
|
@@ -11860,7 +11860,7 @@ function useUserRepo() {
|
|
|
11860
11860
|
}
|
|
11861
11861
|
const result = await collection.findOne({ _id });
|
|
11862
11862
|
if (result) {
|
|
11863
|
-
setCache(cacheKey, result, 300
|
|
11863
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
11864
11864
|
logger2.log({
|
|
11865
11865
|
level: "info",
|
|
11866
11866
|
message: `Cache set for user by id: ${cacheKey}`
|
|
@@ -11934,7 +11934,7 @@ function useUserRepo() {
|
|
|
11934
11934
|
]).toArray();
|
|
11935
11935
|
const length = await collection.countDocuments(query);
|
|
11936
11936
|
const data = paginate2(items, page, limit, length);
|
|
11937
|
-
setCache(cacheKey, data, 600
|
|
11937
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
11938
11938
|
logger2.log({
|
|
11939
11939
|
level: "info",
|
|
11940
11940
|
message: `Cache set for getUsers: ${cacheKey}`
|
|
@@ -12157,9 +12157,9 @@ function useMemberRepo() {
|
|
|
12157
12157
|
}
|
|
12158
12158
|
const namespace_collection = "members";
|
|
12159
12159
|
const collection = db.collection(namespace_collection);
|
|
12160
|
-
const { getCache, setCache, delNamespace } = useCache3();
|
|
12160
|
+
const { getCache, setCache, delNamespace } = useCache3(namespace_collection);
|
|
12161
12161
|
function delCachedData() {
|
|
12162
|
-
delNamespace(
|
|
12162
|
+
delNamespace().then(() => {
|
|
12163
12163
|
logger3.log({
|
|
12164
12164
|
level: "info",
|
|
12165
12165
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -12250,7 +12250,7 @@ function useMemberRepo() {
|
|
|
12250
12250
|
return cached;
|
|
12251
12251
|
}
|
|
12252
12252
|
const data = await collection.findOne({ _id });
|
|
12253
|
-
setCache(cacheKey, data, 300
|
|
12253
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12254
12254
|
logger3.log({
|
|
12255
12255
|
level: "info",
|
|
12256
12256
|
message: `Cache set for member by id: ${cacheKey}`
|
|
@@ -12287,7 +12287,7 @@ function useMemberRepo() {
|
|
|
12287
12287
|
return cached;
|
|
12288
12288
|
}
|
|
12289
12289
|
const data = await collection.findOne({ user });
|
|
12290
|
-
setCache(cacheKey, data, 300
|
|
12290
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12291
12291
|
logger3.log({
|
|
12292
12292
|
level: "info",
|
|
12293
12293
|
message: `Cache set for member by user ID: ${cacheKey}`
|
|
@@ -12340,7 +12340,7 @@ function useMemberRepo() {
|
|
|
12340
12340
|
return cached;
|
|
12341
12341
|
}
|
|
12342
12342
|
const data = await collection.findOne(query);
|
|
12343
|
-
setCache(cacheKey, data, 300
|
|
12343
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12344
12344
|
logger3.log({
|
|
12345
12345
|
level: "info",
|
|
12346
12346
|
message: `Cache set for member by user ID: ${cacheKey}`
|
|
@@ -12444,7 +12444,7 @@ function useMemberRepo() {
|
|
|
12444
12444
|
]).toArray();
|
|
12445
12445
|
const length = await collection.countDocuments(query);
|
|
12446
12446
|
const data = paginate3(items, page, limit, length);
|
|
12447
|
-
setCache(cacheKey, data, 600
|
|
12447
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
12448
12448
|
logger3.log({
|
|
12449
12449
|
level: "info",
|
|
12450
12450
|
message: `Cache set for getAll members: ${cacheKey}`
|
|
@@ -12479,7 +12479,7 @@ function useMemberRepo() {
|
|
|
12479
12479
|
return cached;
|
|
12480
12480
|
}
|
|
12481
12481
|
const data = await collection.countDocuments({ org, status: "active" });
|
|
12482
|
-
setCache(cacheKey, data, 300
|
|
12482
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12483
12483
|
logger3.log({
|
|
12484
12484
|
level: "info",
|
|
12485
12485
|
message: `Cache set for countByOrg members: ${cacheKey}`
|
|
@@ -12516,7 +12516,7 @@ function useMemberRepo() {
|
|
|
12516
12516
|
return cached;
|
|
12517
12517
|
}
|
|
12518
12518
|
const data = await collection.countDocuments({ user, status: "active" });
|
|
12519
|
-
setCache(cacheKey, data, 300
|
|
12519
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12520
12520
|
logger3.log({
|
|
12521
12521
|
level: "info",
|
|
12522
12522
|
message: `Cache set for countByUser members: ${cacheKey}`
|
|
@@ -12590,7 +12590,7 @@ function useMemberRepo() {
|
|
|
12590
12590
|
]).toArray();
|
|
12591
12591
|
const length = await collection.countDocuments(query);
|
|
12592
12592
|
const data = paginate3(items, page, limit, length);
|
|
12593
|
-
setCache(cacheKey, data, 600
|
|
12593
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
12594
12594
|
logger3.log({
|
|
12595
12595
|
level: "info",
|
|
12596
12596
|
message: `Cache set for getOrgsByMembership members: ${cacheKey}`
|
|
@@ -12668,7 +12668,7 @@ function useMemberRepo() {
|
|
|
12668
12668
|
]).toArray();
|
|
12669
12669
|
const length = await collection.countDocuments(query);
|
|
12670
12670
|
const data = paginate3(items, page, limit, length);
|
|
12671
|
-
setCache(cacheKey, data, 300
|
|
12671
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12672
12672
|
logger3.log({
|
|
12673
12673
|
level: "info",
|
|
12674
12674
|
message: `Cache set for getOrgsByUserId members: ${cacheKey}`
|
|
@@ -13241,9 +13241,9 @@ function useTokenRepo() {
|
|
|
13241
13241
|
}
|
|
13242
13242
|
const namespace_collection = "tokens";
|
|
13243
13243
|
const collection = db.collection(namespace_collection);
|
|
13244
|
-
const { getCache, setCache, delNamespace } = useCache4();
|
|
13244
|
+
const { getCache, setCache, delNamespace } = useCache4(namespace_collection);
|
|
13245
13245
|
function delCachedData() {
|
|
13246
|
-
delNamespace(
|
|
13246
|
+
delNamespace().then(() => {
|
|
13247
13247
|
logger5.log({
|
|
13248
13248
|
level: "info",
|
|
13249
13249
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -13282,7 +13282,7 @@ function useTokenRepo() {
|
|
|
13282
13282
|
}
|
|
13283
13283
|
const data = await collection.findOne({ token });
|
|
13284
13284
|
if (data) {
|
|
13285
|
-
setCache(cacheKey, data, 300
|
|
13285
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
13286
13286
|
logger5.log({
|
|
13287
13287
|
level: "info",
|
|
13288
13288
|
message: `Cache set for token: ${cacheKey}`
|
|
@@ -13358,9 +13358,9 @@ function useFileRepo() {
|
|
|
13358
13358
|
}
|
|
13359
13359
|
const namespace_collection = "files";
|
|
13360
13360
|
const collection = db.collection(namespace_collection);
|
|
13361
|
-
const { getCache, setCache, delNamespace } = useCache5();
|
|
13361
|
+
const { getCache, setCache, delNamespace } = useCache5(namespace_collection);
|
|
13362
13362
|
function delCachedData() {
|
|
13363
|
-
delNamespace(
|
|
13363
|
+
delNamespace().then(() => {
|
|
13364
13364
|
logger6.log({
|
|
13365
13365
|
level: "info",
|
|
13366
13366
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -13408,7 +13408,7 @@ function useFileRepo() {
|
|
|
13408
13408
|
return cached;
|
|
13409
13409
|
}
|
|
13410
13410
|
const data = await collection.find({ $and: [{ status: "draft" }, { status: null }] }).toArray();
|
|
13411
|
-
setCache(cacheKey, data, 300
|
|
13411
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
13412
13412
|
logger6.log({
|
|
13413
13413
|
level: "info",
|
|
13414
13414
|
message: `Cache set for getAllDraftedFiles: ${cacheKey}`
|
|
@@ -13481,6 +13481,16 @@ var isPlainObject = (val) => {
|
|
|
13481
13481
|
const prototype3 = getPrototypeOf(val);
|
|
13482
13482
|
return (prototype3 === null || prototype3 === Object.prototype || Object.getPrototypeOf(prototype3) === null) && !(toStringTag in val) && !(iterator in val);
|
|
13483
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
|
+
};
|
|
13484
13494
|
var isDate = kindOfTest("Date");
|
|
13485
13495
|
var isFile = kindOfTest("File");
|
|
13486
13496
|
var isBlob = kindOfTest("Blob");
|
|
@@ -13508,6 +13518,9 @@ function forEach(obj, fn, { allOwnKeys = false } = {}) {
|
|
|
13508
13518
|
fn.call(null, obj[i], i, obj);
|
|
13509
13519
|
}
|
|
13510
13520
|
} else {
|
|
13521
|
+
if (isBuffer(obj)) {
|
|
13522
|
+
return;
|
|
13523
|
+
}
|
|
13511
13524
|
const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
|
13512
13525
|
const len = keys.length;
|
|
13513
13526
|
let key;
|
|
@@ -13518,6 +13531,9 @@ function forEach(obj, fn, { allOwnKeys = false } = {}) {
|
|
|
13518
13531
|
}
|
|
13519
13532
|
}
|
|
13520
13533
|
function findKey(obj, key) {
|
|
13534
|
+
if (isBuffer(obj)) {
|
|
13535
|
+
return null;
|
|
13536
|
+
}
|
|
13521
13537
|
key = key.toLowerCase();
|
|
13522
13538
|
const keys = Object.keys(obj);
|
|
13523
13539
|
let i = keys.length;
|
|
@@ -13714,6 +13730,9 @@ var toJSONObject = (obj) => {
|
|
|
13714
13730
|
if (stack.indexOf(source) >= 0) {
|
|
13715
13731
|
return;
|
|
13716
13732
|
}
|
|
13733
|
+
if (isBuffer(source)) {
|
|
13734
|
+
return source;
|
|
13735
|
+
}
|
|
13717
13736
|
if (!("toJSON" in source)) {
|
|
13718
13737
|
stack[i] = source;
|
|
13719
13738
|
const target = isArray(source) ? [] : {};
|
|
@@ -13763,6 +13782,7 @@ var utils_default = {
|
|
|
13763
13782
|
isBoolean,
|
|
13764
13783
|
isObject,
|
|
13765
13784
|
isPlainObject,
|
|
13785
|
+
isEmptyObject,
|
|
13766
13786
|
isReadableStream,
|
|
13767
13787
|
isRequest,
|
|
13768
13788
|
isResponse,
|
|
@@ -14207,15 +14227,16 @@ var platform_default = {
|
|
|
14207
14227
|
|
|
14208
14228
|
// node_modules/axios/lib/helpers/toURLEncodedForm.js
|
|
14209
14229
|
function toURLEncodedForm(data, options) {
|
|
14210
|
-
return toFormData_default(data, new platform_default.classes.URLSearchParams(),
|
|
14230
|
+
return toFormData_default(data, new platform_default.classes.URLSearchParams(), {
|
|
14211
14231
|
visitor: function(value, key, path, helpers) {
|
|
14212
14232
|
if (platform_default.isNode && utils_default.isBuffer(value)) {
|
|
14213
14233
|
this.append(key, value.toString("base64"));
|
|
14214
14234
|
return false;
|
|
14215
14235
|
}
|
|
14216
14236
|
return helpers.defaultVisitor.apply(this, arguments);
|
|
14217
|
-
}
|
|
14218
|
-
|
|
14237
|
+
},
|
|
14238
|
+
...options
|
|
14239
|
+
});
|
|
14219
14240
|
}
|
|
14220
14241
|
|
|
14221
14242
|
// node_modules/axios/lib/helpers/formDataToJSON.js
|
|
@@ -14728,7 +14749,7 @@ import util2 from "util";
|
|
|
14728
14749
|
import zlib from "zlib";
|
|
14729
14750
|
|
|
14730
14751
|
// node_modules/axios/lib/env/data.js
|
|
14731
|
-
var VERSION = "1.
|
|
14752
|
+
var VERSION = "1.11.0";
|
|
14732
14753
|
|
|
14733
14754
|
// node_modules/axios/lib/helpers/parseProtocol.js
|
|
14734
14755
|
function parseProtocol(url2) {
|
|
@@ -15070,7 +15091,7 @@ function throttle(fn, freq) {
|
|
|
15070
15091
|
clearTimeout(timer);
|
|
15071
15092
|
timer = null;
|
|
15072
15093
|
}
|
|
15073
|
-
fn
|
|
15094
|
+
fn(...args);
|
|
15074
15095
|
};
|
|
15075
15096
|
const throttled = (...args) => {
|
|
15076
15097
|
const now = Date.now();
|
|
@@ -15745,7 +15766,7 @@ function mergeConfig(config1, config2) {
|
|
|
15745
15766
|
validateStatus: mergeDirectKeys,
|
|
15746
15767
|
headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
|
|
15747
15768
|
};
|
|
15748
|
-
utils_default.forEach(Object.keys(
|
|
15769
|
+
utils_default.forEach(Object.keys({ ...config1, ...config2 }), function computeConfigValue(prop) {
|
|
15749
15770
|
const merge2 = mergeMap[prop] || mergeDeepProperties;
|
|
15750
15771
|
const configValue = merge2(config1[prop], config2[prop], prop);
|
|
15751
15772
|
utils_default.isUndefined(configValue) && merge2 !== mergeDirectKeys || (config3[prop] = configValue);
|
|
@@ -16459,8 +16480,8 @@ var Axios = class {
|
|
|
16459
16480
|
let len;
|
|
16460
16481
|
if (!synchronousRequestInterceptors) {
|
|
16461
16482
|
const chain = [dispatchRequest.bind(this), void 0];
|
|
16462
|
-
chain.unshift
|
|
16463
|
-
chain.push
|
|
16483
|
+
chain.unshift(...requestInterceptorChain);
|
|
16484
|
+
chain.push(...responseInterceptorChain);
|
|
16464
16485
|
len = chain.length;
|
|
16465
16486
|
promise = Promise.resolve(config2);
|
|
16466
16487
|
while (i < len) {
|
|
@@ -17442,9 +17463,9 @@ function useRoleRepo() {
|
|
|
17442
17463
|
}
|
|
17443
17464
|
const namespace_collection = "roles";
|
|
17444
17465
|
const collection = db.collection(namespace_collection);
|
|
17445
|
-
const { getCache, setCache, delNamespace } = useCache6();
|
|
17466
|
+
const { getCache, setCache, delNamespace } = useCache6(namespace_collection);
|
|
17446
17467
|
function delCachedData() {
|
|
17447
|
-
delNamespace(
|
|
17468
|
+
delNamespace().then(() => {
|
|
17448
17469
|
logger8.log({
|
|
17449
17470
|
level: "info",
|
|
17450
17471
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -17517,7 +17538,7 @@ function useRoleRepo() {
|
|
|
17517
17538
|
return cached;
|
|
17518
17539
|
}
|
|
17519
17540
|
const data = await collection.findOne({ user: value });
|
|
17520
|
-
setCache(cacheKey, data, 300
|
|
17541
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
17521
17542
|
logger8.log({
|
|
17522
17543
|
level: "info",
|
|
17523
17544
|
message: `Cache set for role by user ID: ${cacheKey}`
|
|
@@ -17552,7 +17573,7 @@ function useRoleRepo() {
|
|
|
17552
17573
|
return cached;
|
|
17553
17574
|
}
|
|
17554
17575
|
const data = await collection.findOne({ _id });
|
|
17555
|
-
setCache(cacheKey, data, 300
|
|
17576
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
17556
17577
|
logger8.log({
|
|
17557
17578
|
level: "info",
|
|
17558
17579
|
message: `Cache set for role by id: ${cacheKey}`
|
|
@@ -17585,7 +17606,7 @@ function useRoleRepo() {
|
|
|
17585
17606
|
return cached;
|
|
17586
17607
|
}
|
|
17587
17608
|
const data = await collection.findOne({ name });
|
|
17588
|
-
setCache(cacheKey, data, 300
|
|
17609
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
17589
17610
|
logger8.log({
|
|
17590
17611
|
level: "info",
|
|
17591
17612
|
message: `Cache set for role by name: ${cacheKey}`
|
|
@@ -17659,7 +17680,7 @@ function useRoleRepo() {
|
|
|
17659
17680
|
]).toArray();
|
|
17660
17681
|
const length = await collection.countDocuments(query);
|
|
17661
17682
|
const data = paginate4(items, page, limit, length);
|
|
17662
|
-
setCache(cacheKey, data, 600
|
|
17683
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
17663
17684
|
logger8.log({
|
|
17664
17685
|
level: "info",
|
|
17665
17686
|
message: `Cache set for getRoles: ${cacheKey}`
|
|
@@ -18373,11 +18394,14 @@ import {
|
|
|
18373
18394
|
comparePassword,
|
|
18374
18395
|
generateToken,
|
|
18375
18396
|
InternalServerError as InternalServerError11,
|
|
18376
|
-
NotFoundError as NotFoundError3
|
|
18397
|
+
NotFoundError as NotFoundError3,
|
|
18398
|
+
useCache as useCache8
|
|
18377
18399
|
} from "@eeplatform/nodejs-utils";
|
|
18378
18400
|
import jwt from "jsonwebtoken";
|
|
18401
|
+
import { v4 as uuidv4 } from "uuid";
|
|
18379
18402
|
function useAuthService() {
|
|
18380
18403
|
const expiresIn = "1m";
|
|
18404
|
+
const { setCache, delCache } = useCache8("sessions");
|
|
18381
18405
|
async function login({ email, password } = {}) {
|
|
18382
18406
|
if (!email) {
|
|
18383
18407
|
throw new BadRequestError13("Email is required");
|
|
@@ -18409,34 +18433,14 @@ function useAuthService() {
|
|
|
18409
18433
|
if (!isPasswordValid) {
|
|
18410
18434
|
throw new BadRequestError13("Invalid password");
|
|
18411
18435
|
}
|
|
18412
|
-
const
|
|
18413
|
-
|
|
18414
|
-
|
|
18415
|
-
|
|
18416
|
-
|
|
18417
|
-
|
|
18418
|
-
|
|
18419
|
-
|
|
18420
|
-
} catch (error) {
|
|
18421
|
-
throw new BadRequestError13("Error generating refresh token");
|
|
18422
|
-
}
|
|
18423
|
-
let accessToken;
|
|
18424
|
-
try {
|
|
18425
|
-
accessToken = generateToken({
|
|
18426
|
-
secret: ACCESS_TOKEN_SECRET,
|
|
18427
|
-
metadata,
|
|
18428
|
-
options: { expiresIn }
|
|
18429
|
-
});
|
|
18430
|
-
} catch (error) {
|
|
18431
|
-
throw new BadRequestError13("Error generating access token");
|
|
18432
|
-
}
|
|
18433
|
-
const user = _user._id ?? "";
|
|
18434
|
-
try {
|
|
18435
|
-
await useTokenRepo().createToken({ token: refreshToken2, user });
|
|
18436
|
-
} catch (error) {
|
|
18437
|
-
throw new BadRequestError13("Error creating refresh token");
|
|
18438
|
-
}
|
|
18439
|
-
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() ?? "" };
|
|
18440
18444
|
}
|
|
18441
18445
|
async function refreshToken(token) {
|
|
18442
18446
|
let decoded;
|
|
@@ -18470,26 +18474,13 @@ function useAuthService() {
|
|
|
18470
18474
|
}
|
|
18471
18475
|
return accessToken;
|
|
18472
18476
|
}
|
|
18473
|
-
async function logout(
|
|
18474
|
-
let _token;
|
|
18475
|
-
try {
|
|
18476
|
-
_token = await useTokenRepo().getToken(token);
|
|
18477
|
-
if (!_token) {
|
|
18478
|
-
throw new NotFoundError3("Invalid token");
|
|
18479
|
-
}
|
|
18480
|
-
} catch (error) {
|
|
18481
|
-
if (error instanceof AppError5) {
|
|
18482
|
-
throw error;
|
|
18483
|
-
} else {
|
|
18484
|
-
throw new InternalServerError11(`${error}`);
|
|
18485
|
-
}
|
|
18486
|
-
}
|
|
18477
|
+
async function logout(sid) {
|
|
18487
18478
|
try {
|
|
18488
|
-
await
|
|
18479
|
+
await delCache(`sid:${sid}`);
|
|
18480
|
+
return "Session deleted successfully";
|
|
18489
18481
|
} catch (error) {
|
|
18490
18482
|
throw new InternalServerError11("Error deleting token");
|
|
18491
18483
|
}
|
|
18492
|
-
return "Logged out successfully";
|
|
18493
18484
|
}
|
|
18494
18485
|
return {
|
|
18495
18486
|
login,
|
|
@@ -18503,7 +18494,8 @@ import Joi5 from "joi";
|
|
|
18503
18494
|
import {
|
|
18504
18495
|
AppError as AppError6,
|
|
18505
18496
|
BadRequestError as BadRequestError14,
|
|
18506
|
-
InternalServerError as InternalServerError12
|
|
18497
|
+
InternalServerError as InternalServerError12,
|
|
18498
|
+
logger as logger10
|
|
18507
18499
|
} from "@eeplatform/nodejs-utils";
|
|
18508
18500
|
function useAuthController() {
|
|
18509
18501
|
const { signUp: _signUp } = useVerificationService();
|
|
@@ -18517,16 +18509,26 @@ function useAuthController() {
|
|
|
18517
18509
|
const { error } = validation.validate({ email, password });
|
|
18518
18510
|
if (error) {
|
|
18519
18511
|
next(new BadRequestError14(error.message));
|
|
18512
|
+
return;
|
|
18520
18513
|
}
|
|
18521
18514
|
try {
|
|
18522
|
-
const
|
|
18523
|
-
|
|
18515
|
+
const session = await useAuthService().login({
|
|
18516
|
+
email,
|
|
18517
|
+
password
|
|
18518
|
+
});
|
|
18519
|
+
res.json(session);
|
|
18524
18520
|
} catch (error2) {
|
|
18521
|
+
logger10.log({
|
|
18522
|
+
level: "error",
|
|
18523
|
+
message: `Error during login: ${error2.message}`
|
|
18524
|
+
});
|
|
18525
|
+
console.log(`Error during login: ${error2}`);
|
|
18525
18526
|
if (error2 instanceof AppError6) {
|
|
18526
18527
|
next(error2);
|
|
18527
18528
|
} else {
|
|
18528
18529
|
next(new InternalServerError12("An unexpected error occurred"));
|
|
18529
18530
|
}
|
|
18531
|
+
return;
|
|
18530
18532
|
}
|
|
18531
18533
|
}
|
|
18532
18534
|
async function refreshToken(req, res, next) {
|
|
@@ -18547,13 +18549,13 @@ function useAuthController() {
|
|
|
18547
18549
|
}
|
|
18548
18550
|
}
|
|
18549
18551
|
async function logout(req, res, next) {
|
|
18550
|
-
const
|
|
18551
|
-
if (!
|
|
18552
|
-
next(new BadRequestError14("
|
|
18552
|
+
const sid = req.headers["authorization"] ?? "";
|
|
18553
|
+
if (!sid) {
|
|
18554
|
+
next(new BadRequestError14("Session ID is required"));
|
|
18553
18555
|
return;
|
|
18554
18556
|
}
|
|
18555
18557
|
try {
|
|
18556
|
-
await useAuthService().logout(
|
|
18558
|
+
await useAuthService().logout(sid);
|
|
18557
18559
|
res.json({ message: "Logged out successfully" });
|
|
18558
18560
|
} catch (error) {
|
|
18559
18561
|
if (error instanceof AppError6) {
|
|
@@ -18628,7 +18630,7 @@ function useAuthController() {
|
|
|
18628
18630
|
}
|
|
18629
18631
|
|
|
18630
18632
|
// src/services/file.service.ts
|
|
18631
|
-
import { logger as
|
|
18633
|
+
import { logger as logger11, useS3 as useS32, useAtlas as useAtlas9 } from "@eeplatform/nodejs-utils";
|
|
18632
18634
|
import cron from "node-cron";
|
|
18633
18635
|
function useFileService() {
|
|
18634
18636
|
const {
|
|
@@ -18689,12 +18691,12 @@ function useFileService() {
|
|
|
18689
18691
|
const file = files[index];
|
|
18690
18692
|
try {
|
|
18691
18693
|
await deleteFile(file._id.toString());
|
|
18692
|
-
await
|
|
18694
|
+
await logger11.log({
|
|
18693
18695
|
level: "info",
|
|
18694
18696
|
message: "Successfully deleted draft files."
|
|
18695
18697
|
});
|
|
18696
18698
|
} catch (error) {
|
|
18697
|
-
|
|
18699
|
+
logger11.log({
|
|
18698
18700
|
level: "info",
|
|
18699
18701
|
message: "Successfully deleted draft files."
|
|
18700
18702
|
});
|
|
@@ -18948,11 +18950,11 @@ import { ObjectId as ObjectId16 } from "mongodb";
|
|
|
18948
18950
|
import {
|
|
18949
18951
|
BadRequestError as BadRequestError17,
|
|
18950
18952
|
InternalServerError as InternalServerError15,
|
|
18951
|
-
logger as
|
|
18953
|
+
logger as logger12,
|
|
18952
18954
|
makeCacheKey as makeCacheKey8,
|
|
18953
18955
|
paginate as paginate5,
|
|
18954
18956
|
useAtlas as useAtlas10,
|
|
18955
|
-
useCache as
|
|
18957
|
+
useCache as useCache9
|
|
18956
18958
|
} from "@eeplatform/nodejs-utils";
|
|
18957
18959
|
function useEntityRepo() {
|
|
18958
18960
|
const db = useAtlas10.getDb();
|
|
@@ -18961,15 +18963,15 @@ function useEntityRepo() {
|
|
|
18961
18963
|
}
|
|
18962
18964
|
const namespace_collection = "entities";
|
|
18963
18965
|
const collection = db.collection(namespace_collection);
|
|
18964
|
-
const { getCache, setCache, delNamespace } =
|
|
18966
|
+
const { getCache, setCache, delNamespace } = useCache9(namespace_collection);
|
|
18965
18967
|
function delCachedData() {
|
|
18966
|
-
delNamespace(
|
|
18967
|
-
|
|
18968
|
+
delNamespace().then(() => {
|
|
18969
|
+
logger12.log({
|
|
18968
18970
|
level: "info",
|
|
18969
18971
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
18970
18972
|
});
|
|
18971
18973
|
}).catch((err) => {
|
|
18972
|
-
|
|
18974
|
+
logger12.log({
|
|
18973
18975
|
level: "error",
|
|
18974
18976
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
18975
18977
|
});
|
|
@@ -18999,7 +19001,7 @@ function useEntityRepo() {
|
|
|
18999
19001
|
delCachedData();
|
|
19000
19002
|
return res.insertedId.toString();
|
|
19001
19003
|
} catch (error) {
|
|
19002
|
-
|
|
19004
|
+
logger12.log({ level: "error", message: `${error}` });
|
|
19003
19005
|
const isDuplicated = error.message.includes("duplicate");
|
|
19004
19006
|
if (isDuplicated) {
|
|
19005
19007
|
throw new BadRequestError17("Entity name already exists.");
|
|
@@ -19029,7 +19031,7 @@ function useEntityRepo() {
|
|
|
19029
19031
|
try {
|
|
19030
19032
|
const cached = await getCache(cacheKey);
|
|
19031
19033
|
if (cached) {
|
|
19032
|
-
|
|
19034
|
+
logger12.log({
|
|
19033
19035
|
level: "info",
|
|
19034
19036
|
message: `Cache hit for getEntities: ${cacheKey}`
|
|
19035
19037
|
});
|
|
@@ -19043,20 +19045,20 @@ function useEntityRepo() {
|
|
|
19043
19045
|
]).toArray();
|
|
19044
19046
|
const length = await collection.countDocuments(query);
|
|
19045
19047
|
const data = paginate5(items, page, limit, length);
|
|
19046
|
-
setCache(cacheKey, data, 600
|
|
19047
|
-
|
|
19048
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
19049
|
+
logger12.log({
|
|
19048
19050
|
level: "info",
|
|
19049
19051
|
message: `Cache set for getEntities: ${cacheKey}`
|
|
19050
19052
|
});
|
|
19051
19053
|
}).catch((err) => {
|
|
19052
|
-
|
|
19054
|
+
logger12.log({
|
|
19053
19055
|
level: "error",
|
|
19054
19056
|
message: `Failed to set cache for getEntities: ${err.message}`
|
|
19055
19057
|
});
|
|
19056
19058
|
});
|
|
19057
19059
|
return data;
|
|
19058
19060
|
} catch (error) {
|
|
19059
|
-
|
|
19061
|
+
logger12.log({ level: "error", message: `${error}` });
|
|
19060
19062
|
throw error;
|
|
19061
19063
|
}
|
|
19062
19064
|
}
|
|
@@ -19312,11 +19314,11 @@ function MSubscription(value) {
|
|
|
19312
19314
|
// src/repositories/subscription.repository.ts
|
|
19313
19315
|
import {
|
|
19314
19316
|
BadRequestError as BadRequestError20,
|
|
19315
|
-
logger as
|
|
19317
|
+
logger as logger13,
|
|
19316
19318
|
makeCacheKey as makeCacheKey9,
|
|
19317
19319
|
paginate as paginate6,
|
|
19318
19320
|
useAtlas as useAtlas11,
|
|
19319
|
-
useCache as
|
|
19321
|
+
useCache as useCache10
|
|
19320
19322
|
} from "@eeplatform/nodejs-utils";
|
|
19321
19323
|
import { ObjectId as ObjectId18 } from "mongodb";
|
|
19322
19324
|
import Joi10 from "joi";
|
|
@@ -19327,15 +19329,15 @@ function useSubscriptionRepo() {
|
|
|
19327
19329
|
}
|
|
19328
19330
|
const namespace_collection = "subscriptions";
|
|
19329
19331
|
const collection = db.collection(namespace_collection);
|
|
19330
|
-
const { getCache, setCache, delNamespace } =
|
|
19332
|
+
const { getCache, setCache, delNamespace } = useCache10(namespace_collection);
|
|
19331
19333
|
function delCachedData() {
|
|
19332
|
-
delNamespace(
|
|
19333
|
-
|
|
19334
|
+
delNamespace().then(() => {
|
|
19335
|
+
logger13.log({
|
|
19334
19336
|
level: "info",
|
|
19335
19337
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
19336
19338
|
});
|
|
19337
19339
|
}).catch((err) => {
|
|
19338
|
-
|
|
19340
|
+
logger13.log({
|
|
19339
19341
|
level: "error",
|
|
19340
19342
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
19341
19343
|
});
|
|
@@ -19387,7 +19389,7 @@ function useSubscriptionRepo() {
|
|
|
19387
19389
|
try {
|
|
19388
19390
|
const cached = await getCache(cacheKey);
|
|
19389
19391
|
if (cached) {
|
|
19390
|
-
|
|
19392
|
+
logger13.log({
|
|
19391
19393
|
level: "info",
|
|
19392
19394
|
message: `Cache hit for getById subscription: ${cacheKey}`
|
|
19393
19395
|
});
|
|
@@ -19395,13 +19397,13 @@ function useSubscriptionRepo() {
|
|
|
19395
19397
|
}
|
|
19396
19398
|
const data = await collection.findOne({ _id });
|
|
19397
19399
|
if (data) {
|
|
19398
|
-
setCache(cacheKey, data, 300
|
|
19399
|
-
|
|
19400
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
19401
|
+
logger13.log({
|
|
19400
19402
|
level: "info",
|
|
19401
19403
|
message: `Cache set for subscription by ID: ${cacheKey}`
|
|
19402
19404
|
});
|
|
19403
19405
|
}).catch((err) => {
|
|
19404
|
-
|
|
19406
|
+
logger13.log({
|
|
19405
19407
|
level: "error",
|
|
19406
19408
|
message: `Failed to set cache for subscription by ID: ${err.message}`
|
|
19407
19409
|
});
|
|
@@ -19422,7 +19424,7 @@ function useSubscriptionRepo() {
|
|
|
19422
19424
|
try {
|
|
19423
19425
|
const cached = await getCache(cacheKey);
|
|
19424
19426
|
if (cached) {
|
|
19425
|
-
|
|
19427
|
+
logger13.log({
|
|
19426
19428
|
level: "info",
|
|
19427
19429
|
message: `Cache hit for getByUserId subscription: ${cacheKey}`
|
|
19428
19430
|
});
|
|
@@ -19430,13 +19432,13 @@ function useSubscriptionRepo() {
|
|
|
19430
19432
|
}
|
|
19431
19433
|
const data = await collection.findOne({ user });
|
|
19432
19434
|
if (data) {
|
|
19433
|
-
setCache(cacheKey, data, 300
|
|
19434
|
-
|
|
19435
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
19436
|
+
logger13.log({
|
|
19435
19437
|
level: "info",
|
|
19436
19438
|
message: `Cache set for subscription by user ID: ${cacheKey}`
|
|
19437
19439
|
});
|
|
19438
19440
|
}).catch((err) => {
|
|
19439
|
-
|
|
19441
|
+
logger13.log({
|
|
19440
19442
|
level: "error",
|
|
19441
19443
|
message: `Failed to set cache for subscription by user ID: ${err.message}`
|
|
19442
19444
|
});
|
|
@@ -19482,7 +19484,7 @@ function useSubscriptionRepo() {
|
|
|
19482
19484
|
try {
|
|
19483
19485
|
const cached = await getCache(cacheKey);
|
|
19484
19486
|
if (cached) {
|
|
19485
|
-
|
|
19487
|
+
logger13.log({
|
|
19486
19488
|
level: "info",
|
|
19487
19489
|
message: `Cache hit for getBySubscriptionId: ${cacheKey}`
|
|
19488
19490
|
});
|
|
@@ -19490,13 +19492,13 @@ function useSubscriptionRepo() {
|
|
|
19490
19492
|
}
|
|
19491
19493
|
const data = await collection.findOne({ subscriptionId });
|
|
19492
19494
|
if (data) {
|
|
19493
|
-
setCache(cacheKey, data, 300
|
|
19494
|
-
|
|
19495
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
19496
|
+
logger13.log({
|
|
19495
19497
|
level: "info",
|
|
19496
19498
|
message: `Cache set for subscription by subscription ID: ${cacheKey}`
|
|
19497
19499
|
});
|
|
19498
19500
|
}).catch((err) => {
|
|
19499
|
-
|
|
19501
|
+
logger13.log({
|
|
19500
19502
|
level: "error",
|
|
19501
19503
|
message: `Failed to set cache for subscription by subscription ID: ${err.message}`
|
|
19502
19504
|
});
|
|
@@ -19532,7 +19534,7 @@ function useSubscriptionRepo() {
|
|
|
19532
19534
|
try {
|
|
19533
19535
|
const cached = await getCache(cacheKey);
|
|
19534
19536
|
if (cached) {
|
|
19535
|
-
|
|
19537
|
+
logger13.log({
|
|
19536
19538
|
level: "info",
|
|
19537
19539
|
message: `Cache hit for getSubscriptions: ${cacheKey}`
|
|
19538
19540
|
});
|
|
@@ -19546,20 +19548,20 @@ function useSubscriptionRepo() {
|
|
|
19546
19548
|
]).toArray();
|
|
19547
19549
|
const length = await collection.countDocuments(query);
|
|
19548
19550
|
const data = paginate6(items, page, limit, length);
|
|
19549
|
-
setCache(cacheKey, data, 600
|
|
19550
|
-
|
|
19551
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
19552
|
+
logger13.log({
|
|
19551
19553
|
level: "info",
|
|
19552
19554
|
message: `Cache set for getSubscriptions: ${cacheKey}`
|
|
19553
19555
|
});
|
|
19554
19556
|
}).catch((err) => {
|
|
19555
|
-
|
|
19557
|
+
logger13.log({
|
|
19556
19558
|
level: "error",
|
|
19557
19559
|
message: `Failed to set cache for getSubscriptions: ${err.message}`
|
|
19558
19560
|
});
|
|
19559
19561
|
});
|
|
19560
19562
|
return data;
|
|
19561
19563
|
} catch (error) {
|
|
19562
|
-
|
|
19564
|
+
logger13.log({ level: "error", message: `${error}` });
|
|
19563
19565
|
throw error;
|
|
19564
19566
|
}
|
|
19565
19567
|
}
|
|
@@ -19706,10 +19708,10 @@ function useSubscriptionRepo() {
|
|
|
19706
19708
|
},
|
|
19707
19709
|
{ session }
|
|
19708
19710
|
);
|
|
19709
|
-
|
|
19711
|
+
logger13.info(`${res.modifiedCount} subscription updated.`);
|
|
19710
19712
|
return "Successfully updated subscription.";
|
|
19711
19713
|
} catch (error2) {
|
|
19712
|
-
|
|
19714
|
+
logger13.error(`${error2}`);
|
|
19713
19715
|
throw new BadRequestError20("Failed to update subscription.");
|
|
19714
19716
|
}
|
|
19715
19717
|
}
|
|
@@ -19961,7 +19963,7 @@ function useSubscriptionRepo() {
|
|
|
19961
19963
|
import {
|
|
19962
19964
|
AppError as AppError9,
|
|
19963
19965
|
BadRequestError as BadRequestError33,
|
|
19964
|
-
logger as
|
|
19966
|
+
logger as logger21,
|
|
19965
19967
|
useAtlas as useAtlas19
|
|
19966
19968
|
} from "@eeplatform/nodejs-utils";
|
|
19967
19969
|
|
|
@@ -19970,11 +19972,11 @@ import {
|
|
|
19970
19972
|
AppError as AppError8,
|
|
19971
19973
|
BadRequestError as BadRequestError22,
|
|
19972
19974
|
InternalServerError as InternalServerError16,
|
|
19973
|
-
logger as
|
|
19975
|
+
logger as logger14,
|
|
19974
19976
|
makeCacheKey as makeCacheKey10,
|
|
19975
19977
|
paginate as paginate7,
|
|
19976
19978
|
useAtlas as useAtlas12,
|
|
19977
|
-
useCache as
|
|
19979
|
+
useCache as useCache11
|
|
19978
19980
|
} from "@eeplatform/nodejs-utils";
|
|
19979
19981
|
|
|
19980
19982
|
// src/models/organization.model.ts
|
|
@@ -20029,7 +20031,7 @@ function useOrgRepo() {
|
|
|
20029
20031
|
}
|
|
20030
20032
|
const namespace_collection = "organizations";
|
|
20031
20033
|
const collection = db.collection(namespace_collection);
|
|
20032
|
-
const { getCache, setCache, delNamespace } =
|
|
20034
|
+
const { getCache, setCache, delNamespace } = useCache11(namespace_collection);
|
|
20033
20035
|
async function createIndex() {
|
|
20034
20036
|
try {
|
|
20035
20037
|
await collection.createIndex([
|
|
@@ -20064,13 +20066,13 @@ function useOrgRepo() {
|
|
|
20064
20066
|
}
|
|
20065
20067
|
}
|
|
20066
20068
|
function delCachedData() {
|
|
20067
|
-
delNamespace(
|
|
20068
|
-
|
|
20069
|
+
delNamespace().then(() => {
|
|
20070
|
+
logger14.log({
|
|
20069
20071
|
level: "info",
|
|
20070
20072
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
20071
20073
|
});
|
|
20072
20074
|
}).catch((err) => {
|
|
20073
|
-
|
|
20075
|
+
logger14.log({
|
|
20074
20076
|
level: "error",
|
|
20075
20077
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
20076
20078
|
});
|
|
@@ -20083,7 +20085,7 @@ function useOrgRepo() {
|
|
|
20083
20085
|
delCachedData();
|
|
20084
20086
|
return res.insertedId;
|
|
20085
20087
|
} catch (error) {
|
|
20086
|
-
|
|
20088
|
+
logger14.log({
|
|
20087
20089
|
level: "error",
|
|
20088
20090
|
message: error.message
|
|
20089
20091
|
});
|
|
@@ -20118,14 +20120,14 @@ function useOrgRepo() {
|
|
|
20118
20120
|
sort: JSON.stringify(sort),
|
|
20119
20121
|
status
|
|
20120
20122
|
});
|
|
20121
|
-
|
|
20123
|
+
logger14.log({
|
|
20122
20124
|
level: "info",
|
|
20123
20125
|
message: `Cache key for getAll organizations: ${cacheKey}`
|
|
20124
20126
|
});
|
|
20125
20127
|
try {
|
|
20126
20128
|
const cached = await getCache(cacheKey);
|
|
20127
20129
|
if (cached) {
|
|
20128
|
-
|
|
20130
|
+
logger14.log({
|
|
20129
20131
|
level: "info",
|
|
20130
20132
|
message: `Cache hit for getAll organizations: ${cacheKey}`
|
|
20131
20133
|
});
|
|
@@ -20148,20 +20150,20 @@ function useOrgRepo() {
|
|
|
20148
20150
|
]).toArray();
|
|
20149
20151
|
const length = await collection.countDocuments(query);
|
|
20150
20152
|
const data = paginate7(items, page, limit, length);
|
|
20151
|
-
setCache(cacheKey, data, 600
|
|
20152
|
-
|
|
20153
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
20154
|
+
logger14.log({
|
|
20153
20155
|
level: "info",
|
|
20154
20156
|
message: `Cache set for getAll organizations: ${cacheKey}`
|
|
20155
20157
|
});
|
|
20156
20158
|
}).catch((err) => {
|
|
20157
|
-
|
|
20159
|
+
logger14.log({
|
|
20158
20160
|
level: "error",
|
|
20159
20161
|
message: `Failed to set cache for getAll organizations: ${err.message}`
|
|
20160
20162
|
});
|
|
20161
20163
|
});
|
|
20162
20164
|
return data;
|
|
20163
20165
|
} catch (error) {
|
|
20164
|
-
|
|
20166
|
+
logger14.log({ level: "error", message: `${error}` });
|
|
20165
20167
|
throw error;
|
|
20166
20168
|
}
|
|
20167
20169
|
}
|
|
@@ -20175,7 +20177,7 @@ function useOrgRepo() {
|
|
|
20175
20177
|
try {
|
|
20176
20178
|
const cached = await getCache(cacheKey);
|
|
20177
20179
|
if (cached) {
|
|
20178
|
-
|
|
20180
|
+
logger14.log({
|
|
20179
20181
|
level: "info",
|
|
20180
20182
|
message: `Cache hit for getById organization: ${cacheKey}`
|
|
20181
20183
|
});
|
|
@@ -20185,13 +20187,13 @@ function useOrgRepo() {
|
|
|
20185
20187
|
if (!result) {
|
|
20186
20188
|
throw new BadRequestError22("Organization not found.");
|
|
20187
20189
|
}
|
|
20188
|
-
setCache(cacheKey, result, 300
|
|
20189
|
-
|
|
20190
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
20191
|
+
logger14.log({
|
|
20190
20192
|
level: "info",
|
|
20191
20193
|
message: `Cache set for organization by id: ${cacheKey}`
|
|
20192
20194
|
});
|
|
20193
20195
|
}).catch((err) => {
|
|
20194
|
-
|
|
20196
|
+
logger14.log({
|
|
20195
20197
|
level: "error",
|
|
20196
20198
|
message: `Failed to set cache for organization by id: ${err.message}`
|
|
20197
20199
|
});
|
|
@@ -20210,7 +20212,7 @@ function useOrgRepo() {
|
|
|
20210
20212
|
try {
|
|
20211
20213
|
const cached = await getCache(cacheKey);
|
|
20212
20214
|
if (cached) {
|
|
20213
|
-
|
|
20215
|
+
logger14.log({
|
|
20214
20216
|
level: "info",
|
|
20215
20217
|
message: `Cache hit for getByName organization: ${cacheKey}`
|
|
20216
20218
|
});
|
|
@@ -20220,13 +20222,13 @@ function useOrgRepo() {
|
|
|
20220
20222
|
if (!result) {
|
|
20221
20223
|
throw new BadRequestError22("Organization not found.");
|
|
20222
20224
|
}
|
|
20223
|
-
setCache(cacheKey, result, 300
|
|
20224
|
-
|
|
20225
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
20226
|
+
logger14.log({
|
|
20225
20227
|
level: "info",
|
|
20226
20228
|
message: `Cache set for organization by name: ${cacheKey}`
|
|
20227
20229
|
});
|
|
20228
20230
|
}).catch((err) => {
|
|
20229
|
-
|
|
20231
|
+
logger14.log({
|
|
20230
20232
|
level: "error",
|
|
20231
20233
|
message: `Failed to set cache for organization by name: ${err.message}`
|
|
20232
20234
|
});
|
|
@@ -20299,9 +20301,9 @@ function useOrgRepo() {
|
|
|
20299
20301
|
import {
|
|
20300
20302
|
BadRequestError as BadRequestError24,
|
|
20301
20303
|
useAtlas as useAtlas13,
|
|
20302
|
-
useCache as
|
|
20304
|
+
useCache as useCache12,
|
|
20303
20305
|
makeCacheKey as makeCacheKey11,
|
|
20304
|
-
logger as
|
|
20306
|
+
logger as logger15
|
|
20305
20307
|
} from "@eeplatform/nodejs-utils";
|
|
20306
20308
|
|
|
20307
20309
|
// src/models/address.model.ts
|
|
@@ -20358,15 +20360,15 @@ function useAddressRepo() {
|
|
|
20358
20360
|
}
|
|
20359
20361
|
const namespace_collection = "addresses";
|
|
20360
20362
|
const collection = db.collection(namespace_collection);
|
|
20361
|
-
const { getCache, setCache, delNamespace } =
|
|
20363
|
+
const { getCache, setCache, delNamespace } = useCache12(namespace_collection);
|
|
20362
20364
|
function delCachedData() {
|
|
20363
|
-
delNamespace(
|
|
20364
|
-
|
|
20365
|
+
delNamespace().then(() => {
|
|
20366
|
+
logger15.log({
|
|
20365
20367
|
level: "info",
|
|
20366
20368
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
20367
20369
|
});
|
|
20368
20370
|
}).catch((err) => {
|
|
20369
|
-
|
|
20371
|
+
logger15.log({
|
|
20370
20372
|
level: "error",
|
|
20371
20373
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
20372
20374
|
});
|
|
@@ -20428,7 +20430,7 @@ function useAddressRepo() {
|
|
|
20428
20430
|
try {
|
|
20429
20431
|
const cached = await getCache(cacheKey);
|
|
20430
20432
|
if (cached) {
|
|
20431
|
-
|
|
20433
|
+
logger15.log({
|
|
20432
20434
|
level: "info",
|
|
20433
20435
|
message: `Cache hit for getByUserId address: ${cacheKey}`
|
|
20434
20436
|
});
|
|
@@ -20436,13 +20438,13 @@ function useAddressRepo() {
|
|
|
20436
20438
|
}
|
|
20437
20439
|
const data = await collection.findOne({ user });
|
|
20438
20440
|
if (data) {
|
|
20439
|
-
setCache(cacheKey, data, 300
|
|
20440
|
-
|
|
20441
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
20442
|
+
logger15.log({
|
|
20441
20443
|
level: "info",
|
|
20442
20444
|
message: `Cache set for address by user ID: ${cacheKey}`
|
|
20443
20445
|
});
|
|
20444
20446
|
}).catch((err) => {
|
|
20445
|
-
|
|
20447
|
+
logger15.log({
|
|
20446
20448
|
level: "error",
|
|
20447
20449
|
message: `Failed to set cache for address by user ID: ${err.message}`
|
|
20448
20450
|
});
|
|
@@ -20463,7 +20465,7 @@ function useAddressRepo() {
|
|
|
20463
20465
|
try {
|
|
20464
20466
|
const cached = await getCache(cacheKey);
|
|
20465
20467
|
if (cached) {
|
|
20466
|
-
|
|
20468
|
+
logger15.log({
|
|
20467
20469
|
level: "info",
|
|
20468
20470
|
message: `Cache hit for getByOrgId address: ${cacheKey}`
|
|
20469
20471
|
});
|
|
@@ -20471,13 +20473,13 @@ function useAddressRepo() {
|
|
|
20471
20473
|
}
|
|
20472
20474
|
const data = await collection.findOne({ org });
|
|
20473
20475
|
if (data) {
|
|
20474
|
-
setCache(cacheKey, data, 300
|
|
20475
|
-
|
|
20476
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
20477
|
+
logger15.log({
|
|
20476
20478
|
level: "info",
|
|
20477
20479
|
message: `Cache set for address by org ID: ${cacheKey}`
|
|
20478
20480
|
});
|
|
20479
20481
|
}).catch((err) => {
|
|
20480
|
-
|
|
20482
|
+
logger15.log({
|
|
20481
20483
|
level: "error",
|
|
20482
20484
|
message: `Failed to set cache for address by org ID: ${err.message}`
|
|
20483
20485
|
});
|
|
@@ -20501,11 +20503,11 @@ function useAddressRepo() {
|
|
|
20501
20503
|
import {
|
|
20502
20504
|
BadRequestError as BadRequestError26,
|
|
20503
20505
|
InternalServerError as InternalServerError17,
|
|
20504
|
-
logger as
|
|
20506
|
+
logger as logger16,
|
|
20505
20507
|
makeCacheKey as makeCacheKey12,
|
|
20506
20508
|
paginate as paginate8,
|
|
20507
20509
|
useAtlas as useAtlas14,
|
|
20508
|
-
useCache as
|
|
20510
|
+
useCache as useCache13
|
|
20509
20511
|
} from "@eeplatform/nodejs-utils";
|
|
20510
20512
|
|
|
20511
20513
|
// src/validations/promo-code.schema.ts
|
|
@@ -20565,15 +20567,15 @@ function usePromoCodeRepo() {
|
|
|
20565
20567
|
}
|
|
20566
20568
|
const namespace_collection = "promo-codes";
|
|
20567
20569
|
const collection = db.collection(namespace_collection);
|
|
20568
|
-
const { getCache, setCache, delNamespace } =
|
|
20570
|
+
const { getCache, setCache, delNamespace } = useCache13(namespace_collection);
|
|
20569
20571
|
function delCachedData() {
|
|
20570
|
-
delNamespace(
|
|
20571
|
-
|
|
20572
|
+
delNamespace().then(() => {
|
|
20573
|
+
logger16.log({
|
|
20572
20574
|
level: "info",
|
|
20573
20575
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
20574
20576
|
});
|
|
20575
20577
|
}).catch((err) => {
|
|
20576
|
-
|
|
20578
|
+
logger16.log({
|
|
20577
20579
|
level: "error",
|
|
20578
20580
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
20579
20581
|
});
|
|
@@ -20606,7 +20608,7 @@ function usePromoCodeRepo() {
|
|
|
20606
20608
|
await collection.insertOne(value);
|
|
20607
20609
|
delCachedData();
|
|
20608
20610
|
} catch (error) {
|
|
20609
|
-
|
|
20611
|
+
logger16.log({ level: "error", message: `${error}` });
|
|
20610
20612
|
const isDuplicated = error.message.includes("duplicate");
|
|
20611
20613
|
if (isDuplicated) {
|
|
20612
20614
|
throw new BadRequestError26("Promo code already exists.");
|
|
@@ -20639,7 +20641,7 @@ function usePromoCodeRepo() {
|
|
|
20639
20641
|
try {
|
|
20640
20642
|
const cached = await getCache(cacheKey);
|
|
20641
20643
|
if (cached) {
|
|
20642
|
-
|
|
20644
|
+
logger16.log({
|
|
20643
20645
|
level: "info",
|
|
20644
20646
|
message: `Cache hit for getByCode promo code: ${cacheKey}`
|
|
20645
20647
|
});
|
|
@@ -20647,13 +20649,13 @@ function usePromoCodeRepo() {
|
|
|
20647
20649
|
}
|
|
20648
20650
|
const data = await collection.findOne(query);
|
|
20649
20651
|
if (data) {
|
|
20650
|
-
setCache(cacheKey, data, 300
|
|
20651
|
-
|
|
20652
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
20653
|
+
logger16.log({
|
|
20652
20654
|
level: "info",
|
|
20653
20655
|
message: `Cache set for promo code by code: ${cacheKey}`
|
|
20654
20656
|
});
|
|
20655
20657
|
}).catch((err) => {
|
|
20656
|
-
|
|
20658
|
+
logger16.log({
|
|
20657
20659
|
level: "error",
|
|
20658
20660
|
message: `Failed to set cache for promo code by code: ${err.message}`
|
|
20659
20661
|
});
|
|
@@ -20681,7 +20683,7 @@ function usePromoCodeRepo() {
|
|
|
20681
20683
|
try {
|
|
20682
20684
|
const cached = await getCache(cacheKey);
|
|
20683
20685
|
if (cached) {
|
|
20684
|
-
|
|
20686
|
+
logger16.log({
|
|
20685
20687
|
level: "info",
|
|
20686
20688
|
message: `Cache hit for getById promo code: ${cacheKey}`
|
|
20687
20689
|
});
|
|
@@ -20689,13 +20691,13 @@ function usePromoCodeRepo() {
|
|
|
20689
20691
|
}
|
|
20690
20692
|
const data = await collection.findOne({ _id });
|
|
20691
20693
|
if (data) {
|
|
20692
|
-
setCache(cacheKey, data, 300
|
|
20693
|
-
|
|
20694
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
20695
|
+
logger16.log({
|
|
20694
20696
|
level: "info",
|
|
20695
20697
|
message: `Cache set for promo code by ID: ${cacheKey}`
|
|
20696
20698
|
});
|
|
20697
20699
|
}).catch((err) => {
|
|
20698
|
-
|
|
20700
|
+
logger16.log({
|
|
20699
20701
|
level: "error",
|
|
20700
20702
|
message: `Failed to set cache for promo code by ID: ${err.message}`
|
|
20701
20703
|
});
|
|
@@ -20734,7 +20736,7 @@ function usePromoCodeRepo() {
|
|
|
20734
20736
|
try {
|
|
20735
20737
|
const cached = await getCache(cacheKey);
|
|
20736
20738
|
if (cached) {
|
|
20737
|
-
|
|
20739
|
+
logger16.log({
|
|
20738
20740
|
level: "info",
|
|
20739
20741
|
message: `Cache hit for getPromoCodes: ${cacheKey}`
|
|
20740
20742
|
});
|
|
@@ -20748,20 +20750,20 @@ function usePromoCodeRepo() {
|
|
|
20748
20750
|
]).toArray();
|
|
20749
20751
|
const length = await collection.countDocuments(query);
|
|
20750
20752
|
const data = paginate8(items, page, limit, length);
|
|
20751
|
-
setCache(cacheKey, data, 600
|
|
20752
|
-
|
|
20753
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
20754
|
+
logger16.log({
|
|
20753
20755
|
level: "info",
|
|
20754
20756
|
message: `Cache set for getPromoCodes: ${cacheKey}`
|
|
20755
20757
|
});
|
|
20756
20758
|
}).catch((err) => {
|
|
20757
|
-
|
|
20759
|
+
logger16.log({
|
|
20758
20760
|
level: "error",
|
|
20759
20761
|
message: `Failed to set cache for getPromoCodes: ${err.message}`
|
|
20760
20762
|
});
|
|
20761
20763
|
});
|
|
20762
20764
|
return data;
|
|
20763
20765
|
} catch (error) {
|
|
20764
|
-
|
|
20766
|
+
logger16.log({ level: "error", message: `${error}` });
|
|
20765
20767
|
throw new InternalServerError17("Internal server error.");
|
|
20766
20768
|
}
|
|
20767
20769
|
}
|
|
@@ -20808,7 +20810,7 @@ import Joi15 from "joi";
|
|
|
20808
20810
|
import {
|
|
20809
20811
|
BadRequestError as BadRequestError28,
|
|
20810
20812
|
InternalServerError as InternalServerError18,
|
|
20811
|
-
logger as
|
|
20813
|
+
logger as logger17,
|
|
20812
20814
|
paginate as paginate9,
|
|
20813
20815
|
useAtlas as useAtlas15
|
|
20814
20816
|
} from "@eeplatform/nodejs-utils";
|
|
@@ -20943,7 +20945,7 @@ function useInvoiceRepo() {
|
|
|
20943
20945
|
value = createInvoice(value);
|
|
20944
20946
|
await collection.insertOne(value, { session });
|
|
20945
20947
|
} catch (error) {
|
|
20946
|
-
|
|
20948
|
+
logger17.log({ level: "error", message: `${error}` });
|
|
20947
20949
|
const isDuplicated = error.message.includes("duplicate");
|
|
20948
20950
|
if (isDuplicated) {
|
|
20949
20951
|
throw new BadRequestError28("Invoice already exists.");
|
|
@@ -21078,9 +21080,9 @@ function useInvoiceRepo() {
|
|
|
21078
21080
|
// src/repositories/counter.repository.ts
|
|
21079
21081
|
import {
|
|
21080
21082
|
useAtlas as useAtlas16,
|
|
21081
|
-
useCache as
|
|
21083
|
+
useCache as useCache14,
|
|
21082
21084
|
makeCacheKey as makeCacheKey13,
|
|
21083
|
-
logger as
|
|
21085
|
+
logger as logger18
|
|
21084
21086
|
} from "@eeplatform/nodejs-utils";
|
|
21085
21087
|
|
|
21086
21088
|
// src/models/counter.model.ts
|
|
@@ -21125,15 +21127,15 @@ function useCounterRepo() {
|
|
|
21125
21127
|
}
|
|
21126
21128
|
const namespace_collection = "counters";
|
|
21127
21129
|
const { collection, createCounter } = useCounterModel(db);
|
|
21128
|
-
const { getCache, setCache, delNamespace } =
|
|
21130
|
+
const { getCache, setCache, delNamespace } = useCache14(namespace_collection);
|
|
21129
21131
|
function delCachedData() {
|
|
21130
|
-
delNamespace(
|
|
21131
|
-
|
|
21132
|
+
delNamespace().then(() => {
|
|
21133
|
+
logger18.log({
|
|
21132
21134
|
level: "info",
|
|
21133
21135
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
21134
21136
|
});
|
|
21135
21137
|
}).catch((err) => {
|
|
21136
|
-
|
|
21138
|
+
logger18.log({
|
|
21137
21139
|
level: "error",
|
|
21138
21140
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
21139
21141
|
});
|
|
@@ -21189,7 +21191,7 @@ function useCounterRepo() {
|
|
|
21189
21191
|
try {
|
|
21190
21192
|
const cached = await getCache(cacheKey);
|
|
21191
21193
|
if (cached) {
|
|
21192
|
-
|
|
21194
|
+
logger18.log({
|
|
21193
21195
|
level: "info",
|
|
21194
21196
|
message: `Cache hit for getByType counter: ${cacheKey}`
|
|
21195
21197
|
});
|
|
@@ -21197,13 +21199,13 @@ function useCounterRepo() {
|
|
|
21197
21199
|
}
|
|
21198
21200
|
const data = await collection.findOne({ type });
|
|
21199
21201
|
if (data) {
|
|
21200
|
-
setCache(cacheKey, data, 300
|
|
21201
|
-
|
|
21202
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
21203
|
+
logger18.log({
|
|
21202
21204
|
level: "info",
|
|
21203
21205
|
message: `Cache set for counter by type: ${cacheKey}`
|
|
21204
21206
|
});
|
|
21205
21207
|
}).catch((err) => {
|
|
21206
|
-
|
|
21208
|
+
logger18.log({
|
|
21207
21209
|
level: "error",
|
|
21208
21210
|
message: `Failed to set cache for counter by type: ${err.message}`
|
|
21209
21211
|
});
|
|
@@ -21227,7 +21229,7 @@ function useCounterRepo() {
|
|
|
21227
21229
|
import {
|
|
21228
21230
|
BadRequestError as BadRequestError30,
|
|
21229
21231
|
InternalServerError as InternalServerError19,
|
|
21230
|
-
logger as
|
|
21232
|
+
logger as logger19,
|
|
21231
21233
|
paginate as paginate10,
|
|
21232
21234
|
useAtlas as useAtlas17
|
|
21233
21235
|
} from "@eeplatform/nodejs-utils";
|
|
@@ -21272,7 +21274,7 @@ function usePaymentRepo() {
|
|
|
21272
21274
|
value = createPayment(value);
|
|
21273
21275
|
await collection.insertOne(value, { session });
|
|
21274
21276
|
} catch (error) {
|
|
21275
|
-
|
|
21277
|
+
logger19.log({ level: "error", message: `${error}` });
|
|
21276
21278
|
const isDuplicated = error.message.includes("duplicate");
|
|
21277
21279
|
if (isDuplicated) {
|
|
21278
21280
|
throw new BadRequestError30("Payment already exists.");
|
|
@@ -21317,7 +21319,7 @@ function usePaymentRepo() {
|
|
|
21317
21319
|
const length = await collection.countDocuments(query);
|
|
21318
21320
|
return paginate10(items, page, limit, length);
|
|
21319
21321
|
} catch (error) {
|
|
21320
|
-
|
|
21322
|
+
logger19.log({ level: "error", message: `${error}` });
|
|
21321
21323
|
throw new InternalServerError19("Internal server error.");
|
|
21322
21324
|
}
|
|
21323
21325
|
}
|
|
@@ -21345,9 +21347,9 @@ function usePaymentRepo() {
|
|
|
21345
21347
|
// src/repositories/price.repository.ts
|
|
21346
21348
|
import {
|
|
21347
21349
|
useAtlas as useAtlas18,
|
|
21348
|
-
useCache as
|
|
21350
|
+
useCache as useCache15,
|
|
21349
21351
|
makeCacheKey as makeCacheKey14,
|
|
21350
|
-
logger as
|
|
21352
|
+
logger as logger20
|
|
21351
21353
|
} from "@eeplatform/nodejs-utils";
|
|
21352
21354
|
|
|
21353
21355
|
// src/models/price.model.ts
|
|
@@ -21401,15 +21403,15 @@ function usePriceRepo() {
|
|
|
21401
21403
|
}
|
|
21402
21404
|
const namespace_collection = "prices";
|
|
21403
21405
|
const { collection, createPrice } = usePriceModel(db);
|
|
21404
|
-
const { getCache, setCache, delNamespace } =
|
|
21406
|
+
const { getCache, setCache, delNamespace } = useCache15(namespace_collection);
|
|
21405
21407
|
function delCachedData() {
|
|
21406
|
-
delNamespace(
|
|
21407
|
-
|
|
21408
|
+
delNamespace().then(() => {
|
|
21409
|
+
logger20.log({
|
|
21408
21410
|
level: "info",
|
|
21409
21411
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
21410
21412
|
});
|
|
21411
21413
|
}).catch((err) => {
|
|
21412
|
-
|
|
21414
|
+
logger20.log({
|
|
21413
21415
|
level: "error",
|
|
21414
21416
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
21415
21417
|
});
|
|
@@ -21465,7 +21467,7 @@ function usePriceRepo() {
|
|
|
21465
21467
|
try {
|
|
21466
21468
|
const cached = await getCache(cacheKey);
|
|
21467
21469
|
if (cached) {
|
|
21468
|
-
|
|
21470
|
+
logger20.log({
|
|
21469
21471
|
level: "info",
|
|
21470
21472
|
message: `Cache hit for getByNameType price: ${cacheKey}`
|
|
21471
21473
|
});
|
|
@@ -21473,13 +21475,13 @@ function usePriceRepo() {
|
|
|
21473
21475
|
}
|
|
21474
21476
|
const data = await collection.findOne({ name, type });
|
|
21475
21477
|
if (data) {
|
|
21476
|
-
setCache(cacheKey, data, 300
|
|
21477
|
-
|
|
21478
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
21479
|
+
logger20.log({
|
|
21478
21480
|
level: "info",
|
|
21479
21481
|
message: `Cache set for price by name and type: ${cacheKey}`
|
|
21480
21482
|
});
|
|
21481
21483
|
}).catch((err) => {
|
|
21482
|
-
|
|
21484
|
+
logger20.log({
|
|
21483
21485
|
level: "error",
|
|
21484
21486
|
message: `Failed to set cache for price by name and type: ${err.message}`
|
|
21485
21487
|
});
|
|
@@ -22251,7 +22253,7 @@ function useSubscriptionService() {
|
|
|
22251
22253
|
while (true) {
|
|
22252
22254
|
const subscriptions = await getDueSubscriptions(batchSize);
|
|
22253
22255
|
if (subscriptions.length === 0) {
|
|
22254
|
-
|
|
22256
|
+
logger21.log({
|
|
22255
22257
|
level: "info",
|
|
22256
22258
|
message: "No more subscriptions to process."
|
|
22257
22259
|
});
|
|
@@ -22391,14 +22393,14 @@ function useSubscriptionService() {
|
|
|
22391
22393
|
);
|
|
22392
22394
|
await session?.commitTransaction();
|
|
22393
22395
|
}
|
|
22394
|
-
|
|
22396
|
+
logger21.log({
|
|
22395
22397
|
level: "info",
|
|
22396
22398
|
message: `Processed subscription ${sub._id} successfully.`
|
|
22397
22399
|
});
|
|
22398
22400
|
return;
|
|
22399
22401
|
} catch (error) {
|
|
22400
22402
|
await session?.abortTransaction();
|
|
22401
|
-
|
|
22403
|
+
logger21.log({
|
|
22402
22404
|
level: "error",
|
|
22403
22405
|
message: `Failed to process ${sub._id}: ${error}`
|
|
22404
22406
|
});
|
|
@@ -22410,7 +22412,7 @@ function useSubscriptionService() {
|
|
|
22410
22412
|
}
|
|
22411
22413
|
})
|
|
22412
22414
|
);
|
|
22413
|
-
|
|
22415
|
+
logger21.log({
|
|
22414
22416
|
level: "info",
|
|
22415
22417
|
message: "Processed a batch of subscriptions."
|
|
22416
22418
|
});
|
|
@@ -22707,7 +22709,7 @@ function useSubscriptionService() {
|
|
|
22707
22709
|
await session?.commitTransaction();
|
|
22708
22710
|
} catch (error2) {
|
|
22709
22711
|
await session?.abortTransaction();
|
|
22710
|
-
|
|
22712
|
+
logger21.log({
|
|
22711
22713
|
level: "error",
|
|
22712
22714
|
message: `Failed to update subscription seats: ${error2}`
|
|
22713
22715
|
});
|
|
@@ -22908,7 +22910,7 @@ function useSubscriptionService() {
|
|
|
22908
22910
|
await session?.commitTransaction();
|
|
22909
22911
|
} catch (error2) {
|
|
22910
22912
|
await session?.abortTransaction();
|
|
22911
|
-
|
|
22913
|
+
logger21.log({
|
|
22912
22914
|
level: "error",
|
|
22913
22915
|
message: `Failed to update subscription seats: ${error2}`
|
|
22914
22916
|
});
|
|
@@ -23009,7 +23011,7 @@ function useSubscriptionService() {
|
|
|
23009
23011
|
await session?.commitTransaction();
|
|
23010
23012
|
} catch (error) {
|
|
23011
23013
|
await session?.abortTransaction();
|
|
23012
|
-
|
|
23014
|
+
logger21.log({
|
|
23013
23015
|
level: "error",
|
|
23014
23016
|
message: `Failed to process subscription payment: ${error}`
|
|
23015
23017
|
});
|
|
@@ -23512,7 +23514,7 @@ function MPaymentMethod(value) {
|
|
|
23512
23514
|
import {
|
|
23513
23515
|
BadRequestError as BadRequestError36,
|
|
23514
23516
|
InternalServerError as InternalServerError20,
|
|
23515
|
-
logger as
|
|
23517
|
+
logger as logger22,
|
|
23516
23518
|
useAtlas as useAtlas20
|
|
23517
23519
|
} from "@eeplatform/nodejs-utils";
|
|
23518
23520
|
import { ObjectId as ObjectId30 } from "mongodb";
|
|
@@ -23558,7 +23560,7 @@ function usePaymentMethodRepo() {
|
|
|
23558
23560
|
await collection.insertOne(value, { session });
|
|
23559
23561
|
return "Successfully added payment method.";
|
|
23560
23562
|
} catch (error) {
|
|
23561
|
-
|
|
23563
|
+
logger22.log({ level: "error", message: `${error}` });
|
|
23562
23564
|
const isDuplicated = error.message.includes("duplicate");
|
|
23563
23565
|
if (isDuplicated) {
|
|
23564
23566
|
throw new BadRequestError36("Payment method already exist.");
|
|
@@ -24731,11 +24733,11 @@ import {
|
|
|
24731
24733
|
AppError as AppError11,
|
|
24732
24734
|
BadRequestError as BadRequestError44,
|
|
24733
24735
|
InternalServerError as InternalServerError22,
|
|
24734
|
-
logger as
|
|
24736
|
+
logger as logger23,
|
|
24735
24737
|
makeCacheKey as makeCacheKey15,
|
|
24736
24738
|
paginate as paginate11,
|
|
24737
24739
|
useAtlas as useAtlas23,
|
|
24738
|
-
useCache as
|
|
24740
|
+
useCache as useCache16
|
|
24739
24741
|
} from "@eeplatform/nodejs-utils";
|
|
24740
24742
|
import { ObjectId as ObjectId32 } from "mongodb";
|
|
24741
24743
|
function useOrderRepo() {
|
|
@@ -24745,15 +24747,15 @@ function useOrderRepo() {
|
|
|
24745
24747
|
}
|
|
24746
24748
|
const namespace_collection = "orders";
|
|
24747
24749
|
const collection = db.collection(namespace_collection);
|
|
24748
|
-
const { getCache, setCache, delNamespace } =
|
|
24750
|
+
const { getCache, setCache, delNamespace } = useCache16(namespace_collection);
|
|
24749
24751
|
function delCachedData() {
|
|
24750
|
-
delNamespace(
|
|
24751
|
-
|
|
24752
|
+
delNamespace().then(() => {
|
|
24753
|
+
logger23.log({
|
|
24752
24754
|
level: "info",
|
|
24753
24755
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
24754
24756
|
});
|
|
24755
24757
|
}).catch((err) => {
|
|
24756
|
-
|
|
24758
|
+
logger23.log({
|
|
24757
24759
|
level: "error",
|
|
24758
24760
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
24759
24761
|
});
|
|
@@ -24776,7 +24778,7 @@ function useOrderRepo() {
|
|
|
24776
24778
|
collection.insertOne(value, { session });
|
|
24777
24779
|
delCachedData();
|
|
24778
24780
|
} catch (error) {
|
|
24779
|
-
|
|
24781
|
+
logger23.log({ level: "error", message: `${error}` });
|
|
24780
24782
|
if (error instanceof AppError11) {
|
|
24781
24783
|
throw error;
|
|
24782
24784
|
}
|
|
@@ -24820,7 +24822,7 @@ function useOrderRepo() {
|
|
|
24820
24822
|
try {
|
|
24821
24823
|
const cached = await getCache(cacheKey);
|
|
24822
24824
|
if (cached) {
|
|
24823
|
-
|
|
24825
|
+
logger23.log({
|
|
24824
24826
|
level: "info",
|
|
24825
24827
|
message: `Cache hit for getOrders: ${cacheKey}`
|
|
24826
24828
|
});
|
|
@@ -24834,20 +24836,20 @@ function useOrderRepo() {
|
|
|
24834
24836
|
]).toArray();
|
|
24835
24837
|
const length = await collection.countDocuments(query);
|
|
24836
24838
|
const data = paginate11(items, page, limit, length);
|
|
24837
|
-
setCache(cacheKey, data, 600
|
|
24838
|
-
|
|
24839
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
24840
|
+
logger23.log({
|
|
24839
24841
|
level: "info",
|
|
24840
24842
|
message: `Cache set for getOrders: ${cacheKey}`
|
|
24841
24843
|
});
|
|
24842
24844
|
}).catch((err) => {
|
|
24843
|
-
|
|
24845
|
+
logger23.log({
|
|
24844
24846
|
level: "error",
|
|
24845
24847
|
message: `Failed to set cache for getOrders: ${err.message}`
|
|
24846
24848
|
});
|
|
24847
24849
|
});
|
|
24848
24850
|
return data;
|
|
24849
24851
|
} catch (error) {
|
|
24850
|
-
|
|
24852
|
+
logger23.log({ level: "error", message: `${error}` });
|
|
24851
24853
|
throw new InternalServerError22("Internal server error.");
|
|
24852
24854
|
}
|
|
24853
24855
|
}
|
|
@@ -24903,7 +24905,7 @@ function useOrderController() {
|
|
|
24903
24905
|
// src/services/invoice.service.ts
|
|
24904
24906
|
import {
|
|
24905
24907
|
BadRequestError as BadRequestError46,
|
|
24906
|
-
logger as
|
|
24908
|
+
logger as logger24,
|
|
24907
24909
|
NotFoundError as NotFoundError7,
|
|
24908
24910
|
useAtlas as useAtlas24
|
|
24909
24911
|
} from "@eeplatform/nodejs-utils";
|
|
@@ -24925,7 +24927,7 @@ function useInvoiceService() {
|
|
|
24925
24927
|
while (true) {
|
|
24926
24928
|
const overdueInvoices = await getOverdueInvoices(BATCH_SIZE);
|
|
24927
24929
|
if (!overdueInvoices.length) {
|
|
24928
|
-
|
|
24930
|
+
logger24.log({
|
|
24929
24931
|
level: "info",
|
|
24930
24932
|
message: "No overdue invoices found."
|
|
24931
24933
|
});
|
|
@@ -24935,21 +24937,21 @@ function useInvoiceService() {
|
|
|
24935
24937
|
overdueInvoices.map(async (invoice) => {
|
|
24936
24938
|
const session = useAtlas24.getClient()?.startSession();
|
|
24937
24939
|
if (!session) {
|
|
24938
|
-
|
|
24940
|
+
logger24.log({
|
|
24939
24941
|
level: "error",
|
|
24940
24942
|
message: "Failed to start session."
|
|
24941
24943
|
});
|
|
24942
24944
|
return;
|
|
24943
24945
|
}
|
|
24944
24946
|
if (!invoice._id) {
|
|
24945
|
-
|
|
24947
|
+
logger24.log({
|
|
24946
24948
|
level: "error",
|
|
24947
24949
|
message: "Invoice ID is missing."
|
|
24948
24950
|
});
|
|
24949
24951
|
return;
|
|
24950
24952
|
}
|
|
24951
24953
|
if (!invoice.metadata?.subscriptionId) {
|
|
24952
|
-
|
|
24954
|
+
logger24.log({
|
|
24953
24955
|
level: "error",
|
|
24954
24956
|
message: "Subscription ID is missing."
|
|
24955
24957
|
});
|
|
@@ -24959,14 +24961,14 @@ function useInvoiceService() {
|
|
|
24959
24961
|
invoice.metadata.subscriptionId
|
|
24960
24962
|
).catch(() => null);
|
|
24961
24963
|
if (!subscription) {
|
|
24962
|
-
|
|
24964
|
+
logger24.log({
|
|
24963
24965
|
level: "error",
|
|
24964
24966
|
message: "Subscription not found."
|
|
24965
24967
|
});
|
|
24966
24968
|
return;
|
|
24967
24969
|
}
|
|
24968
24970
|
if (!subscription._id) {
|
|
24969
|
-
|
|
24971
|
+
logger24.log({
|
|
24970
24972
|
level: "error",
|
|
24971
24973
|
message: "Subscription ID is missing."
|
|
24972
24974
|
});
|
|
@@ -25046,7 +25048,7 @@ function useInvoiceService() {
|
|
|
25046
25048
|
return;
|
|
25047
25049
|
}
|
|
25048
25050
|
} catch (error) {
|
|
25049
|
-
|
|
25051
|
+
logger24.log({
|
|
25050
25052
|
level: "error",
|
|
25051
25053
|
message: String(error)
|
|
25052
25054
|
});
|
|
@@ -25056,7 +25058,7 @@ function useInvoiceService() {
|
|
|
25056
25058
|
}
|
|
25057
25059
|
})
|
|
25058
25060
|
);
|
|
25059
|
-
|
|
25061
|
+
logger24.log({
|
|
25060
25062
|
level: "info",
|
|
25061
25063
|
message: "Successfully processed overdue invoices."
|
|
25062
25064
|
});
|
|
@@ -25068,7 +25070,7 @@ function useInvoiceService() {
|
|
|
25068
25070
|
}
|
|
25069
25071
|
const session = useAtlas24.getClient()?.startSession();
|
|
25070
25072
|
if (!session) {
|
|
25071
|
-
|
|
25073
|
+
logger24.log({
|
|
25072
25074
|
level: "error",
|
|
25073
25075
|
message: "Failed to start session."
|
|
25074
25076
|
});
|
|
@@ -25137,7 +25139,7 @@ function useInvoiceService() {
|
|
|
25137
25139
|
return "Payment processed successfully.";
|
|
25138
25140
|
} catch (error) {
|
|
25139
25141
|
session.abortTransaction();
|
|
25140
|
-
|
|
25142
|
+
logger24.log({
|
|
25141
25143
|
level: "error",
|
|
25142
25144
|
message: String(error)
|
|
25143
25145
|
});
|
|
@@ -25384,11 +25386,11 @@ import {
|
|
|
25384
25386
|
AppError as AppError12,
|
|
25385
25387
|
BadRequestError as BadRequestError51,
|
|
25386
25388
|
InternalServerError as InternalServerError23,
|
|
25387
|
-
logger as
|
|
25389
|
+
logger as logger25,
|
|
25388
25390
|
makeCacheKey as makeCacheKey16,
|
|
25389
25391
|
paginate as paginate12,
|
|
25390
25392
|
useAtlas as useAtlas25,
|
|
25391
|
-
useCache as
|
|
25393
|
+
useCache as useCache17
|
|
25392
25394
|
} from "@eeplatform/nodejs-utils";
|
|
25393
25395
|
import { ObjectId as ObjectId34 } from "mongodb";
|
|
25394
25396
|
function useRegionRepo() {
|
|
@@ -25398,7 +25400,7 @@ function useRegionRepo() {
|
|
|
25398
25400
|
}
|
|
25399
25401
|
const namespace_collection = "regions";
|
|
25400
25402
|
const collection = db.collection(namespace_collection);
|
|
25401
|
-
const { getCache, setCache, delNamespace } =
|
|
25403
|
+
const { getCache, setCache, delNamespace } = useCache17(namespace_collection);
|
|
25402
25404
|
async function createIndex() {
|
|
25403
25405
|
try {
|
|
25404
25406
|
await collection.createIndex([
|
|
@@ -25435,13 +25437,13 @@ function useRegionRepo() {
|
|
|
25435
25437
|
}
|
|
25436
25438
|
}
|
|
25437
25439
|
function delCachedData() {
|
|
25438
|
-
delNamespace(
|
|
25439
|
-
|
|
25440
|
+
delNamespace().then(() => {
|
|
25441
|
+
logger25.log({
|
|
25440
25442
|
level: "info",
|
|
25441
25443
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
25442
25444
|
});
|
|
25443
25445
|
}).catch((err) => {
|
|
25444
|
-
|
|
25446
|
+
logger25.log({
|
|
25445
25447
|
level: "error",
|
|
25446
25448
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
25447
25449
|
});
|
|
@@ -25454,7 +25456,7 @@ function useRegionRepo() {
|
|
|
25454
25456
|
delCachedData();
|
|
25455
25457
|
return res.insertedId;
|
|
25456
25458
|
} catch (error) {
|
|
25457
|
-
|
|
25459
|
+
logger25.log({
|
|
25458
25460
|
level: "error",
|
|
25459
25461
|
message: error.message
|
|
25460
25462
|
});
|
|
@@ -25482,14 +25484,14 @@ function useRegionRepo() {
|
|
|
25482
25484
|
limit,
|
|
25483
25485
|
sort: JSON.stringify(sort)
|
|
25484
25486
|
});
|
|
25485
|
-
|
|
25487
|
+
logger25.log({
|
|
25486
25488
|
level: "info",
|
|
25487
25489
|
message: `Cache key for getAll regions: ${cacheKey}`
|
|
25488
25490
|
});
|
|
25489
25491
|
try {
|
|
25490
25492
|
const cached = await getCache(cacheKey);
|
|
25491
25493
|
if (cached) {
|
|
25492
|
-
|
|
25494
|
+
logger25.log({
|
|
25493
25495
|
level: "info",
|
|
25494
25496
|
message: `Cache hit for getAll regions: ${cacheKey}`
|
|
25495
25497
|
});
|
|
@@ -25513,20 +25515,20 @@ function useRegionRepo() {
|
|
|
25513
25515
|
]).toArray();
|
|
25514
25516
|
const length = await collection.countDocuments(query);
|
|
25515
25517
|
const data = paginate12(items, page, limit, length);
|
|
25516
|
-
setCache(cacheKey, data, 600
|
|
25517
|
-
|
|
25518
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
25519
|
+
logger25.log({
|
|
25518
25520
|
level: "info",
|
|
25519
25521
|
message: `Cache set for getAll regions: ${cacheKey}`
|
|
25520
25522
|
});
|
|
25521
25523
|
}).catch((err) => {
|
|
25522
|
-
|
|
25524
|
+
logger25.log({
|
|
25523
25525
|
level: "error",
|
|
25524
25526
|
message: `Failed to set cache for getAll regions: ${err.message}`
|
|
25525
25527
|
});
|
|
25526
25528
|
});
|
|
25527
25529
|
return data;
|
|
25528
25530
|
} catch (error) {
|
|
25529
|
-
|
|
25531
|
+
logger25.log({ level: "error", message: `${error}` });
|
|
25530
25532
|
throw error;
|
|
25531
25533
|
}
|
|
25532
25534
|
}
|
|
@@ -25540,7 +25542,7 @@ function useRegionRepo() {
|
|
|
25540
25542
|
try {
|
|
25541
25543
|
const cached = await getCache(cacheKey);
|
|
25542
25544
|
if (cached) {
|
|
25543
|
-
|
|
25545
|
+
logger25.log({
|
|
25544
25546
|
level: "info",
|
|
25545
25547
|
message: `Cache hit for getById region: ${cacheKey}`
|
|
25546
25548
|
});
|
|
@@ -25553,13 +25555,13 @@ function useRegionRepo() {
|
|
|
25553
25555
|
if (!result) {
|
|
25554
25556
|
throw new BadRequestError51("Region not found.");
|
|
25555
25557
|
}
|
|
25556
|
-
setCache(cacheKey, result, 300
|
|
25557
|
-
|
|
25558
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
25559
|
+
logger25.log({
|
|
25558
25560
|
level: "info",
|
|
25559
25561
|
message: `Cache set for region by id: ${cacheKey}`
|
|
25560
25562
|
});
|
|
25561
25563
|
}).catch((err) => {
|
|
25562
|
-
|
|
25564
|
+
logger25.log({
|
|
25563
25565
|
level: "error",
|
|
25564
25566
|
message: `Failed to set cache for region by id: ${err.message}`
|
|
25565
25567
|
});
|
|
@@ -25578,7 +25580,7 @@ function useRegionRepo() {
|
|
|
25578
25580
|
try {
|
|
25579
25581
|
const cached = await getCache(cacheKey);
|
|
25580
25582
|
if (cached) {
|
|
25581
|
-
|
|
25583
|
+
logger25.log({
|
|
25582
25584
|
level: "info",
|
|
25583
25585
|
message: `Cache hit for getByName region: ${cacheKey}`
|
|
25584
25586
|
});
|
|
@@ -25591,13 +25593,13 @@ function useRegionRepo() {
|
|
|
25591
25593
|
if (!result) {
|
|
25592
25594
|
throw new BadRequestError51("Region not found.");
|
|
25593
25595
|
}
|
|
25594
|
-
setCache(cacheKey, result, 300
|
|
25595
|
-
|
|
25596
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
25597
|
+
logger25.log({
|
|
25596
25598
|
level: "info",
|
|
25597
25599
|
message: `Cache set for region by name: ${cacheKey}`
|
|
25598
25600
|
});
|
|
25599
25601
|
}).catch((err) => {
|
|
25600
|
-
|
|
25602
|
+
logger25.log({
|
|
25601
25603
|
level: "error",
|
|
25602
25604
|
message: `Failed to set cache for region by name: ${err.message}`
|
|
25603
25605
|
});
|
|
@@ -25665,10 +25667,6 @@ function useRegionRepo() {
|
|
|
25665
25667
|
};
|
|
25666
25668
|
}
|
|
25667
25669
|
|
|
25668
|
-
// src/controllers/region.controller.ts
|
|
25669
|
-
import { BadRequestError as BadRequestError52 } from "@eeplatform/nodejs-utils";
|
|
25670
|
-
import Joi28 from "joi";
|
|
25671
|
-
|
|
25672
25670
|
// src/services/region.service.ts
|
|
25673
25671
|
import { useAtlas as useAtlas26 } from "@eeplatform/nodejs-utils";
|
|
25674
25672
|
function useRegionService() {
|
|
@@ -25708,6 +25706,8 @@ function useRegionService() {
|
|
|
25708
25706
|
}
|
|
25709
25707
|
|
|
25710
25708
|
// src/controllers/region.controller.ts
|
|
25709
|
+
import { BadRequestError as BadRequestError52 } from "@eeplatform/nodejs-utils";
|
|
25710
|
+
import Joi28 from "joi";
|
|
25711
25711
|
function useRegionController() {
|
|
25712
25712
|
const {
|
|
25713
25713
|
getAll: _getAll,
|
|
@@ -25923,11 +25923,11 @@ import {
|
|
|
25923
25923
|
AppError as AppError13,
|
|
25924
25924
|
BadRequestError as BadRequestError54,
|
|
25925
25925
|
InternalServerError as InternalServerError24,
|
|
25926
|
-
logger as
|
|
25926
|
+
logger as logger26,
|
|
25927
25927
|
makeCacheKey as makeCacheKey17,
|
|
25928
25928
|
paginate as paginate13,
|
|
25929
25929
|
useAtlas as useAtlas27,
|
|
25930
|
-
useCache as
|
|
25930
|
+
useCache as useCache18
|
|
25931
25931
|
} from "@eeplatform/nodejs-utils";
|
|
25932
25932
|
import { ObjectId as ObjectId36 } from "mongodb";
|
|
25933
25933
|
function useDivisionRepo() {
|
|
@@ -25937,7 +25937,7 @@ function useDivisionRepo() {
|
|
|
25937
25937
|
}
|
|
25938
25938
|
const namespace_collection = "divisions";
|
|
25939
25939
|
const collection = db.collection(namespace_collection);
|
|
25940
|
-
const { getCache, setCache, delNamespace } =
|
|
25940
|
+
const { getCache, setCache, delNamespace } = useCache18(namespace_collection);
|
|
25941
25941
|
async function createIndex() {
|
|
25942
25942
|
try {
|
|
25943
25943
|
await collection.createIndex([
|
|
@@ -25976,13 +25976,13 @@ function useDivisionRepo() {
|
|
|
25976
25976
|
}
|
|
25977
25977
|
}
|
|
25978
25978
|
function delCachedData() {
|
|
25979
|
-
delNamespace(
|
|
25980
|
-
|
|
25979
|
+
delNamespace().then(() => {
|
|
25980
|
+
logger26.log({
|
|
25981
25981
|
level: "info",
|
|
25982
25982
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
25983
25983
|
});
|
|
25984
25984
|
}).catch((err) => {
|
|
25985
|
-
|
|
25985
|
+
logger26.log({
|
|
25986
25986
|
level: "error",
|
|
25987
25987
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
25988
25988
|
});
|
|
@@ -25995,7 +25995,7 @@ function useDivisionRepo() {
|
|
|
25995
25995
|
delCachedData();
|
|
25996
25996
|
return res.insertedId;
|
|
25997
25997
|
} catch (error) {
|
|
25998
|
-
|
|
25998
|
+
logger26.log({
|
|
25999
25999
|
level: "error",
|
|
26000
26000
|
message: error.message
|
|
26001
26001
|
});
|
|
@@ -26037,14 +26037,14 @@ function useDivisionRepo() {
|
|
|
26037
26037
|
sort: JSON.stringify(sort),
|
|
26038
26038
|
region
|
|
26039
26039
|
});
|
|
26040
|
-
|
|
26040
|
+
logger26.log({
|
|
26041
26041
|
level: "info",
|
|
26042
26042
|
message: `Cache key for getAll divisions: ${cacheKey}`
|
|
26043
26043
|
});
|
|
26044
26044
|
try {
|
|
26045
26045
|
const cached = await getCache(cacheKey);
|
|
26046
26046
|
if (cached) {
|
|
26047
|
-
|
|
26047
|
+
logger26.log({
|
|
26048
26048
|
level: "info",
|
|
26049
26049
|
message: `Cache hit for getAll divisions: ${cacheKey}`
|
|
26050
26050
|
});
|
|
@@ -26070,20 +26070,20 @@ function useDivisionRepo() {
|
|
|
26070
26070
|
]).toArray();
|
|
26071
26071
|
const length = await collection.countDocuments(query);
|
|
26072
26072
|
const data = paginate13(items, page, limit, length);
|
|
26073
|
-
setCache(cacheKey, data, 600
|
|
26074
|
-
|
|
26073
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
26074
|
+
logger26.log({
|
|
26075
26075
|
level: "info",
|
|
26076
26076
|
message: `Cache set for getAll divisions: ${cacheKey}`
|
|
26077
26077
|
});
|
|
26078
26078
|
}).catch((err) => {
|
|
26079
|
-
|
|
26079
|
+
logger26.log({
|
|
26080
26080
|
level: "error",
|
|
26081
26081
|
message: `Failed to set cache for getAll divisions: ${err.message}`
|
|
26082
26082
|
});
|
|
26083
26083
|
});
|
|
26084
26084
|
return data;
|
|
26085
26085
|
} catch (error) {
|
|
26086
|
-
|
|
26086
|
+
logger26.log({ level: "error", message: `${error}` });
|
|
26087
26087
|
throw error;
|
|
26088
26088
|
}
|
|
26089
26089
|
}
|
|
@@ -26097,7 +26097,7 @@ function useDivisionRepo() {
|
|
|
26097
26097
|
try {
|
|
26098
26098
|
const cached = await getCache(cacheKey);
|
|
26099
26099
|
if (cached) {
|
|
26100
|
-
|
|
26100
|
+
logger26.log({
|
|
26101
26101
|
level: "info",
|
|
26102
26102
|
message: `Cache hit for getById division: ${cacheKey}`
|
|
26103
26103
|
});
|
|
@@ -26110,13 +26110,13 @@ function useDivisionRepo() {
|
|
|
26110
26110
|
if (!result) {
|
|
26111
26111
|
throw new BadRequestError54("Division not found.");
|
|
26112
26112
|
}
|
|
26113
|
-
setCache(cacheKey, result, 300
|
|
26114
|
-
|
|
26113
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
26114
|
+
logger26.log({
|
|
26115
26115
|
level: "info",
|
|
26116
26116
|
message: `Cache set for division by id: ${cacheKey}`
|
|
26117
26117
|
});
|
|
26118
26118
|
}).catch((err) => {
|
|
26119
|
-
|
|
26119
|
+
logger26.log({
|
|
26120
26120
|
level: "error",
|
|
26121
26121
|
message: `Failed to set cache for division by id: ${err.message}`
|
|
26122
26122
|
});
|
|
@@ -26135,7 +26135,7 @@ function useDivisionRepo() {
|
|
|
26135
26135
|
try {
|
|
26136
26136
|
const cached = await getCache(cacheKey);
|
|
26137
26137
|
if (cached) {
|
|
26138
|
-
|
|
26138
|
+
logger26.log({
|
|
26139
26139
|
level: "info",
|
|
26140
26140
|
message: `Cache hit for getByName division: ${cacheKey}`
|
|
26141
26141
|
});
|
|
@@ -26148,13 +26148,13 @@ function useDivisionRepo() {
|
|
|
26148
26148
|
if (!result) {
|
|
26149
26149
|
throw new BadRequestError54("Division not found.");
|
|
26150
26150
|
}
|
|
26151
|
-
setCache(cacheKey, result, 300
|
|
26152
|
-
|
|
26151
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
26152
|
+
logger26.log({
|
|
26153
26153
|
level: "info",
|
|
26154
26154
|
message: `Cache set for division by name: ${cacheKey}`
|
|
26155
26155
|
});
|
|
26156
26156
|
}).catch((err) => {
|
|
26157
|
-
|
|
26157
|
+
logger26.log({
|
|
26158
26158
|
level: "error",
|
|
26159
26159
|
message: `Failed to set cache for division by name: ${err.message}`
|
|
26160
26160
|
});
|
|
@@ -26228,10 +26228,6 @@ function useDivisionRepo() {
|
|
|
26228
26228
|
};
|
|
26229
26229
|
}
|
|
26230
26230
|
|
|
26231
|
-
// src/controllers/division.controller.ts
|
|
26232
|
-
import { BadRequestError as BadRequestError55 } from "@eeplatform/nodejs-utils";
|
|
26233
|
-
import Joi30 from "joi";
|
|
26234
|
-
|
|
26235
26231
|
// src/services/division.service.ts
|
|
26236
26232
|
import { useAtlas as useAtlas28 } from "@eeplatform/nodejs-utils";
|
|
26237
26233
|
function useDivisionService() {
|
|
@@ -26271,6 +26267,8 @@ function useDivisionService() {
|
|
|
26271
26267
|
}
|
|
26272
26268
|
|
|
26273
26269
|
// src/controllers/division.controller.ts
|
|
26270
|
+
import { BadRequestError as BadRequestError55 } from "@eeplatform/nodejs-utils";
|
|
26271
|
+
import Joi30 from "joi";
|
|
26274
26272
|
function useDivisionController() {
|
|
26275
26273
|
const {
|
|
26276
26274
|
getAll: _getAll,
|
|
@@ -26524,11 +26522,11 @@ function MSchool(value) {
|
|
|
26524
26522
|
// src/repositories/school.repository.ts
|
|
26525
26523
|
import {
|
|
26526
26524
|
BadRequestError as BadRequestError56,
|
|
26527
|
-
logger as
|
|
26525
|
+
logger as logger27,
|
|
26528
26526
|
makeCacheKey as makeCacheKey18,
|
|
26529
26527
|
paginate as paginate14,
|
|
26530
26528
|
useAtlas as useAtlas29,
|
|
26531
|
-
useCache as
|
|
26529
|
+
useCache as useCache19
|
|
26532
26530
|
} from "@eeplatform/nodejs-utils";
|
|
26533
26531
|
import { ObjectId as ObjectId38 } from "mongodb";
|
|
26534
26532
|
function useSchoolRepo() {
|
|
@@ -26538,15 +26536,15 @@ function useSchoolRepo() {
|
|
|
26538
26536
|
}
|
|
26539
26537
|
const namespace_collection = "schools";
|
|
26540
26538
|
const collection = db.collection(namespace_collection);
|
|
26541
|
-
const { getCache, setCache, delNamespace } =
|
|
26539
|
+
const { getCache, setCache, delNamespace } = useCache19(namespace_collection);
|
|
26542
26540
|
function delCachedData() {
|
|
26543
|
-
delNamespace(
|
|
26544
|
-
|
|
26541
|
+
delNamespace().then(() => {
|
|
26542
|
+
logger27.log({
|
|
26545
26543
|
level: "info",
|
|
26546
26544
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
26547
26545
|
});
|
|
26548
26546
|
}).catch((err) => {
|
|
26549
|
-
|
|
26547
|
+
logger27.log({
|
|
26550
26548
|
level: "error",
|
|
26551
26549
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
26552
26550
|
});
|
|
@@ -26583,7 +26581,7 @@ function useSchoolRepo() {
|
|
|
26583
26581
|
delCachedData();
|
|
26584
26582
|
return res.insertedId;
|
|
26585
26583
|
} catch (error) {
|
|
26586
|
-
|
|
26584
|
+
logger27.log({
|
|
26587
26585
|
level: "error",
|
|
26588
26586
|
message: `Failed to add school: ${error}`
|
|
26589
26587
|
});
|
|
@@ -26640,20 +26638,20 @@ function useSchoolRepo() {
|
|
|
26640
26638
|
]).toArray();
|
|
26641
26639
|
const length = await collection.countDocuments(query);
|
|
26642
26640
|
const data = paginate14(items, page, limit, length);
|
|
26643
|
-
setCache(cacheKey, data, 600
|
|
26644
|
-
|
|
26641
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
26642
|
+
logger27.log({
|
|
26645
26643
|
level: "info",
|
|
26646
26644
|
message: `Cache set for key ${cacheKey}`
|
|
26647
26645
|
});
|
|
26648
26646
|
}).catch((err) => {
|
|
26649
|
-
|
|
26647
|
+
logger27.log({
|
|
26650
26648
|
level: "error",
|
|
26651
26649
|
message: `Failed to set cache for key ${cacheKey}: ${err.message}`
|
|
26652
26650
|
});
|
|
26653
26651
|
});
|
|
26654
26652
|
return data;
|
|
26655
26653
|
} catch (error) {
|
|
26656
|
-
|
|
26654
|
+
logger27.log({
|
|
26657
26655
|
level: "error",
|
|
26658
26656
|
message: `Failed to get all schools: ${error}`
|
|
26659
26657
|
});
|
|
@@ -26731,13 +26729,13 @@ function useSchoolRepo() {
|
|
|
26731
26729
|
}
|
|
26732
26730
|
try {
|
|
26733
26731
|
const school = await collection.findOne({ createdBy, status: "pending" });
|
|
26734
|
-
setCache(cacheKey, school, 600
|
|
26735
|
-
|
|
26732
|
+
setCache(cacheKey, school, 600).then(() => {
|
|
26733
|
+
logger27.log({
|
|
26736
26734
|
level: "info",
|
|
26737
26735
|
message: `Cache set for school by createdBy: ${cacheKey}`
|
|
26738
26736
|
});
|
|
26739
26737
|
}).catch((err) => {
|
|
26740
|
-
|
|
26738
|
+
logger27.log({
|
|
26741
26739
|
level: "error",
|
|
26742
26740
|
message: `Failed to set cache for school by createdBy: ${err.message}`
|
|
26743
26741
|
});
|
|
@@ -26763,13 +26761,13 @@ function useSchoolRepo() {
|
|
|
26763
26761
|
}
|
|
26764
26762
|
try {
|
|
26765
26763
|
const school = await collection.findOne({ _id, status: "pending" });
|
|
26766
|
-
setCache(cacheKey, school, 600
|
|
26767
|
-
|
|
26764
|
+
setCache(cacheKey, school, 600).then(() => {
|
|
26765
|
+
logger27.log({
|
|
26768
26766
|
level: "info",
|
|
26769
26767
|
message: `Cache set for school by ID: ${cacheKey}`
|
|
26770
26768
|
});
|
|
26771
26769
|
}).catch((err) => {
|
|
26772
|
-
|
|
26770
|
+
logger27.log({
|
|
26773
26771
|
level: "error",
|
|
26774
26772
|
message: `Failed to set cache for school by ID: ${err.message}`
|
|
26775
26773
|
});
|
|
@@ -26791,7 +26789,7 @@ function useSchoolRepo() {
|
|
|
26791
26789
|
}
|
|
26792
26790
|
|
|
26793
26791
|
// src/services/school.service.ts
|
|
26794
|
-
import { BadRequestError as BadRequestError57, useAtlas as useAtlas30, logger as
|
|
26792
|
+
import { BadRequestError as BadRequestError57, useAtlas as useAtlas30, logger as logger28 } from "@eeplatform/nodejs-utils";
|
|
26795
26793
|
function useSchoolService() {
|
|
26796
26794
|
const { add, getPendingByCreatedBy, updateStatusById, getPendingById } = useSchoolRepo();
|
|
26797
26795
|
const { addRole } = useRoleRepo();
|
|
@@ -26864,7 +26862,7 @@ function useSchoolService() {
|
|
|
26864
26862
|
await session.commitTransaction();
|
|
26865
26863
|
return "School registration has been approved.";
|
|
26866
26864
|
} catch (error) {
|
|
26867
|
-
|
|
26865
|
+
logger28.log({
|
|
26868
26866
|
level: "error",
|
|
26869
26867
|
message: `Error approving school registration: ${error.message}`
|
|
26870
26868
|
});
|
|
@@ -27033,6 +27031,761 @@ function useSchoolController() {
|
|
|
27033
27031
|
approveSchool
|
|
27034
27032
|
};
|
|
27035
27033
|
}
|
|
27034
|
+
|
|
27035
|
+
// src/models/building.model.ts
|
|
27036
|
+
import { BadRequestError as BadRequestError59, logger as logger29 } from "@eeplatform/nodejs-utils";
|
|
27037
|
+
import Joi33 from "joi";
|
|
27038
|
+
import { ObjectId as ObjectId39 } from "mongodb";
|
|
27039
|
+
var schemaBuilding = Joi33.object({
|
|
27040
|
+
_id: Joi33.string().hex().optional(),
|
|
27041
|
+
school: Joi33.string().hex().required(),
|
|
27042
|
+
serial: Joi33.string().optional().allow("", null),
|
|
27043
|
+
name: Joi33.string().required(),
|
|
27044
|
+
levels: Joi33.number().integer().min(1).required(),
|
|
27045
|
+
createdAt: Joi33.date().optional().allow("", null),
|
|
27046
|
+
updatedAt: Joi33.date().optional().allow("", null),
|
|
27047
|
+
deletedAt: Joi33.date().optional().allow("", null),
|
|
27048
|
+
status: Joi33.string().optional().allow("", null)
|
|
27049
|
+
});
|
|
27050
|
+
var schemaBuildingUnit = Joi33.object({
|
|
27051
|
+
_id: Joi33.string().hex().optional(),
|
|
27052
|
+
school: Joi33.string().hex().required(),
|
|
27053
|
+
name: Joi33.string().optional().allow("", null),
|
|
27054
|
+
building: Joi33.string().hex().required(),
|
|
27055
|
+
buildingName: Joi33.string().optional().allow("", null),
|
|
27056
|
+
level: Joi33.number().integer().min(1).required(),
|
|
27057
|
+
category: Joi33.string().required(),
|
|
27058
|
+
type: Joi33.string().required(),
|
|
27059
|
+
seating_capacity: Joi33.number().integer().min(0).required(),
|
|
27060
|
+
standing_capacity: Joi33.number().integer().min(0).required(),
|
|
27061
|
+
description: Joi33.string().optional().allow("", null),
|
|
27062
|
+
unit_of_measurement: Joi33.string().valid("sqm").required(),
|
|
27063
|
+
area: Joi33.number().positive().required(),
|
|
27064
|
+
status: Joi33.string().optional().allow("", null)
|
|
27065
|
+
});
|
|
27066
|
+
function MBuilding(value) {
|
|
27067
|
+
const { error } = schemaBuilding.validate(value);
|
|
27068
|
+
if (error) {
|
|
27069
|
+
logger29.info(`Building Model: ${error.message}`);
|
|
27070
|
+
throw new BadRequestError59(error.message);
|
|
27071
|
+
}
|
|
27072
|
+
if (value._id && typeof value._id === "string") {
|
|
27073
|
+
try {
|
|
27074
|
+
value._id = new ObjectId39(value._id);
|
|
27075
|
+
} catch (error2) {
|
|
27076
|
+
throw new BadRequestError59("Invalid _id format");
|
|
27077
|
+
}
|
|
27078
|
+
}
|
|
27079
|
+
try {
|
|
27080
|
+
value.school = new ObjectId39(value.school);
|
|
27081
|
+
} catch (error2) {
|
|
27082
|
+
throw new BadRequestError59("Invalid school format");
|
|
27083
|
+
}
|
|
27084
|
+
return {
|
|
27085
|
+
_id: value._id ?? void 0,
|
|
27086
|
+
school: value.school,
|
|
27087
|
+
serial: value.serial ?? "",
|
|
27088
|
+
name: value.name ?? "",
|
|
27089
|
+
levels: value.levels ?? 0,
|
|
27090
|
+
status: value.status ?? "active",
|
|
27091
|
+
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
27092
|
+
updatedAt: value.updatedAt ?? "",
|
|
27093
|
+
deletedAt: value.deletedAt ?? ""
|
|
27094
|
+
};
|
|
27095
|
+
}
|
|
27096
|
+
function MBuildingUnit(value) {
|
|
27097
|
+
const { error } = schemaBuildingUnit.validate(value);
|
|
27098
|
+
if (error) {
|
|
27099
|
+
logger29.info(`Building Unit Model: ${error.message}`);
|
|
27100
|
+
throw new BadRequestError59(error.message);
|
|
27101
|
+
}
|
|
27102
|
+
if (value._id && typeof value._id === "string") {
|
|
27103
|
+
try {
|
|
27104
|
+
value._id = new ObjectId39(value._id);
|
|
27105
|
+
} catch (error2) {
|
|
27106
|
+
throw new BadRequestError59("Invalid ID");
|
|
27107
|
+
}
|
|
27108
|
+
}
|
|
27109
|
+
try {
|
|
27110
|
+
value.school = new ObjectId39(value.school);
|
|
27111
|
+
} catch (error2) {
|
|
27112
|
+
throw new BadRequestError59("Invalid school ID");
|
|
27113
|
+
}
|
|
27114
|
+
try {
|
|
27115
|
+
value.building = new ObjectId39(value.building);
|
|
27116
|
+
} catch (error2) {
|
|
27117
|
+
throw new BadRequestError59("Invalid building ID");
|
|
27118
|
+
}
|
|
27119
|
+
return {
|
|
27120
|
+
_id: value._id ?? void 0,
|
|
27121
|
+
school: value.school,
|
|
27122
|
+
name: value.name ?? "",
|
|
27123
|
+
building: value.building,
|
|
27124
|
+
buildingName: value.buildingName ?? "",
|
|
27125
|
+
level: value.level ?? 0,
|
|
27126
|
+
category: value.category ?? "",
|
|
27127
|
+
type: value.type ?? "",
|
|
27128
|
+
seating_capacity: value.seating_capacity ?? 0,
|
|
27129
|
+
standing_capacity: value.standing_capacity ?? 0,
|
|
27130
|
+
description: value.description ?? "",
|
|
27131
|
+
unit_of_measurement: value.unit_of_measurement ?? "sqm",
|
|
27132
|
+
area: value.area ?? 0,
|
|
27133
|
+
status: value.status ?? "active",
|
|
27134
|
+
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
27135
|
+
updatedAt: value.updatedAt ?? "",
|
|
27136
|
+
deletedAt: value.deletedAt ?? ""
|
|
27137
|
+
};
|
|
27138
|
+
}
|
|
27139
|
+
|
|
27140
|
+
// src/repositories/building.repository.ts
|
|
27141
|
+
import {
|
|
27142
|
+
AppError as AppError14,
|
|
27143
|
+
BadRequestError as BadRequestError60,
|
|
27144
|
+
InternalServerError as InternalServerError25,
|
|
27145
|
+
logger as logger30,
|
|
27146
|
+
makeCacheKey as makeCacheKey19,
|
|
27147
|
+
paginate as paginate15,
|
|
27148
|
+
useAtlas as useAtlas31,
|
|
27149
|
+
useCache as useCache20
|
|
27150
|
+
} from "@eeplatform/nodejs-utils";
|
|
27151
|
+
import { ObjectId as ObjectId40 } from "mongodb";
|
|
27152
|
+
function useBuildingRepo() {
|
|
27153
|
+
const db = useAtlas31.getDb();
|
|
27154
|
+
if (!db) {
|
|
27155
|
+
throw new Error("Unable to connect to server.");
|
|
27156
|
+
}
|
|
27157
|
+
const namespace_collection = "school.buildings";
|
|
27158
|
+
const collection = db.collection(namespace_collection);
|
|
27159
|
+
const { getCache, setCache, delNamespace } = useCache20(namespace_collection);
|
|
27160
|
+
async function createIndex() {
|
|
27161
|
+
try {
|
|
27162
|
+
await collection.createIndex([
|
|
27163
|
+
{ name: 1 },
|
|
27164
|
+
{ school: 1 },
|
|
27165
|
+
{ createdAt: 1 }
|
|
27166
|
+
]);
|
|
27167
|
+
} catch (error) {
|
|
27168
|
+
throw new Error("Failed to create index on buildings.");
|
|
27169
|
+
}
|
|
27170
|
+
}
|
|
27171
|
+
async function createTextIndex() {
|
|
27172
|
+
try {
|
|
27173
|
+
await collection.createIndex({
|
|
27174
|
+
name: "text"
|
|
27175
|
+
});
|
|
27176
|
+
} catch (error) {
|
|
27177
|
+
throw new Error("Failed to create text index on building name.");
|
|
27178
|
+
}
|
|
27179
|
+
}
|
|
27180
|
+
async function add(value, session) {
|
|
27181
|
+
try {
|
|
27182
|
+
value = MBuilding(value);
|
|
27183
|
+
const res = await collection.insertOne(value, { session });
|
|
27184
|
+
delCachedData();
|
|
27185
|
+
return res.insertedId;
|
|
27186
|
+
} catch (error) {
|
|
27187
|
+
logger30.log({
|
|
27188
|
+
level: "error",
|
|
27189
|
+
message: error.message
|
|
27190
|
+
});
|
|
27191
|
+
if (error instanceof AppError14) {
|
|
27192
|
+
throw error;
|
|
27193
|
+
} else {
|
|
27194
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
27195
|
+
if (isDuplicated) {
|
|
27196
|
+
throw new BadRequestError60("Building already exists.");
|
|
27197
|
+
}
|
|
27198
|
+
throw new Error("Failed to create building.");
|
|
27199
|
+
}
|
|
27200
|
+
}
|
|
27201
|
+
}
|
|
27202
|
+
async function getAll({
|
|
27203
|
+
search = "",
|
|
27204
|
+
page = 1,
|
|
27205
|
+
limit = 10,
|
|
27206
|
+
sort = {},
|
|
27207
|
+
school = "",
|
|
27208
|
+
status = "active"
|
|
27209
|
+
} = {}) {
|
|
27210
|
+
page = page > 0 ? page - 1 : 0;
|
|
27211
|
+
const query = {
|
|
27212
|
+
status
|
|
27213
|
+
};
|
|
27214
|
+
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
27215
|
+
if (search) {
|
|
27216
|
+
query.$text = { $search: search };
|
|
27217
|
+
}
|
|
27218
|
+
if (school) {
|
|
27219
|
+
try {
|
|
27220
|
+
query.school = new ObjectId40(school);
|
|
27221
|
+
} catch (error) {
|
|
27222
|
+
throw new BadRequestError60("Invalid school ID.");
|
|
27223
|
+
}
|
|
27224
|
+
}
|
|
27225
|
+
const cacheParams = {
|
|
27226
|
+
page,
|
|
27227
|
+
limit,
|
|
27228
|
+
sort: JSON.stringify(sort)
|
|
27229
|
+
};
|
|
27230
|
+
if (search)
|
|
27231
|
+
cacheParams.search = search;
|
|
27232
|
+
if (school)
|
|
27233
|
+
cacheParams.school = school;
|
|
27234
|
+
if (status !== "active")
|
|
27235
|
+
cacheParams.status = status;
|
|
27236
|
+
const cacheKey = makeCacheKey19(namespace_collection, cacheParams);
|
|
27237
|
+
logger30.log({
|
|
27238
|
+
level: "info",
|
|
27239
|
+
message: `Cache key for getAll buildings: ${cacheKey}`
|
|
27240
|
+
});
|
|
27241
|
+
try {
|
|
27242
|
+
const cached = await getCache(cacheKey);
|
|
27243
|
+
if (cached) {
|
|
27244
|
+
logger30.log({
|
|
27245
|
+
level: "info",
|
|
27246
|
+
message: `Cache hit for getAll buildings: ${cacheKey}`
|
|
27247
|
+
});
|
|
27248
|
+
return cached;
|
|
27249
|
+
}
|
|
27250
|
+
const items = await collection.aggregate([
|
|
27251
|
+
{ $match: query },
|
|
27252
|
+
{ $sort: sort },
|
|
27253
|
+
{ $skip: page * limit },
|
|
27254
|
+
{ $limit: limit }
|
|
27255
|
+
]).toArray();
|
|
27256
|
+
const length = await collection.countDocuments(query);
|
|
27257
|
+
const data = paginate15(items, page, limit, length);
|
|
27258
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
27259
|
+
logger30.log({
|
|
27260
|
+
level: "info",
|
|
27261
|
+
message: `Cache set for getAll buildings: ${cacheKey}`
|
|
27262
|
+
});
|
|
27263
|
+
}).catch((err) => {
|
|
27264
|
+
logger30.log({
|
|
27265
|
+
level: "error",
|
|
27266
|
+
message: `Failed to set cache for getAll buildings: ${err.message}`
|
|
27267
|
+
});
|
|
27268
|
+
});
|
|
27269
|
+
return data;
|
|
27270
|
+
} catch (error) {
|
|
27271
|
+
logger30.log({ level: "error", message: `${error}` });
|
|
27272
|
+
throw error;
|
|
27273
|
+
}
|
|
27274
|
+
}
|
|
27275
|
+
async function getById(_id) {
|
|
27276
|
+
try {
|
|
27277
|
+
_id = new ObjectId40(_id);
|
|
27278
|
+
} catch (error) {
|
|
27279
|
+
throw new BadRequestError60("Invalid ID.");
|
|
27280
|
+
}
|
|
27281
|
+
const cacheKey = makeCacheKey19(namespace_collection, { _id: String(_id) });
|
|
27282
|
+
try {
|
|
27283
|
+
const cached = await getCache(cacheKey);
|
|
27284
|
+
if (cached) {
|
|
27285
|
+
logger30.log({
|
|
27286
|
+
level: "info",
|
|
27287
|
+
message: `Cache hit for getById building: ${cacheKey}`
|
|
27288
|
+
});
|
|
27289
|
+
return cached;
|
|
27290
|
+
}
|
|
27291
|
+
const result = await collection.findOne({
|
|
27292
|
+
_id,
|
|
27293
|
+
deletedAt: { $in: ["", null] }
|
|
27294
|
+
});
|
|
27295
|
+
if (!result) {
|
|
27296
|
+
throw new BadRequestError60("Building not found.");
|
|
27297
|
+
}
|
|
27298
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
27299
|
+
logger30.log({
|
|
27300
|
+
level: "info",
|
|
27301
|
+
message: `Cache set for building by id: ${cacheKey}`
|
|
27302
|
+
});
|
|
27303
|
+
}).catch((err) => {
|
|
27304
|
+
logger30.log({
|
|
27305
|
+
level: "error",
|
|
27306
|
+
message: `Failed to set cache for building by id: ${err.message}`
|
|
27307
|
+
});
|
|
27308
|
+
});
|
|
27309
|
+
return result;
|
|
27310
|
+
} catch (error) {
|
|
27311
|
+
if (error instanceof AppError14) {
|
|
27312
|
+
throw error;
|
|
27313
|
+
} else {
|
|
27314
|
+
throw new InternalServerError25("Failed to get building.");
|
|
27315
|
+
}
|
|
27316
|
+
}
|
|
27317
|
+
}
|
|
27318
|
+
function delCachedData() {
|
|
27319
|
+
delNamespace().then(() => {
|
|
27320
|
+
logger30.log({
|
|
27321
|
+
level: "info",
|
|
27322
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
27323
|
+
});
|
|
27324
|
+
}).catch((err) => {
|
|
27325
|
+
logger30.log({
|
|
27326
|
+
level: "error",
|
|
27327
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
27328
|
+
});
|
|
27329
|
+
});
|
|
27330
|
+
}
|
|
27331
|
+
return {
|
|
27332
|
+
createIndex,
|
|
27333
|
+
createTextIndex,
|
|
27334
|
+
add,
|
|
27335
|
+
getAll,
|
|
27336
|
+
getById
|
|
27337
|
+
};
|
|
27338
|
+
}
|
|
27339
|
+
|
|
27340
|
+
// src/repositories/building-unit.repository.ts
|
|
27341
|
+
import {
|
|
27342
|
+
AppError as AppError15,
|
|
27343
|
+
BadRequestError as BadRequestError61,
|
|
27344
|
+
InternalServerError as InternalServerError26,
|
|
27345
|
+
logger as logger31,
|
|
27346
|
+
makeCacheKey as makeCacheKey20,
|
|
27347
|
+
paginate as paginate16,
|
|
27348
|
+
useAtlas as useAtlas32,
|
|
27349
|
+
useCache as useCache21
|
|
27350
|
+
} from "@eeplatform/nodejs-utils";
|
|
27351
|
+
import { ObjectId as ObjectId41 } from "mongodb";
|
|
27352
|
+
function useBuildingUnitRepo() {
|
|
27353
|
+
const db = useAtlas32.getDb();
|
|
27354
|
+
if (!db) {
|
|
27355
|
+
throw new Error("Unable to connect to server.");
|
|
27356
|
+
}
|
|
27357
|
+
const namespace_collection = "school.building-units";
|
|
27358
|
+
const collection = db.collection(namespace_collection);
|
|
27359
|
+
const { getCache, setCache, delNamespace } = useCache21(namespace_collection);
|
|
27360
|
+
async function createIndex() {
|
|
27361
|
+
try {
|
|
27362
|
+
await collection.createIndexes([
|
|
27363
|
+
{ key: { school: 1 } },
|
|
27364
|
+
{ key: { building: 1 } },
|
|
27365
|
+
{ key: { status: 1 } },
|
|
27366
|
+
{ key: { createdAt: 1 } },
|
|
27367
|
+
{
|
|
27368
|
+
key: {
|
|
27369
|
+
name: "text",
|
|
27370
|
+
buildingName: "text",
|
|
27371
|
+
category: "text",
|
|
27372
|
+
type: "text"
|
|
27373
|
+
}
|
|
27374
|
+
}
|
|
27375
|
+
]);
|
|
27376
|
+
} catch (error) {
|
|
27377
|
+
throw new Error("Failed to create index on building units.");
|
|
27378
|
+
}
|
|
27379
|
+
}
|
|
27380
|
+
function delCachedData() {
|
|
27381
|
+
delNamespace().then(() => {
|
|
27382
|
+
logger31.log({
|
|
27383
|
+
level: "info",
|
|
27384
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
27385
|
+
});
|
|
27386
|
+
}).catch((err) => {
|
|
27387
|
+
logger31.log({
|
|
27388
|
+
level: "error",
|
|
27389
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
27390
|
+
});
|
|
27391
|
+
});
|
|
27392
|
+
}
|
|
27393
|
+
async function add(value, session) {
|
|
27394
|
+
try {
|
|
27395
|
+
value = MBuildingUnit(value);
|
|
27396
|
+
const res = await collection.insertOne(value, { session });
|
|
27397
|
+
delCachedData();
|
|
27398
|
+
return res.insertedId;
|
|
27399
|
+
} catch (error) {
|
|
27400
|
+
logger31.log({
|
|
27401
|
+
level: "error",
|
|
27402
|
+
message: error.message
|
|
27403
|
+
});
|
|
27404
|
+
if (error instanceof AppError15) {
|
|
27405
|
+
throw error;
|
|
27406
|
+
} else {
|
|
27407
|
+
throw new Error("Failed to create building unit.");
|
|
27408
|
+
}
|
|
27409
|
+
}
|
|
27410
|
+
}
|
|
27411
|
+
async function getAll({
|
|
27412
|
+
search = "",
|
|
27413
|
+
page = 1,
|
|
27414
|
+
limit = 10,
|
|
27415
|
+
sort = {},
|
|
27416
|
+
school = "",
|
|
27417
|
+
building = "",
|
|
27418
|
+
status = "active"
|
|
27419
|
+
} = {}) {
|
|
27420
|
+
page = page > 0 ? page - 1 : 0;
|
|
27421
|
+
const query = {
|
|
27422
|
+
deletedAt: { $in: ["", null] },
|
|
27423
|
+
status: { $in: [status, "", null] }
|
|
27424
|
+
};
|
|
27425
|
+
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
27426
|
+
if (search) {
|
|
27427
|
+
query.$text = { $search: search };
|
|
27428
|
+
}
|
|
27429
|
+
if (school) {
|
|
27430
|
+
try {
|
|
27431
|
+
query.school = new ObjectId41(school);
|
|
27432
|
+
} catch (error) {
|
|
27433
|
+
throw new BadRequestError61("Invalid school ID.");
|
|
27434
|
+
}
|
|
27435
|
+
}
|
|
27436
|
+
if (building) {
|
|
27437
|
+
try {
|
|
27438
|
+
query.building = new ObjectId41(building);
|
|
27439
|
+
} catch (error) {
|
|
27440
|
+
throw new BadRequestError61("Invalid building ID.");
|
|
27441
|
+
}
|
|
27442
|
+
}
|
|
27443
|
+
const cacheParams = {
|
|
27444
|
+
page,
|
|
27445
|
+
limit,
|
|
27446
|
+
sort: JSON.stringify(sort)
|
|
27447
|
+
};
|
|
27448
|
+
if (search)
|
|
27449
|
+
cacheParams.search = search;
|
|
27450
|
+
if (school)
|
|
27451
|
+
cacheParams.school = school;
|
|
27452
|
+
if (building)
|
|
27453
|
+
cacheParams.building = building;
|
|
27454
|
+
if (status !== "active")
|
|
27455
|
+
cacheParams.status = status;
|
|
27456
|
+
const cacheKey = makeCacheKey20(namespace_collection, cacheParams);
|
|
27457
|
+
logger31.log({
|
|
27458
|
+
level: "info",
|
|
27459
|
+
message: `Cache key for getAll building units: ${cacheKey}`
|
|
27460
|
+
});
|
|
27461
|
+
try {
|
|
27462
|
+
const cached = await getCache(cacheKey);
|
|
27463
|
+
if (cached) {
|
|
27464
|
+
logger31.log({
|
|
27465
|
+
level: "info",
|
|
27466
|
+
message: `Cache hit for getAll building units: ${cacheKey}`
|
|
27467
|
+
});
|
|
27468
|
+
return cached;
|
|
27469
|
+
}
|
|
27470
|
+
const items = await collection.aggregate([
|
|
27471
|
+
{ $match: query },
|
|
27472
|
+
{ $sort: sort },
|
|
27473
|
+
{ $skip: page * limit },
|
|
27474
|
+
{ $limit: limit }
|
|
27475
|
+
]).toArray();
|
|
27476
|
+
const length = await collection.countDocuments(query);
|
|
27477
|
+
const data = paginate16(items, page, limit, length);
|
|
27478
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
27479
|
+
logger31.log({
|
|
27480
|
+
level: "info",
|
|
27481
|
+
message: `Cache set for getAll building units: ${cacheKey}`
|
|
27482
|
+
});
|
|
27483
|
+
}).catch((err) => {
|
|
27484
|
+
logger31.log({
|
|
27485
|
+
level: "error",
|
|
27486
|
+
message: `Failed to set cache for getAll building units: ${err.message}`
|
|
27487
|
+
});
|
|
27488
|
+
});
|
|
27489
|
+
return data;
|
|
27490
|
+
} catch (error) {
|
|
27491
|
+
logger31.log({ level: "error", message: `${error}` });
|
|
27492
|
+
throw error;
|
|
27493
|
+
}
|
|
27494
|
+
}
|
|
27495
|
+
async function getById(_id) {
|
|
27496
|
+
try {
|
|
27497
|
+
_id = new ObjectId41(_id);
|
|
27498
|
+
} catch (error) {
|
|
27499
|
+
throw new BadRequestError61("Invalid ID.");
|
|
27500
|
+
}
|
|
27501
|
+
const cacheKey = makeCacheKey20(namespace_collection, { _id: String(_id) });
|
|
27502
|
+
try {
|
|
27503
|
+
const cached = await getCache(cacheKey);
|
|
27504
|
+
if (cached) {
|
|
27505
|
+
logger31.log({
|
|
27506
|
+
level: "info",
|
|
27507
|
+
message: `Cache hit for getById building unit: ${cacheKey}`
|
|
27508
|
+
});
|
|
27509
|
+
return cached;
|
|
27510
|
+
}
|
|
27511
|
+
const result = await collection.findOne({
|
|
27512
|
+
_id,
|
|
27513
|
+
deletedAt: { $in: ["", null] }
|
|
27514
|
+
});
|
|
27515
|
+
if (!result) {
|
|
27516
|
+
throw new BadRequestError61("Building unit not found.");
|
|
27517
|
+
}
|
|
27518
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
27519
|
+
logger31.log({
|
|
27520
|
+
level: "info",
|
|
27521
|
+
message: `Cache set for building unit by id: ${cacheKey}`
|
|
27522
|
+
});
|
|
27523
|
+
}).catch((err) => {
|
|
27524
|
+
logger31.log({
|
|
27525
|
+
level: "error",
|
|
27526
|
+
message: `Failed to set cache for building unit by id: ${err.message}`
|
|
27527
|
+
});
|
|
27528
|
+
});
|
|
27529
|
+
return result;
|
|
27530
|
+
} catch (error) {
|
|
27531
|
+
if (error instanceof AppError15) {
|
|
27532
|
+
throw error;
|
|
27533
|
+
} else {
|
|
27534
|
+
throw new InternalServerError26("Failed to get building unit.");
|
|
27535
|
+
}
|
|
27536
|
+
}
|
|
27537
|
+
}
|
|
27538
|
+
return {
|
|
27539
|
+
createIndex,
|
|
27540
|
+
add,
|
|
27541
|
+
getAll,
|
|
27542
|
+
getById
|
|
27543
|
+
};
|
|
27544
|
+
}
|
|
27545
|
+
|
|
27546
|
+
// src/controllers/building.controller.ts
|
|
27547
|
+
import { BadRequestError as BadRequestError62, logger as logger32 } from "@eeplatform/nodejs-utils";
|
|
27548
|
+
import Joi34 from "joi";
|
|
27549
|
+
function useBuildingController() {
|
|
27550
|
+
const { getAll: _getAll, getById: _getById, add: _add } = useBuildingRepo();
|
|
27551
|
+
async function createBuilding(req, res, next) {
|
|
27552
|
+
const value = req.body;
|
|
27553
|
+
const validation = Joi34.object({
|
|
27554
|
+
name: Joi34.string().required(),
|
|
27555
|
+
school: Joi34.string().hex().required(),
|
|
27556
|
+
levels: Joi34.number().integer().min(1).required(),
|
|
27557
|
+
serial: Joi34.string().optional().allow("", null),
|
|
27558
|
+
status: Joi34.string().optional().allow("", null)
|
|
27559
|
+
});
|
|
27560
|
+
const { error } = validation.validate(value);
|
|
27561
|
+
if (error) {
|
|
27562
|
+
next(new BadRequestError62(error.message));
|
|
27563
|
+
logger32.info(`Controller: ${error.message}`);
|
|
27564
|
+
return;
|
|
27565
|
+
}
|
|
27566
|
+
try {
|
|
27567
|
+
const result = await _add(value);
|
|
27568
|
+
res.json(result);
|
|
27569
|
+
return;
|
|
27570
|
+
} catch (error2) {
|
|
27571
|
+
next(error2);
|
|
27572
|
+
}
|
|
27573
|
+
}
|
|
27574
|
+
async function getAll(req, res, next) {
|
|
27575
|
+
const query = req.query;
|
|
27576
|
+
const validation = Joi34.object({
|
|
27577
|
+
page: Joi34.number().min(1).optional().allow("", null),
|
|
27578
|
+
limit: Joi34.number().min(1).optional().allow("", null),
|
|
27579
|
+
search: Joi34.string().optional().allow("", null),
|
|
27580
|
+
school: Joi34.string().hex().optional().allow("", null),
|
|
27581
|
+
status: Joi34.string().optional().allow("", null)
|
|
27582
|
+
});
|
|
27583
|
+
const { error } = validation.validate(query);
|
|
27584
|
+
if (error) {
|
|
27585
|
+
next(new BadRequestError62(error.message));
|
|
27586
|
+
return;
|
|
27587
|
+
}
|
|
27588
|
+
const page = parseInt(req.query.page) ?? 1;
|
|
27589
|
+
let limit = parseInt(req.query.limit) ?? 20;
|
|
27590
|
+
limit = isNaN(limit) ? 20 : limit;
|
|
27591
|
+
const sort = req.query.sort ? String(req.query.sort).split(",") : "";
|
|
27592
|
+
const sortOrder = req.query.sortOrder ? String(req.query.sortOrder).split(",") : "";
|
|
27593
|
+
const sortObj = {};
|
|
27594
|
+
if (sort && Array.isArray(sort) && sort.length && sortOrder && Array.isArray(sortOrder) && sortOrder.length) {
|
|
27595
|
+
sort.forEach((field, index) => {
|
|
27596
|
+
sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
|
|
27597
|
+
});
|
|
27598
|
+
}
|
|
27599
|
+
const status = req.query.status ?? "active";
|
|
27600
|
+
const school = req.query.school ?? "";
|
|
27601
|
+
const search = req.query.search ?? "";
|
|
27602
|
+
try {
|
|
27603
|
+
const buildings = await _getAll({
|
|
27604
|
+
page,
|
|
27605
|
+
limit,
|
|
27606
|
+
sort: sortObj,
|
|
27607
|
+
status,
|
|
27608
|
+
school,
|
|
27609
|
+
search
|
|
27610
|
+
});
|
|
27611
|
+
res.json(buildings);
|
|
27612
|
+
return;
|
|
27613
|
+
} catch (error2) {
|
|
27614
|
+
next(error2);
|
|
27615
|
+
}
|
|
27616
|
+
}
|
|
27617
|
+
async function getById(req, res, next) {
|
|
27618
|
+
const id = req.params.id;
|
|
27619
|
+
const validation = Joi34.object({
|
|
27620
|
+
id: Joi34.string().hex().required()
|
|
27621
|
+
});
|
|
27622
|
+
const { error } = validation.validate({ id });
|
|
27623
|
+
if (error) {
|
|
27624
|
+
next(new BadRequestError62(error.message));
|
|
27625
|
+
return;
|
|
27626
|
+
}
|
|
27627
|
+
try {
|
|
27628
|
+
const building = await _getById(id);
|
|
27629
|
+
res.json({
|
|
27630
|
+
message: "Successfully retrieved building.",
|
|
27631
|
+
data: { building }
|
|
27632
|
+
});
|
|
27633
|
+
return;
|
|
27634
|
+
} catch (error2) {
|
|
27635
|
+
next(error2);
|
|
27636
|
+
}
|
|
27637
|
+
}
|
|
27638
|
+
return {
|
|
27639
|
+
createBuilding,
|
|
27640
|
+
getAll,
|
|
27641
|
+
getById
|
|
27642
|
+
};
|
|
27643
|
+
}
|
|
27644
|
+
|
|
27645
|
+
// src/controllers/building-unit.controller.ts
|
|
27646
|
+
import { BadRequestError as BadRequestError63 } from "@eeplatform/nodejs-utils";
|
|
27647
|
+
import Joi35 from "joi";
|
|
27648
|
+
|
|
27649
|
+
// src/services/building-unit.service.ts
|
|
27650
|
+
import { useAtlas as useAtlas33 } from "@eeplatform/nodejs-utils";
|
|
27651
|
+
function useBuildingUnitService() {
|
|
27652
|
+
const { add: _add } = useBuildingUnitRepo();
|
|
27653
|
+
async function add(value) {
|
|
27654
|
+
const session = useAtlas33.getClient()?.startSession();
|
|
27655
|
+
if (!session) {
|
|
27656
|
+
throw new Error("Unable to start session for building unit service.");
|
|
27657
|
+
}
|
|
27658
|
+
try {
|
|
27659
|
+
await session.startTransaction();
|
|
27660
|
+
for (let index = 0; index < value.qty; index++) {
|
|
27661
|
+
await _add({ ...value.building }, session);
|
|
27662
|
+
}
|
|
27663
|
+
await session.commitTransaction();
|
|
27664
|
+
return "Building unit added successfully.";
|
|
27665
|
+
} catch (error) {
|
|
27666
|
+
await session.abortTransaction();
|
|
27667
|
+
throw error;
|
|
27668
|
+
} finally {
|
|
27669
|
+
session.endSession();
|
|
27670
|
+
}
|
|
27671
|
+
}
|
|
27672
|
+
return {
|
|
27673
|
+
add
|
|
27674
|
+
};
|
|
27675
|
+
}
|
|
27676
|
+
|
|
27677
|
+
// src/controllers/building-unit.controller.ts
|
|
27678
|
+
function useBuildingUnitController() {
|
|
27679
|
+
const { getAll: _getAll, getById: _getById } = useBuildingUnitRepo();
|
|
27680
|
+
const { add: _add } = useBuildingUnitService();
|
|
27681
|
+
async function add(req, res, next) {
|
|
27682
|
+
const data = req.body;
|
|
27683
|
+
const validation = Joi35.object({
|
|
27684
|
+
building: Joi35.object({
|
|
27685
|
+
school: Joi35.string().hex().required(),
|
|
27686
|
+
name: Joi35.string().optional().allow("", null),
|
|
27687
|
+
building: Joi35.string().hex().required(),
|
|
27688
|
+
buildingName: Joi35.string().optional().allow("", null),
|
|
27689
|
+
level: Joi35.number().integer().min(1).required(),
|
|
27690
|
+
category: Joi35.string().required(),
|
|
27691
|
+
type: Joi35.string().required(),
|
|
27692
|
+
seating_capacity: Joi35.number().integer().min(0).required(),
|
|
27693
|
+
standing_capacity: Joi35.number().integer().min(0).required(),
|
|
27694
|
+
description: Joi35.string().optional().allow("", null),
|
|
27695
|
+
unit_of_measurement: Joi35.string().valid("sqm").required(),
|
|
27696
|
+
area: Joi35.number().positive().required(),
|
|
27697
|
+
status: Joi35.string().optional().allow("", null)
|
|
27698
|
+
}),
|
|
27699
|
+
qty: Joi35.number().integer().min(1).max(20).optional().default(1)
|
|
27700
|
+
});
|
|
27701
|
+
const { error } = validation.validate(data);
|
|
27702
|
+
if (error) {
|
|
27703
|
+
next(new BadRequestError63(error.message));
|
|
27704
|
+
return;
|
|
27705
|
+
}
|
|
27706
|
+
try {
|
|
27707
|
+
const buildingUnit = await _add(data);
|
|
27708
|
+
res.json({
|
|
27709
|
+
message: "Building unit added successfully.",
|
|
27710
|
+
data: { buildingUnit }
|
|
27711
|
+
});
|
|
27712
|
+
} catch (error2) {
|
|
27713
|
+
next(error2);
|
|
27714
|
+
}
|
|
27715
|
+
}
|
|
27716
|
+
async function getAll(req, res, next) {
|
|
27717
|
+
const query = req.query;
|
|
27718
|
+
const validation = Joi35.object({
|
|
27719
|
+
page: Joi35.number().min(1).optional().allow("", null),
|
|
27720
|
+
limit: Joi35.number().min(1).optional().allow("", null),
|
|
27721
|
+
search: Joi35.string().optional().allow("", null),
|
|
27722
|
+
school: Joi35.string().hex().optional().allow("", null),
|
|
27723
|
+
building: Joi35.string().hex().optional().allow("", null),
|
|
27724
|
+
status: Joi35.string().optional().allow("", null)
|
|
27725
|
+
});
|
|
27726
|
+
const { error } = validation.validate(query);
|
|
27727
|
+
if (error) {
|
|
27728
|
+
next(new BadRequestError63(error.message));
|
|
27729
|
+
return;
|
|
27730
|
+
}
|
|
27731
|
+
const page = parseInt(req.query.page) ?? 1;
|
|
27732
|
+
let limit = parseInt(req.query.limit) ?? 20;
|
|
27733
|
+
limit = isNaN(limit) ? 20 : limit;
|
|
27734
|
+
const sort = req.query.sort ? String(req.query.sort).split(",") : "";
|
|
27735
|
+
const sortOrder = req.query.sortOrder ? String(req.query.sortOrder).split(",") : "";
|
|
27736
|
+
const sortObj = {};
|
|
27737
|
+
if (sort && Array.isArray(sort) && sort.length && sortOrder && Array.isArray(sortOrder) && sortOrder.length) {
|
|
27738
|
+
sort.forEach((field, index) => {
|
|
27739
|
+
sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
|
|
27740
|
+
});
|
|
27741
|
+
}
|
|
27742
|
+
const status = req.query.status ?? "active";
|
|
27743
|
+
const school = req.query.school ?? "";
|
|
27744
|
+
const building = req.query.building ?? "";
|
|
27745
|
+
const search = req.query.search ?? "";
|
|
27746
|
+
try {
|
|
27747
|
+
const buildings = await _getAll({
|
|
27748
|
+
page,
|
|
27749
|
+
limit,
|
|
27750
|
+
sort: sortObj,
|
|
27751
|
+
status,
|
|
27752
|
+
school,
|
|
27753
|
+
search,
|
|
27754
|
+
building
|
|
27755
|
+
});
|
|
27756
|
+
res.json(buildings);
|
|
27757
|
+
return;
|
|
27758
|
+
} catch (error2) {
|
|
27759
|
+
next(error2);
|
|
27760
|
+
}
|
|
27761
|
+
}
|
|
27762
|
+
async function getById(req, res, next) {
|
|
27763
|
+
const id = req.params.id;
|
|
27764
|
+
const validation = Joi35.object({
|
|
27765
|
+
id: Joi35.string().hex().required()
|
|
27766
|
+
});
|
|
27767
|
+
const { error } = validation.validate({ id });
|
|
27768
|
+
if (error) {
|
|
27769
|
+
next(new BadRequestError63(error.message));
|
|
27770
|
+
return;
|
|
27771
|
+
}
|
|
27772
|
+
try {
|
|
27773
|
+
const buildingUnit = await _getById(id);
|
|
27774
|
+
res.json({
|
|
27775
|
+
message: "Successfully retrieved building unit.",
|
|
27776
|
+
data: { buildingUnit }
|
|
27777
|
+
});
|
|
27778
|
+
return;
|
|
27779
|
+
} catch (error2) {
|
|
27780
|
+
next(error2);
|
|
27781
|
+
}
|
|
27782
|
+
}
|
|
27783
|
+
return {
|
|
27784
|
+
add,
|
|
27785
|
+
getAll,
|
|
27786
|
+
getById
|
|
27787
|
+
};
|
|
27788
|
+
}
|
|
27036
27789
|
export {
|
|
27037
27790
|
ACCESS_TOKEN_EXPIRY,
|
|
27038
27791
|
ACCESS_TOKEN_SECRET,
|
|
@@ -27051,6 +27804,8 @@ export {
|
|
|
27051
27804
|
MAILER_TRANSPORT_PORT,
|
|
27052
27805
|
MAILER_TRANSPORT_SECURE,
|
|
27053
27806
|
MAddress,
|
|
27807
|
+
MBuilding,
|
|
27808
|
+
MBuildingUnit,
|
|
27054
27809
|
MDivision,
|
|
27055
27810
|
MEntity,
|
|
27056
27811
|
MFile,
|
|
@@ -27091,6 +27846,8 @@ export {
|
|
|
27091
27846
|
addressSchema,
|
|
27092
27847
|
isDev,
|
|
27093
27848
|
schema,
|
|
27849
|
+
schemaBuilding,
|
|
27850
|
+
schemaBuildingUnit,
|
|
27094
27851
|
schemaDivision,
|
|
27095
27852
|
schemaRegion,
|
|
27096
27853
|
schemaSchool,
|
|
@@ -27098,10 +27855,15 @@ export {
|
|
|
27098
27855
|
useAddressRepo,
|
|
27099
27856
|
useAuthController,
|
|
27100
27857
|
useAuthService,
|
|
27858
|
+
useBuildingController,
|
|
27859
|
+
useBuildingRepo,
|
|
27860
|
+
useBuildingUnitController,
|
|
27861
|
+
useBuildingUnitRepo,
|
|
27101
27862
|
useCounterModel,
|
|
27102
27863
|
useCounterRepo,
|
|
27103
27864
|
useDivisionController,
|
|
27104
27865
|
useDivisionRepo,
|
|
27866
|
+
useDivisionService,
|
|
27105
27867
|
useEntityController,
|
|
27106
27868
|
useEntityRepo,
|
|
27107
27869
|
useFileController,
|
|
@@ -27132,6 +27894,7 @@ export {
|
|
|
27132
27894
|
usePromoCodeRepo,
|
|
27133
27895
|
useRegionController,
|
|
27134
27896
|
useRegionRepo,
|
|
27897
|
+
useRegionService,
|
|
27135
27898
|
useRoleController,
|
|
27136
27899
|
useRoleRepo,
|
|
27137
27900
|
useSchoolController,
|