feat(sync): harden the Hiboutik sync, share rate limits across instances, update dependencies (#4)
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user