Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.financialsConfig = functions
- // .runWith(runtimeOpts)
- .https.onCall((data) => {
- return db.collection('financials').get()
- .limit(25)
- .then((qs: QuerySnapshot) => {
- qs.forEach((fDoc: QueryDocumentSnapshot) => {
- // A way to filter out the unwanted properties and keep desired ones.
- // See https://codeburst.io/use-es2015-object-rest-operator-to-omit-properties-38a3ecffe90
- const {childFirstName, childLastName, fatherEmail, motherEmail, grade, ...keep} = fDoc.data();
- return db.collection('students').doc(fDoc.id).collection('financials').doc(fDoc.id).set(keep)
- .then(()=> {
- // Go to the top-level 'financials' collection and
- // get all the docs from each subcollection with each financial doc.
- // Cloud function for each collection.
- const collections = ['extendedCareCharges',
- 'extendedCarePayments',
- 'lunchCharges',
- 'lunchPayments',
- 'miscCharges',
- 'miscPayments',
- 'tuitionCharges',
- 'tuitionPayments'];
- collections.forEach(collection => {
- return db.collection('financials').doc(fDoc.id).collection(collection)
- .get()
- .then((qss: QuerySnapshot) => {
- console.log(`MD: qss`, qss);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement