Files
servicio_social_api/server/db/actualizar.js
T
2021-03-24 20:09:14 -06:00

43 lines
1.2 KiB
JavaScript

const moment = require('moment');
const Servicio = require('./tablas/Servicio');
const lastYear = moment('2021-01-31');
const fechaLiberacion = async () => {
Servicio.findAll({ where: { idStatus: 6 } })
.then(async (res) => {
for (let i = 0; i < res.length; i++) {
let lastUpdate = moment(res[i].updatedAt);
if (lastUpdate <= lastYear) {
// await Servicio.update(
// { fechaLiberacion: lastYear },
// { where: { idServicio: res[i].idServicio } }
// );
console.log(
`El servicio con id ${res[i].idServicio} fue actualizado el ${res[i].updatedAt} año pasado`
);
} else {
// await Servicio.update(
// { fechaLiberacion: lastUpdate },
// { where: { idServicio: res[i].idServicio } }
// );
console.log(
`El servicio con id ${res[i].idServicio} fue actualizado el ${res[i].updatedAt} siguiente año`
);
}
}
})
.catch((err) => {
console.log(err);
});
};
fechaLiberacion();
/*
ALTER TABLE servicio ADD fechaLiberacion datetime
agrear campo fecha liberacion a la tabla servicio
asignar fecha de liberacipon a servicios liberados
*/