import { firestore } from 'firebase-admin' ; import { GitHubEventModel , GitHubEventType } from '../event.mapper' ; import { GitHubPayloadInput , GitHubPayloadMapper } from '../payload.mapper' ; import { GitHubRepositoryMapper } from '../repository.mapper' ; import { GitHubUserMapper } from '../user.mapper' ; import { isExistProperties , HubEventActions , Repository , User } from './shared' ; export interface WatchEventInput { action : 'started' ; repository : Repository ; sender : User ; } export class WatchEventModel implements WatchEventInput , HubEventActions { action : 'started' ; repository : Repository ; sender : User ; constructor ( input ) { Object . assign ( this , input ) ; } public static isCurrentModel ( input ) { const requireKeys = [ 'action' , 'repository' , 'sender' ] ; return Object . keys ( input ) . length === requireKeys . length && isExistProperties ( input , requireKeys ) && input . action === 'started' ; } convertToHubEvent ( ) { const eventType = 'WatchEvent' ; const payload = { action : this . action , } ; const data = { type : eventType , public : true , actor : GitHubUserMapper . import ( this . sender ) , repository : GitHubRepositoryMapper . import ( this . repository , 'event' ) , payload : GitHubPayloadMapper . import ( eventType , payload ) , createdOn : firestore . Timestamp . now ( ) , } ; return data ; } }