-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
41 lines (41 loc) · 1018 Bytes
/
server.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
'use strict'
const express = require("express")
const dbDatabase = require("./models")
const { Model } = require('sequelize')
/*const app = express()
app.listen(8080,() => {
console.log("le serveur tourne sur le porte 8080")
});*/
dbDatabase.sequelize.sync({ force: true }).then(() => {
console.log("Connecté à MySQL");
});
module.exports = (sequelize, DataTypes) => {
class Post extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
models.Post.belongsTo(models.User, {
foreignKey: {
allowNull: false,
},
})
models.Post.hasMany(models.Comment)
}
}
Post.init(
{
userId: DataTypes.INTEGER,
message: DataTypes.STRING,
image: DataTypes.STRING,
createdAt: DataTypes.DATE,
},
{
sequelize,
modelName: 'Post',
}
)
return Post
}