From 6c1d967c8cd48b42291aac7828fe443b3c309e0c Mon Sep 17 00:00:00 2001 From: lemuel Date: Fri, 14 Oct 2022 12:16:24 -0500 Subject: [PATCH] =?UTF-8?q?ya=20no=20deber=C3=ADan=20haber=20duplicados?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/controller/CasoEspecial/liberacion.js | 2 +- server/controller/Servicio/nuevo.js | 52 ++++++++++++-------- server/helper/drive.js | 34 ++++++++++--- 3 files changed, 60 insertions(+), 28 deletions(-) diff --git a/server/controller/CasoEspecial/liberacion.js b/server/controller/CasoEspecial/liberacion.js index c8b9031..ac8d147 100644 --- a/server/controller/CasoEspecial/liberacion.js +++ b/server/controller/CasoEspecial/liberacion.js @@ -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.', })); }; diff --git a/server/controller/Servicio/nuevo.js b/server/controller/Servicio/nuevo.js index 69d9deb..a80585a 100644 --- a/server/controller/Servicio/nuevo.js +++ b/server/controller/Servicio/nuevo.js @@ -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; diff --git a/server/helper/drive.js b/server/helper/drive.js index 6e5def0..4250e49 100644 --- a/server/helper/drive.js +++ b/server/helper/drive.js @@ -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, };