import * as events from 'events' ; import { inject , injectable } from 'inversify' ; import * as apid from '../../../api' ; import RecordedTag from '../../db/entities/RecordedTag' ; import ILogger from '../ILogger' ; import ILoggerModel from '../ILoggerModel' ; import IRecordedTagEvent from './IRecordedTagEvent' ; @ injectable ( ) class RecordedTagEvent implements IRecordedTagEvent { private log : ILogger ; private emitter : events . EventEmitter = new events . EventEmitter ( ) ; constructor ( @ inject ( 'ILoggerModel' ) logger ) { this . log = logger . getLogger ( ) ; } param tag public emitCreated ( tag ) { this . emitter . emit ( RecordedTagEvent . CREATED_EVENT , tag ) ; } param tagId public emitUpdated ( tagId ) { this . emitter . emit ( RecordedTagEvent . UPDATED_EVENT , tagId ) ; } param tagId param recordedId public emitRelated ( tagId , recordedId ) { this . emitter . emit ( RecordedTagEvent . RELATER_EVENT , tagId , recordedId ) ; } param tagId public emitDeleted ( tagId ) { this . emitter . emit ( RecordedTagEvent . DELETED_EVENT , tagId ) ; } param tagId param recordedId public emitDeletedRelation ( tagId , recordedId ) { this . emitter . emit ( RecordedTagEvent . DELETED_RELATION_EVENT , tagId , recordedId ) ; } param callback public setCreated ( callback ) { this . emitter . on ( RecordedTagEvent . CREATED_EVENT , async ( tag ) => { try { await callback ( tag ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setUpdated ( callback ) { this . emitter . on ( RecordedTagEvent . UPDATED_EVENT , async ( tagId ) => { try { await callback ( tagId ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setRelated ( callback ) { this . emitter . on ( RecordedTagEvent . RELATER_EVENT , async ( tagId , recordedId ) => { try { await callback ( tagId , recordedId ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setDeleted ( callback ) { this . emitter . on ( RecordedTagEvent . DELETED_EVENT , async ( tagId ) => { try { await callback ( tagId ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setDeletedRelation ( callback ) { this . emitter . on ( RecordedTagEvent . DELETED_RELATION_EVENT , async ( tagId , recordedId ) => { try { await callback ( tagId , recordedId ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } } namespace RecordedTagEvent { export const CREATED_EVENT = 'Created' ; export const UPDATED_EVENT = 'Updated' ; export const RELATER_EVENT = 'Related' ; export const DELETED_EVENT = 'Deleted' ; export const DELETED_RELATION_EVENT = 'DeletedRelation' ; } export default RecordedTagEvent ;