1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
letu/models/group.js

32 lines
891 B
JavaScript
Raw Normal View History

2020-11-22 16:48:06 +01:00
"use strict";
const { Model } = require("sequelize");
module.exports = (sequelize, DataTypes) => {
class Group extends Model {
static associate(models) {
2021-01-20 17:14:33 +01:00
Group.belongsTo(models.Semester, {foreignKey: {allowNull: false}});
2020-11-22 16:48:06 +01:00
Group.belongsToMany(models.User, {through: "UserGroup"});
Group.belongsToMany(models.Event, {through: "EventGroup"});
}
}
2021-01-20 17:14:33 +01:00
return Group.init({
2020-11-22 16:48:06 +01:00
number: {
type: DataTypes.STRING,
allowNull: false
2021-01-20 17:14:33 +01:00
},
displayName: {
type: DataTypes.VIRTUAL,
get() {
if (this.number.startsWith("G"))
return this.number + this.Semester.name;
else
return this.Semester.name + " " + this.number
}
2020-11-22 16:48:06 +01:00
}
}, {
sequelize,
2021-01-20 17:14:33 +01:00
modelName: "Group"
2020-11-22 16:48:06 +01:00
});
};