feat(sync): harden the Hiboutik sync, share rate limits across instances, update dependencies (#4)

This commit is contained in:
2026-11-08 13:45:08 +00:00
parent 04960379e8
commit d07c4df52d
62 changed files with 1546 additions and 639 deletions

View File

@@ -9,12 +9,19 @@ import { OrderStatus } from '../models/orderStatus';
export class OrderDatabaseRepository {
constructor(private readonly prisma: PrismaService) {}
/** Among `hiboutikSaleIds`, the ones already stored as completed orders. */
async getCompletedSaleIds(hiboutikSaleIds: number[]): Promise<Set<number>> {
/**
* Among `hiboutikSaleIds`, the ones already stored as completed orders of this customer. A completed order that lost
* its customer (customer deleted, then found again in Hiboutik) is not returned, so that the sync links it back.
*/
async getCompletedSaleIds(customerHiboutikId: number, hiboutikSaleIds: number[]): Promise<Set<number>> {
if (hiboutikSaleIds.length === 0) return new Set();
const orders = await this.prisma.order.findMany({
where: { hiboutikSaleId: { in: hiboutikSaleIds }, status: OrderStatus.COMPLETED },
where: {
hiboutikSaleId: { in: hiboutikSaleIds },
status: OrderStatus.COMPLETED,
customer: { is: { hiboutikId: customerHiboutikId } },
},
select: { hiboutikSaleId: true },
});
return new Set(orders.map((order) => order.hiboutikSaleId).filter((id): id is number => id !== null));