fix[BE]Reset chickin pending usage and skip zero entries

This commit is contained in:
aguhh18
2025-12-31 11:34:57 +07:00
parent 610555c3cf
commit 42853aaac0
2 changed files with 13 additions and 0 deletions
@@ -572,6 +572,7 @@ func (s *chickinService) convertChickinsToTarget(ctx *fiber.Ctx, chickins []enti
}
ProjectFlockPopulationRepotx := s.ProjectflockPopulationRepo.WithTx(dbTransaction)
chickinRepoTx := s.Repository.WithTx(dbTransaction)
var totalQuantityAdded float64
@@ -601,6 +602,13 @@ func (s *chickinService) convertChickinsToTarget(ctx *fiber.Ctx, chickins []enti
return err
}
// Reset PendingUsageQty to 0 since population has been created
if err := chickinRepoTx.PatchOne(ctx.Context(), chickin.Id, map[string]any{
"pending_usage_qty": 0,
}, nil); err != nil {
return fmt.Errorf("failed to reset pending usage qty for chickin %d: %w", chickin.Id, err)
}
totalQuantityAdded += quantityToConvert
}
@@ -204,6 +204,11 @@ func toAvailableQtyDTOsFromMap(chickins []entity.ProjectChickin, availableQtyMap
result := make([]AvailableQtyDTO, 0, len(availableQtyMap))
for pwId, availableQty := range availableQtyMap {
// Skip jika available qty = 0
if availableQty <= 0 {
continue
}
pw, exists := pwMap[pwId]
if !exists || pw == nil {
continue