21 lines
733 B
JavaScript
21 lines
733 B
JavaScript
const models = require("../../models");
|
|
|
|
module.exports = socket => {
|
|
return async (data) => {
|
|
let options = {where: {}, include: [{model: models.Semester, require: true}]};
|
|
if (data.number)
|
|
options.where.number = data.number;
|
|
if (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};
|
|
}
|
|
if (data.users)
|
|
options.include.push({model: models.User, require: true});
|
|
|
|
socket.emit("groupGet", await models.Group.findAll(options));
|
|
}
|
|
};
|