Created
October 11, 2020 18:29
-
-
Save AZKZero/7b91d7cada8185d197c426924ac523df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as functions from 'firebase-functions'; | |
import admin = require('firebase-admin'); | |
import * as utilities from "./utilities" | |
admin.initializeApp(); | |
const fireStore = admin.firestore(); | |
// // Start writing Firebase Functions | |
// // https://firebase.google.com/docs/functions/typescript | |
// | |
// export const helloWorld = functions.https.onRequest((request, response) => { | |
// functions.logger.info("Hello logs!", {structuredData: true}); | |
// response.send("Hello from Firebase!"); | |
// }); | |
export const returnCollections = functions.https.onCall(async (data, context) => { | |
try { | |
const collections = await fireStore.listCollections(); | |
const responses: { [x: number]: any; }[] = []; | |
for (let index = 0; index < collections.length; index++) { | |
const inThatLevel: never[]=[]; | |
const element = collections[index]; | |
console.log(element); | |
let collectionsData = await element.get(); | |
console.log("Collection: "+collectionsData) | |
await Promise.all(collectionsData.docs.map(async (elementX) => { | |
utilities.listSubsEx(elementX, inThatLevel); | |
})) | |
/* element.get().forEach((elementX: any) => { | |
utilities.listSubsEx(elementX, responses); | |
}); */ | |
/* while(listEmptyCount) { | |
documentList.forEach(async elementX => { | |
if((await elementX.get()).exists) | |
}); | |
} */ | |
/* responses.push({ | |
[element.id]: element | |
}); */ | |
responses.push({ | |
[element.id]:inThatLevel | |
}) | |
} | |
/* collections.forEach(async (element) => { | |
// let documentList = await element.listDocuments(); | |
// let listEmptyCount = documentList.length; | |
console.log(element); | |
let collectionsData = await element.get(); | |
await Promise.all(collectionsData.docs.map(async (elementX) => { | |
utilities.listSubsEx(elementX, responses); | |
})) | |
/* element.get().forEach((elementX: any) => { | |
utilities.listSubsEx(elementX, responses); | |
}); */ | |
/* while(listEmptyCount) { | |
documentList.forEach(async elementX => { | |
if((await elementX.get()).exists) | |
}); | |
} */ /* | |
responses.push({ | |
[element.id]: element | |
}); | |
}); */ | |
return { | |
responses | |
} | |
} catch (err) { | |
console.error(err) | |
return { | |
error: err | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { QueryDocumentSnapshot } from "firebase-functions/lib/providers/firestore"; | |
export const listSubsEx = async function (elementY: QueryDocumentSnapshot, responses: any) { | |
try { | |
const inThisLevel={}; | |
// console.log("function e dhuksi") | |
const data = elementY.data(); | |
console.log(Object.keys(data)); | |
if (!('_queryOptions' in elementY.data())) { | |
console.log(elementY.data()); | |
responses[elementY.id]= elementY.data() | |
} else { | |
const collections = await elementY.ref.listCollections(); | |
for (let index = 0; index < collections.length; index++) { | |
const element = collections[index]; | |
let collectionsData = await element.get(); | |
await Promise.all(collectionsData.docs.map(async (elementX) => { | |
listSubsEx(elementX, inThisLevel); | |
})) | |
} | |
responses[elementY.id]= inThisLevel | |
/* collections.forEach(async (element) => { | |
}); */ | |
} | |
} catch (err) { | |
console.error(err) | |
} | |
} | |
/* module.exports={ | |
listSubsEx:listSubs | |
} */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment