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/sockets/get/groupGet.js

27 lines
998 B
JavaScript
Raw Permalink Normal View History

2020-11-24 08:47:13 +01:00
const models = require("../../models");
module.exports = socket => {
return async (data) => {
2020-12-14 23:13:32 +01:00
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)
2020-11-24 08:47:13 +01:00
options.where.number = data.number;
2020-12-14 23:13:32 +01:00
if (data && data.semester) {
2020-11-24 08:47:13 +01:00
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};
2020-12-14 23:13:32 +01:00
options.include[0].require = true;
2020-11-24 08:47:13 +01:00
}
2020-12-14 23:13:32 +01:00
if (data && data.users)
options.include.push({model: models.User, where: {email: {[models.Sequelize.Op.in]: data.users}}, require: true});
2020-11-24 08:47:13 +01:00
socket.emit("groupGet", await models.Group.findAll(options));
}
};