import { injectable } from "inversify"; import BaseService from "../../service"; import { IService, IResourceMapper, IFindParams } from "../../interfaces"; import { IVideoSource, IVideoSourceResource, IVideoSourceResponse, videoSourceType } from "./"; import Mapper from "./mapper"; export interface IVideoSourceService extends IService { findByVideoId(videoId: string, options: IFindParams): Promise findBySourceId(videoId: string, sourceId: string, options: IFindParams): Promise } @injectable() export default class VideoSourceService extends BaseService implements IVideoSourceService { resource: string = videoSourceType; mapper: IResourceMapper = new Mapper(); public url(videoId) { return `${this.host}/videos/${videoId}/sources`; } public async findByVideoId(videoId: string, options: IFindParams = {}): Promise { const resources = await this.http.fetch( `${this.url(videoId)}/${this.qs(options)}`, { headers: this.headers(), } ); return this.mapper.map(resources); } public async findBySourceId(videoId: string, sourceId: string, options: IFindParams = {} ): Promise { const resources = await this.http.fetch( `${this.url(videoId)}/${sourceId}/${this.qs(options)}`, { headers: this.headers(), } ); return this.mapper.map(resources); } }