mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat(BE-278): add delete document s3
This commit is contained in:
@@ -1097,6 +1097,10 @@ func (s *purchaseService) DeleteItems(c *fiber.Ctx, id uint, req *validation.Del
|
||||
return nil, utils.Internal("Failed to delete purchase items")
|
||||
}
|
||||
|
||||
if err := s.deletePurchaseItemDocuments(ctx, itemsToDelete); err != nil {
|
||||
return nil, utils.Internal("Failed to delete purchase documents")
|
||||
}
|
||||
|
||||
if len(itemsToDelete) > 0 {
|
||||
if err := s.notifyExpenseItemsDeleted(ctx, purchase.Id, itemsToDelete); err != nil {
|
||||
s.Log.Errorf("Failed to sync expense deletion for purchase %d: %+v", purchase.Id, err)
|
||||
@@ -1156,6 +1160,10 @@ func (s *purchaseService) DeletePurchase(c *fiber.Ctx, id uint) error {
|
||||
return utils.Internal("Failed to delete purchase")
|
||||
}
|
||||
|
||||
if err := s.deletePurchaseItemDocuments(ctx, itemsToDelete); err != nil {
|
||||
return utils.Internal("Failed to delete purchase documents")
|
||||
}
|
||||
|
||||
if len(itemsToDelete) > 0 {
|
||||
if err := s.notifyExpenseItemsDeleted(ctx, uint(id), itemsToDelete); err != nil {
|
||||
s.Log.Errorf("Failed to sync expense deletion for purchase %d: %+v", id, err)
|
||||
@@ -1239,6 +1247,21 @@ func (s *purchaseService) notifyExpenseItemsDeleted(ctx context.Context, purchas
|
||||
|
||||
}
|
||||
|
||||
func (s *purchaseService) deletePurchaseItemDocuments(ctx context.Context, items []entity.PurchaseItem) error {
|
||||
if s.DocumentSvc == nil || len(items) == 0 {
|
||||
return nil
|
||||
}
|
||||
for _, item := range items {
|
||||
if item.Id == 0 {
|
||||
continue
|
||||
}
|
||||
if err := s.DocumentSvc.DeleteByTarget(ctx, string(utils.DocumentableTypePurchaseItem), uint64(item.Id), true); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *purchaseService) buildStaffAdjustmentPayload(
|
||||
ctx context.Context,
|
||||
purchase *entity.Purchase,
|
||||
|
||||
Reference in New Issue
Block a user