import { inject , injectable } from 'inversify' ; import mirakurun from 'mirakurun' ; import * as apid from '../../../../api' ; import IChannelDB from '../../db/IChannelDB' ; import IMirakurunClientModel from '../../IMirakurunClientModel' ; import IChannelApiModel , { IChannelApiModelError } from './IChannelApiModel' ; @ injectable ( ) class ChannelApiModel implements IChannelApiModel { private channelDB : IChannelDB ; private mirakurunClient : mirakurun ; constructor ( @ inject ( 'IChannelDB' ) channelDB , @ inject ( 'IMirakurunClientModel' ) mirakurunClientModel ) { this . channelDB = channelDB ; this . mirakurunClient = mirakurunClientModel . getClient ( ) ; } return public async getChannels ( ) { const channels = await this . channelDB . findAll ( true ) ; return channels . map ( c => { const result = { id : c . id , serviceId : c . serviceId , networkId : c . networkId , name : c . name , halfWidthName : c . halfWidthName , hasLogoData : c . hasLogoData , channelType : < any > c . channelType , channel : c . channel , } ; if ( c . remoteControlKeyId !== null ) { result . remoteControlKeyId = c . remoteControlKeyId ; } return result ; } ) ; } param channelId return public async getLogo ( channelId ) { const channel = await this . channelDB . findId ( channelId ) ; if ( channel === null || channel . hasLogoData === false ) { throw new Error ( IChannelApiModelError . NOT_FOUND ) ; } return this . mirakurunClient . getLogoImage ( channelId ) ; } } export default ChannelApiModel ;