@goweekdays/core 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +18 -11
- package/dist/index.js +175 -82
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +173 -83
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -802,6 +802,7 @@ type TApp = {
|
|
|
802
802
|
deletedAt?: string | Date;
|
|
803
803
|
};
|
|
804
804
|
declare const schemaApp: Joi.ObjectSchema<any>;
|
|
805
|
+
declare const schemaAppUpdate: Joi.ObjectSchema<any>;
|
|
805
806
|
declare function modelApp(value: TApp): TApp;
|
|
806
807
|
|
|
807
808
|
declare function useAppRepo(): {
|
|
@@ -818,8 +819,7 @@ declare function useAppRepo(): {
|
|
|
818
819
|
getById: (_id: string | ObjectId) => Promise<TApp | null>;
|
|
819
820
|
updateById: (_id: ObjectId | string, value: {
|
|
820
821
|
name: string;
|
|
821
|
-
|
|
822
|
-
levels: number;
|
|
822
|
+
description: string;
|
|
823
823
|
}, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
|
|
824
824
|
deleteById: (_id: string | ObjectId, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
|
|
825
825
|
};
|
|
@@ -830,6 +830,7 @@ declare function useAppService(): {
|
|
|
830
830
|
|
|
831
831
|
declare function useAppController(): {
|
|
832
832
|
add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
833
|
+
updateById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
833
834
|
getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
834
835
|
getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
835
836
|
deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -842,29 +843,31 @@ type TPermission = {
|
|
|
842
843
|
group: string;
|
|
843
844
|
description: string;
|
|
844
845
|
deprecated: boolean;
|
|
846
|
+
status?: string;
|
|
845
847
|
createdAt?: string | Date;
|
|
846
848
|
updatedAt?: string | Date;
|
|
847
849
|
deletedAt?: string | Date;
|
|
848
850
|
};
|
|
849
851
|
declare const schemaPermission: Joi.ObjectSchema<any>;
|
|
852
|
+
declare const schemaPermissionUpdate: Joi.ObjectSchema<any>;
|
|
850
853
|
declare function modelPermission(value: TPermission): TPermission;
|
|
851
854
|
|
|
852
855
|
declare function usePermissionRepo(): {
|
|
853
856
|
createIndexes: () => Promise<void>;
|
|
854
857
|
add: (value: TPermission, session?: ClientSession) => Promise<ObjectId>;
|
|
855
|
-
getAll: ({ search, page, limit, sort,
|
|
858
|
+
getAll: ({ search, page, limit, sort, app, status, }?: {
|
|
856
859
|
search?: string | undefined;
|
|
857
860
|
page?: number | undefined;
|
|
858
861
|
limit?: number | undefined;
|
|
859
862
|
sort?: {} | undefined;
|
|
860
|
-
|
|
863
|
+
app?: string | undefined;
|
|
861
864
|
status?: string | undefined;
|
|
862
865
|
}) => Promise<Record<string, any>>;
|
|
863
866
|
getById: (_id: string | ObjectId) => Promise<TPermission | null>;
|
|
864
867
|
updateById: (_id: ObjectId | string, value: {
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
+
key?: string;
|
|
869
|
+
group?: string;
|
|
870
|
+
description?: string;
|
|
868
871
|
}, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
|
|
869
872
|
deleteById: (_id: string | ObjectId, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
|
|
870
873
|
countByGroup: (group: string) => Promise<number>;
|
|
@@ -879,6 +882,7 @@ declare function usePermissionController(): {
|
|
|
879
882
|
getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
880
883
|
getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
881
884
|
deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
885
|
+
updateById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
882
886
|
};
|
|
883
887
|
|
|
884
888
|
type TPermissionGroup = {
|
|
@@ -886,23 +890,25 @@ type TPermissionGroup = {
|
|
|
886
890
|
app: string;
|
|
887
891
|
key: string;
|
|
888
892
|
label: string;
|
|
889
|
-
order
|
|
893
|
+
order?: number;
|
|
894
|
+
status?: string;
|
|
890
895
|
createdAt?: string | Date;
|
|
891
896
|
updatedAt?: string | Date;
|
|
892
897
|
deletedAt?: string | Date;
|
|
893
898
|
};
|
|
894
899
|
declare const schemaPermissionGroup: Joi.ObjectSchema<any>;
|
|
900
|
+
declare const schemaPermissionGroupUpdate: Joi.ObjectSchema<any>;
|
|
895
901
|
declare function modelPermissionGroup(value: TPermissionGroup): TPermissionGroup;
|
|
896
902
|
|
|
897
903
|
declare function usePermissionGroupRepo(): {
|
|
898
904
|
createIndexes: () => Promise<void>;
|
|
899
905
|
add: (value: TPermissionGroup, session?: ClientSession) => Promise<ObjectId>;
|
|
900
|
-
getAll: ({ search, page, limit, sort,
|
|
906
|
+
getAll: ({ search, page, limit, sort, app, status, }?: {
|
|
901
907
|
search?: string | undefined;
|
|
902
908
|
page?: number | undefined;
|
|
903
909
|
limit?: number | undefined;
|
|
904
910
|
sort?: {} | undefined;
|
|
905
|
-
|
|
911
|
+
app?: string | undefined;
|
|
906
912
|
status?: string | undefined;
|
|
907
913
|
}) => Promise<Record<string, any>>;
|
|
908
914
|
getById: (_id: string | ObjectId) => Promise<TPermissionGroup | null>;
|
|
@@ -923,6 +929,7 @@ declare function usePermissionGroupController(): {
|
|
|
923
929
|
getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
924
930
|
getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
925
931
|
deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
932
|
+
updateById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
926
933
|
};
|
|
927
934
|
|
|
928
935
|
declare const MONGO_URI: string;
|
|
@@ -962,4 +969,4 @@ declare const XENDIT_SECRET_KEY: string;
|
|
|
962
969
|
declare const XENDIT_BASE_URL: string;
|
|
963
970
|
declare const DOMAIN: string;
|
|
964
971
|
|
|
965
|
-
export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, DOMAIN, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MAddress, MBuilding, MBuildingUnit, MFile, MMember, MONGO_DB, MONGO_URI, MOrg, MRole, MUser, MUserRole, MVerification, OrgTypes, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PORT, REDIS_HOST, REDIS_PASSWORD, REDIS_PORT, REFRESH_TOKEN_EXPIRY, REFRESH_TOKEN_SECRET, SECRET_KEY, SPACES_ACCESS_KEY, SPACES_BUCKET, SPACES_ENDPOINT, SPACES_REGION, SPACES_SECRET_KEY, TAddress, TApp, TBuilding, TBuildingUnit, TCounter, TFile, TMember, TMiniRole, TOrg, TPSGC, TPermission, TPermissionGroup, TRole, TUser, TUserRole, TVerification, TVerificationMetadata, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, addressSchema, isDev, modelApp, modelPSGC, modelPermission, modelPermissionGroup, schemaApp, schemaBuilding, schemaBuildingUnit, schemaOrg, schemaPSGC, schemaPermission, schemaPermissionGroup, schemaUpdateOptions, transactionSchema, useAddressController, useAddressRepo, useAppController, useAppRepo, useAppService, useAuthController, useAuthService, useBuildingController, useBuildingRepo, useBuildingService, useBuildingUnitController, useBuildingUnitRepo, useBuildingUnitService, useCounterModel, useCounterRepo, useFileController, useFileRepo, useFileService, useGitHubService, useMemberController, useMemberRepo, useOrgController, useOrgRepo, useOrgService, usePSGCController, usePSGCRepo, usePermissionController, usePermissionGroupController, usePermissionGroupRepo, usePermissionGroupService, usePermissionRepo, usePermissionService, useRoleController, useRoleRepo, useUserController, useUserRepo, useUserService, useUtilController, useVerificationController, useVerificationRepo, useVerificationService };
|
|
972
|
+
export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, DOMAIN, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MAddress, MBuilding, MBuildingUnit, MFile, MMember, MONGO_DB, MONGO_URI, MOrg, MRole, MUser, MUserRole, MVerification, OrgTypes, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PORT, REDIS_HOST, REDIS_PASSWORD, REDIS_PORT, REFRESH_TOKEN_EXPIRY, REFRESH_TOKEN_SECRET, SECRET_KEY, SPACES_ACCESS_KEY, SPACES_BUCKET, SPACES_ENDPOINT, SPACES_REGION, SPACES_SECRET_KEY, TAddress, TApp, TBuilding, TBuildingUnit, TCounter, TFile, TMember, TMiniRole, TOrg, TPSGC, TPermission, TPermissionGroup, TRole, TUser, TUserRole, TVerification, TVerificationMetadata, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, addressSchema, isDev, modelApp, modelPSGC, modelPermission, modelPermissionGroup, schemaApp, schemaAppUpdate, schemaBuilding, schemaBuildingUnit, schemaOrg, schemaPSGC, schemaPermission, schemaPermissionGroup, schemaPermissionGroupUpdate, schemaPermissionUpdate, schemaUpdateOptions, transactionSchema, useAddressController, useAddressRepo, useAppController, useAppRepo, useAppService, useAuthController, useAuthService, useBuildingController, useBuildingRepo, useBuildingService, useBuildingUnitController, useBuildingUnitRepo, useBuildingUnitService, useCounterModel, useCounterRepo, useFileController, useFileRepo, useFileService, useGitHubService, useMemberController, useMemberRepo, useOrgController, useOrgRepo, useOrgService, usePSGCController, usePSGCRepo, usePermissionController, usePermissionGroupController, usePermissionGroupRepo, usePermissionGroupService, usePermissionRepo, usePermissionService, useRoleController, useRoleRepo, useUserController, useUserRepo, useUserService, useUtilController, useVerificationController, useVerificationRepo, useVerificationService };
|
package/dist/index.js
CHANGED
|
@@ -83,12 +83,15 @@ __export(src_exports, {
|
|
|
83
83
|
modelPermission: () => modelPermission,
|
|
84
84
|
modelPermissionGroup: () => modelPermissionGroup,
|
|
85
85
|
schemaApp: () => schemaApp,
|
|
86
|
+
schemaAppUpdate: () => schemaAppUpdate,
|
|
86
87
|
schemaBuilding: () => schemaBuilding,
|
|
87
88
|
schemaBuildingUnit: () => schemaBuildingUnit,
|
|
88
89
|
schemaOrg: () => schemaOrg,
|
|
89
90
|
schemaPSGC: () => schemaPSGC,
|
|
90
91
|
schemaPermission: () => schemaPermission,
|
|
91
92
|
schemaPermissionGroup: () => schemaPermissionGroup,
|
|
93
|
+
schemaPermissionGroupUpdate: () => schemaPermissionGroupUpdate,
|
|
94
|
+
schemaPermissionUpdate: () => schemaPermissionUpdate,
|
|
92
95
|
schemaUpdateOptions: () => schemaUpdateOptions,
|
|
93
96
|
transactionSchema: () => transactionSchema,
|
|
94
97
|
useAddressController: () => useAddressController,
|
|
@@ -6556,6 +6559,11 @@ var schemaApp = import_joi19.default.object({
|
|
|
6556
6559
|
name: import_joi19.default.string().max(255).required(),
|
|
6557
6560
|
description: import_joi19.default.string().max(1024).optional().allow("", null)
|
|
6558
6561
|
});
|
|
6562
|
+
var schemaAppUpdate = import_joi19.default.object({
|
|
6563
|
+
code: import_joi19.default.string().alphanum().max(20).optional().allow("", null),
|
|
6564
|
+
name: import_joi19.default.string().max(255).optional().allow("", null),
|
|
6565
|
+
description: import_joi19.default.string().max(1024).optional().allow("", null)
|
|
6566
|
+
});
|
|
6559
6567
|
function modelApp(value) {
|
|
6560
6568
|
const { error } = schemaApp.validate(value);
|
|
6561
6569
|
if (error) {
|
|
@@ -6587,15 +6595,24 @@ function useAppRepo() {
|
|
|
6587
6595
|
async function createIndexes() {
|
|
6588
6596
|
try {
|
|
6589
6597
|
await collection.createIndexes([
|
|
6590
|
-
{ key: { name: 1 }, unique: true, name: "unique_name_index" },
|
|
6591
6598
|
{ key: { code: 1 } },
|
|
6592
6599
|
{ key: { status: 1 } },
|
|
6593
6600
|
{
|
|
6594
6601
|
key: { code: "text", name: "text", description: "text" },
|
|
6595
6602
|
name: "text_index"
|
|
6596
6603
|
},
|
|
6597
|
-
{
|
|
6598
|
-
|
|
6604
|
+
{
|
|
6605
|
+
key: { code: 1, status: 1 },
|
|
6606
|
+
unique: true,
|
|
6607
|
+
name: "unique_code",
|
|
6608
|
+
partialFilterExpression: { status: { $in: ["active", "draft"] } }
|
|
6609
|
+
},
|
|
6610
|
+
{
|
|
6611
|
+
key: { name: 1, status: 1 },
|
|
6612
|
+
unique: true,
|
|
6613
|
+
name: "unique_name",
|
|
6614
|
+
partialFilterExpression: { status: { $in: ["active", "draft"] } }
|
|
6615
|
+
}
|
|
6599
6616
|
]);
|
|
6600
6617
|
} catch (error) {
|
|
6601
6618
|
throw new Error("Failed to create index on apps.");
|
|
@@ -6836,21 +6853,18 @@ function useAppService() {
|
|
|
6836
6853
|
var import_utils40 = require("@goweekdays/utils");
|
|
6837
6854
|
var import_joi20 = __toESM(require("joi"));
|
|
6838
6855
|
function useAppController() {
|
|
6839
|
-
const {
|
|
6856
|
+
const {
|
|
6857
|
+
getAll: _getAll,
|
|
6858
|
+
getById: _getById,
|
|
6859
|
+
add: _add,
|
|
6860
|
+
updateById: _updateById
|
|
6861
|
+
} = useAppRepo();
|
|
6840
6862
|
const { deleteById: _deleteById } = useAppService();
|
|
6841
6863
|
async function add(req, res, next) {
|
|
6842
6864
|
const value = req.body;
|
|
6843
|
-
const
|
|
6844
|
-
name: import_joi20.default.string().required(),
|
|
6845
|
-
school: import_joi20.default.string().hex().required(),
|
|
6846
|
-
levels: import_joi20.default.number().integer().min(1).required(),
|
|
6847
|
-
serial: import_joi20.default.string().optional().allow("", null),
|
|
6848
|
-
status: import_joi20.default.string().optional().allow("", null)
|
|
6849
|
-
});
|
|
6850
|
-
const { error } = validation.validate(value);
|
|
6865
|
+
const { error } = schemaApp.validate(value);
|
|
6851
6866
|
if (error) {
|
|
6852
6867
|
next(new import_utils40.BadRequestError(error.message));
|
|
6853
|
-
import_utils40.logger.info(`Controller: ${error.message}`);
|
|
6854
6868
|
return;
|
|
6855
6869
|
}
|
|
6856
6870
|
try {
|
|
@@ -6861,6 +6875,27 @@ function useAppController() {
|
|
|
6861
6875
|
next(error2);
|
|
6862
6876
|
}
|
|
6863
6877
|
}
|
|
6878
|
+
async function updateById(req, res, next) {
|
|
6879
|
+
const id = req.params.id ?? "";
|
|
6880
|
+
const { error: errorId } = import_joi20.default.string().hex().required().validate(id);
|
|
6881
|
+
if (errorId) {
|
|
6882
|
+
next(new import_utils40.BadRequestError(errorId.message));
|
|
6883
|
+
return;
|
|
6884
|
+
}
|
|
6885
|
+
const value = req.body;
|
|
6886
|
+
const { error } = schemaAppUpdate.validate(value);
|
|
6887
|
+
if (error) {
|
|
6888
|
+
next(new import_utils40.BadRequestError(error.message));
|
|
6889
|
+
return;
|
|
6890
|
+
}
|
|
6891
|
+
try {
|
|
6892
|
+
const result = await _updateById(req.params.id, value);
|
|
6893
|
+
res.json(result);
|
|
6894
|
+
return;
|
|
6895
|
+
} catch (error2) {
|
|
6896
|
+
next(error2);
|
|
6897
|
+
}
|
|
6898
|
+
}
|
|
6864
6899
|
async function getAll(req, res, next) {
|
|
6865
6900
|
const query = req.query;
|
|
6866
6901
|
const validation = import_joi20.default.object({
|
|
@@ -6945,6 +6980,7 @@ function useAppController() {
|
|
|
6945
6980
|
}
|
|
6946
6981
|
return {
|
|
6947
6982
|
add,
|
|
6983
|
+
updateById,
|
|
6948
6984
|
getAll,
|
|
6949
6985
|
getById,
|
|
6950
6986
|
deleteById
|
|
@@ -6961,6 +6997,11 @@ var schemaPermission = import_joi21.default.object({
|
|
|
6961
6997
|
description: import_joi21.default.string().max(1024).required(),
|
|
6962
6998
|
deprecated: import_joi21.default.boolean().optional().allow(null)
|
|
6963
6999
|
});
|
|
7000
|
+
var schemaPermissionUpdate = import_joi21.default.object({
|
|
7001
|
+
key: import_joi21.default.string().optional().allow("", null),
|
|
7002
|
+
group: import_joi21.default.string().optional().allow("", null),
|
|
7003
|
+
description: import_joi21.default.string().max(1024).optional().allow("", null)
|
|
7004
|
+
});
|
|
6964
7005
|
function modelPermission(value) {
|
|
6965
7006
|
const { error } = schemaPermission.validate(value);
|
|
6966
7007
|
if (error) {
|
|
@@ -6973,6 +7014,7 @@ function modelPermission(value) {
|
|
|
6973
7014
|
group: value.group,
|
|
6974
7015
|
description: value.description,
|
|
6975
7016
|
deprecated: value.deprecated ?? false,
|
|
7017
|
+
status: value.status ?? "active",
|
|
6976
7018
|
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
6977
7019
|
updatedAt: "",
|
|
6978
7020
|
deletedAt: ""
|
|
@@ -7038,9 +7080,13 @@ function usePermissionRepo() {
|
|
|
7038
7080
|
async function updateById(_id, value, session) {
|
|
7039
7081
|
try {
|
|
7040
7082
|
_id = new import_mongodb20.ObjectId(_id);
|
|
7041
|
-
} catch (
|
|
7083
|
+
} catch (error2) {
|
|
7042
7084
|
throw new import_utils42.BadRequestError("Invalid ID.");
|
|
7043
7085
|
}
|
|
7086
|
+
const { error } = schemaPermissionUpdate.validate(value);
|
|
7087
|
+
if (error) {
|
|
7088
|
+
throw new import_utils42.BadRequestError(`Invalid data: ${error.message}`);
|
|
7089
|
+
}
|
|
7044
7090
|
try {
|
|
7045
7091
|
const res = await collection.updateOne(
|
|
7046
7092
|
{ _id },
|
|
@@ -7049,13 +7095,13 @@ function usePermissionRepo() {
|
|
|
7049
7095
|
);
|
|
7050
7096
|
delCachedData();
|
|
7051
7097
|
return res;
|
|
7052
|
-
} catch (
|
|
7098
|
+
} catch (error2) {
|
|
7053
7099
|
import_utils42.logger.log({
|
|
7054
7100
|
level: "error",
|
|
7055
|
-
message:
|
|
7101
|
+
message: error2.message
|
|
7056
7102
|
});
|
|
7057
|
-
if (
|
|
7058
|
-
throw
|
|
7103
|
+
if (error2 instanceof import_utils42.AppError) {
|
|
7104
|
+
throw error2;
|
|
7059
7105
|
} else {
|
|
7060
7106
|
throw new Error("Failed to update permission.");
|
|
7061
7107
|
}
|
|
@@ -7066,35 +7112,27 @@ function usePermissionRepo() {
|
|
|
7066
7112
|
page = 1,
|
|
7067
7113
|
limit = 10,
|
|
7068
7114
|
sort = {},
|
|
7069
|
-
|
|
7115
|
+
app = "",
|
|
7070
7116
|
status = "active"
|
|
7071
7117
|
} = {}) {
|
|
7072
7118
|
page = page > 0 ? page - 1 : 0;
|
|
7073
|
-
const query = {
|
|
7074
|
-
status
|
|
7075
|
-
};
|
|
7076
|
-
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
7077
|
-
if (search) {
|
|
7078
|
-
query.$text = { $search: search };
|
|
7079
|
-
}
|
|
7080
|
-
if (school) {
|
|
7081
|
-
try {
|
|
7082
|
-
query.school = new import_mongodb20.ObjectId(school);
|
|
7083
|
-
} catch (error) {
|
|
7084
|
-
throw new import_utils42.BadRequestError("Invalid school ID.");
|
|
7085
|
-
}
|
|
7086
|
-
}
|
|
7119
|
+
const query = {};
|
|
7087
7120
|
const cacheParams = {
|
|
7088
7121
|
page,
|
|
7089
7122
|
limit,
|
|
7090
7123
|
sort: JSON.stringify(sort)
|
|
7091
7124
|
};
|
|
7092
|
-
|
|
7125
|
+
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
7126
|
+
query.status = status;
|
|
7127
|
+
cacheParams.status = status;
|
|
7128
|
+
if (search) {
|
|
7129
|
+
query.$text = { $search: search };
|
|
7093
7130
|
cacheParams.search = search;
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
cacheParams.
|
|
7131
|
+
}
|
|
7132
|
+
if (app) {
|
|
7133
|
+
query.app = app;
|
|
7134
|
+
cacheParams.app = app;
|
|
7135
|
+
}
|
|
7098
7136
|
const cacheKey = (0, import_utils42.makeCacheKey)(namespace_collection, cacheParams);
|
|
7099
7137
|
import_utils42.logger.log({
|
|
7100
7138
|
level: "info",
|
|
@@ -7283,7 +7321,12 @@ function usePermissionService() {
|
|
|
7283
7321
|
var import_utils43 = require("@goweekdays/utils");
|
|
7284
7322
|
var import_joi22 = __toESM(require("joi"));
|
|
7285
7323
|
function usePermissionController() {
|
|
7286
|
-
const {
|
|
7324
|
+
const {
|
|
7325
|
+
getAll: _getAll,
|
|
7326
|
+
getById: _getById,
|
|
7327
|
+
add: _add,
|
|
7328
|
+
updateById: _updateById
|
|
7329
|
+
} = usePermissionRepo();
|
|
7287
7330
|
const { deleteById: _deleteById } = usePermissionService();
|
|
7288
7331
|
async function add(req, res, next) {
|
|
7289
7332
|
const value = req.body;
|
|
@@ -7307,7 +7350,7 @@ function usePermissionController() {
|
|
|
7307
7350
|
page: import_joi22.default.number().min(1).optional().allow("", null),
|
|
7308
7351
|
limit: import_joi22.default.number().min(1).optional().allow("", null),
|
|
7309
7352
|
search: import_joi22.default.string().optional().allow("", null),
|
|
7310
|
-
|
|
7353
|
+
app: import_joi22.default.string().optional().allow("", null),
|
|
7311
7354
|
status: import_joi22.default.string().optional().allow("", null)
|
|
7312
7355
|
});
|
|
7313
7356
|
const { error } = validation.validate(query);
|
|
@@ -7326,17 +7369,17 @@ function usePermissionController() {
|
|
|
7326
7369
|
sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
|
|
7327
7370
|
});
|
|
7328
7371
|
}
|
|
7329
|
-
const
|
|
7330
|
-
const school = req.query.school ?? "";
|
|
7372
|
+
const app = req.query.app ?? "";
|
|
7331
7373
|
const search = req.query.search ?? "";
|
|
7374
|
+
const status = req.query.status ?? "active";
|
|
7332
7375
|
try {
|
|
7333
7376
|
const buildings = await _getAll({
|
|
7334
7377
|
page,
|
|
7335
7378
|
limit,
|
|
7336
7379
|
sort: sortObj,
|
|
7337
|
-
|
|
7338
|
-
|
|
7339
|
-
|
|
7380
|
+
app,
|
|
7381
|
+
search,
|
|
7382
|
+
status
|
|
7340
7383
|
});
|
|
7341
7384
|
res.json(buildings);
|
|
7342
7385
|
return;
|
|
@@ -7383,11 +7426,33 @@ function usePermissionController() {
|
|
|
7383
7426
|
next(error2);
|
|
7384
7427
|
}
|
|
7385
7428
|
}
|
|
7429
|
+
async function updateById(req, res, next) {
|
|
7430
|
+
const id = req.params.id;
|
|
7431
|
+
const { error: errorId } = import_joi22.default.string().hex().required().validate(id);
|
|
7432
|
+
if (errorId) {
|
|
7433
|
+
next(new import_utils43.BadRequestError(errorId.message));
|
|
7434
|
+
return;
|
|
7435
|
+
}
|
|
7436
|
+
const payload = req.body;
|
|
7437
|
+
const { error } = schemaPermissionUpdate.validate(payload);
|
|
7438
|
+
if (error) {
|
|
7439
|
+
next(new import_utils43.BadRequestError(error.message));
|
|
7440
|
+
return;
|
|
7441
|
+
}
|
|
7442
|
+
try {
|
|
7443
|
+
const message = await _updateById(id, payload);
|
|
7444
|
+
res.json(message);
|
|
7445
|
+
return;
|
|
7446
|
+
} catch (error2) {
|
|
7447
|
+
next(error2);
|
|
7448
|
+
}
|
|
7449
|
+
}
|
|
7386
7450
|
return {
|
|
7387
7451
|
add,
|
|
7388
7452
|
getAll,
|
|
7389
7453
|
getById,
|
|
7390
|
-
deleteById
|
|
7454
|
+
deleteById,
|
|
7455
|
+
updateById
|
|
7391
7456
|
};
|
|
7392
7457
|
}
|
|
7393
7458
|
|
|
@@ -7398,7 +7463,12 @@ var schemaPermissionGroup = import_joi23.default.object({
|
|
|
7398
7463
|
app: import_joi23.default.string().required(),
|
|
7399
7464
|
key: import_joi23.default.string().required(),
|
|
7400
7465
|
label: import_joi23.default.string().required(),
|
|
7401
|
-
order: import_joi23.default.number().integer().
|
|
7466
|
+
order: import_joi23.default.number().integer().optional().allow("", null)
|
|
7467
|
+
});
|
|
7468
|
+
var schemaPermissionGroupUpdate = import_joi23.default.object({
|
|
7469
|
+
key: import_joi23.default.string().optional().allow("", null),
|
|
7470
|
+
label: import_joi23.default.string().optional().allow("", null),
|
|
7471
|
+
order: import_joi23.default.number().integer().optional().allow("", null)
|
|
7402
7472
|
});
|
|
7403
7473
|
function modelPermissionGroup(value) {
|
|
7404
7474
|
const { error } = schemaPermissionGroup.validate(value);
|
|
@@ -7410,7 +7480,8 @@ function modelPermissionGroup(value) {
|
|
|
7410
7480
|
app: value.app,
|
|
7411
7481
|
key: value.key,
|
|
7412
7482
|
label: value.label,
|
|
7413
|
-
order: value.order,
|
|
7483
|
+
order: value.order ?? Date.now(),
|
|
7484
|
+
status: value.status ?? "active",
|
|
7414
7485
|
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
7415
7486
|
updatedAt: "",
|
|
7416
7487
|
deletedAt: ""
|
|
@@ -7439,7 +7510,7 @@ function usePermissionGroupRepo() {
|
|
|
7439
7510
|
name: "text_index"
|
|
7440
7511
|
},
|
|
7441
7512
|
{
|
|
7442
|
-
key: { app: 1, key: 1 },
|
|
7513
|
+
key: { app: 1, key: 1, label: 1 },
|
|
7443
7514
|
unique: true,
|
|
7444
7515
|
name: "unique_permission_group"
|
|
7445
7516
|
}
|
|
@@ -7476,9 +7547,13 @@ function usePermissionGroupRepo() {
|
|
|
7476
7547
|
async function updateById(_id, value, session) {
|
|
7477
7548
|
try {
|
|
7478
7549
|
_id = new import_mongodb21.ObjectId(_id);
|
|
7479
|
-
} catch (
|
|
7550
|
+
} catch (error2) {
|
|
7480
7551
|
throw new import_utils45.BadRequestError("Invalid ID.");
|
|
7481
7552
|
}
|
|
7553
|
+
const { error } = schemaPermissionGroupUpdate.validate(value);
|
|
7554
|
+
if (error) {
|
|
7555
|
+
throw new import_utils45.BadRequestError(`Invalid data: ${error.message}`);
|
|
7556
|
+
}
|
|
7482
7557
|
try {
|
|
7483
7558
|
const res = await collection.updateOne(
|
|
7484
7559
|
{ _id },
|
|
@@ -7487,13 +7562,13 @@ function usePermissionGroupRepo() {
|
|
|
7487
7562
|
);
|
|
7488
7563
|
delCachedData();
|
|
7489
7564
|
return res;
|
|
7490
|
-
} catch (
|
|
7565
|
+
} catch (error2) {
|
|
7491
7566
|
import_utils45.logger.log({
|
|
7492
7567
|
level: "error",
|
|
7493
|
-
message:
|
|
7568
|
+
message: error2.message
|
|
7494
7569
|
});
|
|
7495
|
-
if (
|
|
7496
|
-
throw
|
|
7570
|
+
if (error2 instanceof import_utils45.AppError) {
|
|
7571
|
+
throw error2;
|
|
7497
7572
|
} else {
|
|
7498
7573
|
throw new Error("Failed to update permission group.");
|
|
7499
7574
|
}
|
|
@@ -7504,35 +7579,27 @@ function usePermissionGroupRepo() {
|
|
|
7504
7579
|
page = 1,
|
|
7505
7580
|
limit = 10,
|
|
7506
7581
|
sort = {},
|
|
7507
|
-
|
|
7582
|
+
app = "",
|
|
7508
7583
|
status = "active"
|
|
7509
7584
|
} = {}) {
|
|
7510
7585
|
page = page > 0 ? page - 1 : 0;
|
|
7511
|
-
const query = {
|
|
7512
|
-
status
|
|
7513
|
-
};
|
|
7514
|
-
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
7515
|
-
if (search) {
|
|
7516
|
-
query.$text = { $search: search };
|
|
7517
|
-
}
|
|
7518
|
-
if (school) {
|
|
7519
|
-
try {
|
|
7520
|
-
query.school = new import_mongodb21.ObjectId(school);
|
|
7521
|
-
} catch (error) {
|
|
7522
|
-
throw new import_utils45.BadRequestError("Invalid school ID.");
|
|
7523
|
-
}
|
|
7524
|
-
}
|
|
7586
|
+
const query = {};
|
|
7525
7587
|
const cacheParams = {
|
|
7526
7588
|
page,
|
|
7527
7589
|
limit,
|
|
7528
7590
|
sort: JSON.stringify(sort)
|
|
7529
7591
|
};
|
|
7530
|
-
|
|
7592
|
+
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
7593
|
+
query.status = status;
|
|
7594
|
+
cacheParams.status = status;
|
|
7595
|
+
if (search) {
|
|
7596
|
+
query.$text = { $search: search };
|
|
7531
7597
|
cacheParams.search = search;
|
|
7532
|
-
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
-
cacheParams.
|
|
7598
|
+
}
|
|
7599
|
+
if (app) {
|
|
7600
|
+
query.app = app;
|
|
7601
|
+
cacheParams.app = app;
|
|
7602
|
+
}
|
|
7536
7603
|
const cacheKey = (0, import_utils45.makeCacheKey)(namespace_collection, cacheParams);
|
|
7537
7604
|
import_utils45.logger.log({
|
|
7538
7605
|
level: "info",
|
|
@@ -7697,7 +7764,8 @@ function usePermissionGroupController() {
|
|
|
7697
7764
|
const {
|
|
7698
7765
|
getAll: _getAll,
|
|
7699
7766
|
getById: _getById,
|
|
7700
|
-
add: _add
|
|
7767
|
+
add: _add,
|
|
7768
|
+
updateById: _updateById
|
|
7701
7769
|
} = usePermissionGroupRepo();
|
|
7702
7770
|
const { deleteById: _deleteById } = usePermissionGroupService();
|
|
7703
7771
|
async function add(req, res, next) {
|
|
@@ -7722,7 +7790,7 @@ function usePermissionGroupController() {
|
|
|
7722
7790
|
page: import_joi24.default.number().min(1).optional().allow("", null),
|
|
7723
7791
|
limit: import_joi24.default.number().min(1).optional().allow("", null),
|
|
7724
7792
|
search: import_joi24.default.string().optional().allow("", null),
|
|
7725
|
-
|
|
7793
|
+
app: import_joi24.default.string().optional().allow("", null),
|
|
7726
7794
|
status: import_joi24.default.string().optional().allow("", null)
|
|
7727
7795
|
});
|
|
7728
7796
|
const { error } = validation.validate(query);
|
|
@@ -7741,17 +7809,17 @@ function usePermissionGroupController() {
|
|
|
7741
7809
|
sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
|
|
7742
7810
|
});
|
|
7743
7811
|
}
|
|
7744
|
-
const
|
|
7745
|
-
const school = req.query.school ?? "";
|
|
7812
|
+
const app = req.query.app ?? "";
|
|
7746
7813
|
const search = req.query.search ?? "";
|
|
7814
|
+
const status = req.query.status ?? "active";
|
|
7747
7815
|
try {
|
|
7748
7816
|
const buildings = await _getAll({
|
|
7749
7817
|
page,
|
|
7750
7818
|
limit,
|
|
7751
7819
|
sort: sortObj,
|
|
7752
|
-
|
|
7753
|
-
|
|
7754
|
-
|
|
7820
|
+
app,
|
|
7821
|
+
search,
|
|
7822
|
+
status
|
|
7755
7823
|
});
|
|
7756
7824
|
res.json(buildings);
|
|
7757
7825
|
return;
|
|
@@ -7798,11 +7866,33 @@ function usePermissionGroupController() {
|
|
|
7798
7866
|
next(error2);
|
|
7799
7867
|
}
|
|
7800
7868
|
}
|
|
7869
|
+
async function updateById(req, res, next) {
|
|
7870
|
+
const id = req.params.id;
|
|
7871
|
+
const { error: errorId } = import_joi24.default.string().hex().required().validate(id);
|
|
7872
|
+
if (errorId) {
|
|
7873
|
+
next(new import_utils46.BadRequestError(errorId.message));
|
|
7874
|
+
return;
|
|
7875
|
+
}
|
|
7876
|
+
const payload = req.body;
|
|
7877
|
+
const { error } = schemaPermissionGroupUpdate.validate(payload);
|
|
7878
|
+
if (error) {
|
|
7879
|
+
next(new import_utils46.BadRequestError(error.message));
|
|
7880
|
+
return;
|
|
7881
|
+
}
|
|
7882
|
+
try {
|
|
7883
|
+
const message = await _updateById(id, payload);
|
|
7884
|
+
res.json(message);
|
|
7885
|
+
return;
|
|
7886
|
+
} catch (error2) {
|
|
7887
|
+
next(error2);
|
|
7888
|
+
}
|
|
7889
|
+
}
|
|
7801
7890
|
return {
|
|
7802
7891
|
add,
|
|
7803
7892
|
getAll,
|
|
7804
7893
|
getById,
|
|
7805
|
-
deleteById
|
|
7894
|
+
deleteById,
|
|
7895
|
+
updateById
|
|
7806
7896
|
};
|
|
7807
7897
|
}
|
|
7808
7898
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -7860,12 +7950,15 @@ function usePermissionGroupController() {
|
|
|
7860
7950
|
modelPermission,
|
|
7861
7951
|
modelPermissionGroup,
|
|
7862
7952
|
schemaApp,
|
|
7953
|
+
schemaAppUpdate,
|
|
7863
7954
|
schemaBuilding,
|
|
7864
7955
|
schemaBuildingUnit,
|
|
7865
7956
|
schemaOrg,
|
|
7866
7957
|
schemaPSGC,
|
|
7867
7958
|
schemaPermission,
|
|
7868
7959
|
schemaPermissionGroup,
|
|
7960
|
+
schemaPermissionGroupUpdate,
|
|
7961
|
+
schemaPermissionUpdate,
|
|
7869
7962
|
schemaUpdateOptions,
|
|
7870
7963
|
transactionSchema,
|
|
7871
7964
|
useAddressController,
|