Fixed error with creation of document

This commit is contained in:
2026-05-25 12:19:05 +01:00
parent b59a8b6c3d
commit d46fa606b7
5 changed files with 9 additions and 7 deletions
@@ -23,6 +23,7 @@ public class CreatePurchaseOrder(
public override async Task HandleAsync(CreatePurchaseOrderDto req, CancellationToken ct) public override async Task HandleAsync(CreatePurchaseOrderDto req, CancellationToken ct)
{ {
PurchaseOrder purchaseOrder = mapper.Map<PurchaseOrder>(req); PurchaseOrder purchaseOrder = mapper.Map<PurchaseOrder>(req);
await purchaseOrdersRepository.AddAsync(purchaseOrder, ct);
if (req.Products != null) if (req.Products != null)
{ {
@@ -49,8 +50,6 @@ public class CreatePurchaseOrder(
await purchaseProductsRepository.AddAsync(productOnPurchase, ct); await purchaseProductsRepository.AddAsync(productOnPurchase, ct);
} }
} }
await purchaseOrdersRepository.AddAsync(purchaseOrder, ct);
await Send.NoContentAsync(ct); await Send.NoContentAsync(ct);
} }
} }
@@ -1,6 +1,5 @@
using FastEndpoints; using FastEndpoints;
using PyroFetes.DTO.Quotation.Request; using PyroFetes.DTO.Quotation.Request;
using PyroFetes.DTO.Quotation.Response;
using PyroFetes.DTO.QuotationProduct.Request; using PyroFetes.DTO.QuotationProduct.Request;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
@@ -25,6 +24,7 @@ public class CreateQuotationEndpoint(
{ {
Quotation quotation = mapper.Map<Quotation>(req); Quotation quotation = mapper.Map<Quotation>(req);
quotation.CustomerId = 1; // TODO: A changer quotation.CustomerId = 1; // TODO: A changer
await quotationsRepository.AddAsync(quotation, ct);
if (req.Products != null) if (req.Products != null)
{ {
@@ -43,6 +43,7 @@ public class CreateQuotationEndpoint(
if (quotationProduct is not null) if (quotationProduct is not null)
{ {
await Send.StringAsync("Le produit est déjà dans le devis", 400, cancellation: ct); await Send.StringAsync("Le produit est déjà dans le devis", 400, cancellation: ct);
return;
} }
QuotationProduct? productOnQuotation = mapper.Map<QuotationProduct>(line); QuotationProduct? productOnQuotation = mapper.Map<QuotationProduct>(line);
@@ -51,8 +52,7 @@ public class CreateQuotationEndpoint(
await quotationProductsRepository.AddAsync(productOnQuotation, ct); await quotationProductsRepository.AddAsync(productOnQuotation, ct);
} }
} }
await quotationsRepository.AddAsync(quotation, ct);
await Send.NoContentAsync(ct); await Send.NoContentAsync(ct);
} }
} }
@@ -1,6 +1,5 @@
using FastEndpoints; using FastEndpoints;
using PyroFetes.DTO.Quotation.Request; using PyroFetes.DTO.Quotation.Request;
using PyroFetes.DTO.Quotation.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.Quotations; using PyroFetes.Specifications.Quotations;
@@ -44,6 +44,7 @@ public class DtoToEntityMappings : Profile
.ForMember(dest => dest.Id, opt => opt.Ignore()); .ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap<CreatePurchaseProductDto, PurchaseProduct>(); CreateMap<CreatePurchaseProductDto, PurchaseProduct>();
CreateMap<CreatePurchaseOrderProductDto, PurchaseProduct>();
CreateMap<PatchPurchaseProductQuantityDto, PurchaseProduct>() CreateMap<PatchPurchaseProductQuantityDto, PurchaseProduct>()
.ForMember(dest => dest.ProductId, opt => opt.Ignore()) .ForMember(dest => dest.ProductId, opt => opt.Ignore())
.ForMember(dest => dest.PurchaseOrderId, opt => opt.Ignore()); .ForMember(dest => dest.PurchaseOrderId, opt => opt.Ignore());
@@ -52,7 +53,10 @@ public class DtoToEntityMappings : Profile
.ForMember(dest => dest.Id, opt => opt.Ignore()); .ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap<PatchQuotationMessageDto, Quotation>() CreateMap<PatchQuotationMessageDto, Quotation>()
.ForMember(dest => dest.Id, opt => opt.Ignore()); .ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap<CreateProductQuotationDto, Quotation>(); CreateMap<CreateQuotationDto, Quotation>();
CreateMap<CreateProductQuotationDto, QuotationProduct>();
CreateMap<UpdateQuotationDto, Quotation>()
.ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap<AddQuotationProductDto, QuotationProduct>(); CreateMap<AddQuotationProductDto, QuotationProduct>();
CreateMap<PatchQuotationProductQuantityDto, QuotationProduct>() CreateMap<PatchQuotationProductQuantityDto, QuotationProduct>()