feat(sync): synchronize Hiboutik data through POST /sync

This commit is contained in:
MastersGame
2026-11-05 23:00:49 +01:00
parent 60cd4cc1d6
commit 358e99c1ba
17 changed files with 878 additions and 34 deletions

24
src/utils/sync.ts Normal file
View File

@@ -0,0 +1,24 @@
import { Logger } from '@nestjs/common';
/**
* Runs `action` on each item, one at a time: a failing item is logged and skipped, the others are still processed.
* @param describe label of an item in the error log, e.g. "Hiboutik brand 12".
* @returns the number of failed items.
*/
export async function forEachSafely<T>(
items: T[],
action: (item: T) => Promise<unknown>,
logger: Logger,
describe: (item: T) => string,
): Promise<number> {
let nbFailed = 0;
for (const item of items) {
try {
await action(item);
} catch (error) {
nbFailed++;
logger.error(`Failed to sync ${describe(item)}`, (error as Error)?.stack);
}
}
return nbFailed;
}