@churchsoln/dbms 1.0.3 → 1.0.4
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 +2 -1
- package/controllers/church.js +17 -1
- package/deployment/nginx/nginx.local.conf +2 -2
- package/migrations/church/20240918170621-create-church.js +39 -0
- package/migrations/common/20240918170624-update-church.js +23 -0
- package/models/church/church.js +47 -0
- package/models/common/church.js +0 -20
- package/models/common/churchPermission.js +1 -1
- package/package.json +2 -1
- package/public/swagger/church.json +42 -72
- package/public/swagger/master.json +1 -1
- package/public/swagger/migration.json +1 -1
- package/public/swagger/seed.json +1 -1
- package/redis/config.js +3 -2
- package/routes/v1/church.js +2 -1
- package/services/church.js +14 -9
- package/utils/docUpload.js +51 -0
- package/validators/church.js +6 -6
- package/deployment/docker-compose copy.yml +0 -81
package/Dockerfile
CHANGED
|
@@ -9,6 +9,7 @@ RUN apk update && \
|
|
|
9
9
|
|
|
10
10
|
# Set registry and timeout
|
|
11
11
|
RUN npm config set registry https://registry.npmmirror.com
|
|
12
|
+
RUN npm rebuild bcrypt --build-from-source
|
|
12
13
|
RUN npm install --legacy-peer-deps --force --timeout=60000
|
|
13
14
|
RUN npm cache clean --force
|
|
14
15
|
|
|
@@ -17,5 +18,5 @@ RUN npm cache clean --force
|
|
|
17
18
|
RUN apk del make gcc g++ python3 && \
|
|
18
19
|
rm -rf /var/cache/apk/* && \
|
|
19
20
|
npm cache clean --force
|
|
20
|
-
EXPOSE
|
|
21
|
+
EXPOSE 5007
|
|
21
22
|
CMD [ "npm", "run", "start" ]
|
package/controllers/church.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { churchService } = require("../services");
|
|
2
2
|
const errorCodes = require("../config/errorCodes");
|
|
3
3
|
const response = require("../utils/response");
|
|
4
|
+
const errorMsgs = require("../config/errorMsgs");
|
|
4
5
|
class ChurchController {
|
|
5
6
|
async onboardChurch(req, res) {
|
|
6
7
|
try {
|
|
@@ -37,7 +38,22 @@ class ChurchController {
|
|
|
37
38
|
response.error(req, res, errorCodes.HTTP_INTERNAL_SERVER_ERROR, err);
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
+
async uploadFile(req, res) {
|
|
42
|
+
try {
|
|
43
|
+
const file = req.files[0];
|
|
44
|
+
let file_folder = "documents";
|
|
45
|
+
if (file?.mimetype?.includes("image")) file_folder = "images";
|
|
46
|
+
else if (file?.mimetype?.includes("video")) file_folder = "videos";
|
|
47
|
+
else file_folder = "documents";
|
|
48
|
+
const responseData = {
|
|
49
|
+
url: `${process.env.BASE_URL}/dbms/api/uploads/${file_folder}/${file?.filename}`,
|
|
50
|
+
original_name: file?.originalname,
|
|
51
|
+
};
|
|
52
|
+
response.success(req, res, errorCodes.HTTP_OK, responseData, errorMsgs.success);
|
|
53
|
+
} catch (err) {
|
|
54
|
+
response.error(req, res, errorCodes.HTTP_INTERNAL_SERVER_ERROR, err);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
41
57
|
async addChurchPermission(req, res) {
|
|
42
58
|
try {
|
|
43
59
|
const result = await churchService.addChurchPermissionService({
|
|
@@ -11,11 +11,11 @@ http {
|
|
|
11
11
|
keepalive_timeout 65;
|
|
12
12
|
|
|
13
13
|
upstream frontend {
|
|
14
|
-
server host.docker.internal:
|
|
14
|
+
server host.docker.internal:5010;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
upstream backend {
|
|
18
|
-
server host.docker.internal:
|
|
18
|
+
server host.docker.internal:5009;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
# Redirect HTTP to HTTPS
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
up: async (queryInterface, DataTypes) => {
|
|
5
|
+
await queryInterface
|
|
6
|
+
.createTable(
|
|
7
|
+
"Church",
|
|
8
|
+
{
|
|
9
|
+
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
|
10
|
+
name: { type: DataTypes.STRING },
|
|
11
|
+
address: { type: DataTypes.STRING },
|
|
12
|
+
cityId: { type: DataTypes.INTEGER },
|
|
13
|
+
provinceId: { type: DataTypes.INTEGER },
|
|
14
|
+
country: { type: DataTypes.STRING },
|
|
15
|
+
postalCode: { type: DataTypes.STRING },
|
|
16
|
+
email: { type: DataTypes.STRING },
|
|
17
|
+
phoneNumber: { type: DataTypes.STRING },
|
|
18
|
+
contactPerson: { type: DataTypes.STRING },
|
|
19
|
+
currency: { type: DataTypes.STRING },
|
|
20
|
+
charitable_reg_no: { type: DataTypes.STRING },
|
|
21
|
+
registration_agency: { type: DataTypes.STRING },
|
|
22
|
+
profile_image: { type: DataTypes.STRING },
|
|
23
|
+
status: { type: DataTypes.BOOLEAN, defaultValue: true },
|
|
24
|
+
createdAt: {
|
|
25
|
+
type: DataTypes.DATE,
|
|
26
|
+
defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
|
|
27
|
+
},
|
|
28
|
+
updatedAt: {
|
|
29
|
+
type: DataTypes.DATE,
|
|
30
|
+
defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{ timestamps: false }
|
|
34
|
+
);
|
|
35
|
+
},
|
|
36
|
+
down: async (queryInterface) => {
|
|
37
|
+
await queryInterface.dropTable("Church");
|
|
38
|
+
},
|
|
39
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
up: async (queryInterface, DataTypes) => {
|
|
5
|
+
return Promise.all([
|
|
6
|
+
queryInterface.removeColumn("Church", "profile_image"),
|
|
7
|
+
queryInterface.removeColumn("Church", "registration_agency"),
|
|
8
|
+
queryInterface.removeColumn("Church", "charitable_reg_no"),
|
|
9
|
+
queryInterface.removeColumn("Church", "currency"),
|
|
10
|
+
queryInterface.removeColumn("Church", "postalCode"),
|
|
11
|
+
queryInterface.removeColumn("Church", "country"),
|
|
12
|
+
queryInterface.removeConstraint("Church", "church_provinceId_fk").then(() =>
|
|
13
|
+
queryInterface.removeColumn("Church", "provinceId")
|
|
14
|
+
),
|
|
15
|
+
queryInterface.removeConstraint("Church", "church_cityId_fk").then(() =>
|
|
16
|
+
queryInterface.removeColumn("Church", "cityId")
|
|
17
|
+
),
|
|
18
|
+
queryInterface.removeColumn("Church", "address"),
|
|
19
|
+
]);
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
down: async (queryInterface) => {},
|
|
23
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const { ONBOARD_STATUS } = require("../../constants");
|
|
2
|
+
|
|
3
|
+
module.exports = (sequelize, DataTypes) => {
|
|
4
|
+
const church = sequelize.define(
|
|
5
|
+
"Church",
|
|
6
|
+
{
|
|
7
|
+
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
|
8
|
+
name: { type: DataTypes.STRING },
|
|
9
|
+
address: { type: DataTypes.STRING },
|
|
10
|
+
cityId: { type: DataTypes.INTEGER },
|
|
11
|
+
provinceId: { type: DataTypes.INTEGER },
|
|
12
|
+
country: { type: DataTypes.STRING },
|
|
13
|
+
postalCode: { type: DataTypes.STRING },
|
|
14
|
+
email: { type: DataTypes.STRING },
|
|
15
|
+
phoneNumber: { type: DataTypes.STRING },
|
|
16
|
+
contactPerson: { type: DataTypes.STRING },
|
|
17
|
+
currency: { type: DataTypes.STRING },
|
|
18
|
+
charitable_reg_no: { type: DataTypes.STRING },
|
|
19
|
+
registration_agency: { type: DataTypes.STRING },
|
|
20
|
+
profile_image: { type: DataTypes.STRING },
|
|
21
|
+
status: { type: DataTypes.BOOLEAN },
|
|
22
|
+
createdAt: { type: DataTypes.DATE },
|
|
23
|
+
updatedAt: { type: DataTypes.DATE },
|
|
24
|
+
},
|
|
25
|
+
{ freezeTableName: true, timestamps: false }
|
|
26
|
+
);
|
|
27
|
+
church.selectedFields = [
|
|
28
|
+
"id",
|
|
29
|
+
"name",
|
|
30
|
+
"address",
|
|
31
|
+
"cityId",
|
|
32
|
+
"provinceId",
|
|
33
|
+
"country",
|
|
34
|
+
"postalCode",
|
|
35
|
+
"email",
|
|
36
|
+
"phoneNumber",
|
|
37
|
+
"contactPerson",
|
|
38
|
+
"currency",
|
|
39
|
+
"charitable_reg_no",
|
|
40
|
+
"registration_agency",
|
|
41
|
+
"profile_image",
|
|
42
|
+
"status",
|
|
43
|
+
"createdAt",
|
|
44
|
+
"updatedAt",
|
|
45
|
+
];
|
|
46
|
+
return church;
|
|
47
|
+
};
|
package/models/common/church.js
CHANGED
|
@@ -7,18 +7,9 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
7
7
|
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
|
8
8
|
name: { type: DataTypes.STRING },
|
|
9
9
|
connectionUrl: { type: DataTypes.STRING },
|
|
10
|
-
address: { type: DataTypes.STRING },
|
|
11
|
-
cityId: { type: DataTypes.INTEGER },
|
|
12
|
-
provinceId: { type: DataTypes.INTEGER },
|
|
13
|
-
country: { type: DataTypes.STRING },
|
|
14
|
-
postalCode: { type: DataTypes.STRING },
|
|
15
10
|
email: { type: DataTypes.STRING },
|
|
16
11
|
phoneNumber: { type: DataTypes.STRING },
|
|
17
12
|
contactPerson: { type: DataTypes.STRING },
|
|
18
|
-
currency: { type: DataTypes.STRING },
|
|
19
|
-
charitable_reg_no: { type: DataTypes.STRING },
|
|
20
|
-
registration_agency: { type: DataTypes.STRING },
|
|
21
|
-
profile_image: { type: DataTypes.STRING },
|
|
22
13
|
registeredAt: { type: DataTypes.DATEONLY },
|
|
23
14
|
subscribedAt: { type: DataTypes.DATEONLY },
|
|
24
15
|
subscriptionPlanId: { type: DataTypes.INTEGER },
|
|
@@ -43,25 +34,14 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
43
34
|
foreignKey: "subscriptionPlanId",
|
|
44
35
|
as: "subscriptionPlan",
|
|
45
36
|
});
|
|
46
|
-
church.belongsTo(models.city, { foreignKey: "cityId", as: "city" });
|
|
47
|
-
church.belongsTo(models.province, { foreignKey: "provinceId", as: "province" });
|
|
48
37
|
};
|
|
49
38
|
church.selectedFields = [
|
|
50
39
|
"id",
|
|
51
40
|
"name",
|
|
52
41
|
"connectionUrl",
|
|
53
|
-
"address",
|
|
54
|
-
"cityId",
|
|
55
|
-
"provinceId",
|
|
56
|
-
"country",
|
|
57
|
-
"postalCode",
|
|
58
42
|
"email",
|
|
59
43
|
"phoneNumber",
|
|
60
44
|
"contactPerson",
|
|
61
|
-
"currency",
|
|
62
|
-
"charitable_reg_no",
|
|
63
|
-
"registration_agency",
|
|
64
|
-
"profile_image",
|
|
65
45
|
"registeredAt",
|
|
66
46
|
"subscribedAt",
|
|
67
47
|
"subscriptionPlanId",
|
|
@@ -21,6 +21,6 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
21
21
|
as: "church",
|
|
22
22
|
});
|
|
23
23
|
};
|
|
24
|
-
churchPermission.selectedFields = ["id", "churchId", "permissionId"];
|
|
24
|
+
churchPermission.selectedFields = ["id", "churchId", "permissionId", "createdAt"];
|
|
25
25
|
return churchPermission;
|
|
26
26
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@churchsoln/dbms",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prestart": "node db-setup.js",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"joi": "^17.1.1",
|
|
26
26
|
"jsonwebtoken": "^9.0.2",
|
|
27
27
|
"morgan": "^1.10.0",
|
|
28
|
+
"multer": "^1.4.4",
|
|
28
29
|
"mysql2": "^3.12.0",
|
|
29
30
|
"nodemon": "^3.1.4",
|
|
30
31
|
"pg": "^8.8.0",
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
},
|
|
8
8
|
"servers": [
|
|
9
9
|
{
|
|
10
|
-
"url": "http://localhost:
|
|
10
|
+
"url": "http://localhost:5007/dbms/api/v1",
|
|
11
11
|
"description": "Local"
|
|
12
12
|
},
|
|
13
13
|
{
|
|
@@ -47,20 +47,9 @@
|
|
|
47
47
|
},
|
|
48
48
|
"example": {
|
|
49
49
|
"name": "Xavier",
|
|
50
|
-
"address": "Address",
|
|
51
|
-
"cityId": 1,
|
|
52
|
-
"provinceId": 1,
|
|
53
|
-
"country": "Country",
|
|
54
|
-
"postalCode": "123",
|
|
55
50
|
"email": "email",
|
|
56
51
|
"phoneNumber": "1234",
|
|
57
52
|
"contactPerson": "string",
|
|
58
|
-
"currency": "dollar",
|
|
59
|
-
"charitable_reg_no": "123",
|
|
60
|
-
"registration_agency": "agency",
|
|
61
|
-
"profileImage": "http://image.com",
|
|
62
|
-
"registeredAt": "2023-08-01",
|
|
63
|
-
"subscribedAt": "2023-08-01",
|
|
64
53
|
"subscriptionPlanId": 1,
|
|
65
54
|
"churchAdminDetails": {
|
|
66
55
|
"firstName": "Jose",
|
|
@@ -171,6 +160,31 @@
|
|
|
171
160
|
"deprecated": false
|
|
172
161
|
}
|
|
173
162
|
},
|
|
163
|
+
"/church/upload-file": {
|
|
164
|
+
"post": {
|
|
165
|
+
"tags": ["Church API's"],
|
|
166
|
+
"summary": "Upload file",
|
|
167
|
+
"operationId": "Upload file",
|
|
168
|
+
"parameters": [],
|
|
169
|
+
"requestBody": {
|
|
170
|
+
"content": {
|
|
171
|
+
"multipart/form-data": {
|
|
172
|
+
"schema": {
|
|
173
|
+
"$ref": "#/components/schemas/UploadFileDataRequest"
|
|
174
|
+
},
|
|
175
|
+
"encoding": {}
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
"required": false
|
|
179
|
+
},
|
|
180
|
+
"responses": {
|
|
181
|
+
"200": {
|
|
182
|
+
"description": "OK"
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
"deprecated": false
|
|
186
|
+
}
|
|
187
|
+
},
|
|
174
188
|
"/church/{churchId}/permission": {
|
|
175
189
|
"post": {
|
|
176
190
|
"tags": ["Church Permission API's"],
|
|
@@ -197,7 +211,7 @@
|
|
|
197
211
|
"$ref": "#/components/schemas/AddChurchPermissionDataRequest"
|
|
198
212
|
},
|
|
199
213
|
"example": {
|
|
200
|
-
"permissionId": 1
|
|
214
|
+
"permissionId": [1]
|
|
201
215
|
}
|
|
202
216
|
}
|
|
203
217
|
},
|
|
@@ -312,20 +326,9 @@
|
|
|
312
326
|
"title": "OnboardNewDataRequest",
|
|
313
327
|
"required": [
|
|
314
328
|
"name",
|
|
315
|
-
"address",
|
|
316
|
-
"cityId",
|
|
317
|
-
"provinceId",
|
|
318
|
-
"country",
|
|
319
|
-
"postalCode",
|
|
320
329
|
"email",
|
|
321
330
|
"phoneNumber",
|
|
322
331
|
"contactPerson",
|
|
323
|
-
"currency",
|
|
324
|
-
"charitable_reg_no",
|
|
325
|
-
"registration_agency",
|
|
326
|
-
"profile_image",
|
|
327
|
-
"registeredAt",
|
|
328
|
-
"subscribedAt",
|
|
329
332
|
"subscriptionPlanId",
|
|
330
333
|
"churchAdminDetails"
|
|
331
334
|
],
|
|
@@ -334,23 +337,6 @@
|
|
|
334
337
|
"name": {
|
|
335
338
|
"type": "string"
|
|
336
339
|
},
|
|
337
|
-
"address": {
|
|
338
|
-
"type": "string"
|
|
339
|
-
},
|
|
340
|
-
"cityId": {
|
|
341
|
-
"type": "integer",
|
|
342
|
-
"format": "int32"
|
|
343
|
-
},
|
|
344
|
-
"provinceId": {
|
|
345
|
-
"type": "integer",
|
|
346
|
-
"format": "int32"
|
|
347
|
-
},
|
|
348
|
-
"country": {
|
|
349
|
-
"type": "string"
|
|
350
|
-
},
|
|
351
|
-
"postalCode": {
|
|
352
|
-
"type": "string"
|
|
353
|
-
},
|
|
354
340
|
"email": {
|
|
355
341
|
"type": "string"
|
|
356
342
|
},
|
|
@@ -360,24 +346,6 @@
|
|
|
360
346
|
"contactPerson": {
|
|
361
347
|
"type": "string"
|
|
362
348
|
},
|
|
363
|
-
"currency": {
|
|
364
|
-
"type": "string"
|
|
365
|
-
},
|
|
366
|
-
"charitable_reg_no": {
|
|
367
|
-
"type": "string"
|
|
368
|
-
},
|
|
369
|
-
"registration_agency": {
|
|
370
|
-
"type": "string"
|
|
371
|
-
},
|
|
372
|
-
"profile_image": {
|
|
373
|
-
"type": "string"
|
|
374
|
-
},
|
|
375
|
-
"registeredAt": {
|
|
376
|
-
"type": "string"
|
|
377
|
-
},
|
|
378
|
-
"subscribedAt": {
|
|
379
|
-
"type": "string"
|
|
380
|
-
},
|
|
381
349
|
"subscriptionPlanId": {
|
|
382
350
|
"type": "integer",
|
|
383
351
|
"format": "int32"
|
|
@@ -389,20 +357,9 @@
|
|
|
389
357
|
},
|
|
390
358
|
"example": {
|
|
391
359
|
"name": "Xavier",
|
|
392
|
-
"address": "Address",
|
|
393
|
-
"cityId": 1,
|
|
394
|
-
"provinceId": 1,
|
|
395
|
-
"country": "Country",
|
|
396
|
-
"postalCode": "123",
|
|
397
360
|
"email": "email",
|
|
398
361
|
"phoneNumber": "1234",
|
|
399
362
|
"contactPerson": "string",
|
|
400
|
-
"currenncy": "dollar",
|
|
401
|
-
"charitable_reg_no": "123",
|
|
402
|
-
"registration_agency": "agency",
|
|
403
|
-
"profileImage": "http://image.com",
|
|
404
|
-
"registeredAt": "2023-08-01",
|
|
405
|
-
"subscribedAt": "2023-08-01",
|
|
406
363
|
"subscriptionPlanId": 1,
|
|
407
364
|
"churchAdminDetails": {
|
|
408
365
|
"firstName": "Jose",
|
|
@@ -465,8 +422,21 @@
|
|
|
465
422
|
"type": "object",
|
|
466
423
|
"properties": {
|
|
467
424
|
"permissionId": {
|
|
468
|
-
"type": "
|
|
469
|
-
"
|
|
425
|
+
"type": "array",
|
|
426
|
+
"items": {
|
|
427
|
+
"type": "number"
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
"UploadFileDataRequest": {
|
|
433
|
+
"title": "UploadFileDataRequest",
|
|
434
|
+
"required": ["file"],
|
|
435
|
+
"type": "object",
|
|
436
|
+
"properties": {
|
|
437
|
+
"file": {
|
|
438
|
+
"type": "string",
|
|
439
|
+
"format": "binary"
|
|
470
440
|
}
|
|
471
441
|
}
|
|
472
442
|
}
|
package/public/swagger/seed.json
CHANGED
package/redis/config.js
CHANGED
package/routes/v1/church.js
CHANGED
|
@@ -3,6 +3,7 @@ const router = express.Router();
|
|
|
3
3
|
const { ChurchController } = require("../../controllers");
|
|
4
4
|
const validators = require("../../validators");
|
|
5
5
|
const verifyToken = require("../../utils/verifyToken");
|
|
6
|
+
const docUpload = require("../../utils/docUpload");
|
|
6
7
|
|
|
7
8
|
// Church API's
|
|
8
9
|
router.post("", verifyToken, validators.onboardChurch, ChurchController.onboardChurch);
|
|
@@ -19,7 +20,7 @@ router.patch(
|
|
|
19
20
|
validators.updateChurch,
|
|
20
21
|
ChurchController.updateChurchById
|
|
21
22
|
);
|
|
22
|
-
|
|
23
|
+
router.post("/upload-file", verifyToken, docUpload, ChurchController.uploadFile);
|
|
23
24
|
// Church Permissions
|
|
24
25
|
router.post(
|
|
25
26
|
"/:churchId/permission",
|
package/services/church.js
CHANGED
|
@@ -26,6 +26,8 @@ class ChurchService {
|
|
|
26
26
|
const churchData = await commonDb.church.create(
|
|
27
27
|
{
|
|
28
28
|
...params,
|
|
29
|
+
registeredAt: new Date(),
|
|
30
|
+
subscribedAt: new Date(),
|
|
29
31
|
connectionUrl: process.env.CHURCH_SHADOW_DATABASE_URL.replace(
|
|
30
32
|
"church_shadow",
|
|
31
33
|
name.toLowerCase()
|
|
@@ -67,6 +69,7 @@ class ChurchService {
|
|
|
67
69
|
roleId: ROLES.CHURCH_ADMIN,
|
|
68
70
|
churchId: churchData.id,
|
|
69
71
|
});
|
|
72
|
+
await churchDb.church.create(params)
|
|
70
73
|
console.log(`Church onboarding completed for church: ${name}`);
|
|
71
74
|
}
|
|
72
75
|
});
|
|
@@ -118,7 +121,7 @@ class ChurchService {
|
|
|
118
121
|
|
|
119
122
|
async addChurchPermissionService(params) {
|
|
120
123
|
try {
|
|
121
|
-
const { churchId, permissionId } = params;
|
|
124
|
+
const { churchId, permissionId = [] } = params;
|
|
122
125
|
const existingChurch = await commonDb.church.findOne({
|
|
123
126
|
where: { id: churchId },
|
|
124
127
|
raw: true,
|
|
@@ -126,26 +129,28 @@ class ChurchService {
|
|
|
126
129
|
if (!existingChurch) {
|
|
127
130
|
return { code: errorCodes.HTTP_BAD_REQUEST, message: errorMsgs.invalidChurchId };
|
|
128
131
|
}
|
|
129
|
-
const existingPermission = await commonDb.permission.
|
|
132
|
+
const existingPermission = await commonDb.permission.findAll({
|
|
130
133
|
where: { id: permissionId },
|
|
131
134
|
raw: true,
|
|
132
135
|
});
|
|
133
|
-
if (
|
|
136
|
+
if (existingPermission.length !== permissionId.length) {
|
|
134
137
|
return {
|
|
135
138
|
code: errorCodes.HTTP_BAD_REQUEST,
|
|
136
139
|
message: errorMsgs.invalidPermissionId,
|
|
137
140
|
};
|
|
138
141
|
}
|
|
139
|
-
const existingChurchPermission = await commonDb.churchPermission.
|
|
142
|
+
const existingChurchPermission = await commonDb.churchPermission.findAll({
|
|
140
143
|
where: { churchId, permissionId },
|
|
141
144
|
raw: true,
|
|
142
145
|
});
|
|
143
|
-
|
|
144
|
-
|
|
146
|
+
const excludedPermissions = permissionId.filter(
|
|
147
|
+
(x) => !existingChurchPermission.map((y) => y.permissionId).includes(x)
|
|
148
|
+
);
|
|
149
|
+
if(excludedPermissions.length) {
|
|
150
|
+
const queries = excludedPermissions.map((x) => commonDb.churchPermission.create({ churchId, permissionId: x }))
|
|
151
|
+
await Promise.all(queries);
|
|
145
152
|
}
|
|
146
|
-
|
|
147
|
-
const data = response.get({ plain: true });
|
|
148
|
-
return { code: errorCodes.HTTP_OK, message: errorMsgs.success, data };
|
|
153
|
+
return { code: errorCodes.HTTP_OK, message: errorMsgs.success };
|
|
149
154
|
} catch (err) {
|
|
150
155
|
return { code: errorCodes.HTTP_INTERNAL_SERVER_ERROR, message: err };
|
|
151
156
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const multer = require("multer");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const response = require("./response");
|
|
4
|
+
const errorCodes = require("../config/errorCodes");
|
|
5
|
+
const docUpload = async (req, res, next) => {
|
|
6
|
+
const storage = multer.diskStorage({
|
|
7
|
+
destination: function (req, file, cb) {
|
|
8
|
+
let file_folder = "documents";
|
|
9
|
+
if (file.mimetype.includes("image")) file_folder = "images";
|
|
10
|
+
else if (file.mimetype.includes("video")) file_folder = "videos";
|
|
11
|
+
else file_folder = "documents";
|
|
12
|
+
cb(null, `/app/uploads/${file_folder}`);
|
|
13
|
+
},
|
|
14
|
+
filename: function (req, file, cb) {
|
|
15
|
+
const filename =
|
|
16
|
+
file.fieldname +
|
|
17
|
+
"-" +
|
|
18
|
+
Date.now() +
|
|
19
|
+
path.extname(file.originalname).toLocaleLowerCase();
|
|
20
|
+
cb(null, filename);
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
const filter = (req, res, file, cb) => {
|
|
24
|
+
if (
|
|
25
|
+
file.mimetype.includes("pdf") ||
|
|
26
|
+
file.mimetype.includes("image") ||
|
|
27
|
+
file.mimetype.includes("video")
|
|
28
|
+
) {
|
|
29
|
+
cb(null, true);
|
|
30
|
+
} else {
|
|
31
|
+
return cb(new Error("Only images/pdf/videos are allowed"));
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
req.files = {};
|
|
35
|
+
multer({
|
|
36
|
+
storage,
|
|
37
|
+
fileFilter: (req, file, cb) => filter(req, res, file, cb),
|
|
38
|
+
limits: { fileSize: 20 * 1024 * 1024 },
|
|
39
|
+
}).any()(req, res, (err) => {
|
|
40
|
+
console.log(err)
|
|
41
|
+
if (err)
|
|
42
|
+
response.invalid(
|
|
43
|
+
req,
|
|
44
|
+
res,
|
|
45
|
+
errorCodes.HTTP_BAD_REQUEST,
|
|
46
|
+
"Only images/videos under 20 MB each are permitted."
|
|
47
|
+
);
|
|
48
|
+
else next();
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
module.exports = docUpload;
|
package/validators/church.js
CHANGED
|
@@ -13,11 +13,11 @@ const schemas = {
|
|
|
13
13
|
postalCode: BaseJoi.string().required(),
|
|
14
14
|
email: BaseJoi.string().required(),
|
|
15
15
|
phoneNumber: BaseJoi.string().required(),
|
|
16
|
-
contactPerson: BaseJoi.string().
|
|
17
|
-
currency: BaseJoi.string().
|
|
18
|
-
charitable_reg_no: BaseJoi.string().
|
|
19
|
-
registration_agency: BaseJoi.string().
|
|
20
|
-
profileImage: BaseJoi.string().
|
|
16
|
+
contactPerson: BaseJoi.string().optional().allow(null),
|
|
17
|
+
currency: BaseJoi.string().optional().allow(null),
|
|
18
|
+
charitable_reg_no: BaseJoi.string().optional().allow(null),
|
|
19
|
+
registration_agency: BaseJoi.string().optional().allow(null),
|
|
20
|
+
profileImage: BaseJoi.string().optional().allow(null),
|
|
21
21
|
registeredAt: BaseJoi.string().required(),
|
|
22
22
|
subscribedAt: BaseJoi.string().required(),
|
|
23
23
|
subscriptionPlanId: BaseJoi.number().required(),
|
|
@@ -34,7 +34,7 @@ const schemas = {
|
|
|
34
34
|
}),
|
|
35
35
|
addChurchPermission: BaseJoi.object({
|
|
36
36
|
churchId: BaseJoi.number().required(),
|
|
37
|
-
permissionId: BaseJoi.number().required(),
|
|
37
|
+
permissionId: BaseJoi.array().items(BaseJoi.number().required()),
|
|
38
38
|
}),
|
|
39
39
|
getByChurchId: BaseJoi.object({
|
|
40
40
|
churchId: BaseJoi.number().required(),
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
version: '3'
|
|
2
|
-
services:
|
|
3
|
-
churchsoln_backend:
|
|
4
|
-
container_name: churchsoln_backend
|
|
5
|
-
build:
|
|
6
|
-
context: ./churchsoln_backend
|
|
7
|
-
dockerfile: Dockerfile
|
|
8
|
-
restart: always
|
|
9
|
-
ports:
|
|
10
|
-
- "5009:5009"
|
|
11
|
-
depends_on:
|
|
12
|
-
- postgres-backend
|
|
13
|
-
env_file: ./churchsoln_backend/.env
|
|
14
|
-
volumes:
|
|
15
|
-
- ./churchsoln_backend/:/app
|
|
16
|
-
- image-volume:/app/uploads/images
|
|
17
|
-
- document-volume:/app/uploads/documents
|
|
18
|
-
- video-volume:/app/uploads/videos
|
|
19
|
-
networks:
|
|
20
|
-
- app-network
|
|
21
|
-
churchsoln_dbms:
|
|
22
|
-
container_name: churchsoln_dbms
|
|
23
|
-
build:
|
|
24
|
-
context: ./churchsoln_dbms
|
|
25
|
-
dockerfile: Dockerfile
|
|
26
|
-
restart: always
|
|
27
|
-
ports:
|
|
28
|
-
- "5007:5007"
|
|
29
|
-
depends_on:
|
|
30
|
-
- postgres
|
|
31
|
-
- redis1
|
|
32
|
-
env_file: ./churchsoln_dbms/.env
|
|
33
|
-
volumes:
|
|
34
|
-
- ./churchsoln_dbms/:/app
|
|
35
|
-
- image-volume:/app/uploads/images
|
|
36
|
-
- document-volume:/app/uploads/documents
|
|
37
|
-
- video-volume:/app/uploads/videos
|
|
38
|
-
networks:
|
|
39
|
-
- app-network
|
|
40
|
-
|
|
41
|
-
postgres:
|
|
42
|
-
image: postgres:15
|
|
43
|
-
container_name: postgres
|
|
44
|
-
env_file: ../.env
|
|
45
|
-
restart: always
|
|
46
|
-
volumes:
|
|
47
|
-
- pgdata:/var/lib/postgresql/data
|
|
48
|
-
networks:
|
|
49
|
-
- app-network
|
|
50
|
-
|
|
51
|
-
pgadmin1:
|
|
52
|
-
image: dpage/pgadmin4
|
|
53
|
-
container_name: pgadmin1
|
|
54
|
-
env_file: ../.env
|
|
55
|
-
ports:
|
|
56
|
-
- "5008:80"
|
|
57
|
-
depends_on:
|
|
58
|
-
- postgres
|
|
59
|
-
networks:
|
|
60
|
-
- app-network
|
|
61
|
-
|
|
62
|
-
redis1:
|
|
63
|
-
image: redis:latest
|
|
64
|
-
container_name: redis1
|
|
65
|
-
ports:
|
|
66
|
-
- "6379:6379"
|
|
67
|
-
volumes:
|
|
68
|
-
- redis-data:/data
|
|
69
|
-
networks:
|
|
70
|
-
- app-network
|
|
71
|
-
|
|
72
|
-
networks:
|
|
73
|
-
app-network:
|
|
74
|
-
driver: bridge
|
|
75
|
-
|
|
76
|
-
volumes:
|
|
77
|
-
pgdata:
|
|
78
|
-
redis-data:
|
|
79
|
-
image-volume:
|
|
80
|
-
document-volume:
|
|
81
|
-
video-volume:
|