@@ -3,6 +3,7 @@ import { Customer } from "../../../../domain/maintenance/entities/Customer";
33import { CustomerAddress } from "../../../../domain/maintenance/value-object/CustomerAddress" ;
44import { VehicleImmatriculation } from "../../../../domain/shared/value-object/VehicleImmatriculation" ;
55import { Result , VoidResult } from "../../../../shared/Result" ;
6+ import { CustomerMapper } from "../../../entityMappers/CustomerMapper" ;
67import { AbstractKnexRepository } from "../AbstractKnexRepository" ;
78
89export class KnexCustomerRepository extends AbstractKnexRepository implements CustomerRepository {
@@ -31,11 +32,11 @@ export class KnexCustomerRepository extends AbstractKnexRepository implements Cu
3132 customerRow . name ,
3233 customerRow . email ,
3334 customerRow . phone ,
34- customerRow . address ,
3535 vehiculeImmatriculation ,
36+ customerRow . address ,
3637 ) ;
3738
38- return Result . Success < Customer > ( customer ) ;
39+ return Result . Success < Customer > ( CustomerMapper . toDomain ( customer ) ) ;
3940 } catch ( e ) {
4041 console . error ( e ) ;
4142 return Result . FailureStr ( "An error occurred while getting customer" ) ;
@@ -46,20 +47,9 @@ export class KnexCustomerRepository extends AbstractKnexRepository implements Cu
4647 const transaction = await this . connection . transaction ( ) ;
4748
4849 try {
49- const addressId = await transaction ( this . tableName ) . insert ( {
50- street : customer . address . street ,
51- city : customer . address . city ,
52- postalCode : customer . address . postalCode ,
53- country : customer . address . country ,
54- } ) . into ( this . addressesTableName ) ;
55-
56- await transaction . insert ( {
57- name : customer . name ,
58- email : customer . email ,
59- phone : customer . phoneNumber ,
60- address_id : addressId ,
61- } ) . into ( this . tableName ) ;
62-
50+ await transaction . insert (
51+ CustomerMapper . toPersistence ( customer )
52+ ) . into ( this . tableName ) ;
6353 await transaction . insert ( {
6454 immatriculation : customer . vehiculeImmatrictulation ,
6555 customer_id : customer . id ,
0 commit comments