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/set/gradeSet.js

20 lines
794 B
JavaScript
Raw Normal View History

2021-01-20 17:14:33 +01:00
const models = require("../../models");
module.exports = socket => {
return async (data) => {
if (!data || !data.evaluation || !data.grades) {
socket.emit("gradeSet", {error: {message: "missing_arguments"}});
return;
}
for (let student in data.grades) {
let grade = await models.Grade.findOne({where: {StudentGradeEmail: student, EvaluationId: data.evaluation}});
if (!grade) {
await models.Grade.create({TeacherGradeEmail: socket.request.session.user.email, StudentGradeEmail: student, EvaluationId: data.evaluation, score: data.grades[student], limit: 20})
} else {
grade.score = data.grades[student];
await grade.save();
}
}
}
};