mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 21:41:55 +00:00
[FEAT/BE] recording reject add
This commit is contained in:
@@ -692,6 +692,13 @@ func (s recordingService) Approval(c *fiber.Ctx, req *validation.Approve) ([]ent
|
|||||||
); err != nil {
|
); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if action == entity.ApprovalActionRejected {
|
||||||
|
note := fmt.Sprintf("Recording-Reject#%d", id)
|
||||||
|
if err := s.rollbackRecordingInventory(ctx, tx, id, note, actorID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -729,43 +736,7 @@ func (s recordingService) DeleteOne(c *fiber.Ctx, id uint) error {
|
|||||||
note := fmt.Sprintf("Recording-Delete#%d", id)
|
note := fmt.Sprintf("Recording-Delete#%d", id)
|
||||||
|
|
||||||
return s.Repository.DB().WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
return s.Repository.DB().WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||||
oldDepletions, err := s.Repository.ListDepletions(tx, id)
|
if err := s.rollbackRecordingInventory(ctx, tx, id, note, actorID); err != nil {
|
||||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
s.Log.Errorf("Failed to list depletions before delete: %+v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if s.FifoSvc != nil {
|
|
||||||
if err := s.releaseRecordingDepletions(ctx, tx, oldDepletions, note, actorID); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
oldEggs, err := s.Repository.ListEggs(tx, id)
|
|
||||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
s.Log.Errorf("Failed to list eggs before delete: %+v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if s.FifoSvc != nil {
|
|
||||||
if err := ensureRecordingEggsUnused(oldEggs); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
oldStocks, err := s.Repository.ListStocks(tx, id)
|
|
||||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
s.Log.Errorf("Failed to list stocks before delete: %+v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := s.releaseRecordingStocks(ctx, tx, oldStocks, note, actorID); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := s.adjustProductWarehouseQuantities(ctx, tx, buildWarehouseDeltas(oldDepletions, nil, oldEggs, nil)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := s.logRecordingEggRollback(ctx, tx, oldEggs, note, actorID); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -781,6 +752,51 @@ func (s recordingService) DeleteOne(c *fiber.Ctx, id uint) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *recordingService) rollbackRecordingInventory(ctx context.Context, tx *gorm.DB, recordingID uint, note string, actorID uint) error {
|
||||||
|
if recordingID == 0 || tx == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
oldDepletions, err := s.Repository.ListDepletions(tx, recordingID)
|
||||||
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
s.Log.Errorf("Failed to list depletions: %+v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
oldEggs, err := s.Repository.ListEggs(tx, recordingID)
|
||||||
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
s.Log.Errorf("Failed to list eggs: %+v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if s.FifoSvc != nil {
|
||||||
|
if err := ensureRecordingEggsUnused(oldEggs); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s.releaseRecordingDepletions(ctx, tx, oldDepletions, note, actorID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
oldStocks, err := s.Repository.ListStocks(tx, recordingID)
|
||||||
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
s.Log.Errorf("Failed to list stocks: %+v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s.releaseRecordingStocks(ctx, tx, oldStocks, note, actorID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := s.adjustProductWarehouseQuantities(ctx, tx, buildWarehouseDeltas(oldDepletions, nil, oldEggs, nil)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := s.logRecordingEggRollback(ctx, tx, oldEggs, note, actorID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// === Persistence Helpers ===
|
// === Persistence Helpers ===
|
||||||
|
|
||||||
func (s *recordingService) ensureProductWarehousesExist(c *fiber.Ctx, stocks []validation.Stock, depletions []validation.Depletion, eggs []validation.Egg) error {
|
func (s *recordingService) ensureProductWarehousesExist(c *fiber.Ctx, stocks []validation.Stock, depletions []validation.Depletion, eggs []validation.Egg) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user