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 => {
|
module.exports = socket => {
|
||||||
return async (data) => {
|
return async (data) => {
|
||||||
let options = {where: {}, include: [{model: models.Semester, require: true}]};
|
let options = {include: [{model: models.Semester}]};
|
||||||
if (data.number)
|
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;
|
options.where.number = data.number;
|
||||||
if (data.semester) {
|
if (data && data.semester) {
|
||||||
let s = await models.Semester.findByPk(data.semester);
|
let s = await models.Semester.findByPk(data.semester);
|
||||||
if (!s) {
|
if (!s) {
|
||||||
socket.emit("groupGet", {error: {message: "semester_not_found"}});
|
socket.emit("groupGet", {error: {message: "semester_not_found"}});
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
options.include[0].where = {id: s.id};
|
options.include[0].where = {id: s.id};
|
||||||
|
options.include[0].require = true;
|
||||||
}
|
}
|
||||||
if (data.users)
|
if (data && data.users)
|
||||||
options.include.push({model: models.User, require: true});
|
options.include.push({model: models.User, where: {email: {[models.Sequelize.Op.in]: data.users}}, require: true});
|
||||||
|
|
||||||
socket.emit("groupGet", await models.Group.findAll(options));
|
socket.emit("groupGet", await models.Group.findAll(options));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,17 @@ const models = require("../../models");
|
||||||
|
|
||||||
module.exports = socket => {
|
module.exports = socket => {
|
||||||
return async (data) => {
|
return async (data) => {
|
||||||
let options = {where: {}, include: []};
|
let options = {include: [{model: models.Group}]};
|
||||||
if (data.name)
|
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;
|
options.where.name = data.name;
|
||||||
if (data.year)
|
if (data && data.year)
|
||||||
options.where.year = data.year;
|
options.where.year = data.year;
|
||||||
if (data.groups)
|
if (data && data.groups)
|
||||||
options.include.push({model: models.Group, require: true});
|
options.include[0].where = {id: {[models.Sequelize.Op.or]: data.groups}};
|
||||||
|
|
||||||
socket.emit("semesterGet", await models.Semester.findAll(options));
|
socket.emit("semesterGet", await models.Semester.findAll(options));
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,11 @@ module.exports = socket => {
|
||||||
socket.on("gradeGet", require("./get/gradeGet")(socket));
|
socket.on("gradeGet", require("./get/gradeGet")(socket));
|
||||||
if (socket.request.session.user.permissions > 1)
|
if (socket.request.session.user.permissions > 1)
|
||||||
socket.on("evaluationGet", require("./get/evaluationGet")(socket));
|
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.on("userSet", require("./set/userSet")(socket));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
socket.emit("connected");
|
socket.emit("connected");
|
||||||
};
|
};
|
||||||
|
|
Reference in a new issue