mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 88bdf70994 |
+3
-13
@@ -86,24 +86,14 @@ func (r *ProductWarehouseRepositoryImpl) ProductWarehouseExistByProductAndWareho
|
|||||||
func (r *ProductWarehouseRepositoryImpl) GetProductWarehouseByProductAndWarehouseID(ctx context.Context, productId, warehouseId uint) (*entity.ProductWarehouse, error) {
|
func (r *ProductWarehouseRepositoryImpl) GetProductWarehouseByProductAndWarehouseID(ctx context.Context, productId, warehouseId uint) (*entity.ProductWarehouse, error) {
|
||||||
var productWarehouse entity.ProductWarehouse
|
var productWarehouse entity.ProductWarehouse
|
||||||
|
|
||||||
|
// Cari product warehouse dengan project_flock_kandang yang masih aktif (belum closed)
|
||||||
err := r.DB().WithContext(ctx).
|
err := r.DB().WithContext(ctx).
|
||||||
Where("product_id = ? AND warehouse_id = ? AND project_flock_kandang_id IS NOT NULL", productId, warehouseId).
|
Joins("LEFT JOIN project_flock_kandangs ON project_flock_kandangs.id = product_warehouses.project_flock_kandang_id").
|
||||||
|
Where("product_id = ? AND warehouse_id = ? AND (project_flock_kandang_id IS NULL OR project_flock_kandangs.closed_at IS NULL)", productId, warehouseId).
|
||||||
Order("id DESC").
|
Order("id DESC").
|
||||||
Preload("ProjectFlockKandang").
|
Preload("ProjectFlockKandang").
|
||||||
First(&productWarehouse).Error
|
First(&productWarehouse).Error
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
|
|
||||||
if productWarehouse.ProjectFlockKandang.ClosedAt == nil {
|
|
||||||
return &productWarehouse, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
err = r.DB().WithContext(ctx).
|
|
||||||
Where("product_id = ? AND warehouse_id = ? AND project_flock_kandang_id IS NULL", productId, warehouseId).
|
|
||||||
First(&productWarehouse).Error
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user