update category
This commit is contained in:
@@ -39,6 +39,7 @@ type ProductRepository interface {
|
||||
ExistsBySKU(ctx context.Context, organizationID uuid.UUID, sku string, excludeID *uuid.UUID) (bool, error)
|
||||
GetByName(ctx context.Context, organizationID uuid.UUID, name string) (*entities.Product, error)
|
||||
ExistsByName(ctx context.Context, organizationID uuid.UUID, name string, excludeID *uuid.UUID) (bool, error)
|
||||
ExistsByNameInOutlet(ctx context.Context, organizationID uuid.UUID, outletID uuid.UUID, name string, excludeID *uuid.UUID) (bool, error)
|
||||
UpdateActiveStatus(ctx context.Context, id uuid.UUID, isActive bool) error
|
||||
GetLowCostProducts(ctx context.Context, organizationID uuid.UUID, maxCost float64) ([]*entities.Product, error)
|
||||
}
|
||||
@@ -79,12 +80,12 @@ func (p *ProductProcessorImpl) CreateProduct(ctx context.Context, req *models.Cr
|
||||
}
|
||||
}
|
||||
|
||||
exists, err := p.productRepo.ExistsByName(ctx, req.OrganizationID, req.Name, nil)
|
||||
exists, err := p.productRepo.ExistsByNameInOutlet(ctx, req.OrganizationID, req.OutletID, req.Name, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to check product name uniqueness: %w", err)
|
||||
}
|
||||
if exists {
|
||||
return nil, fmt.Errorf("product with name '%s' already exists for this organization", req.Name)
|
||||
return nil, fmt.Errorf("product with name '%s' already exists for this outlet", req.Name)
|
||||
}
|
||||
|
||||
productEntity := mappers.CreateProductRequestToEntity(req)
|
||||
@@ -173,12 +174,12 @@ func (p *ProductProcessorImpl) UpdateProduct(ctx context.Context, id uuid.UUID,
|
||||
}
|
||||
|
||||
if req.Name != nil && *req.Name != existingProduct.Name {
|
||||
exists, err := p.productRepo.ExistsByName(ctx, existingProduct.OrganizationID, *req.Name, &id)
|
||||
exists, err := p.productRepo.ExistsByNameInOutlet(ctx, existingProduct.OrganizationID, req.OutletID, *req.Name, &id)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to check product name uniqueness: %w", err)
|
||||
}
|
||||
if exists {
|
||||
return nil, fmt.Errorf("product with name '%s' already exists for this organization", *req.Name)
|
||||
return nil, fmt.Errorf("product with name '%s' already exists for this outlet", *req.Name)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user