20 lines
674 B
TypeScript
20 lines
674 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { HiboutikClient } from './hiboutik.client';
|
|
import { SaleHiboutikDto, saleHiboutikSchema } from '../models/hiboutikDTO/sale.hiboutik.dto';
|
|
|
|
/** Reads sales from the Hiboutik API. */
|
|
@Injectable()
|
|
export class SaleHiboutikRepository {
|
|
constructor(private readonly hiboutikClient: HiboutikClient) {}
|
|
|
|
/**
|
|
* Full sale, with its lines.
|
|
* @throws if the sale does not exist.
|
|
*/
|
|
async getSaleById(id: number): Promise<SaleHiboutikDto> {
|
|
const sale = await this.hiboutikClient.getOne(`/sales/${id}`, saleHiboutikSchema);
|
|
if (!sale) throw new Error(`Hiboutik sale ${id} not found`);
|
|
return sale;
|
|
}
|
|
}
|