update category
This commit is contained in:
@@ -72,6 +72,9 @@ func (r *CategoryRepositoryImpl) List(ctx context.Context, filters map[string]in
|
||||
case "search":
|
||||
searchValue := "%" + value.(string) + "%"
|
||||
query = query.Where("name ILIKE ? OR description ILIKE ?", searchValue, searchValue)
|
||||
case "outlet_id":
|
||||
// Include outlet-specific categories AND global categories (outlet_id IS NULL)
|
||||
query = query.Where("outlet_id = ? OR outlet_id IS NULL", value)
|
||||
default:
|
||||
query = query.Where(key+" = ?", value)
|
||||
}
|
||||
|
||||
@@ -178,6 +178,26 @@ func (r *ProductRepositoryImpl) ExistsByName(ctx context.Context, organizationID
|
||||
return count > 0, err
|
||||
}
|
||||
|
||||
// ExistsByNameInOutlet checks name uniqueness scoped to a specific outlet via product_outlet_prices.
|
||||
// Falls back to organization-scoped check when outletID is zero.
|
||||
func (r *ProductRepositoryImpl) ExistsByNameInOutlet(ctx context.Context, organizationID uuid.UUID, outletID uuid.UUID, name string, excludeID *uuid.UUID) (bool, error) {
|
||||
if outletID == uuid.Nil {
|
||||
return r.ExistsByName(ctx, organizationID, name, excludeID)
|
||||
}
|
||||
|
||||
query := r.db.WithContext(ctx).Model(&entities.Product{}).
|
||||
Joins("INNER JOIN product_outlet_prices pop ON pop.product_id = products.id AND pop.outlet_id = ?", outletID).
|
||||
Where("products.organization_id = ? AND products.name = ?", organizationID, name)
|
||||
|
||||
if excludeID != nil {
|
||||
query = query.Where("products.id != ?", *excludeID)
|
||||
}
|
||||
|
||||
var count int64
|
||||
err := query.Count(&count).Error
|
||||
return count > 0, err
|
||||
}
|
||||
|
||||
func (r *ProductRepositoryImpl) UpdateActiveStatus(ctx context.Context, id uuid.UUID, isActive bool) error {
|
||||
return r.db.WithContext(ctx).Model(&entities.Product{}).
|
||||
Where("id = ?", id).
|
||||
|
||||
Reference in New Issue
Block a user