-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.js
114 lines (108 loc) · 2.84 KB
/
models.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const Sequelize = require('sequelize');
// Initialize Sequelize with your PostgreSQL database credentials
const sequelize = new Sequelize({
database: 'postgres',
username: 'postgres',
password: 'admin',
dialect: 'postgres',
host: '127.0.0.1'
});
// Define the Users model
const Users = sequelize.define('users', {
id: {
allowNull: false,
defaultValue: Sequelize.UUIDV4,
primaryKey: true,
type: Sequelize.UUID,
},
username: {
type: Sequelize.STRING,
allowNull: false,
},
email: {
type: Sequelize.STRING,
allowNull: false,
},
password: {
type: Sequelize.STRING,
allowNull: false,
},
mobileNo: {
type: Sequelize.STRING,
allowNull: false,
},
firstName: {
type: Sequelize.STRING,
allowNull: false,
},
lastName: {
type: Sequelize.STRING,
allowNull: false,
},
accountType: {
type: Sequelize.STRING,
allowNull: false,
},
companyId: {
type: Sequelize.INTEGER,
allowNull: false,
},
verifiedEmail: {
type: Sequelize.SMALLINT,
allowNull: false,
},
verifiedMobile: {
type: Sequelize.SMALLINT,
allowNull: false,
},
createdAt: { // Change column name to 'createdAt'
allowNull: false,
type: Sequelize.DATE,
field: 'created_at' // Add field option for custom column name
},
updatedAt: { // Change column name to 'updatedAt'
allowNull: false,
type: Sequelize.DATE,
field: 'updated_at' // Add field option for custom column name
},
});
// Define the Bank Account model
const Bank_accounts = sequelize.define('bank_accounts', {
id: {
allowNull: false,
defaultValue: Sequelize.UUIDV4,
primaryKey: true,
type: Sequelize.UUID,
},
user_id: {
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4,
primaryKey: true,
},
account_number: {
type: Sequelize.STRING,
unique: true // Add unique constraint
},
createdAt: { // Change column name to 'createdAt'
allowNull: false,
type: Sequelize.DATE,
field: 'created_at' // Add field option for custom column name
},
updatedAt: { // Change column name to 'updatedAt'
allowNull: false,
type: Sequelize.DATE,
field: 'updated_at' // Add field option for custom column name
}
});
// Set up associations between Users and Bank_accounts
Users.hasMany(Bank_accounts, { foreignKey: 'user_id' });
Bank_accounts.belongsTo(Users, { foreignKey: 'user_id' });
// Sync the model with the database
sequelize.sync()
.then(() => {
console.log('Database and tables synced successfully');
})
.catch((err) => {
console.error('Error syncing database:', err);
});
module.exports = { Users, Bank_accounts };