Skip to content

Commit ce22068

Browse files
committed
feat(customer): add CustomerMapper use in repository
1 parent c191ad3 commit ce22068

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

backend/src/infrastructure/repositories/knex/maintenance/KnexCustomerRepository.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Customer } from "../../../../domain/maintenance/entities/Customer";
33
import { CustomerAddress } from "../../../../domain/maintenance/value-object/CustomerAddress";
44
import { VehicleImmatriculation } from "../../../../domain/shared/value-object/VehicleImmatriculation";
55
import { Result, VoidResult } from "../../../../shared/Result";
6+
import { CustomerMapper } from "../../../entityMappers/CustomerMapper";
67
import { AbstractKnexRepository } from "../AbstractKnexRepository";
78

89
export 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

Comments
 (0)