import { firestore , Change , CloudFunction , EventContext } from 'firebase-functions' ; import { Logger } from '../client/logger' ; import { RepositoryModel } from '../models/index.model' ; import { DocumentData , DocumentSnapshot } from './../client/firebase-admin' ; export const onUpdateRepository = firestore . document ( 'repositories/{repositoryUid}' ) . onUpdate ( async ( change , context ) => { try { const newData = change . after . data ( ) ; if ( ! newData . projects || Array . isArray ( newData . projects ) && newData . projects . length === 0 ) { Logger . info ( `Delete repository ${ context . params . repositoryUid }` ) ; return RepositoryModel . getRepositoryReference ( context . params . repositoryUid ) . delete ( ) ; } return newData ; } catch ( err ) { Logger . error ( err ) ; throw new Error ( err ) ; } } ) ;