Add DB models
This commit is contained in:
parent
a00bf323da
commit
1ad5056ba7
7 changed files with 118 additions and 0 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -112,3 +112,7 @@ config/config.json
|
|||
|
||||
# Sass output
|
||||
public/stylesheets
|
||||
|
||||
# Floobits
|
||||
.floo
|
||||
.flooignore
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
"contact": "Your Contact <contact@your-email.fr>",
|
||||
"mailPath": "https://yourServer.com"
|
||||
},
|
||||
"edt": "https://adelb.univ-lyon1.fr/jsp/custom/modules/plannings/anonymous_cal.jsp?resources=XXXX&projectId=XXXX&calType=ical&firstDate=",
|
||||
"secret": "keyboard cat",
|
||||
"passwordPrivateKey": "ecc635295f200847b79299df48e15759"
|
||||
}
|
||||
|
|
23
models/UE.js
Normal file
23
models/UE.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
"use strict";
|
||||
|
||||
const { Model } = require("sequelize");
|
||||
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
class UE extends Model {
|
||||
static associate(models) {
|
||||
UE.hasMany(models.Event);
|
||||
UE.belongsToMany(models.User, {through: "UEUser"});
|
||||
}
|
||||
}
|
||||
UE.init({
|
||||
name : {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: true
|
||||
}
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: "UE",
|
||||
});
|
||||
return UE;
|
||||
};
|
36
models/event.js
Normal file
36
models/event.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
"use strict";
|
||||
|
||||
const { Model } = require("sequelize");
|
||||
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
class Event extends Model {
|
||||
static associate(models) {
|
||||
Event.belongsToMany(models.Semester, {through: "EventSemester"});
|
||||
Event.belongsToMany(models.Group, {through: "EventGroup"});
|
||||
Event.belongsToMany(models.User, {through: "EventTeacher"});
|
||||
Event.belongsTo(models.UE);
|
||||
}
|
||||
}
|
||||
Event.init({
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
locations: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
startDate: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false
|
||||
},
|
||||
endDate: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: "Event",
|
||||
});
|
||||
return Event;
|
||||
};
|
23
models/group.js
Normal file
23
models/group.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
"use strict";
|
||||
|
||||
const { Model } = require("sequelize");
|
||||
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
class Group extends Model {
|
||||
static associate(models) {
|
||||
Group.belongsTo(models.Semester);
|
||||
Group.belongsToMany(models.User, {through: "UserGroup"});
|
||||
Group.belongsToMany(models.Event, {through: "EventGroup"});
|
||||
}
|
||||
}
|
||||
Group.init({
|
||||
number: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: "Group",
|
||||
});
|
||||
return Group;
|
||||
};
|
28
models/semester.js
Normal file
28
models/semester.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
"use strict";
|
||||
|
||||
const { Model } = require("sequelize");
|
||||
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
class Semester extends Model {
|
||||
static associate(models) {
|
||||
Semester.hasMany(models.Group);
|
||||
Semester.belongsToMany(models.Event, {through: "EventSemester"});
|
||||
}
|
||||
}
|
||||
Semester.init({
|
||||
year: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
unique: "semester"
|
||||
},
|
||||
name : {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: "semester"
|
||||
}
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: "Semester",
|
||||
});
|
||||
return Semester;
|
||||
};
|
|
@ -18,6 +18,9 @@ module.exports = (sequelize, DataTypes) => {
|
|||
|
||||
class User extends Model {
|
||||
static associate(models) {
|
||||
User.belongsToMany(models.Group, {through: "UserGroup"});
|
||||
User.belongsToMany(models.Event, {through: "EventTeacher"})
|
||||
User.belongsToMany(models.UE, {through: "UEUser"});
|
||||
}
|
||||
|
||||
checkPassword(password) {
|
||||
|
|
Reference in a new issue