funcion insertIdCarpetas ya jalando xd

This commit is contained in:
eithan
2021-01-14 21:18:37 -06:00
parent 16df3a5d66
commit 11879e8626
+52 -59
View File
@@ -1,99 +1,92 @@
const drive = require ("../helper/drive")
const drive = require("../helper/drive")
const Servicio = require('../db/tablas/Servicio');
const Usuario = require('../db/tablas/Usuario');
const getCarpetas = async ()=>{
const getCarpetas = async () => {
let listado = await drive.list()
let carpetas =[]
let noBorrar ='Babyhelon'
let carpetas = []
let noBorrar = 'Babyhelon'
for(let i = 0 ; i < listado.length; i++){
for (let i = 0; i < listado.length; i++) {
if (listado[i].mimeType == 'application/vnd.google-apps.folder')
carpetas.push( listado[i])
carpetas.push(listado[i])
}
carpetas = carpetas.filter(item => item.name !== noBorrar)
return carpetas
}
const duplicados = () =>{
getCarpetas().then((carpetas)=>{
const duplicados=[]
const duplicados = () => {
getCarpetas().then((carpetas) => {
const duplicados = []
const tempArray = [...carpetas].sort();
for (let i = 0; i < tempArray.length -1; i++) {
for (let i = 0; i < tempArray.length - 1; i++) {
if (tempArray[i + 1].name === tempArray[i].name) {
duplicados.push(tempArray[i]);
}
else{
if(i!=0 && tempArray[i-1].name === tempArray[i].name){
duplicados.push(tempArray[i]);
else {
if (i != 0 && tempArray[i - 1].name === tempArray[i].name) {
duplicados.push(tempArray[i]);
}
}
}
console.log(duplicados)
return duplicados
})
}
const getAlumnosNull = async () => {
return Servicio.findAll({
where:{carpeta:null},
where: { carpeta: null },
include: [
{ model: Usuario },
],
})
.then((res)=>{
const alumnosNull =[]
console.log("servicios con carpeta null = " + res.length )
for(let i= 0 ; i< res.length; i++){
alumnosNull.push(res[i].Usuario.usuario)
}
return alumnosNull
});
.then((res) => {
const alumnosNull = []
console.log("servicios con carpeta null = " + res.length)
for (let i = 0; i < res.length; i++) {
alumnosNull.push(res[i].Usuario.usuario)
}
return alumnosNull
});
}
const insertIdCarpetas = async ()=>{
const insertIdCarpetas = async () => {
getAlumnosNull()
.then ((alumnos)=>{
getCarpetas()
.then((carpetas)=>{
console.log(alumnos) // alumnos con carpeta null
console.log(carpetas) // carpetas disponibles en drive (este array aun tiene carpetas repetidas)
.then((alumnos) => {
for(let i= 0; i < alumnos.length; i++){
for(let j= 0; j < carpetas.length; j++){
if(alumnos[i] == carpetas[j].name ){
console.log(alumnos[i]) // alumnos qno tienen carpeta pero si existe su carpeta
/* return Servicio.findAll({
where:{carpeta:null},
include: [
{ model: Usuario, where:{idUsuario:alumnos[i]} },
],
})
.then((res)=>{
console.log(res)
}) */
getCarpetas()
.then(async(carpetas) => {
console.log(alumnos) // alumnos con carpeta null
console.log(carpetas) // carpetas disponibles en drive (este array aun tiene carpetas repetidas)
for (let i = 0; i < alumnos.length; i++) {
for (let j = 0; j < carpetas.length; j++) {
if (alumnos[i] == carpetas[j].name) {
console.log(alumnos[i]) // alumnos qno tienen carpeta pero si existe su carpeta
await Servicio.update({
carpeta: carpetas[j].id
},
{
where: { idUsuario: alumnos[i] }
}
)
.then((rep) => {
console.log(rep)
})
}
}
}
}
}
})
})
})
}
//duplicados()