Files
citas_recorridos_api/server/controller/PrimerSemestre/asistencia.js
T
2021-07-21 09:07:59 -05:00

25 lines
788 B
JavaScript

const helperPath = '../../helper';
const validar = require(`${helperPath}/validar`);
const dbPath = '../../db/tablas';
const PrimerSemestre = require(`${dbPath}/PrimerSemestre`);
const asistencia = async (body) => {
const idPrimerSemestre = validar.validarId(body.idPrimerSemestre);
return PrimerSemestre.findOne({ where: { idPrimerSemestre } })
.then((res) => {
if (!res) throw new Error('No existe este alumno.');
if (res.asistio)
throw new Error('Ya fue registrada la asistencia de este alumno.');
return PrimerSemestre.update(
{ asistio: true },
{ where: { idPrimerSemestre } }
);
})
.then((res) => ({
message: 'Se registro correctamente la asistencia de este alumno.',
}));
};
module.exports = asistencia;