import { inject, injectable } from "inversify"; import Mapper from "../../mapper"; import * as TYPES from "../../types"; import BookmarkPopularity, { bookmarkPopularityType, IBookmarkPopularity, IBookmarkPopularityResource } from "../bookmarkPopularity"; import {IJsonApiRelationshipResource} from "../../interfaces"; @injectable() export class BookmarkPopularityMapper extends Mapper { @inject(TYPES.BookmarkPopularity) model: IBookmarkPopularity; toModel(resource: IBookmarkPopularityResource): IBookmarkPopularity { const model = new BookmarkPopularity(); model.id = resource.id; model.count = resource.attributes.bookmark_count; model.target = resource.relationships.target.data; return model; } toResource(model: IBookmarkPopularity): IBookmarkPopularityResource { const resource: IBookmarkPopularityResource = { id: model.id, type: bookmarkPopularityType, attributes: { bookmark_count: model.count, }, relationships: {} }; if (model.target) { resource.relationships.target = { data: { type: model.target.type, id: model.target.id, } }; } return resource; } } export default BookmarkPopularityMapper;