@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/services/migration.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
const errorCodes = require("../config/errorCodes");
|
|
2
|
-
const errorMsgs = require("../config/errorMsgs");
|
|
3
|
-
const { migrationsQueue } = require("../queues");
|
|
4
|
-
const commonDb = require("../models/common");
|
|
5
|
-
const { QUEUES } = require("../constants");
|
|
6
|
-
class MigrationService {
|
|
7
|
-
async migrateAllChurchModels() {
|
|
8
|
-
try {
|
|
9
|
-
await migrationsQueue.add(QUEUES.MIGRATION, {});
|
|
10
|
-
return { code: errorCodes.HTTP_OK, message: errorMsgs.migrationInitiated };
|
|
11
|
-
} catch (err) {
|
|
12
|
-
throw new Error(err.message);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async migrateModelsByChurchId(churchId) {
|
|
17
|
-
try {
|
|
18
|
-
const churchExists = await commonDb.church.findOne({
|
|
19
|
-
where: { id: churchId },
|
|
20
|
-
raw: true,
|
|
21
|
-
});
|
|
22
|
-
if (!churchExists) throw new Error(`Church with id ${churchId} does not exist`);
|
|
23
|
-
await migrationsQueue.add(QUEUES.MIGRATION, { churchId });
|
|
24
|
-
return { code: errorCodes.HTTP_OK, message: errorMsgs.migrationInitiated };
|
|
25
|
-
} catch (err) {
|
|
26
|
-
throw new Error(err.message);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
module.exports = new MigrationService();
|
|
1
|
+
const errorCodes = require("../config/errorCodes");
|
|
2
|
+
const errorMsgs = require("../config/errorMsgs");
|
|
3
|
+
const { migrationsQueue } = require("../queues");
|
|
4
|
+
const commonDb = require("../models/common");
|
|
5
|
+
const { QUEUES } = require("../constants");
|
|
6
|
+
class MigrationService {
|
|
7
|
+
async migrateAllChurchModels() {
|
|
8
|
+
try {
|
|
9
|
+
await migrationsQueue.add(QUEUES.MIGRATION, {});
|
|
10
|
+
return { code: errorCodes.HTTP_OK, message: errorMsgs.migrationInitiated };
|
|
11
|
+
} catch (err) {
|
|
12
|
+
throw new Error(err.message);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async migrateModelsByChurchId(churchId) {
|
|
17
|
+
try {
|
|
18
|
+
const churchExists = await commonDb.church.findOne({
|
|
19
|
+
where: { id: churchId },
|
|
20
|
+
raw: true,
|
|
21
|
+
});
|
|
22
|
+
if (!churchExists) throw new Error(`Church with id ${churchId} does not exist`);
|
|
23
|
+
await migrationsQueue.add(QUEUES.MIGRATION, { churchId });
|
|
24
|
+
return { code: errorCodes.HTTP_OK, message: errorMsgs.migrationInitiated };
|
|
25
|
+
} catch (err) {
|
|
26
|
+
throw new Error(err.message);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
module.exports = new MigrationService();
|
package/services/seed.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
const errorCodes = require("../config/errorCodes");
|
|
2
|
-
const errorMsgs = require("../config/errorMsgs");
|
|
3
|
-
const { seedQueue } = require("../queues");
|
|
4
|
-
const commonDb = require("../models/common");
|
|
5
|
-
const { QUEUES } = require("../constants");
|
|
6
|
-
class SeedService {
|
|
7
|
-
async seedCommonDb() {
|
|
8
|
-
try {
|
|
9
|
-
await seedQueue.add(QUEUES.SEED, { isCommonDb: true });
|
|
10
|
-
return { code: errorCodes.HTTP_OK, message: errorMsgs.seedInitiated };
|
|
11
|
-
} catch (err) {
|
|
12
|
-
throw new Error(err.message);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async seedAllChurch() {
|
|
17
|
-
try {
|
|
18
|
-
await seedQueue.add(QUEUES.SEED, {});
|
|
19
|
-
return { code: errorCodes.HTTP_OK, message: errorMsgs.seedInitiated };
|
|
20
|
-
} catch (err) {
|
|
21
|
-
throw new Error(err.message);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async seedByChurchId(churchId) {
|
|
26
|
-
try {
|
|
27
|
-
const churchExists = await commonDb.church.findOne({
|
|
28
|
-
where: { id: churchId },
|
|
29
|
-
raw: true,
|
|
30
|
-
});
|
|
31
|
-
if (!churchExists) throw new Error(`Church with id ${churchId} does not exist`);
|
|
32
|
-
await seedQueue.add(QUEUES.SEED, { churchId });
|
|
33
|
-
return { code: errorCodes.HTTP_OK, message: errorMsgs.seedInitiated };
|
|
34
|
-
} catch (err) {
|
|
35
|
-
throw new Error(err.message);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
module.exports = new SeedService();
|
|
1
|
+
const errorCodes = require("../config/errorCodes");
|
|
2
|
+
const errorMsgs = require("../config/errorMsgs");
|
|
3
|
+
const { seedQueue } = require("../queues");
|
|
4
|
+
const commonDb = require("../models/common");
|
|
5
|
+
const { QUEUES } = require("../constants");
|
|
6
|
+
class SeedService {
|
|
7
|
+
async seedCommonDb() {
|
|
8
|
+
try {
|
|
9
|
+
await seedQueue.add(QUEUES.SEED, { isCommonDb: true });
|
|
10
|
+
return { code: errorCodes.HTTP_OK, message: errorMsgs.seedInitiated };
|
|
11
|
+
} catch (err) {
|
|
12
|
+
throw new Error(err.message);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async seedAllChurch() {
|
|
17
|
+
try {
|
|
18
|
+
await seedQueue.add(QUEUES.SEED, {});
|
|
19
|
+
return { code: errorCodes.HTTP_OK, message: errorMsgs.seedInitiated };
|
|
20
|
+
} catch (err) {
|
|
21
|
+
throw new Error(err.message);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async seedByChurchId(churchId) {
|
|
26
|
+
try {
|
|
27
|
+
const churchExists = await commonDb.church.findOne({
|
|
28
|
+
where: { id: churchId },
|
|
29
|
+
raw: true,
|
|
30
|
+
});
|
|
31
|
+
if (!churchExists) throw new Error(`Church with id ${churchId} does not exist`);
|
|
32
|
+
await seedQueue.add(QUEUES.SEED, { churchId });
|
|
33
|
+
return { code: errorCodes.HTTP_OK, message: errorMsgs.seedInitiated };
|
|
34
|
+
} catch (err) {
|
|
35
|
+
throw new Error(err.message);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
module.exports = new SeedService();
|
package/utils/churchManager.js
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
const { getDbConnection } = require("../models/church");
|
|
2
|
-
const commonDb = require("../models/common");
|
|
3
|
-
class ChurchManager {
|
|
4
|
-
churchClients = new Map();
|
|
5
|
-
intervalId = null;
|
|
6
|
-
constructor() {}
|
|
7
|
-
|
|
8
|
-
async getCommonDbConnection() {
|
|
9
|
-
return commonDb;
|
|
10
|
-
}
|
|
11
|
-
async getChurchDbConnectionById(churchId) {
|
|
12
|
-
try {
|
|
13
|
-
if (this.churchClients.has(churchId)) {
|
|
14
|
-
const clientData = this.churchClients.get(churchId);
|
|
15
|
-
clientData.lastAccessed = Date.now();
|
|
16
|
-
return clientData.dbConnection;
|
|
17
|
-
} else {
|
|
18
|
-
if (!this.intervalId) {
|
|
19
|
-
this.startCleanupTask();
|
|
20
|
-
}
|
|
21
|
-
const churchData = await commonDb.church.findOne({
|
|
22
|
-
where: { id: churchId },
|
|
23
|
-
attributes: commonDb.church.selectedFields,
|
|
24
|
-
raw: true,
|
|
25
|
-
});
|
|
26
|
-
if (!churchData) {
|
|
27
|
-
throw new Error(`Church with id ${churchId} not found`);
|
|
28
|
-
}
|
|
29
|
-
const { connectionUrl } = churchData;
|
|
30
|
-
const dbConnection = getDbConnection(connectionUrl);
|
|
31
|
-
this.churchClients.set(churchId, {
|
|
32
|
-
dbConnection,
|
|
33
|
-
lastAccessed: Date.now(),
|
|
34
|
-
});
|
|
35
|
-
return dbConnection;
|
|
36
|
-
}
|
|
37
|
-
} catch (error) {
|
|
38
|
-
console.error("Error getting church client:", error.message);
|
|
39
|
-
throw new Error(error.message);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async getChurchDbConnectionByDomain(domain) {
|
|
44
|
-
try {
|
|
45
|
-
const churchData = await commonDb.churchDomain.findOne({
|
|
46
|
-
where: { domain },
|
|
47
|
-
attributes: commonDb.churchDomain.selectedFields,
|
|
48
|
-
raw: true,
|
|
49
|
-
});
|
|
50
|
-
if (!churchData) {
|
|
51
|
-
throw new Error(`Church with domain ${domain} not found`);
|
|
52
|
-
}
|
|
53
|
-
const { churchId } = churchData;
|
|
54
|
-
return this.getChurchDbConnectionById(churchId);
|
|
55
|
-
} catch (error) {
|
|
56
|
-
console.error("Error getting church client:", error.message);
|
|
57
|
-
throw new Error(error.message);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async getChurchIdByDomain(domain) {
|
|
62
|
-
try {
|
|
63
|
-
const churchData = await commonDb.churchDomain.findOne({
|
|
64
|
-
where: { domain },
|
|
65
|
-
attributes: commonDb.churchDomain.selectedFields,
|
|
66
|
-
raw: true,
|
|
67
|
-
});
|
|
68
|
-
if (!churchData) {
|
|
69
|
-
throw new Error(`Church with domain ${domain} not found`);
|
|
70
|
-
}
|
|
71
|
-
return churchData.churchId;
|
|
72
|
-
} catch (error) {
|
|
73
|
-
console.error("Error getting church id:", error.message);
|
|
74
|
-
throw new Error(error.message);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async disconnectInactiveConnections() {
|
|
79
|
-
const now = Date.now();
|
|
80
|
-
const timeout = 30 * 60 * 1000;
|
|
81
|
-
for (const [churchId, clientData] of this.churchClients.entries()) {
|
|
82
|
-
if (now - clientData.lastAccessed > timeout) {
|
|
83
|
-
const db = await clientData.dbConnection;
|
|
84
|
-
console.log(
|
|
85
|
-
`Disconnecting inactive connection for churchId: ${churchId}`
|
|
86
|
-
);
|
|
87
|
-
await db.sequelize.close();
|
|
88
|
-
this.churchClients.delete(churchId);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
startCleanupTask() {
|
|
94
|
-
this.intervalId = setInterval(() => {
|
|
95
|
-
this.disconnectInactiveConnections();
|
|
96
|
-
}, 30 * 60 * 1000);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
1
|
+
const { getDbConnection } = require("../models/church");
|
|
2
|
+
const commonDb = require("../models/common");
|
|
3
|
+
class ChurchManager {
|
|
4
|
+
churchClients = new Map();
|
|
5
|
+
intervalId = null;
|
|
6
|
+
constructor() {}
|
|
7
|
+
|
|
8
|
+
async getCommonDbConnection() {
|
|
9
|
+
return commonDb;
|
|
10
|
+
}
|
|
11
|
+
async getChurchDbConnectionById(churchId) {
|
|
12
|
+
try {
|
|
13
|
+
if (this.churchClients.has(churchId)) {
|
|
14
|
+
const clientData = this.churchClients.get(churchId);
|
|
15
|
+
clientData.lastAccessed = Date.now();
|
|
16
|
+
return clientData.dbConnection;
|
|
17
|
+
} else {
|
|
18
|
+
if (!this.intervalId) {
|
|
19
|
+
this.startCleanupTask();
|
|
20
|
+
}
|
|
21
|
+
const churchData = await commonDb.church.findOne({
|
|
22
|
+
where: { id: churchId },
|
|
23
|
+
attributes: commonDb.church.selectedFields,
|
|
24
|
+
raw: true,
|
|
25
|
+
});
|
|
26
|
+
if (!churchData) {
|
|
27
|
+
throw new Error(`Church with id ${churchId} not found`);
|
|
28
|
+
}
|
|
29
|
+
const { connectionUrl } = churchData;
|
|
30
|
+
const dbConnection = getDbConnection(connectionUrl);
|
|
31
|
+
this.churchClients.set(churchId, {
|
|
32
|
+
dbConnection,
|
|
33
|
+
lastAccessed: Date.now(),
|
|
34
|
+
});
|
|
35
|
+
return dbConnection;
|
|
36
|
+
}
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error("Error getting church client:", error.message);
|
|
39
|
+
throw new Error(error.message);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async getChurchDbConnectionByDomain(domain) {
|
|
44
|
+
try {
|
|
45
|
+
const churchData = await commonDb.churchDomain.findOne({
|
|
46
|
+
where: { domain },
|
|
47
|
+
attributes: commonDb.churchDomain.selectedFields,
|
|
48
|
+
raw: true,
|
|
49
|
+
});
|
|
50
|
+
if (!churchData) {
|
|
51
|
+
throw new Error(`Church with domain ${domain} not found`);
|
|
52
|
+
}
|
|
53
|
+
const { churchId } = churchData;
|
|
54
|
+
return this.getChurchDbConnectionById(churchId);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error("Error getting church client:", error.message);
|
|
57
|
+
throw new Error(error.message);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async getChurchIdByDomain(domain) {
|
|
62
|
+
try {
|
|
63
|
+
const churchData = await commonDb.churchDomain.findOne({
|
|
64
|
+
where: { domain },
|
|
65
|
+
attributes: commonDb.churchDomain.selectedFields,
|
|
66
|
+
raw: true,
|
|
67
|
+
});
|
|
68
|
+
if (!churchData) {
|
|
69
|
+
throw new Error(`Church with domain ${domain} not found`);
|
|
70
|
+
}
|
|
71
|
+
return churchData.churchId;
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error("Error getting church id:", error.message);
|
|
74
|
+
throw new Error(error.message);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async disconnectInactiveConnections() {
|
|
79
|
+
const now = Date.now();
|
|
80
|
+
const timeout = 30 * 60 * 1000;
|
|
81
|
+
for (const [churchId, clientData] of this.churchClients.entries()) {
|
|
82
|
+
if (now - clientData.lastAccessed > timeout) {
|
|
83
|
+
const db = await clientData.dbConnection;
|
|
84
|
+
console.log(
|
|
85
|
+
`Disconnecting inactive connection for churchId: ${churchId}`
|
|
86
|
+
);
|
|
87
|
+
await db.sequelize.close();
|
|
88
|
+
this.churchClients.delete(churchId);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
startCleanupTask() {
|
|
94
|
+
this.intervalId = setInterval(() => {
|
|
95
|
+
this.disconnectInactiveConnections();
|
|
96
|
+
}, 30 * 60 * 1000);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
99
|
module.exports = new ChurchManager();
|
package/utils/crypto.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
const CryptoJS = require("crypto-js");
|
|
2
|
-
|
|
3
|
-
const iterationCount = 1000;
|
|
4
|
-
const keySize = 128;
|
|
5
|
-
const passPhrase = process.env.AES_PASSPHRASE;
|
|
6
|
-
|
|
7
|
-
const salt = process.env.AES_SALT;
|
|
8
|
-
const iv = process.env.AES_FOUR;
|
|
9
|
-
|
|
10
|
-
const AesUtil = function (keySize, iterationCount) {
|
|
11
|
-
this.keySize = keySize / 32;
|
|
12
|
-
this.iterationCount = iterationCount;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
AesUtil.prototype.generateKey = function () {
|
|
16
|
-
const key = CryptoJS.PBKDF2(passPhrase, CryptoJS.enc.Hex.parse(salt), {
|
|
17
|
-
keySize: this.keySize,
|
|
18
|
-
iterations: this.iterationCount,
|
|
19
|
-
});
|
|
20
|
-
return key;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
AesUtil.prototype.encrypt = function (plainText) {
|
|
24
|
-
const key = this.generateKey();
|
|
25
|
-
const encrypted = CryptoJS.AES.encrypt(String(plainText), key, {
|
|
26
|
-
iv: CryptoJS.enc.Hex.parse(iv),
|
|
27
|
-
});
|
|
28
|
-
return encrypted.ciphertext.toString(CryptoJS.enc.Base64);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
AesUtil.prototype.decrypt = function (cipherText) {
|
|
32
|
-
const key = this.generateKey();
|
|
33
|
-
const cipherParams = CryptoJS.lib.CipherParams.create({
|
|
34
|
-
ciphertext: CryptoJS.enc.Base64.parse(cipherText),
|
|
35
|
-
});
|
|
36
|
-
const decrypted = CryptoJS.AES.decrypt(cipherParams, key, { iv: CryptoJS.enc.Hex.parse(iv) });
|
|
37
|
-
return decrypted.toString(CryptoJS.enc.Utf8);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
module.exports = new AesUtil(keySize, iterationCount);
|
|
1
|
+
const CryptoJS = require("crypto-js");
|
|
2
|
+
|
|
3
|
+
const iterationCount = 1000;
|
|
4
|
+
const keySize = 128;
|
|
5
|
+
const passPhrase = process.env.AES_PASSPHRASE;
|
|
6
|
+
|
|
7
|
+
const salt = process.env.AES_SALT;
|
|
8
|
+
const iv = process.env.AES_FOUR;
|
|
9
|
+
|
|
10
|
+
const AesUtil = function (keySize, iterationCount) {
|
|
11
|
+
this.keySize = keySize / 32;
|
|
12
|
+
this.iterationCount = iterationCount;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
AesUtil.prototype.generateKey = function () {
|
|
16
|
+
const key = CryptoJS.PBKDF2(passPhrase, CryptoJS.enc.Hex.parse(salt), {
|
|
17
|
+
keySize: this.keySize,
|
|
18
|
+
iterations: this.iterationCount,
|
|
19
|
+
});
|
|
20
|
+
return key;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
AesUtil.prototype.encrypt = function (plainText) {
|
|
24
|
+
const key = this.generateKey();
|
|
25
|
+
const encrypted = CryptoJS.AES.encrypt(String(plainText), key, {
|
|
26
|
+
iv: CryptoJS.enc.Hex.parse(iv),
|
|
27
|
+
});
|
|
28
|
+
return encrypted.ciphertext.toString(CryptoJS.enc.Base64);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
AesUtil.prototype.decrypt = function (cipherText) {
|
|
32
|
+
const key = this.generateKey();
|
|
33
|
+
const cipherParams = CryptoJS.lib.CipherParams.create({
|
|
34
|
+
ciphertext: CryptoJS.enc.Base64.parse(cipherText),
|
|
35
|
+
});
|
|
36
|
+
const decrypted = CryptoJS.AES.decrypt(cipherParams, key, { iv: CryptoJS.enc.Hex.parse(iv) });
|
|
37
|
+
return decrypted.toString(CryptoJS.enc.Utf8);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
module.exports = new AesUtil(keySize, iterationCount);
|
package/utils/docUpload.js
CHANGED
|
@@ -1,51 +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;
|
|
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/utils/encryptDecrypt.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
const errorCodes = require("../config/errorCodes");
|
|
2
|
-
const errorMessages = require("../config/errorMsgs");
|
|
3
|
-
const cryptr = require("./crypto");
|
|
4
|
-
const canDecrypt = process.env.API_ENCRYPT == "true";
|
|
5
|
-
module.exports = {
|
|
6
|
-
decryptData: async (req, res, next) => {
|
|
7
|
-
if (!canDecrypt) return next();
|
|
8
|
-
if (req.method == "GET") return next();
|
|
9
|
-
if (req.body && req.body.data) {
|
|
10
|
-
const decryptedData = cryptr.decrypt(req.body.data);
|
|
11
|
-
if (decryptedData && decryptedData.length > 0) {
|
|
12
|
-
req.body = JSON.parse(decryptedData);
|
|
13
|
-
return next();
|
|
14
|
-
} else {
|
|
15
|
-
return res
|
|
16
|
-
.status(errorCodes.HTTP_UNPROCESSABLE_ENTITY)
|
|
17
|
-
.json({ messge: errorMessages[errorCodes.HTTP_UNPROCESSABLE_ENTITY] });
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
next();
|
|
21
|
-
},
|
|
22
|
-
encryptData: async (data) => {
|
|
23
|
-
if (!canDecrypt) return data;
|
|
24
|
-
return data ? { data: cryptr.encrypt(JSON.stringify(data)) } : null;
|
|
25
|
-
},
|
|
26
|
-
};
|
|
1
|
+
const errorCodes = require("../config/errorCodes");
|
|
2
|
+
const errorMessages = require("../config/errorMsgs");
|
|
3
|
+
const cryptr = require("./crypto");
|
|
4
|
+
const canDecrypt = process.env.API_ENCRYPT == "true";
|
|
5
|
+
module.exports = {
|
|
6
|
+
decryptData: async (req, res, next) => {
|
|
7
|
+
if (!canDecrypt) return next();
|
|
8
|
+
if (req.method == "GET") return next();
|
|
9
|
+
if (req.body && req.body.data) {
|
|
10
|
+
const decryptedData = cryptr.decrypt(req.body.data);
|
|
11
|
+
if (decryptedData && decryptedData.length > 0) {
|
|
12
|
+
req.body = JSON.parse(decryptedData);
|
|
13
|
+
return next();
|
|
14
|
+
} else {
|
|
15
|
+
return res
|
|
16
|
+
.status(errorCodes.HTTP_UNPROCESSABLE_ENTITY)
|
|
17
|
+
.json({ messge: errorMessages[errorCodes.HTTP_UNPROCESSABLE_ENTITY] });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
next();
|
|
21
|
+
},
|
|
22
|
+
encryptData: async (data) => {
|
|
23
|
+
if (!canDecrypt) return data;
|
|
24
|
+
return data ? { data: cryptr.encrypt(JSON.stringify(data)) } : null;
|
|
25
|
+
},
|
|
26
|
+
};
|
package/utils/index.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
const bcrypt = require("bcrypt");
|
|
2
|
-
const response = require("./response");
|
|
3
|
-
const errorCodes = require("../config/errorCodes");
|
|
4
|
-
const errorMessages = require("../config/errorMsgs");
|
|
5
|
-
class Utils {
|
|
6
|
-
genHash(data) {
|
|
7
|
-
let salt = bcrypt.genSaltSync(8);
|
|
8
|
-
return bcrypt.hashSync(data, salt);
|
|
9
|
-
}
|
|
10
|
-
hasRole(roles = []) {
|
|
11
|
-
return async (req, res, next) => {
|
|
12
|
-
if (!roles.includes(req.user.roleId)) {
|
|
13
|
-
return response.invalid(
|
|
14
|
-
req,
|
|
15
|
-
res,
|
|
16
|
-
errorCodes.HTTP_UNAUTHORIZED,
|
|
17
|
-
errorMessages.actionNotPermitted
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
next();
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
generateCode(length) {
|
|
24
|
-
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
25
|
-
let code = "";
|
|
26
|
-
for (let i = 0; i < length; i++) {
|
|
27
|
-
const randomIndex = Math.floor(Math.random() * characters.length);
|
|
28
|
-
code += characters[randomIndex];
|
|
29
|
-
}
|
|
30
|
-
return code;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
module.exports = new Utils();
|
|
1
|
+
const bcrypt = require("bcrypt");
|
|
2
|
+
const response = require("./response");
|
|
3
|
+
const errorCodes = require("../config/errorCodes");
|
|
4
|
+
const errorMessages = require("../config/errorMsgs");
|
|
5
|
+
class Utils {
|
|
6
|
+
genHash(data) {
|
|
7
|
+
let salt = bcrypt.genSaltSync(8);
|
|
8
|
+
return bcrypt.hashSync(data, salt);
|
|
9
|
+
}
|
|
10
|
+
hasRole(roles = []) {
|
|
11
|
+
return async (req, res, next) => {
|
|
12
|
+
if (!roles.includes(req.user.roleId)) {
|
|
13
|
+
return response.invalid(
|
|
14
|
+
req,
|
|
15
|
+
res,
|
|
16
|
+
errorCodes.HTTP_UNAUTHORIZED,
|
|
17
|
+
errorMessages.actionNotPermitted
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
next();
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
generateCode(length) {
|
|
24
|
+
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
25
|
+
let code = "";
|
|
26
|
+
for (let i = 0; i < length; i++) {
|
|
27
|
+
const randomIndex = Math.floor(Math.random() * characters.length);
|
|
28
|
+
code += characters[randomIndex];
|
|
29
|
+
}
|
|
30
|
+
return code;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
module.exports = new Utils();
|