aboutsummaryrefslogtreecommitdiffstats
path: root/db/index.js
blob: 6fa225e6a81fe71b861fdb66a9a9f78b6f135382 (plain) (blame)
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
const Sequelize = require("sequelize");
const conf = config.dbOptions;

db = new Sequelize(conf.database, conf.username, conf.password, {
  host: conf.host,
  dialect: conf.dialect,
  logging: false,
  dialectOptions: conf.dialectOptions
});

require("./models/accounts.js");
require("./models/codes.js");
require("./models/invoices.js");
require("./models/keys.js");
require("./models/payments.js");
require("./models/proposals.js");
require("./models/users.js");

db["User"].hasMany(db["Account"], {
  as: "accounts",
  foreignKey: "user_id"
});

db["User"].hasMany(db["Invoice"], {
  as: "invoices",
  foreignKey: "user_id"
});

db["User"].hasMany(db["Key"], {
  as: "keys",
  foreignKey: "user_id"
});

db["User"].hasMany(db["Payment"], {
  as: "payments",
  foreignKey: "user_id"
});

db["User"].belongsTo(db["Account"], {
  as: "account",
  foreignKey: "account_id"
});

db["Invoice"].belongsTo(db["Account"], {
  as: "account",
  foreignKey: "account_id"
});

db["Account"].belongsTo(db["User"], {
  as: "user",
  foreignKey: "user_id"
});

db["Invoice"].belongsTo(db["User"], {
  as: "user",
  foreignKey: "user_id"
});

db["Key"].belongsTo(db["User"], {
  as: "user",
  foreignKey: "user_id"
});

db["Payment"].belongsTo(db["Account"], {
  as: "account",
  foreignKey: "account_id"
});

db["Payment"].belongsTo(db["User"], {
  as: "user",
  foreignKey: "user_id"
});

db["Proposal"].belongsTo(db["User"], {
  as: "user",
  foreignKey: "user_id"
});