import { HasOneInterface, BaseRequestModelInterface } from '../interfaces'; import { Id, Methods } from '../../types'; import { combineUrl } from '../../helpers'; type BelongsToOptions

= { parent: BaseRequestModelInterface

; targetPath: string; }; export class HasOneModel implements HasOneInterface { parent: BaseRequestModelInterface

; targetPath: string; constructor(options: BelongsToOptions

) { this.parent = options.parent; this.targetPath = options.targetPath; this.get = this.get.bind(this); this.post = this.post.bind(this); } async get(parentId: Id): Promise { return this.parent.request({ url: combineUrl(this.parent.basePath, `${parentId}`, this.targetPath), method: Methods.GET, }); } async post(parentId: Id, item: T): Promise { return this.parent.request({ url: combineUrl(this.parent.basePath, `${parentId}`, this.targetPath), method: Methods.POST, data: item, }); } }