@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.js
CHANGED
|
@@ -11342,6 +11342,8 @@ __export(src_exports, {
|
|
|
11342
11342
|
MAILER_TRANSPORT_PORT: () => MAILER_TRANSPORT_PORT,
|
|
11343
11343
|
MAILER_TRANSPORT_SECURE: () => MAILER_TRANSPORT_SECURE,
|
|
11344
11344
|
MAddress: () => MAddress,
|
|
11345
|
+
MBuilding: () => MBuilding,
|
|
11346
|
+
MBuildingUnit: () => MBuildingUnit,
|
|
11345
11347
|
MDivision: () => MDivision,
|
|
11346
11348
|
MEntity: () => MEntity,
|
|
11347
11349
|
MFile: () => MFile,
|
|
@@ -11382,6 +11384,8 @@ __export(src_exports, {
|
|
|
11382
11384
|
addressSchema: () => addressSchema,
|
|
11383
11385
|
isDev: () => isDev,
|
|
11384
11386
|
schema: () => schema,
|
|
11387
|
+
schemaBuilding: () => schemaBuilding,
|
|
11388
|
+
schemaBuildingUnit: () => schemaBuildingUnit,
|
|
11385
11389
|
schemaDivision: () => schemaDivision,
|
|
11386
11390
|
schemaRegion: () => schemaRegion,
|
|
11387
11391
|
schemaSchool: () => schemaSchool,
|
|
@@ -11389,10 +11393,15 @@ __export(src_exports, {
|
|
|
11389
11393
|
useAddressRepo: () => useAddressRepo,
|
|
11390
11394
|
useAuthController: () => useAuthController,
|
|
11391
11395
|
useAuthService: () => useAuthService,
|
|
11396
|
+
useBuildingController: () => useBuildingController,
|
|
11397
|
+
useBuildingRepo: () => useBuildingRepo,
|
|
11398
|
+
useBuildingUnitController: () => useBuildingUnitController,
|
|
11399
|
+
useBuildingUnitRepo: () => useBuildingUnitRepo,
|
|
11392
11400
|
useCounterModel: () => useCounterModel,
|
|
11393
11401
|
useCounterRepo: () => useCounterRepo,
|
|
11394
11402
|
useDivisionController: () => useDivisionController,
|
|
11395
11403
|
useDivisionRepo: () => useDivisionRepo,
|
|
11404
|
+
useDivisionService: () => useDivisionService,
|
|
11396
11405
|
useEntityController: () => useEntityController,
|
|
11397
11406
|
useEntityRepo: () => useEntityRepo,
|
|
11398
11407
|
useFileController: () => useFileController,
|
|
@@ -11423,6 +11432,7 @@ __export(src_exports, {
|
|
|
11423
11432
|
usePromoCodeRepo: () => usePromoCodeRepo,
|
|
11424
11433
|
useRegionController: () => useRegionController,
|
|
11425
11434
|
useRegionRepo: () => useRegionRepo,
|
|
11435
|
+
useRegionService: () => useRegionService,
|
|
11426
11436
|
useRoleController: () => useRoleController,
|
|
11427
11437
|
useRoleRepo: () => useRoleRepo,
|
|
11428
11438
|
useSchoolController: () => useSchoolController,
|
|
@@ -11478,9 +11488,9 @@ function useVerificationRepo() {
|
|
|
11478
11488
|
}
|
|
11479
11489
|
const namespace_collection = "verifications";
|
|
11480
11490
|
const collection = db.collection(namespace_collection);
|
|
11481
|
-
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils2.useCache)();
|
|
11491
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils2.useCache)(namespace_collection);
|
|
11482
11492
|
function delCachedData() {
|
|
11483
|
-
delNamespace(
|
|
11493
|
+
delNamespace().then(() => {
|
|
11484
11494
|
import_nodejs_utils2.logger.log({
|
|
11485
11495
|
level: "info",
|
|
11486
11496
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -11568,7 +11578,7 @@ function useVerificationRepo() {
|
|
|
11568
11578
|
return cached;
|
|
11569
11579
|
}
|
|
11570
11580
|
const data = await collection.findOne({ _id });
|
|
11571
|
-
setCache(cacheKey, data, 300
|
|
11581
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
11572
11582
|
import_nodejs_utils2.logger.log({
|
|
11573
11583
|
level: "info",
|
|
11574
11584
|
message: `Cache set for verification by id: ${cacheKey}`
|
|
@@ -11648,7 +11658,7 @@ function useVerificationRepo() {
|
|
|
11648
11658
|
]).toArray();
|
|
11649
11659
|
const length = await collection.countDocuments(query);
|
|
11650
11660
|
const data = (0, import_nodejs_utils2.paginate)(items, page, limit, length);
|
|
11651
|
-
setCache(cacheKey, data, 600
|
|
11661
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
11652
11662
|
import_nodejs_utils2.logger.log({
|
|
11653
11663
|
level: "info",
|
|
11654
11664
|
message: `Cache set for getVerifications: ${cacheKey}`
|
|
@@ -11679,7 +11689,7 @@ function useVerificationRepo() {
|
|
|
11679
11689
|
return cached;
|
|
11680
11690
|
}
|
|
11681
11691
|
const data = await collection.find({ type }).toArray();
|
|
11682
|
-
setCache(cacheKey, data, 600
|
|
11692
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
11683
11693
|
import_nodejs_utils2.logger.log({
|
|
11684
11694
|
level: "info",
|
|
11685
11695
|
message: `Cache set for verification by type: ${cacheKey}`
|
|
@@ -11824,9 +11834,9 @@ function useUserRepo() {
|
|
|
11824
11834
|
}
|
|
11825
11835
|
const namespace_collection = "users";
|
|
11826
11836
|
const collection = db.collection(namespace_collection);
|
|
11827
|
-
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils3.useCache)();
|
|
11837
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils3.useCache)(namespace_collection);
|
|
11828
11838
|
function delCachedData() {
|
|
11829
|
-
delNamespace(
|
|
11839
|
+
delNamespace().then(() => {
|
|
11830
11840
|
import_nodejs_utils3.logger.log({
|
|
11831
11841
|
level: "info",
|
|
11832
11842
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -11888,7 +11898,7 @@ function useUserRepo() {
|
|
|
11888
11898
|
}
|
|
11889
11899
|
const result = await collection.findOne({ email });
|
|
11890
11900
|
if (result) {
|
|
11891
|
-
setCache(cacheKey, result, 300
|
|
11901
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
11892
11902
|
import_nodejs_utils3.logger.log({
|
|
11893
11903
|
level: "info",
|
|
11894
11904
|
message: `Cache set for user by email: ${cacheKey}`
|
|
@@ -11918,7 +11928,7 @@ function useUserRepo() {
|
|
|
11918
11928
|
}
|
|
11919
11929
|
const result = await collection.findOne({ referralCode });
|
|
11920
11930
|
if (result) {
|
|
11921
|
-
setCache(cacheKey, result, 300
|
|
11931
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
11922
11932
|
import_nodejs_utils3.logger.log({
|
|
11923
11933
|
level: "info",
|
|
11924
11934
|
message: `Cache set for user by referral code: ${cacheKey}`
|
|
@@ -11953,7 +11963,7 @@ function useUserRepo() {
|
|
|
11953
11963
|
}
|
|
11954
11964
|
const result = await collection.findOne({ _id });
|
|
11955
11965
|
if (result) {
|
|
11956
|
-
setCache(cacheKey, result, 300
|
|
11966
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
11957
11967
|
import_nodejs_utils3.logger.log({
|
|
11958
11968
|
level: "info",
|
|
11959
11969
|
message: `Cache set for user by id: ${cacheKey}`
|
|
@@ -12027,7 +12037,7 @@ function useUserRepo() {
|
|
|
12027
12037
|
]).toArray();
|
|
12028
12038
|
const length = await collection.countDocuments(query);
|
|
12029
12039
|
const data = (0, import_nodejs_utils3.paginate)(items, page, limit, length);
|
|
12030
|
-
setCache(cacheKey, data, 600
|
|
12040
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
12031
12041
|
import_nodejs_utils3.logger.log({
|
|
12032
12042
|
level: "info",
|
|
12033
12043
|
message: `Cache set for getUsers: ${cacheKey}`
|
|
@@ -12241,9 +12251,9 @@ function useMemberRepo() {
|
|
|
12241
12251
|
}
|
|
12242
12252
|
const namespace_collection = "members";
|
|
12243
12253
|
const collection = db.collection(namespace_collection);
|
|
12244
|
-
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils5.useCache)();
|
|
12254
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils5.useCache)(namespace_collection);
|
|
12245
12255
|
function delCachedData() {
|
|
12246
|
-
delNamespace(
|
|
12256
|
+
delNamespace().then(() => {
|
|
12247
12257
|
import_nodejs_utils5.logger.log({
|
|
12248
12258
|
level: "info",
|
|
12249
12259
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -12334,7 +12344,7 @@ function useMemberRepo() {
|
|
|
12334
12344
|
return cached;
|
|
12335
12345
|
}
|
|
12336
12346
|
const data = await collection.findOne({ _id });
|
|
12337
|
-
setCache(cacheKey, data, 300
|
|
12347
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12338
12348
|
import_nodejs_utils5.logger.log({
|
|
12339
12349
|
level: "info",
|
|
12340
12350
|
message: `Cache set for member by id: ${cacheKey}`
|
|
@@ -12371,7 +12381,7 @@ function useMemberRepo() {
|
|
|
12371
12381
|
return cached;
|
|
12372
12382
|
}
|
|
12373
12383
|
const data = await collection.findOne({ user });
|
|
12374
|
-
setCache(cacheKey, data, 300
|
|
12384
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12375
12385
|
import_nodejs_utils5.logger.log({
|
|
12376
12386
|
level: "info",
|
|
12377
12387
|
message: `Cache set for member by user ID: ${cacheKey}`
|
|
@@ -12424,7 +12434,7 @@ function useMemberRepo() {
|
|
|
12424
12434
|
return cached;
|
|
12425
12435
|
}
|
|
12426
12436
|
const data = await collection.findOne(query);
|
|
12427
|
-
setCache(cacheKey, data, 300
|
|
12437
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12428
12438
|
import_nodejs_utils5.logger.log({
|
|
12429
12439
|
level: "info",
|
|
12430
12440
|
message: `Cache set for member by user ID: ${cacheKey}`
|
|
@@ -12528,7 +12538,7 @@ function useMemberRepo() {
|
|
|
12528
12538
|
]).toArray();
|
|
12529
12539
|
const length = await collection.countDocuments(query);
|
|
12530
12540
|
const data = (0, import_nodejs_utils5.paginate)(items, page, limit, length);
|
|
12531
|
-
setCache(cacheKey, data, 600
|
|
12541
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
12532
12542
|
import_nodejs_utils5.logger.log({
|
|
12533
12543
|
level: "info",
|
|
12534
12544
|
message: `Cache set for getAll members: ${cacheKey}`
|
|
@@ -12563,7 +12573,7 @@ function useMemberRepo() {
|
|
|
12563
12573
|
return cached;
|
|
12564
12574
|
}
|
|
12565
12575
|
const data = await collection.countDocuments({ org, status: "active" });
|
|
12566
|
-
setCache(cacheKey, data, 300
|
|
12576
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12567
12577
|
import_nodejs_utils5.logger.log({
|
|
12568
12578
|
level: "info",
|
|
12569
12579
|
message: `Cache set for countByOrg members: ${cacheKey}`
|
|
@@ -12600,7 +12610,7 @@ function useMemberRepo() {
|
|
|
12600
12610
|
return cached;
|
|
12601
12611
|
}
|
|
12602
12612
|
const data = await collection.countDocuments({ user, status: "active" });
|
|
12603
|
-
setCache(cacheKey, data, 300
|
|
12613
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12604
12614
|
import_nodejs_utils5.logger.log({
|
|
12605
12615
|
level: "info",
|
|
12606
12616
|
message: `Cache set for countByUser members: ${cacheKey}`
|
|
@@ -12674,7 +12684,7 @@ function useMemberRepo() {
|
|
|
12674
12684
|
]).toArray();
|
|
12675
12685
|
const length = await collection.countDocuments(query);
|
|
12676
12686
|
const data = (0, import_nodejs_utils5.paginate)(items, page, limit, length);
|
|
12677
|
-
setCache(cacheKey, data, 600
|
|
12687
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
12678
12688
|
import_nodejs_utils5.logger.log({
|
|
12679
12689
|
level: "info",
|
|
12680
12690
|
message: `Cache set for getOrgsByMembership members: ${cacheKey}`
|
|
@@ -12752,7 +12762,7 @@ function useMemberRepo() {
|
|
|
12752
12762
|
]).toArray();
|
|
12753
12763
|
const length = await collection.countDocuments(query);
|
|
12754
12764
|
const data = (0, import_nodejs_utils5.paginate)(items, page, limit, length);
|
|
12755
|
-
setCache(cacheKey, data, 300
|
|
12765
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
12756
12766
|
import_nodejs_utils5.logger.log({
|
|
12757
12767
|
level: "info",
|
|
12758
12768
|
message: `Cache set for getOrgsByUserId members: ${cacheKey}`
|
|
@@ -13315,9 +13325,9 @@ function useTokenRepo() {
|
|
|
13315
13325
|
}
|
|
13316
13326
|
const namespace_collection = "tokens";
|
|
13317
13327
|
const collection = db.collection(namespace_collection);
|
|
13318
|
-
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils8.useCache)();
|
|
13328
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils8.useCache)(namespace_collection);
|
|
13319
13329
|
function delCachedData() {
|
|
13320
|
-
delNamespace(
|
|
13330
|
+
delNamespace().then(() => {
|
|
13321
13331
|
import_nodejs_utils8.logger.log({
|
|
13322
13332
|
level: "info",
|
|
13323
13333
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -13356,7 +13366,7 @@ function useTokenRepo() {
|
|
|
13356
13366
|
}
|
|
13357
13367
|
const data = await collection.findOne({ token });
|
|
13358
13368
|
if (data) {
|
|
13359
|
-
setCache(cacheKey, data, 300
|
|
13369
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
13360
13370
|
import_nodejs_utils8.logger.log({
|
|
13361
13371
|
level: "info",
|
|
13362
13372
|
message: `Cache set for token: ${cacheKey}`
|
|
@@ -13415,9 +13425,9 @@ function useFileRepo() {
|
|
|
13415
13425
|
}
|
|
13416
13426
|
const namespace_collection = "files";
|
|
13417
13427
|
const collection = db.collection(namespace_collection);
|
|
13418
|
-
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils9.useCache)();
|
|
13428
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils9.useCache)(namespace_collection);
|
|
13419
13429
|
function delCachedData() {
|
|
13420
|
-
delNamespace(
|
|
13430
|
+
delNamespace().then(() => {
|
|
13421
13431
|
import_nodejs_utils9.logger.log({
|
|
13422
13432
|
level: "info",
|
|
13423
13433
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -13465,7 +13475,7 @@ function useFileRepo() {
|
|
|
13465
13475
|
return cached;
|
|
13466
13476
|
}
|
|
13467
13477
|
const data = await collection.find({ $and: [{ status: "draft" }, { status: null }] }).toArray();
|
|
13468
|
-
setCache(cacheKey, data, 300
|
|
13478
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
13469
13479
|
import_nodejs_utils9.logger.log({
|
|
13470
13480
|
level: "info",
|
|
13471
13481
|
message: `Cache set for getAllDraftedFiles: ${cacheKey}`
|
|
@@ -13538,6 +13548,16 @@ var isPlainObject = (val) => {
|
|
|
13538
13548
|
const prototype3 = getPrototypeOf(val);
|
|
13539
13549
|
return (prototype3 === null || prototype3 === Object.prototype || Object.getPrototypeOf(prototype3) === null) && !(toStringTag in val) && !(iterator in val);
|
|
13540
13550
|
};
|
|
13551
|
+
var isEmptyObject = (val) => {
|
|
13552
|
+
if (!isObject(val) || isBuffer(val)) {
|
|
13553
|
+
return false;
|
|
13554
|
+
}
|
|
13555
|
+
try {
|
|
13556
|
+
return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
|
|
13557
|
+
} catch (e) {
|
|
13558
|
+
return false;
|
|
13559
|
+
}
|
|
13560
|
+
};
|
|
13541
13561
|
var isDate = kindOfTest("Date");
|
|
13542
13562
|
var isFile = kindOfTest("File");
|
|
13543
13563
|
var isBlob = kindOfTest("Blob");
|
|
@@ -13565,6 +13585,9 @@ function forEach(obj, fn, { allOwnKeys = false } = {}) {
|
|
|
13565
13585
|
fn.call(null, obj[i], i, obj);
|
|
13566
13586
|
}
|
|
13567
13587
|
} else {
|
|
13588
|
+
if (isBuffer(obj)) {
|
|
13589
|
+
return;
|
|
13590
|
+
}
|
|
13568
13591
|
const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
|
13569
13592
|
const len = keys.length;
|
|
13570
13593
|
let key;
|
|
@@ -13575,6 +13598,9 @@ function forEach(obj, fn, { allOwnKeys = false } = {}) {
|
|
|
13575
13598
|
}
|
|
13576
13599
|
}
|
|
13577
13600
|
function findKey(obj, key) {
|
|
13601
|
+
if (isBuffer(obj)) {
|
|
13602
|
+
return null;
|
|
13603
|
+
}
|
|
13578
13604
|
key = key.toLowerCase();
|
|
13579
13605
|
const keys = Object.keys(obj);
|
|
13580
13606
|
let i = keys.length;
|
|
@@ -13771,6 +13797,9 @@ var toJSONObject = (obj) => {
|
|
|
13771
13797
|
if (stack.indexOf(source) >= 0) {
|
|
13772
13798
|
return;
|
|
13773
13799
|
}
|
|
13800
|
+
if (isBuffer(source)) {
|
|
13801
|
+
return source;
|
|
13802
|
+
}
|
|
13774
13803
|
if (!("toJSON" in source)) {
|
|
13775
13804
|
stack[i] = source;
|
|
13776
13805
|
const target = isArray(source) ? [] : {};
|
|
@@ -13820,6 +13849,7 @@ var utils_default = {
|
|
|
13820
13849
|
isBoolean,
|
|
13821
13850
|
isObject,
|
|
13822
13851
|
isPlainObject,
|
|
13852
|
+
isEmptyObject,
|
|
13823
13853
|
isReadableStream,
|
|
13824
13854
|
isRequest,
|
|
13825
13855
|
isResponse,
|
|
@@ -14264,15 +14294,16 @@ var platform_default = {
|
|
|
14264
14294
|
|
|
14265
14295
|
// node_modules/axios/lib/helpers/toURLEncodedForm.js
|
|
14266
14296
|
function toURLEncodedForm(data, options) {
|
|
14267
|
-
return toFormData_default(data, new platform_default.classes.URLSearchParams(),
|
|
14297
|
+
return toFormData_default(data, new platform_default.classes.URLSearchParams(), {
|
|
14268
14298
|
visitor: function(value, key, path, helpers) {
|
|
14269
14299
|
if (platform_default.isNode && utils_default.isBuffer(value)) {
|
|
14270
14300
|
this.append(key, value.toString("base64"));
|
|
14271
14301
|
return false;
|
|
14272
14302
|
}
|
|
14273
14303
|
return helpers.defaultVisitor.apply(this, arguments);
|
|
14274
|
-
}
|
|
14275
|
-
|
|
14304
|
+
},
|
|
14305
|
+
...options
|
|
14306
|
+
});
|
|
14276
14307
|
}
|
|
14277
14308
|
|
|
14278
14309
|
// node_modules/axios/lib/helpers/formDataToJSON.js
|
|
@@ -14785,7 +14816,7 @@ var import_follow_redirects = __toESM(require_follow_redirects(), 1);
|
|
|
14785
14816
|
var import_zlib = __toESM(require("zlib"), 1);
|
|
14786
14817
|
|
|
14787
14818
|
// node_modules/axios/lib/env/data.js
|
|
14788
|
-
var VERSION = "1.
|
|
14819
|
+
var VERSION = "1.11.0";
|
|
14789
14820
|
|
|
14790
14821
|
// node_modules/axios/lib/helpers/parseProtocol.js
|
|
14791
14822
|
function parseProtocol(url2) {
|
|
@@ -15127,7 +15158,7 @@ function throttle(fn, freq) {
|
|
|
15127
15158
|
clearTimeout(timer);
|
|
15128
15159
|
timer = null;
|
|
15129
15160
|
}
|
|
15130
|
-
fn
|
|
15161
|
+
fn(...args);
|
|
15131
15162
|
};
|
|
15132
15163
|
const throttled = (...args) => {
|
|
15133
15164
|
const now = Date.now();
|
|
@@ -15802,7 +15833,7 @@ function mergeConfig(config1, config2) {
|
|
|
15802
15833
|
validateStatus: mergeDirectKeys,
|
|
15803
15834
|
headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
|
|
15804
15835
|
};
|
|
15805
|
-
utils_default.forEach(Object.keys(
|
|
15836
|
+
utils_default.forEach(Object.keys({ ...config1, ...config2 }), function computeConfigValue(prop) {
|
|
15806
15837
|
const merge2 = mergeMap[prop] || mergeDeepProperties;
|
|
15807
15838
|
const configValue = merge2(config1[prop], config2[prop], prop);
|
|
15808
15839
|
utils_default.isUndefined(configValue) && merge2 !== mergeDirectKeys || (config3[prop] = configValue);
|
|
@@ -16516,8 +16547,8 @@ var Axios = class {
|
|
|
16516
16547
|
let len;
|
|
16517
16548
|
if (!synchronousRequestInterceptors) {
|
|
16518
16549
|
const chain = [dispatchRequest.bind(this), void 0];
|
|
16519
|
-
chain.unshift
|
|
16520
|
-
chain.push
|
|
16550
|
+
chain.unshift(...requestInterceptorChain);
|
|
16551
|
+
chain.push(...responseInterceptorChain);
|
|
16521
16552
|
len = chain.length;
|
|
16522
16553
|
promise = Promise.resolve(config2);
|
|
16523
16554
|
while (i < len) {
|
|
@@ -17491,9 +17522,9 @@ function useRoleRepo() {
|
|
|
17491
17522
|
}
|
|
17492
17523
|
const namespace_collection = "roles";
|
|
17493
17524
|
const collection = db.collection(namespace_collection);
|
|
17494
|
-
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils11.useCache)();
|
|
17525
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils11.useCache)(namespace_collection);
|
|
17495
17526
|
function delCachedData() {
|
|
17496
|
-
delNamespace(
|
|
17527
|
+
delNamespace().then(() => {
|
|
17497
17528
|
import_nodejs_utils11.logger.log({
|
|
17498
17529
|
level: "info",
|
|
17499
17530
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -17566,7 +17597,7 @@ function useRoleRepo() {
|
|
|
17566
17597
|
return cached;
|
|
17567
17598
|
}
|
|
17568
17599
|
const data = await collection.findOne({ user: value });
|
|
17569
|
-
setCache(cacheKey, data, 300
|
|
17600
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
17570
17601
|
import_nodejs_utils11.logger.log({
|
|
17571
17602
|
level: "info",
|
|
17572
17603
|
message: `Cache set for role by user ID: ${cacheKey}`
|
|
@@ -17601,7 +17632,7 @@ function useRoleRepo() {
|
|
|
17601
17632
|
return cached;
|
|
17602
17633
|
}
|
|
17603
17634
|
const data = await collection.findOne({ _id });
|
|
17604
|
-
setCache(cacheKey, data, 300
|
|
17635
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
17605
17636
|
import_nodejs_utils11.logger.log({
|
|
17606
17637
|
level: "info",
|
|
17607
17638
|
message: `Cache set for role by id: ${cacheKey}`
|
|
@@ -17634,7 +17665,7 @@ function useRoleRepo() {
|
|
|
17634
17665
|
return cached;
|
|
17635
17666
|
}
|
|
17636
17667
|
const data = await collection.findOne({ name });
|
|
17637
|
-
setCache(cacheKey, data, 300
|
|
17668
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
17638
17669
|
import_nodejs_utils11.logger.log({
|
|
17639
17670
|
level: "info",
|
|
17640
17671
|
message: `Cache set for role by name: ${cacheKey}`
|
|
@@ -17708,7 +17739,7 @@ function useRoleRepo() {
|
|
|
17708
17739
|
]).toArray();
|
|
17709
17740
|
const length = await collection.countDocuments(query);
|
|
17710
17741
|
const data = (0, import_nodejs_utils11.paginate)(items, page, limit, length);
|
|
17711
|
-
setCache(cacheKey, data, 600
|
|
17742
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
17712
17743
|
import_nodejs_utils11.logger.log({
|
|
17713
17744
|
level: "info",
|
|
17714
17745
|
message: `Cache set for getRoles: ${cacheKey}`
|
|
@@ -18414,8 +18445,10 @@ function useUserController() {
|
|
|
18414
18445
|
// src/services/auth.service.ts
|
|
18415
18446
|
var import_nodejs_utils14 = require("@eeplatform/nodejs-utils");
|
|
18416
18447
|
var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
|
|
18448
|
+
var import_uuid = require("uuid");
|
|
18417
18449
|
function useAuthService() {
|
|
18418
18450
|
const expiresIn = "1m";
|
|
18451
|
+
const { setCache, delCache } = (0, import_nodejs_utils14.useCache)("sessions");
|
|
18419
18452
|
async function login({ email, password } = {}) {
|
|
18420
18453
|
if (!email) {
|
|
18421
18454
|
throw new import_nodejs_utils14.BadRequestError("Email is required");
|
|
@@ -18447,34 +18480,14 @@ function useAuthService() {
|
|
|
18447
18480
|
if (!isPasswordValid) {
|
|
18448
18481
|
throw new import_nodejs_utils14.BadRequestError("Invalid password");
|
|
18449
18482
|
}
|
|
18450
|
-
const
|
|
18451
|
-
|
|
18452
|
-
|
|
18453
|
-
|
|
18454
|
-
|
|
18455
|
-
|
|
18456
|
-
|
|
18457
|
-
|
|
18458
|
-
} catch (error) {
|
|
18459
|
-
throw new import_nodejs_utils14.BadRequestError("Error generating refresh token");
|
|
18460
|
-
}
|
|
18461
|
-
let accessToken;
|
|
18462
|
-
try {
|
|
18463
|
-
accessToken = (0, import_nodejs_utils14.generateToken)({
|
|
18464
|
-
secret: ACCESS_TOKEN_SECRET,
|
|
18465
|
-
metadata,
|
|
18466
|
-
options: { expiresIn }
|
|
18467
|
-
});
|
|
18468
|
-
} catch (error) {
|
|
18469
|
-
throw new import_nodejs_utils14.BadRequestError("Error generating access token");
|
|
18470
|
-
}
|
|
18471
|
-
const user = _user._id ?? "";
|
|
18472
|
-
try {
|
|
18473
|
-
await useTokenRepo().createToken({ token: refreshToken2, user });
|
|
18474
|
-
} catch (error) {
|
|
18475
|
-
throw new import_nodejs_utils14.BadRequestError("Error creating refresh token");
|
|
18476
|
-
}
|
|
18477
|
-
return { accessToken, refreshToken: refreshToken2, id: _user._id };
|
|
18483
|
+
const sid = (0, import_uuid.v4)();
|
|
18484
|
+
const cacheKey = `sid:${sid}`;
|
|
18485
|
+
setCache(cacheKey, _user, 14400).then(() => {
|
|
18486
|
+
console.log("Session ID cached successfully");
|
|
18487
|
+
}).catch((error) => {
|
|
18488
|
+
console.error("Error caching session ID:", error);
|
|
18489
|
+
});
|
|
18490
|
+
return { sid, user: _user._id?.toString() ?? "" };
|
|
18478
18491
|
}
|
|
18479
18492
|
async function refreshToken(token) {
|
|
18480
18493
|
let decoded;
|
|
@@ -18508,26 +18521,13 @@ function useAuthService() {
|
|
|
18508
18521
|
}
|
|
18509
18522
|
return accessToken;
|
|
18510
18523
|
}
|
|
18511
|
-
async function logout(
|
|
18512
|
-
let _token;
|
|
18513
|
-
try {
|
|
18514
|
-
_token = await useTokenRepo().getToken(token);
|
|
18515
|
-
if (!_token) {
|
|
18516
|
-
throw new import_nodejs_utils14.NotFoundError("Invalid token");
|
|
18517
|
-
}
|
|
18518
|
-
} catch (error) {
|
|
18519
|
-
if (error instanceof import_nodejs_utils14.AppError) {
|
|
18520
|
-
throw error;
|
|
18521
|
-
} else {
|
|
18522
|
-
throw new import_nodejs_utils14.InternalServerError(`${error}`);
|
|
18523
|
-
}
|
|
18524
|
-
}
|
|
18524
|
+
async function logout(sid) {
|
|
18525
18525
|
try {
|
|
18526
|
-
await
|
|
18526
|
+
await delCache(`sid:${sid}`);
|
|
18527
|
+
return "Session deleted successfully";
|
|
18527
18528
|
} catch (error) {
|
|
18528
18529
|
throw new import_nodejs_utils14.InternalServerError("Error deleting token");
|
|
18529
18530
|
}
|
|
18530
|
-
return "Logged out successfully";
|
|
18531
18531
|
}
|
|
18532
18532
|
return {
|
|
18533
18533
|
login,
|
|
@@ -18551,16 +18551,26 @@ function useAuthController() {
|
|
|
18551
18551
|
const { error } = validation.validate({ email, password });
|
|
18552
18552
|
if (error) {
|
|
18553
18553
|
next(new import_nodejs_utils15.BadRequestError(error.message));
|
|
18554
|
+
return;
|
|
18554
18555
|
}
|
|
18555
18556
|
try {
|
|
18556
|
-
const
|
|
18557
|
-
|
|
18557
|
+
const session = await useAuthService().login({
|
|
18558
|
+
email,
|
|
18559
|
+
password
|
|
18560
|
+
});
|
|
18561
|
+
res.json(session);
|
|
18558
18562
|
} catch (error2) {
|
|
18563
|
+
import_nodejs_utils15.logger.log({
|
|
18564
|
+
level: "error",
|
|
18565
|
+
message: `Error during login: ${error2.message}`
|
|
18566
|
+
});
|
|
18567
|
+
console.log(`Error during login: ${error2}`);
|
|
18559
18568
|
if (error2 instanceof import_nodejs_utils15.AppError) {
|
|
18560
18569
|
next(error2);
|
|
18561
18570
|
} else {
|
|
18562
18571
|
next(new import_nodejs_utils15.InternalServerError("An unexpected error occurred"));
|
|
18563
18572
|
}
|
|
18573
|
+
return;
|
|
18564
18574
|
}
|
|
18565
18575
|
}
|
|
18566
18576
|
async function refreshToken(req, res, next) {
|
|
@@ -18581,13 +18591,13 @@ function useAuthController() {
|
|
|
18581
18591
|
}
|
|
18582
18592
|
}
|
|
18583
18593
|
async function logout(req, res, next) {
|
|
18584
|
-
const
|
|
18585
|
-
if (!
|
|
18586
|
-
next(new import_nodejs_utils15.BadRequestError("
|
|
18594
|
+
const sid = req.headers["authorization"] ?? "";
|
|
18595
|
+
if (!sid) {
|
|
18596
|
+
next(new import_nodejs_utils15.BadRequestError("Session ID is required"));
|
|
18587
18597
|
return;
|
|
18588
18598
|
}
|
|
18589
18599
|
try {
|
|
18590
|
-
await useAuthService().logout(
|
|
18600
|
+
await useAuthService().logout(sid);
|
|
18591
18601
|
res.json({ message: "Logged out successfully" });
|
|
18592
18602
|
} catch (error) {
|
|
18593
18603
|
if (error instanceof import_nodejs_utils15.AppError) {
|
|
@@ -18983,9 +18993,9 @@ function useEntityRepo() {
|
|
|
18983
18993
|
}
|
|
18984
18994
|
const namespace_collection = "entities";
|
|
18985
18995
|
const collection = db.collection(namespace_collection);
|
|
18986
|
-
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils19.useCache)();
|
|
18996
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils19.useCache)(namespace_collection);
|
|
18987
18997
|
function delCachedData() {
|
|
18988
|
-
delNamespace(
|
|
18998
|
+
delNamespace().then(() => {
|
|
18989
18999
|
import_nodejs_utils19.logger.log({
|
|
18990
19000
|
level: "info",
|
|
18991
19001
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -19065,7 +19075,7 @@ function useEntityRepo() {
|
|
|
19065
19075
|
]).toArray();
|
|
19066
19076
|
const length = await collection.countDocuments(query);
|
|
19067
19077
|
const data = (0, import_nodejs_utils19.paginate)(items, page, limit, length);
|
|
19068
|
-
setCache(cacheKey, data, 600
|
|
19078
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
19069
19079
|
import_nodejs_utils19.logger.log({
|
|
19070
19080
|
level: "info",
|
|
19071
19081
|
message: `Cache set for getEntities: ${cacheKey}`
|
|
@@ -19342,9 +19352,9 @@ function useSubscriptionRepo() {
|
|
|
19342
19352
|
}
|
|
19343
19353
|
const namespace_collection = "subscriptions";
|
|
19344
19354
|
const collection = db.collection(namespace_collection);
|
|
19345
|
-
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils22.useCache)();
|
|
19355
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils22.useCache)(namespace_collection);
|
|
19346
19356
|
function delCachedData() {
|
|
19347
|
-
delNamespace(
|
|
19357
|
+
delNamespace().then(() => {
|
|
19348
19358
|
import_nodejs_utils22.logger.log({
|
|
19349
19359
|
level: "info",
|
|
19350
19360
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -19410,7 +19420,7 @@ function useSubscriptionRepo() {
|
|
|
19410
19420
|
}
|
|
19411
19421
|
const data = await collection.findOne({ _id });
|
|
19412
19422
|
if (data) {
|
|
19413
|
-
setCache(cacheKey, data, 300
|
|
19423
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
19414
19424
|
import_nodejs_utils22.logger.log({
|
|
19415
19425
|
level: "info",
|
|
19416
19426
|
message: `Cache set for subscription by ID: ${cacheKey}`
|
|
@@ -19445,7 +19455,7 @@ function useSubscriptionRepo() {
|
|
|
19445
19455
|
}
|
|
19446
19456
|
const data = await collection.findOne({ user });
|
|
19447
19457
|
if (data) {
|
|
19448
|
-
setCache(cacheKey, data, 300
|
|
19458
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
19449
19459
|
import_nodejs_utils22.logger.log({
|
|
19450
19460
|
level: "info",
|
|
19451
19461
|
message: `Cache set for subscription by user ID: ${cacheKey}`
|
|
@@ -19505,7 +19515,7 @@ function useSubscriptionRepo() {
|
|
|
19505
19515
|
}
|
|
19506
19516
|
const data = await collection.findOne({ subscriptionId });
|
|
19507
19517
|
if (data) {
|
|
19508
|
-
setCache(cacheKey, data, 300
|
|
19518
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
19509
19519
|
import_nodejs_utils22.logger.log({
|
|
19510
19520
|
level: "info",
|
|
19511
19521
|
message: `Cache set for subscription by subscription ID: ${cacheKey}`
|
|
@@ -19561,7 +19571,7 @@ function useSubscriptionRepo() {
|
|
|
19561
19571
|
]).toArray();
|
|
19562
19572
|
const length = await collection.countDocuments(query);
|
|
19563
19573
|
const data = (0, import_nodejs_utils22.paginate)(items, page, limit, length);
|
|
19564
|
-
setCache(cacheKey, data, 600
|
|
19574
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
19565
19575
|
import_nodejs_utils22.logger.log({
|
|
19566
19576
|
level: "info",
|
|
19567
19577
|
message: `Cache set for getSubscriptions: ${cacheKey}`
|
|
@@ -20030,7 +20040,7 @@ function useOrgRepo() {
|
|
|
20030
20040
|
}
|
|
20031
20041
|
const namespace_collection = "organizations";
|
|
20032
20042
|
const collection = db.collection(namespace_collection);
|
|
20033
|
-
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils24.useCache)();
|
|
20043
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils24.useCache)(namespace_collection);
|
|
20034
20044
|
async function createIndex() {
|
|
20035
20045
|
try {
|
|
20036
20046
|
await collection.createIndex([
|
|
@@ -20065,7 +20075,7 @@ function useOrgRepo() {
|
|
|
20065
20075
|
}
|
|
20066
20076
|
}
|
|
20067
20077
|
function delCachedData() {
|
|
20068
|
-
delNamespace(
|
|
20078
|
+
delNamespace().then(() => {
|
|
20069
20079
|
import_nodejs_utils24.logger.log({
|
|
20070
20080
|
level: "info",
|
|
20071
20081
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -20149,7 +20159,7 @@ function useOrgRepo() {
|
|
|
20149
20159
|
]).toArray();
|
|
20150
20160
|
const length = await collection.countDocuments(query);
|
|
20151
20161
|
const data = (0, import_nodejs_utils24.paginate)(items, page, limit, length);
|
|
20152
|
-
setCache(cacheKey, data, 600
|
|
20162
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
20153
20163
|
import_nodejs_utils24.logger.log({
|
|
20154
20164
|
level: "info",
|
|
20155
20165
|
message: `Cache set for getAll organizations: ${cacheKey}`
|
|
@@ -20186,7 +20196,7 @@ function useOrgRepo() {
|
|
|
20186
20196
|
if (!result) {
|
|
20187
20197
|
throw new import_nodejs_utils24.BadRequestError("Organization not found.");
|
|
20188
20198
|
}
|
|
20189
|
-
setCache(cacheKey, result, 300
|
|
20199
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
20190
20200
|
import_nodejs_utils24.logger.log({
|
|
20191
20201
|
level: "info",
|
|
20192
20202
|
message: `Cache set for organization by id: ${cacheKey}`
|
|
@@ -20221,7 +20231,7 @@ function useOrgRepo() {
|
|
|
20221
20231
|
if (!result) {
|
|
20222
20232
|
throw new import_nodejs_utils24.BadRequestError("Organization not found.");
|
|
20223
20233
|
}
|
|
20224
|
-
setCache(cacheKey, result, 300
|
|
20234
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
20225
20235
|
import_nodejs_utils24.logger.log({
|
|
20226
20236
|
level: "info",
|
|
20227
20237
|
message: `Cache set for organization by name: ${cacheKey}`
|
|
@@ -20353,9 +20363,9 @@ function useAddressRepo() {
|
|
|
20353
20363
|
}
|
|
20354
20364
|
const namespace_collection = "addresses";
|
|
20355
20365
|
const collection = db.collection(namespace_collection);
|
|
20356
|
-
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils26.useCache)();
|
|
20366
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils26.useCache)(namespace_collection);
|
|
20357
20367
|
function delCachedData() {
|
|
20358
|
-
delNamespace(
|
|
20368
|
+
delNamespace().then(() => {
|
|
20359
20369
|
import_nodejs_utils26.logger.log({
|
|
20360
20370
|
level: "info",
|
|
20361
20371
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -20431,7 +20441,7 @@ function useAddressRepo() {
|
|
|
20431
20441
|
}
|
|
20432
20442
|
const data = await collection.findOne({ user });
|
|
20433
20443
|
if (data) {
|
|
20434
|
-
setCache(cacheKey, data, 300
|
|
20444
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
20435
20445
|
import_nodejs_utils26.logger.log({
|
|
20436
20446
|
level: "info",
|
|
20437
20447
|
message: `Cache set for address by user ID: ${cacheKey}`
|
|
@@ -20466,7 +20476,7 @@ function useAddressRepo() {
|
|
|
20466
20476
|
}
|
|
20467
20477
|
const data = await collection.findOne({ org });
|
|
20468
20478
|
if (data) {
|
|
20469
|
-
setCache(cacheKey, data, 300
|
|
20479
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
20470
20480
|
import_nodejs_utils26.logger.log({
|
|
20471
20481
|
level: "info",
|
|
20472
20482
|
message: `Cache set for address by org ID: ${cacheKey}`
|
|
@@ -20552,9 +20562,9 @@ function usePromoCodeRepo() {
|
|
|
20552
20562
|
}
|
|
20553
20563
|
const namespace_collection = "promo-codes";
|
|
20554
20564
|
const collection = db.collection(namespace_collection);
|
|
20555
|
-
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils28.useCache)();
|
|
20565
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils28.useCache)(namespace_collection);
|
|
20556
20566
|
function delCachedData() {
|
|
20557
|
-
delNamespace(
|
|
20567
|
+
delNamespace().then(() => {
|
|
20558
20568
|
import_nodejs_utils28.logger.log({
|
|
20559
20569
|
level: "info",
|
|
20560
20570
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -20634,7 +20644,7 @@ function usePromoCodeRepo() {
|
|
|
20634
20644
|
}
|
|
20635
20645
|
const data = await collection.findOne(query);
|
|
20636
20646
|
if (data) {
|
|
20637
|
-
setCache(cacheKey, data, 300
|
|
20647
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
20638
20648
|
import_nodejs_utils28.logger.log({
|
|
20639
20649
|
level: "info",
|
|
20640
20650
|
message: `Cache set for promo code by code: ${cacheKey}`
|
|
@@ -20676,7 +20686,7 @@ function usePromoCodeRepo() {
|
|
|
20676
20686
|
}
|
|
20677
20687
|
const data = await collection.findOne({ _id });
|
|
20678
20688
|
if (data) {
|
|
20679
|
-
setCache(cacheKey, data, 300
|
|
20689
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
20680
20690
|
import_nodejs_utils28.logger.log({
|
|
20681
20691
|
level: "info",
|
|
20682
20692
|
message: `Cache set for promo code by ID: ${cacheKey}`
|
|
@@ -20735,7 +20745,7 @@ function usePromoCodeRepo() {
|
|
|
20735
20745
|
]).toArray();
|
|
20736
20746
|
const length = await collection.countDocuments(query);
|
|
20737
20747
|
const data = (0, import_nodejs_utils28.paginate)(items, page, limit, length);
|
|
20738
|
-
setCache(cacheKey, data, 600
|
|
20748
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
20739
20749
|
import_nodejs_utils28.logger.log({
|
|
20740
20750
|
level: "info",
|
|
20741
20751
|
message: `Cache set for getPromoCodes: ${cacheKey}`
|
|
@@ -21101,9 +21111,9 @@ function useCounterRepo() {
|
|
|
21101
21111
|
}
|
|
21102
21112
|
const namespace_collection = "counters";
|
|
21103
21113
|
const { collection, createCounter } = useCounterModel(db);
|
|
21104
|
-
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils32.useCache)();
|
|
21114
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils32.useCache)(namespace_collection);
|
|
21105
21115
|
function delCachedData() {
|
|
21106
|
-
delNamespace(
|
|
21116
|
+
delNamespace().then(() => {
|
|
21107
21117
|
import_nodejs_utils32.logger.log({
|
|
21108
21118
|
level: "info",
|
|
21109
21119
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -21173,7 +21183,7 @@ function useCounterRepo() {
|
|
|
21173
21183
|
}
|
|
21174
21184
|
const data = await collection.findOne({ type });
|
|
21175
21185
|
if (data) {
|
|
21176
|
-
setCache(cacheKey, data, 300
|
|
21186
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
21177
21187
|
import_nodejs_utils32.logger.log({
|
|
21178
21188
|
level: "info",
|
|
21179
21189
|
message: `Cache set for counter by type: ${cacheKey}`
|
|
@@ -21366,9 +21376,9 @@ function usePriceRepo() {
|
|
|
21366
21376
|
}
|
|
21367
21377
|
const namespace_collection = "prices";
|
|
21368
21378
|
const { collection, createPrice } = usePriceModel(db);
|
|
21369
|
-
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils35.useCache)();
|
|
21379
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils35.useCache)(namespace_collection);
|
|
21370
21380
|
function delCachedData() {
|
|
21371
|
-
delNamespace(
|
|
21381
|
+
delNamespace().then(() => {
|
|
21372
21382
|
import_nodejs_utils35.logger.log({
|
|
21373
21383
|
level: "info",
|
|
21374
21384
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -21438,7 +21448,7 @@ function usePriceRepo() {
|
|
|
21438
21448
|
}
|
|
21439
21449
|
const data = await collection.findOne({ name, type });
|
|
21440
21450
|
if (data) {
|
|
21441
|
-
setCache(cacheKey, data, 300
|
|
21451
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
21442
21452
|
import_nodejs_utils35.logger.log({
|
|
21443
21453
|
level: "info",
|
|
21444
21454
|
message: `Cache set for price by name and type: ${cacheKey}`
|
|
@@ -24691,9 +24701,9 @@ function useOrderRepo() {
|
|
|
24691
24701
|
}
|
|
24692
24702
|
const namespace_collection = "orders";
|
|
24693
24703
|
const collection = db.collection(namespace_collection);
|
|
24694
|
-
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils49.useCache)();
|
|
24704
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils49.useCache)(namespace_collection);
|
|
24695
24705
|
function delCachedData() {
|
|
24696
|
-
delNamespace(
|
|
24706
|
+
delNamespace().then(() => {
|
|
24697
24707
|
import_nodejs_utils49.logger.log({
|
|
24698
24708
|
level: "info",
|
|
24699
24709
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -24780,7 +24790,7 @@ function useOrderRepo() {
|
|
|
24780
24790
|
]).toArray();
|
|
24781
24791
|
const length = await collection.countDocuments(query);
|
|
24782
24792
|
const data = (0, import_nodejs_utils49.paginate)(items, page, limit, length);
|
|
24783
|
-
setCache(cacheKey, data, 600
|
|
24793
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
24784
24794
|
import_nodejs_utils49.logger.log({
|
|
24785
24795
|
level: "info",
|
|
24786
24796
|
message: `Cache set for getOrders: ${cacheKey}`
|
|
@@ -25330,7 +25340,7 @@ function useRegionRepo() {
|
|
|
25330
25340
|
}
|
|
25331
25341
|
const namespace_collection = "regions";
|
|
25332
25342
|
const collection = db.collection(namespace_collection);
|
|
25333
|
-
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils56.useCache)();
|
|
25343
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils56.useCache)(namespace_collection);
|
|
25334
25344
|
async function createIndex() {
|
|
25335
25345
|
try {
|
|
25336
25346
|
await collection.createIndex([
|
|
@@ -25367,7 +25377,7 @@ function useRegionRepo() {
|
|
|
25367
25377
|
}
|
|
25368
25378
|
}
|
|
25369
25379
|
function delCachedData() {
|
|
25370
|
-
delNamespace(
|
|
25380
|
+
delNamespace().then(() => {
|
|
25371
25381
|
import_nodejs_utils56.logger.log({
|
|
25372
25382
|
level: "info",
|
|
25373
25383
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -25445,7 +25455,7 @@ function useRegionRepo() {
|
|
|
25445
25455
|
]).toArray();
|
|
25446
25456
|
const length = await collection.countDocuments(query);
|
|
25447
25457
|
const data = (0, import_nodejs_utils56.paginate)(items, page, limit, length);
|
|
25448
|
-
setCache(cacheKey, data, 600
|
|
25458
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
25449
25459
|
import_nodejs_utils56.logger.log({
|
|
25450
25460
|
level: "info",
|
|
25451
25461
|
message: `Cache set for getAll regions: ${cacheKey}`
|
|
@@ -25485,7 +25495,7 @@ function useRegionRepo() {
|
|
|
25485
25495
|
if (!result) {
|
|
25486
25496
|
throw new import_nodejs_utils56.BadRequestError("Region not found.");
|
|
25487
25497
|
}
|
|
25488
|
-
setCache(cacheKey, result, 300
|
|
25498
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
25489
25499
|
import_nodejs_utils56.logger.log({
|
|
25490
25500
|
level: "info",
|
|
25491
25501
|
message: `Cache set for region by id: ${cacheKey}`
|
|
@@ -25523,7 +25533,7 @@ function useRegionRepo() {
|
|
|
25523
25533
|
if (!result) {
|
|
25524
25534
|
throw new import_nodejs_utils56.BadRequestError("Region not found.");
|
|
25525
25535
|
}
|
|
25526
|
-
setCache(cacheKey, result, 300
|
|
25536
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
25527
25537
|
import_nodejs_utils56.logger.log({
|
|
25528
25538
|
level: "info",
|
|
25529
25539
|
message: `Cache set for region by name: ${cacheKey}`
|
|
@@ -25597,10 +25607,6 @@ function useRegionRepo() {
|
|
|
25597
25607
|
};
|
|
25598
25608
|
}
|
|
25599
25609
|
|
|
25600
|
-
// src/controllers/region.controller.ts
|
|
25601
|
-
var import_nodejs_utils58 = require("@eeplatform/nodejs-utils");
|
|
25602
|
-
var import_joi28 = __toESM(require("joi"));
|
|
25603
|
-
|
|
25604
25610
|
// src/services/region.service.ts
|
|
25605
25611
|
var import_nodejs_utils57 = require("@eeplatform/nodejs-utils");
|
|
25606
25612
|
function useRegionService() {
|
|
@@ -25640,6 +25646,8 @@ function useRegionService() {
|
|
|
25640
25646
|
}
|
|
25641
25647
|
|
|
25642
25648
|
// src/controllers/region.controller.ts
|
|
25649
|
+
var import_nodejs_utils58 = require("@eeplatform/nodejs-utils");
|
|
25650
|
+
var import_joi28 = __toESM(require("joi"));
|
|
25643
25651
|
function useRegionController() {
|
|
25644
25652
|
const {
|
|
25645
25653
|
getAll: _getAll,
|
|
@@ -25860,7 +25868,7 @@ function useDivisionRepo() {
|
|
|
25860
25868
|
}
|
|
25861
25869
|
const namespace_collection = "divisions";
|
|
25862
25870
|
const collection = db.collection(namespace_collection);
|
|
25863
|
-
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils60.useCache)();
|
|
25871
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils60.useCache)(namespace_collection);
|
|
25864
25872
|
async function createIndex() {
|
|
25865
25873
|
try {
|
|
25866
25874
|
await collection.createIndex([
|
|
@@ -25899,7 +25907,7 @@ function useDivisionRepo() {
|
|
|
25899
25907
|
}
|
|
25900
25908
|
}
|
|
25901
25909
|
function delCachedData() {
|
|
25902
|
-
delNamespace(
|
|
25910
|
+
delNamespace().then(() => {
|
|
25903
25911
|
import_nodejs_utils60.logger.log({
|
|
25904
25912
|
level: "info",
|
|
25905
25913
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -25993,7 +26001,7 @@ function useDivisionRepo() {
|
|
|
25993
26001
|
]).toArray();
|
|
25994
26002
|
const length = await collection.countDocuments(query);
|
|
25995
26003
|
const data = (0, import_nodejs_utils60.paginate)(items, page, limit, length);
|
|
25996
|
-
setCache(cacheKey, data, 600
|
|
26004
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
25997
26005
|
import_nodejs_utils60.logger.log({
|
|
25998
26006
|
level: "info",
|
|
25999
26007
|
message: `Cache set for getAll divisions: ${cacheKey}`
|
|
@@ -26033,7 +26041,7 @@ function useDivisionRepo() {
|
|
|
26033
26041
|
if (!result) {
|
|
26034
26042
|
throw new import_nodejs_utils60.BadRequestError("Division not found.");
|
|
26035
26043
|
}
|
|
26036
|
-
setCache(cacheKey, result, 300
|
|
26044
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
26037
26045
|
import_nodejs_utils60.logger.log({
|
|
26038
26046
|
level: "info",
|
|
26039
26047
|
message: `Cache set for division by id: ${cacheKey}`
|
|
@@ -26071,7 +26079,7 @@ function useDivisionRepo() {
|
|
|
26071
26079
|
if (!result) {
|
|
26072
26080
|
throw new import_nodejs_utils60.BadRequestError("Division not found.");
|
|
26073
26081
|
}
|
|
26074
|
-
setCache(cacheKey, result, 300
|
|
26082
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
26075
26083
|
import_nodejs_utils60.logger.log({
|
|
26076
26084
|
level: "info",
|
|
26077
26085
|
message: `Cache set for division by name: ${cacheKey}`
|
|
@@ -26151,10 +26159,6 @@ function useDivisionRepo() {
|
|
|
26151
26159
|
};
|
|
26152
26160
|
}
|
|
26153
26161
|
|
|
26154
|
-
// src/controllers/division.controller.ts
|
|
26155
|
-
var import_nodejs_utils62 = require("@eeplatform/nodejs-utils");
|
|
26156
|
-
var import_joi30 = __toESM(require("joi"));
|
|
26157
|
-
|
|
26158
26162
|
// src/services/division.service.ts
|
|
26159
26163
|
var import_nodejs_utils61 = require("@eeplatform/nodejs-utils");
|
|
26160
26164
|
function useDivisionService() {
|
|
@@ -26194,6 +26198,8 @@ function useDivisionService() {
|
|
|
26194
26198
|
}
|
|
26195
26199
|
|
|
26196
26200
|
// src/controllers/division.controller.ts
|
|
26201
|
+
var import_nodejs_utils62 = require("@eeplatform/nodejs-utils");
|
|
26202
|
+
var import_joi30 = __toESM(require("joi"));
|
|
26197
26203
|
function useDivisionController() {
|
|
26198
26204
|
const {
|
|
26199
26205
|
getAll: _getAll,
|
|
@@ -26454,9 +26460,9 @@ function useSchoolRepo() {
|
|
|
26454
26460
|
}
|
|
26455
26461
|
const namespace_collection = "schools";
|
|
26456
26462
|
const collection = db.collection(namespace_collection);
|
|
26457
|
-
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils63.useCache)();
|
|
26463
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils63.useCache)(namespace_collection);
|
|
26458
26464
|
function delCachedData() {
|
|
26459
|
-
delNamespace(
|
|
26465
|
+
delNamespace().then(() => {
|
|
26460
26466
|
import_nodejs_utils63.logger.log({
|
|
26461
26467
|
level: "info",
|
|
26462
26468
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
@@ -26556,7 +26562,7 @@ function useSchoolRepo() {
|
|
|
26556
26562
|
]).toArray();
|
|
26557
26563
|
const length = await collection.countDocuments(query);
|
|
26558
26564
|
const data = (0, import_nodejs_utils63.paginate)(items, page, limit, length);
|
|
26559
|
-
setCache(cacheKey, data, 600
|
|
26565
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
26560
26566
|
import_nodejs_utils63.logger.log({
|
|
26561
26567
|
level: "info",
|
|
26562
26568
|
message: `Cache set for key ${cacheKey}`
|
|
@@ -26647,7 +26653,7 @@ function useSchoolRepo() {
|
|
|
26647
26653
|
}
|
|
26648
26654
|
try {
|
|
26649
26655
|
const school = await collection.findOne({ createdBy, status: "pending" });
|
|
26650
|
-
setCache(cacheKey, school, 600
|
|
26656
|
+
setCache(cacheKey, school, 600).then(() => {
|
|
26651
26657
|
import_nodejs_utils63.logger.log({
|
|
26652
26658
|
level: "info",
|
|
26653
26659
|
message: `Cache set for school by createdBy: ${cacheKey}`
|
|
@@ -26679,7 +26685,7 @@ function useSchoolRepo() {
|
|
|
26679
26685
|
}
|
|
26680
26686
|
try {
|
|
26681
26687
|
const school = await collection.findOne({ _id, status: "pending" });
|
|
26682
|
-
setCache(cacheKey, school, 600
|
|
26688
|
+
setCache(cacheKey, school, 600).then(() => {
|
|
26683
26689
|
import_nodejs_utils63.logger.log({
|
|
26684
26690
|
level: "info",
|
|
26685
26691
|
message: `Cache set for school by ID: ${cacheKey}`
|
|
@@ -26949,6 +26955,743 @@ function useSchoolController() {
|
|
|
26949
26955
|
approveSchool
|
|
26950
26956
|
};
|
|
26951
26957
|
}
|
|
26958
|
+
|
|
26959
|
+
// src/models/building.model.ts
|
|
26960
|
+
var import_nodejs_utils66 = require("@eeplatform/nodejs-utils");
|
|
26961
|
+
var import_joi33 = __toESM(require("joi"));
|
|
26962
|
+
var import_mongodb39 = require("mongodb");
|
|
26963
|
+
var schemaBuilding = import_joi33.default.object({
|
|
26964
|
+
_id: import_joi33.default.string().hex().optional(),
|
|
26965
|
+
school: import_joi33.default.string().hex().required(),
|
|
26966
|
+
serial: import_joi33.default.string().optional().allow("", null),
|
|
26967
|
+
name: import_joi33.default.string().required(),
|
|
26968
|
+
levels: import_joi33.default.number().integer().min(1).required(),
|
|
26969
|
+
createdAt: import_joi33.default.date().optional().allow("", null),
|
|
26970
|
+
updatedAt: import_joi33.default.date().optional().allow("", null),
|
|
26971
|
+
deletedAt: import_joi33.default.date().optional().allow("", null),
|
|
26972
|
+
status: import_joi33.default.string().optional().allow("", null)
|
|
26973
|
+
});
|
|
26974
|
+
var schemaBuildingUnit = import_joi33.default.object({
|
|
26975
|
+
_id: import_joi33.default.string().hex().optional(),
|
|
26976
|
+
school: import_joi33.default.string().hex().required(),
|
|
26977
|
+
name: import_joi33.default.string().optional().allow("", null),
|
|
26978
|
+
building: import_joi33.default.string().hex().required(),
|
|
26979
|
+
buildingName: import_joi33.default.string().optional().allow("", null),
|
|
26980
|
+
level: import_joi33.default.number().integer().min(1).required(),
|
|
26981
|
+
category: import_joi33.default.string().required(),
|
|
26982
|
+
type: import_joi33.default.string().required(),
|
|
26983
|
+
seating_capacity: import_joi33.default.number().integer().min(0).required(),
|
|
26984
|
+
standing_capacity: import_joi33.default.number().integer().min(0).required(),
|
|
26985
|
+
description: import_joi33.default.string().optional().allow("", null),
|
|
26986
|
+
unit_of_measurement: import_joi33.default.string().valid("sqm").required(),
|
|
26987
|
+
area: import_joi33.default.number().positive().required(),
|
|
26988
|
+
status: import_joi33.default.string().optional().allow("", null)
|
|
26989
|
+
});
|
|
26990
|
+
function MBuilding(value) {
|
|
26991
|
+
const { error } = schemaBuilding.validate(value);
|
|
26992
|
+
if (error) {
|
|
26993
|
+
import_nodejs_utils66.logger.info(`Building Model: ${error.message}`);
|
|
26994
|
+
throw new import_nodejs_utils66.BadRequestError(error.message);
|
|
26995
|
+
}
|
|
26996
|
+
if (value._id && typeof value._id === "string") {
|
|
26997
|
+
try {
|
|
26998
|
+
value._id = new import_mongodb39.ObjectId(value._id);
|
|
26999
|
+
} catch (error2) {
|
|
27000
|
+
throw new import_nodejs_utils66.BadRequestError("Invalid _id format");
|
|
27001
|
+
}
|
|
27002
|
+
}
|
|
27003
|
+
try {
|
|
27004
|
+
value.school = new import_mongodb39.ObjectId(value.school);
|
|
27005
|
+
} catch (error2) {
|
|
27006
|
+
throw new import_nodejs_utils66.BadRequestError("Invalid school format");
|
|
27007
|
+
}
|
|
27008
|
+
return {
|
|
27009
|
+
_id: value._id ?? void 0,
|
|
27010
|
+
school: value.school,
|
|
27011
|
+
serial: value.serial ?? "",
|
|
27012
|
+
name: value.name ?? "",
|
|
27013
|
+
levels: value.levels ?? 0,
|
|
27014
|
+
status: value.status ?? "active",
|
|
27015
|
+
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
27016
|
+
updatedAt: value.updatedAt ?? "",
|
|
27017
|
+
deletedAt: value.deletedAt ?? ""
|
|
27018
|
+
};
|
|
27019
|
+
}
|
|
27020
|
+
function MBuildingUnit(value) {
|
|
27021
|
+
const { error } = schemaBuildingUnit.validate(value);
|
|
27022
|
+
if (error) {
|
|
27023
|
+
import_nodejs_utils66.logger.info(`Building Unit Model: ${error.message}`);
|
|
27024
|
+
throw new import_nodejs_utils66.BadRequestError(error.message);
|
|
27025
|
+
}
|
|
27026
|
+
if (value._id && typeof value._id === "string") {
|
|
27027
|
+
try {
|
|
27028
|
+
value._id = new import_mongodb39.ObjectId(value._id);
|
|
27029
|
+
} catch (error2) {
|
|
27030
|
+
throw new import_nodejs_utils66.BadRequestError("Invalid ID");
|
|
27031
|
+
}
|
|
27032
|
+
}
|
|
27033
|
+
try {
|
|
27034
|
+
value.school = new import_mongodb39.ObjectId(value.school);
|
|
27035
|
+
} catch (error2) {
|
|
27036
|
+
throw new import_nodejs_utils66.BadRequestError("Invalid school ID");
|
|
27037
|
+
}
|
|
27038
|
+
try {
|
|
27039
|
+
value.building = new import_mongodb39.ObjectId(value.building);
|
|
27040
|
+
} catch (error2) {
|
|
27041
|
+
throw new import_nodejs_utils66.BadRequestError("Invalid building ID");
|
|
27042
|
+
}
|
|
27043
|
+
return {
|
|
27044
|
+
_id: value._id ?? void 0,
|
|
27045
|
+
school: value.school,
|
|
27046
|
+
name: value.name ?? "",
|
|
27047
|
+
building: value.building,
|
|
27048
|
+
buildingName: value.buildingName ?? "",
|
|
27049
|
+
level: value.level ?? 0,
|
|
27050
|
+
category: value.category ?? "",
|
|
27051
|
+
type: value.type ?? "",
|
|
27052
|
+
seating_capacity: value.seating_capacity ?? 0,
|
|
27053
|
+
standing_capacity: value.standing_capacity ?? 0,
|
|
27054
|
+
description: value.description ?? "",
|
|
27055
|
+
unit_of_measurement: value.unit_of_measurement ?? "sqm",
|
|
27056
|
+
area: value.area ?? 0,
|
|
27057
|
+
status: value.status ?? "active",
|
|
27058
|
+
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
27059
|
+
updatedAt: value.updatedAt ?? "",
|
|
27060
|
+
deletedAt: value.deletedAt ?? ""
|
|
27061
|
+
};
|
|
27062
|
+
}
|
|
27063
|
+
|
|
27064
|
+
// src/repositories/building.repository.ts
|
|
27065
|
+
var import_nodejs_utils67 = require("@eeplatform/nodejs-utils");
|
|
27066
|
+
var import_mongodb40 = require("mongodb");
|
|
27067
|
+
function useBuildingRepo() {
|
|
27068
|
+
const db = import_nodejs_utils67.useAtlas.getDb();
|
|
27069
|
+
if (!db) {
|
|
27070
|
+
throw new Error("Unable to connect to server.");
|
|
27071
|
+
}
|
|
27072
|
+
const namespace_collection = "school.buildings";
|
|
27073
|
+
const collection = db.collection(namespace_collection);
|
|
27074
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils67.useCache)(namespace_collection);
|
|
27075
|
+
async function createIndex() {
|
|
27076
|
+
try {
|
|
27077
|
+
await collection.createIndex([
|
|
27078
|
+
{ name: 1 },
|
|
27079
|
+
{ school: 1 },
|
|
27080
|
+
{ createdAt: 1 }
|
|
27081
|
+
]);
|
|
27082
|
+
} catch (error) {
|
|
27083
|
+
throw new Error("Failed to create index on buildings.");
|
|
27084
|
+
}
|
|
27085
|
+
}
|
|
27086
|
+
async function createTextIndex() {
|
|
27087
|
+
try {
|
|
27088
|
+
await collection.createIndex({
|
|
27089
|
+
name: "text"
|
|
27090
|
+
});
|
|
27091
|
+
} catch (error) {
|
|
27092
|
+
throw new Error("Failed to create text index on building name.");
|
|
27093
|
+
}
|
|
27094
|
+
}
|
|
27095
|
+
async function add(value, session) {
|
|
27096
|
+
try {
|
|
27097
|
+
value = MBuilding(value);
|
|
27098
|
+
const res = await collection.insertOne(value, { session });
|
|
27099
|
+
delCachedData();
|
|
27100
|
+
return res.insertedId;
|
|
27101
|
+
} catch (error) {
|
|
27102
|
+
import_nodejs_utils67.logger.log({
|
|
27103
|
+
level: "error",
|
|
27104
|
+
message: error.message
|
|
27105
|
+
});
|
|
27106
|
+
if (error instanceof import_nodejs_utils67.AppError) {
|
|
27107
|
+
throw error;
|
|
27108
|
+
} else {
|
|
27109
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
27110
|
+
if (isDuplicated) {
|
|
27111
|
+
throw new import_nodejs_utils67.BadRequestError("Building already exists.");
|
|
27112
|
+
}
|
|
27113
|
+
throw new Error("Failed to create building.");
|
|
27114
|
+
}
|
|
27115
|
+
}
|
|
27116
|
+
}
|
|
27117
|
+
async function getAll({
|
|
27118
|
+
search = "",
|
|
27119
|
+
page = 1,
|
|
27120
|
+
limit = 10,
|
|
27121
|
+
sort = {},
|
|
27122
|
+
school = "",
|
|
27123
|
+
status = "active"
|
|
27124
|
+
} = {}) {
|
|
27125
|
+
page = page > 0 ? page - 1 : 0;
|
|
27126
|
+
const query = {
|
|
27127
|
+
status
|
|
27128
|
+
};
|
|
27129
|
+
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
27130
|
+
if (search) {
|
|
27131
|
+
query.$text = { $search: search };
|
|
27132
|
+
}
|
|
27133
|
+
if (school) {
|
|
27134
|
+
try {
|
|
27135
|
+
query.school = new import_mongodb40.ObjectId(school);
|
|
27136
|
+
} catch (error) {
|
|
27137
|
+
throw new import_nodejs_utils67.BadRequestError("Invalid school ID.");
|
|
27138
|
+
}
|
|
27139
|
+
}
|
|
27140
|
+
const cacheParams = {
|
|
27141
|
+
page,
|
|
27142
|
+
limit,
|
|
27143
|
+
sort: JSON.stringify(sort)
|
|
27144
|
+
};
|
|
27145
|
+
if (search)
|
|
27146
|
+
cacheParams.search = search;
|
|
27147
|
+
if (school)
|
|
27148
|
+
cacheParams.school = school;
|
|
27149
|
+
if (status !== "active")
|
|
27150
|
+
cacheParams.status = status;
|
|
27151
|
+
const cacheKey = (0, import_nodejs_utils67.makeCacheKey)(namespace_collection, cacheParams);
|
|
27152
|
+
import_nodejs_utils67.logger.log({
|
|
27153
|
+
level: "info",
|
|
27154
|
+
message: `Cache key for getAll buildings: ${cacheKey}`
|
|
27155
|
+
});
|
|
27156
|
+
try {
|
|
27157
|
+
const cached = await getCache(cacheKey);
|
|
27158
|
+
if (cached) {
|
|
27159
|
+
import_nodejs_utils67.logger.log({
|
|
27160
|
+
level: "info",
|
|
27161
|
+
message: `Cache hit for getAll buildings: ${cacheKey}`
|
|
27162
|
+
});
|
|
27163
|
+
return cached;
|
|
27164
|
+
}
|
|
27165
|
+
const items = await collection.aggregate([
|
|
27166
|
+
{ $match: query },
|
|
27167
|
+
{ $sort: sort },
|
|
27168
|
+
{ $skip: page * limit },
|
|
27169
|
+
{ $limit: limit }
|
|
27170
|
+
]).toArray();
|
|
27171
|
+
const length = await collection.countDocuments(query);
|
|
27172
|
+
const data = (0, import_nodejs_utils67.paginate)(items, page, limit, length);
|
|
27173
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
27174
|
+
import_nodejs_utils67.logger.log({
|
|
27175
|
+
level: "info",
|
|
27176
|
+
message: `Cache set for getAll buildings: ${cacheKey}`
|
|
27177
|
+
});
|
|
27178
|
+
}).catch((err) => {
|
|
27179
|
+
import_nodejs_utils67.logger.log({
|
|
27180
|
+
level: "error",
|
|
27181
|
+
message: `Failed to set cache for getAll buildings: ${err.message}`
|
|
27182
|
+
});
|
|
27183
|
+
});
|
|
27184
|
+
return data;
|
|
27185
|
+
} catch (error) {
|
|
27186
|
+
import_nodejs_utils67.logger.log({ level: "error", message: `${error}` });
|
|
27187
|
+
throw error;
|
|
27188
|
+
}
|
|
27189
|
+
}
|
|
27190
|
+
async function getById(_id) {
|
|
27191
|
+
try {
|
|
27192
|
+
_id = new import_mongodb40.ObjectId(_id);
|
|
27193
|
+
} catch (error) {
|
|
27194
|
+
throw new import_nodejs_utils67.BadRequestError("Invalid ID.");
|
|
27195
|
+
}
|
|
27196
|
+
const cacheKey = (0, import_nodejs_utils67.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
27197
|
+
try {
|
|
27198
|
+
const cached = await getCache(cacheKey);
|
|
27199
|
+
if (cached) {
|
|
27200
|
+
import_nodejs_utils67.logger.log({
|
|
27201
|
+
level: "info",
|
|
27202
|
+
message: `Cache hit for getById building: ${cacheKey}`
|
|
27203
|
+
});
|
|
27204
|
+
return cached;
|
|
27205
|
+
}
|
|
27206
|
+
const result = await collection.findOne({
|
|
27207
|
+
_id,
|
|
27208
|
+
deletedAt: { $in: ["", null] }
|
|
27209
|
+
});
|
|
27210
|
+
if (!result) {
|
|
27211
|
+
throw new import_nodejs_utils67.BadRequestError("Building not found.");
|
|
27212
|
+
}
|
|
27213
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
27214
|
+
import_nodejs_utils67.logger.log({
|
|
27215
|
+
level: "info",
|
|
27216
|
+
message: `Cache set for building by id: ${cacheKey}`
|
|
27217
|
+
});
|
|
27218
|
+
}).catch((err) => {
|
|
27219
|
+
import_nodejs_utils67.logger.log({
|
|
27220
|
+
level: "error",
|
|
27221
|
+
message: `Failed to set cache for building by id: ${err.message}`
|
|
27222
|
+
});
|
|
27223
|
+
});
|
|
27224
|
+
return result;
|
|
27225
|
+
} catch (error) {
|
|
27226
|
+
if (error instanceof import_nodejs_utils67.AppError) {
|
|
27227
|
+
throw error;
|
|
27228
|
+
} else {
|
|
27229
|
+
throw new import_nodejs_utils67.InternalServerError("Failed to get building.");
|
|
27230
|
+
}
|
|
27231
|
+
}
|
|
27232
|
+
}
|
|
27233
|
+
function delCachedData() {
|
|
27234
|
+
delNamespace().then(() => {
|
|
27235
|
+
import_nodejs_utils67.logger.log({
|
|
27236
|
+
level: "info",
|
|
27237
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
27238
|
+
});
|
|
27239
|
+
}).catch((err) => {
|
|
27240
|
+
import_nodejs_utils67.logger.log({
|
|
27241
|
+
level: "error",
|
|
27242
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
27243
|
+
});
|
|
27244
|
+
});
|
|
27245
|
+
}
|
|
27246
|
+
return {
|
|
27247
|
+
createIndex,
|
|
27248
|
+
createTextIndex,
|
|
27249
|
+
add,
|
|
27250
|
+
getAll,
|
|
27251
|
+
getById
|
|
27252
|
+
};
|
|
27253
|
+
}
|
|
27254
|
+
|
|
27255
|
+
// src/repositories/building-unit.repository.ts
|
|
27256
|
+
var import_nodejs_utils68 = require("@eeplatform/nodejs-utils");
|
|
27257
|
+
var import_mongodb41 = require("mongodb");
|
|
27258
|
+
function useBuildingUnitRepo() {
|
|
27259
|
+
const db = import_nodejs_utils68.useAtlas.getDb();
|
|
27260
|
+
if (!db) {
|
|
27261
|
+
throw new Error("Unable to connect to server.");
|
|
27262
|
+
}
|
|
27263
|
+
const namespace_collection = "school.building-units";
|
|
27264
|
+
const collection = db.collection(namespace_collection);
|
|
27265
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils68.useCache)(namespace_collection);
|
|
27266
|
+
async function createIndex() {
|
|
27267
|
+
try {
|
|
27268
|
+
await collection.createIndexes([
|
|
27269
|
+
{ key: { school: 1 } },
|
|
27270
|
+
{ key: { building: 1 } },
|
|
27271
|
+
{ key: { status: 1 } },
|
|
27272
|
+
{ key: { createdAt: 1 } },
|
|
27273
|
+
{
|
|
27274
|
+
key: {
|
|
27275
|
+
name: "text",
|
|
27276
|
+
buildingName: "text",
|
|
27277
|
+
category: "text",
|
|
27278
|
+
type: "text"
|
|
27279
|
+
}
|
|
27280
|
+
}
|
|
27281
|
+
]);
|
|
27282
|
+
} catch (error) {
|
|
27283
|
+
throw new Error("Failed to create index on building units.");
|
|
27284
|
+
}
|
|
27285
|
+
}
|
|
27286
|
+
function delCachedData() {
|
|
27287
|
+
delNamespace().then(() => {
|
|
27288
|
+
import_nodejs_utils68.logger.log({
|
|
27289
|
+
level: "info",
|
|
27290
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
27291
|
+
});
|
|
27292
|
+
}).catch((err) => {
|
|
27293
|
+
import_nodejs_utils68.logger.log({
|
|
27294
|
+
level: "error",
|
|
27295
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
27296
|
+
});
|
|
27297
|
+
});
|
|
27298
|
+
}
|
|
27299
|
+
async function add(value, session) {
|
|
27300
|
+
try {
|
|
27301
|
+
value = MBuildingUnit(value);
|
|
27302
|
+
const res = await collection.insertOne(value, { session });
|
|
27303
|
+
delCachedData();
|
|
27304
|
+
return res.insertedId;
|
|
27305
|
+
} catch (error) {
|
|
27306
|
+
import_nodejs_utils68.logger.log({
|
|
27307
|
+
level: "error",
|
|
27308
|
+
message: error.message
|
|
27309
|
+
});
|
|
27310
|
+
if (error instanceof import_nodejs_utils68.AppError) {
|
|
27311
|
+
throw error;
|
|
27312
|
+
} else {
|
|
27313
|
+
throw new Error("Failed to create building unit.");
|
|
27314
|
+
}
|
|
27315
|
+
}
|
|
27316
|
+
}
|
|
27317
|
+
async function getAll({
|
|
27318
|
+
search = "",
|
|
27319
|
+
page = 1,
|
|
27320
|
+
limit = 10,
|
|
27321
|
+
sort = {},
|
|
27322
|
+
school = "",
|
|
27323
|
+
building = "",
|
|
27324
|
+
status = "active"
|
|
27325
|
+
} = {}) {
|
|
27326
|
+
page = page > 0 ? page - 1 : 0;
|
|
27327
|
+
const query = {
|
|
27328
|
+
deletedAt: { $in: ["", null] },
|
|
27329
|
+
status: { $in: [status, "", null] }
|
|
27330
|
+
};
|
|
27331
|
+
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
27332
|
+
if (search) {
|
|
27333
|
+
query.$text = { $search: search };
|
|
27334
|
+
}
|
|
27335
|
+
if (school) {
|
|
27336
|
+
try {
|
|
27337
|
+
query.school = new import_mongodb41.ObjectId(school);
|
|
27338
|
+
} catch (error) {
|
|
27339
|
+
throw new import_nodejs_utils68.BadRequestError("Invalid school ID.");
|
|
27340
|
+
}
|
|
27341
|
+
}
|
|
27342
|
+
if (building) {
|
|
27343
|
+
try {
|
|
27344
|
+
query.building = new import_mongodb41.ObjectId(building);
|
|
27345
|
+
} catch (error) {
|
|
27346
|
+
throw new import_nodejs_utils68.BadRequestError("Invalid building ID.");
|
|
27347
|
+
}
|
|
27348
|
+
}
|
|
27349
|
+
const cacheParams = {
|
|
27350
|
+
page,
|
|
27351
|
+
limit,
|
|
27352
|
+
sort: JSON.stringify(sort)
|
|
27353
|
+
};
|
|
27354
|
+
if (search)
|
|
27355
|
+
cacheParams.search = search;
|
|
27356
|
+
if (school)
|
|
27357
|
+
cacheParams.school = school;
|
|
27358
|
+
if (building)
|
|
27359
|
+
cacheParams.building = building;
|
|
27360
|
+
if (status !== "active")
|
|
27361
|
+
cacheParams.status = status;
|
|
27362
|
+
const cacheKey = (0, import_nodejs_utils68.makeCacheKey)(namespace_collection, cacheParams);
|
|
27363
|
+
import_nodejs_utils68.logger.log({
|
|
27364
|
+
level: "info",
|
|
27365
|
+
message: `Cache key for getAll building units: ${cacheKey}`
|
|
27366
|
+
});
|
|
27367
|
+
try {
|
|
27368
|
+
const cached = await getCache(cacheKey);
|
|
27369
|
+
if (cached) {
|
|
27370
|
+
import_nodejs_utils68.logger.log({
|
|
27371
|
+
level: "info",
|
|
27372
|
+
message: `Cache hit for getAll building units: ${cacheKey}`
|
|
27373
|
+
});
|
|
27374
|
+
return cached;
|
|
27375
|
+
}
|
|
27376
|
+
const items = await collection.aggregate([
|
|
27377
|
+
{ $match: query },
|
|
27378
|
+
{ $sort: sort },
|
|
27379
|
+
{ $skip: page * limit },
|
|
27380
|
+
{ $limit: limit }
|
|
27381
|
+
]).toArray();
|
|
27382
|
+
const length = await collection.countDocuments(query);
|
|
27383
|
+
const data = (0, import_nodejs_utils68.paginate)(items, page, limit, length);
|
|
27384
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
27385
|
+
import_nodejs_utils68.logger.log({
|
|
27386
|
+
level: "info",
|
|
27387
|
+
message: `Cache set for getAll building units: ${cacheKey}`
|
|
27388
|
+
});
|
|
27389
|
+
}).catch((err) => {
|
|
27390
|
+
import_nodejs_utils68.logger.log({
|
|
27391
|
+
level: "error",
|
|
27392
|
+
message: `Failed to set cache for getAll building units: ${err.message}`
|
|
27393
|
+
});
|
|
27394
|
+
});
|
|
27395
|
+
return data;
|
|
27396
|
+
} catch (error) {
|
|
27397
|
+
import_nodejs_utils68.logger.log({ level: "error", message: `${error}` });
|
|
27398
|
+
throw error;
|
|
27399
|
+
}
|
|
27400
|
+
}
|
|
27401
|
+
async function getById(_id) {
|
|
27402
|
+
try {
|
|
27403
|
+
_id = new import_mongodb41.ObjectId(_id);
|
|
27404
|
+
} catch (error) {
|
|
27405
|
+
throw new import_nodejs_utils68.BadRequestError("Invalid ID.");
|
|
27406
|
+
}
|
|
27407
|
+
const cacheKey = (0, import_nodejs_utils68.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
27408
|
+
try {
|
|
27409
|
+
const cached = await getCache(cacheKey);
|
|
27410
|
+
if (cached) {
|
|
27411
|
+
import_nodejs_utils68.logger.log({
|
|
27412
|
+
level: "info",
|
|
27413
|
+
message: `Cache hit for getById building unit: ${cacheKey}`
|
|
27414
|
+
});
|
|
27415
|
+
return cached;
|
|
27416
|
+
}
|
|
27417
|
+
const result = await collection.findOne({
|
|
27418
|
+
_id,
|
|
27419
|
+
deletedAt: { $in: ["", null] }
|
|
27420
|
+
});
|
|
27421
|
+
if (!result) {
|
|
27422
|
+
throw new import_nodejs_utils68.BadRequestError("Building unit not found.");
|
|
27423
|
+
}
|
|
27424
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
27425
|
+
import_nodejs_utils68.logger.log({
|
|
27426
|
+
level: "info",
|
|
27427
|
+
message: `Cache set for building unit by id: ${cacheKey}`
|
|
27428
|
+
});
|
|
27429
|
+
}).catch((err) => {
|
|
27430
|
+
import_nodejs_utils68.logger.log({
|
|
27431
|
+
level: "error",
|
|
27432
|
+
message: `Failed to set cache for building unit by id: ${err.message}`
|
|
27433
|
+
});
|
|
27434
|
+
});
|
|
27435
|
+
return result;
|
|
27436
|
+
} catch (error) {
|
|
27437
|
+
if (error instanceof import_nodejs_utils68.AppError) {
|
|
27438
|
+
throw error;
|
|
27439
|
+
} else {
|
|
27440
|
+
throw new import_nodejs_utils68.InternalServerError("Failed to get building unit.");
|
|
27441
|
+
}
|
|
27442
|
+
}
|
|
27443
|
+
}
|
|
27444
|
+
return {
|
|
27445
|
+
createIndex,
|
|
27446
|
+
add,
|
|
27447
|
+
getAll,
|
|
27448
|
+
getById
|
|
27449
|
+
};
|
|
27450
|
+
}
|
|
27451
|
+
|
|
27452
|
+
// src/controllers/building.controller.ts
|
|
27453
|
+
var import_nodejs_utils69 = require("@eeplatform/nodejs-utils");
|
|
27454
|
+
var import_joi34 = __toESM(require("joi"));
|
|
27455
|
+
function useBuildingController() {
|
|
27456
|
+
const { getAll: _getAll, getById: _getById, add: _add } = useBuildingRepo();
|
|
27457
|
+
async function createBuilding(req, res, next) {
|
|
27458
|
+
const value = req.body;
|
|
27459
|
+
const validation = import_joi34.default.object({
|
|
27460
|
+
name: import_joi34.default.string().required(),
|
|
27461
|
+
school: import_joi34.default.string().hex().required(),
|
|
27462
|
+
levels: import_joi34.default.number().integer().min(1).required(),
|
|
27463
|
+
serial: import_joi34.default.string().optional().allow("", null),
|
|
27464
|
+
status: import_joi34.default.string().optional().allow("", null)
|
|
27465
|
+
});
|
|
27466
|
+
const { error } = validation.validate(value);
|
|
27467
|
+
if (error) {
|
|
27468
|
+
next(new import_nodejs_utils69.BadRequestError(error.message));
|
|
27469
|
+
import_nodejs_utils69.logger.info(`Controller: ${error.message}`);
|
|
27470
|
+
return;
|
|
27471
|
+
}
|
|
27472
|
+
try {
|
|
27473
|
+
const result = await _add(value);
|
|
27474
|
+
res.json(result);
|
|
27475
|
+
return;
|
|
27476
|
+
} catch (error2) {
|
|
27477
|
+
next(error2);
|
|
27478
|
+
}
|
|
27479
|
+
}
|
|
27480
|
+
async function getAll(req, res, next) {
|
|
27481
|
+
const query = req.query;
|
|
27482
|
+
const validation = import_joi34.default.object({
|
|
27483
|
+
page: import_joi34.default.number().min(1).optional().allow("", null),
|
|
27484
|
+
limit: import_joi34.default.number().min(1).optional().allow("", null),
|
|
27485
|
+
search: import_joi34.default.string().optional().allow("", null),
|
|
27486
|
+
school: import_joi34.default.string().hex().optional().allow("", null),
|
|
27487
|
+
status: import_joi34.default.string().optional().allow("", null)
|
|
27488
|
+
});
|
|
27489
|
+
const { error } = validation.validate(query);
|
|
27490
|
+
if (error) {
|
|
27491
|
+
next(new import_nodejs_utils69.BadRequestError(error.message));
|
|
27492
|
+
return;
|
|
27493
|
+
}
|
|
27494
|
+
const page = parseInt(req.query.page) ?? 1;
|
|
27495
|
+
let limit = parseInt(req.query.limit) ?? 20;
|
|
27496
|
+
limit = isNaN(limit) ? 20 : limit;
|
|
27497
|
+
const sort = req.query.sort ? String(req.query.sort).split(",") : "";
|
|
27498
|
+
const sortOrder = req.query.sortOrder ? String(req.query.sortOrder).split(",") : "";
|
|
27499
|
+
const sortObj = {};
|
|
27500
|
+
if (sort && Array.isArray(sort) && sort.length && sortOrder && Array.isArray(sortOrder) && sortOrder.length) {
|
|
27501
|
+
sort.forEach((field, index) => {
|
|
27502
|
+
sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
|
|
27503
|
+
});
|
|
27504
|
+
}
|
|
27505
|
+
const status = req.query.status ?? "active";
|
|
27506
|
+
const school = req.query.school ?? "";
|
|
27507
|
+
const search = req.query.search ?? "";
|
|
27508
|
+
try {
|
|
27509
|
+
const buildings = await _getAll({
|
|
27510
|
+
page,
|
|
27511
|
+
limit,
|
|
27512
|
+
sort: sortObj,
|
|
27513
|
+
status,
|
|
27514
|
+
school,
|
|
27515
|
+
search
|
|
27516
|
+
});
|
|
27517
|
+
res.json(buildings);
|
|
27518
|
+
return;
|
|
27519
|
+
} catch (error2) {
|
|
27520
|
+
next(error2);
|
|
27521
|
+
}
|
|
27522
|
+
}
|
|
27523
|
+
async function getById(req, res, next) {
|
|
27524
|
+
const id = req.params.id;
|
|
27525
|
+
const validation = import_joi34.default.object({
|
|
27526
|
+
id: import_joi34.default.string().hex().required()
|
|
27527
|
+
});
|
|
27528
|
+
const { error } = validation.validate({ id });
|
|
27529
|
+
if (error) {
|
|
27530
|
+
next(new import_nodejs_utils69.BadRequestError(error.message));
|
|
27531
|
+
return;
|
|
27532
|
+
}
|
|
27533
|
+
try {
|
|
27534
|
+
const building = await _getById(id);
|
|
27535
|
+
res.json({
|
|
27536
|
+
message: "Successfully retrieved building.",
|
|
27537
|
+
data: { building }
|
|
27538
|
+
});
|
|
27539
|
+
return;
|
|
27540
|
+
} catch (error2) {
|
|
27541
|
+
next(error2);
|
|
27542
|
+
}
|
|
27543
|
+
}
|
|
27544
|
+
return {
|
|
27545
|
+
createBuilding,
|
|
27546
|
+
getAll,
|
|
27547
|
+
getById
|
|
27548
|
+
};
|
|
27549
|
+
}
|
|
27550
|
+
|
|
27551
|
+
// src/controllers/building-unit.controller.ts
|
|
27552
|
+
var import_nodejs_utils71 = require("@eeplatform/nodejs-utils");
|
|
27553
|
+
var import_joi35 = __toESM(require("joi"));
|
|
27554
|
+
|
|
27555
|
+
// src/services/building-unit.service.ts
|
|
27556
|
+
var import_nodejs_utils70 = require("@eeplatform/nodejs-utils");
|
|
27557
|
+
function useBuildingUnitService() {
|
|
27558
|
+
const { add: _add } = useBuildingUnitRepo();
|
|
27559
|
+
async function add(value) {
|
|
27560
|
+
const session = import_nodejs_utils70.useAtlas.getClient()?.startSession();
|
|
27561
|
+
if (!session) {
|
|
27562
|
+
throw new Error("Unable to start session for building unit service.");
|
|
27563
|
+
}
|
|
27564
|
+
try {
|
|
27565
|
+
await session.startTransaction();
|
|
27566
|
+
for (let index = 0; index < value.qty; index++) {
|
|
27567
|
+
await _add({ ...value.building }, session);
|
|
27568
|
+
}
|
|
27569
|
+
await session.commitTransaction();
|
|
27570
|
+
return "Building unit added successfully.";
|
|
27571
|
+
} catch (error) {
|
|
27572
|
+
await session.abortTransaction();
|
|
27573
|
+
throw error;
|
|
27574
|
+
} finally {
|
|
27575
|
+
session.endSession();
|
|
27576
|
+
}
|
|
27577
|
+
}
|
|
27578
|
+
return {
|
|
27579
|
+
add
|
|
27580
|
+
};
|
|
27581
|
+
}
|
|
27582
|
+
|
|
27583
|
+
// src/controllers/building-unit.controller.ts
|
|
27584
|
+
function useBuildingUnitController() {
|
|
27585
|
+
const { getAll: _getAll, getById: _getById } = useBuildingUnitRepo();
|
|
27586
|
+
const { add: _add } = useBuildingUnitService();
|
|
27587
|
+
async function add(req, res, next) {
|
|
27588
|
+
const data = req.body;
|
|
27589
|
+
const validation = import_joi35.default.object({
|
|
27590
|
+
building: import_joi35.default.object({
|
|
27591
|
+
school: import_joi35.default.string().hex().required(),
|
|
27592
|
+
name: import_joi35.default.string().optional().allow("", null),
|
|
27593
|
+
building: import_joi35.default.string().hex().required(),
|
|
27594
|
+
buildingName: import_joi35.default.string().optional().allow("", null),
|
|
27595
|
+
level: import_joi35.default.number().integer().min(1).required(),
|
|
27596
|
+
category: import_joi35.default.string().required(),
|
|
27597
|
+
type: import_joi35.default.string().required(),
|
|
27598
|
+
seating_capacity: import_joi35.default.number().integer().min(0).required(),
|
|
27599
|
+
standing_capacity: import_joi35.default.number().integer().min(0).required(),
|
|
27600
|
+
description: import_joi35.default.string().optional().allow("", null),
|
|
27601
|
+
unit_of_measurement: import_joi35.default.string().valid("sqm").required(),
|
|
27602
|
+
area: import_joi35.default.number().positive().required(),
|
|
27603
|
+
status: import_joi35.default.string().optional().allow("", null)
|
|
27604
|
+
}),
|
|
27605
|
+
qty: import_joi35.default.number().integer().min(1).max(20).optional().default(1)
|
|
27606
|
+
});
|
|
27607
|
+
const { error } = validation.validate(data);
|
|
27608
|
+
if (error) {
|
|
27609
|
+
next(new import_nodejs_utils71.BadRequestError(error.message));
|
|
27610
|
+
return;
|
|
27611
|
+
}
|
|
27612
|
+
try {
|
|
27613
|
+
const buildingUnit = await _add(data);
|
|
27614
|
+
res.json({
|
|
27615
|
+
message: "Building unit added successfully.",
|
|
27616
|
+
data: { buildingUnit }
|
|
27617
|
+
});
|
|
27618
|
+
} catch (error2) {
|
|
27619
|
+
next(error2);
|
|
27620
|
+
}
|
|
27621
|
+
}
|
|
27622
|
+
async function getAll(req, res, next) {
|
|
27623
|
+
const query = req.query;
|
|
27624
|
+
const validation = import_joi35.default.object({
|
|
27625
|
+
page: import_joi35.default.number().min(1).optional().allow("", null),
|
|
27626
|
+
limit: import_joi35.default.number().min(1).optional().allow("", null),
|
|
27627
|
+
search: import_joi35.default.string().optional().allow("", null),
|
|
27628
|
+
school: import_joi35.default.string().hex().optional().allow("", null),
|
|
27629
|
+
building: import_joi35.default.string().hex().optional().allow("", null),
|
|
27630
|
+
status: import_joi35.default.string().optional().allow("", null)
|
|
27631
|
+
});
|
|
27632
|
+
const { error } = validation.validate(query);
|
|
27633
|
+
if (error) {
|
|
27634
|
+
next(new import_nodejs_utils71.BadRequestError(error.message));
|
|
27635
|
+
return;
|
|
27636
|
+
}
|
|
27637
|
+
const page = parseInt(req.query.page) ?? 1;
|
|
27638
|
+
let limit = parseInt(req.query.limit) ?? 20;
|
|
27639
|
+
limit = isNaN(limit) ? 20 : limit;
|
|
27640
|
+
const sort = req.query.sort ? String(req.query.sort).split(",") : "";
|
|
27641
|
+
const sortOrder = req.query.sortOrder ? String(req.query.sortOrder).split(",") : "";
|
|
27642
|
+
const sortObj = {};
|
|
27643
|
+
if (sort && Array.isArray(sort) && sort.length && sortOrder && Array.isArray(sortOrder) && sortOrder.length) {
|
|
27644
|
+
sort.forEach((field, index) => {
|
|
27645
|
+
sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
|
|
27646
|
+
});
|
|
27647
|
+
}
|
|
27648
|
+
const status = req.query.status ?? "active";
|
|
27649
|
+
const school = req.query.school ?? "";
|
|
27650
|
+
const building = req.query.building ?? "";
|
|
27651
|
+
const search = req.query.search ?? "";
|
|
27652
|
+
try {
|
|
27653
|
+
const buildings = await _getAll({
|
|
27654
|
+
page,
|
|
27655
|
+
limit,
|
|
27656
|
+
sort: sortObj,
|
|
27657
|
+
status,
|
|
27658
|
+
school,
|
|
27659
|
+
search,
|
|
27660
|
+
building
|
|
27661
|
+
});
|
|
27662
|
+
res.json(buildings);
|
|
27663
|
+
return;
|
|
27664
|
+
} catch (error2) {
|
|
27665
|
+
next(error2);
|
|
27666
|
+
}
|
|
27667
|
+
}
|
|
27668
|
+
async function getById(req, res, next) {
|
|
27669
|
+
const id = req.params.id;
|
|
27670
|
+
const validation = import_joi35.default.object({
|
|
27671
|
+
id: import_joi35.default.string().hex().required()
|
|
27672
|
+
});
|
|
27673
|
+
const { error } = validation.validate({ id });
|
|
27674
|
+
if (error) {
|
|
27675
|
+
next(new import_nodejs_utils71.BadRequestError(error.message));
|
|
27676
|
+
return;
|
|
27677
|
+
}
|
|
27678
|
+
try {
|
|
27679
|
+
const buildingUnit = await _getById(id);
|
|
27680
|
+
res.json({
|
|
27681
|
+
message: "Successfully retrieved building unit.",
|
|
27682
|
+
data: { buildingUnit }
|
|
27683
|
+
});
|
|
27684
|
+
return;
|
|
27685
|
+
} catch (error2) {
|
|
27686
|
+
next(error2);
|
|
27687
|
+
}
|
|
27688
|
+
}
|
|
27689
|
+
return {
|
|
27690
|
+
add,
|
|
27691
|
+
getAll,
|
|
27692
|
+
getById
|
|
27693
|
+
};
|
|
27694
|
+
}
|
|
26952
27695
|
// Annotate the CommonJS export names for ESM import in node:
|
|
26953
27696
|
0 && (module.exports = {
|
|
26954
27697
|
ACCESS_TOKEN_EXPIRY,
|
|
@@ -26968,6 +27711,8 @@ function useSchoolController() {
|
|
|
26968
27711
|
MAILER_TRANSPORT_PORT,
|
|
26969
27712
|
MAILER_TRANSPORT_SECURE,
|
|
26970
27713
|
MAddress,
|
|
27714
|
+
MBuilding,
|
|
27715
|
+
MBuildingUnit,
|
|
26971
27716
|
MDivision,
|
|
26972
27717
|
MEntity,
|
|
26973
27718
|
MFile,
|
|
@@ -27008,6 +27753,8 @@ function useSchoolController() {
|
|
|
27008
27753
|
addressSchema,
|
|
27009
27754
|
isDev,
|
|
27010
27755
|
schema,
|
|
27756
|
+
schemaBuilding,
|
|
27757
|
+
schemaBuildingUnit,
|
|
27011
27758
|
schemaDivision,
|
|
27012
27759
|
schemaRegion,
|
|
27013
27760
|
schemaSchool,
|
|
@@ -27015,10 +27762,15 @@ function useSchoolController() {
|
|
|
27015
27762
|
useAddressRepo,
|
|
27016
27763
|
useAuthController,
|
|
27017
27764
|
useAuthService,
|
|
27765
|
+
useBuildingController,
|
|
27766
|
+
useBuildingRepo,
|
|
27767
|
+
useBuildingUnitController,
|
|
27768
|
+
useBuildingUnitRepo,
|
|
27018
27769
|
useCounterModel,
|
|
27019
27770
|
useCounterRepo,
|
|
27020
27771
|
useDivisionController,
|
|
27021
27772
|
useDivisionRepo,
|
|
27773
|
+
useDivisionService,
|
|
27022
27774
|
useEntityController,
|
|
27023
27775
|
useEntityRepo,
|
|
27024
27776
|
useFileController,
|
|
@@ -27049,6 +27801,7 @@ function useSchoolController() {
|
|
|
27049
27801
|
usePromoCodeRepo,
|
|
27050
27802
|
useRegionController,
|
|
27051
27803
|
useRegionRepo,
|
|
27804
|
+
useRegionService,
|
|
27052
27805
|
useRoleController,
|
|
27053
27806
|
useRoleRepo,
|
|
27054
27807
|
useSchoolController,
|