ya no deberían haber duplicados

This commit is contained in:
2022-10-14 12:16:24 -05:00
parent 0aa406fb15
commit 6c1d967c8c
3 changed files with 60 additions and 28 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ const liberacion = async (body) => {
.then((res) => CasoEspecial.update(update, { where: { idCasoEspecial } }))
.then((res) => ({
message:
'Se cambio de estatus correctamente y se envio un correo al alumno informandole de su liberación.',
'Se cambió de estatus correctamente y se envió un correo al alumno informandole de su liberación.',
}));
};
+31 -21
View File
@@ -41,7 +41,6 @@ const nuevo = async (body, file) => {
const profesor = body.profesor
? validar.validarTexto(body.profesor, 'profesor', true, 50)
: '';
let carpeta = '';
return Usuario.findOne({
where: { idUsuario },
@@ -65,19 +64,7 @@ const nuevo = async (body, file) => {
.then(async (res) => {
if (res)
throw new Error('Este alumno ya tienen un Servicio Social activo.');
return drive.folder(numeroCuenta);
})
.then((res) => {
carpeta = res;
return drive.uploadFile(
path,
`Carta_Aceptacion.pdf`,
'application/pdf',
carpeta
);
})
.then((res) =>
Servicio.create({
return Servicio.create({
idUsuario,
idPrograma,
idCarrera,
@@ -85,15 +72,38 @@ const nuevo = async (body, file) => {
correo,
fechaInicio: fechaInicio.format(),
fechaFin: fechaFin.format(),
carpeta,
cartaAceptacion: res,
carpeta: '',
cartaAceptacion: '',
profesor,
programaInterno,
})
)
.then((res) => ({
message: `Se Pre-Registro correctamente a este alumno alumno.`,
}));
});
})
.then((servicio) => {
let carpeta = '';
drive
.folder(numeroCuenta)
.then((res) => {
carpeta = res;
return drive.uploadFile(
path,
`Carta_Aceptacion.pdf`,
'application/pdf',
carpeta
);
})
.then((res) =>
Servicio.update(
{ carpeta, cartaAceptacion: res },
{ where: { idServicio: servicio.idServicio } }
)
)
.then((res) => {
console.log(res);
console.log("Se subió el archivo");
});
return { message: `Se Pre-Registro correctamente a este alumno alumno.` };
});
};
module.exports = nuevo;
+28 -6
View File
@@ -144,15 +144,37 @@ const folder = async (numeroCuenta) => {
return mkDir(numeroCuenta);
};
const borrarTodo = () => {
return list().then(async (res) => {
for (let i = 0; i < res.files.length; i++)
if (res.files[i].id !== process.env.CARPETA)
await deleteFile(res.files[i].id);
});
// const borrarTodo = () => {
// return list().then(async (res) => {
// for (let i = 0; i < res.files.length; i++)
// if (res.files[i].id !== process.env.CARPETA)
// await deleteFile(res.files[i].id);
// });
// };
const findAll = async () => {
const folders = [];
const pdfs = [];
let pageToken = '';
do {
await list(pageToken).then((res) => {
for (let i = 0; i < res.files.length; i++) {
if (res.files[i].id !== process.env.CARPETA) {
if (res.files[i].mimeType === 'application/vnd.google-apps.folder')
folders.push(res.files[i].id);
if (res.files[i].mimeType === 'application/pdf')
pdfs.push(res.files[i].id);
}
}
pageToken = res.nextPageToken ? res.nextPageToken : '';
});
} while (pageToken);
return { folders, pdfs };
};
module.exports = {
folder,
uploadFile,
findAll,
};