import { injectable } from "inversify"; import BaseService from "../../service"; import { IService, IResourceMapper, IFindParams } from "../../interfaces"; import TagAssociation, { ITagAssociation, ITagAssociationResource, ITagAssociationResponse } from "./"; import Mapper from "./mapper"; export interface ITagAssociationService extends IService {} @injectable() export default class TagAssociationService extends BaseService implements ITagAssociationService { resource: string = "tag-association"; mapper: IResourceMapper = new Mapper(); public url() { return `${this.host}/tags/associations`; } public async findById(id: string, options: IFindParams = {}) { const response = await this.http.fetch( `${this.url()}/${id}${this.serializeQuery(options)}`, { headers: { ...this.headers(), "Accept-Version": "v2" }, }); return this.mapper.map(response); } public async find(options: IFindParams = {}) { const response = await this.http.fetch( `${this.url()}${this.serializeQuery(options)}`, { headers: { ...this.headers(), "Accept-Version": "v2" }, }); return this.mapper.map(response); } private serializeQuery(options: IFindParams): string { return this.qs({ ...options, resource: "tag_association" // filters require underscored resource type }); } }