Skip to content

Commit

Permalink
Firebase & AngularFire In Depth
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Jun 18, 2021
1 parent 85914b7 commit 87e68ee
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
16 changes: 16 additions & 0 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import * as functions from "firebase-functions";

import {db} from "./init";

import {firestore} from 'firebase-admin/lib/firestore';
import FieldValue = firestore.FieldValue;



//
// Start writing Firebase Functions
// https://firebase.google.com/docs/functions/typescript
Expand All @@ -18,5 +25,14 @@ export const onAddCourseUpdatePromoCounter =
functions.logger.debug(
`Running add course trigger for courseId ${context.params.courseId}`);

const course = snap.data();

if (course.promo) {

return db.doc("courses/stats").update({
totalPromo: FieldValue.increment(1)
})

}
});

13 changes: 13 additions & 0 deletions functions/src/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


const admin = require('firebase-admin');


admin.initializeApp();

export const db = admin.firestore();

export const auth = admin.auth();



3 changes: 2 additions & 1 deletion functions/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017"
"target": "es2017",
"noImplicitAny": false
},
"compileOnSave": true,
"include": [
Expand Down

0 comments on commit 87e68ee

Please sign in to comment.