Files
dinggadingga-backend/src/hiboutik/stock.hiboutik.repository.ts
MastersGame 30c56f9330 feat(sync): trust Hiboutik answers for deletions
A successful (2xx) answer from Hiboutik is now the truth, even an empty
list: records missing from it are deleted. The "empty list means API
issue" safety nets are removed.

Deletion stays safe because a failed call deletes nothing: HTTP errors
throw, and the new HiboutikClient.getList (used by getAllPages and the
non-paginated lists) also throws on a 2xx body that is not a list, so a
malformed answer is never mistaken for an empty list. A 2xx without body
is an empty list.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-08 10:11:34 +01:00

21 lines
839 B
TypeScript

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.getList<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),
}));
}
}