feat(hiboutik): add Hiboutik API client, repositories and DTOs
HiboutikClient handles Basic auth and walks paginated endpoints. One read-only repository per entity (brands, categories, suppliers, products, stocks, customers).
This commit is contained in:
25
src/hiboutik/customer.hiboutik.repository.ts
Normal file
25
src/hiboutik/customer.hiboutik.repository.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { HiboutikClient } from './hiboutik.client';
|
||||
import { CustomerHiboutikDto, FullCustomerHiboutikDto } from '../models/hiboutikDTO/customer.hiboutik.dto';
|
||||
|
||||
/** Reads customers from the Hiboutik API. */
|
||||
@Injectable()
|
||||
export class CustomerHiboutikRepository {
|
||||
constructor(private readonly hiboutikClient: HiboutikClient) {}
|
||||
|
||||
/** Customer summaries only: use {@link getCustomerById} for addresses and sales. */
|
||||
async getCustomers(): Promise<CustomerHiboutikDto[]> {
|
||||
return this.hiboutikClient.getAllPages<CustomerHiboutikDto>('/customers');
|
||||
}
|
||||
|
||||
/**
|
||||
* Full customer, with its addresses and sales (Hiboutik answers with a one-element array).
|
||||
* @throws if the customer does not exist.
|
||||
*/
|
||||
async getCustomerById(id: number): Promise<FullCustomerHiboutikDto> {
|
||||
const data = await this.hiboutikClient.get<FullCustomerHiboutikDto[]>('/customer/' + String(id));
|
||||
const customer = data[0];
|
||||
if (!customer) throw new Error(`Hiboutik customer ${id} not found`);
|
||||
return customer;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user