import { inject , injectable } from 'inversify' ; import * as apid from '../../../../api' ; import IRecordedTagDB from '../../db/IRecordedTagDB' ; import IIPCClient from '../../ipc/IIPCClient' ; import IRecordedTagApiModel from './IRecordedTagApiModel' ; @ injectable ( ) export default class RecordedTagApiModel implements IRecordedTagApiModel { private ipc : IIPCClient ; private recordedTagDB : IRecordedTagDB ; constructor ( @ inject ( 'IIPCClient' ) ipc , @ inject ( 'IRecordedTagDB' ) recordedTagDB ) { this . ipc = ipc ; this . recordedTagDB = recordedTagDB ; } param name param color return public async create ( name , color ) { const tagId = await this . ipc . recordedTag . create ( name , color ) ; return tagId ; } param tagId param name param color return public async update ( tagId , name , color ) { await this . ipc . recordedTag . update ( tagId , name , color ) ; } param tagId param recordedId return public async setRelation ( tagId , recordedId ) { await this . ipc . recordedTag . setRelation ( tagId , recordedId ) ; } param tagId return public async delete ( tagId ) { await this . ipc . recordedTag . delete ( tagId ) ; } param tagId param recordedId return public async deleteRelation ( tagId , recordedId ) { await this . ipc . recordedTag . deleteRelation ( tagId , recordedId ) ; } return public async gets ( option ) { const [ tags , total ] = await this . recordedTagDB . findAll ( option ) ; return { tags : tags . map ( t => { return { id : t . id , name : t . name , color : t . color , } ; } ) , total : total , } ; } }