-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.js
37 lines (37 loc) · 1.15 KB
/
user.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
"use strict";
const { Model } = require("sequelize");
module.exports = (sequelize, DataTypes) => {
class user extends Model {
static associate(models) {
// define association here
user.hasMany(models.photos, { foreignKey: "userId", as: "photos" });
user.hasMany(models.reviews);
// user.hasMany(models.restSpace);
user.belongsToMany(models.restSpace, {
through: "favoriteRestaurants",
foreignKey: "userId",
});
user.belongsToMany(models.photos, {
through: "favoritephotos",
foreignKey: "userId",
as: "fav",
});
}
}
user.init(
{
name: { type: DataTypes.STRING, allowNull: false },
email: { type: DataTypes.STRING, allowNull: false, unique: true },
password: { type: DataTypes.STRING, allowNull: false },
restaurant: { type: DataTypes.BOOLEAN, defaultValue: false },
darkKitchen: { type: DataTypes.BOOLEAN, defaultValue: false },
country: { type: DataTypes.STRING, allowNull: false },
isAdmin: { type: DataTypes.BOOLEAN, defaultValue: false },
},
{
sequelize,
modelName: "user",
}
);
return user;
};