[FIX/BE-US] feat adjustment location and area

This commit is contained in:
ragilap
2026-01-27 10:34:25 +07:00
parent 571f6b4bf3
commit 00cdfb692b
26 changed files with 753 additions and 600 deletions
@@ -54,7 +54,14 @@ func (s warehouseService) GetAll(c *fiber.Ctx, params *validation.Query) ([]enti
warehouses, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB {
db = s.withRelations(db)
db, scopeErr = m.ApplyAreaScope(c, db, "warehouses.area_id")
applyScope := true
if params.TransferContext == utils.TransferContextInventoryTransfer {
applyScope = !m.HasPermission(c, m.P_TransferCreateOne)
}
if applyScope {
db, scopeErr = m.ApplyLocationAreaScope(c, db, "warehouses.location_id", "warehouses.area_id")
}
if params.Search != "" {
db = db.Where("warehouses.name ILIKE ?", "%"+params.Search+"%")
}
@@ -81,6 +88,9 @@ func (s warehouseService) GetAll(c *fiber.Ctx, params *validation.Query) ([]enti
)
`, "Aktif")
}
if len(params.ExcludeIDs) > 0 {
db = db.Where("warehouses.id NOT IN ?", params.ExcludeIDs)
}
return db.Order("created_at DESC").Order("updated_at DESC")
})
@@ -99,7 +109,7 @@ func (s warehouseService) GetOne(c *fiber.Ctx, id uint) (*entity.Warehouse, erro
warehouse, err := s.Repository.GetByID(c.Context(), id, func(db *gorm.DB) *gorm.DB {
db = s.withRelations(db)
db, scopeErr = m.ApplyAreaScope(c, db, "warehouses.area_id")
db, scopeErr = m.ApplyLocationAreaScope(c, db, "warehouses.location_id", "warehouses.area_id")
return db
})
if scopeErr != nil {