@churchsoln/dbms 1.0.4 → 1.0.6

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.
@@ -1,6 +1,7 @@
1
1
  module.exports = {
2
2
  success: "Success",
3
3
  churchCreated: "Church created successfully",
4
+ churchUpdated: "Church updated successfully",
4
5
  churchAlreadyExists: "Church already exists",
5
6
  migrationInitiated: "Migration initiated successfully",
6
7
  seedInitiated: "Seed initiated successfully",
@@ -32,7 +32,7 @@ class ChurchController {
32
32
 
33
33
  async updateChurchById(req, res) {
34
34
  try {
35
- const result = await churchService.updateChurchByIdService({ ...req.params, ...req.query });
35
+ const result = await churchService.updateChurchByIdService({ ...req.params, ...req.body });
36
36
  response.success(req, res, result.code, result.data, result.message);
37
37
  } catch (err) {
38
38
  response.error(req, res, errorCodes.HTTP_INTERNAL_SERVER_ERROR, err);
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ up: async (queryInterface, DataTypes) => {
5
+ await queryInterface
6
+ .createTable(
7
+ "Group",
8
+ {
9
+ id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
10
+ name: { type: DataTypes.STRING },
11
+ description: { type: DataTypes.TEXT },
12
+ isInclude: { type: DataTypes.BOOLEAN, defaultValue: false },
13
+ isPrivate: { type: DataTypes.BOOLEAN, defaultValue: false },
14
+ maxMembers: { type: DataTypes.INTEGER, defaultValue: 50 },
15
+ profileUrl: { type: DataTypes.STRING },
16
+ status: { type: DataTypes.BOOLEAN, defaultValue: true },
17
+ createdAt: {
18
+ type: DataTypes.DATE,
19
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
20
+ },
21
+ updatedAt: {
22
+ type: DataTypes.DATE,
23
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
24
+ },
25
+ createdBy: { type: DataTypes.INTEGER },
26
+ updatedBy: { type: DataTypes.INTEGER },
27
+ deletedAt: { type: DataTypes.DATE },
28
+ deletedBy: { type: DataTypes.INTEGER },
29
+ },
30
+ { timestamps: false }
31
+ )
32
+ .then(() =>
33
+ queryInterface.addConstraint("Group", {
34
+ fields: ["createdBy"],
35
+ type: "foreign key",
36
+ name: "Group_CreatedBy_Fkey",
37
+ references: {
38
+ table: "User",
39
+ field: "id",
40
+ },
41
+ onDelete: "cascade",
42
+ onUpdate: "cascade",
43
+ })
44
+ ).then(() =>
45
+ queryInterface.addConstraint("Group", {
46
+ fields: ["updatedBy"],
47
+ type: "foreign key",
48
+ name: "Group_UpdatedBy_Fkey",
49
+ references: {
50
+ table: "User",
51
+ field: "id",
52
+ },
53
+ onDelete: "cascade",
54
+ onUpdate: "cascade",
55
+ })
56
+ );
57
+ },
58
+ down: async (queryInterface) => {
59
+ await queryInterface.dropTable("Group");
60
+ },
61
+ };
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ up: async (queryInterface, DataTypes) => {
5
+ await queryInterface
6
+ .createTable(
7
+ "GroupMembers",
8
+ {
9
+ id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
10
+ userId: { type: DataTypes.INTEGER },
11
+ groupId: { type: DataTypes.INTEGER },
12
+ isAdmin: { type: DataTypes.BOOLEAN, defaultValue: false },
13
+ status: { type: DataTypes.BOOLEAN, defaultValue: true },
14
+ createdAt: {
15
+ type: DataTypes.DATE,
16
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
17
+ },
18
+ updatedAt: {
19
+ type: DataTypes.DATE,
20
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
21
+ },
22
+ createdBy: { type: DataTypes.INTEGER },
23
+ updatedBy: { type: DataTypes.INTEGER },
24
+ }
25
+ ).then(() =>
26
+ queryInterface.addConstraint("GroupMembers", {
27
+ fields: ["userId"],
28
+ type: "foreign key",
29
+ name: "GroupMembers_UserId_Fkey",
30
+ references: {
31
+ table: "User",
32
+ field: "id",
33
+ },
34
+ onDelete: "cascade",
35
+ onUpdate: "cascade",
36
+ })
37
+ ).then(() =>
38
+ queryInterface.addConstraint("GroupMembers", {
39
+ fields: ["groupId"],
40
+ type: "foreign key",
41
+ name: "GroupMembers_GroupId_Fkey",
42
+ references: {
43
+ table: "Group",
44
+ field: "id",
45
+ },
46
+ onDelete: "cascade",
47
+ onUpdate: "cascade",
48
+ })
49
+ ).then(() =>
50
+ queryInterface.addConstraint("GroupMembers", {
51
+ fields: ["createdBy"],
52
+ type: "foreign key",
53
+ name: "GroupMembers_CreatedBy_Fkey",
54
+ references: {
55
+ table: "User",
56
+ field: "id",
57
+ },
58
+ onDelete: "cascade",
59
+ onUpdate: "cascade",
60
+ })
61
+ ).then(() =>
62
+ queryInterface.addConstraint("GroupMembers", {
63
+ fields: ["updatedBy"],
64
+ type: "foreign key",
65
+ name: "GroupMembers_UpdatedBy_Fkey",
66
+ references: {
67
+ table: "User",
68
+ field: "id",
69
+ },
70
+ onDelete: "cascade",
71
+ onUpdate: "cascade",
72
+ })
73
+ )
74
+ }
75
+ }
@@ -0,0 +1,74 @@
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const group = sequelize.define(
3
+ "Group",
4
+ {
5
+ id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
6
+ name: { type: DataTypes.STRING },
7
+ description: { type: DataTypes.TEXT },
8
+ isInclude: { type: DataTypes.BOOLEAN, defaultValue: false },
9
+ isPrivate: { type: DataTypes.BOOLEAN, defaultValue: false },
10
+ maxMembers: { type: DataTypes.INTEGER, defaultValue: 50 },
11
+ profileUrl: { type: DataTypes.STRING },
12
+ status: { type: DataTypes.BOOLEAN, defaultValue: true },
13
+ createdAt: {
14
+ type: DataTypes.DATE,
15
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
16
+ },
17
+ updatedAt: {
18
+ type: DataTypes.DATE,
19
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
20
+ },
21
+ createdBy: {
22
+ type: DataTypes.INTEGER,
23
+ set(createdBy) {
24
+ this.setDataValue("createdBy", createdBy?.id || createdBy);
25
+ },
26
+ },
27
+ updatedBy: {
28
+ type: DataTypes.INTEGER,
29
+ set(updatedBy) {
30
+ this.setDataValue("updatedBy", updatedBy?.id || updatedBy);
31
+ },
32
+ },
33
+ deletedAt: { type: DataTypes.DATE },
34
+ deletedBy: {
35
+ type: DataTypes.INTEGER,
36
+ set(deletedBy) {
37
+ this.setDataValue("deletedBy", deletedBy?.id || deletedBy);
38
+ },
39
+ },
40
+ },
41
+ { freezeTableName: true, timestamps: false }
42
+ );
43
+ group.associate = function (models) {
44
+ group.belongsTo(models.user, {
45
+ foreignKey: "createdBy",
46
+ as: "createdByUser",
47
+ });
48
+ group.belongsTo(models.user, {
49
+ foreignKey: "updatedBy",
50
+ as: "updatedByUser",
51
+ });
52
+ group.belongsTo(models.user, {
53
+ foreignKey: "deletedBy",
54
+ as: "deletedByUser",
55
+ });
56
+ };
57
+ group.selectedFields = [
58
+ "id",
59
+ "name",
60
+ "description",
61
+ "isInclude",
62
+ "isPrivate",
63
+ "maxMembers",
64
+ "profileUrl",
65
+ "status",
66
+ "createdAt",
67
+ "updatedAt",
68
+ "createdBy",
69
+ "updatedBy",
70
+ "deletedAt",
71
+ "deletedBy",
72
+ ];
73
+ return group;
74
+ };
@@ -0,0 +1,72 @@
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const groupMembers = sequelize.define(
3
+ "GroupMembers",
4
+ {
5
+ id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
6
+ userId: {
7
+ type: DataTypes.INTEGER,
8
+ set(userId) {
9
+ this.setDataValue("userId", userId?.id || userId);
10
+ },
11
+ },
12
+ groupId: {
13
+ type: DataTypes.INTEGER,
14
+ set(groupId) {
15
+ this.setDataValue("groupId", groupId?.id || groupId);
16
+ },
17
+ },
18
+ isAdmin: { type: DataTypes.BOOLEAN, defaultValue: false },
19
+ status: { type: DataTypes.BOOLEAN, defaultValue: true },
20
+ createdAt: {
21
+ type: DataTypes.DATE,
22
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
23
+ },
24
+ updatedAt: {
25
+ type: DataTypes.DATE,
26
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
27
+ },
28
+ createdBy: {
29
+ type: DataTypes.INTEGER,
30
+ set(createdBy) {
31
+ this.setDataValue("createdBy", createdBy?.id || createdBy);
32
+ },
33
+ },
34
+ updatedBy: {
35
+ type: DataTypes.INTEGER,
36
+ set(updatedBy) {
37
+ this.setDataValue("updatedBy", updatedBy?.id || updatedBy);
38
+ },
39
+ },
40
+ },
41
+ { freezeTableName: true, timestamps: false }
42
+ );
43
+ groupMembers.associate = function (models) {
44
+ groupMembers.belongsTo(models.user, {
45
+ foreignKey: "userId",
46
+ as: "user",
47
+ });
48
+ groupMembers.belongsTo(models.group, {
49
+ foreignKey: "groupId",
50
+ as: "group",
51
+ });
52
+ groupMembers.belongsTo(models.user, {
53
+ foreignKey: "createdBy",
54
+ as: "createdByUser",
55
+ });
56
+ groupMembers.belongsTo(models.user, {
57
+ foreignKey: "updatedBy",
58
+ as: "updatedByUser",
59
+ });
60
+ };
61
+ groupMembers.selectedFields = [
62
+ "id",
63
+ "userId",
64
+ "groupId",
65
+ "isAdmin",
66
+ "status",
67
+ "createdAt",
68
+ "updatedAt",
69
+ "createdBy",
70
+ "updatedBy",
71
+ ];
72
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@churchsoln/dbms",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "prestart": "node db-setup.js",
@@ -125,8 +125,8 @@
125
125
  },
126
126
  "patch": {
127
127
  "tags": ["Church API's"],
128
- "summary": "Activate/Deactivate Church by id",
129
- "operationId": "Activate/Deactivate Church by id",
128
+ "summary": "Update Church by id",
129
+ "operationId": "Update Church by id",
130
130
  "parameters": [
131
131
  {
132
132
  "name": "id",
@@ -139,19 +139,25 @@
139
139
  "format": "int32",
140
140
  "example": 1
141
141
  }
142
- },
143
- {
144
- "name": "status",
145
- "in": "query",
146
- "required": true,
147
- "style": "form",
148
- "explode": true,
149
- "schema": {
150
- "type": "boolean",
151
- "example": true
152
- }
153
142
  }
154
143
  ],
144
+ "requestBody": {
145
+ "content": {
146
+ "application/json": {
147
+ "schema": {
148
+ "$ref": "#/components/schemas/UpdateChurchDataRequest"
149
+ },
150
+ "example": {
151
+ "name": "Xavier",
152
+ "email": "email",
153
+ "phoneNumber": "1234",
154
+ "contactPerson": "string",
155
+ "subscriptionPlanId": 1,
156
+ "status": true
157
+ }
158
+ }
159
+ }
160
+ },
155
161
  "responses": {
156
162
  "200": {
157
163
  "description": "OK"
@@ -370,6 +376,40 @@
370
376
  }
371
377
  }
372
378
  },
379
+ "UpdateChurchDataRequest": {
380
+ "title": "UpdateChurchDataRequest",
381
+ "required": [],
382
+ "type": "object",
383
+ "properties": {
384
+ "name": {
385
+ "type": "string"
386
+ },
387
+ "email": {
388
+ "type": "string"
389
+ },
390
+ "phoneNumber": {
391
+ "type": "string"
392
+ },
393
+ "contactPerson": {
394
+ "type": "string"
395
+ },
396
+ "subscriptionPlanId": {
397
+ "type": "integer",
398
+ "format": "int32"
399
+ },
400
+ "status": {
401
+ "type": "boolean"
402
+ }
403
+ },
404
+ "example": {
405
+ "name": "Xavier",
406
+ "email": "email",
407
+ "phoneNumber": "1234",
408
+ "contactPerson": "string",
409
+ "subscriptionPlanId": 1,
410
+ "status": true
411
+ }
412
+ },
373
413
  "ChurchAdminDataRequest": {
374
414
  "title": "ChurchAdminDataRequest",
375
415
  "required": ["firstName", "lastName", "email", "phone", "password"],
@@ -16,6 +16,7 @@ module.exports = {
16
16
  { name: "Accounts", status: true },
17
17
  { name: "Donations", status: true },
18
18
  { name: "Transfer Type", status: true },
19
+ { name: "Groups", status: true },
19
20
  ];
20
21
 
21
22
  for (const permission of permissions) {
@@ -84,9 +84,14 @@ class ChurchService {
84
84
  const { search = null } = params;
85
85
  const searchCondition = !!search ? { name: { [Op.like]: `%${search}%` } } : {};
86
86
  const data = await commonDb.church.findAll({
87
- where: { status: true, ...searchCondition },
87
+ where: { ...searchCondition },
88
88
  attributes: commonDb.church.selectedFields,
89
- raw: true,
89
+ include: {
90
+ model: commonDb.subscriptionPlan,
91
+ as: "subscriptionPlan",
92
+ attributes: commonDb.subscriptionPlan.selectedFields,
93
+ required: false,
94
+ },
90
95
  });
91
96
  return { code: errorCodes.HTTP_OK, message: errorMsgs.success, data };
92
97
  } catch (err) {
@@ -110,10 +115,12 @@ class ChurchService {
110
115
 
111
116
  async updateChurchByIdService(params) {
112
117
  try {
113
- const { id, status } = params;
114
- await commonDb.church.update({ status }, { where: { id } });
115
- const message = status ? errorMsgs.activated : errorMsgs.deactivated;
116
- return { code: errorCodes.HTTP_OK, message };
118
+ const { id, ...restParams } = params;
119
+ if(restParams.subscriptionPlanId) {
120
+ restParams.subscribedAt = new Date();
121
+ }
122
+ await commonDb.church.update(restParams, { where: { id } });
123
+ return { code: errorCodes.HTTP_OK, message: errorMsgs.churchUpdated };
117
124
  } catch (err) {
118
125
  return { code: errorCodes.HTTP_INTERNAL_SERVER_ERROR, message: err };
119
126
  }
@@ -6,20 +6,9 @@ const schemas = {
6
6
  .max(20)
7
7
  .regex(/^[a-zA-Z]+$/)
8
8
  .required(),
9
- address: BaseJoi.string().required(),
10
- cityId: BaseJoi.number().required(),
11
- provinceId: BaseJoi.number().required(),
12
- country: BaseJoi.string().required(),
13
- postalCode: BaseJoi.string().required(),
14
9
  email: BaseJoi.string().required(),
15
10
  phoneNumber: BaseJoi.string().required(),
16
11
  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
- registeredAt: BaseJoi.string().required(),
22
- subscribedAt: BaseJoi.string().required(),
23
12
  subscriptionPlanId: BaseJoi.number().required(),
24
13
  churchAdminDetails: BaseJoi.object({
25
14
  firstName: BaseJoi.string().required(),
@@ -30,7 +19,13 @@ const schemas = {
30
19
  }).required(),
31
20
  }),
32
21
  updateChurch: BaseJoi.object({
33
- status: BaseJoi.boolean().required(),
22
+ id: BaseJoi.number().required(),
23
+ name: BaseJoi.string().optional(),
24
+ email: BaseJoi.string().optional(),
25
+ phoneNumber: BaseJoi.string().optional(),
26
+ contactPerson: BaseJoi.string().optional(),
27
+ subscriptionPlanId: BaseJoi.number().optional(),
28
+ status: BaseJoi.boolean().optional(),
34
29
  }),
35
30
  addChurchPermission: BaseJoi.object({
36
31
  churchId: BaseJoi.number().required(),
@@ -54,14 +49,14 @@ const options = {
54
49
  abortEarly: false,
55
50
  convert: true,
56
51
  allowUnknown: false,
57
- stripUnknown: true,
52
+ stripUnknown: false,
58
53
  },
59
54
  array: {
60
55
  abortEarly: false,
61
56
  convert: true,
62
- allowUnknown: true,
57
+ allowUnknown: false,
63
58
  stripUnknown: {
64
- objects: true,
59
+ objects: false,
65
60
  },
66
61
  },
67
62
  };
@@ -79,7 +74,7 @@ const updateChurch = async (req, res, next) => {
79
74
  const { updateChurch } = schemas;
80
75
  const { basic } = options;
81
76
  try {
82
- await updateChurch.validateAsync({ ...req.params, ...req.query }, basic);
77
+ await updateChurch.validateAsync({ ...req.params, ...req.body }, basic);
83
78
  next();
84
79
  } catch (err) {
85
80
  throwError(req, res, err);