feat(sync): synchronize customer adresses and orders from Hiboutik sales (#1)

This commit is contained in:
2026-11-07 09:56:53 +00:00
parent 358e99c1ba
commit c91a510c56
16 changed files with 755 additions and 17 deletions

View File

@@ -1,6 +1,10 @@
import { Injectable } from '@nestjs/common';
import { HiboutikClient } from './hiboutik.client';
import { CustomerHiboutikDto, FullCustomerHiboutikDto } from '../models/hiboutikDTO/customer.hiboutik.dto';
import {
CustomerAddressDetailsHiboutikDto,
CustomerHiboutikDto,
FullCustomerHiboutikDto,
} from '../models/hiboutikDTO/customer.hiboutik.dto';
/** Reads customers from the Hiboutik API. */
@Injectable()
@@ -22,4 +26,15 @@ export class CustomerHiboutikRepository {
if (!customer) throw new Error(`Hiboutik customer ${id} not found`);
return customer;
}
/**
* Address with its company details (Hiboutik answers with a one-element array).
* @throws if the address does not exist.
*/
async getAddressById(id: number): Promise<CustomerAddressDetailsHiboutikDto> {
const data = await this.hiboutikClient.get<CustomerAddressDetailsHiboutikDto[]>('/customers_addresses/' + String(id));
const address = data[0];
if (!address) throw new Error(`Hiboutik address ${id} not found`);
return address;
}
}

View File

@@ -0,0 +1,20 @@
import { Injectable } from '@nestjs/common';
import { HiboutikClient } from './hiboutik.client';
import { SaleHiboutikDto } from '../models/hiboutikDTO/sale.hiboutik.dto';
/** Reads sales from the Hiboutik API. */
@Injectable()
export class SaleHiboutikRepository {
constructor(private readonly hiboutikClient: HiboutikClient) {}
/**
* Full sale, with its lines (Hiboutik answers with a one-element array).
* @throws if the sale does not exist.
*/
async getSaleById(id: number): Promise<SaleHiboutikDto> {
const data = await this.hiboutikClient.get<SaleHiboutikDto[]>('/sales/' + String(id));
const sale = data[0];
if (!sale) throw new Error(`Hiboutik sale ${id} not found`);
return sale;
}
}