Update groupGet and semesterGet
This commit is contained in:
parent
b930cd11ea
commit
25d228a035
3 changed files with 23 additions and 11 deletions
|
@ -2,19 +2,24 @@ const models = require("../../models");
|
|||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
let options = {where: {}, include: [{model: models.Semester, require: true}]};
|
||||
if (data.number)
|
||||
let options = {include: [{model: models.Semester}]};
|
||||
if (data && (data.id || data.number || data.semester))
|
||||
options.where = {};
|
||||
if (data && data.id)
|
||||
options.where.id = data.id;
|
||||
if (data && data.number)
|
||||
options.where.number = data.number;
|
||||
if (data.semester) {
|
||||
if (data && data.semester) {
|
||||
let s = await models.Semester.findByPk(data.semester);
|
||||
if (!s) {
|
||||
socket.emit("groupGet", {error: {message: "semester_not_found"}});
|
||||
return
|
||||
}
|
||||
options.include[0].where = {id: s.id};
|
||||
options.include[0].require = true;
|
||||
}
|
||||
if (data.users)
|
||||
options.include.push({model: models.User, require: true});
|
||||
if (data && data.users)
|
||||
options.include.push({model: models.User, where: {email: {[models.Sequelize.Op.in]: data.users}}, require: true});
|
||||
|
||||
socket.emit("groupGet", await models.Group.findAll(options));
|
||||
}
|
||||
|
|
|
@ -2,13 +2,17 @@ const models = require("../../models");
|
|||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
let options = {where: {}, include: []};
|
||||
if (data.name)
|
||||
let options = {include: [{model: models.Group}]};
|
||||
if (data && (data.id || data.name || data.year))
|
||||
options.where = {};
|
||||
if (data && data.id)
|
||||
options.where.id = data.id;
|
||||
if (data && data.name)
|
||||
options.where.name = data.name;
|
||||
if (data.year)
|
||||
if (data && data.year)
|
||||
options.where.year = data.year;
|
||||
if (data.groups)
|
||||
options.include.push({model: models.Group, require: true});
|
||||
if (data && data.groups)
|
||||
options.include[0].where = {id: {[models.Sequelize.Op.or]: data.groups}};
|
||||
|
||||
socket.emit("semesterGet", await models.Semester.findAll(options));
|
||||
}
|
||||
|
|
|
@ -13,8 +13,11 @@ module.exports = socket => {
|
|||
socket.on("gradeGet", require("./get/gradeGet")(socket));
|
||||
if (socket.request.session.user.permissions > 1)
|
||||
socket.on("evaluationGet", require("./get/evaluationGet")(socket));
|
||||
if (socket.request.session.user.permissions > 2)
|
||||
if (socket.request.session.user.permissions > 2) {
|
||||
socket.on("groupGet", require("./get/groupGet")(socket));
|
||||
socket.on("semesterGet", require("./get/semesterGet")(socket));
|
||||
socket.on("userSet", require("./set/userSet")(socket));
|
||||
}
|
||||
}
|
||||
socket.emit("connected");
|
||||
};
|
||||
|
|
Reference in a new issue