@churchsoln/dbms 1.0.33 → 1.0.34

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.
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ module.exports = {
3
+ up: async (queryInterface, DataTypes) => {
4
+ await queryInterface
5
+ .createTable(
6
+ "ContributionBatch",
7
+ {
8
+ id: {
9
+ type: DataTypes.BIGINT,
10
+ autoIncrement: true,
11
+ primaryKey: true,
12
+ },
13
+ batchDate: {
14
+ type: DataTypes.DATEONLY,
15
+ allowNull: false,
16
+ validate: {
17
+ notNull: { msg: "Batch date is required" },
18
+ isDate: { msg: "Batch date must be a valid date" },
19
+ },
20
+ },
21
+ description: {
22
+ type: DataTypes.TEXT,
23
+ },
24
+ closed: {
25
+ type: DataTypes.BOOLEAN,
26
+ defaultValue: false,
27
+ },
28
+ createdAt: {
29
+ type: DataTypes.DATE,
30
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
31
+ },
32
+ updatedAt: {
33
+ type: DataTypes.DATE,
34
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
35
+ },
36
+ },
37
+ { timestamps: false }
38
+ )
39
+ },
40
+ down: async (queryInterface) => {
41
+ await queryInterface.dropTable("ContributionBatch");
42
+ },
43
+ }
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ module.exports = {
3
+ up: async (queryInterface, DataTypes) => {
4
+ await queryInterface
5
+ .createTable(
6
+ "ContributionTransaction",
7
+ {
8
+ id: {
9
+ type: DataTypes.BIGINT,
10
+ autoIncrement: true,
11
+ primaryKey: true,
12
+ },
13
+ contributionBatchId: {
14
+ type: DataTypes.INTEGER,
15
+ references: {
16
+ model: "ContributionBatch",
17
+ key: "id",
18
+ },
19
+ onDelete: "CASCADE",
20
+ },
21
+ memberId: {
22
+ type: DataTypes.INTEGER,
23
+ references: {
24
+ model: "Member",
25
+ key: "id",
26
+ },
27
+ onDelete: "CASCADE",
28
+ },
29
+ transferTypeId: {
30
+ type: DataTypes.INTEGER,
31
+ references: {
32
+ model: "TransferType",
33
+ key: "id",
34
+ },
35
+ onDelete: "SET NULL",
36
+ },
37
+ transferedAt: {
38
+ type: DataTypes.DATEONLY,
39
+ allowNull: false,
40
+ validate: {
41
+ notNull: { msg: "Transfer date is required" },
42
+ isDate: { msg: "Transfer date must be a valid date" },
43
+ },
44
+ },
45
+ amount: {
46
+ type: DataTypes.DECIMAL(10, 2),
47
+ validate: {
48
+ isDecimal: { msg: "Total amount must be a valid decimal" },
49
+ },
50
+ },
51
+ confirmationNo: {
52
+ type: DataTypes.TEXT,
53
+ },
54
+ isTaxable: {
55
+ type: DataTypes.BOOLEAN,
56
+ defaultValue: false,
57
+ },
58
+ isLoosePlate: { type: DataTypes.BOOLEAN, defaultValue: false },
59
+ notes: {
60
+ type: DataTypes.TEXT,
61
+ },
62
+ fullName: { type: DataTypes.STRING },
63
+ status: {
64
+ type: DataTypes.ENUM("Pending", "Cleared", "Voided", "Reversed"),
65
+ allowNull: false,
66
+ validate: {
67
+ isIn: {
68
+ args: [["Pending", "Cleared", "Voided", "Reversed"]],
69
+ msg: "Status must be one of Pending, Cleared, Voided, Reversed",
70
+ },
71
+ },
72
+ },
73
+ createdAt: {
74
+ type: DataTypes.DATE,
75
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
76
+ },
77
+ updatedAt: {
78
+ type: DataTypes.DATE,
79
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
80
+ },
81
+ },
82
+ { timestamps: false }
83
+ )
84
+ },
85
+ down: async (queryInterface) => {
86
+ await queryInterface.dropTable("ContributionTransaction");
87
+ },
88
+ }
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ module.exports = {
3
+ up: async (queryInterface, DataTypes) => {
4
+ await queryInterface
5
+ .createTable(
6
+ "ContributionTransactionLine",
7
+ {
8
+ id: {
9
+ type: DataTypes.BIGINT,
10
+ autoIncrement: true,
11
+ primaryKey: true,
12
+ },
13
+ contributionTransactionId: {
14
+ type: DataTypes.BIGINT,
15
+ allowNull: false,
16
+ validate: {
17
+ notNull: { msg: "Transaction ID is required" },
18
+ isInt: { msg: "Transaction ID must be an integer" },
19
+ },
20
+ references: {
21
+ model: "ContributionTransaction",
22
+ key: "id",
23
+ },
24
+ onDelete: "CASCADE",
25
+ },
26
+ accountId: {
27
+ type: DataTypes.BIGINT,
28
+ allowNull: false,
29
+ validate: {
30
+ notNull: { msg: "Account ID is required" },
31
+ isInt: { msg: "Account ID must be an integer" },
32
+ },
33
+ references: {
34
+ model: "Accounts",
35
+ key: "id",
36
+ },
37
+ onDelete: "SET NULL",
38
+ },
39
+ amount: {
40
+ type: DataTypes.DECIMAL(10, 2),
41
+ allowNull: false,
42
+ validate: {
43
+ notNull: { msg: "Amount is required" },
44
+ isDecimal: { msg: "Amount must be a valid decimal" },
45
+ minAmount(value) {
46
+ if (parseFloat(value) <= 0) {
47
+ throw new Error("Amount must be greater than 0");
48
+ }
49
+ },
50
+ },
51
+ },
52
+ isTaxable: {
53
+ type: DataTypes.BOOLEAN,
54
+ defaultValue: true,
55
+ },
56
+ memo: {
57
+ type: DataTypes.TEXT,
58
+ },
59
+ },
60
+ { timestamps: false }
61
+ )
62
+ },
63
+ down: async (queryInterface) => {
64
+ await queryInterface.dropTable("ContributionTransactionLine");
65
+ },
66
+ }
@@ -0,0 +1,39 @@
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const contributionBatch = sequelize.define(
3
+ "ContributionBatch",
4
+ {
5
+ id: {
6
+ type: DataTypes.BIGINT,
7
+ autoIncrement: true,
8
+ primaryKey: true,
9
+ },
10
+ batchDate: {
11
+ type: DataTypes.DATEONLY,
12
+ allowNull: false,
13
+ validate: {
14
+ notNull: { msg: "Batch date is required" },
15
+ isDate: { msg: "Batch date must be a valid date" },
16
+ },
17
+ },
18
+ description: {
19
+ type: DataTypes.TEXT,
20
+ },
21
+ closed: {
22
+ type: DataTypes.BOOLEAN,
23
+ defaultValue: false,
24
+ },
25
+ createdAt: { type: DataTypes.DATE },
26
+ updatedAt: { type: DataTypes.DATE },
27
+ },
28
+ { freezeTableName: true, timestamps: false }
29
+ );
30
+ contributionBatch.selectedFields = [
31
+ "id",
32
+ "batchDate",
33
+ "description",
34
+ "closed",
35
+ "createdAt",
36
+ "updatedAt"
37
+ ];
38
+ return contributionBatch;
39
+ };
@@ -0,0 +1,91 @@
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const contributionTransaction = sequelize.define(
3
+ "ContributionTransaction",
4
+ {
5
+ id: {
6
+ type: DataTypes.BIGINT,
7
+ autoIncrement: true,
8
+ primaryKey: true,
9
+ },
10
+ contributionBatchId: { type: DataTypes.INTEGER },
11
+ memberId: { type: DataTypes.INTEGER },
12
+ transferTypeId: { type: DataTypes.INTEGER },
13
+ transferedAt: {
14
+ type: DataTypes.DATEONLY,
15
+ allowNull: false,
16
+ validate: {
17
+ notNull: { msg: "Transfer date is required" },
18
+ isDate: { msg: "Transfer date must be a valid date" },
19
+ },
20
+ },
21
+ amount: {
22
+ type: DataTypes.DECIMAL(10, 2),
23
+ validate: {
24
+ isDecimal: { msg: "Total amount must be a valid decimal" },
25
+ },
26
+ },
27
+ confirmationNo: {
28
+ type: DataTypes.TEXT,
29
+ },
30
+ isTaxable: {
31
+ type: DataTypes.BOOLEAN,
32
+ defaultValue: false,
33
+ },
34
+ isLoosePlate: { type: DataTypes.BOOLEAN, defaultValue: false },
35
+ notes: {
36
+ type: DataTypes.TEXT,
37
+ },
38
+ fullName: { type: DataTypes.STRING },
39
+ status: {
40
+ type: DataTypes.ENUM("Pending", "Cleared", "Voided", "Reversed"),
41
+ allowNull: false,
42
+ validate: {
43
+ isIn: {
44
+ args: [["Pending", "Cleared", "Voided", "Reversed"]],
45
+ msg: "Status must be one of Pending, Cleared, Voided, Reversed",
46
+ },
47
+ },
48
+ },
49
+ createdAt: {
50
+ type: DataTypes.DATE,
51
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
52
+ },
53
+ updatedAt: {
54
+ type: DataTypes.DATE,
55
+ defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
56
+ },
57
+ },
58
+ { freezeTableName: true, timestamps: false }
59
+ );
60
+ contributionTransaction.associate = function (models) {
61
+ contributionTransaction.belongsTo(models.contributionBatch, {
62
+ foreignKey: "contributionBatchId",
63
+ as: "contributionBatch",
64
+ });
65
+ contributionTransaction.belongsTo(models.member, {
66
+ foreignKey: "memberId",
67
+ as: "member",
68
+ });
69
+ contributionTransaction.belongsTo(models.transferType, {
70
+ foreignKey: "transferTypeId",
71
+ as: "transferType",
72
+ });
73
+ }
74
+ contributionTransaction.selectedFields = [
75
+ "id",
76
+ "contributionBatchId",
77
+ "memberId",
78
+ "transferTypeId",
79
+ "transferedAt",
80
+ "amount",
81
+ "confirmationNo",
82
+ "isTaxable",
83
+ "isLoosePlate",
84
+ "notes",
85
+ "fullName",
86
+ "status",
87
+ "createdAt",
88
+ "updatedAt",
89
+ ];
90
+ return contributionTransaction;
91
+ };
@@ -0,0 +1,58 @@
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const contributionTransactionLine = sequelize.define(
3
+ "ContributionTransactionLine",
4
+ {
5
+ id: {
6
+ type: DataTypes.BIGINT,
7
+ autoIncrement: true,
8
+ primaryKey: true,
9
+ },
10
+ contributionTransactionId: {
11
+ type: DataTypes.BIGINT,
12
+ allowNull: false,
13
+ validate: {
14
+ notNull: { msg: "Transaction ID is required" },
15
+ isInt: { msg: "Transaction ID must be an integer" },
16
+ },
17
+ },
18
+ accountId: {
19
+ type: DataTypes.BIGINT,
20
+ allowNull: false,
21
+ validate: {
22
+ notNull: { msg: "Account ID is required" },
23
+ isInt: { msg: "Account ID must be an integer" },
24
+ },
25
+ },
26
+ amount: {
27
+ type: DataTypes.DECIMAL(10, 2),
28
+ allowNull: false,
29
+ validate: {
30
+ notNull: { msg: "Amount is required" },
31
+ isDecimal: { msg: "Amount must be a valid decimal" },
32
+ minAmount(value) {
33
+ if (parseFloat(value) <= 0) {
34
+ throw new Error("Amount must be greater than 0");
35
+ }
36
+ },
37
+ },
38
+ },
39
+ isTaxable: {
40
+ type: DataTypes.BOOLEAN,
41
+ defaultValue: true,
42
+ },
43
+ memo: {
44
+ type: DataTypes.TEXT,
45
+ },
46
+ },
47
+ { freezeTableName: true, timestamps: false }
48
+ );
49
+ contributionTransactionLine.selectedFields = [
50
+ "id",
51
+ "contributionTransactionId",
52
+ "accountId",
53
+ "amount",
54
+ "isTaxable",
55
+ "memo"
56
+ ];
57
+ return contributionTransactionLine;
58
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@churchsoln/dbms",
3
- "version": "1.0.33",
3
+ "version": "1.0.34",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "prestart": "node db-setup.js",
@@ -1,73 +0,0 @@
1
- "use strict";
2
- module.exports = {
3
- up: async (queryInterface, DataTypes) => {
4
- await queryInterface
5
- .createTable(
6
- "Donation",
7
- {
8
- id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
9
- memberId: { type: DataTypes.INTEGER },
10
- transferTypeId: { type: DataTypes.INTEGER },
11
- accountId: { type: DataTypes.INTEGER },
12
- transferedAt: { type: DataTypes.DATE },
13
- amount: { type: DataTypes.INTEGER },
14
- isTaxable: { type: DataTypes.BOOLEAN, defaultValue: false },
15
- isLoosePlate: { type: DataTypes.BOOLEAN, defaultValue: false },
16
- fullName: { type: DataTypes.STRING },
17
- note: { type: DataTypes.TEXT },
18
- status: { type: DataTypes.BOOLEAN, defaultValue: true },
19
- createdAt: {
20
- type: DataTypes.DATE,
21
- defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
22
- },
23
- updatedAt: {
24
- type: DataTypes.DATE,
25
- defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
26
- },
27
- },
28
- { timestamps: false }
29
- )
30
- .then(() =>
31
- queryInterface.addConstraint("Donation", {
32
- fields: ["memberId"],
33
- type: "foreign key",
34
- name: "Donation_MemberId_Fkey",
35
- references: {
36
- table: "Member",
37
- field: "id",
38
- },
39
- onDelete: "cascade",
40
- onUpdate: "cascade",
41
- })
42
- )
43
- .then(() =>
44
- queryInterface.addConstraint("Donation", {
45
- fields: ["accountId"],
46
- type: "foreign key",
47
- name: "Donation_Account_Fkey",
48
- references: {
49
- table: "Accounts",
50
- field: "id",
51
- },
52
- onDelete: "cascade",
53
- onUpdate: "cascade",
54
- })
55
- )
56
- .then(() =>
57
- queryInterface.addConstraint("Donation", {
58
- fields: ["transferTypeId"],
59
- type: "foreign key",
60
- name: "Donation_TransferType_Fkey",
61
- references: {
62
- table: "TransferType",
63
- field: "id",
64
- },
65
- onDelete: "cascade",
66
- onUpdate: "cascade",
67
- })
68
- );
69
- },
70
- down: async (queryInterface) => {
71
- await queryInterface.dropTable("Donation");
72
- },
73
- };
@@ -1,71 +0,0 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const donation = sequelize.define(
3
- "Donation",
4
- {
5
- id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
6
- memberId: {
7
- type: DataTypes.INTEGER,
8
- set(memberId) {
9
- this.setDataValue("memberId", memberId?.id || memberId);
10
- },
11
- },
12
- transferTypeId: {
13
- type: DataTypes.INTEGER,
14
- set(transferTypeId) {
15
- this.setDataValue("transferTypeId", transferTypeId?.id || transferTypeId);
16
- },
17
- },
18
- accountId: {
19
- type: DataTypes.INTEGER,
20
- set(accountId) {
21
- this.setDataValue("accountId", accountId?.id || accountId);
22
- },
23
- },
24
- transferedAt: { type: DataTypes.DATE },
25
- amount: { type: DataTypes.INTEGER },
26
- isTaxable: { type: DataTypes.BOOLEAN, defaultValue: false },
27
- isLoosePlate: { type: DataTypes.BOOLEAN, defaultValue: false },
28
- note: { type: DataTypes.TEXT },
29
- fullName: { type: DataTypes.STRING },
30
- status: { type: DataTypes.BOOLEAN, defaultValue: true },
31
- createdAt: {
32
- type: DataTypes.DATE,
33
- defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
34
- },
35
- updatedAt: {
36
- type: DataTypes.DATE,
37
- defaultValue: DataTypes.literal("CURRENT_TIMESTAMP"),
38
- },
39
- },
40
- { freezeTableName: true, timestamps: false }
41
- );
42
- donation.associate = function (models) {
43
- donation.belongsTo(models.member, {
44
- foreignKey: "memberId",
45
- as: "member",
46
- });
47
- donation.belongsTo(models.transferType, {
48
- foreignKey: "transferTypeId",
49
- as: "transferType",
50
- });
51
- donation.belongsTo(models.accounts, {
52
- foreignKey: "accountId",
53
- as: "accounts",
54
- });
55
- };
56
- donation.selectedFields = [
57
- "id",
58
- "memberId",
59
- "transferTypeId",
60
- "accountId",
61
- "transferedAt",
62
- "amount",
63
- "isTaxable",
64
- "isLoosePlate",
65
- "note",
66
- "fullName",
67
- "status",
68
- "createdAt"
69
- ];
70
- return donation;
71
- };