SHARE
TWEET

Untitled

a guest Oct 21st, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. exports.financialsConfig = functions
  2. // .runWith(runtimeOpts)
  3. .https.onCall((data) => {
  4.     return db.collection('financials').get()
  5.     .limit(25)
  6.     .then((qs: QuerySnapshot) => {
  7.       qs.forEach((fDoc: QueryDocumentSnapshot) => {
  8.         // A way to filter out the unwanted properties and keep desired ones.
  9.         // See https://codeburst.io/use-es2015-object-rest-operator-to-omit-properties-38a3ecffe90
  10.         const {childFirstName, childLastName, fatherEmail, motherEmail, grade, ...keep} = fDoc.data();
  11.         return db.collection('students').doc(fDoc.id).collection('financials').doc(fDoc.id).set(keep)
  12.           .then(()=> {
  13.             // Go to the top-level 'financials' collection and
  14.             // get all the docs from each subcollection with each financial doc.
  15.  
  16.             // Cloud function for each collection.
  17.             const collections = ['extendedCareCharges',
  18.                                   'extendedCarePayments',
  19.                                   'lunchCharges',
  20.                                   'lunchPayments',
  21.                                   'miscCharges',
  22.                                   'miscPayments',
  23.                                   'tuitionCharges',
  24.                                   'tuitionPayments'];
  25.             collections.forEach(collection => {
  26.               return db.collection('financials').doc(fDoc.id).collection(collection)
  27.               .get()
  28.               .then((qss: QuerySnapshot) => {
  29.                   console.log(`MD: qss`, qss);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top