feat(sync): synchronize customer addresses
Mirror the addresses embedded in GET /customer/🆔 per customer, delete the ones missing from Hiboutik, then upsert each of them (failures logged and skipped). CustomerAddress gains its own recipient (firstName, lastName, company, phone) plus state and other. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
32
src/models/converter/customerAddress.converter.ts
Normal file
32
src/models/converter/customerAddress.converter.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Converter } from './converter';
|
||||
import { CustomerAddressCreateInput } from '../../../prisma/generated/models/CustomerAddress';
|
||||
import { CustomerAddressHiboutikDto } from '../hiboutikDTO/customer.hiboutik.dto';
|
||||
|
||||
/** Trimmed value, `null` when empty so that a value removed in Hiboutik is also removed in database. */
|
||||
const optional = (value: string | null | undefined): string | null => value?.trim() || null;
|
||||
const required = (value: string | null | undefined): string => value?.trim() ?? '';
|
||||
|
||||
@Injectable()
|
||||
export class CustomerAddressConverter extends Converter<CustomerAddressCreateInput, CustomerAddressHiboutikDto> {
|
||||
fromHiboutik(dto: CustomerAddressHiboutikDto): CustomerAddressCreateInput {
|
||||
return {
|
||||
address: required(dto.address),
|
||||
city: required(dto.city),
|
||||
company: optional(dto.company),
|
||||
country: required(dto.country),
|
||||
firstName: required(dto.first_name),
|
||||
hiboutikId: Number(dto.address_id),
|
||||
isDefault: Number(dto.default) === 1,
|
||||
lastName: required(dto.last_name),
|
||||
other: optional(dto.other),
|
||||
phone: optional(dto.phone),
|
||||
state: optional(dto.state),
|
||||
zipCode: required(dto.zip_code),
|
||||
customer: { connect: { hiboutikId: Number(dto.customers_id) } },
|
||||
};
|
||||
}
|
||||
toHiboutik(): CustomerAddressHiboutikDto {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user