Make vendor nullable

This commit is contained in:
2026-06-18 11:04:59 +07:00
parent 2ad9e2f85f
commit c1d859ebdd
13 changed files with 88 additions and 39 deletions
@@ -55,10 +55,12 @@ func NewPurchaseOrderProcessorImpl(
}
func (p *PurchaseOrderProcessorImpl) CreatePurchaseOrder(ctx context.Context, organizationID uuid.UUID, req *models.CreatePurchaseOrderRequest) (*models.PurchaseOrderResponse, error) {
// Check if vendor exists and belongs to organization
_, err := p.vendorRepo.GetByIDAndOrganizationID(ctx, req.VendorID, organizationID)
if err != nil {
return nil, fmt.Errorf("vendor not found: %w", err)
// Check if vendor exists and belongs to organization when provided.
if req.VendorID != nil {
_, err := p.vendorRepo.GetByIDAndOrganizationID(ctx, *req.VendorID, organizationID)
if err != nil {
return nil, fmt.Errorf("vendor not found: %w", err)
}
}
// Check if PO number already exists in organization
@@ -186,7 +188,7 @@ func (p *PurchaseOrderProcessorImpl) UpdatePurchaseOrder(ctx context.Context, id
if err != nil {
return nil, fmt.Errorf("vendor not found: %w", err)
}
poEntity.VendorID = *req.VendorID
poEntity.VendorID = req.VendorID
}
// Check if PO number already exists (if PO number is being updated)