@eeplatform/core 1.8.8 → 1.8.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +198 -42
- package/dist/index.js +2531 -662
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2557 -676
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -78,12 +78,24 @@ __export(src_exports, {
|
|
|
78
78
|
XENDIT_SECRET_KEY: () => XENDIT_SECRET_KEY,
|
|
79
79
|
addressSchema: () => addressSchema,
|
|
80
80
|
isDev: () => isDev,
|
|
81
|
+
modelApp: () => modelApp,
|
|
81
82
|
modelPSGC: () => modelPSGC,
|
|
83
|
+
modelPermission: () => modelPermission,
|
|
84
|
+
modelPermissionGroup: () => modelPermissionGroup,
|
|
85
|
+
schemaApp: () => schemaApp,
|
|
86
|
+
schemaAppUpdate: () => schemaAppUpdate,
|
|
82
87
|
schemaOrg: () => schemaOrg,
|
|
83
88
|
schemaPSGC: () => schemaPSGC,
|
|
89
|
+
schemaPermission: () => schemaPermission,
|
|
90
|
+
schemaPermissionGroup: () => schemaPermissionGroup,
|
|
91
|
+
schemaPermissionGroupUpdate: () => schemaPermissionGroupUpdate,
|
|
92
|
+
schemaPermissionUpdate: () => schemaPermissionUpdate,
|
|
84
93
|
transactionSchema: () => transactionSchema,
|
|
85
94
|
useAddressController: () => useAddressController,
|
|
86
95
|
useAddressRepo: () => useAddressRepo,
|
|
96
|
+
useAppController: () => useAppController,
|
|
97
|
+
useAppRepo: () => useAppRepo,
|
|
98
|
+
useAppService: () => useAppService,
|
|
87
99
|
useAudioTranscriptionController: () => useAudioTranscriptionController,
|
|
88
100
|
useAuthController: () => useAuthController,
|
|
89
101
|
useAuthService: () => useAuthService,
|
|
@@ -101,6 +113,12 @@ __export(src_exports, {
|
|
|
101
113
|
useOrgService: () => useOrgService,
|
|
102
114
|
usePSGCController: () => usePSGCController,
|
|
103
115
|
usePSGCRepo: () => usePSGCRepo,
|
|
116
|
+
usePermissionController: () => usePermissionController,
|
|
117
|
+
usePermissionGroupController: () => usePermissionGroupController,
|
|
118
|
+
usePermissionGroupRepo: () => usePermissionGroupRepo,
|
|
119
|
+
usePermissionGroupService: () => usePermissionGroupService,
|
|
120
|
+
usePermissionRepo: () => usePermissionRepo,
|
|
121
|
+
usePermissionService: () => usePermissionService,
|
|
104
122
|
useRoleController: () => useRoleController,
|
|
105
123
|
useRoleRepo: () => useRoleRepo,
|
|
106
124
|
useTokenRepo: () => useTokenRepo,
|
|
@@ -184,26 +202,25 @@ function useUserRepo() {
|
|
|
184
202
|
});
|
|
185
203
|
});
|
|
186
204
|
}
|
|
187
|
-
async function
|
|
188
|
-
try {
|
|
189
|
-
await collection.createIndex({
|
|
190
|
-
firstName: "text",
|
|
191
|
-
middleName: "text",
|
|
192
|
-
lastName: "text",
|
|
193
|
-
email: "text"
|
|
194
|
-
});
|
|
195
|
-
} catch (error) {
|
|
196
|
-
throw new Error("Failed to create text index on email.");
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
async function createUniqueIndex() {
|
|
205
|
+
async function createIndexes() {
|
|
200
206
|
try {
|
|
201
|
-
await collection.
|
|
202
|
-
{
|
|
203
|
-
|
|
204
|
-
|
|
207
|
+
await collection.createIndexes([
|
|
208
|
+
{
|
|
209
|
+
key: {
|
|
210
|
+
firstName: "text",
|
|
211
|
+
middleName: "text",
|
|
212
|
+
lastName: "text",
|
|
213
|
+
email: "text"
|
|
214
|
+
},
|
|
215
|
+
name: "search_index"
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
key: { email: 1, deletedAt: 1 },
|
|
219
|
+
unique: true
|
|
220
|
+
}
|
|
221
|
+
]);
|
|
205
222
|
} catch (error) {
|
|
206
|
-
throw new Error("Failed to create
|
|
223
|
+
throw new Error("Failed to create user indexes.");
|
|
207
224
|
}
|
|
208
225
|
}
|
|
209
226
|
async function createUser(value, session) {
|
|
@@ -500,8 +517,7 @@ function useUserRepo() {
|
|
|
500
517
|
}
|
|
501
518
|
}
|
|
502
519
|
return {
|
|
503
|
-
|
|
504
|
-
createUniqueIndex,
|
|
520
|
+
createIndexes,
|
|
505
521
|
createUser,
|
|
506
522
|
getUserByEmail,
|
|
507
523
|
getUserById,
|
|
@@ -1229,46 +1245,33 @@ function useMemberRepo() {
|
|
|
1229
1245
|
});
|
|
1230
1246
|
});
|
|
1231
1247
|
}
|
|
1232
|
-
async function
|
|
1233
|
-
try {
|
|
1234
|
-
await collection.createIndex([
|
|
1235
|
-
{
|
|
1236
|
-
name: 1
|
|
1237
|
-
},
|
|
1238
|
-
{
|
|
1239
|
-
status: 1
|
|
1240
|
-
}
|
|
1241
|
-
]);
|
|
1242
|
-
} catch (error) {
|
|
1243
|
-
throw new Error("Failed to create index.");
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
async function createUniqueIndex() {
|
|
1248
|
+
async function createIndexes() {
|
|
1247
1249
|
try {
|
|
1248
|
-
await collection.
|
|
1250
|
+
await collection.createIndexes([
|
|
1249
1251
|
{
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1252
|
+
key: {
|
|
1253
|
+
name: 1,
|
|
1254
|
+
status: 1
|
|
1255
|
+
}
|
|
1253
1256
|
},
|
|
1254
|
-
{ partialFilterExpression: { deletedAt: "" }, unique: true }
|
|
1255
|
-
);
|
|
1256
|
-
} catch (error) {
|
|
1257
|
-
throw new Error("Failed to create unique index.");
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
async function createTextIndex() {
|
|
1261
|
-
try {
|
|
1262
|
-
await collection.createIndex([
|
|
1263
1257
|
{
|
|
1264
|
-
|
|
1258
|
+
key: {
|
|
1259
|
+
org: 1,
|
|
1260
|
+
user: 1,
|
|
1261
|
+
type: 1
|
|
1262
|
+
},
|
|
1263
|
+
partialFilterExpression: { deletedAt: "" },
|
|
1264
|
+
unique: true
|
|
1265
1265
|
},
|
|
1266
1266
|
{
|
|
1267
|
-
|
|
1267
|
+
key: {
|
|
1268
|
+
name: "text",
|
|
1269
|
+
orgName: "text"
|
|
1270
|
+
},
|
|
1271
|
+
name: "search_index"
|
|
1268
1272
|
}
|
|
1269
1273
|
]);
|
|
1270
1274
|
} catch (error) {
|
|
1271
|
-
throw new Error("Failed to create text index.");
|
|
1272
1275
|
}
|
|
1273
1276
|
}
|
|
1274
1277
|
async function add(value, session) {
|
|
@@ -1806,9 +1809,7 @@ function useMemberRepo() {
|
|
|
1806
1809
|
}
|
|
1807
1810
|
}
|
|
1808
1811
|
return {
|
|
1809
|
-
|
|
1810
|
-
createUniqueIndex,
|
|
1811
|
-
createTextIndex,
|
|
1812
|
+
createIndexes,
|
|
1812
1813
|
add,
|
|
1813
1814
|
getById,
|
|
1814
1815
|
getByOrg,
|
|
@@ -2223,21 +2224,22 @@ function useRoleRepo() {
|
|
|
2223
2224
|
});
|
|
2224
2225
|
});
|
|
2225
2226
|
}
|
|
2226
|
-
async function
|
|
2227
|
-
try {
|
|
2228
|
-
await collection.createIndex({ name: 1 });
|
|
2229
|
-
await collection.createIndex({ type: 1 });
|
|
2230
|
-
await collection.createIndex({ status: 1 });
|
|
2231
|
-
await collection.createIndex({ id: 1 });
|
|
2232
|
-
} catch (error) {
|
|
2233
|
-
throw new import_nodejs_utils10.InternalServerError("Failed to create index on role.");
|
|
2234
|
-
}
|
|
2235
|
-
}
|
|
2236
|
-
async function createTextIndex() {
|
|
2227
|
+
async function createIndexes() {
|
|
2237
2228
|
try {
|
|
2238
|
-
await collection.
|
|
2229
|
+
await collection.createIndexes([
|
|
2230
|
+
{
|
|
2231
|
+
key: {
|
|
2232
|
+
name: "text"
|
|
2233
|
+
},
|
|
2234
|
+
name: "text_index"
|
|
2235
|
+
},
|
|
2236
|
+
{
|
|
2237
|
+
key: { name: 1, type: 1, status: 1, id: 1 },
|
|
2238
|
+
unique: true
|
|
2239
|
+
}
|
|
2240
|
+
]);
|
|
2239
2241
|
} catch (error) {
|
|
2240
|
-
throw new import_nodejs_utils10.InternalServerError("Failed to create
|
|
2242
|
+
throw new import_nodejs_utils10.InternalServerError("Failed to create role indexes.");
|
|
2241
2243
|
}
|
|
2242
2244
|
}
|
|
2243
2245
|
async function createUniqueIndex() {
|
|
@@ -2520,8 +2522,7 @@ function useRoleRepo() {
|
|
|
2520
2522
|
}
|
|
2521
2523
|
}
|
|
2522
2524
|
return {
|
|
2523
|
-
|
|
2524
|
-
createTextIndex,
|
|
2525
|
+
createIndexes,
|
|
2525
2526
|
createUniqueIndex,
|
|
2526
2527
|
addRole,
|
|
2527
2528
|
getRoles,
|
|
@@ -3737,136 +3738,2128 @@ function useOrgController() {
|
|
|
3737
3738
|
};
|
|
3738
3739
|
}
|
|
3739
3740
|
|
|
3740
|
-
// src/resources/
|
|
3741
|
-
var
|
|
3742
|
-
var
|
|
3741
|
+
// src/resources/app/app.model.ts
|
|
3742
|
+
var import_nodejs_utils18 = require("@eeplatform/nodejs-utils");
|
|
3743
|
+
var import_joi6 = __toESM(require("joi"));
|
|
3744
|
+
var schemaApp = import_joi6.default.object({
|
|
3745
|
+
code: import_joi6.default.string().alphanum().max(20).required(),
|
|
3746
|
+
name: import_joi6.default.string().max(255).required(),
|
|
3747
|
+
description: import_joi6.default.string().max(1024).optional().allow("", null),
|
|
3748
|
+
type: import_joi6.default.string().allow("default", "standard").optional().allow("", null)
|
|
3749
|
+
});
|
|
3750
|
+
var schemaAppUpdate = import_joi6.default.object({
|
|
3751
|
+
code: import_joi6.default.string().alphanum().max(20).optional().allow("", null),
|
|
3752
|
+
name: import_joi6.default.string().max(255).optional().allow("", null),
|
|
3753
|
+
description: import_joi6.default.string().max(1024).optional().allow("", null)
|
|
3754
|
+
});
|
|
3755
|
+
function modelApp(value) {
|
|
3756
|
+
const { error } = schemaApp.validate(value);
|
|
3757
|
+
if (error) {
|
|
3758
|
+
throw new import_nodejs_utils18.BadRequestError(error.message);
|
|
3759
|
+
}
|
|
3760
|
+
return {
|
|
3761
|
+
_id: value._id,
|
|
3762
|
+
code: value.code,
|
|
3763
|
+
name: value.name,
|
|
3764
|
+
description: value.description,
|
|
3765
|
+
type: value.type ?? "standard",
|
|
3766
|
+
status: value.status ?? "active",
|
|
3767
|
+
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
3768
|
+
updatedAt: "",
|
|
3769
|
+
deletedAt: ""
|
|
3770
|
+
};
|
|
3771
|
+
}
|
|
3743
3772
|
|
|
3744
|
-
// src/resources/
|
|
3773
|
+
// src/resources/app/app.repository.ts
|
|
3745
3774
|
var import_nodejs_utils19 = require("@eeplatform/nodejs-utils");
|
|
3775
|
+
var import_mongodb14 = require("mongodb");
|
|
3746
3776
|
var import_joi7 = __toESM(require("joi"));
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3777
|
+
function useAppRepo() {
|
|
3778
|
+
const namespace_collection = "apps";
|
|
3779
|
+
const repo = (0, import_nodejs_utils19.useRepo)(namespace_collection);
|
|
3780
|
+
async function createIndexes() {
|
|
3781
|
+
try {
|
|
3782
|
+
await repo.collection.createIndexes([
|
|
3783
|
+
{ key: { code: 1 } },
|
|
3784
|
+
{ key: { status: 1 } },
|
|
3785
|
+
{
|
|
3786
|
+
key: { code: "text", name: "text", description: "text" },
|
|
3787
|
+
name: "text_index"
|
|
3788
|
+
},
|
|
3789
|
+
{
|
|
3790
|
+
key: { code: 1, status: 1 },
|
|
3791
|
+
unique: true,
|
|
3792
|
+
name: "unique_code",
|
|
3793
|
+
partialFilterExpression: { status: { $in: ["active", "draft"] } }
|
|
3794
|
+
},
|
|
3795
|
+
{
|
|
3796
|
+
key: { name: 1, status: 1 },
|
|
3797
|
+
unique: true,
|
|
3798
|
+
name: "unique_name",
|
|
3799
|
+
partialFilterExpression: { status: { $in: ["active", "draft"] } }
|
|
3800
|
+
}
|
|
3801
|
+
]);
|
|
3802
|
+
} catch (error) {
|
|
3803
|
+
throw new Error("Failed to create index on apps.");
|
|
3768
3804
|
}
|
|
3805
|
+
}
|
|
3806
|
+
async function add(value, session) {
|
|
3769
3807
|
try {
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3808
|
+
value = modelApp(value);
|
|
3809
|
+
const res = await repo.collection.insertOne(value, { session });
|
|
3810
|
+
repo.delCachedData();
|
|
3811
|
+
return res.insertedId;
|
|
3812
|
+
} catch (error) {
|
|
3813
|
+
import_nodejs_utils19.logger.log({
|
|
3814
|
+
level: "error",
|
|
3815
|
+
message: error.message
|
|
3816
|
+
});
|
|
3817
|
+
if (error instanceof import_nodejs_utils19.AppError) {
|
|
3818
|
+
throw error;
|
|
3819
|
+
} else {
|
|
3820
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
3821
|
+
if (isDuplicated) {
|
|
3822
|
+
throw new import_nodejs_utils19.BadRequestError("App already exists.");
|
|
3823
|
+
}
|
|
3824
|
+
throw new Error("Failed to create app.");
|
|
3774
3825
|
}
|
|
3775
|
-
res.json(member);
|
|
3776
|
-
} catch (error2) {
|
|
3777
|
-
next(error2);
|
|
3778
3826
|
}
|
|
3779
3827
|
}
|
|
3780
|
-
async function
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
});
|
|
3786
|
-
const { error } = validation.validate({ ...req.params, ...req.query });
|
|
3787
|
-
if (error) {
|
|
3788
|
-
next(new import_nodejs_utils18.BadRequestError(error.message));
|
|
3789
|
-
return;
|
|
3828
|
+
async function updateById(_id, value, session) {
|
|
3829
|
+
try {
|
|
3830
|
+
_id = new import_mongodb14.ObjectId(_id);
|
|
3831
|
+
} catch (error) {
|
|
3832
|
+
throw new import_nodejs_utils19.BadRequestError("Invalid ID.");
|
|
3790
3833
|
}
|
|
3791
|
-
const orgId = req.query.org;
|
|
3792
|
-
const userId = req.params.user;
|
|
3793
|
-
const type = req.params.type;
|
|
3794
3834
|
try {
|
|
3795
|
-
const
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3835
|
+
const res = await repo.collection.updateOne(
|
|
3836
|
+
{ _id },
|
|
3837
|
+
{ $set: value },
|
|
3838
|
+
{ session }
|
|
3839
|
+
);
|
|
3840
|
+
repo.delCachedData();
|
|
3841
|
+
return res;
|
|
3842
|
+
} catch (error) {
|
|
3843
|
+
import_nodejs_utils19.logger.log({
|
|
3844
|
+
level: "error",
|
|
3845
|
+
message: error.message
|
|
3846
|
+
});
|
|
3847
|
+
if (error instanceof import_nodejs_utils19.AppError) {
|
|
3848
|
+
throw error;
|
|
3849
|
+
} else {
|
|
3850
|
+
throw new Error("Failed to update app.");
|
|
3799
3851
|
}
|
|
3800
|
-
res.json(member);
|
|
3801
|
-
} catch (error2) {
|
|
3802
|
-
next(error2);
|
|
3803
3852
|
}
|
|
3804
3853
|
}
|
|
3805
|
-
async function getAll(
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
status: import_joi6.default.string().required()
|
|
3821
|
-
});
|
|
3822
|
-
const { error } = validation.validate({
|
|
3823
|
-
search,
|
|
3854
|
+
async function getAll({
|
|
3855
|
+
search = "",
|
|
3856
|
+
page = 1,
|
|
3857
|
+
limit = 10,
|
|
3858
|
+
sort = {},
|
|
3859
|
+
status = "active",
|
|
3860
|
+
type = "standard"
|
|
3861
|
+
} = {}) {
|
|
3862
|
+
page = page > 0 ? page - 1 : 0;
|
|
3863
|
+
const query = {
|
|
3864
|
+
status
|
|
3865
|
+
};
|
|
3866
|
+
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
3867
|
+
const cacheParams = {
|
|
3868
|
+
status,
|
|
3824
3869
|
page,
|
|
3825
|
-
user,
|
|
3826
|
-
org,
|
|
3827
|
-
type,
|
|
3828
3870
|
limit,
|
|
3829
|
-
|
|
3830
|
-
}
|
|
3831
|
-
if (
|
|
3832
|
-
|
|
3833
|
-
|
|
3871
|
+
sort: JSON.stringify(sort)
|
|
3872
|
+
};
|
|
3873
|
+
if (search) {
|
|
3874
|
+
query.$text = { $search: search };
|
|
3875
|
+
cacheParams.search = search;
|
|
3876
|
+
}
|
|
3877
|
+
if (type) {
|
|
3878
|
+
if (Array.isArray(type)) {
|
|
3879
|
+
query.type = { $in: type };
|
|
3880
|
+
} else {
|
|
3881
|
+
query.type = type;
|
|
3882
|
+
}
|
|
3883
|
+
cacheParams.type = type;
|
|
3834
3884
|
}
|
|
3885
|
+
const cacheKey = (0, import_nodejs_utils19.makeCacheKey)(namespace_collection, cacheParams);
|
|
3886
|
+
import_nodejs_utils19.logger.log({
|
|
3887
|
+
level: "info",
|
|
3888
|
+
message: `Cache key for getAll apps: ${cacheKey}`
|
|
3889
|
+
});
|
|
3835
3890
|
try {
|
|
3836
|
-
const
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3891
|
+
const cached = await repo.getCache(cacheKey);
|
|
3892
|
+
if (cached) {
|
|
3893
|
+
import_nodejs_utils19.logger.log({
|
|
3894
|
+
level: "info",
|
|
3895
|
+
message: `Cache hit for getAll apps: ${cacheKey}`
|
|
3896
|
+
});
|
|
3897
|
+
return cached;
|
|
3898
|
+
}
|
|
3899
|
+
const items = await repo.collection.aggregate([
|
|
3900
|
+
{ $match: query },
|
|
3901
|
+
{ $sort: sort },
|
|
3902
|
+
{ $skip: page * limit },
|
|
3903
|
+
{ $limit: limit }
|
|
3904
|
+
]).toArray();
|
|
3905
|
+
const length = await repo.collection.countDocuments(query);
|
|
3906
|
+
const data = (0, import_nodejs_utils19.paginate)(items, page, limit, length);
|
|
3907
|
+
repo.setCache(cacheKey, data, 600).then(() => {
|
|
3908
|
+
import_nodejs_utils19.logger.log({
|
|
3909
|
+
level: "info",
|
|
3910
|
+
message: `Cache set for getAll apps: ${cacheKey}`
|
|
3911
|
+
});
|
|
3912
|
+
}).catch((err) => {
|
|
3913
|
+
import_nodejs_utils19.logger.log({
|
|
3914
|
+
level: "error",
|
|
3915
|
+
message: `Failed to set cache for getAll apps: ${err.message}`
|
|
3916
|
+
});
|
|
3844
3917
|
});
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3918
|
+
return data;
|
|
3919
|
+
} catch (error) {
|
|
3920
|
+
import_nodejs_utils19.logger.log({ level: "error", message: `${error}` });
|
|
3921
|
+
throw error;
|
|
3849
3922
|
}
|
|
3850
3923
|
}
|
|
3851
|
-
async function
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3924
|
+
async function getById(_id) {
|
|
3925
|
+
try {
|
|
3926
|
+
_id = new import_mongodb14.ObjectId(_id);
|
|
3927
|
+
} catch (error) {
|
|
3928
|
+
throw new import_nodejs_utils19.BadRequestError("Invalid ID.");
|
|
3929
|
+
}
|
|
3930
|
+
const cacheKey = (0, import_nodejs_utils19.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
3931
|
+
try {
|
|
3932
|
+
const cached = await repo.getCache(cacheKey);
|
|
3933
|
+
if (cached) {
|
|
3934
|
+
import_nodejs_utils19.logger.log({
|
|
3935
|
+
level: "info",
|
|
3936
|
+
message: `Cache hit for getById app: ${cacheKey}`
|
|
3937
|
+
});
|
|
3938
|
+
return cached;
|
|
3939
|
+
}
|
|
3940
|
+
const result = await repo.collection.findOne({
|
|
3941
|
+
_id
|
|
3942
|
+
});
|
|
3943
|
+
repo.setCache(cacheKey, result, 300).then(() => {
|
|
3944
|
+
import_nodejs_utils19.logger.log({
|
|
3945
|
+
level: "info",
|
|
3946
|
+
message: `Cache set for app by id: ${cacheKey}`
|
|
3947
|
+
});
|
|
3948
|
+
}).catch((err) => {
|
|
3949
|
+
import_nodejs_utils19.logger.log({
|
|
3950
|
+
level: "error",
|
|
3951
|
+
message: `Failed to set cache for app by id: ${err.message}`
|
|
3952
|
+
});
|
|
3953
|
+
});
|
|
3954
|
+
return result;
|
|
3955
|
+
} catch (error) {
|
|
3956
|
+
if (error instanceof import_nodejs_utils19.AppError) {
|
|
3957
|
+
throw error;
|
|
3958
|
+
} else {
|
|
3959
|
+
throw new import_nodejs_utils19.InternalServerError("Failed to get app.");
|
|
3960
|
+
}
|
|
3961
|
+
}
|
|
3962
|
+
}
|
|
3963
|
+
async function getByCode(code) {
|
|
3964
|
+
const validate = import_joi7.default.string().required();
|
|
3965
|
+
const { error } = validate.validate(code);
|
|
3966
|
+
if (error) {
|
|
3967
|
+
throw new import_nodejs_utils19.BadRequestError("Invalid code.");
|
|
3968
|
+
}
|
|
3969
|
+
const cacheKey = (0, import_nodejs_utils19.makeCacheKey)(namespace_collection, {
|
|
3970
|
+
code,
|
|
3971
|
+
tag: "byCode"
|
|
3972
|
+
});
|
|
3973
|
+
try {
|
|
3974
|
+
const cached = await repo.getCache(cacheKey);
|
|
3975
|
+
if (cached) {
|
|
3976
|
+
import_nodejs_utils19.logger.log({
|
|
3977
|
+
level: "info",
|
|
3978
|
+
message: `Cache hit for getByCode app: ${cacheKey}`
|
|
3979
|
+
});
|
|
3980
|
+
return cached;
|
|
3981
|
+
}
|
|
3982
|
+
const result = await repo.collection.findOne({
|
|
3983
|
+
code
|
|
3984
|
+
});
|
|
3985
|
+
repo.setCache(cacheKey, result, 300).then(() => {
|
|
3986
|
+
import_nodejs_utils19.logger.log({
|
|
3987
|
+
level: "info",
|
|
3988
|
+
message: `Cache set for app by code: ${cacheKey}`
|
|
3989
|
+
});
|
|
3990
|
+
}).catch((err) => {
|
|
3991
|
+
import_nodejs_utils19.logger.log({
|
|
3992
|
+
level: "error",
|
|
3993
|
+
message: `Failed to set cache for app by code: ${err.message}`
|
|
3994
|
+
});
|
|
3995
|
+
});
|
|
3996
|
+
return result;
|
|
3997
|
+
} catch (error2) {
|
|
3998
|
+
if (error2 instanceof import_nodejs_utils19.AppError) {
|
|
3999
|
+
throw error2;
|
|
4000
|
+
} else {
|
|
4001
|
+
throw new import_nodejs_utils19.InternalServerError("Failed to get app.");
|
|
4002
|
+
}
|
|
4003
|
+
}
|
|
4004
|
+
}
|
|
4005
|
+
async function deleteById(_id, session) {
|
|
4006
|
+
try {
|
|
4007
|
+
_id = new import_mongodb14.ObjectId(_id);
|
|
4008
|
+
} catch (error) {
|
|
4009
|
+
throw new import_nodejs_utils19.BadRequestError("Invalid ID.");
|
|
4010
|
+
}
|
|
4011
|
+
try {
|
|
4012
|
+
const res = await repo.collection.updateOne(
|
|
4013
|
+
{ _id },
|
|
4014
|
+
{ $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } }
|
|
4015
|
+
);
|
|
4016
|
+
repo.delCachedData();
|
|
4017
|
+
return res;
|
|
4018
|
+
} catch (error) {
|
|
4019
|
+
import_nodejs_utils19.logger.log({
|
|
4020
|
+
level: "error",
|
|
4021
|
+
message: error.message
|
|
4022
|
+
});
|
|
4023
|
+
if (error instanceof import_nodejs_utils19.AppError) {
|
|
4024
|
+
throw error;
|
|
4025
|
+
} else {
|
|
4026
|
+
throw new import_nodejs_utils19.InternalServerError("Failed to delete app.");
|
|
4027
|
+
}
|
|
4028
|
+
}
|
|
4029
|
+
}
|
|
4030
|
+
return {
|
|
4031
|
+
createIndexes,
|
|
4032
|
+
add,
|
|
4033
|
+
getAll,
|
|
4034
|
+
getById,
|
|
4035
|
+
getByCode,
|
|
4036
|
+
updateById,
|
|
4037
|
+
deleteById
|
|
4038
|
+
};
|
|
4039
|
+
}
|
|
4040
|
+
|
|
4041
|
+
// src/resources/app/app.service.ts
|
|
4042
|
+
var import_nodejs_utils20 = require("@eeplatform/nodejs-utils");
|
|
4043
|
+
function useAppService() {
|
|
4044
|
+
const {
|
|
4045
|
+
updateById: _updateById,
|
|
4046
|
+
getById: _getById,
|
|
4047
|
+
deleteById: _deleteById,
|
|
4048
|
+
getByCode: _getByCode,
|
|
4049
|
+
add: _add
|
|
4050
|
+
} = useAppRepo();
|
|
4051
|
+
async function addDefaultApps() {
|
|
4052
|
+
const apps = [
|
|
4053
|
+
{
|
|
4054
|
+
code: "admin",
|
|
4055
|
+
name: "Admin",
|
|
4056
|
+
description: "Administrative application.",
|
|
4057
|
+
type: "default"
|
|
4058
|
+
},
|
|
4059
|
+
{
|
|
4060
|
+
code: "basic-edu-ro",
|
|
4061
|
+
name: "Basic Education Regional Office",
|
|
4062
|
+
description: "Basic Education Regional Office application."
|
|
4063
|
+
},
|
|
4064
|
+
{
|
|
4065
|
+
code: "basic-edu-sdo",
|
|
4066
|
+
name: "Basic Education School Division Office",
|
|
4067
|
+
description: "Basic Education School Division Office application."
|
|
4068
|
+
},
|
|
4069
|
+
{
|
|
4070
|
+
code: "basic-edu-school",
|
|
4071
|
+
name: "Basic Education School",
|
|
4072
|
+
description: "Basic Education School application."
|
|
4073
|
+
}
|
|
4074
|
+
];
|
|
4075
|
+
const session = import_nodejs_utils20.useAtlas.getClient()?.startSession();
|
|
4076
|
+
if (!session) {
|
|
4077
|
+
throw new Error("Failed to start database session.");
|
|
4078
|
+
}
|
|
4079
|
+
try {
|
|
4080
|
+
session?.startTransaction();
|
|
4081
|
+
for (const app of apps) {
|
|
4082
|
+
const existingApp = await _getByCode(app.code);
|
|
4083
|
+
if (!existingApp) {
|
|
4084
|
+
await _add(app, session);
|
|
4085
|
+
}
|
|
4086
|
+
}
|
|
4087
|
+
await session.commitTransaction();
|
|
4088
|
+
import_nodejs_utils20.logger.log({
|
|
4089
|
+
level: "info",
|
|
4090
|
+
message: "Default apps added successfully."
|
|
4091
|
+
});
|
|
4092
|
+
return;
|
|
4093
|
+
} catch (error) {
|
|
4094
|
+
await session.abortTransaction();
|
|
4095
|
+
import_nodejs_utils20.logger.log({
|
|
4096
|
+
level: "error",
|
|
4097
|
+
message: `Failed to add default apps: ${error}`
|
|
4098
|
+
});
|
|
4099
|
+
throw error;
|
|
4100
|
+
} finally {
|
|
4101
|
+
await session.endSession();
|
|
4102
|
+
}
|
|
4103
|
+
}
|
|
4104
|
+
async function deleteById(id) {
|
|
4105
|
+
try {
|
|
4106
|
+
await _deleteById(id);
|
|
4107
|
+
return "App deleted successfully.";
|
|
4108
|
+
} catch (error) {
|
|
4109
|
+
throw error;
|
|
4110
|
+
}
|
|
4111
|
+
}
|
|
4112
|
+
return {
|
|
4113
|
+
addDefaultApps,
|
|
4114
|
+
deleteById
|
|
4115
|
+
};
|
|
4116
|
+
}
|
|
4117
|
+
|
|
4118
|
+
// src/resources/app/app.controller.ts
|
|
4119
|
+
var import_nodejs_utils21 = require("@eeplatform/nodejs-utils");
|
|
4120
|
+
var import_joi8 = __toESM(require("joi"));
|
|
4121
|
+
function useAppController() {
|
|
4122
|
+
const {
|
|
4123
|
+
getAll: _getAll,
|
|
4124
|
+
getById: _getById,
|
|
4125
|
+
add: _add,
|
|
4126
|
+
updateById: _updateById
|
|
4127
|
+
} = useAppRepo();
|
|
4128
|
+
const { deleteById: _deleteById } = useAppService();
|
|
4129
|
+
async function add(req, res, next) {
|
|
4130
|
+
const value = req.body;
|
|
4131
|
+
const { error } = schemaApp.validate(value);
|
|
4132
|
+
if (error) {
|
|
4133
|
+
next(new import_nodejs_utils21.BadRequestError(error.message));
|
|
4134
|
+
return;
|
|
4135
|
+
}
|
|
4136
|
+
try {
|
|
4137
|
+
const result = await _add(value);
|
|
4138
|
+
res.json(result);
|
|
4139
|
+
return;
|
|
4140
|
+
} catch (error2) {
|
|
4141
|
+
next(error2);
|
|
4142
|
+
}
|
|
4143
|
+
}
|
|
4144
|
+
async function updateById(req, res, next) {
|
|
4145
|
+
const id = req.params.id ?? "";
|
|
4146
|
+
const { error: errorId } = import_joi8.default.string().hex().required().validate(id);
|
|
4147
|
+
if (errorId) {
|
|
4148
|
+
next(new import_nodejs_utils21.BadRequestError(errorId.message));
|
|
4149
|
+
return;
|
|
4150
|
+
}
|
|
4151
|
+
const value = req.body;
|
|
4152
|
+
const { error } = schemaAppUpdate.validate(value);
|
|
4153
|
+
if (error) {
|
|
4154
|
+
next(new import_nodejs_utils21.BadRequestError(error.message));
|
|
4155
|
+
return;
|
|
4156
|
+
}
|
|
4157
|
+
try {
|
|
4158
|
+
const result = await _updateById(req.params.id, value);
|
|
4159
|
+
res.json(result);
|
|
4160
|
+
return;
|
|
4161
|
+
} catch (error2) {
|
|
4162
|
+
next(error2);
|
|
4163
|
+
}
|
|
4164
|
+
}
|
|
4165
|
+
async function getAll(req, res, next) {
|
|
4166
|
+
const query = req.query;
|
|
4167
|
+
const validation = import_joi8.default.object({
|
|
4168
|
+
page: import_joi8.default.number().min(1).optional().allow("", null),
|
|
4169
|
+
limit: import_joi8.default.number().min(1).optional().allow("", null),
|
|
4170
|
+
search: import_joi8.default.string().optional().allow("", null),
|
|
4171
|
+
status: import_joi8.default.string().optional().allow("", null),
|
|
4172
|
+
type: import_joi8.default.string().optional().allow("", null)
|
|
4173
|
+
});
|
|
4174
|
+
const { error } = validation.validate(query);
|
|
4175
|
+
if (error) {
|
|
4176
|
+
next(new import_nodejs_utils21.BadRequestError(error.message));
|
|
4177
|
+
return;
|
|
4178
|
+
}
|
|
4179
|
+
const page = parseInt(req.query.page) ?? 1;
|
|
4180
|
+
let limit = parseInt(req.query.limit) ?? 20;
|
|
4181
|
+
limit = isNaN(limit) ? 20 : limit;
|
|
4182
|
+
const sort = req.query.sort ? String(req.query.sort).split(",") : "";
|
|
4183
|
+
const sortOrder = req.query.sortOrder ? String(req.query.sortOrder).split(",") : "";
|
|
4184
|
+
const sortObj = {};
|
|
4185
|
+
if (sort && Array.isArray(sort) && sort.length && sortOrder && Array.isArray(sortOrder) && sortOrder.length) {
|
|
4186
|
+
sort.forEach((field, index) => {
|
|
4187
|
+
sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
|
|
4188
|
+
});
|
|
4189
|
+
}
|
|
4190
|
+
const status = req.query.status ?? "active";
|
|
4191
|
+
const search = req.query.search ?? "";
|
|
4192
|
+
let type = req.query.type ? req.query.type.split(",") : "standard";
|
|
4193
|
+
try {
|
|
4194
|
+
const buildings = await _getAll({
|
|
4195
|
+
page,
|
|
4196
|
+
limit,
|
|
4197
|
+
sort: sortObj,
|
|
4198
|
+
status,
|
|
4199
|
+
search,
|
|
4200
|
+
type
|
|
4201
|
+
});
|
|
4202
|
+
res.json(buildings);
|
|
4203
|
+
return;
|
|
4204
|
+
} catch (error2) {
|
|
4205
|
+
next(error2);
|
|
4206
|
+
}
|
|
4207
|
+
}
|
|
4208
|
+
async function getById(req, res, next) {
|
|
4209
|
+
const id = req.params.id;
|
|
4210
|
+
const validation = import_joi8.default.object({
|
|
4211
|
+
id: import_joi8.default.string().hex().required()
|
|
4212
|
+
});
|
|
4213
|
+
const { error } = validation.validate({ id });
|
|
4214
|
+
if (error) {
|
|
4215
|
+
next(new import_nodejs_utils21.BadRequestError(error.message));
|
|
4216
|
+
return;
|
|
4217
|
+
}
|
|
4218
|
+
try {
|
|
4219
|
+
const data = await _getById(id);
|
|
4220
|
+
res.json({
|
|
4221
|
+
message: "Successfully retrieved app.",
|
|
4222
|
+
data
|
|
4223
|
+
});
|
|
4224
|
+
return;
|
|
4225
|
+
} catch (error2) {
|
|
4226
|
+
next(error2);
|
|
4227
|
+
}
|
|
4228
|
+
}
|
|
4229
|
+
async function deleteById(req, res, next) {
|
|
4230
|
+
const id = req.params.id;
|
|
4231
|
+
const validation = import_joi8.default.object({
|
|
4232
|
+
id: import_joi8.default.string().hex().required()
|
|
4233
|
+
});
|
|
4234
|
+
const { error } = validation.validate({ id });
|
|
4235
|
+
if (error) {
|
|
4236
|
+
next(new import_nodejs_utils21.BadRequestError(error.message));
|
|
4237
|
+
return;
|
|
4238
|
+
}
|
|
4239
|
+
try {
|
|
4240
|
+
const message = await _deleteById(id);
|
|
4241
|
+
res.json(message);
|
|
4242
|
+
return;
|
|
4243
|
+
} catch (error2) {
|
|
4244
|
+
next(error2);
|
|
4245
|
+
}
|
|
4246
|
+
}
|
|
4247
|
+
return {
|
|
4248
|
+
add,
|
|
4249
|
+
updateById,
|
|
4250
|
+
getAll,
|
|
4251
|
+
getById,
|
|
4252
|
+
deleteById
|
|
4253
|
+
};
|
|
4254
|
+
}
|
|
4255
|
+
|
|
4256
|
+
// src/resources/permission/permission.model.ts
|
|
4257
|
+
var import_nodejs_utils22 = require("@eeplatform/nodejs-utils");
|
|
4258
|
+
var import_joi9 = __toESM(require("joi"));
|
|
4259
|
+
var schemaPermission = import_joi9.default.object({
|
|
4260
|
+
app: import_joi9.default.string().required(),
|
|
4261
|
+
key: import_joi9.default.string().required(),
|
|
4262
|
+
name: import_joi9.default.string().required(),
|
|
4263
|
+
group: import_joi9.default.string().required(),
|
|
4264
|
+
description: import_joi9.default.string().required(),
|
|
4265
|
+
deprecated: import_joi9.default.boolean().optional().allow(null)
|
|
4266
|
+
});
|
|
4267
|
+
var schemaPermissionUpdate = import_joi9.default.object({
|
|
4268
|
+
key: import_joi9.default.string().optional().allow("", null),
|
|
4269
|
+
name: import_joi9.default.string().optional().allow("", null),
|
|
4270
|
+
group: import_joi9.default.string().optional().allow("", null),
|
|
4271
|
+
description: import_joi9.default.string().max(1024).optional().allow("", null)
|
|
4272
|
+
});
|
|
4273
|
+
function modelPermission(value) {
|
|
4274
|
+
const { error } = schemaPermission.validate(value);
|
|
4275
|
+
if (error) {
|
|
4276
|
+
throw new import_nodejs_utils22.BadRequestError(error.message);
|
|
4277
|
+
}
|
|
4278
|
+
return {
|
|
4279
|
+
_id: value._id,
|
|
4280
|
+
app: value.app,
|
|
4281
|
+
key: value.key,
|
|
4282
|
+
name: value.name,
|
|
4283
|
+
group: value.group,
|
|
4284
|
+
description: value.description,
|
|
4285
|
+
deprecated: value.deprecated ?? false,
|
|
4286
|
+
status: value.status ?? "active",
|
|
4287
|
+
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
4288
|
+
updatedAt: "",
|
|
4289
|
+
deletedAt: ""
|
|
4290
|
+
};
|
|
4291
|
+
}
|
|
4292
|
+
|
|
4293
|
+
// src/resources/permission/permission.repository.ts
|
|
4294
|
+
var import_nodejs_utils23 = require("@eeplatform/nodejs-utils");
|
|
4295
|
+
var import_mongodb15 = require("mongodb");
|
|
4296
|
+
var import_joi10 = __toESM(require("joi"));
|
|
4297
|
+
function usePermissionRepo() {
|
|
4298
|
+
const namespace_collection = "permissions";
|
|
4299
|
+
const repo = (0, import_nodejs_utils23.useRepo)(namespace_collection);
|
|
4300
|
+
async function createIndexes() {
|
|
4301
|
+
try {
|
|
4302
|
+
await repo.collection.createIndexes([
|
|
4303
|
+
{ key: { app: 1 } },
|
|
4304
|
+
{ key: { name: 1 } },
|
|
4305
|
+
{ key: { key: 1 } },
|
|
4306
|
+
{ key: { group: 1 } },
|
|
4307
|
+
{
|
|
4308
|
+
key: {
|
|
4309
|
+
app: "text",
|
|
4310
|
+
name: "text",
|
|
4311
|
+
key: "text",
|
|
4312
|
+
description: "text",
|
|
4313
|
+
group: "text"
|
|
4314
|
+
},
|
|
4315
|
+
name: "text_index"
|
|
4316
|
+
},
|
|
4317
|
+
{
|
|
4318
|
+
key: { app: 1, name: 1, key: 1, group: 1 },
|
|
4319
|
+
unique: true,
|
|
4320
|
+
name: "unique_permission"
|
|
4321
|
+
}
|
|
4322
|
+
]);
|
|
4323
|
+
} catch (error) {
|
|
4324
|
+
throw new Error("Failed to create index on permissions.");
|
|
4325
|
+
}
|
|
4326
|
+
}
|
|
4327
|
+
async function add(value, session) {
|
|
4328
|
+
try {
|
|
4329
|
+
value = modelPermission(value);
|
|
4330
|
+
const res = await repo.collection.insertOne(value, { session });
|
|
4331
|
+
repo.delCachedData();
|
|
4332
|
+
return res.insertedId;
|
|
4333
|
+
} catch (error) {
|
|
4334
|
+
import_nodejs_utils23.logger.log({
|
|
4335
|
+
level: "error",
|
|
4336
|
+
message: error.message
|
|
4337
|
+
});
|
|
4338
|
+
if (error instanceof import_nodejs_utils23.AppError) {
|
|
4339
|
+
throw error;
|
|
4340
|
+
} else {
|
|
4341
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
4342
|
+
if (isDuplicated) {
|
|
4343
|
+
throw new import_nodejs_utils23.BadRequestError("Permission already exists.");
|
|
4344
|
+
}
|
|
4345
|
+
throw new Error("Failed to create permission.");
|
|
4346
|
+
}
|
|
4347
|
+
}
|
|
4348
|
+
}
|
|
4349
|
+
async function updateById(_id, value, session) {
|
|
4350
|
+
try {
|
|
4351
|
+
_id = new import_mongodb15.ObjectId(_id);
|
|
4352
|
+
} catch (error2) {
|
|
4353
|
+
throw new import_nodejs_utils23.BadRequestError("Invalid ID.");
|
|
4354
|
+
}
|
|
4355
|
+
const { error } = schemaPermissionUpdate.validate(value);
|
|
4356
|
+
if (error) {
|
|
4357
|
+
throw new import_nodejs_utils23.BadRequestError(`Invalid data: ${error.message}`);
|
|
4358
|
+
}
|
|
4359
|
+
try {
|
|
4360
|
+
const res = await repo.collection.updateOne(
|
|
4361
|
+
{ _id },
|
|
4362
|
+
{ $set: value },
|
|
4363
|
+
{ session }
|
|
4364
|
+
);
|
|
4365
|
+
repo.delCachedData();
|
|
4366
|
+
return res;
|
|
4367
|
+
} catch (error2) {
|
|
4368
|
+
import_nodejs_utils23.logger.log({
|
|
4369
|
+
level: "error",
|
|
4370
|
+
message: error2.message
|
|
4371
|
+
});
|
|
4372
|
+
if (error2 instanceof import_nodejs_utils23.AppError) {
|
|
4373
|
+
throw error2;
|
|
4374
|
+
} else {
|
|
4375
|
+
throw new Error("Failed to update permission.");
|
|
4376
|
+
}
|
|
4377
|
+
}
|
|
4378
|
+
}
|
|
4379
|
+
async function getAll({
|
|
4380
|
+
search = "",
|
|
4381
|
+
page = 1,
|
|
4382
|
+
limit = 10,
|
|
4383
|
+
sort = {},
|
|
4384
|
+
app = "",
|
|
4385
|
+
status = "active"
|
|
4386
|
+
} = {}) {
|
|
4387
|
+
page = page > 0 ? page - 1 : 0;
|
|
4388
|
+
const query = {};
|
|
4389
|
+
const cacheParams = {
|
|
4390
|
+
page,
|
|
4391
|
+
limit,
|
|
4392
|
+
sort: JSON.stringify(sort)
|
|
4393
|
+
};
|
|
4394
|
+
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
4395
|
+
query.status = status;
|
|
4396
|
+
cacheParams.status = status;
|
|
4397
|
+
if (search) {
|
|
4398
|
+
query.$text = { $search: search };
|
|
4399
|
+
cacheParams.search = search;
|
|
4400
|
+
}
|
|
4401
|
+
if (app) {
|
|
4402
|
+
query.app = app;
|
|
4403
|
+
cacheParams.app = app;
|
|
4404
|
+
}
|
|
4405
|
+
const cacheKey = (0, import_nodejs_utils23.makeCacheKey)(namespace_collection, cacheParams);
|
|
4406
|
+
import_nodejs_utils23.logger.log({
|
|
4407
|
+
level: "info",
|
|
4408
|
+
message: `Cache key for getAll permissions: ${cacheKey}`
|
|
4409
|
+
});
|
|
4410
|
+
try {
|
|
4411
|
+
const cached = await repo.getCache(cacheKey);
|
|
4412
|
+
if (cached) {
|
|
4413
|
+
import_nodejs_utils23.logger.log({
|
|
4414
|
+
level: "info",
|
|
4415
|
+
message: `Cache hit for getAll permissions: ${cacheKey}`
|
|
4416
|
+
});
|
|
4417
|
+
return cached;
|
|
4418
|
+
}
|
|
4419
|
+
const items = await repo.collection.aggregate([
|
|
4420
|
+
{ $match: query },
|
|
4421
|
+
{ $sort: sort },
|
|
4422
|
+
{ $skip: page * limit },
|
|
4423
|
+
{ $limit: limit }
|
|
4424
|
+
]).toArray();
|
|
4425
|
+
const length = await repo.collection.countDocuments(query);
|
|
4426
|
+
const data = (0, import_nodejs_utils23.paginate)(items, page, limit, length);
|
|
4427
|
+
repo.setCache(cacheKey, data, 600).then(() => {
|
|
4428
|
+
import_nodejs_utils23.logger.log({
|
|
4429
|
+
level: "info",
|
|
4430
|
+
message: `Cache set for getAll permissions: ${cacheKey}`
|
|
4431
|
+
});
|
|
4432
|
+
}).catch((err) => {
|
|
4433
|
+
import_nodejs_utils23.logger.log({
|
|
4434
|
+
level: "error",
|
|
4435
|
+
message: `Failed to set cache for getAll permissions: ${err.message}`
|
|
4436
|
+
});
|
|
4437
|
+
});
|
|
4438
|
+
return data;
|
|
4439
|
+
} catch (error) {
|
|
4440
|
+
import_nodejs_utils23.logger.log({ level: "error", message: `${error}` });
|
|
4441
|
+
throw error;
|
|
4442
|
+
}
|
|
4443
|
+
}
|
|
4444
|
+
async function getById(_id) {
|
|
4445
|
+
try {
|
|
4446
|
+
_id = new import_mongodb15.ObjectId(_id);
|
|
4447
|
+
} catch (error) {
|
|
4448
|
+
throw new import_nodejs_utils23.BadRequestError("Invalid ID.");
|
|
4449
|
+
}
|
|
4450
|
+
const cacheKey = (0, import_nodejs_utils23.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
4451
|
+
try {
|
|
4452
|
+
const cached = await repo.getCache(cacheKey);
|
|
4453
|
+
if (cached) {
|
|
4454
|
+
import_nodejs_utils23.logger.log({
|
|
4455
|
+
level: "info",
|
|
4456
|
+
message: `Cache hit for getById permission: ${cacheKey}`
|
|
4457
|
+
});
|
|
4458
|
+
return cached;
|
|
4459
|
+
}
|
|
4460
|
+
const result = await repo.collection.findOne({
|
|
4461
|
+
_id
|
|
4462
|
+
});
|
|
4463
|
+
repo.setCache(cacheKey, result, 300).then(() => {
|
|
4464
|
+
import_nodejs_utils23.logger.log({
|
|
4465
|
+
level: "info",
|
|
4466
|
+
message: `Cache set for permission by id: ${cacheKey}`
|
|
4467
|
+
});
|
|
4468
|
+
}).catch((err) => {
|
|
4469
|
+
import_nodejs_utils23.logger.log({
|
|
4470
|
+
level: "error",
|
|
4471
|
+
message: `Failed to set cache for permission by id: ${err.message}`
|
|
4472
|
+
});
|
|
4473
|
+
});
|
|
4474
|
+
return result;
|
|
4475
|
+
} catch (error) {
|
|
4476
|
+
if (error instanceof import_nodejs_utils23.AppError) {
|
|
4477
|
+
throw error;
|
|
4478
|
+
} else {
|
|
4479
|
+
throw new import_nodejs_utils23.InternalServerError("Failed to get permission.");
|
|
4480
|
+
}
|
|
4481
|
+
}
|
|
4482
|
+
}
|
|
4483
|
+
async function getByKey(key, group, app) {
|
|
4484
|
+
const validation = import_joi10.default.object({
|
|
4485
|
+
key: import_joi10.default.string().required(),
|
|
4486
|
+
group: import_joi10.default.string().optional().allow("", null),
|
|
4487
|
+
app: import_joi10.default.string().optional().allow("", null)
|
|
4488
|
+
});
|
|
4489
|
+
const { error } = validation.validate({ key, group });
|
|
4490
|
+
if (error) {
|
|
4491
|
+
throw new import_nodejs_utils23.BadRequestError(`Invalid data: ${error.message}`);
|
|
4492
|
+
}
|
|
4493
|
+
const query = {};
|
|
4494
|
+
const cacheKeyOptions = {};
|
|
4495
|
+
query.key = key;
|
|
4496
|
+
cacheKeyOptions.key = key;
|
|
4497
|
+
if (group) {
|
|
4498
|
+
query.group = group;
|
|
4499
|
+
cacheKeyOptions.group = group;
|
|
4500
|
+
}
|
|
4501
|
+
if (app) {
|
|
4502
|
+
query.app = app;
|
|
4503
|
+
cacheKeyOptions.app = app;
|
|
4504
|
+
}
|
|
4505
|
+
const cacheKey = (0, import_nodejs_utils23.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
4506
|
+
try {
|
|
4507
|
+
const cached = await repo.getCache(cacheKey);
|
|
4508
|
+
if (cached) {
|
|
4509
|
+
import_nodejs_utils23.logger.log({
|
|
4510
|
+
level: "info",
|
|
4511
|
+
message: `Cache hit for getById permission: ${cacheKey}`
|
|
4512
|
+
});
|
|
4513
|
+
return cached;
|
|
4514
|
+
}
|
|
4515
|
+
const result = await repo.collection.findOne(query);
|
|
4516
|
+
repo.setCache(cacheKey, result, 300).then(() => {
|
|
4517
|
+
import_nodejs_utils23.logger.log({
|
|
4518
|
+
level: "info",
|
|
4519
|
+
message: `Cache set for permission by key: ${cacheKey}`
|
|
4520
|
+
});
|
|
4521
|
+
}).catch((err) => {
|
|
4522
|
+
import_nodejs_utils23.logger.log({
|
|
4523
|
+
level: "error",
|
|
4524
|
+
message: `Failed to set cache for permission by key: ${err.message}`
|
|
4525
|
+
});
|
|
4526
|
+
});
|
|
4527
|
+
return result;
|
|
4528
|
+
} catch (error2) {
|
|
4529
|
+
if (error2 instanceof import_nodejs_utils23.AppError) {
|
|
4530
|
+
throw error2;
|
|
4531
|
+
} else {
|
|
4532
|
+
throw new import_nodejs_utils23.InternalServerError("Failed to get permission.");
|
|
4533
|
+
}
|
|
4534
|
+
}
|
|
4535
|
+
}
|
|
4536
|
+
async function countByGroup(group) {
|
|
4537
|
+
const cacheKey = (0, import_nodejs_utils23.makeCacheKey)(namespace_collection, {
|
|
4538
|
+
group,
|
|
4539
|
+
tag: "countByGroup"
|
|
4540
|
+
});
|
|
4541
|
+
try {
|
|
4542
|
+
const cached = await repo.getCache(cacheKey);
|
|
4543
|
+
if (cached) {
|
|
4544
|
+
import_nodejs_utils23.logger.log({
|
|
4545
|
+
level: "info",
|
|
4546
|
+
message: `Cache hit for getById permission: ${cacheKey}`
|
|
4547
|
+
});
|
|
4548
|
+
return cached;
|
|
4549
|
+
}
|
|
4550
|
+
const result = await repo.collection.countDocuments({
|
|
4551
|
+
group
|
|
4552
|
+
});
|
|
4553
|
+
repo.setCache(cacheKey, result, 300).then(() => {
|
|
4554
|
+
import_nodejs_utils23.logger.log({
|
|
4555
|
+
level: "info",
|
|
4556
|
+
message: `Cache set for permission count by group: ${cacheKey}`
|
|
4557
|
+
});
|
|
4558
|
+
}).catch((err) => {
|
|
4559
|
+
import_nodejs_utils23.logger.log({
|
|
4560
|
+
level: "error",
|
|
4561
|
+
message: `Failed to set cache for permission by group: ${err.message}`
|
|
4562
|
+
});
|
|
4563
|
+
});
|
|
4564
|
+
return result;
|
|
4565
|
+
} catch (error) {
|
|
4566
|
+
if (error instanceof import_nodejs_utils23.AppError) {
|
|
4567
|
+
throw error;
|
|
4568
|
+
} else {
|
|
4569
|
+
throw new import_nodejs_utils23.InternalServerError("Failed to count permission by group.");
|
|
4570
|
+
}
|
|
4571
|
+
}
|
|
4572
|
+
}
|
|
4573
|
+
async function deleteById(_id, session) {
|
|
4574
|
+
try {
|
|
4575
|
+
_id = new import_mongodb15.ObjectId(_id);
|
|
4576
|
+
} catch (error) {
|
|
4577
|
+
throw new import_nodejs_utils23.BadRequestError("Invalid ID.");
|
|
4578
|
+
}
|
|
4579
|
+
try {
|
|
4580
|
+
const res = await repo.collection.updateOne(
|
|
4581
|
+
{ _id },
|
|
4582
|
+
{ $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } }
|
|
4583
|
+
);
|
|
4584
|
+
repo.delCachedData();
|
|
4585
|
+
return res;
|
|
4586
|
+
} catch (error) {
|
|
4587
|
+
import_nodejs_utils23.logger.log({
|
|
4588
|
+
level: "error",
|
|
4589
|
+
message: error.message
|
|
4590
|
+
});
|
|
4591
|
+
if (error instanceof import_nodejs_utils23.AppError) {
|
|
4592
|
+
throw error;
|
|
4593
|
+
} else {
|
|
4594
|
+
throw new import_nodejs_utils23.InternalServerError("Failed to delete permission.");
|
|
4595
|
+
}
|
|
4596
|
+
}
|
|
4597
|
+
}
|
|
4598
|
+
return {
|
|
4599
|
+
createIndexes,
|
|
4600
|
+
add,
|
|
4601
|
+
getAll,
|
|
4602
|
+
getById,
|
|
4603
|
+
getByKey,
|
|
4604
|
+
updateById,
|
|
4605
|
+
deleteById,
|
|
4606
|
+
countByGroup
|
|
4607
|
+
};
|
|
4608
|
+
}
|
|
4609
|
+
|
|
4610
|
+
// src/resources/permission/permission.service.ts
|
|
4611
|
+
function usePermissionService() {
|
|
4612
|
+
const {
|
|
4613
|
+
updateById: _updateById,
|
|
4614
|
+
getById: _getById,
|
|
4615
|
+
deleteById: _deleteById
|
|
4616
|
+
} = usePermissionRepo();
|
|
4617
|
+
async function deleteById(id) {
|
|
4618
|
+
try {
|
|
4619
|
+
await _deleteById(id);
|
|
4620
|
+
return "Permission deleted successfully.";
|
|
4621
|
+
} catch (error) {
|
|
4622
|
+
throw error;
|
|
4623
|
+
}
|
|
4624
|
+
}
|
|
4625
|
+
return {
|
|
4626
|
+
deleteById
|
|
4627
|
+
};
|
|
4628
|
+
}
|
|
4629
|
+
|
|
4630
|
+
// src/resources/permission/permission.controller.ts
|
|
4631
|
+
var import_nodejs_utils24 = require("@eeplatform/nodejs-utils");
|
|
4632
|
+
var import_joi11 = __toESM(require("joi"));
|
|
4633
|
+
function usePermissionController() {
|
|
4634
|
+
const {
|
|
4635
|
+
getAll: _getAll,
|
|
4636
|
+
getById: _getById,
|
|
4637
|
+
add: _add,
|
|
4638
|
+
updateById: _updateById
|
|
4639
|
+
} = usePermissionRepo();
|
|
4640
|
+
const { deleteById: _deleteById } = usePermissionService();
|
|
4641
|
+
async function add(req, res, next) {
|
|
4642
|
+
const value = req.body;
|
|
4643
|
+
const { error } = schemaPermission.validate(value);
|
|
4644
|
+
if (error) {
|
|
4645
|
+
next(new import_nodejs_utils24.BadRequestError(error.message));
|
|
4646
|
+
import_nodejs_utils24.logger.info(`Controller: ${error.message}`);
|
|
4647
|
+
return;
|
|
4648
|
+
}
|
|
4649
|
+
try {
|
|
4650
|
+
const result = await _add(value);
|
|
4651
|
+
res.json(result);
|
|
4652
|
+
return;
|
|
4653
|
+
} catch (error2) {
|
|
4654
|
+
next(error2);
|
|
4655
|
+
}
|
|
4656
|
+
}
|
|
4657
|
+
async function getAll(req, res, next) {
|
|
4658
|
+
const query = req.query;
|
|
4659
|
+
const validation = import_joi11.default.object({
|
|
4660
|
+
page: import_joi11.default.number().min(1).optional().allow("", null),
|
|
4661
|
+
limit: import_joi11.default.number().min(1).optional().allow("", null),
|
|
4662
|
+
search: import_joi11.default.string().optional().allow("", null),
|
|
4663
|
+
app: import_joi11.default.string().optional().allow("", null),
|
|
4664
|
+
status: import_joi11.default.string().optional().allow("", null)
|
|
4665
|
+
});
|
|
4666
|
+
const { error } = validation.validate(query);
|
|
4667
|
+
if (error) {
|
|
4668
|
+
next(new import_nodejs_utils24.BadRequestError(error.message));
|
|
4669
|
+
return;
|
|
4670
|
+
}
|
|
4671
|
+
const page = parseInt(req.query.page) ?? 1;
|
|
4672
|
+
let limit = parseInt(req.query.limit) ?? 20;
|
|
4673
|
+
limit = isNaN(limit) ? 20 : limit;
|
|
4674
|
+
const sort = req.query.sort ? String(req.query.sort).split(",") : "";
|
|
4675
|
+
const sortOrder = req.query.sortOrder ? String(req.query.sortOrder).split(",") : "";
|
|
4676
|
+
const sortObj = {};
|
|
4677
|
+
if (sort && Array.isArray(sort) && sort.length && sortOrder && Array.isArray(sortOrder) && sortOrder.length) {
|
|
4678
|
+
sort.forEach((field, index) => {
|
|
4679
|
+
sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
|
|
4680
|
+
});
|
|
4681
|
+
}
|
|
4682
|
+
const app = req.query.app ?? "";
|
|
4683
|
+
const search = req.query.search ?? "";
|
|
4684
|
+
const status = req.query.status ?? "active";
|
|
4685
|
+
try {
|
|
4686
|
+
const buildings = await _getAll({
|
|
4687
|
+
page,
|
|
4688
|
+
limit,
|
|
4689
|
+
sort: sortObj,
|
|
4690
|
+
app,
|
|
4691
|
+
search,
|
|
4692
|
+
status
|
|
4693
|
+
});
|
|
4694
|
+
res.json(buildings);
|
|
4695
|
+
return;
|
|
4696
|
+
} catch (error2) {
|
|
4697
|
+
next(error2);
|
|
4698
|
+
}
|
|
4699
|
+
}
|
|
4700
|
+
async function getById(req, res, next) {
|
|
4701
|
+
const id = req.params.id;
|
|
4702
|
+
const validation = import_joi11.default.object({
|
|
4703
|
+
id: import_joi11.default.string().hex().required()
|
|
4704
|
+
});
|
|
4705
|
+
const { error } = validation.validate({ id });
|
|
4706
|
+
if (error) {
|
|
4707
|
+
next(new import_nodejs_utils24.BadRequestError(error.message));
|
|
4708
|
+
return;
|
|
4709
|
+
}
|
|
4710
|
+
try {
|
|
4711
|
+
const data = await _getById(id);
|
|
4712
|
+
res.json({
|
|
4713
|
+
message: "Successfully retrieved permission.",
|
|
4714
|
+
data
|
|
4715
|
+
});
|
|
4716
|
+
return;
|
|
4717
|
+
} catch (error2) {
|
|
4718
|
+
next(error2);
|
|
4719
|
+
}
|
|
4720
|
+
}
|
|
4721
|
+
async function deleteById(req, res, next) {
|
|
4722
|
+
const id = req.params.id;
|
|
4723
|
+
const validation = import_joi11.default.object({
|
|
4724
|
+
id: import_joi11.default.string().hex().required()
|
|
4725
|
+
});
|
|
4726
|
+
const { error } = validation.validate({ id });
|
|
4727
|
+
if (error) {
|
|
4728
|
+
next(new import_nodejs_utils24.BadRequestError(error.message));
|
|
4729
|
+
return;
|
|
4730
|
+
}
|
|
4731
|
+
try {
|
|
4732
|
+
const message = await _deleteById(id);
|
|
4733
|
+
res.json(message);
|
|
4734
|
+
return;
|
|
4735
|
+
} catch (error2) {
|
|
4736
|
+
next(error2);
|
|
4737
|
+
}
|
|
4738
|
+
}
|
|
4739
|
+
async function updateById(req, res, next) {
|
|
4740
|
+
const id = req.params.id;
|
|
4741
|
+
const { error: errorId } = import_joi11.default.string().hex().required().validate(id);
|
|
4742
|
+
if (errorId) {
|
|
4743
|
+
next(new import_nodejs_utils24.BadRequestError(errorId.message));
|
|
4744
|
+
return;
|
|
4745
|
+
}
|
|
4746
|
+
const payload = req.body;
|
|
4747
|
+
const { error } = schemaPermissionUpdate.validate(payload);
|
|
4748
|
+
if (error) {
|
|
4749
|
+
next(new import_nodejs_utils24.BadRequestError(error.message));
|
|
4750
|
+
return;
|
|
4751
|
+
}
|
|
4752
|
+
try {
|
|
4753
|
+
const message = await _updateById(id, payload);
|
|
4754
|
+
res.json(message);
|
|
4755
|
+
return;
|
|
4756
|
+
} catch (error2) {
|
|
4757
|
+
next(error2);
|
|
4758
|
+
}
|
|
4759
|
+
}
|
|
4760
|
+
return {
|
|
4761
|
+
add,
|
|
4762
|
+
getAll,
|
|
4763
|
+
getById,
|
|
4764
|
+
deleteById,
|
|
4765
|
+
updateById
|
|
4766
|
+
};
|
|
4767
|
+
}
|
|
4768
|
+
|
|
4769
|
+
// src/resources/permission/permission.group.model.ts
|
|
4770
|
+
var import_nodejs_utils25 = require("@eeplatform/nodejs-utils");
|
|
4771
|
+
var import_joi12 = __toESM(require("joi"));
|
|
4772
|
+
var schemaPermissionGroup = import_joi12.default.object({
|
|
4773
|
+
app: import_joi12.default.string().required(),
|
|
4774
|
+
key: import_joi12.default.string().required(),
|
|
4775
|
+
label: import_joi12.default.string().required(),
|
|
4776
|
+
order: import_joi12.default.number().integer().optional().allow("", null)
|
|
4777
|
+
});
|
|
4778
|
+
var schemaPermissionGroupUpdate = import_joi12.default.object({
|
|
4779
|
+
key: import_joi12.default.string().optional().allow("", null),
|
|
4780
|
+
label: import_joi12.default.string().optional().allow("", null),
|
|
4781
|
+
order: import_joi12.default.number().integer().optional().allow("", null)
|
|
4782
|
+
});
|
|
4783
|
+
function modelPermissionGroup(value) {
|
|
4784
|
+
const { error } = schemaPermissionGroup.validate(value);
|
|
4785
|
+
if (error) {
|
|
4786
|
+
throw new import_nodejs_utils25.BadRequestError(error.message);
|
|
4787
|
+
}
|
|
4788
|
+
return {
|
|
4789
|
+
_id: value._id,
|
|
4790
|
+
app: value.app,
|
|
4791
|
+
key: value.key,
|
|
4792
|
+
label: value.label,
|
|
4793
|
+
order: value.order ?? Date.now(),
|
|
4794
|
+
status: value.status ?? "active",
|
|
4795
|
+
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
4796
|
+
updatedAt: "",
|
|
4797
|
+
deletedAt: ""
|
|
4798
|
+
};
|
|
4799
|
+
}
|
|
4800
|
+
|
|
4801
|
+
// src/resources/permission/permission.group.repository.ts
|
|
4802
|
+
var import_nodejs_utils26 = require("@eeplatform/nodejs-utils");
|
|
4803
|
+
var import_mongodb16 = require("mongodb");
|
|
4804
|
+
var import_joi13 = __toESM(require("joi"));
|
|
4805
|
+
function usePermissionGroupRepo() {
|
|
4806
|
+
const namespace_collection = "permission.groups";
|
|
4807
|
+
const repo = (0, import_nodejs_utils26.useRepo)(namespace_collection);
|
|
4808
|
+
async function createIndexes() {
|
|
4809
|
+
try {
|
|
4810
|
+
await repo.collection.createIndexes([
|
|
4811
|
+
{ key: { app: 1 } },
|
|
4812
|
+
{ key: { key: 1 } },
|
|
4813
|
+
{ key: { label: 1 } },
|
|
4814
|
+
{
|
|
4815
|
+
key: { app: "text", key: "text", label: "text" },
|
|
4816
|
+
name: "text_index"
|
|
4817
|
+
},
|
|
4818
|
+
{
|
|
4819
|
+
key: { app: 1, key: 1, label: 1 },
|
|
4820
|
+
unique: true,
|
|
4821
|
+
name: "unique_permission_group"
|
|
4822
|
+
}
|
|
4823
|
+
]);
|
|
4824
|
+
} catch (error) {
|
|
4825
|
+
throw new Error("Failed to create index on permission groups.");
|
|
4826
|
+
}
|
|
4827
|
+
}
|
|
4828
|
+
async function add(value, session) {
|
|
4829
|
+
try {
|
|
4830
|
+
value = modelPermissionGroup(value);
|
|
4831
|
+
const res = await repo.collection.insertOne(value, { session });
|
|
4832
|
+
repo.delCachedData();
|
|
4833
|
+
return res.insertedId;
|
|
4834
|
+
} catch (error) {
|
|
4835
|
+
import_nodejs_utils26.logger.log({
|
|
4836
|
+
level: "error",
|
|
4837
|
+
message: error.message
|
|
4838
|
+
});
|
|
4839
|
+
if (error instanceof import_nodejs_utils26.AppError) {
|
|
4840
|
+
throw error;
|
|
4841
|
+
} else {
|
|
4842
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
4843
|
+
if (isDuplicated) {
|
|
4844
|
+
throw new import_nodejs_utils26.BadRequestError("Permission group already exists.");
|
|
4845
|
+
}
|
|
4846
|
+
throw new Error("Failed to create permission group.");
|
|
4847
|
+
}
|
|
4848
|
+
}
|
|
4849
|
+
}
|
|
4850
|
+
async function updateById(_id, value, session) {
|
|
4851
|
+
try {
|
|
4852
|
+
_id = new import_mongodb16.ObjectId(_id);
|
|
4853
|
+
} catch (error2) {
|
|
4854
|
+
throw new import_nodejs_utils26.BadRequestError("Invalid ID.");
|
|
4855
|
+
}
|
|
4856
|
+
const { error } = schemaPermissionGroupUpdate.validate(value);
|
|
4857
|
+
if (error) {
|
|
4858
|
+
throw new import_nodejs_utils26.BadRequestError(`Invalid data: ${error.message}`);
|
|
4859
|
+
}
|
|
4860
|
+
try {
|
|
4861
|
+
const res = await repo.collection.updateOne(
|
|
4862
|
+
{ _id },
|
|
4863
|
+
{ $set: value },
|
|
4864
|
+
{ session }
|
|
4865
|
+
);
|
|
4866
|
+
repo.delCachedData();
|
|
4867
|
+
return res;
|
|
4868
|
+
} catch (error2) {
|
|
4869
|
+
import_nodejs_utils26.logger.log({
|
|
4870
|
+
level: "error",
|
|
4871
|
+
message: error2.message
|
|
4872
|
+
});
|
|
4873
|
+
if (error2 instanceof import_nodejs_utils26.AppError) {
|
|
4874
|
+
throw error2;
|
|
4875
|
+
} else {
|
|
4876
|
+
throw new Error("Failed to update permission group.");
|
|
4877
|
+
}
|
|
4878
|
+
}
|
|
4879
|
+
}
|
|
4880
|
+
async function getAll({
|
|
4881
|
+
search = "",
|
|
4882
|
+
page = 1,
|
|
4883
|
+
limit = 10,
|
|
4884
|
+
sort = {},
|
|
4885
|
+
app = "",
|
|
4886
|
+
status = "active"
|
|
4887
|
+
} = {}) {
|
|
4888
|
+
page = page > 0 ? page - 1 : 0;
|
|
4889
|
+
const query = {};
|
|
4890
|
+
const cacheParams = {
|
|
4891
|
+
page,
|
|
4892
|
+
limit,
|
|
4893
|
+
sort: JSON.stringify(sort)
|
|
4894
|
+
};
|
|
4895
|
+
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
4896
|
+
query.status = status;
|
|
4897
|
+
cacheParams.status = status;
|
|
4898
|
+
if (search) {
|
|
4899
|
+
query.$text = { $search: search };
|
|
4900
|
+
cacheParams.search = search;
|
|
4901
|
+
}
|
|
4902
|
+
if (app) {
|
|
4903
|
+
query.app = app;
|
|
4904
|
+
cacheParams.app = app;
|
|
4905
|
+
}
|
|
4906
|
+
const cacheKey = (0, import_nodejs_utils26.makeCacheKey)(namespace_collection, cacheParams);
|
|
4907
|
+
import_nodejs_utils26.logger.log({
|
|
4908
|
+
level: "info",
|
|
4909
|
+
message: `Cache key for getAll permission groups: ${cacheKey}`
|
|
4910
|
+
});
|
|
4911
|
+
try {
|
|
4912
|
+
const cached = await repo.getCache(cacheKey);
|
|
4913
|
+
if (cached) {
|
|
4914
|
+
import_nodejs_utils26.logger.log({
|
|
4915
|
+
level: "info",
|
|
4916
|
+
message: `Cache hit for getAll permission groups: ${cacheKey}`
|
|
4917
|
+
});
|
|
4918
|
+
return cached;
|
|
4919
|
+
}
|
|
4920
|
+
const items = await repo.collection.aggregate([
|
|
4921
|
+
{ $match: query },
|
|
4922
|
+
{ $sort: sort },
|
|
4923
|
+
{ $skip: page * limit },
|
|
4924
|
+
{ $limit: limit }
|
|
4925
|
+
]).toArray();
|
|
4926
|
+
const length = await repo.collection.countDocuments(query);
|
|
4927
|
+
const data = (0, import_nodejs_utils26.paginate)(items, page, limit, length);
|
|
4928
|
+
repo.setCache(cacheKey, data, 600).then(() => {
|
|
4929
|
+
import_nodejs_utils26.logger.log({
|
|
4930
|
+
level: "info",
|
|
4931
|
+
message: `Cache set for getAll permission groups: ${cacheKey}`
|
|
4932
|
+
});
|
|
4933
|
+
}).catch((err) => {
|
|
4934
|
+
import_nodejs_utils26.logger.log({
|
|
4935
|
+
level: "error",
|
|
4936
|
+
message: `Failed to set cache for getAll permission groups: ${err.message}`
|
|
4937
|
+
});
|
|
4938
|
+
});
|
|
4939
|
+
return data;
|
|
4940
|
+
} catch (error) {
|
|
4941
|
+
import_nodejs_utils26.logger.log({ level: "error", message: `${error}` });
|
|
4942
|
+
throw error;
|
|
4943
|
+
}
|
|
4944
|
+
}
|
|
4945
|
+
async function getById(_id) {
|
|
4946
|
+
try {
|
|
4947
|
+
_id = new import_mongodb16.ObjectId(_id);
|
|
4948
|
+
} catch (error) {
|
|
4949
|
+
throw new import_nodejs_utils26.BadRequestError("Invalid ID.");
|
|
4950
|
+
}
|
|
4951
|
+
const cacheKey = (0, import_nodejs_utils26.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
4952
|
+
try {
|
|
4953
|
+
const cached = await repo.getCache(cacheKey);
|
|
4954
|
+
if (cached) {
|
|
4955
|
+
import_nodejs_utils26.logger.log({
|
|
4956
|
+
level: "info",
|
|
4957
|
+
message: `Cache hit for getById permission group: ${cacheKey}`
|
|
4958
|
+
});
|
|
4959
|
+
return cached;
|
|
4960
|
+
}
|
|
4961
|
+
const result = await repo.collection.findOne({
|
|
4962
|
+
_id
|
|
4963
|
+
});
|
|
4964
|
+
repo.setCache(cacheKey, result, 300).then(() => {
|
|
4965
|
+
import_nodejs_utils26.logger.log({
|
|
4966
|
+
level: "info",
|
|
4967
|
+
message: `Cache set for permission group by id: ${cacheKey}`
|
|
4968
|
+
});
|
|
4969
|
+
}).catch((err) => {
|
|
4970
|
+
import_nodejs_utils26.logger.log({
|
|
4971
|
+
level: "error",
|
|
4972
|
+
message: `Failed to set cache for permission group by id: ${err.message}`
|
|
4973
|
+
});
|
|
4974
|
+
});
|
|
4975
|
+
return result;
|
|
4976
|
+
} catch (error) {
|
|
4977
|
+
if (error instanceof import_nodejs_utils26.AppError) {
|
|
4978
|
+
throw error;
|
|
4979
|
+
} else {
|
|
4980
|
+
throw new import_nodejs_utils26.InternalServerError("Failed to get permission group.");
|
|
4981
|
+
}
|
|
4982
|
+
}
|
|
4983
|
+
}
|
|
4984
|
+
async function getByKey(key, app) {
|
|
4985
|
+
const validation = import_joi13.default.object({
|
|
4986
|
+
key: import_joi13.default.string().required(),
|
|
4987
|
+
app: import_joi13.default.string().optional().allow(null, "")
|
|
4988
|
+
});
|
|
4989
|
+
const { error } = validation.validate({ key, app });
|
|
4990
|
+
if (error) {
|
|
4991
|
+
throw new import_nodejs_utils26.BadRequestError("Invalid key.");
|
|
4992
|
+
}
|
|
4993
|
+
const query = { key };
|
|
4994
|
+
const cacheKeyOptions = { key, tag: "byKey" };
|
|
4995
|
+
if (app) {
|
|
4996
|
+
query.app = app;
|
|
4997
|
+
cacheKeyOptions.app = app;
|
|
4998
|
+
}
|
|
4999
|
+
const cacheKey = (0, import_nodejs_utils26.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
5000
|
+
try {
|
|
5001
|
+
const cached = await repo.getCache(cacheKey);
|
|
5002
|
+
if (cached) {
|
|
5003
|
+
import_nodejs_utils26.logger.log({
|
|
5004
|
+
level: "info",
|
|
5005
|
+
message: `Cache hit for getById permission group: ${cacheKey}`
|
|
5006
|
+
});
|
|
5007
|
+
return cached;
|
|
5008
|
+
}
|
|
5009
|
+
const result = await repo.collection.findOne(query);
|
|
5010
|
+
repo.setCache(cacheKey, result, 300).then(() => {
|
|
5011
|
+
import_nodejs_utils26.logger.log({
|
|
5012
|
+
level: "info",
|
|
5013
|
+
message: `Cache set for permission group by key: ${cacheKey}`
|
|
5014
|
+
});
|
|
5015
|
+
}).catch((err) => {
|
|
5016
|
+
import_nodejs_utils26.logger.log({
|
|
5017
|
+
level: "error",
|
|
5018
|
+
message: `Failed to set cache for permission group by key: ${err.message}`
|
|
5019
|
+
});
|
|
5020
|
+
});
|
|
5021
|
+
return result;
|
|
5022
|
+
} catch (error2) {
|
|
5023
|
+
if (error2 instanceof import_nodejs_utils26.AppError) {
|
|
5024
|
+
throw error2;
|
|
5025
|
+
} else {
|
|
5026
|
+
throw new import_nodejs_utils26.InternalServerError("Failed to get permission group.");
|
|
5027
|
+
}
|
|
5028
|
+
}
|
|
5029
|
+
}
|
|
5030
|
+
async function deleteById(_id, session) {
|
|
5031
|
+
try {
|
|
5032
|
+
_id = new import_mongodb16.ObjectId(_id);
|
|
5033
|
+
} catch (error) {
|
|
5034
|
+
throw new import_nodejs_utils26.BadRequestError("Invalid ID.");
|
|
5035
|
+
}
|
|
5036
|
+
try {
|
|
5037
|
+
const res = await repo.collection.updateOne(
|
|
5038
|
+
{ _id },
|
|
5039
|
+
{ $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } }
|
|
5040
|
+
);
|
|
5041
|
+
repo.delCachedData();
|
|
5042
|
+
return res;
|
|
5043
|
+
} catch (error) {
|
|
5044
|
+
import_nodejs_utils26.logger.log({
|
|
5045
|
+
level: "error",
|
|
5046
|
+
message: error.message
|
|
5047
|
+
});
|
|
5048
|
+
if (error instanceof import_nodejs_utils26.AppError) {
|
|
5049
|
+
throw error;
|
|
5050
|
+
} else {
|
|
5051
|
+
throw new import_nodejs_utils26.InternalServerError("Failed to delete permission group.");
|
|
5052
|
+
}
|
|
5053
|
+
}
|
|
5054
|
+
}
|
|
5055
|
+
return {
|
|
5056
|
+
createIndexes,
|
|
5057
|
+
add,
|
|
5058
|
+
getAll,
|
|
5059
|
+
getById,
|
|
5060
|
+
getByKey,
|
|
5061
|
+
updateById,
|
|
5062
|
+
deleteById
|
|
5063
|
+
};
|
|
5064
|
+
}
|
|
5065
|
+
|
|
5066
|
+
// src/resources/permission/permission.group.service.ts
|
|
5067
|
+
var import_nodejs_utils27 = require("@eeplatform/nodejs-utils");
|
|
5068
|
+
function usePermissionGroupService() {
|
|
5069
|
+
const {
|
|
5070
|
+
updateById: _updateById,
|
|
5071
|
+
getById: _getById,
|
|
5072
|
+
deleteById: _deleteById,
|
|
5073
|
+
getByKey: _getByKey,
|
|
5074
|
+
add: _add
|
|
5075
|
+
} = usePermissionGroupRepo();
|
|
5076
|
+
const { getAll: getAllApps } = useAppRepo();
|
|
5077
|
+
const {
|
|
5078
|
+
countByGroup,
|
|
5079
|
+
getByKey: getPermissionByKey,
|
|
5080
|
+
add: addPermission
|
|
5081
|
+
} = usePermissionRepo();
|
|
5082
|
+
async function addDefaultModule() {
|
|
5083
|
+
const session = import_nodejs_utils27.useAtlas.getClient()?.startSession();
|
|
5084
|
+
if (!session) {
|
|
5085
|
+
throw new Error("Failed to start database session.");
|
|
5086
|
+
}
|
|
5087
|
+
try {
|
|
5088
|
+
session?.startTransaction();
|
|
5089
|
+
const apps = await getAllApps({
|
|
5090
|
+
limit: 20,
|
|
5091
|
+
type: ["default", "standard"]
|
|
5092
|
+
});
|
|
5093
|
+
if (apps && apps.items && apps.items.length) {
|
|
5094
|
+
const modules = [
|
|
5095
|
+
{
|
|
5096
|
+
key: "members",
|
|
5097
|
+
label: "Members",
|
|
5098
|
+
permissions: [
|
|
5099
|
+
{
|
|
5100
|
+
key: "members.view",
|
|
5101
|
+
name: "View Members",
|
|
5102
|
+
description: "Allow user to view members"
|
|
5103
|
+
},
|
|
5104
|
+
{
|
|
5105
|
+
key: "members.view.details",
|
|
5106
|
+
name: "View Member Details",
|
|
5107
|
+
description: "Allow user to view member details"
|
|
5108
|
+
},
|
|
5109
|
+
{
|
|
5110
|
+
key: "members.add",
|
|
5111
|
+
name: "Add Members",
|
|
5112
|
+
description: "Allow user to add new members"
|
|
5113
|
+
},
|
|
5114
|
+
{
|
|
5115
|
+
key: "members.edit.details",
|
|
5116
|
+
name: "Edit Member Details",
|
|
5117
|
+
description: "Allow user to edit member details"
|
|
5118
|
+
},
|
|
5119
|
+
{
|
|
5120
|
+
key: "members.delete",
|
|
5121
|
+
name: "Delete Members",
|
|
5122
|
+
description: "Allow user to delete members"
|
|
5123
|
+
}
|
|
5124
|
+
]
|
|
5125
|
+
},
|
|
5126
|
+
{
|
|
5127
|
+
key: "roles",
|
|
5128
|
+
label: "Roles",
|
|
5129
|
+
permissions: [
|
|
5130
|
+
{
|
|
5131
|
+
key: "roles.view",
|
|
5132
|
+
name: "View Roles",
|
|
5133
|
+
description: "Allow user to view roles"
|
|
5134
|
+
},
|
|
5135
|
+
{
|
|
5136
|
+
key: "roles.view.details",
|
|
5137
|
+
name: "View Role Details",
|
|
5138
|
+
description: "Allow user to view role details"
|
|
5139
|
+
},
|
|
5140
|
+
{
|
|
5141
|
+
key: "roles.add",
|
|
5142
|
+
name: "Add Roles",
|
|
5143
|
+
description: "Allow user to add new roles"
|
|
5144
|
+
},
|
|
5145
|
+
{
|
|
5146
|
+
key: "roles.edit.details",
|
|
5147
|
+
name: "Edit Role Details",
|
|
5148
|
+
description: "Allow user to edit role details"
|
|
5149
|
+
},
|
|
5150
|
+
{
|
|
5151
|
+
key: "roles.delete",
|
|
5152
|
+
name: "Delete Roles",
|
|
5153
|
+
description: "Allow user to delete roles"
|
|
5154
|
+
}
|
|
5155
|
+
]
|
|
5156
|
+
},
|
|
5157
|
+
{
|
|
5158
|
+
key: "invitations",
|
|
5159
|
+
label: "Invitations",
|
|
5160
|
+
permissions: [
|
|
5161
|
+
{
|
|
5162
|
+
key: "invitations.view",
|
|
5163
|
+
name: "View Invitations",
|
|
5164
|
+
description: "Allow user to view invitations"
|
|
5165
|
+
},
|
|
5166
|
+
{
|
|
5167
|
+
key: "invitations.view.details",
|
|
5168
|
+
name: "View Invitation Details",
|
|
5169
|
+
description: "Allow user to view invitation details"
|
|
5170
|
+
},
|
|
5171
|
+
{
|
|
5172
|
+
key: "invitations.send",
|
|
5173
|
+
name: "Send Invitations",
|
|
5174
|
+
description: "Allow user to send invitations"
|
|
5175
|
+
},
|
|
5176
|
+
{
|
|
5177
|
+
key: "invitations.revoke",
|
|
5178
|
+
name: "Revoke Invitations",
|
|
5179
|
+
description: "Allow user to revoke invitations"
|
|
5180
|
+
}
|
|
5181
|
+
]
|
|
5182
|
+
}
|
|
5183
|
+
];
|
|
5184
|
+
for (const app of apps.items) {
|
|
5185
|
+
for (const module2 of modules) {
|
|
5186
|
+
const existingGroup = await _getByKey(module2.key, app.code);
|
|
5187
|
+
if (!existingGroup) {
|
|
5188
|
+
await _add({
|
|
5189
|
+
app: app.code,
|
|
5190
|
+
key: module2.key,
|
|
5191
|
+
label: module2.label
|
|
5192
|
+
});
|
|
5193
|
+
import_nodejs_utils27.logger.log({
|
|
5194
|
+
level: "info",
|
|
5195
|
+
message: `Default permission group added: ${app.code} - ${module2.key}`
|
|
5196
|
+
});
|
|
5197
|
+
}
|
|
5198
|
+
for (const permission of module2.permissions) {
|
|
5199
|
+
const existingPermission = await getPermissionByKey(
|
|
5200
|
+
permission.key,
|
|
5201
|
+
module2.key,
|
|
5202
|
+
app.code
|
|
5203
|
+
);
|
|
5204
|
+
if (!existingPermission) {
|
|
5205
|
+
await addPermission({
|
|
5206
|
+
app: app.code,
|
|
5207
|
+
group: module2.key,
|
|
5208
|
+
key: permission.key,
|
|
5209
|
+
name: permission.name,
|
|
5210
|
+
description: permission.description
|
|
5211
|
+
});
|
|
5212
|
+
}
|
|
5213
|
+
}
|
|
5214
|
+
}
|
|
5215
|
+
if (app.code === "admin") {
|
|
5216
|
+
const modules2 = [
|
|
5217
|
+
{
|
|
5218
|
+
key: "applications",
|
|
5219
|
+
label: "Applications",
|
|
5220
|
+
permissions: [
|
|
5221
|
+
{
|
|
5222
|
+
key: "applications.add",
|
|
5223
|
+
name: "Add Applications",
|
|
5224
|
+
description: "Allow user to add new applications"
|
|
5225
|
+
},
|
|
5226
|
+
{
|
|
5227
|
+
key: "applications.view",
|
|
5228
|
+
name: "View Applications",
|
|
5229
|
+
description: "Allow user to view applications"
|
|
5230
|
+
},
|
|
5231
|
+
{
|
|
5232
|
+
key: "applications.view.details",
|
|
5233
|
+
name: "View Application Details",
|
|
5234
|
+
description: "Allow user to view application details"
|
|
5235
|
+
},
|
|
5236
|
+
{
|
|
5237
|
+
key: "applications.edit",
|
|
5238
|
+
name: "Edit Applications",
|
|
5239
|
+
description: "Allow user to edit existing applications"
|
|
5240
|
+
},
|
|
5241
|
+
{
|
|
5242
|
+
key: "applications.update.details",
|
|
5243
|
+
name: "Update Application Details",
|
|
5244
|
+
description: "Allow user to update application details"
|
|
5245
|
+
},
|
|
5246
|
+
{
|
|
5247
|
+
key: "applications.delete",
|
|
5248
|
+
name: "Delete Applications",
|
|
5249
|
+
description: "Allow user to delete applications"
|
|
5250
|
+
}
|
|
5251
|
+
]
|
|
5252
|
+
},
|
|
5253
|
+
{
|
|
5254
|
+
key: "deped-ro",
|
|
5255
|
+
label: "Regional Offices",
|
|
5256
|
+
permissions: [
|
|
5257
|
+
{
|
|
5258
|
+
key: "deped-ro.add",
|
|
5259
|
+
name: "Add Regional Office",
|
|
5260
|
+
description: "Allow user to add new regional office"
|
|
5261
|
+
},
|
|
5262
|
+
{
|
|
5263
|
+
key: "deped-ro.view",
|
|
5264
|
+
name: "View Regional Offices",
|
|
5265
|
+
description: "Allow user to view regional offices"
|
|
5266
|
+
},
|
|
5267
|
+
{
|
|
5268
|
+
key: "deped-ro.view.details",
|
|
5269
|
+
name: "View Regional Office Details",
|
|
5270
|
+
description: "Allow user to view regional office details"
|
|
5271
|
+
},
|
|
5272
|
+
{
|
|
5273
|
+
key: "deped-ro.update.details",
|
|
5274
|
+
name: "Update Regional Office Details",
|
|
5275
|
+
description: "Allow user to update regional office details"
|
|
5276
|
+
},
|
|
5277
|
+
{
|
|
5278
|
+
key: "deped-ro.delete",
|
|
5279
|
+
name: "Delete Regional Office",
|
|
5280
|
+
description: "Allow user to delete regional office"
|
|
5281
|
+
}
|
|
5282
|
+
]
|
|
5283
|
+
},
|
|
5284
|
+
{
|
|
5285
|
+
key: "deped-sdo",
|
|
5286
|
+
label: "School Division Offices",
|
|
5287
|
+
permissions: [
|
|
5288
|
+
{
|
|
5289
|
+
key: "deped-sdo.add",
|
|
5290
|
+
name: "Add School Division Office",
|
|
5291
|
+
description: "Allow user to add new school division office"
|
|
5292
|
+
},
|
|
5293
|
+
{
|
|
5294
|
+
key: "deped-sdo.view",
|
|
5295
|
+
name: "View School Division Offices",
|
|
5296
|
+
description: "Allow user to view school division offices"
|
|
5297
|
+
},
|
|
5298
|
+
{
|
|
5299
|
+
key: "deped-sdo.view.details",
|
|
5300
|
+
name: "View School Division Office Details",
|
|
5301
|
+
description: "Allow user to view school division office details"
|
|
5302
|
+
},
|
|
5303
|
+
{
|
|
5304
|
+
key: "deped-sdo.update.details",
|
|
5305
|
+
name: "Update School Division Office Details",
|
|
5306
|
+
description: "Allow user to update school division office details"
|
|
5307
|
+
},
|
|
5308
|
+
{
|
|
5309
|
+
key: "deped-sdo.delete",
|
|
5310
|
+
name: "Delete School Division Office",
|
|
5311
|
+
description: "Allow user to delete school division office"
|
|
5312
|
+
}
|
|
5313
|
+
]
|
|
5314
|
+
},
|
|
5315
|
+
{
|
|
5316
|
+
key: "deped-school",
|
|
5317
|
+
label: "Schools",
|
|
5318
|
+
permissions: [
|
|
5319
|
+
{
|
|
5320
|
+
key: "deped-school.add",
|
|
5321
|
+
name: "Add School",
|
|
5322
|
+
description: "Allow user to add new school"
|
|
5323
|
+
},
|
|
5324
|
+
{
|
|
5325
|
+
key: "deped-school.view",
|
|
5326
|
+
name: "View Schools",
|
|
5327
|
+
description: "Allow user to view schools"
|
|
5328
|
+
},
|
|
5329
|
+
{
|
|
5330
|
+
key: "deped-school.view.details",
|
|
5331
|
+
name: "View School Details",
|
|
5332
|
+
description: "Allow user to view school details"
|
|
5333
|
+
},
|
|
5334
|
+
{
|
|
5335
|
+
key: "deped-school.update.details",
|
|
5336
|
+
name: "Update School Details",
|
|
5337
|
+
description: "Allow user to update school details"
|
|
5338
|
+
},
|
|
5339
|
+
{
|
|
5340
|
+
key: "deped-school.delete",
|
|
5341
|
+
name: "Delete School",
|
|
5342
|
+
description: "Allow user to delete school"
|
|
5343
|
+
}
|
|
5344
|
+
]
|
|
5345
|
+
},
|
|
5346
|
+
{
|
|
5347
|
+
key: "users",
|
|
5348
|
+
label: "Users",
|
|
5349
|
+
permissions: [
|
|
5350
|
+
{
|
|
5351
|
+
key: "users.add",
|
|
5352
|
+
name: "Add Users",
|
|
5353
|
+
description: "Allow user to add new users"
|
|
5354
|
+
},
|
|
5355
|
+
{
|
|
5356
|
+
key: "users.view",
|
|
5357
|
+
name: "View Users",
|
|
5358
|
+
description: "Allow user to view users"
|
|
5359
|
+
},
|
|
5360
|
+
{
|
|
5361
|
+
key: "users.view.details",
|
|
5362
|
+
name: "View User Details",
|
|
5363
|
+
description: "Allow user to view user details"
|
|
5364
|
+
},
|
|
5365
|
+
{
|
|
5366
|
+
key: "users.edit.status",
|
|
5367
|
+
name: "Edit User Status",
|
|
5368
|
+
description: "Allow user to edit user status"
|
|
5369
|
+
},
|
|
5370
|
+
{
|
|
5371
|
+
key: "users.delete",
|
|
5372
|
+
name: "Delete Users",
|
|
5373
|
+
description: "Allow user to delete users"
|
|
5374
|
+
}
|
|
5375
|
+
]
|
|
5376
|
+
}
|
|
5377
|
+
];
|
|
5378
|
+
for (const module2 of modules2) {
|
|
5379
|
+
const existingGroup = await _getByKey(module2.key, app.code);
|
|
5380
|
+
if (!existingGroup) {
|
|
5381
|
+
await _add({
|
|
5382
|
+
app: app.code,
|
|
5383
|
+
key: module2.key,
|
|
5384
|
+
label: module2.label
|
|
5385
|
+
});
|
|
5386
|
+
import_nodejs_utils27.logger.log({
|
|
5387
|
+
level: "info",
|
|
5388
|
+
message: `Default permission group added: ${app.code} - ${module2.key}`
|
|
5389
|
+
});
|
|
5390
|
+
}
|
|
5391
|
+
for (const permission of module2.permissions) {
|
|
5392
|
+
const existingPermission = await getPermissionByKey(
|
|
5393
|
+
permission.key,
|
|
5394
|
+
module2.key
|
|
5395
|
+
);
|
|
5396
|
+
if (!existingPermission) {
|
|
5397
|
+
await addPermission({
|
|
5398
|
+
app: app.code,
|
|
5399
|
+
group: module2.key,
|
|
5400
|
+
key: permission.key,
|
|
5401
|
+
name: permission.name,
|
|
5402
|
+
description: permission.description
|
|
5403
|
+
});
|
|
5404
|
+
}
|
|
5405
|
+
}
|
|
5406
|
+
}
|
|
5407
|
+
}
|
|
5408
|
+
}
|
|
5409
|
+
await session.commitTransaction();
|
|
5410
|
+
}
|
|
5411
|
+
import_nodejs_utils27.logger.log({
|
|
5412
|
+
level: "info",
|
|
5413
|
+
message: "Default permission groups added successfully."
|
|
5414
|
+
});
|
|
5415
|
+
return;
|
|
5416
|
+
} catch (error) {
|
|
5417
|
+
console.log(error);
|
|
5418
|
+
await session.abortTransaction();
|
|
5419
|
+
throw error;
|
|
5420
|
+
} finally {
|
|
5421
|
+
await session.endSession();
|
|
5422
|
+
}
|
|
5423
|
+
}
|
|
5424
|
+
async function deleteById(id) {
|
|
5425
|
+
const permission = await _getById(id);
|
|
5426
|
+
if (!permission) {
|
|
5427
|
+
throw new Error("Permission Group not found.");
|
|
5428
|
+
}
|
|
5429
|
+
const associatedPermissionsCount = await countByGroup(permission.key);
|
|
5430
|
+
if (associatedPermissionsCount > 0) {
|
|
5431
|
+
throw new import_nodejs_utils27.BadRequestError(
|
|
5432
|
+
"Cannot delete Permission Group with associated Permissions."
|
|
5433
|
+
);
|
|
5434
|
+
}
|
|
5435
|
+
try {
|
|
5436
|
+
await _deleteById(id);
|
|
5437
|
+
return "Permission deleted successfully.";
|
|
5438
|
+
} catch (error) {
|
|
5439
|
+
if (error instanceof import_nodejs_utils27.AppError) {
|
|
5440
|
+
throw error;
|
|
5441
|
+
} else {
|
|
5442
|
+
throw new import_nodejs_utils27.InternalServerError("Failed to delete Permission Group.");
|
|
5443
|
+
}
|
|
5444
|
+
}
|
|
5445
|
+
}
|
|
5446
|
+
return {
|
|
5447
|
+
addDefaultModule,
|
|
5448
|
+
deleteById
|
|
5449
|
+
};
|
|
5450
|
+
}
|
|
5451
|
+
|
|
5452
|
+
// src/resources/permission/permission.group.controller.ts
|
|
5453
|
+
var import_nodejs_utils28 = require("@eeplatform/nodejs-utils");
|
|
5454
|
+
var import_joi14 = __toESM(require("joi"));
|
|
5455
|
+
function usePermissionGroupController() {
|
|
5456
|
+
const {
|
|
5457
|
+
getAll: _getAll,
|
|
5458
|
+
getById: _getById,
|
|
5459
|
+
add: _add,
|
|
5460
|
+
updateById: _updateById
|
|
5461
|
+
} = usePermissionGroupRepo();
|
|
5462
|
+
const { deleteById: _deleteById } = usePermissionGroupService();
|
|
5463
|
+
async function add(req, res, next) {
|
|
5464
|
+
const value = req.body;
|
|
5465
|
+
const { error } = schemaPermissionGroup.validate(value);
|
|
5466
|
+
if (error) {
|
|
5467
|
+
next(new import_nodejs_utils28.BadRequestError(error.message));
|
|
5468
|
+
import_nodejs_utils28.logger.info(`Controller: ${error.message}`);
|
|
5469
|
+
return;
|
|
5470
|
+
}
|
|
5471
|
+
try {
|
|
5472
|
+
const result = await _add(value);
|
|
5473
|
+
res.json(result);
|
|
5474
|
+
return;
|
|
5475
|
+
} catch (error2) {
|
|
5476
|
+
next(error2);
|
|
5477
|
+
}
|
|
5478
|
+
}
|
|
5479
|
+
async function getAll(req, res, next) {
|
|
5480
|
+
const query = req.query;
|
|
5481
|
+
const validation = import_joi14.default.object({
|
|
5482
|
+
page: import_joi14.default.number().min(1).optional().allow("", null),
|
|
5483
|
+
limit: import_joi14.default.number().min(1).optional().allow("", null),
|
|
5484
|
+
search: import_joi14.default.string().optional().allow("", null),
|
|
5485
|
+
app: import_joi14.default.string().optional().allow("", null),
|
|
5486
|
+
status: import_joi14.default.string().optional().allow("", null)
|
|
5487
|
+
});
|
|
5488
|
+
const { error } = validation.validate(query);
|
|
5489
|
+
if (error) {
|
|
5490
|
+
next(new import_nodejs_utils28.BadRequestError(error.message));
|
|
5491
|
+
return;
|
|
5492
|
+
}
|
|
5493
|
+
const page = parseInt(req.query.page) ?? 1;
|
|
5494
|
+
let limit = parseInt(req.query.limit) ?? 20;
|
|
5495
|
+
limit = isNaN(limit) ? 20 : limit;
|
|
5496
|
+
const sort = req.query.sort ? String(req.query.sort).split(",") : "";
|
|
5497
|
+
const sortOrder = req.query.sortOrder ? String(req.query.sortOrder).split(",") : "";
|
|
5498
|
+
const sortObj = {};
|
|
5499
|
+
if (sort && Array.isArray(sort) && sort.length && sortOrder && Array.isArray(sortOrder) && sortOrder.length) {
|
|
5500
|
+
sort.forEach((field, index) => {
|
|
5501
|
+
sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
|
|
5502
|
+
});
|
|
5503
|
+
}
|
|
5504
|
+
const app = req.query.app ?? "";
|
|
5505
|
+
const search = req.query.search ?? "";
|
|
5506
|
+
const status = req.query.status ?? "active";
|
|
5507
|
+
try {
|
|
5508
|
+
const buildings = await _getAll({
|
|
5509
|
+
page,
|
|
5510
|
+
limit,
|
|
5511
|
+
sort: sortObj,
|
|
5512
|
+
app,
|
|
5513
|
+
search,
|
|
5514
|
+
status
|
|
5515
|
+
});
|
|
5516
|
+
res.json(buildings);
|
|
5517
|
+
return;
|
|
5518
|
+
} catch (error2) {
|
|
5519
|
+
next(error2);
|
|
5520
|
+
}
|
|
5521
|
+
}
|
|
5522
|
+
async function getById(req, res, next) {
|
|
5523
|
+
const id = req.params.id;
|
|
5524
|
+
const validation = import_joi14.default.object({
|
|
5525
|
+
id: import_joi14.default.string().hex().required()
|
|
5526
|
+
});
|
|
5527
|
+
const { error } = validation.validate({ id });
|
|
5528
|
+
if (error) {
|
|
5529
|
+
next(new import_nodejs_utils28.BadRequestError(error.message));
|
|
5530
|
+
return;
|
|
5531
|
+
}
|
|
5532
|
+
try {
|
|
5533
|
+
const data = await _getById(id);
|
|
5534
|
+
res.json({
|
|
5535
|
+
message: "Successfully retrieved permission group.",
|
|
5536
|
+
data
|
|
5537
|
+
});
|
|
5538
|
+
return;
|
|
5539
|
+
} catch (error2) {
|
|
5540
|
+
next(error2);
|
|
5541
|
+
}
|
|
5542
|
+
}
|
|
5543
|
+
async function deleteById(req, res, next) {
|
|
5544
|
+
const id = req.params.id;
|
|
5545
|
+
const validation = import_joi14.default.object({
|
|
5546
|
+
id: import_joi14.default.string().hex().required()
|
|
5547
|
+
});
|
|
5548
|
+
const { error } = validation.validate({ id });
|
|
5549
|
+
if (error) {
|
|
5550
|
+
next(new import_nodejs_utils28.BadRequestError(error.message));
|
|
5551
|
+
return;
|
|
5552
|
+
}
|
|
5553
|
+
try {
|
|
5554
|
+
const message = await _deleteById(id);
|
|
5555
|
+
res.json(message);
|
|
5556
|
+
return;
|
|
5557
|
+
} catch (error2) {
|
|
5558
|
+
next(error2);
|
|
5559
|
+
}
|
|
5560
|
+
}
|
|
5561
|
+
async function updateById(req, res, next) {
|
|
5562
|
+
const id = req.params.id;
|
|
5563
|
+
const { error: errorId } = import_joi14.default.string().hex().required().validate(id);
|
|
5564
|
+
if (errorId) {
|
|
5565
|
+
next(new import_nodejs_utils28.BadRequestError(errorId.message));
|
|
5566
|
+
return;
|
|
5567
|
+
}
|
|
5568
|
+
const payload = req.body;
|
|
5569
|
+
const { error } = schemaPermissionGroupUpdate.validate(payload);
|
|
5570
|
+
if (error) {
|
|
5571
|
+
next(new import_nodejs_utils28.BadRequestError(error.message));
|
|
5572
|
+
return;
|
|
5573
|
+
}
|
|
5574
|
+
try {
|
|
5575
|
+
const message = await _updateById(id, payload);
|
|
5576
|
+
res.json(message);
|
|
5577
|
+
return;
|
|
5578
|
+
} catch (error2) {
|
|
5579
|
+
next(error2);
|
|
5580
|
+
}
|
|
5581
|
+
}
|
|
5582
|
+
return {
|
|
5583
|
+
add,
|
|
5584
|
+
getAll,
|
|
5585
|
+
getById,
|
|
5586
|
+
deleteById,
|
|
5587
|
+
updateById
|
|
5588
|
+
};
|
|
5589
|
+
}
|
|
5590
|
+
|
|
5591
|
+
// src/resources/file/file.service.ts
|
|
5592
|
+
var import_nodejs_utils29 = require("@eeplatform/nodejs-utils");
|
|
5593
|
+
var import_node_cron = __toESM(require("node-cron"));
|
|
5594
|
+
var fs = __toESM(require("fs"));
|
|
5595
|
+
function useFileService() {
|
|
5596
|
+
const {
|
|
5597
|
+
createFile: _createFile,
|
|
5598
|
+
deleteFileById,
|
|
5599
|
+
getAllDraftedFiles
|
|
5600
|
+
} = useFileRepo();
|
|
5601
|
+
const s3 = new import_nodejs_utils29.useS3({
|
|
5602
|
+
accessKeyId: SPACES_ACCESS_KEY,
|
|
5603
|
+
secretAccessKey: SPACES_SECRET_KEY,
|
|
5604
|
+
endpoint: SPACES_ENDPOINT,
|
|
5605
|
+
region: SPACES_REGION,
|
|
5606
|
+
bucket: SPACES_BUCKET,
|
|
5607
|
+
forcePathStyle: true
|
|
5608
|
+
});
|
|
5609
|
+
async function createFile(value) {
|
|
5610
|
+
const session = import_nodejs_utils29.useAtlas.getClient()?.startSession();
|
|
5611
|
+
session?.startTransaction();
|
|
5612
|
+
const file = {
|
|
5613
|
+
name: value.originalname,
|
|
5614
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5615
|
+
};
|
|
5616
|
+
try {
|
|
5617
|
+
const id = await _createFile(file, session);
|
|
5618
|
+
const fileBuffer = value.buffer || await fs.promises.readFile(value.path);
|
|
5619
|
+
await s3.uploadObject({
|
|
5620
|
+
key: id,
|
|
5621
|
+
body: fileBuffer,
|
|
5622
|
+
contentType: value.mimetype
|
|
5623
|
+
});
|
|
5624
|
+
await session?.commitTransaction();
|
|
5625
|
+
if (value.path) {
|
|
5626
|
+
try {
|
|
5627
|
+
await fs.promises.unlink(value.path);
|
|
5628
|
+
} catch (cleanupError) {
|
|
5629
|
+
console.error(
|
|
5630
|
+
`Failed to cleanup temporary file ${value.path}:`,
|
|
5631
|
+
cleanupError
|
|
5632
|
+
);
|
|
5633
|
+
}
|
|
5634
|
+
}
|
|
5635
|
+
return id;
|
|
5636
|
+
} catch (error) {
|
|
5637
|
+
await session?.abortTransaction();
|
|
5638
|
+
throw error;
|
|
5639
|
+
} finally {
|
|
5640
|
+
session?.endSession();
|
|
5641
|
+
}
|
|
5642
|
+
}
|
|
5643
|
+
async function deleteFile(id) {
|
|
5644
|
+
const session = import_nodejs_utils29.useAtlas.getClient()?.startSession();
|
|
5645
|
+
session?.startTransaction();
|
|
5646
|
+
try {
|
|
5647
|
+
await deleteFileById(id, session);
|
|
5648
|
+
await s3.deleteObject(id);
|
|
5649
|
+
await session?.commitTransaction();
|
|
5650
|
+
return "File deleted successfully";
|
|
5651
|
+
} catch (error) {
|
|
5652
|
+
await session?.abortTransaction();
|
|
5653
|
+
throw error;
|
|
5654
|
+
} finally {
|
|
5655
|
+
session?.endSession();
|
|
5656
|
+
}
|
|
5657
|
+
}
|
|
5658
|
+
function deleteDraft() {
|
|
5659
|
+
import_node_cron.default.schedule("0 0 * * *", async () => {
|
|
5660
|
+
const files = await getAllDraftedFiles();
|
|
5661
|
+
for (let index = 0; index < files.length; index++) {
|
|
5662
|
+
const file = files[index];
|
|
5663
|
+
try {
|
|
5664
|
+
await deleteFile(file._id.toString());
|
|
5665
|
+
await import_nodejs_utils29.logger.log({
|
|
5666
|
+
level: "info",
|
|
5667
|
+
message: "Successfully deleted draft files."
|
|
5668
|
+
});
|
|
5669
|
+
} catch (error) {
|
|
5670
|
+
import_nodejs_utils29.logger.log({
|
|
5671
|
+
level: "info",
|
|
5672
|
+
message: "Successfully deleted draft files."
|
|
5673
|
+
});
|
|
5674
|
+
return;
|
|
5675
|
+
}
|
|
5676
|
+
}
|
|
5677
|
+
});
|
|
5678
|
+
}
|
|
5679
|
+
return {
|
|
5680
|
+
createFile,
|
|
5681
|
+
deleteFile,
|
|
5682
|
+
deleteDraft
|
|
5683
|
+
};
|
|
5684
|
+
}
|
|
5685
|
+
|
|
5686
|
+
// src/resources/file/file.controller.ts
|
|
5687
|
+
var import_nodejs_utils30 = require("@eeplatform/nodejs-utils");
|
|
5688
|
+
var import_joi15 = __toESM(require("joi"));
|
|
5689
|
+
function useFileController() {
|
|
5690
|
+
const { createFile, deleteFile: _deleteFile } = useFileService();
|
|
5691
|
+
async function upload(req, res, next) {
|
|
5692
|
+
if (!req.file) {
|
|
5693
|
+
res.status(400).send("File is required!");
|
|
5694
|
+
return;
|
|
5695
|
+
}
|
|
5696
|
+
try {
|
|
5697
|
+
const id = await createFile(req.file);
|
|
5698
|
+
res.json({ message: "Successfully uploaded file", id });
|
|
5699
|
+
return;
|
|
5700
|
+
} catch (error) {
|
|
5701
|
+
if (error instanceof import_nodejs_utils30.AppError) {
|
|
5702
|
+
next(error);
|
|
5703
|
+
} else {
|
|
5704
|
+
next(new import_nodejs_utils30.InternalServerError(error));
|
|
5705
|
+
}
|
|
5706
|
+
}
|
|
5707
|
+
}
|
|
5708
|
+
async function deleteFile(req, res, next) {
|
|
5709
|
+
const id = req.params.id;
|
|
5710
|
+
const validation = import_joi15.default.string().required();
|
|
5711
|
+
const { error } = validation.validate(id);
|
|
5712
|
+
if (error) {
|
|
5713
|
+
next(new import_nodejs_utils30.BadRequestError(error.message));
|
|
5714
|
+
}
|
|
5715
|
+
try {
|
|
5716
|
+
const message = await _deleteFile(id);
|
|
5717
|
+
res.json({ message });
|
|
5718
|
+
return;
|
|
5719
|
+
} catch (error2) {
|
|
5720
|
+
if (error2 instanceof import_nodejs_utils30.AppError) {
|
|
5721
|
+
next(error2);
|
|
5722
|
+
} else {
|
|
5723
|
+
next(new import_nodejs_utils30.InternalServerError(error2));
|
|
5724
|
+
}
|
|
5725
|
+
}
|
|
5726
|
+
}
|
|
5727
|
+
return {
|
|
5728
|
+
upload,
|
|
5729
|
+
deleteFile
|
|
5730
|
+
};
|
|
5731
|
+
}
|
|
5732
|
+
|
|
5733
|
+
// src/resources/role/role.controller.ts
|
|
5734
|
+
var import_joi18 = __toESM(require("joi"));
|
|
5735
|
+
var import_nodejs_utils33 = require("@eeplatform/nodejs-utils");
|
|
5736
|
+
|
|
5737
|
+
// src/resources/role/role.service.ts
|
|
5738
|
+
var import_nodejs_utils32 = require("@eeplatform/nodejs-utils");
|
|
5739
|
+
var import_joi17 = __toESM(require("joi"));
|
|
5740
|
+
|
|
5741
|
+
// src/resources/member/member.controller.ts
|
|
5742
|
+
var import_joi16 = __toESM(require("joi"));
|
|
5743
|
+
var import_nodejs_utils31 = require("@eeplatform/nodejs-utils");
|
|
5744
|
+
function useMemberController() {
|
|
5745
|
+
const {
|
|
5746
|
+
getByUserId: _getByUserId,
|
|
5747
|
+
getAll: _getAll,
|
|
5748
|
+
getOrgsByMembership: _getOrgsByMembership,
|
|
5749
|
+
updateStatusByUserId: _updateStatusByUserId,
|
|
5750
|
+
getByUserType: _getByUserType
|
|
5751
|
+
} = useMemberRepo();
|
|
5752
|
+
async function getByUserId(req, res, next) {
|
|
5753
|
+
const userId = req.params.id;
|
|
5754
|
+
const validation = import_joi16.default.object({
|
|
5755
|
+
id: import_joi16.default.string().hex().required()
|
|
5756
|
+
});
|
|
5757
|
+
const { error } = validation.validate({ id: userId });
|
|
5758
|
+
if (error) {
|
|
5759
|
+
next(new import_nodejs_utils31.BadRequestError(error.message));
|
|
5760
|
+
return;
|
|
5761
|
+
}
|
|
5762
|
+
try {
|
|
5763
|
+
const member = await _getByUserId(userId);
|
|
5764
|
+
if (!member) {
|
|
5765
|
+
res.status(404).json({ message: "Member not found." });
|
|
5766
|
+
return;
|
|
5767
|
+
}
|
|
5768
|
+
res.json(member);
|
|
5769
|
+
} catch (error2) {
|
|
5770
|
+
next(error2);
|
|
5771
|
+
}
|
|
5772
|
+
}
|
|
5773
|
+
async function getByUserType(req, res, next) {
|
|
5774
|
+
const validation = import_joi16.default.object({
|
|
5775
|
+
org: import_joi16.default.string().hex().optional().allow("", null),
|
|
5776
|
+
user: import_joi16.default.string().hex().required(),
|
|
5777
|
+
type: import_joi16.default.string().required()
|
|
5778
|
+
});
|
|
5779
|
+
const { error } = validation.validate({ ...req.params, ...req.query });
|
|
5780
|
+
if (error) {
|
|
5781
|
+
next(new import_nodejs_utils31.BadRequestError(error.message));
|
|
5782
|
+
return;
|
|
5783
|
+
}
|
|
5784
|
+
const orgId = req.query.org;
|
|
5785
|
+
const userId = req.params.user;
|
|
5786
|
+
const type = req.params.type;
|
|
5787
|
+
try {
|
|
5788
|
+
const member = await _getByUserType(userId, type, orgId);
|
|
5789
|
+
if (!member) {
|
|
5790
|
+
res.status(404).json({ message: "Member not found." });
|
|
5791
|
+
return;
|
|
5792
|
+
}
|
|
5793
|
+
res.json(member);
|
|
5794
|
+
} catch (error2) {
|
|
5795
|
+
next(error2);
|
|
5796
|
+
}
|
|
5797
|
+
}
|
|
5798
|
+
async function getAll(req, res, next) {
|
|
5799
|
+
const limit = Number(req.query.limit) ?? 10;
|
|
5800
|
+
const search = req.query.search ?? "";
|
|
5801
|
+
const page = Number(req.query.page) ?? 1;
|
|
5802
|
+
const user = req.query.user ?? "";
|
|
5803
|
+
const org = req.query.org ?? "";
|
|
5804
|
+
const type = req.query.type ?? "main";
|
|
5805
|
+
const status = req.query.status ?? "active";
|
|
5806
|
+
const validation = import_joi16.default.object({
|
|
5807
|
+
limit: import_joi16.default.number().min(10).max(300).required(),
|
|
5808
|
+
search: import_joi16.default.string().optional().allow("", null),
|
|
5809
|
+
page: import_joi16.default.number().required(),
|
|
5810
|
+
user: import_joi16.default.string().hex().optional().allow("", null),
|
|
5811
|
+
org: import_joi16.default.string().hex().optional().allow("", null),
|
|
5812
|
+
type: import_joi16.default.string().required(),
|
|
5813
|
+
status: import_joi16.default.string().required()
|
|
5814
|
+
});
|
|
5815
|
+
const { error } = validation.validate({
|
|
5816
|
+
search,
|
|
5817
|
+
page,
|
|
5818
|
+
user,
|
|
5819
|
+
org,
|
|
5820
|
+
type,
|
|
5821
|
+
limit,
|
|
5822
|
+
status
|
|
5823
|
+
});
|
|
5824
|
+
if (error) {
|
|
5825
|
+
next(new import_nodejs_utils31.BadRequestError(error.message));
|
|
5826
|
+
return;
|
|
5827
|
+
}
|
|
5828
|
+
try {
|
|
5829
|
+
const items = await _getAll({
|
|
5830
|
+
search,
|
|
5831
|
+
page,
|
|
5832
|
+
user,
|
|
5833
|
+
org,
|
|
5834
|
+
type,
|
|
5835
|
+
limit,
|
|
5836
|
+
status
|
|
5837
|
+
});
|
|
5838
|
+
res.json(items);
|
|
5839
|
+
return;
|
|
5840
|
+
} catch (error2) {
|
|
5841
|
+
next(error2);
|
|
5842
|
+
}
|
|
5843
|
+
}
|
|
5844
|
+
async function getOrgsByMembership(req, res, next) {
|
|
5845
|
+
const limit = Number(req.query.limit) ?? 10;
|
|
5846
|
+
const search = req.query.search ?? "";
|
|
5847
|
+
const page = Number(req.query.page) ?? 1;
|
|
5848
|
+
const user = req.query.user ?? "";
|
|
5849
|
+
const validation = import_joi16.default.object({
|
|
5850
|
+
limit: import_joi16.default.number().min(10).max(50).required(),
|
|
5851
|
+
search: import_joi16.default.string().optional().allow("", null),
|
|
5852
|
+
page: import_joi16.default.number().required(),
|
|
5853
|
+
user: import_joi16.default.string().hex().optional().allow("", null)
|
|
5854
|
+
});
|
|
5855
|
+
const { error } = validation.validate({
|
|
5856
|
+
search,
|
|
5857
|
+
page,
|
|
5858
|
+
user,
|
|
5859
|
+
limit
|
|
5860
|
+
});
|
|
5861
|
+
if (error) {
|
|
5862
|
+
next(new import_nodejs_utils31.BadRequestError(error.message));
|
|
3870
5863
|
}
|
|
3871
5864
|
try {
|
|
3872
5865
|
const items = await _getOrgsByMembership({
|
|
@@ -3882,13 +5875,13 @@ function useMemberController() {
|
|
|
3882
5875
|
}
|
|
3883
5876
|
}
|
|
3884
5877
|
async function updateStatusByUserId(req, res, next) {
|
|
3885
|
-
const validation =
|
|
3886
|
-
id:
|
|
3887
|
-
status:
|
|
5878
|
+
const validation = import_joi16.default.object({
|
|
5879
|
+
id: import_joi16.default.string().hex().required(),
|
|
5880
|
+
status: import_joi16.default.string().valid("active", "suspended", "deleted").required()
|
|
3888
5881
|
});
|
|
3889
5882
|
const { error } = validation.validate(req.params);
|
|
3890
5883
|
if (error) {
|
|
3891
|
-
next(new
|
|
5884
|
+
next(new import_nodejs_utils31.BadRequestError(error.message));
|
|
3892
5885
|
return;
|
|
3893
5886
|
}
|
|
3894
5887
|
const id = req.params.id;
|
|
@@ -3914,26 +5907,26 @@ function useRoleService() {
|
|
|
3914
5907
|
const { getByOrg } = useMemberRepo();
|
|
3915
5908
|
const { deleteRole, getRoleById } = useRoleRepo();
|
|
3916
5909
|
async function deleteById(_id) {
|
|
3917
|
-
const { error } =
|
|
5910
|
+
const { error } = import_joi17.default.string().hex().length(24).validate(_id);
|
|
3918
5911
|
if (error) {
|
|
3919
|
-
throw new
|
|
5912
|
+
throw new import_nodejs_utils32.BadRequestError("Invalid Role ID");
|
|
3920
5913
|
}
|
|
3921
5914
|
try {
|
|
3922
5915
|
const role = await getRoleById(_id);
|
|
3923
5916
|
if (!role) {
|
|
3924
|
-
throw new
|
|
5917
|
+
throw new import_nodejs_utils32.BadRequestError("Role not found");
|
|
3925
5918
|
}
|
|
3926
5919
|
const org = await getByOrg(String(role.id));
|
|
3927
5920
|
if (org) {
|
|
3928
|
-
throw new
|
|
5921
|
+
throw new import_nodejs_utils32.BadRequestError("Cannot delete role assigned to members");
|
|
3929
5922
|
}
|
|
3930
5923
|
await deleteRole(_id);
|
|
3931
5924
|
return "Role deleted successfully";
|
|
3932
5925
|
} catch (error2) {
|
|
3933
|
-
if (error2 instanceof
|
|
5926
|
+
if (error2 instanceof import_nodejs_utils32.AppError) {
|
|
3934
5927
|
throw error2;
|
|
3935
5928
|
}
|
|
3936
|
-
throw new
|
|
5929
|
+
throw new import_nodejs_utils32.InternalServerError("Failed to delete role");
|
|
3937
5930
|
}
|
|
3938
5931
|
}
|
|
3939
5932
|
return {
|
|
@@ -3953,15 +5946,15 @@ function useRoleController() {
|
|
|
3953
5946
|
} = useRoleRepo();
|
|
3954
5947
|
async function createRole(req, res, next) {
|
|
3955
5948
|
const payload = req.body;
|
|
3956
|
-
const validation =
|
|
3957
|
-
name:
|
|
3958
|
-
permissions:
|
|
3959
|
-
type:
|
|
3960
|
-
id:
|
|
5949
|
+
const validation = import_joi18.default.object({
|
|
5950
|
+
name: import_joi18.default.string().required(),
|
|
5951
|
+
permissions: import_joi18.default.array().items(import_joi18.default.string()).required(),
|
|
5952
|
+
type: import_joi18.default.string().valid("school", "division", "region", "account").required(),
|
|
5953
|
+
id: import_joi18.default.string().hex().optional().allow("", null)
|
|
3961
5954
|
});
|
|
3962
5955
|
const { error } = validation.validate(payload);
|
|
3963
5956
|
if (error) {
|
|
3964
|
-
next(new
|
|
5957
|
+
next(new import_nodejs_utils33.BadRequestError(error.message));
|
|
3965
5958
|
return;
|
|
3966
5959
|
}
|
|
3967
5960
|
try {
|
|
@@ -3978,16 +5971,16 @@ function useRoleController() {
|
|
|
3978
5971
|
const limit = parseInt(req.query.limit ?? "10");
|
|
3979
5972
|
const type = req.query.type ?? "";
|
|
3980
5973
|
const id = req.query.id ?? "";
|
|
3981
|
-
const validation =
|
|
3982
|
-
search:
|
|
3983
|
-
page:
|
|
3984
|
-
limit:
|
|
3985
|
-
type:
|
|
3986
|
-
id:
|
|
5974
|
+
const validation = import_joi18.default.object({
|
|
5975
|
+
search: import_joi18.default.string().optional().allow("", null),
|
|
5976
|
+
page: import_joi18.default.number().required(),
|
|
5977
|
+
limit: import_joi18.default.number().required(),
|
|
5978
|
+
type: import_joi18.default.string().optional().allow("", null),
|
|
5979
|
+
id: import_joi18.default.string().hex().optional().allow("", null)
|
|
3987
5980
|
});
|
|
3988
5981
|
const { error } = validation.validate({ search, page, limit, type, id });
|
|
3989
5982
|
if (error) {
|
|
3990
|
-
next(new
|
|
5983
|
+
next(new import_nodejs_utils33.BadRequestError(error.message));
|
|
3991
5984
|
return;
|
|
3992
5985
|
}
|
|
3993
5986
|
try {
|
|
@@ -4000,12 +5993,12 @@ function useRoleController() {
|
|
|
4000
5993
|
}
|
|
4001
5994
|
async function getRoleByUserId(req, res, next) {
|
|
4002
5995
|
const userId = req.params.userId;
|
|
4003
|
-
const validation =
|
|
4004
|
-
userId:
|
|
5996
|
+
const validation = import_joi18.default.object({
|
|
5997
|
+
userId: import_joi18.default.string().required()
|
|
4005
5998
|
});
|
|
4006
5999
|
const { error } = validation.validate({ userId });
|
|
4007
6000
|
if (error) {
|
|
4008
|
-
next(new
|
|
6001
|
+
next(new import_nodejs_utils33.BadRequestError(error.message));
|
|
4009
6002
|
return;
|
|
4010
6003
|
}
|
|
4011
6004
|
try {
|
|
@@ -4018,12 +6011,12 @@ function useRoleController() {
|
|
|
4018
6011
|
}
|
|
4019
6012
|
async function getRoleById(req, res, next) {
|
|
4020
6013
|
const _id = req.params.id;
|
|
4021
|
-
const validation =
|
|
4022
|
-
_id:
|
|
6014
|
+
const validation = import_joi18.default.object({
|
|
6015
|
+
_id: import_joi18.default.string().hex().required()
|
|
4023
6016
|
});
|
|
4024
6017
|
const { error } = validation.validate({ _id });
|
|
4025
6018
|
if (error) {
|
|
4026
|
-
next(new
|
|
6019
|
+
next(new import_nodejs_utils33.BadRequestError(error.message));
|
|
4027
6020
|
return;
|
|
4028
6021
|
}
|
|
4029
6022
|
try {
|
|
@@ -4038,14 +6031,14 @@ function useRoleController() {
|
|
|
4038
6031
|
const _id = req.params.id;
|
|
4039
6032
|
const name = req.body.name ?? "";
|
|
4040
6033
|
const permissions = req.body.permissions ?? [];
|
|
4041
|
-
const validation =
|
|
4042
|
-
_id:
|
|
4043
|
-
name:
|
|
4044
|
-
permissions:
|
|
6034
|
+
const validation = import_joi18.default.object({
|
|
6035
|
+
_id: import_joi18.default.string().required(),
|
|
6036
|
+
name: import_joi18.default.string().required(),
|
|
6037
|
+
permissions: import_joi18.default.array().items(import_joi18.default.string()).required()
|
|
4045
6038
|
});
|
|
4046
6039
|
const { error } = validation.validate({ _id, name, permissions });
|
|
4047
6040
|
if (error) {
|
|
4048
|
-
next(new
|
|
6041
|
+
next(new import_nodejs_utils33.BadRequestError(error.message));
|
|
4049
6042
|
return;
|
|
4050
6043
|
}
|
|
4051
6044
|
try {
|
|
@@ -4059,13 +6052,13 @@ function useRoleController() {
|
|
|
4059
6052
|
async function updatePermissionsById(req, res, next) {
|
|
4060
6053
|
const _id = req.params.id;
|
|
4061
6054
|
const permissions = req.body.permissions ?? [];
|
|
4062
|
-
const validation =
|
|
4063
|
-
_id:
|
|
4064
|
-
permissions:
|
|
6055
|
+
const validation = import_joi18.default.object({
|
|
6056
|
+
_id: import_joi18.default.string().required(),
|
|
6057
|
+
permissions: import_joi18.default.array().items(import_joi18.default.string()).required()
|
|
4065
6058
|
});
|
|
4066
6059
|
const { error } = validation.validate({ _id, permissions });
|
|
4067
6060
|
if (error) {
|
|
4068
|
-
next(new
|
|
6061
|
+
next(new import_nodejs_utils33.BadRequestError(error.message));
|
|
4069
6062
|
return;
|
|
4070
6063
|
}
|
|
4071
6064
|
try {
|
|
@@ -4079,12 +6072,12 @@ function useRoleController() {
|
|
|
4079
6072
|
const { deleteById } = useRoleService();
|
|
4080
6073
|
async function deleteRole(req, res, next) {
|
|
4081
6074
|
const _id = req.params.id;
|
|
4082
|
-
const validation =
|
|
4083
|
-
_id:
|
|
6075
|
+
const validation = import_joi18.default.object({
|
|
6076
|
+
_id: import_joi18.default.string().required()
|
|
4084
6077
|
});
|
|
4085
6078
|
const { error } = validation.validate({ _id });
|
|
4086
6079
|
if (error) {
|
|
4087
|
-
next(new
|
|
6080
|
+
next(new import_nodejs_utils33.BadRequestError(error.message));
|
|
4088
6081
|
return;
|
|
4089
6082
|
}
|
|
4090
6083
|
try {
|
|
@@ -4106,151 +6099,9 @@ function useRoleController() {
|
|
|
4106
6099
|
};
|
|
4107
6100
|
}
|
|
4108
6101
|
|
|
4109
|
-
// src/resources/file/file.service.ts
|
|
4110
|
-
var import_nodejs_utils21 = require("@eeplatform/nodejs-utils");
|
|
4111
|
-
var import_node_cron = __toESM(require("node-cron"));
|
|
4112
|
-
var fs = __toESM(require("fs"));
|
|
4113
|
-
function useFileService() {
|
|
4114
|
-
const {
|
|
4115
|
-
createFile: _createFile,
|
|
4116
|
-
deleteFileById,
|
|
4117
|
-
getAllDraftedFiles
|
|
4118
|
-
} = useFileRepo();
|
|
4119
|
-
const s3 = new import_nodejs_utils21.useS3({
|
|
4120
|
-
accessKeyId: SPACES_ACCESS_KEY,
|
|
4121
|
-
secretAccessKey: SPACES_SECRET_KEY,
|
|
4122
|
-
endpoint: SPACES_ENDPOINT,
|
|
4123
|
-
region: SPACES_REGION,
|
|
4124
|
-
bucket: SPACES_BUCKET,
|
|
4125
|
-
forcePathStyle: true
|
|
4126
|
-
});
|
|
4127
|
-
async function createFile(value) {
|
|
4128
|
-
const session = import_nodejs_utils21.useAtlas.getClient()?.startSession();
|
|
4129
|
-
session?.startTransaction();
|
|
4130
|
-
const file = {
|
|
4131
|
-
name: value.originalname,
|
|
4132
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4133
|
-
};
|
|
4134
|
-
try {
|
|
4135
|
-
const id = await _createFile(file, session);
|
|
4136
|
-
const fileBuffer = value.buffer || await fs.promises.readFile(value.path);
|
|
4137
|
-
await s3.uploadObject({
|
|
4138
|
-
key: id,
|
|
4139
|
-
body: fileBuffer,
|
|
4140
|
-
contentType: value.mimetype
|
|
4141
|
-
});
|
|
4142
|
-
await session?.commitTransaction();
|
|
4143
|
-
if (value.path) {
|
|
4144
|
-
try {
|
|
4145
|
-
await fs.promises.unlink(value.path);
|
|
4146
|
-
} catch (cleanupError) {
|
|
4147
|
-
console.error(
|
|
4148
|
-
`Failed to cleanup temporary file ${value.path}:`,
|
|
4149
|
-
cleanupError
|
|
4150
|
-
);
|
|
4151
|
-
}
|
|
4152
|
-
}
|
|
4153
|
-
return id;
|
|
4154
|
-
} catch (error) {
|
|
4155
|
-
await session?.abortTransaction();
|
|
4156
|
-
throw error;
|
|
4157
|
-
} finally {
|
|
4158
|
-
session?.endSession();
|
|
4159
|
-
}
|
|
4160
|
-
}
|
|
4161
|
-
async function deleteFile(id) {
|
|
4162
|
-
const session = import_nodejs_utils21.useAtlas.getClient()?.startSession();
|
|
4163
|
-
session?.startTransaction();
|
|
4164
|
-
try {
|
|
4165
|
-
await deleteFileById(id, session);
|
|
4166
|
-
await s3.deleteObject(id);
|
|
4167
|
-
await session?.commitTransaction();
|
|
4168
|
-
return "File deleted successfully";
|
|
4169
|
-
} catch (error) {
|
|
4170
|
-
await session?.abortTransaction();
|
|
4171
|
-
throw error;
|
|
4172
|
-
} finally {
|
|
4173
|
-
session?.endSession();
|
|
4174
|
-
}
|
|
4175
|
-
}
|
|
4176
|
-
function deleteDraft() {
|
|
4177
|
-
import_node_cron.default.schedule("0 0 * * *", async () => {
|
|
4178
|
-
const files = await getAllDraftedFiles();
|
|
4179
|
-
for (let index = 0; index < files.length; index++) {
|
|
4180
|
-
const file = files[index];
|
|
4181
|
-
try {
|
|
4182
|
-
await deleteFile(file._id.toString());
|
|
4183
|
-
await import_nodejs_utils21.logger.log({
|
|
4184
|
-
level: "info",
|
|
4185
|
-
message: "Successfully deleted draft files."
|
|
4186
|
-
});
|
|
4187
|
-
} catch (error) {
|
|
4188
|
-
import_nodejs_utils21.logger.log({
|
|
4189
|
-
level: "info",
|
|
4190
|
-
message: "Successfully deleted draft files."
|
|
4191
|
-
});
|
|
4192
|
-
return;
|
|
4193
|
-
}
|
|
4194
|
-
}
|
|
4195
|
-
});
|
|
4196
|
-
}
|
|
4197
|
-
return {
|
|
4198
|
-
createFile,
|
|
4199
|
-
deleteFile,
|
|
4200
|
-
deleteDraft
|
|
4201
|
-
};
|
|
4202
|
-
}
|
|
4203
|
-
|
|
4204
|
-
// src/resources/file/file.controller.ts
|
|
4205
|
-
var import_nodejs_utils22 = require("@eeplatform/nodejs-utils");
|
|
4206
|
-
var import_joi9 = __toESM(require("joi"));
|
|
4207
|
-
function useFileController() {
|
|
4208
|
-
const { createFile, deleteFile: _deleteFile } = useFileService();
|
|
4209
|
-
async function upload(req, res, next) {
|
|
4210
|
-
if (!req.file) {
|
|
4211
|
-
res.status(400).send("File is required!");
|
|
4212
|
-
return;
|
|
4213
|
-
}
|
|
4214
|
-
try {
|
|
4215
|
-
const id = await createFile(req.file);
|
|
4216
|
-
res.json({ message: "Successfully uploaded file", id });
|
|
4217
|
-
return;
|
|
4218
|
-
} catch (error) {
|
|
4219
|
-
if (error instanceof import_nodejs_utils22.AppError) {
|
|
4220
|
-
next(error);
|
|
4221
|
-
} else {
|
|
4222
|
-
next(new import_nodejs_utils22.InternalServerError(error));
|
|
4223
|
-
}
|
|
4224
|
-
}
|
|
4225
|
-
}
|
|
4226
|
-
async function deleteFile(req, res, next) {
|
|
4227
|
-
const id = req.params.id;
|
|
4228
|
-
const validation = import_joi9.default.string().required();
|
|
4229
|
-
const { error } = validation.validate(id);
|
|
4230
|
-
if (error) {
|
|
4231
|
-
next(new import_nodejs_utils22.BadRequestError(error.message));
|
|
4232
|
-
}
|
|
4233
|
-
try {
|
|
4234
|
-
const message = await _deleteFile(id);
|
|
4235
|
-
res.json({ message });
|
|
4236
|
-
return;
|
|
4237
|
-
} catch (error2) {
|
|
4238
|
-
if (error2 instanceof import_nodejs_utils22.AppError) {
|
|
4239
|
-
next(error2);
|
|
4240
|
-
} else {
|
|
4241
|
-
next(new import_nodejs_utils22.InternalServerError(error2));
|
|
4242
|
-
}
|
|
4243
|
-
}
|
|
4244
|
-
}
|
|
4245
|
-
return {
|
|
4246
|
-
upload,
|
|
4247
|
-
deleteFile
|
|
4248
|
-
};
|
|
4249
|
-
}
|
|
4250
|
-
|
|
4251
6102
|
// src/resources/verification/verification.controller.ts
|
|
4252
|
-
var
|
|
4253
|
-
var
|
|
6103
|
+
var import_nodejs_utils34 = require("@eeplatform/nodejs-utils");
|
|
6104
|
+
var import_joi19 = __toESM(require("joi"));
|
|
4254
6105
|
function useVerificationController() {
|
|
4255
6106
|
const {
|
|
4256
6107
|
createUserInvite: _createUserInvite,
|
|
@@ -4260,17 +6111,17 @@ function useVerificationController() {
|
|
|
4260
6111
|
} = useVerificationService();
|
|
4261
6112
|
const { getVerifications: _getVerifications } = useVerificationRepo();
|
|
4262
6113
|
async function createUserInvite(req, res, next) {
|
|
4263
|
-
const validation =
|
|
4264
|
-
email:
|
|
4265
|
-
app:
|
|
4266
|
-
role:
|
|
4267
|
-
roleName:
|
|
4268
|
-
org:
|
|
4269
|
-
orgName:
|
|
6114
|
+
const validation = import_joi19.default.object({
|
|
6115
|
+
email: import_joi19.default.string().email().required(),
|
|
6116
|
+
app: import_joi19.default.string().required(),
|
|
6117
|
+
role: import_joi19.default.string().hex().required(),
|
|
6118
|
+
roleName: import_joi19.default.string().required(),
|
|
6119
|
+
org: import_joi19.default.string().hex().optional().optional().allow("", null),
|
|
6120
|
+
orgName: import_joi19.default.string().optional().optional().allow("", null)
|
|
4270
6121
|
});
|
|
4271
6122
|
const { error } = validation.validate(req.body);
|
|
4272
6123
|
if (error) {
|
|
4273
|
-
next(new
|
|
6124
|
+
next(new import_nodejs_utils34.BadRequestError(error.message));
|
|
4274
6125
|
return;
|
|
4275
6126
|
}
|
|
4276
6127
|
const email = req.body.email ?? "";
|
|
@@ -4298,10 +6149,10 @@ function useVerificationController() {
|
|
|
4298
6149
|
}
|
|
4299
6150
|
async function createForgetPassword(req, res, next) {
|
|
4300
6151
|
const email = req.body.email || "";
|
|
4301
|
-
const validation =
|
|
6152
|
+
const validation = import_joi19.default.string().email().required();
|
|
4302
6153
|
const { error } = validation.validate(email);
|
|
4303
6154
|
if (error) {
|
|
4304
|
-
next(new
|
|
6155
|
+
next(new import_nodejs_utils34.BadRequestError(error.message));
|
|
4305
6156
|
return;
|
|
4306
6157
|
}
|
|
4307
6158
|
try {
|
|
@@ -4311,25 +6162,25 @@ function useVerificationController() {
|
|
|
4311
6162
|
});
|
|
4312
6163
|
return;
|
|
4313
6164
|
} catch (error2) {
|
|
4314
|
-
if (error2 instanceof
|
|
6165
|
+
if (error2 instanceof import_nodejs_utils34.AppError) {
|
|
4315
6166
|
next(error2);
|
|
4316
6167
|
} else {
|
|
4317
|
-
next(new
|
|
6168
|
+
next(new import_nodejs_utils34.InternalServerError("An unexpected error occurred"));
|
|
4318
6169
|
}
|
|
4319
6170
|
}
|
|
4320
6171
|
}
|
|
4321
6172
|
async function getVerifications(req, res, next) {
|
|
4322
|
-
const validation =
|
|
4323
|
-
status:
|
|
4324
|
-
search:
|
|
4325
|
-
page:
|
|
4326
|
-
type:
|
|
4327
|
-
email:
|
|
4328
|
-
app:
|
|
6173
|
+
const validation = import_joi19.default.object({
|
|
6174
|
+
status: import_joi19.default.string().required(),
|
|
6175
|
+
search: import_joi19.default.string().optional().allow("", null),
|
|
6176
|
+
page: import_joi19.default.number().required(),
|
|
6177
|
+
type: import_joi19.default.string().optional().allow("", null),
|
|
6178
|
+
email: import_joi19.default.string().optional().allow("", null),
|
|
6179
|
+
app: import_joi19.default.string().optional().allow("", null)
|
|
4329
6180
|
});
|
|
4330
6181
|
const { error } = validation.validate(req.query);
|
|
4331
6182
|
if (error) {
|
|
4332
|
-
next(new
|
|
6183
|
+
next(new import_nodejs_utils34.BadRequestError(error.message));
|
|
4333
6184
|
return;
|
|
4334
6185
|
}
|
|
4335
6186
|
const status = req.query.status ?? "";
|
|
@@ -4360,10 +6211,10 @@ function useVerificationController() {
|
|
|
4360
6211
|
}
|
|
4361
6212
|
async function verify(req, res, next) {
|
|
4362
6213
|
const id = req.params.id || "";
|
|
4363
|
-
const validation =
|
|
6214
|
+
const validation = import_joi19.default.string().hex().required();
|
|
4364
6215
|
const { error } = validation.validate(id);
|
|
4365
6216
|
if (error) {
|
|
4366
|
-
next(new
|
|
6217
|
+
next(new import_nodejs_utils34.BadRequestError(error.message));
|
|
4367
6218
|
return;
|
|
4368
6219
|
}
|
|
4369
6220
|
try {
|
|
@@ -4376,10 +6227,10 @@ function useVerificationController() {
|
|
|
4376
6227
|
}
|
|
4377
6228
|
async function cancelUserInvitation(req, res, next) {
|
|
4378
6229
|
const otpId = req.params.id || "";
|
|
4379
|
-
const validation =
|
|
6230
|
+
const validation = import_joi19.default.string().hex().required();
|
|
4380
6231
|
const { error } = validation.validate(otpId);
|
|
4381
6232
|
if (error) {
|
|
4382
|
-
next(new
|
|
6233
|
+
next(new import_nodejs_utils34.BadRequestError(error.message));
|
|
4383
6234
|
return;
|
|
4384
6235
|
}
|
|
4385
6236
|
try {
|
|
@@ -4401,34 +6252,34 @@ function useVerificationController() {
|
|
|
4401
6252
|
}
|
|
4402
6253
|
|
|
4403
6254
|
// src/resources/address/address.model.ts
|
|
4404
|
-
var
|
|
4405
|
-
var
|
|
4406
|
-
var
|
|
4407
|
-
var addressSchema =
|
|
4408
|
-
type:
|
|
4409
|
-
user:
|
|
4410
|
-
org:
|
|
4411
|
-
country:
|
|
4412
|
-
address:
|
|
4413
|
-
continuedAddress:
|
|
4414
|
-
city:
|
|
4415
|
-
province:
|
|
4416
|
-
postalCode:
|
|
4417
|
-
taxId:
|
|
6255
|
+
var import_nodejs_utils35 = require("@eeplatform/nodejs-utils");
|
|
6256
|
+
var import_joi20 = __toESM(require("joi"));
|
|
6257
|
+
var import_mongodb17 = require("mongodb");
|
|
6258
|
+
var addressSchema = import_joi20.default.object({
|
|
6259
|
+
type: import_joi20.default.string().required(),
|
|
6260
|
+
user: import_joi20.default.string().hex().optional().allow("", null),
|
|
6261
|
+
org: import_joi20.default.string().hex().optional().allow("", null),
|
|
6262
|
+
country: import_joi20.default.string().required(),
|
|
6263
|
+
address: import_joi20.default.string().required(),
|
|
6264
|
+
continuedAddress: import_joi20.default.string().optional().allow("", null),
|
|
6265
|
+
city: import_joi20.default.string().required(),
|
|
6266
|
+
province: import_joi20.default.string().required(),
|
|
6267
|
+
postalCode: import_joi20.default.string().required(),
|
|
6268
|
+
taxId: import_joi20.default.string().optional().allow("", null)
|
|
4418
6269
|
});
|
|
4419
6270
|
function MAddress(value) {
|
|
4420
6271
|
if (value.user) {
|
|
4421
6272
|
try {
|
|
4422
|
-
value.user = new
|
|
6273
|
+
value.user = new import_mongodb17.ObjectId(value.user);
|
|
4423
6274
|
} catch (error) {
|
|
4424
|
-
throw new
|
|
6275
|
+
throw new import_nodejs_utils35.BadRequestError("Invalid user ID.");
|
|
4425
6276
|
}
|
|
4426
6277
|
}
|
|
4427
6278
|
if (value.org) {
|
|
4428
6279
|
try {
|
|
4429
|
-
value.org = new
|
|
6280
|
+
value.org = new import_mongodb17.ObjectId(value.org);
|
|
4430
6281
|
} catch (error) {
|
|
4431
|
-
throw new
|
|
6282
|
+
throw new import_nodejs_utils35.BadRequestError("Invalid org ID.");
|
|
4432
6283
|
}
|
|
4433
6284
|
}
|
|
4434
6285
|
return {
|
|
@@ -4446,24 +6297,24 @@ function MAddress(value) {
|
|
|
4446
6297
|
}
|
|
4447
6298
|
|
|
4448
6299
|
// src/resources/address/address.repository.ts
|
|
4449
|
-
var
|
|
4450
|
-
var
|
|
6300
|
+
var import_nodejs_utils36 = require("@eeplatform/nodejs-utils");
|
|
6301
|
+
var import_mongodb18 = require("mongodb");
|
|
4451
6302
|
function useAddressRepo() {
|
|
4452
|
-
const db =
|
|
6303
|
+
const db = import_nodejs_utils36.useAtlas.getDb();
|
|
4453
6304
|
if (!db) {
|
|
4454
|
-
throw new
|
|
6305
|
+
throw new import_nodejs_utils36.BadRequestError("Unable to connect to server.");
|
|
4455
6306
|
}
|
|
4456
6307
|
const namespace_collection = "addresses";
|
|
4457
6308
|
const collection = db.collection(namespace_collection);
|
|
4458
|
-
const { getCache, setCache, delNamespace } = (0,
|
|
6309
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils36.useCache)(namespace_collection);
|
|
4459
6310
|
function delCachedData() {
|
|
4460
6311
|
delNamespace().then(() => {
|
|
4461
|
-
|
|
6312
|
+
import_nodejs_utils36.logger.log({
|
|
4462
6313
|
level: "info",
|
|
4463
6314
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
4464
6315
|
});
|
|
4465
6316
|
}).catch((err) => {
|
|
4466
|
-
|
|
6317
|
+
import_nodejs_utils36.logger.log({
|
|
4467
6318
|
level: "error",
|
|
4468
6319
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
4469
6320
|
});
|
|
@@ -4477,7 +6328,7 @@ function useAddressRepo() {
|
|
|
4477
6328
|
{ key: { orgId: 1 } }
|
|
4478
6329
|
]);
|
|
4479
6330
|
} catch (error) {
|
|
4480
|
-
throw new
|
|
6331
|
+
throw new import_nodejs_utils36.BadRequestError("Failed to create index on address.");
|
|
4481
6332
|
}
|
|
4482
6333
|
}
|
|
4483
6334
|
async function add(value, session) {
|
|
@@ -4487,20 +6338,20 @@ function useAddressRepo() {
|
|
|
4487
6338
|
delCachedData();
|
|
4488
6339
|
return res.insertedId;
|
|
4489
6340
|
} catch (error) {
|
|
4490
|
-
throw new
|
|
6341
|
+
throw new import_nodejs_utils36.BadRequestError("Failed to create address.");
|
|
4491
6342
|
}
|
|
4492
6343
|
}
|
|
4493
6344
|
async function updateById(_id, value, session) {
|
|
4494
6345
|
try {
|
|
4495
|
-
_id = new
|
|
6346
|
+
_id = new import_mongodb18.ObjectId(_id);
|
|
4496
6347
|
} catch (error) {
|
|
4497
|
-
throw new
|
|
6348
|
+
throw new import_nodejs_utils36.BadRequestError("Invalid address ID.");
|
|
4498
6349
|
}
|
|
4499
6350
|
if (value.org) {
|
|
4500
6351
|
try {
|
|
4501
|
-
value.org = new
|
|
6352
|
+
value.org = new import_mongodb18.ObjectId(value.org);
|
|
4502
6353
|
} catch (error) {
|
|
4503
|
-
throw new
|
|
6354
|
+
throw new import_nodejs_utils36.BadRequestError("Invalid org ID.");
|
|
4504
6355
|
}
|
|
4505
6356
|
}
|
|
4506
6357
|
try {
|
|
@@ -4512,20 +6363,20 @@ function useAddressRepo() {
|
|
|
4512
6363
|
delCachedData();
|
|
4513
6364
|
return "Successfully updated address.";
|
|
4514
6365
|
} catch (error) {
|
|
4515
|
-
throw new
|
|
6366
|
+
throw new import_nodejs_utils36.BadRequestError("Failed to update address.");
|
|
4516
6367
|
}
|
|
4517
6368
|
}
|
|
4518
6369
|
async function getByUserId(user) {
|
|
4519
6370
|
try {
|
|
4520
|
-
user = new
|
|
6371
|
+
user = new import_mongodb18.ObjectId(user);
|
|
4521
6372
|
} catch (error) {
|
|
4522
|
-
throw new
|
|
6373
|
+
throw new import_nodejs_utils36.BadRequestError("Invalid user ID.");
|
|
4523
6374
|
}
|
|
4524
|
-
const cacheKey = (0,
|
|
6375
|
+
const cacheKey = (0, import_nodejs_utils36.makeCacheKey)(namespace_collection, { user: String(user) });
|
|
4525
6376
|
try {
|
|
4526
6377
|
const cached = await getCache(cacheKey);
|
|
4527
6378
|
if (cached) {
|
|
4528
|
-
|
|
6379
|
+
import_nodejs_utils36.logger.log({
|
|
4529
6380
|
level: "info",
|
|
4530
6381
|
message: `Cache hit for getByUserId address: ${cacheKey}`
|
|
4531
6382
|
});
|
|
@@ -4534,12 +6385,12 @@ function useAddressRepo() {
|
|
|
4534
6385
|
const data = await collection.findOne({ user });
|
|
4535
6386
|
if (data) {
|
|
4536
6387
|
setCache(cacheKey, data, 300).then(() => {
|
|
4537
|
-
|
|
6388
|
+
import_nodejs_utils36.logger.log({
|
|
4538
6389
|
level: "info",
|
|
4539
6390
|
message: `Cache set for address by user ID: ${cacheKey}`
|
|
4540
6391
|
});
|
|
4541
6392
|
}).catch((err) => {
|
|
4542
|
-
|
|
6393
|
+
import_nodejs_utils36.logger.log({
|
|
4543
6394
|
level: "error",
|
|
4544
6395
|
message: `Failed to set cache for address by user ID: ${err.message}`
|
|
4545
6396
|
});
|
|
@@ -4547,20 +6398,20 @@ function useAddressRepo() {
|
|
|
4547
6398
|
}
|
|
4548
6399
|
return data;
|
|
4549
6400
|
} catch (error) {
|
|
4550
|
-
throw new
|
|
6401
|
+
throw new import_nodejs_utils36.BadRequestError("Failed to get address by ID.");
|
|
4551
6402
|
}
|
|
4552
6403
|
}
|
|
4553
6404
|
async function getByOrgId(org) {
|
|
4554
6405
|
try {
|
|
4555
|
-
org = new
|
|
6406
|
+
org = new import_mongodb18.ObjectId(org);
|
|
4556
6407
|
} catch (error) {
|
|
4557
|
-
throw new
|
|
6408
|
+
throw new import_nodejs_utils36.BadRequestError("Invalid orgId.");
|
|
4558
6409
|
}
|
|
4559
|
-
const cacheKey = (0,
|
|
6410
|
+
const cacheKey = (0, import_nodejs_utils36.makeCacheKey)(namespace_collection, { org: String(org) });
|
|
4560
6411
|
try {
|
|
4561
6412
|
const cached = await getCache(cacheKey);
|
|
4562
6413
|
if (cached) {
|
|
4563
|
-
|
|
6414
|
+
import_nodejs_utils36.logger.log({
|
|
4564
6415
|
level: "info",
|
|
4565
6416
|
message: `Cache hit for getByOrgId address: ${cacheKey}`
|
|
4566
6417
|
});
|
|
@@ -4569,12 +6420,12 @@ function useAddressRepo() {
|
|
|
4569
6420
|
const data = await collection.findOne({ org });
|
|
4570
6421
|
if (data) {
|
|
4571
6422
|
setCache(cacheKey, data, 300).then(() => {
|
|
4572
|
-
|
|
6423
|
+
import_nodejs_utils36.logger.log({
|
|
4573
6424
|
level: "info",
|
|
4574
6425
|
message: `Cache set for address by org ID: ${cacheKey}`
|
|
4575
6426
|
});
|
|
4576
6427
|
}).catch((err) => {
|
|
4577
|
-
|
|
6428
|
+
import_nodejs_utils36.logger.log({
|
|
4578
6429
|
level: "error",
|
|
4579
6430
|
message: `Failed to set cache for address by org ID: ${err.message}`
|
|
4580
6431
|
});
|
|
@@ -4582,7 +6433,7 @@ function useAddressRepo() {
|
|
|
4582
6433
|
}
|
|
4583
6434
|
return data;
|
|
4584
6435
|
} catch (error) {
|
|
4585
|
-
throw new
|
|
6436
|
+
throw new import_nodejs_utils36.BadRequestError("Failed to get address by orgId.");
|
|
4586
6437
|
}
|
|
4587
6438
|
}
|
|
4588
6439
|
return {
|
|
@@ -4595,8 +6446,8 @@ function useAddressRepo() {
|
|
|
4595
6446
|
}
|
|
4596
6447
|
|
|
4597
6448
|
// src/resources/address/address.controller.ts
|
|
4598
|
-
var
|
|
4599
|
-
var
|
|
6449
|
+
var import_nodejs_utils37 = require("@eeplatform/nodejs-utils");
|
|
6450
|
+
var import_joi21 = __toESM(require("joi"));
|
|
4600
6451
|
function useAddressController() {
|
|
4601
6452
|
const {
|
|
4602
6453
|
add: _add,
|
|
@@ -4606,21 +6457,21 @@ function useAddressController() {
|
|
|
4606
6457
|
} = useAddressRepo();
|
|
4607
6458
|
async function add(req, res, next) {
|
|
4608
6459
|
const value = req.body;
|
|
4609
|
-
const validation =
|
|
4610
|
-
type:
|
|
4611
|
-
user:
|
|
4612
|
-
org:
|
|
4613
|
-
country:
|
|
4614
|
-
address:
|
|
4615
|
-
continuedAddress:
|
|
4616
|
-
city:
|
|
4617
|
-
province:
|
|
4618
|
-
postalCode:
|
|
4619
|
-
taxId:
|
|
6460
|
+
const validation = import_joi21.default.object({
|
|
6461
|
+
type: import_joi21.default.string().required(),
|
|
6462
|
+
user: import_joi21.default.string().hex().optional().allow("", null),
|
|
6463
|
+
org: import_joi21.default.string().hex().optional().allow("", null),
|
|
6464
|
+
country: import_joi21.default.string().required(),
|
|
6465
|
+
address: import_joi21.default.string().required(),
|
|
6466
|
+
continuedAddress: import_joi21.default.string().optional().allow("", null),
|
|
6467
|
+
city: import_joi21.default.string().required(),
|
|
6468
|
+
province: import_joi21.default.string().required(),
|
|
6469
|
+
postalCode: import_joi21.default.string().required(),
|
|
6470
|
+
taxId: import_joi21.default.string().optional().allow("", null)
|
|
4620
6471
|
});
|
|
4621
6472
|
const { error } = validation.validate(value);
|
|
4622
6473
|
if (error) {
|
|
4623
|
-
next(new
|
|
6474
|
+
next(new import_nodejs_utils37.BadRequestError(error.message));
|
|
4624
6475
|
}
|
|
4625
6476
|
try {
|
|
4626
6477
|
const value2 = req.body;
|
|
@@ -4634,20 +6485,20 @@ function useAddressController() {
|
|
|
4634
6485
|
async function updateById(req, res, next) {
|
|
4635
6486
|
const id = req.params.id ?? "";
|
|
4636
6487
|
const value = req.body;
|
|
4637
|
-
const validation =
|
|
4638
|
-
id:
|
|
4639
|
-
country:
|
|
4640
|
-
address:
|
|
4641
|
-
continuedAddress:
|
|
4642
|
-
city:
|
|
4643
|
-
province:
|
|
4644
|
-
postalCode:
|
|
4645
|
-
taxId:
|
|
4646
|
-
org:
|
|
6488
|
+
const validation = import_joi21.default.object({
|
|
6489
|
+
id: import_joi21.default.string().hex().required(),
|
|
6490
|
+
country: import_joi21.default.string().required(),
|
|
6491
|
+
address: import_joi21.default.string().required(),
|
|
6492
|
+
continuedAddress: import_joi21.default.string().optional().allow("", null),
|
|
6493
|
+
city: import_joi21.default.string().required(),
|
|
6494
|
+
province: import_joi21.default.string().required(),
|
|
6495
|
+
postalCode: import_joi21.default.string().required(),
|
|
6496
|
+
taxId: import_joi21.default.string().optional().allow("", null),
|
|
6497
|
+
org: import_joi21.default.string().hex().optional().allow("", null)
|
|
4647
6498
|
});
|
|
4648
6499
|
const { error } = validation.validate({ id, ...value });
|
|
4649
6500
|
if (error) {
|
|
4650
|
-
next(new
|
|
6501
|
+
next(new import_nodejs_utils37.BadRequestError(error.message));
|
|
4651
6502
|
return;
|
|
4652
6503
|
}
|
|
4653
6504
|
try {
|
|
@@ -4660,15 +6511,15 @@ function useAddressController() {
|
|
|
4660
6511
|
}
|
|
4661
6512
|
async function getByUserId(req, res, next) {
|
|
4662
6513
|
const user = req.params.user;
|
|
4663
|
-
const validation =
|
|
6514
|
+
const validation = import_joi21.default.string().hex().required();
|
|
4664
6515
|
const { error } = validation.validate(user);
|
|
4665
6516
|
if (error) {
|
|
4666
|
-
next(new
|
|
6517
|
+
next(new import_nodejs_utils37.BadRequestError(error.message));
|
|
4667
6518
|
}
|
|
4668
6519
|
try {
|
|
4669
6520
|
const address = await _getByUserId(user);
|
|
4670
6521
|
if (!address) {
|
|
4671
|
-
next(new
|
|
6522
|
+
next(new import_nodejs_utils37.NotFoundError("Address not found."));
|
|
4672
6523
|
return;
|
|
4673
6524
|
}
|
|
4674
6525
|
res.json(address);
|
|
@@ -4679,15 +6530,15 @@ function useAddressController() {
|
|
|
4679
6530
|
}
|
|
4680
6531
|
async function getByOrgId(req, res, next) {
|
|
4681
6532
|
const id = req.params.id;
|
|
4682
|
-
const validation =
|
|
6533
|
+
const validation = import_joi21.default.string().hex().required();
|
|
4683
6534
|
const { error } = validation.validate(id);
|
|
4684
6535
|
if (error) {
|
|
4685
|
-
next(new
|
|
6536
|
+
next(new import_nodejs_utils37.BadRequestError(error.message));
|
|
4686
6537
|
}
|
|
4687
6538
|
try {
|
|
4688
6539
|
const address = await _getByOrgId(id);
|
|
4689
6540
|
if (!address) {
|
|
4690
|
-
next(new
|
|
6541
|
+
next(new import_nodejs_utils37.NotFoundError("Address not found."));
|
|
4691
6542
|
return;
|
|
4692
6543
|
}
|
|
4693
6544
|
res.json(address);
|
|
@@ -4705,24 +6556,24 @@ function useAddressController() {
|
|
|
4705
6556
|
}
|
|
4706
6557
|
|
|
4707
6558
|
// src/resources/token/token.model.ts
|
|
4708
|
-
var
|
|
6559
|
+
var import_mongodb19 = require("mongodb");
|
|
4709
6560
|
var MToken = class {
|
|
4710
6561
|
constructor(value) {
|
|
4711
6562
|
this.token = value.token ?? "";
|
|
4712
|
-
this.user = value.user ?? new
|
|
6563
|
+
this.user = value.user ?? new import_mongodb19.ObjectId();
|
|
4713
6564
|
this.createdAt = value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
4714
6565
|
}
|
|
4715
6566
|
};
|
|
4716
6567
|
|
|
4717
6568
|
// src/resources/counter/counter.model.ts
|
|
4718
|
-
var
|
|
4719
|
-
var
|
|
6569
|
+
var import_nodejs_utils38 = require("@eeplatform/nodejs-utils");
|
|
6570
|
+
var import_mongodb20 = require("mongodb");
|
|
4720
6571
|
var import_zod = require("zod");
|
|
4721
6572
|
var TCounter = import_zod.z.object({
|
|
4722
6573
|
_id: import_zod.z.union([
|
|
4723
6574
|
import_zod.z.string().length(24, "Invalid ObjectId hex string"),
|
|
4724
|
-
import_zod.z.instanceof(
|
|
4725
|
-
]).transform((val) => typeof val === "string" ? new
|
|
6575
|
+
import_zod.z.instanceof(import_mongodb20.ObjectId)
|
|
6576
|
+
]).transform((val) => typeof val === "string" ? new import_mongodb20.ObjectId(val) : val).optional(),
|
|
4726
6577
|
count: import_zod.z.number().int().min(0).default(0),
|
|
4727
6578
|
type: import_zod.z.string(),
|
|
4728
6579
|
createdAt: import_zod.z.date().optional().default(() => /* @__PURE__ */ new Date()),
|
|
@@ -4735,7 +6586,7 @@ function useCounterModel(db) {
|
|
|
4735
6586
|
try {
|
|
4736
6587
|
return TCounter.parse(value);
|
|
4737
6588
|
} catch (error) {
|
|
4738
|
-
throw new
|
|
6589
|
+
throw new import_nodejs_utils38.BadRequestError(error.issues[0].message);
|
|
4739
6590
|
}
|
|
4740
6591
|
}
|
|
4741
6592
|
function validateCounter(data) {
|
|
@@ -4749,23 +6600,23 @@ function useCounterModel(db) {
|
|
|
4749
6600
|
}
|
|
4750
6601
|
|
|
4751
6602
|
// src/resources/counter/counter.repository.ts
|
|
4752
|
-
var
|
|
6603
|
+
var import_nodejs_utils39 = require("@eeplatform/nodejs-utils");
|
|
4753
6604
|
function useCounterRepo() {
|
|
4754
|
-
const db =
|
|
6605
|
+
const db = import_nodejs_utils39.useAtlas.getDb();
|
|
4755
6606
|
if (!db) {
|
|
4756
6607
|
throw new Error("Unable to connect to server.");
|
|
4757
6608
|
}
|
|
4758
6609
|
const namespace_collection = "counters";
|
|
4759
6610
|
const { collection, createCounter } = useCounterModel(db);
|
|
4760
|
-
const { getCache, setCache, delNamespace } = (0,
|
|
6611
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils39.useCache)(namespace_collection);
|
|
4761
6612
|
function delCachedData() {
|
|
4762
6613
|
delNamespace().then(() => {
|
|
4763
|
-
|
|
6614
|
+
import_nodejs_utils39.logger.log({
|
|
4764
6615
|
level: "info",
|
|
4765
6616
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
4766
6617
|
});
|
|
4767
6618
|
}).catch((err) => {
|
|
4768
|
-
|
|
6619
|
+
import_nodejs_utils39.logger.log({
|
|
4769
6620
|
level: "error",
|
|
4770
6621
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
4771
6622
|
});
|
|
@@ -4817,11 +6668,11 @@ function useCounterRepo() {
|
|
|
4817
6668
|
}
|
|
4818
6669
|
}
|
|
4819
6670
|
async function getByType(type) {
|
|
4820
|
-
const cacheKey = (0,
|
|
6671
|
+
const cacheKey = (0, import_nodejs_utils39.makeCacheKey)(namespace_collection, { type });
|
|
4821
6672
|
try {
|
|
4822
6673
|
const cached = await getCache(cacheKey);
|
|
4823
6674
|
if (cached) {
|
|
4824
|
-
|
|
6675
|
+
import_nodejs_utils39.logger.log({
|
|
4825
6676
|
level: "info",
|
|
4826
6677
|
message: `Cache hit for getByType counter: ${cacheKey}`
|
|
4827
6678
|
});
|
|
@@ -4830,12 +6681,12 @@ function useCounterRepo() {
|
|
|
4830
6681
|
const data = await collection.findOne({ type });
|
|
4831
6682
|
if (data) {
|
|
4832
6683
|
setCache(cacheKey, data, 300).then(() => {
|
|
4833
|
-
|
|
6684
|
+
import_nodejs_utils39.logger.log({
|
|
4834
6685
|
level: "info",
|
|
4835
6686
|
message: `Cache set for counter by type: ${cacheKey}`
|
|
4836
6687
|
});
|
|
4837
6688
|
}).catch((err) => {
|
|
4838
|
-
|
|
6689
|
+
import_nodejs_utils39.logger.log({
|
|
4839
6690
|
level: "error",
|
|
4840
6691
|
message: `Failed to set cache for counter by type: ${err.message}`
|
|
4841
6692
|
});
|
|
@@ -5173,7 +7024,7 @@ IMPORTANT: Only consider it a match if the target phoneme is the FIRST sound pro
|
|
|
5173
7024
|
}
|
|
5174
7025
|
|
|
5175
7026
|
// src/resources/utils/github.service.ts
|
|
5176
|
-
var
|
|
7027
|
+
var import_nodejs_utils40 = require("@eeplatform/nodejs-utils");
|
|
5177
7028
|
var import_rest = require("@octokit/rest");
|
|
5178
7029
|
var import_libsodium_wrappers = __toESM(require("libsodium-wrappers"));
|
|
5179
7030
|
function useGitHubService() {
|
|
@@ -5187,23 +7038,23 @@ function useGitHubService() {
|
|
|
5187
7038
|
try {
|
|
5188
7039
|
const { data: repoData } = await octokit.repos.get({ owner, repo });
|
|
5189
7040
|
if (!repoData.permissions?.admin) {
|
|
5190
|
-
throw new
|
|
7041
|
+
throw new import_nodejs_utils40.BadRequestError(
|
|
5191
7042
|
"You do not have admin access to this repository."
|
|
5192
7043
|
);
|
|
5193
7044
|
}
|
|
5194
7045
|
} catch (error) {
|
|
5195
7046
|
if (error.status === 404) {
|
|
5196
|
-
throw new
|
|
7047
|
+
throw new import_nodejs_utils40.BadRequestError(
|
|
5197
7048
|
"Repository not found or you don't have access to it."
|
|
5198
7049
|
);
|
|
5199
7050
|
} else if (error.status === 401) {
|
|
5200
|
-
throw new
|
|
7051
|
+
throw new import_nodejs_utils40.BadRequestError(
|
|
5201
7052
|
"Invalid GitHub token or insufficient permissions."
|
|
5202
7053
|
);
|
|
5203
7054
|
} else if (error.message.includes("admin access")) {
|
|
5204
7055
|
throw error;
|
|
5205
7056
|
} else {
|
|
5206
|
-
throw new
|
|
7057
|
+
throw new import_nodejs_utils40.BadRequestError(
|
|
5207
7058
|
`Failed to check repository permissions: ${error.message}`
|
|
5208
7059
|
);
|
|
5209
7060
|
}
|
|
@@ -5252,7 +7103,7 @@ function useGitHubService() {
|
|
|
5252
7103
|
key_id: publicKeyRes.key_id
|
|
5253
7104
|
});
|
|
5254
7105
|
} catch (encryptionError) {
|
|
5255
|
-
throw new
|
|
7106
|
+
throw new import_nodejs_utils40.BadRequestError(
|
|
5256
7107
|
`Failed to encrypt secret '${key}': ${encryptionError.message}`
|
|
5257
7108
|
);
|
|
5258
7109
|
}
|
|
@@ -5268,22 +7119,22 @@ function useGitHubService() {
|
|
|
5268
7119
|
}
|
|
5269
7120
|
return `Successfully set ${lines.length} ${type} variables/secrets in environment '${environment}'`;
|
|
5270
7121
|
} catch (error) {
|
|
5271
|
-
if (error instanceof
|
|
7122
|
+
if (error instanceof import_nodejs_utils40.AppError)
|
|
5272
7123
|
throw error;
|
|
5273
7124
|
if (error.status === 422) {
|
|
5274
|
-
throw new
|
|
7125
|
+
throw new import_nodejs_utils40.BadRequestError(
|
|
5275
7126
|
`GitHub API validation error: ${error.message}`
|
|
5276
7127
|
);
|
|
5277
7128
|
} else if (error.status === 404) {
|
|
5278
|
-
throw new
|
|
7129
|
+
throw new import_nodejs_utils40.BadRequestError("Environment or repository not found.");
|
|
5279
7130
|
} else if (error.status === 403) {
|
|
5280
|
-
throw new
|
|
7131
|
+
throw new import_nodejs_utils40.BadRequestError(
|
|
5281
7132
|
"Forbidden: Insufficient permissions or rate limit exceeded."
|
|
5282
7133
|
);
|
|
5283
7134
|
} else if (error.message.includes("admin access") || error.message.includes("permissions")) {
|
|
5284
7135
|
throw error;
|
|
5285
7136
|
} else {
|
|
5286
|
-
throw new
|
|
7137
|
+
throw new import_nodejs_utils40.BadRequestError(
|
|
5287
7138
|
`Failed to set GitHub variables: ${error.message}`
|
|
5288
7139
|
);
|
|
5289
7140
|
}
|
|
@@ -5295,19 +7146,19 @@ function useGitHubService() {
|
|
|
5295
7146
|
}
|
|
5296
7147
|
|
|
5297
7148
|
// src/resources/utils/transcribe.service.ts
|
|
5298
|
-
var
|
|
7149
|
+
var import_nodejs_utils41 = require("@eeplatform/nodejs-utils");
|
|
5299
7150
|
function useTranscribeService() {
|
|
5300
7151
|
const { createFile } = useFileService();
|
|
5301
|
-
const { getClient } = (0,
|
|
7152
|
+
const { getClient } = (0, import_nodejs_utils41.useRedis)();
|
|
5302
7153
|
const redisClient = getClient();
|
|
5303
7154
|
async function transcribeAudio(file) {
|
|
5304
7155
|
try {
|
|
5305
7156
|
const fileId = await createFile(file);
|
|
5306
7157
|
} catch (error) {
|
|
5307
|
-
if (error instanceof
|
|
7158
|
+
if (error instanceof import_nodejs_utils41.AppError) {
|
|
5308
7159
|
throw error;
|
|
5309
7160
|
} else {
|
|
5310
|
-
throw new
|
|
7161
|
+
throw new import_nodejs_utils41.BadRequestError("Failed to transcribe audio file");
|
|
5311
7162
|
}
|
|
5312
7163
|
}
|
|
5313
7164
|
}
|
|
@@ -5317,28 +7168,28 @@ function useTranscribeService() {
|
|
|
5317
7168
|
}
|
|
5318
7169
|
|
|
5319
7170
|
// src/resources/utils/audio-transcription.controller.ts
|
|
5320
|
-
var
|
|
5321
|
-
var
|
|
7171
|
+
var import_nodejs_utils42 = require("@eeplatform/nodejs-utils");
|
|
7172
|
+
var import_joi22 = __toESM(require("joi"));
|
|
5322
7173
|
function useAudioTranscriptionController() {
|
|
5323
7174
|
const geminiService = useGeminiAiService();
|
|
5324
|
-
const transcriptionOptionsSchema =
|
|
5325
|
-
language:
|
|
5326
|
-
enableTimestamps:
|
|
5327
|
-
prompt:
|
|
5328
|
-
maxTokens:
|
|
7175
|
+
const transcriptionOptionsSchema = import_joi22.default.object({
|
|
7176
|
+
language: import_joi22.default.string().optional().max(50),
|
|
7177
|
+
enableTimestamps: import_joi22.default.boolean().optional(),
|
|
7178
|
+
prompt: import_joi22.default.string().optional().max(1e3),
|
|
7179
|
+
maxTokens: import_joi22.default.number().integer().min(1).max(8192).optional()
|
|
5329
7180
|
});
|
|
5330
|
-
const phonemeOptionsSchema =
|
|
5331
|
-
language:
|
|
5332
|
-
caseSensitive:
|
|
5333
|
-
partialMatch:
|
|
7181
|
+
const phonemeOptionsSchema = import_joi22.default.object({
|
|
7182
|
+
language: import_joi22.default.string().optional().max(50),
|
|
7183
|
+
caseSensitive: import_joi22.default.boolean().optional(),
|
|
7184
|
+
partialMatch: import_joi22.default.boolean().optional()
|
|
5334
7185
|
});
|
|
5335
|
-
const phonemeMatchSchema =
|
|
5336
|
-
targetPhoneme:
|
|
7186
|
+
const phonemeMatchSchema = import_joi22.default.object({
|
|
7187
|
+
targetPhoneme: import_joi22.default.string().required().min(1).max(10),
|
|
5337
7188
|
options: phonemeOptionsSchema.optional()
|
|
5338
7189
|
});
|
|
5339
7190
|
async function transcribeFromFile(req, res, next) {
|
|
5340
7191
|
if (!req.file) {
|
|
5341
|
-
next(new
|
|
7192
|
+
next(new import_nodejs_utils42.BadRequestError("Audio file is required"));
|
|
5342
7193
|
return;
|
|
5343
7194
|
}
|
|
5344
7195
|
try {
|
|
@@ -5346,14 +7197,14 @@ function useAudioTranscriptionController() {
|
|
|
5346
7197
|
req.body
|
|
5347
7198
|
);
|
|
5348
7199
|
if (error) {
|
|
5349
|
-
next(new
|
|
7200
|
+
next(new import_nodejs_utils42.BadRequestError(error.message));
|
|
5350
7201
|
return;
|
|
5351
7202
|
}
|
|
5352
7203
|
const { buffer, mimetype, originalname, size } = req.file;
|
|
5353
7204
|
if (!geminiService.validateAudioFormat(mimetype)) {
|
|
5354
7205
|
const supportedFormats = geminiService.getSupportedAudioFormats();
|
|
5355
7206
|
next(
|
|
5356
|
-
new
|
|
7207
|
+
new import_nodejs_utils42.BadRequestError(
|
|
5357
7208
|
`Unsupported audio format: ${mimetype}. Supported formats: ${supportedFormats.join(
|
|
5358
7209
|
", "
|
|
5359
7210
|
)}`
|
|
@@ -5364,7 +7215,7 @@ function useAudioTranscriptionController() {
|
|
|
5364
7215
|
const maxSizeBytes = 25 * 1024 * 1024;
|
|
5365
7216
|
if (size > maxSizeBytes) {
|
|
5366
7217
|
next(
|
|
5367
|
-
new
|
|
7218
|
+
new import_nodejs_utils42.BadRequestError(
|
|
5368
7219
|
`File size too large. Maximum allowed size is ${maxSizeBytes / (1024 * 1024)}MB`
|
|
5369
7220
|
)
|
|
5370
7221
|
);
|
|
@@ -5394,11 +7245,11 @@ function useAudioTranscriptionController() {
|
|
|
5394
7245
|
}
|
|
5395
7246
|
});
|
|
5396
7247
|
} catch (error) {
|
|
5397
|
-
if (error instanceof
|
|
7248
|
+
if (error instanceof import_nodejs_utils42.AppError) {
|
|
5398
7249
|
next(error);
|
|
5399
7250
|
} else {
|
|
5400
7251
|
next(
|
|
5401
|
-
new
|
|
7252
|
+
new import_nodejs_utils42.InternalServerError(
|
|
5402
7253
|
`Audio transcription failed: ${error.message}`
|
|
5403
7254
|
)
|
|
5404
7255
|
);
|
|
@@ -5407,21 +7258,21 @@ function useAudioTranscriptionController() {
|
|
|
5407
7258
|
}
|
|
5408
7259
|
async function transcribeFromBase64(req, res, next) {
|
|
5409
7260
|
try {
|
|
5410
|
-
const bodySchema =
|
|
5411
|
-
audioData:
|
|
5412
|
-
mimeType:
|
|
7261
|
+
const bodySchema = import_joi22.default.object({
|
|
7262
|
+
audioData: import_joi22.default.string().required(),
|
|
7263
|
+
mimeType: import_joi22.default.string().required(),
|
|
5413
7264
|
options: transcriptionOptionsSchema.optional()
|
|
5414
7265
|
});
|
|
5415
7266
|
const { error, value } = bodySchema.validate(req.body);
|
|
5416
7267
|
if (error) {
|
|
5417
|
-
next(new
|
|
7268
|
+
next(new import_nodejs_utils42.BadRequestError(error.message));
|
|
5418
7269
|
return;
|
|
5419
7270
|
}
|
|
5420
7271
|
const { audioData, mimeType, options = {} } = value;
|
|
5421
7272
|
if (!geminiService.validateAudioFormat(mimeType)) {
|
|
5422
7273
|
const supportedFormats = geminiService.getSupportedAudioFormats();
|
|
5423
7274
|
next(
|
|
5424
|
-
new
|
|
7275
|
+
new import_nodejs_utils42.BadRequestError(
|
|
5425
7276
|
`Unsupported audio format: ${mimeType}. Supported formats: ${supportedFormats.join(
|
|
5426
7277
|
", "
|
|
5427
7278
|
)}`
|
|
@@ -5433,13 +7284,13 @@ function useAudioTranscriptionController() {
|
|
|
5433
7284
|
try {
|
|
5434
7285
|
audioBuffer = Buffer.from(audioData, "base64");
|
|
5435
7286
|
} catch (conversionError) {
|
|
5436
|
-
next(new
|
|
7287
|
+
next(new import_nodejs_utils42.BadRequestError("Invalid base64 audio data"));
|
|
5437
7288
|
return;
|
|
5438
7289
|
}
|
|
5439
7290
|
const maxSizeBytes = 25 * 1024 * 1024;
|
|
5440
7291
|
if (audioBuffer.length > maxSizeBytes) {
|
|
5441
7292
|
next(
|
|
5442
|
-
new
|
|
7293
|
+
new import_nodejs_utils42.BadRequestError(
|
|
5443
7294
|
`Audio data too large. Maximum allowed size is ${maxSizeBytes / (1024 * 1024)}MB`
|
|
5444
7295
|
)
|
|
5445
7296
|
);
|
|
@@ -5468,11 +7319,11 @@ function useAudioTranscriptionController() {
|
|
|
5468
7319
|
}
|
|
5469
7320
|
});
|
|
5470
7321
|
} catch (error) {
|
|
5471
|
-
if (error instanceof
|
|
7322
|
+
if (error instanceof import_nodejs_utils42.AppError) {
|
|
5472
7323
|
next(error);
|
|
5473
7324
|
} else {
|
|
5474
7325
|
next(
|
|
5475
|
-
new
|
|
7326
|
+
new import_nodejs_utils42.InternalServerError(
|
|
5476
7327
|
`Audio transcription failed: ${error.message}`
|
|
5477
7328
|
)
|
|
5478
7329
|
);
|
|
@@ -5492,7 +7343,7 @@ function useAudioTranscriptionController() {
|
|
|
5492
7343
|
});
|
|
5493
7344
|
} catch (error) {
|
|
5494
7345
|
next(
|
|
5495
|
-
new
|
|
7346
|
+
new import_nodejs_utils42.InternalServerError(
|
|
5496
7347
|
`Failed to get supported formats: ${error.message}`
|
|
5497
7348
|
)
|
|
5498
7349
|
);
|
|
@@ -5500,12 +7351,12 @@ function useAudioTranscriptionController() {
|
|
|
5500
7351
|
}
|
|
5501
7352
|
async function validateFormat(req, res, next) {
|
|
5502
7353
|
try {
|
|
5503
|
-
const schema =
|
|
5504
|
-
mimeType:
|
|
7354
|
+
const schema = import_joi22.default.object({
|
|
7355
|
+
mimeType: import_joi22.default.string().required()
|
|
5505
7356
|
});
|
|
5506
7357
|
const { error, value } = schema.validate(req.body);
|
|
5507
7358
|
if (error) {
|
|
5508
|
-
next(new
|
|
7359
|
+
next(new import_nodejs_utils42.BadRequestError(error.message));
|
|
5509
7360
|
return;
|
|
5510
7361
|
}
|
|
5511
7362
|
const { mimeType } = value;
|
|
@@ -5521,19 +7372,19 @@ function useAudioTranscriptionController() {
|
|
|
5521
7372
|
});
|
|
5522
7373
|
} catch (error) {
|
|
5523
7374
|
next(
|
|
5524
|
-
new
|
|
7375
|
+
new import_nodejs_utils42.InternalServerError(`Format validation failed: ${error.message}`)
|
|
5525
7376
|
);
|
|
5526
7377
|
}
|
|
5527
7378
|
}
|
|
5528
7379
|
async function checkPhonemeFromFile(req, res, next) {
|
|
5529
7380
|
if (!req.file) {
|
|
5530
|
-
next(new
|
|
7381
|
+
next(new import_nodejs_utils42.BadRequestError("Audio file is required"));
|
|
5531
7382
|
return;
|
|
5532
7383
|
}
|
|
5533
7384
|
try {
|
|
5534
7385
|
const { error, value } = phonemeMatchSchema.validate(req.body);
|
|
5535
7386
|
if (error) {
|
|
5536
|
-
next(new
|
|
7387
|
+
next(new import_nodejs_utils42.BadRequestError(error.message));
|
|
5537
7388
|
return;
|
|
5538
7389
|
}
|
|
5539
7390
|
const { targetPhoneme, options = {} } = value;
|
|
@@ -5541,7 +7392,7 @@ function useAudioTranscriptionController() {
|
|
|
5541
7392
|
if (!geminiService.validateAudioFormat(mimetype)) {
|
|
5542
7393
|
const supportedFormats = geminiService.getSupportedAudioFormats();
|
|
5543
7394
|
next(
|
|
5544
|
-
new
|
|
7395
|
+
new import_nodejs_utils42.BadRequestError(
|
|
5545
7396
|
`Unsupported audio format: ${mimetype}. Supported formats: ${supportedFormats.join(
|
|
5546
7397
|
", "
|
|
5547
7398
|
)}`
|
|
@@ -5552,7 +7403,7 @@ function useAudioTranscriptionController() {
|
|
|
5552
7403
|
const maxSizeBytes = 25 * 1024 * 1024;
|
|
5553
7404
|
if (size > maxSizeBytes) {
|
|
5554
7405
|
next(
|
|
5555
|
-
new
|
|
7406
|
+
new import_nodejs_utils42.BadRequestError(
|
|
5556
7407
|
`File size too large. Maximum allowed size is ${maxSizeBytes / (1024 * 1024)}MB`
|
|
5557
7408
|
)
|
|
5558
7409
|
);
|
|
@@ -5567,7 +7418,7 @@ function useAudioTranscriptionController() {
|
|
|
5567
7418
|
);
|
|
5568
7419
|
const processingTime = Date.now() - startTime;
|
|
5569
7420
|
if (!result.isMatch) {
|
|
5570
|
-
throw new
|
|
7421
|
+
throw new import_nodejs_utils42.BadRequestError(
|
|
5571
7422
|
`Phoneme "${targetPhoneme}" not found in the provided audio. Transcription: "${result.transcription}"`
|
|
5572
7423
|
);
|
|
5573
7424
|
}
|
|
@@ -5595,33 +7446,33 @@ function useAudioTranscriptionController() {
|
|
|
5595
7446
|
}
|
|
5596
7447
|
});
|
|
5597
7448
|
} catch (error) {
|
|
5598
|
-
if (error instanceof
|
|
7449
|
+
if (error instanceof import_nodejs_utils42.AppError) {
|
|
5599
7450
|
next(error);
|
|
5600
7451
|
} else {
|
|
5601
7452
|
next(
|
|
5602
|
-
new
|
|
7453
|
+
new import_nodejs_utils42.InternalServerError(`Phoneme analysis failed: ${error.message}`)
|
|
5603
7454
|
);
|
|
5604
7455
|
}
|
|
5605
7456
|
}
|
|
5606
7457
|
}
|
|
5607
7458
|
async function checkPhonemeFromBase64(req, res, next) {
|
|
5608
7459
|
try {
|
|
5609
|
-
const bodySchema =
|
|
5610
|
-
audioData:
|
|
5611
|
-
mimeType:
|
|
5612
|
-
targetPhoneme:
|
|
7460
|
+
const bodySchema = import_joi22.default.object({
|
|
7461
|
+
audioData: import_joi22.default.string().required(),
|
|
7462
|
+
mimeType: import_joi22.default.string().required(),
|
|
7463
|
+
targetPhoneme: import_joi22.default.string().required().min(1).max(10),
|
|
5613
7464
|
options: phonemeOptionsSchema.optional()
|
|
5614
7465
|
});
|
|
5615
7466
|
const { error, value } = bodySchema.validate(req.body);
|
|
5616
7467
|
if (error) {
|
|
5617
|
-
next(new
|
|
7468
|
+
next(new import_nodejs_utils42.BadRequestError(error.message));
|
|
5618
7469
|
return;
|
|
5619
7470
|
}
|
|
5620
7471
|
const { audioData, mimeType, targetPhoneme, options = {} } = value;
|
|
5621
7472
|
if (!geminiService.validateAudioFormat(mimeType)) {
|
|
5622
7473
|
const supportedFormats = geminiService.getSupportedAudioFormats();
|
|
5623
7474
|
next(
|
|
5624
|
-
new
|
|
7475
|
+
new import_nodejs_utils42.BadRequestError(
|
|
5625
7476
|
`Unsupported audio format: ${mimeType}. Supported formats: ${supportedFormats.join(
|
|
5626
7477
|
", "
|
|
5627
7478
|
)}`
|
|
@@ -5633,13 +7484,13 @@ function useAudioTranscriptionController() {
|
|
|
5633
7484
|
try {
|
|
5634
7485
|
audioBuffer = Buffer.from(audioData, "base64");
|
|
5635
7486
|
} catch (conversionError) {
|
|
5636
|
-
next(new
|
|
7487
|
+
next(new import_nodejs_utils42.BadRequestError("Invalid base64 audio data"));
|
|
5637
7488
|
return;
|
|
5638
7489
|
}
|
|
5639
7490
|
const maxSizeBytes = 25 * 1024 * 1024;
|
|
5640
7491
|
if (audioBuffer.length > maxSizeBytes) {
|
|
5641
7492
|
next(
|
|
5642
|
-
new
|
|
7493
|
+
new import_nodejs_utils42.BadRequestError(
|
|
5643
7494
|
`Audio data too large. Maximum allowed size is ${maxSizeBytes / (1024 * 1024)}MB`
|
|
5644
7495
|
)
|
|
5645
7496
|
);
|
|
@@ -5654,7 +7505,7 @@ function useAudioTranscriptionController() {
|
|
|
5654
7505
|
);
|
|
5655
7506
|
const processingTime = Date.now() - startTime;
|
|
5656
7507
|
if (!result.isMatch) {
|
|
5657
|
-
throw new
|
|
7508
|
+
throw new import_nodejs_utils42.BadRequestError(
|
|
5658
7509
|
`Phoneme "${targetPhoneme}" not found in the provided audio. Transcription: "${result.transcription}"`
|
|
5659
7510
|
);
|
|
5660
7511
|
}
|
|
@@ -5681,28 +7532,28 @@ function useAudioTranscriptionController() {
|
|
|
5681
7532
|
}
|
|
5682
7533
|
});
|
|
5683
7534
|
} catch (error) {
|
|
5684
|
-
if (error instanceof
|
|
7535
|
+
if (error instanceof import_nodejs_utils42.AppError) {
|
|
5685
7536
|
next(error);
|
|
5686
7537
|
} else {
|
|
5687
7538
|
next(
|
|
5688
|
-
new
|
|
7539
|
+
new import_nodejs_utils42.InternalServerError(`Phoneme analysis failed: ${error.message}`)
|
|
5689
7540
|
);
|
|
5690
7541
|
}
|
|
5691
7542
|
}
|
|
5692
7543
|
}
|
|
5693
7544
|
async function batchPhonemeCheck(req, res, next) {
|
|
5694
7545
|
if (!req.file) {
|
|
5695
|
-
next(new
|
|
7546
|
+
next(new import_nodejs_utils42.BadRequestError("Audio file is required"));
|
|
5696
7547
|
return;
|
|
5697
7548
|
}
|
|
5698
7549
|
try {
|
|
5699
|
-
const batchSchema =
|
|
5700
|
-
targetPhonemes:
|
|
7550
|
+
const batchSchema = import_joi22.default.object({
|
|
7551
|
+
targetPhonemes: import_joi22.default.array().items(import_joi22.default.string().min(1).max(10)).min(1).max(20).required(),
|
|
5701
7552
|
options: phonemeOptionsSchema.optional()
|
|
5702
7553
|
});
|
|
5703
7554
|
const { error, value } = batchSchema.validate(req.body);
|
|
5704
7555
|
if (error) {
|
|
5705
|
-
next(new
|
|
7556
|
+
next(new import_nodejs_utils42.BadRequestError(error.message));
|
|
5706
7557
|
return;
|
|
5707
7558
|
}
|
|
5708
7559
|
const { targetPhonemes, options = {} } = value;
|
|
@@ -5710,7 +7561,7 @@ function useAudioTranscriptionController() {
|
|
|
5710
7561
|
if (!geminiService.validateAudioFormat(mimetype)) {
|
|
5711
7562
|
const supportedFormats = geminiService.getSupportedAudioFormats();
|
|
5712
7563
|
next(
|
|
5713
|
-
new
|
|
7564
|
+
new import_nodejs_utils42.BadRequestError(
|
|
5714
7565
|
`Unsupported audio format: ${mimetype}. Supported formats: ${supportedFormats.join(
|
|
5715
7566
|
", "
|
|
5716
7567
|
)}`
|
|
@@ -5721,7 +7572,7 @@ function useAudioTranscriptionController() {
|
|
|
5721
7572
|
const maxSizeBytes = 25 * 1024 * 1024;
|
|
5722
7573
|
if (size > maxSizeBytes) {
|
|
5723
7574
|
next(
|
|
5724
|
-
new
|
|
7575
|
+
new import_nodejs_utils42.BadRequestError(
|
|
5725
7576
|
`File size too large. Maximum allowed size is ${maxSizeBytes / (1024 * 1024)}MB`
|
|
5726
7577
|
)
|
|
5727
7578
|
);
|
|
@@ -5777,11 +7628,11 @@ function useAudioTranscriptionController() {
|
|
|
5777
7628
|
}
|
|
5778
7629
|
});
|
|
5779
7630
|
} catch (error) {
|
|
5780
|
-
if (error instanceof
|
|
7631
|
+
if (error instanceof import_nodejs_utils42.AppError) {
|
|
5781
7632
|
next(error);
|
|
5782
7633
|
} else {
|
|
5783
7634
|
next(
|
|
5784
|
-
new
|
|
7635
|
+
new import_nodejs_utils42.InternalServerError(
|
|
5785
7636
|
`Batch phoneme analysis failed: ${error.message}`
|
|
5786
7637
|
)
|
|
5787
7638
|
);
|
|
@@ -5802,7 +7653,7 @@ function useAudioTranscriptionController() {
|
|
|
5802
7653
|
}
|
|
5803
7654
|
});
|
|
5804
7655
|
} catch (error) {
|
|
5805
|
-
next(new
|
|
7656
|
+
next(new import_nodejs_utils42.InternalServerError(`Health check failed: ${error.message}`));
|
|
5806
7657
|
}
|
|
5807
7658
|
}
|
|
5808
7659
|
return {
|
|
@@ -5818,8 +7669,8 @@ function useAudioTranscriptionController() {
|
|
|
5818
7669
|
}
|
|
5819
7670
|
|
|
5820
7671
|
// src/resources/utils/util.controller.ts
|
|
5821
|
-
var
|
|
5822
|
-
var
|
|
7672
|
+
var import_joi23 = __toESM(require("joi"));
|
|
7673
|
+
var import_nodejs_utils43 = require("@eeplatform/nodejs-utils");
|
|
5823
7674
|
function useUtilController() {
|
|
5824
7675
|
async function healthCheck(req, res, next) {
|
|
5825
7676
|
try {
|
|
@@ -5835,32 +7686,32 @@ function useUtilController() {
|
|
|
5835
7686
|
}
|
|
5836
7687
|
});
|
|
5837
7688
|
} catch (error) {
|
|
5838
|
-
|
|
5839
|
-
next(new
|
|
7689
|
+
import_nodejs_utils43.logger.error("Health check failed", { error: error.message });
|
|
7690
|
+
next(new import_nodejs_utils43.InternalServerError("Health check failed"));
|
|
5840
7691
|
}
|
|
5841
7692
|
}
|
|
5842
7693
|
async function setGitHubVariables(req, res, next) {
|
|
5843
7694
|
try {
|
|
5844
7695
|
const { githubToken, repoUrl, environment, type, keyValues } = req.body;
|
|
5845
|
-
const validation =
|
|
5846
|
-
githubToken:
|
|
7696
|
+
const validation = import_joi23.default.object({
|
|
7697
|
+
githubToken: import_joi23.default.string().required().messages({
|
|
5847
7698
|
"string.empty": "GitHub token is required",
|
|
5848
7699
|
"any.required": "GitHub token is required"
|
|
5849
7700
|
}),
|
|
5850
|
-
repoUrl:
|
|
7701
|
+
repoUrl: import_joi23.default.string().uri().required().messages({
|
|
5851
7702
|
"string.empty": "Repository URL is required",
|
|
5852
7703
|
"string.uri": "Repository URL must be a valid URL",
|
|
5853
7704
|
"any.required": "Repository URL is required"
|
|
5854
7705
|
}),
|
|
5855
|
-
environment:
|
|
7706
|
+
environment: import_joi23.default.string().required().messages({
|
|
5856
7707
|
"string.empty": "Environment name is required",
|
|
5857
7708
|
"any.required": "Environment name is required"
|
|
5858
7709
|
}),
|
|
5859
|
-
type:
|
|
7710
|
+
type: import_joi23.default.string().valid("env", "secret").required().messages({
|
|
5860
7711
|
"any.only": 'Type must be either "env" or "secret"',
|
|
5861
7712
|
"any.required": "Type is required"
|
|
5862
7713
|
}),
|
|
5863
|
-
keyValues:
|
|
7714
|
+
keyValues: import_joi23.default.string().required().messages({
|
|
5864
7715
|
"string.empty": "Key-value pairs are required",
|
|
5865
7716
|
"any.required": "Key-value pairs are required"
|
|
5866
7717
|
})
|
|
@@ -5873,13 +7724,13 @@ function useUtilController() {
|
|
|
5873
7724
|
keyValues
|
|
5874
7725
|
});
|
|
5875
7726
|
if (error) {
|
|
5876
|
-
next(new
|
|
7727
|
+
next(new import_nodejs_utils43.BadRequestError(error.message));
|
|
5877
7728
|
return;
|
|
5878
7729
|
}
|
|
5879
7730
|
const repoUrlPattern = /github\.com[:\/]([^\/]+)\/(.+)\.git$/;
|
|
5880
7731
|
if (!repoUrlPattern.test(repoUrl)) {
|
|
5881
7732
|
next(
|
|
5882
|
-
new
|
|
7733
|
+
new import_nodejs_utils43.BadRequestError(
|
|
5883
7734
|
"Invalid GitHub repository URL format. Expected format: https://github.com/owner/repo.git"
|
|
5884
7735
|
)
|
|
5885
7736
|
);
|
|
@@ -5891,7 +7742,7 @@ function useUtilController() {
|
|
|
5891
7742
|
);
|
|
5892
7743
|
if (invalidLines.length > 0) {
|
|
5893
7744
|
next(
|
|
5894
|
-
new
|
|
7745
|
+
new import_nodejs_utils43.BadRequestError(
|
|
5895
7746
|
"Invalid key-value format. Each pair should be in format: KEY=value. Pairs should be separated by semicolons."
|
|
5896
7747
|
)
|
|
5897
7748
|
);
|
|
@@ -5905,7 +7756,7 @@ function useUtilController() {
|
|
|
5905
7756
|
type,
|
|
5906
7757
|
keyValues
|
|
5907
7758
|
});
|
|
5908
|
-
|
|
7759
|
+
import_nodejs_utils43.logger.info(`GitHub variables set successfully`, {
|
|
5909
7760
|
repoUrl,
|
|
5910
7761
|
environment,
|
|
5911
7762
|
type,
|
|
@@ -5922,15 +7773,15 @@ function useUtilController() {
|
|
|
5922
7773
|
}
|
|
5923
7774
|
});
|
|
5924
7775
|
} catch (error) {
|
|
5925
|
-
|
|
7776
|
+
import_nodejs_utils43.logger.error("Failed to set GitHub variables", {
|
|
5926
7777
|
error: error.message,
|
|
5927
7778
|
stack: error.stack
|
|
5928
7779
|
});
|
|
5929
|
-
if (error instanceof
|
|
7780
|
+
if (error instanceof import_nodejs_utils43.AppError) {
|
|
5930
7781
|
next(error);
|
|
5931
7782
|
} else {
|
|
5932
7783
|
next(
|
|
5933
|
-
new
|
|
7784
|
+
new import_nodejs_utils43.InternalServerError(
|
|
5934
7785
|
`Failed to set GitHub variables: ${error.message}`
|
|
5935
7786
|
)
|
|
5936
7787
|
);
|
|
@@ -5944,34 +7795,34 @@ function useUtilController() {
|
|
|
5944
7795
|
}
|
|
5945
7796
|
|
|
5946
7797
|
// src/resources/utils/transaction.schema.ts
|
|
5947
|
-
var
|
|
5948
|
-
var transactionSchema =
|
|
5949
|
-
_id:
|
|
5950
|
-
payment:
|
|
5951
|
-
user:
|
|
5952
|
-
org:
|
|
5953
|
-
type:
|
|
5954
|
-
amount:
|
|
5955
|
-
currency:
|
|
5956
|
-
description:
|
|
5957
|
-
metadata:
|
|
5958
|
-
subscriptionId:
|
|
5959
|
-
cycle:
|
|
5960
|
-
seats:
|
|
5961
|
-
promoCode:
|
|
7798
|
+
var import_joi24 = __toESM(require("joi"));
|
|
7799
|
+
var transactionSchema = import_joi24.default.object({
|
|
7800
|
+
_id: import_joi24.default.string().hex().optional().allow("", null),
|
|
7801
|
+
payment: import_joi24.default.string().required(),
|
|
7802
|
+
user: import_joi24.default.string().hex().optional().allow("", null),
|
|
7803
|
+
org: import_joi24.default.string().hex().optional().allow("", null),
|
|
7804
|
+
type: import_joi24.default.string().required(),
|
|
7805
|
+
amount: import_joi24.default.number().positive().min(0).required(),
|
|
7806
|
+
currency: import_joi24.default.string().required(),
|
|
7807
|
+
description: import_joi24.default.string().optional().allow("", null),
|
|
7808
|
+
metadata: import_joi24.default.object({
|
|
7809
|
+
subscriptionId: import_joi24.default.string().hex().optional().allow("", null),
|
|
7810
|
+
cycle: import_joi24.default.number().optional().allow("", null),
|
|
7811
|
+
seats: import_joi24.default.number().optional().allow("", null),
|
|
7812
|
+
promoCode: import_joi24.default.string().optional().allow("", null)
|
|
5962
7813
|
}).optional().allow("", null),
|
|
5963
|
-
status:
|
|
5964
|
-
createdAt:
|
|
5965
|
-
updatedAt:
|
|
5966
|
-
deletedAt:
|
|
7814
|
+
status: import_joi24.default.string().optional().allow("", null),
|
|
7815
|
+
createdAt: import_joi24.default.string().optional().allow("", null),
|
|
7816
|
+
updatedAt: import_joi24.default.string().optional().allow("", null),
|
|
7817
|
+
deletedAt: import_joi24.default.string().optional().allow("", null)
|
|
5967
7818
|
});
|
|
5968
7819
|
|
|
5969
7820
|
// src/resources/psgc/psgc.model.ts
|
|
5970
|
-
var
|
|
5971
|
-
var schemaPSGC =
|
|
5972
|
-
code:
|
|
5973
|
-
name:
|
|
5974
|
-
type:
|
|
7821
|
+
var import_joi25 = __toESM(require("joi"));
|
|
7822
|
+
var schemaPSGC = import_joi25.default.object({
|
|
7823
|
+
code: import_joi25.default.string().length(10).required(),
|
|
7824
|
+
name: import_joi25.default.string().required(),
|
|
7825
|
+
type: import_joi25.default.string().valid("Reg", "Prov", "City", "Mun", "Bgy").required()
|
|
5975
7826
|
});
|
|
5976
7827
|
function modelPSGC(data) {
|
|
5977
7828
|
const { error } = schemaPSGC.validate(data);
|
|
@@ -5986,16 +7837,16 @@ function modelPSGC(data) {
|
|
|
5986
7837
|
}
|
|
5987
7838
|
|
|
5988
7839
|
// src/resources/psgc/psgc.repository.ts
|
|
5989
|
-
var
|
|
5990
|
-
var
|
|
7840
|
+
var import_nodejs_utils44 = require("@eeplatform/nodejs-utils");
|
|
7841
|
+
var import_mongodb21 = require("mongodb");
|
|
5991
7842
|
function usePSGCRepo() {
|
|
5992
|
-
const db =
|
|
7843
|
+
const db = import_nodejs_utils44.useAtlas.getDb();
|
|
5993
7844
|
if (!db) {
|
|
5994
7845
|
throw new Error("Unable to connect to server.");
|
|
5995
7846
|
}
|
|
5996
7847
|
const namespace_collection = "psgc";
|
|
5997
7848
|
const collection = db.collection(namespace_collection);
|
|
5998
|
-
const { getCache, setCache, delNamespace } = (0,
|
|
7849
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils44.useCache)(namespace_collection);
|
|
5999
7850
|
async function createIndexes() {
|
|
6000
7851
|
try {
|
|
6001
7852
|
await collection.createIndexes([
|
|
@@ -6009,12 +7860,12 @@ function usePSGCRepo() {
|
|
|
6009
7860
|
}
|
|
6010
7861
|
function delCachedData() {
|
|
6011
7862
|
delNamespace().then(() => {
|
|
6012
|
-
|
|
7863
|
+
import_nodejs_utils44.logger.log({
|
|
6013
7864
|
level: "info",
|
|
6014
7865
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
6015
7866
|
});
|
|
6016
7867
|
}).catch((err) => {
|
|
6017
|
-
|
|
7868
|
+
import_nodejs_utils44.logger.log({
|
|
6018
7869
|
level: "error",
|
|
6019
7870
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
6020
7871
|
});
|
|
@@ -6027,16 +7878,16 @@ function usePSGCRepo() {
|
|
|
6027
7878
|
delCachedData();
|
|
6028
7879
|
return res.insertedId;
|
|
6029
7880
|
} catch (error) {
|
|
6030
|
-
|
|
7881
|
+
import_nodejs_utils44.logger.log({
|
|
6031
7882
|
level: "error",
|
|
6032
7883
|
message: error.message
|
|
6033
7884
|
});
|
|
6034
|
-
if (error instanceof
|
|
7885
|
+
if (error instanceof import_nodejs_utils44.AppError) {
|
|
6035
7886
|
throw error;
|
|
6036
7887
|
} else {
|
|
6037
7888
|
const isDuplicated = error.message.includes("duplicate");
|
|
6038
7889
|
if (isDuplicated) {
|
|
6039
|
-
throw new
|
|
7890
|
+
throw new import_nodejs_utils44.BadRequestError("Region already exists.");
|
|
6040
7891
|
}
|
|
6041
7892
|
throw new Error("Failed to create PSGC.");
|
|
6042
7893
|
}
|
|
@@ -6072,15 +7923,15 @@ function usePSGCRepo() {
|
|
|
6072
7923
|
query.$text = { $search: search };
|
|
6073
7924
|
cacheKeyOptions.search = search;
|
|
6074
7925
|
}
|
|
6075
|
-
const cacheKey = (0,
|
|
6076
|
-
|
|
7926
|
+
const cacheKey = (0, import_nodejs_utils44.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
7927
|
+
import_nodejs_utils44.logger.log({
|
|
6077
7928
|
level: "info",
|
|
6078
7929
|
message: `Cache key for getAll PSGC: ${cacheKey}`
|
|
6079
7930
|
});
|
|
6080
7931
|
try {
|
|
6081
7932
|
const cached = await getCache(cacheKey);
|
|
6082
7933
|
if (cached) {
|
|
6083
|
-
|
|
7934
|
+
import_nodejs_utils44.logger.log({
|
|
6084
7935
|
level: "info",
|
|
6085
7936
|
message: `Cache hit for getAll PSGC: ${cacheKey}`
|
|
6086
7937
|
});
|
|
@@ -6093,35 +7944,35 @@ function usePSGCRepo() {
|
|
|
6093
7944
|
{ $limit: limit }
|
|
6094
7945
|
]).toArray();
|
|
6095
7946
|
const length = await collection.countDocuments(query);
|
|
6096
|
-
const data = (0,
|
|
7947
|
+
const data = (0, import_nodejs_utils44.paginate)(items, page, limit, length);
|
|
6097
7948
|
setCache(cacheKey, data, 600).then(() => {
|
|
6098
|
-
|
|
7949
|
+
import_nodejs_utils44.logger.log({
|
|
6099
7950
|
level: "info",
|
|
6100
7951
|
message: `Cache set for getAll PSGC: ${cacheKey}`
|
|
6101
7952
|
});
|
|
6102
7953
|
}).catch((err) => {
|
|
6103
|
-
|
|
7954
|
+
import_nodejs_utils44.logger.log({
|
|
6104
7955
|
level: "error",
|
|
6105
7956
|
message: `Failed to set cache for getAll PSGC: ${err.message}`
|
|
6106
7957
|
});
|
|
6107
7958
|
});
|
|
6108
7959
|
return data;
|
|
6109
7960
|
} catch (error) {
|
|
6110
|
-
|
|
7961
|
+
import_nodejs_utils44.logger.log({ level: "error", message: `${error}` });
|
|
6111
7962
|
throw error;
|
|
6112
7963
|
}
|
|
6113
7964
|
}
|
|
6114
7965
|
async function getById(_id) {
|
|
6115
7966
|
try {
|
|
6116
|
-
_id = new
|
|
7967
|
+
_id = new import_mongodb21.ObjectId(_id);
|
|
6117
7968
|
} catch (error) {
|
|
6118
|
-
throw new
|
|
7969
|
+
throw new import_nodejs_utils44.BadRequestError("Invalid ID.");
|
|
6119
7970
|
}
|
|
6120
|
-
const cacheKey = (0,
|
|
7971
|
+
const cacheKey = (0, import_nodejs_utils44.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
6121
7972
|
try {
|
|
6122
7973
|
const cached = await getCache(cacheKey);
|
|
6123
7974
|
if (cached) {
|
|
6124
|
-
|
|
7975
|
+
import_nodejs_utils44.logger.log({
|
|
6125
7976
|
level: "info",
|
|
6126
7977
|
message: `Cache hit for getById PSGC: ${cacheKey}`
|
|
6127
7978
|
});
|
|
@@ -6132,25 +7983,25 @@ function usePSGCRepo() {
|
|
|
6132
7983
|
deletedAt: { $in: ["", null] }
|
|
6133
7984
|
});
|
|
6134
7985
|
if (!result) {
|
|
6135
|
-
throw new
|
|
7986
|
+
throw new import_nodejs_utils44.BadRequestError("Region not found.");
|
|
6136
7987
|
}
|
|
6137
7988
|
setCache(cacheKey, result, 300).then(() => {
|
|
6138
|
-
|
|
7989
|
+
import_nodejs_utils44.logger.log({
|
|
6139
7990
|
level: "info",
|
|
6140
7991
|
message: `Cache set for PSGC by id: ${cacheKey}`
|
|
6141
7992
|
});
|
|
6142
7993
|
}).catch((err) => {
|
|
6143
|
-
|
|
7994
|
+
import_nodejs_utils44.logger.log({
|
|
6144
7995
|
level: "error",
|
|
6145
7996
|
message: `Failed to set cache for PSGC by id: ${err.message}`
|
|
6146
7997
|
});
|
|
6147
7998
|
});
|
|
6148
7999
|
return result;
|
|
6149
8000
|
} catch (error) {
|
|
6150
|
-
if (error instanceof
|
|
8001
|
+
if (error instanceof import_nodejs_utils44.AppError) {
|
|
6151
8002
|
throw error;
|
|
6152
8003
|
} else {
|
|
6153
|
-
throw new
|
|
8004
|
+
throw new import_nodejs_utils44.InternalServerError("Failed to get PSGC.");
|
|
6154
8005
|
}
|
|
6155
8006
|
}
|
|
6156
8007
|
}
|
|
@@ -6174,15 +8025,15 @@ function usePSGCRepo() {
|
|
|
6174
8025
|
query.code = { $regex: `^${prefix}` };
|
|
6175
8026
|
cacheKeyOptions.prefix = prefix;
|
|
6176
8027
|
}
|
|
6177
|
-
const cacheKey = (0,
|
|
6178
|
-
|
|
8028
|
+
const cacheKey = (0, import_nodejs_utils44.makeCacheKey)(namespace_collection, { name });
|
|
8029
|
+
import_nodejs_utils44.logger.log({
|
|
6179
8030
|
level: "info",
|
|
6180
8031
|
message: `Query for getByName PSGC: ${JSON.stringify(query)}`
|
|
6181
8032
|
});
|
|
6182
8033
|
try {
|
|
6183
8034
|
const cached = await getCache(cacheKey);
|
|
6184
8035
|
if (cached) {
|
|
6185
|
-
|
|
8036
|
+
import_nodejs_utils44.logger.log({
|
|
6186
8037
|
level: "info",
|
|
6187
8038
|
message: `Cache hit for getByName PSGC: ${cacheKey}`
|
|
6188
8039
|
});
|
|
@@ -6190,36 +8041,36 @@ function usePSGCRepo() {
|
|
|
6190
8041
|
}
|
|
6191
8042
|
const result = await collection.findOne(query);
|
|
6192
8043
|
setCache(cacheKey, result, 300).then(() => {
|
|
6193
|
-
|
|
8044
|
+
import_nodejs_utils44.logger.log({
|
|
6194
8045
|
level: "info",
|
|
6195
8046
|
message: `Cache set for PSGC by name: ${cacheKey}`
|
|
6196
8047
|
});
|
|
6197
8048
|
}).catch((err) => {
|
|
6198
|
-
|
|
8049
|
+
import_nodejs_utils44.logger.log({
|
|
6199
8050
|
level: "error",
|
|
6200
8051
|
message: `Failed to set cache for PSGC by name: ${err.message}`
|
|
6201
8052
|
});
|
|
6202
8053
|
});
|
|
6203
8054
|
return result;
|
|
6204
8055
|
} catch (error) {
|
|
6205
|
-
if (error instanceof
|
|
8056
|
+
if (error instanceof import_nodejs_utils44.AppError) {
|
|
6206
8057
|
throw error;
|
|
6207
8058
|
} else {
|
|
6208
|
-
throw new
|
|
8059
|
+
throw new import_nodejs_utils44.InternalServerError("Failed to get PSGC.");
|
|
6209
8060
|
}
|
|
6210
8061
|
}
|
|
6211
8062
|
}
|
|
6212
8063
|
async function updateFieldById({ _id, field, value } = {}, session) {
|
|
6213
8064
|
const allowedFields = ["name"];
|
|
6214
8065
|
if (!allowedFields.includes(field)) {
|
|
6215
|
-
throw new
|
|
8066
|
+
throw new import_nodejs_utils44.BadRequestError(
|
|
6216
8067
|
`Field "${field}" is not allowed to be updated.`
|
|
6217
8068
|
);
|
|
6218
8069
|
}
|
|
6219
8070
|
try {
|
|
6220
|
-
_id = new
|
|
8071
|
+
_id = new import_mongodb21.ObjectId(_id);
|
|
6221
8072
|
} catch (error) {
|
|
6222
|
-
throw new
|
|
8073
|
+
throw new import_nodejs_utils44.BadRequestError("Invalid ID.");
|
|
6223
8074
|
}
|
|
6224
8075
|
try {
|
|
6225
8076
|
await collection.updateOne(
|
|
@@ -6230,14 +8081,14 @@ function usePSGCRepo() {
|
|
|
6230
8081
|
delCachedData();
|
|
6231
8082
|
return `Successfully updated PSGC ${field}.`;
|
|
6232
8083
|
} catch (error) {
|
|
6233
|
-
throw new
|
|
8084
|
+
throw new import_nodejs_utils44.InternalServerError(`Failed to update PSGC ${field}.`);
|
|
6234
8085
|
}
|
|
6235
8086
|
}
|
|
6236
8087
|
async function deleteById(_id) {
|
|
6237
8088
|
try {
|
|
6238
|
-
_id = new
|
|
8089
|
+
_id = new import_mongodb21.ObjectId(_id);
|
|
6239
8090
|
} catch (error) {
|
|
6240
|
-
throw new
|
|
8091
|
+
throw new import_nodejs_utils44.BadRequestError("Invalid ID.");
|
|
6241
8092
|
}
|
|
6242
8093
|
try {
|
|
6243
8094
|
await collection.updateOne(
|
|
@@ -6247,7 +8098,7 @@ function usePSGCRepo() {
|
|
|
6247
8098
|
delCachedData();
|
|
6248
8099
|
return "Successfully deleted PSGC.";
|
|
6249
8100
|
} catch (error) {
|
|
6250
|
-
throw new
|
|
8101
|
+
throw new import_nodejs_utils44.InternalServerError("Failed to delete PSGC.");
|
|
6251
8102
|
}
|
|
6252
8103
|
}
|
|
6253
8104
|
async function setRegionProvinceName() {
|
|
@@ -6297,8 +8148,8 @@ function usePSGCRepo() {
|
|
|
6297
8148
|
}
|
|
6298
8149
|
|
|
6299
8150
|
// src/resources/psgc/psgc.controller.ts
|
|
6300
|
-
var
|
|
6301
|
-
var
|
|
8151
|
+
var import_nodejs_utils45 = require("@eeplatform/nodejs-utils");
|
|
8152
|
+
var import_joi26 = __toESM(require("joi"));
|
|
6302
8153
|
function usePSGCController() {
|
|
6303
8154
|
const {
|
|
6304
8155
|
add: _add,
|
|
@@ -6312,7 +8163,7 @@ function usePSGCController() {
|
|
|
6312
8163
|
const value = req.body;
|
|
6313
8164
|
const { error } = schemaPSGC.validate(value);
|
|
6314
8165
|
if (error) {
|
|
6315
|
-
next(new
|
|
8166
|
+
next(new import_nodejs_utils45.BadRequestError(error.message));
|
|
6316
8167
|
return;
|
|
6317
8168
|
}
|
|
6318
8169
|
try {
|
|
@@ -6328,12 +8179,12 @@ function usePSGCController() {
|
|
|
6328
8179
|
}
|
|
6329
8180
|
async function getAll(req, res, next) {
|
|
6330
8181
|
const query = req.query;
|
|
6331
|
-
const validation =
|
|
6332
|
-
page:
|
|
6333
|
-
limit:
|
|
6334
|
-
search:
|
|
6335
|
-
type:
|
|
6336
|
-
prefix:
|
|
8182
|
+
const validation = import_joi26.default.object({
|
|
8183
|
+
page: import_joi26.default.number().min(1).optional().allow("", null),
|
|
8184
|
+
limit: import_joi26.default.number().min(1).optional().allow("", null),
|
|
8185
|
+
search: import_joi26.default.string().optional().allow("", null),
|
|
8186
|
+
type: import_joi26.default.string().valid("Reg", "Prov", "City", "Mun", "Bgy").required(),
|
|
8187
|
+
prefix: import_joi26.default.string().optional().allow("", null)
|
|
6337
8188
|
});
|
|
6338
8189
|
const { error } = validation.validate(query);
|
|
6339
8190
|
const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
|
|
@@ -6343,16 +8194,16 @@ function usePSGCController() {
|
|
|
6343
8194
|
const prefix = req.query.prefix ? String(req.query.prefix) : "";
|
|
6344
8195
|
const isPageNumber = isFinite(page);
|
|
6345
8196
|
if (!isPageNumber) {
|
|
6346
|
-
next(new
|
|
8197
|
+
next(new import_nodejs_utils45.BadRequestError("Invalid page number."));
|
|
6347
8198
|
return;
|
|
6348
8199
|
}
|
|
6349
8200
|
const isLimitNumber = isFinite(limit);
|
|
6350
8201
|
if (!isLimitNumber) {
|
|
6351
|
-
next(new
|
|
8202
|
+
next(new import_nodejs_utils45.BadRequestError("Invalid limit number."));
|
|
6352
8203
|
return;
|
|
6353
8204
|
}
|
|
6354
8205
|
if (error) {
|
|
6355
|
-
next(new
|
|
8206
|
+
next(new import_nodejs_utils45.BadRequestError(error.message));
|
|
6356
8207
|
return;
|
|
6357
8208
|
}
|
|
6358
8209
|
try {
|
|
@@ -6371,12 +8222,12 @@ function usePSGCController() {
|
|
|
6371
8222
|
}
|
|
6372
8223
|
async function getById(req, res, next) {
|
|
6373
8224
|
const id = req.params.id;
|
|
6374
|
-
const validation =
|
|
6375
|
-
id:
|
|
8225
|
+
const validation = import_joi26.default.object({
|
|
8226
|
+
id: import_joi26.default.string().hex().required()
|
|
6376
8227
|
});
|
|
6377
8228
|
const { error } = validation.validate({ id });
|
|
6378
8229
|
if (error) {
|
|
6379
|
-
next(new
|
|
8230
|
+
next(new import_nodejs_utils45.BadRequestError(error.message));
|
|
6380
8231
|
return;
|
|
6381
8232
|
}
|
|
6382
8233
|
try {
|
|
@@ -6392,12 +8243,12 @@ function usePSGCController() {
|
|
|
6392
8243
|
}
|
|
6393
8244
|
async function getByName(req, res, next) {
|
|
6394
8245
|
const name = req.params.name;
|
|
6395
|
-
const validation =
|
|
6396
|
-
name:
|
|
8246
|
+
const validation = import_joi26.default.object({
|
|
8247
|
+
name: import_joi26.default.string().required()
|
|
6397
8248
|
});
|
|
6398
8249
|
const { error } = validation.validate({ name });
|
|
6399
8250
|
if (error) {
|
|
6400
|
-
next(new
|
|
8251
|
+
next(new import_nodejs_utils45.BadRequestError(error.message));
|
|
6401
8252
|
return;
|
|
6402
8253
|
}
|
|
6403
8254
|
try {
|
|
@@ -6414,14 +8265,14 @@ function usePSGCController() {
|
|
|
6414
8265
|
async function updateField(req, res, next) {
|
|
6415
8266
|
const _id = req.params.id;
|
|
6416
8267
|
const { field, value } = req.body;
|
|
6417
|
-
const validation =
|
|
6418
|
-
_id:
|
|
6419
|
-
field:
|
|
6420
|
-
value:
|
|
8268
|
+
const validation = import_joi26.default.object({
|
|
8269
|
+
_id: import_joi26.default.string().hex().required(),
|
|
8270
|
+
field: import_joi26.default.string().valid("name", "director", "directorName").required(),
|
|
8271
|
+
value: import_joi26.default.string().required()
|
|
6421
8272
|
});
|
|
6422
8273
|
const { error } = validation.validate({ _id, field, value });
|
|
6423
8274
|
if (error) {
|
|
6424
|
-
next(new
|
|
8275
|
+
next(new import_nodejs_utils45.BadRequestError(error.message));
|
|
6425
8276
|
return;
|
|
6426
8277
|
}
|
|
6427
8278
|
try {
|
|
@@ -6434,12 +8285,12 @@ function usePSGCController() {
|
|
|
6434
8285
|
}
|
|
6435
8286
|
async function deleteById(req, res, next) {
|
|
6436
8287
|
const _id = req.params.id;
|
|
6437
|
-
const validation =
|
|
6438
|
-
_id:
|
|
8288
|
+
const validation = import_joi26.default.object({
|
|
8289
|
+
_id: import_joi26.default.string().hex().required()
|
|
6439
8290
|
});
|
|
6440
8291
|
const { error } = validation.validate({ _id });
|
|
6441
8292
|
if (error) {
|
|
6442
|
-
next(new
|
|
8293
|
+
next(new import_nodejs_utils45.BadRequestError(error.message));
|
|
6443
8294
|
return;
|
|
6444
8295
|
}
|
|
6445
8296
|
try {
|
|
@@ -6509,12 +8360,24 @@ function usePSGCController() {
|
|
|
6509
8360
|
XENDIT_SECRET_KEY,
|
|
6510
8361
|
addressSchema,
|
|
6511
8362
|
isDev,
|
|
8363
|
+
modelApp,
|
|
6512
8364
|
modelPSGC,
|
|
8365
|
+
modelPermission,
|
|
8366
|
+
modelPermissionGroup,
|
|
8367
|
+
schemaApp,
|
|
8368
|
+
schemaAppUpdate,
|
|
6513
8369
|
schemaOrg,
|
|
6514
8370
|
schemaPSGC,
|
|
8371
|
+
schemaPermission,
|
|
8372
|
+
schemaPermissionGroup,
|
|
8373
|
+
schemaPermissionGroupUpdate,
|
|
8374
|
+
schemaPermissionUpdate,
|
|
6515
8375
|
transactionSchema,
|
|
6516
8376
|
useAddressController,
|
|
6517
8377
|
useAddressRepo,
|
|
8378
|
+
useAppController,
|
|
8379
|
+
useAppRepo,
|
|
8380
|
+
useAppService,
|
|
6518
8381
|
useAudioTranscriptionController,
|
|
6519
8382
|
useAuthController,
|
|
6520
8383
|
useAuthService,
|
|
@@ -6532,6 +8395,12 @@ function usePSGCController() {
|
|
|
6532
8395
|
useOrgService,
|
|
6533
8396
|
usePSGCController,
|
|
6534
8397
|
usePSGCRepo,
|
|
8398
|
+
usePermissionController,
|
|
8399
|
+
usePermissionGroupController,
|
|
8400
|
+
usePermissionGroupRepo,
|
|
8401
|
+
usePermissionGroupService,
|
|
8402
|
+
usePermissionRepo,
|
|
8403
|
+
usePermissionService,
|
|
6535
8404
|
useRoleController,
|
|
6536
8405
|
useRoleRepo,
|
|
6537
8406
|
useTokenRepo,
|