import { firestore , CloudFunction , EventContext } from 'firebase-functions' ; import { DocumentSnapshot , FirebaseAdmin , IncrementFieldValue } from '../client/firebase-admin' ; import { Logger } from '../client/logger' ; export const onCreateProject = firestore . document ( 'projects/{projectUid}' ) . onCreate ( async ( snapshot , context ) => { try { await FirebaseAdmin . firestore ( ) . collection ( 'platform' ) . doc ( 'stats' ) . set ( { projects : IncrementFieldValue , } , { merge : true } ) ; } catch ( err ) { Logger . error ( err ) ; throw new Error ( err ) ; } } ) ; export const onCreateUser = firestore . document ( 'users/{userUid}' ) . onCreate ( async ( snapshot , context ) => { try { await FirebaseAdmin . firestore ( ) . collection ( 'platform' ) . doc ( 'stats' ) . set ( { users : IncrementFieldValue , } , { merge : true } ) ; } catch ( err ) { Logger . error ( err ) ; throw new Error ( err ) ; } } ) ; export const onCreatePings = firestore . document ( 'projects/{projectUid}/pings/{pingUid}' ) . onCreate ( async ( snapshot , context ) => { try { await FirebaseAdmin . firestore ( ) . collection ( 'platform' ) . doc ( 'stats' ) . set ( { pings : IncrementFieldValue , } , { merge : true } ) ; } catch ( err ) { Logger . error ( err ) ; throw new Error ( err ) ; } } ) ; export const onCreateEvent = async ( ) : Promise < any > => { try { await FirebaseAdmin . firestore ( ) . collection ( 'platform' ) . doc ( 'stats' ) . set ( { events : IncrementFieldValue , } , { merge : true } ) ; } catch ( err ) { Logger . error ( err ) ; throw new Error ( err ) ; } } ;