@churchsoln/dbms 1.0.47 → 1.0.49
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/Dockerfile +21 -21
- package/Makefile +132 -132
- package/app.js +37 -37
- package/config/config.js +33 -33
- package/config/errorCodes.js +65 -65
- package/config/errorMsgs.js +82 -82
- package/constants/index.js +94 -94
- package/controllers/church.js +100 -100
- package/controllers/index.js +6 -6
- package/controllers/master.js +138 -138
- package/controllers/migration.js +24 -24
- package/controllers/seed.js +33 -33
- package/db-setup.js +87 -87
- package/deployment/docker-compose.local.yml +64 -64
- package/deployment/docker-compose.yml +62 -62
- package/deployment/nginx/nginx-certs/localhost.crt +22 -22
- package/deployment/nginx/nginx-certs/localhost.key +28 -28
- package/deployment/nginx/nginx.local.conf +72 -72
- package/middlewares/church-filter.js +16 -16
- package/migrations/church/20221226151615-create-province.js +27 -27
- package/migrations/church/20221226151616-create-city.js +41 -41
- package/migrations/church/20221226151617-create-subRole.js +25 -25
- package/migrations/church/20221226151618-create-membership.js +68 -68
- package/migrations/church/20221226151619-create-member.js +140 -140
- package/migrations/church/20221227151615-create-user.js +60 -60
- package/migrations/church/20230826140644-create-eventsUpdates.js +29 -29
- package/migrations/church/20230904143429-create-ministries.js +26 -26
- package/migrations/church/20231021160018-create-gallery.js +28 -28
- package/migrations/church/20231105074019-create-feedback.js +28 -28
- package/migrations/church/20231111113342-create-banner.js +29 -29
- package/migrations/church/20231216105640-create-directoryBoard.js +31 -31
- package/migrations/church/20240214160101-create-volunteer.js +31 -31
- package/migrations/church/20240330111437-create-download.js +29 -29
- package/migrations/church/20240427170617-create-links.js +26 -26
- package/migrations/church/20240815170617-create-userTransfer.js +63 -63
- package/migrations/church/20240815170620-create-subRolePermission.js +40 -40
- package/migrations/church/20240915170620-create-transferType.js +25 -25
- package/migrations/church/20240917170620-create-accounts.js +27 -27
- package/migrations/church/20240918170621-create-church.js +54 -54
- package/migrations/church/20240918170622-create-group.js +61 -61
- package/migrations/church/20240918170623-create-groupMembers.js +74 -74
- package/migrations/church/20240918170627-create-pledge.js +96 -96
- package/migrations/church/20240919170627-create-contributionBatch.js +42 -42
- package/migrations/church/20240919170628-create-contributionTransaction.js +82 -82
- package/migrations/church/20240919170629-create-contributionTransactionLine.js +74 -74
- package/migrations/church/20240919170630-update-groupMembers.js +77 -77
- package/migrations/church/20241204170631-create-pledgeAccount.js +55 -55
- package/migrations/church/20241204170632-create-memberStatus.js +26 -0
- package/migrations/church/20241204170633-update-member.js +33 -0
- package/migrations/church/20241204170634-update-membership.js +33 -0
- package/migrations/church/20241204170635-update-pledge.js +33 -0
- package/migrations/church/20241204170636-update-contributionTransactionLine.js +33 -0
- package/migrations/common/20221226140655-create-subscriptionPlan.js +31 -31
- package/migrations/common/20221226143006-create-role.js +25 -25
- package/migrations/common/20240815170619-create-permission.js +27 -27
- package/migrations/common/20240815170620-create-church.js +56 -56
- package/migrations/common/20240815170621-create-churchDomain.js +40 -40
- package/migrations/common/20240918170621-create-churchPermission.js +53 -53
- package/migrations/common/20240918170622-create-user.js +35 -35
- package/migrations/common/20240918170627-create-subscriptionPlanPermission.js +53 -53
- package/models/church/accounts.js +23 -27
- package/models/church/banner.js +29 -29
- package/models/church/church.js +62 -62
- package/models/church/city.js +23 -23
- package/models/church/contributionBatch.js +45 -45
- package/models/church/contributionTransaction.js +90 -90
- package/models/church/contributionTransactionLine.js +81 -80
- package/models/church/directoryBoard.js +33 -33
- package/models/church/download.js +35 -35
- package/models/church/eventsUpdates.js +29 -29
- package/models/church/feedback.js +27 -27
- package/models/church/gallery.js +33 -33
- package/models/church/group.js +78 -78
- package/models/church/groupMembers.js +73 -73
- package/models/church/index.js +30 -30
- package/models/church/links.js +22 -22
- package/models/church/member.js +161 -171
- package/models/church/memberStatus.js +22 -0
- package/models/church/membership.js +80 -81
- package/models/church/ministries.js +16 -16
- package/models/church/pledge.js +65 -65
- package/models/church/pledgeAccount.js +45 -37
- package/models/church/province.js +23 -23
- package/models/church/subRole.js +21 -21
- package/models/church/subRolePermission.js +22 -22
- package/models/church/transferType.js +15 -15
- package/models/church/user.js +78 -78
- package/models/church/userTransfer.js +45 -45
- package/models/church/volunteer.js +33 -33
- package/models/common/church.js +58 -58
- package/models/common/churchDomain.js +21 -21
- package/models/common/churchPermission.js +26 -26
- package/models/common/index.js +40 -40
- package/models/common/permission.js +17 -17
- package/models/common/role.js +15 -15
- package/models/common/subscriptionPlan.js +34 -34
- package/models/common/subscriptionPlanPermission.js +33 -33
- package/models/common/user.js +39 -39
- package/package.json +41 -41
- package/public/swagger/church.json +521 -521
- package/public/swagger/master.json +537 -537
- package/public/swagger/migration.json +83 -83
- package/public/swagger/seed.json +98 -98
- package/queues/db-create.js +9 -9
- package/queues/index.js +5 -5
- package/queues/master.js +9 -9
- package/queues/migration.js +9 -9
- package/queues/seed.js +9 -9
- package/redis/config.js +5 -5
- package/routes/index.js +30 -30
- package/routes/v1/church.js +45 -45
- package/routes/v1/index.js +7 -7
- package/routes/v1/master.js +68 -68
- package/routes/v1/migration.js +10 -10
- package/routes/v1/seed.js +12 -12
- package/seeders/church/20241005124245-province.js +101 -101
- package/seeders/church/20241005124547-city.js +87 -87
- package/seeders/church/20241005131418-transferType.js +40 -40
- package/seeders/church/20241005131419-memberStatus.js +34 -0
- package/seeders/common/20241005123516-subscriptionPlan.js +43 -43
- package/seeders/common/20241005124105-role.js +38 -38
- package/seeders/common/20241005153047-permission.js +252 -242
- package/seeders/common/20241005153048-user.js +48 -48
- package/services/church.js +312 -312
- package/services/index.js +6 -6
- package/services/master.js +344 -344
- package/services/migration.js +30 -30
- package/services/seed.js +39 -39
- package/utils/churchManager.js +98 -98
- package/utils/crypto.js +40 -40
- package/utils/docUpload.js +51 -51
- package/utils/encryptDecrypt.js +26 -26
- package/utils/index.js +33 -33
- package/utils/logger.js +104 -104
- package/utils/response.js +108 -108
- package/utils/swagger.js +25 -25
- package/utils/verifyToken.js +58 -58
- package/validators/church.js +154 -154
- package/validators/index.js +3 -3
- package/validators/master.js +152 -152
- package/workers/db-create.js +37 -37
- package/workers/index.js +4 -4
- package/workers/master.js +50 -50
- package/workers/migrations.js +63 -63
- package/workers/seed.js +85 -85
package/validators/church.js
CHANGED
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
const BaseJoi = require("joi");
|
|
2
|
-
const response = require("../utils/response");
|
|
3
|
-
const permission = require("../models/common/permission");
|
|
4
|
-
const { SUBSCRIPTION_PLAN_ID } = require("../constants");
|
|
5
|
-
const schemas = {
|
|
6
|
-
onboardChurch: BaseJoi.object({
|
|
7
|
-
name: BaseJoi.string()
|
|
8
|
-
.max(20)
|
|
9
|
-
.regex(/^[a-zA-Z]+$/)
|
|
10
|
-
.required(),
|
|
11
|
-
email: BaseJoi.string().required(),
|
|
12
|
-
phoneNumber: BaseJoi.string().required(),
|
|
13
|
-
contactPerson: BaseJoi.string().optional().allow(null),
|
|
14
|
-
subscriptionPlanId: BaseJoi.number().required(),
|
|
15
|
-
validity: BaseJoi.number().required(),
|
|
16
|
-
permissionId: BaseJoi.array().items(BaseJoi.number().required()).when("subscriptionPlanId", {
|
|
17
|
-
is: BaseJoi.number().valid(SUBSCRIPTION_PLAN_ID.CUSTOM),
|
|
18
|
-
then: BaseJoi.required(),
|
|
19
|
-
otherwise: BaseJoi.optional(),
|
|
20
|
-
}),
|
|
21
|
-
churchAdminDetails: BaseJoi.object({
|
|
22
|
-
username: BaseJoi.string().required(),
|
|
23
|
-
email: BaseJoi.string().required(),
|
|
24
|
-
password: BaseJoi.string().required(),
|
|
25
|
-
firstName: BaseJoi.string().required(),
|
|
26
|
-
lastName: BaseJoi.string().required()
|
|
27
|
-
}).required(),
|
|
28
|
-
}),
|
|
29
|
-
updateChurch: BaseJoi.object({
|
|
30
|
-
id: BaseJoi.number().required(),
|
|
31
|
-
name: BaseJoi.string().optional(),
|
|
32
|
-
email: BaseJoi.string().optional(),
|
|
33
|
-
phoneNumber: BaseJoi.string().optional(),
|
|
34
|
-
contactPerson: BaseJoi.string().optional(),
|
|
35
|
-
subscriptionPlanId: BaseJoi.number().optional(),
|
|
36
|
-
validity: BaseJoi.number().when('subscriptionPlanId', {
|
|
37
|
-
is: BaseJoi.exist(),
|
|
38
|
-
then: BaseJoi.required(),
|
|
39
|
-
otherwise: BaseJoi.optional()
|
|
40
|
-
}),
|
|
41
|
-
permissionId: BaseJoi.array()
|
|
42
|
-
.items(BaseJoi.number().required())
|
|
43
|
-
.optional()
|
|
44
|
-
.when("subscriptionPlanId", {
|
|
45
|
-
is: BaseJoi.number().valid(SUBSCRIPTION_PLAN_ID.CUSTOM),
|
|
46
|
-
then: BaseJoi.required(),
|
|
47
|
-
otherwise: BaseJoi.optional(),
|
|
48
|
-
}),
|
|
49
|
-
status: BaseJoi.boolean().optional(),
|
|
50
|
-
}),
|
|
51
|
-
addChurchPermission: BaseJoi.object({
|
|
52
|
-
churchId: BaseJoi.number().required(),
|
|
53
|
-
permissionId: BaseJoi.array().items(BaseJoi.number().required()),
|
|
54
|
-
}),
|
|
55
|
-
getByChurchId: BaseJoi.object({
|
|
56
|
-
churchId: BaseJoi.number().required(),
|
|
57
|
-
}),
|
|
58
|
-
getChurchById: BaseJoi.object({
|
|
59
|
-
id: BaseJoi.number().required(),
|
|
60
|
-
churchId: BaseJoi.number().required(),
|
|
61
|
-
}),
|
|
62
|
-
login: BaseJoi.object({
|
|
63
|
-
username: BaseJoi.string().required(),
|
|
64
|
-
password: BaseJoi.string().required(),
|
|
65
|
-
}),
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const options = {
|
|
69
|
-
basic: {
|
|
70
|
-
abortEarly: false,
|
|
71
|
-
convert: true,
|
|
72
|
-
allowUnknown: false,
|
|
73
|
-
stripUnknown: false,
|
|
74
|
-
},
|
|
75
|
-
array: {
|
|
76
|
-
abortEarly: false,
|
|
77
|
-
convert: true,
|
|
78
|
-
allowUnknown: false,
|
|
79
|
-
stripUnknown: {
|
|
80
|
-
objects: false,
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
const onboardChurch = async (req, res, next) => {
|
|
85
|
-
const { onboardChurch } = schemas;
|
|
86
|
-
const { basic } = options;
|
|
87
|
-
try {
|
|
88
|
-
await onboardChurch.validateAsync({ ...req.body }, basic);
|
|
89
|
-
next();
|
|
90
|
-
} catch (err) {
|
|
91
|
-
throwError(req, res, err);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
const updateChurch = async (req, res, next) => {
|
|
95
|
-
const { updateChurch } = schemas;
|
|
96
|
-
const { basic } = options;
|
|
97
|
-
try {
|
|
98
|
-
await updateChurch.validateAsync({ ...req.params, ...req.body }, basic);
|
|
99
|
-
next();
|
|
100
|
-
} catch (err) {
|
|
101
|
-
throwError(req, res, err);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
const addChurchPermission = async (req, res, next) => {
|
|
105
|
-
const { addChurchPermission } = schemas;
|
|
106
|
-
const { basic } = options;
|
|
107
|
-
try {
|
|
108
|
-
await addChurchPermission.validateAsync({ ...req.body, ...req.params }, basic);
|
|
109
|
-
next();
|
|
110
|
-
} catch (err) {
|
|
111
|
-
throwError(req, res, err);
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
const getByChurchId = async (req, res, next) => {
|
|
115
|
-
const { getByChurchId } = schemas;
|
|
116
|
-
const { basic } = options;
|
|
117
|
-
try {
|
|
118
|
-
await getByChurchId.validateAsync({ ...req.params }, basic);
|
|
119
|
-
next();
|
|
120
|
-
} catch (err) {
|
|
121
|
-
throwError(req, res, err);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
const getChurchById = async (req, res, next) => {
|
|
125
|
-
const { getChurchById } = schemas;
|
|
126
|
-
const { basic } = options;
|
|
127
|
-
try {
|
|
128
|
-
await getChurchById.validateAsync({ ...req.params }, basic);
|
|
129
|
-
next();
|
|
130
|
-
} catch (err) {
|
|
131
|
-
throwError(req, res, err);
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
const login = async (req, res, next) => {
|
|
135
|
-
const { login } = schemas;
|
|
136
|
-
const { basic } = options;
|
|
137
|
-
try {
|
|
138
|
-
await login.validateAsync({ ...req.body }, basic);
|
|
139
|
-
next();
|
|
140
|
-
} catch (err) {
|
|
141
|
-
throwError(req, res, err);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
const throwError = (req, res, err) => {
|
|
145
|
-
return response.joierrors(req, res, err);
|
|
146
|
-
};
|
|
147
|
-
module.exports = {
|
|
148
|
-
onboardChurch,
|
|
149
|
-
updateChurch,
|
|
150
|
-
addChurchPermission,
|
|
151
|
-
getByChurchId,
|
|
152
|
-
getChurchById,
|
|
153
|
-
login,
|
|
154
|
-
};
|
|
1
|
+
const BaseJoi = require("joi");
|
|
2
|
+
const response = require("../utils/response");
|
|
3
|
+
const permission = require("../models/common/permission");
|
|
4
|
+
const { SUBSCRIPTION_PLAN_ID } = require("../constants");
|
|
5
|
+
const schemas = {
|
|
6
|
+
onboardChurch: BaseJoi.object({
|
|
7
|
+
name: BaseJoi.string()
|
|
8
|
+
.max(20)
|
|
9
|
+
.regex(/^[a-zA-Z]+$/)
|
|
10
|
+
.required(),
|
|
11
|
+
email: BaseJoi.string().required(),
|
|
12
|
+
phoneNumber: BaseJoi.string().required(),
|
|
13
|
+
contactPerson: BaseJoi.string().optional().allow(null),
|
|
14
|
+
subscriptionPlanId: BaseJoi.number().required(),
|
|
15
|
+
validity: BaseJoi.number().required(),
|
|
16
|
+
permissionId: BaseJoi.array().items(BaseJoi.number().required()).when("subscriptionPlanId", {
|
|
17
|
+
is: BaseJoi.number().valid(SUBSCRIPTION_PLAN_ID.CUSTOM),
|
|
18
|
+
then: BaseJoi.required(),
|
|
19
|
+
otherwise: BaseJoi.optional(),
|
|
20
|
+
}),
|
|
21
|
+
churchAdminDetails: BaseJoi.object({
|
|
22
|
+
username: BaseJoi.string().required(),
|
|
23
|
+
email: BaseJoi.string().required(),
|
|
24
|
+
password: BaseJoi.string().required(),
|
|
25
|
+
firstName: BaseJoi.string().required(),
|
|
26
|
+
lastName: BaseJoi.string().required()
|
|
27
|
+
}).required(),
|
|
28
|
+
}),
|
|
29
|
+
updateChurch: BaseJoi.object({
|
|
30
|
+
id: BaseJoi.number().required(),
|
|
31
|
+
name: BaseJoi.string().optional(),
|
|
32
|
+
email: BaseJoi.string().optional(),
|
|
33
|
+
phoneNumber: BaseJoi.string().optional(),
|
|
34
|
+
contactPerson: BaseJoi.string().optional(),
|
|
35
|
+
subscriptionPlanId: BaseJoi.number().optional(),
|
|
36
|
+
validity: BaseJoi.number().when('subscriptionPlanId', {
|
|
37
|
+
is: BaseJoi.exist(),
|
|
38
|
+
then: BaseJoi.required(),
|
|
39
|
+
otherwise: BaseJoi.optional()
|
|
40
|
+
}),
|
|
41
|
+
permissionId: BaseJoi.array()
|
|
42
|
+
.items(BaseJoi.number().required())
|
|
43
|
+
.optional()
|
|
44
|
+
.when("subscriptionPlanId", {
|
|
45
|
+
is: BaseJoi.number().valid(SUBSCRIPTION_PLAN_ID.CUSTOM),
|
|
46
|
+
then: BaseJoi.required(),
|
|
47
|
+
otherwise: BaseJoi.optional(),
|
|
48
|
+
}),
|
|
49
|
+
status: BaseJoi.boolean().optional(),
|
|
50
|
+
}),
|
|
51
|
+
addChurchPermission: BaseJoi.object({
|
|
52
|
+
churchId: BaseJoi.number().required(),
|
|
53
|
+
permissionId: BaseJoi.array().items(BaseJoi.number().required()),
|
|
54
|
+
}),
|
|
55
|
+
getByChurchId: BaseJoi.object({
|
|
56
|
+
churchId: BaseJoi.number().required(),
|
|
57
|
+
}),
|
|
58
|
+
getChurchById: BaseJoi.object({
|
|
59
|
+
id: BaseJoi.number().required(),
|
|
60
|
+
churchId: BaseJoi.number().required(),
|
|
61
|
+
}),
|
|
62
|
+
login: BaseJoi.object({
|
|
63
|
+
username: BaseJoi.string().required(),
|
|
64
|
+
password: BaseJoi.string().required(),
|
|
65
|
+
}),
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const options = {
|
|
69
|
+
basic: {
|
|
70
|
+
abortEarly: false,
|
|
71
|
+
convert: true,
|
|
72
|
+
allowUnknown: false,
|
|
73
|
+
stripUnknown: false,
|
|
74
|
+
},
|
|
75
|
+
array: {
|
|
76
|
+
abortEarly: false,
|
|
77
|
+
convert: true,
|
|
78
|
+
allowUnknown: false,
|
|
79
|
+
stripUnknown: {
|
|
80
|
+
objects: false,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
const onboardChurch = async (req, res, next) => {
|
|
85
|
+
const { onboardChurch } = schemas;
|
|
86
|
+
const { basic } = options;
|
|
87
|
+
try {
|
|
88
|
+
await onboardChurch.validateAsync({ ...req.body }, basic);
|
|
89
|
+
next();
|
|
90
|
+
} catch (err) {
|
|
91
|
+
throwError(req, res, err);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const updateChurch = async (req, res, next) => {
|
|
95
|
+
const { updateChurch } = schemas;
|
|
96
|
+
const { basic } = options;
|
|
97
|
+
try {
|
|
98
|
+
await updateChurch.validateAsync({ ...req.params, ...req.body }, basic);
|
|
99
|
+
next();
|
|
100
|
+
} catch (err) {
|
|
101
|
+
throwError(req, res, err);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const addChurchPermission = async (req, res, next) => {
|
|
105
|
+
const { addChurchPermission } = schemas;
|
|
106
|
+
const { basic } = options;
|
|
107
|
+
try {
|
|
108
|
+
await addChurchPermission.validateAsync({ ...req.body, ...req.params }, basic);
|
|
109
|
+
next();
|
|
110
|
+
} catch (err) {
|
|
111
|
+
throwError(req, res, err);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const getByChurchId = async (req, res, next) => {
|
|
115
|
+
const { getByChurchId } = schemas;
|
|
116
|
+
const { basic } = options;
|
|
117
|
+
try {
|
|
118
|
+
await getByChurchId.validateAsync({ ...req.params }, basic);
|
|
119
|
+
next();
|
|
120
|
+
} catch (err) {
|
|
121
|
+
throwError(req, res, err);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const getChurchById = async (req, res, next) => {
|
|
125
|
+
const { getChurchById } = schemas;
|
|
126
|
+
const { basic } = options;
|
|
127
|
+
try {
|
|
128
|
+
await getChurchById.validateAsync({ ...req.params }, basic);
|
|
129
|
+
next();
|
|
130
|
+
} catch (err) {
|
|
131
|
+
throwError(req, res, err);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
const login = async (req, res, next) => {
|
|
135
|
+
const { login } = schemas;
|
|
136
|
+
const { basic } = options;
|
|
137
|
+
try {
|
|
138
|
+
await login.validateAsync({ ...req.body }, basic);
|
|
139
|
+
next();
|
|
140
|
+
} catch (err) {
|
|
141
|
+
throwError(req, res, err);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const throwError = (req, res, err) => {
|
|
145
|
+
return response.joierrors(req, res, err);
|
|
146
|
+
};
|
|
147
|
+
module.exports = {
|
|
148
|
+
onboardChurch,
|
|
149
|
+
updateChurch,
|
|
150
|
+
addChurchPermission,
|
|
151
|
+
getByChurchId,
|
|
152
|
+
getChurchById,
|
|
153
|
+
login,
|
|
154
|
+
};
|
package/validators/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const tenant = require("./church");
|
|
2
|
-
const master = require("./master");
|
|
3
|
-
module.exports = { ...tenant, ...master };
|
|
1
|
+
const tenant = require("./church");
|
|
2
|
+
const master = require("./master");
|
|
3
|
+
module.exports = { ...tenant, ...master };
|
package/validators/master.js
CHANGED
|
@@ -1,153 +1,153 @@
|
|
|
1
|
-
const BaseJoi = require("joi");
|
|
2
|
-
const response = require("../utils/response");
|
|
3
|
-
const { add } = require("winston");
|
|
4
|
-
const schemas = {
|
|
5
|
-
getById: BaseJoi.object({
|
|
6
|
-
id: BaseJoi.number().required(),
|
|
7
|
-
}),
|
|
8
|
-
updateById: BaseJoi.object({
|
|
9
|
-
id: BaseJoi.number().required(),
|
|
10
|
-
name: BaseJoi.string().required(),
|
|
11
|
-
}),
|
|
12
|
-
addMaster: BaseJoi.object({
|
|
13
|
-
name: BaseJoi.string().required(),
|
|
14
|
-
}),
|
|
15
|
-
addSubscriptionPlan: BaseJoi.object({
|
|
16
|
-
name: BaseJoi.string().required(),
|
|
17
|
-
subscriptionPlanPermission: BaseJoi.array().items({
|
|
18
|
-
permissionId: BaseJoi.number().required(),
|
|
19
|
-
}),
|
|
20
|
-
}),
|
|
21
|
-
updateSubscriptionPlan: BaseJoi.object({
|
|
22
|
-
id: BaseJoi.number().required(),
|
|
23
|
-
name: BaseJoi.string().required(),
|
|
24
|
-
subscriptionPlanPermission: BaseJoi.array().items({
|
|
25
|
-
permissionId: BaseJoi.number().required(),
|
|
26
|
-
}),
|
|
27
|
-
}),
|
|
28
|
-
addCity: BaseJoi.object({
|
|
29
|
-
provinceId: BaseJoi.number().required(),
|
|
30
|
-
name: BaseJoi.string().required(),
|
|
31
|
-
}),
|
|
32
|
-
allCities: BaseJoi.object({
|
|
33
|
-
provinceId: BaseJoi.number().required(),
|
|
34
|
-
}),
|
|
35
|
-
addPermission: BaseJoi.object({
|
|
36
|
-
name: BaseJoi.string().required(),
|
|
37
|
-
permission: BaseJoi.array().items({
|
|
38
|
-
permissionId: BaseJoi.number().required(),
|
|
39
|
-
}),
|
|
40
|
-
}),
|
|
41
|
-
}
|
|
42
|
-
const options = {
|
|
43
|
-
basic: {
|
|
44
|
-
abortEarly: false,
|
|
45
|
-
convert: true,
|
|
46
|
-
allowUnknown: false,
|
|
47
|
-
stripUnknown: true,
|
|
48
|
-
},
|
|
49
|
-
array: {
|
|
50
|
-
abortEarly: false,
|
|
51
|
-
convert: true,
|
|
52
|
-
allowUnknown: true,
|
|
53
|
-
stripUnknown: {
|
|
54
|
-
objects: true,
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const updateById = async (req, res, next) => {
|
|
60
|
-
const { updateById } = schemas;
|
|
61
|
-
const { basic } = options;
|
|
62
|
-
try {
|
|
63
|
-
await updateById.validateAsync({ ...req.params, ...req.body }, basic);
|
|
64
|
-
next();
|
|
65
|
-
} catch (err) {
|
|
66
|
-
throwError(req, res, err);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
const addMaster = async (req, res, next) => {
|
|
70
|
-
const { addMaster } = schemas;
|
|
71
|
-
const { basic } = options;
|
|
72
|
-
try {
|
|
73
|
-
await addMaster.validateAsync({ ...req.body }, basic);
|
|
74
|
-
next();
|
|
75
|
-
} catch (err) {
|
|
76
|
-
throwError(req, res, err);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
const addSubscriptionPlan = async (req, res, next) => {
|
|
80
|
-
const { addSubscriptionPlan } = schemas;
|
|
81
|
-
const { basic } = options;
|
|
82
|
-
try {
|
|
83
|
-
await addSubscriptionPlan.validateAsync({ ...req.body }, basic);
|
|
84
|
-
next();
|
|
85
|
-
} catch (err) {
|
|
86
|
-
throwError(req, res, err);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const updateSubscriptionPlan = async (req, res, next) => {
|
|
91
|
-
const { updateSubscriptionPlan } = schemas;
|
|
92
|
-
const { basic } = options;
|
|
93
|
-
try {
|
|
94
|
-
await updateSubscriptionPlan.validateAsync({ ...req.params, ...req.body }, basic);
|
|
95
|
-
next();
|
|
96
|
-
} catch (err) {
|
|
97
|
-
throwError(req, res, err);
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
const getById = async (req, res, next) => {
|
|
101
|
-
const { getById } = schemas;
|
|
102
|
-
const { basic } = options;
|
|
103
|
-
try {
|
|
104
|
-
await getById.validateAsync({ ...req.params }, basic);
|
|
105
|
-
next();
|
|
106
|
-
} catch (err) {
|
|
107
|
-
throwError(req, res, err);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
const allCities = async (req, res, next) => {
|
|
111
|
-
const { allCities } = schemas;
|
|
112
|
-
const { basic } = options;
|
|
113
|
-
try {
|
|
114
|
-
await allCities.validateAsync({ ...req.query }, basic);
|
|
115
|
-
next();
|
|
116
|
-
} catch (err) {
|
|
117
|
-
throwError(req, res, err);
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
const addCity = async (req, res, next) => {
|
|
121
|
-
const { addCity } = schemas;
|
|
122
|
-
const { basic } = options;
|
|
123
|
-
try {
|
|
124
|
-
await addCity.validateAsync({ ...req.query, ...req.body }, basic);
|
|
125
|
-
next();
|
|
126
|
-
} catch (err) {
|
|
127
|
-
throwError(req, res, err);
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
const addPermission = async (req, res, next) => {
|
|
131
|
-
const { addPermission } = schemas;
|
|
132
|
-
const { basic } = options;
|
|
133
|
-
try {
|
|
134
|
-
await addPermission.validateAsync({ ...req.body }, basic);
|
|
135
|
-
next();
|
|
136
|
-
} catch (err) {
|
|
137
|
-
throwError(req, res, err);
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const throwError = (req, res, err) => {
|
|
142
|
-
return response.joierrors(req, res, err);
|
|
143
|
-
};
|
|
144
|
-
module.exports = {
|
|
145
|
-
getById,
|
|
146
|
-
updateById,
|
|
147
|
-
addMaster,
|
|
148
|
-
addSubscriptionPlan,
|
|
149
|
-
updateSubscriptionPlan,
|
|
150
|
-
allCities,
|
|
151
|
-
addCity,
|
|
152
|
-
addPermission,
|
|
1
|
+
const BaseJoi = require("joi");
|
|
2
|
+
const response = require("../utils/response");
|
|
3
|
+
const { add } = require("winston");
|
|
4
|
+
const schemas = {
|
|
5
|
+
getById: BaseJoi.object({
|
|
6
|
+
id: BaseJoi.number().required(),
|
|
7
|
+
}),
|
|
8
|
+
updateById: BaseJoi.object({
|
|
9
|
+
id: BaseJoi.number().required(),
|
|
10
|
+
name: BaseJoi.string().required(),
|
|
11
|
+
}),
|
|
12
|
+
addMaster: BaseJoi.object({
|
|
13
|
+
name: BaseJoi.string().required(),
|
|
14
|
+
}),
|
|
15
|
+
addSubscriptionPlan: BaseJoi.object({
|
|
16
|
+
name: BaseJoi.string().required(),
|
|
17
|
+
subscriptionPlanPermission: BaseJoi.array().items({
|
|
18
|
+
permissionId: BaseJoi.number().required(),
|
|
19
|
+
}),
|
|
20
|
+
}),
|
|
21
|
+
updateSubscriptionPlan: BaseJoi.object({
|
|
22
|
+
id: BaseJoi.number().required(),
|
|
23
|
+
name: BaseJoi.string().required(),
|
|
24
|
+
subscriptionPlanPermission: BaseJoi.array().items({
|
|
25
|
+
permissionId: BaseJoi.number().required(),
|
|
26
|
+
}),
|
|
27
|
+
}),
|
|
28
|
+
addCity: BaseJoi.object({
|
|
29
|
+
provinceId: BaseJoi.number().required(),
|
|
30
|
+
name: BaseJoi.string().required(),
|
|
31
|
+
}),
|
|
32
|
+
allCities: BaseJoi.object({
|
|
33
|
+
provinceId: BaseJoi.number().required(),
|
|
34
|
+
}),
|
|
35
|
+
addPermission: BaseJoi.object({
|
|
36
|
+
name: BaseJoi.string().required(),
|
|
37
|
+
permission: BaseJoi.array().items({
|
|
38
|
+
permissionId: BaseJoi.number().required(),
|
|
39
|
+
}),
|
|
40
|
+
}),
|
|
41
|
+
}
|
|
42
|
+
const options = {
|
|
43
|
+
basic: {
|
|
44
|
+
abortEarly: false,
|
|
45
|
+
convert: true,
|
|
46
|
+
allowUnknown: false,
|
|
47
|
+
stripUnknown: true,
|
|
48
|
+
},
|
|
49
|
+
array: {
|
|
50
|
+
abortEarly: false,
|
|
51
|
+
convert: true,
|
|
52
|
+
allowUnknown: true,
|
|
53
|
+
stripUnknown: {
|
|
54
|
+
objects: true,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const updateById = async (req, res, next) => {
|
|
60
|
+
const { updateById } = schemas;
|
|
61
|
+
const { basic } = options;
|
|
62
|
+
try {
|
|
63
|
+
await updateById.validateAsync({ ...req.params, ...req.body }, basic);
|
|
64
|
+
next();
|
|
65
|
+
} catch (err) {
|
|
66
|
+
throwError(req, res, err);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const addMaster = async (req, res, next) => {
|
|
70
|
+
const { addMaster } = schemas;
|
|
71
|
+
const { basic } = options;
|
|
72
|
+
try {
|
|
73
|
+
await addMaster.validateAsync({ ...req.body }, basic);
|
|
74
|
+
next();
|
|
75
|
+
} catch (err) {
|
|
76
|
+
throwError(req, res, err);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const addSubscriptionPlan = async (req, res, next) => {
|
|
80
|
+
const { addSubscriptionPlan } = schemas;
|
|
81
|
+
const { basic } = options;
|
|
82
|
+
try {
|
|
83
|
+
await addSubscriptionPlan.validateAsync({ ...req.body }, basic);
|
|
84
|
+
next();
|
|
85
|
+
} catch (err) {
|
|
86
|
+
throwError(req, res, err);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const updateSubscriptionPlan = async (req, res, next) => {
|
|
91
|
+
const { updateSubscriptionPlan } = schemas;
|
|
92
|
+
const { basic } = options;
|
|
93
|
+
try {
|
|
94
|
+
await updateSubscriptionPlan.validateAsync({ ...req.params, ...req.body }, basic);
|
|
95
|
+
next();
|
|
96
|
+
} catch (err) {
|
|
97
|
+
throwError(req, res, err);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const getById = async (req, res, next) => {
|
|
101
|
+
const { getById } = schemas;
|
|
102
|
+
const { basic } = options;
|
|
103
|
+
try {
|
|
104
|
+
await getById.validateAsync({ ...req.params }, basic);
|
|
105
|
+
next();
|
|
106
|
+
} catch (err) {
|
|
107
|
+
throwError(req, res, err);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const allCities = async (req, res, next) => {
|
|
111
|
+
const { allCities } = schemas;
|
|
112
|
+
const { basic } = options;
|
|
113
|
+
try {
|
|
114
|
+
await allCities.validateAsync({ ...req.query }, basic);
|
|
115
|
+
next();
|
|
116
|
+
} catch (err) {
|
|
117
|
+
throwError(req, res, err);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const addCity = async (req, res, next) => {
|
|
121
|
+
const { addCity } = schemas;
|
|
122
|
+
const { basic } = options;
|
|
123
|
+
try {
|
|
124
|
+
await addCity.validateAsync({ ...req.query, ...req.body }, basic);
|
|
125
|
+
next();
|
|
126
|
+
} catch (err) {
|
|
127
|
+
throwError(req, res, err);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const addPermission = async (req, res, next) => {
|
|
131
|
+
const { addPermission } = schemas;
|
|
132
|
+
const { basic } = options;
|
|
133
|
+
try {
|
|
134
|
+
await addPermission.validateAsync({ ...req.body }, basic);
|
|
135
|
+
next();
|
|
136
|
+
} catch (err) {
|
|
137
|
+
throwError(req, res, err);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const throwError = (req, res, err) => {
|
|
142
|
+
return response.joierrors(req, res, err);
|
|
143
|
+
};
|
|
144
|
+
module.exports = {
|
|
145
|
+
getById,
|
|
146
|
+
updateById,
|
|
147
|
+
addMaster,
|
|
148
|
+
addSubscriptionPlan,
|
|
149
|
+
updateSubscriptionPlan,
|
|
150
|
+
allCities,
|
|
151
|
+
addCity,
|
|
152
|
+
addPermission,
|
|
153
153
|
}
|