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:
20
src/hiboutik/stock.hiboutik.repository.ts
Normal file
20
src/hiboutik/stock.hiboutik.repository.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { HiboutikClient } from './hiboutik.client';
|
||||
import { StockHiboutikDto } from '../models/hiboutikDTO/stock.hiboutik.dto';
|
||||
|
||||
/** Reads available stocks from the Hiboutik API. */
|
||||
@Injectable()
|
||||
export class StockHiboutikRepository {
|
||||
constructor(private readonly hiboutikClient: HiboutikClient) {}
|
||||
|
||||
/** Stock of every product and size, all warehouses combined. Not paginated. */
|
||||
async getStocks(): Promise<StockHiboutikDto[]> {
|
||||
const stocks = await this.hiboutikClient.get<StockHiboutikDto[]>('/stock_available/all_wh', {});
|
||||
// Hiboutik may return ids as strings: normalize them so strict comparisons work downstream
|
||||
return stocks.map((stock) => ({
|
||||
...stock,
|
||||
product_id: Number(stock.product_id),
|
||||
product_size: Number(stock.product_size),
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user