-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
54 lines (40 loc) · 1.48 KB
/
app.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
const express = require("express");
const morgan = require("morgan");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const User = require("./models/user");
const Category = require("./models/category");
const Expense = require("./models/expense");
const Comment = require("./models/comment");
const CategoryItem = require("./models/categoryItem");
/** @Associations */
User.hasMany(Category);
Category.belongsTo(User, { onDelete: "CASCADE" });
User.hasMany(Expense);
Expense.belongsTo(User, { onDelete: "CASCADE" });
Category.hasMany(Expense);
Expense.belongsToMany(Category, { through: CategoryItem });
Category.belongsToMany(Expense, { through: CategoryItem });
Expense.hasMany(Comment);
Comment.belongsTo(Expense, { constraints: true, onDelete: "CASCADE" });
const authRoutes = require("./routes/auth");
const categoryRoutes = require("./routes/category");
const expenseRoutes = require("./routes/expense");
const commentRoutes = require("./routes/comment");
const errhandler = require("./middlewares/errhandler");
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(morgan("dev"));
app.use("/auth", authRoutes);
app.use("/categories", categoryRoutes);
app.use("/expenses", expenseRoutes);
app.use("/comments", commentRoutes);
app.use("/", (req, res, next) => {
res.status(404).json({
message: "not found",
});
});
app.use(errhandler);
module.exports = app;