/**
 * Relations handler
 */ import { ManyItems , OneItem , PartialItem } from '../items' ; import { ITransport } from '../transport' ; import { RelationType , DefaultType , ID } from '../types' ; export type RelationItem < T = DefaultType > = RelationType & T ; export class RelationsHandler < T = RelationItem > { transport : ITransport ; constructor ( transport ) { this . transport = transport ; } async readOne ( collection , id ) { const response = await this . transport . get ( `/relations/${ collection }/${ id }` ) ; return response . data as T ; } async readMany ( collection ) { const response = await this . transport . get ( `/relations/${ collection }` ) ; return response . data ; } async readAll ( ) { const response = await this . transport . get ( `/relations` ) ; return response . data ; } async createOne ( item ) { return ( await this . transport . post < T > ( `/relations` , item ) ) . data ; } async updateOne ( collection , field , item ) { return ( await this . transport . patch < PartialItem < T > > ( `/relations/${ collection }/${ field }` , { params : item , } ) ) . data ; } async deleteOne ( collection , field ) { await this . transport . delete ( `/relations/${ collection }/${ field }` ) ; } }