feat(sync): synchronize customer adresses and orders from Hiboutik sales (#1)
Co-authored-by: MastersGame <quentin.duwa1210@gmail.com> Reviewed-on: #1
This commit is contained in:
20
src/hiboutik/sale.hiboutik.repository.ts
Normal file
20
src/hiboutik/sale.hiboutik.repository.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { HiboutikClient } from './hiboutik.client';
|
||||
import { SaleHiboutikDto } 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 (Hiboutik answers with a one-element array).
|
||||
* @throws if the sale does not exist.
|
||||
*/
|
||||
async getSaleById(id: number): Promise<SaleHiboutikDto> {
|
||||
const data = await this.hiboutikClient.get<SaleHiboutikDto[]>('/sales/' + String(id));
|
||||
const sale = data[0];
|
||||
if (!sale) throw new Error(`Hiboutik sale ${id} not found`);
|
||||
return sale;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user