mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat(BE): fix delete project flock budget and uniformity, and fix uniformity with update purchase document
This commit is contained in:
@@ -180,7 +180,10 @@ func (ctrl *PurchaseController) ReceiveProducts(c *fiber.Ctx) error {
|
||||
req.Items = []validation.ReceivePurchaseItemRequest{singleItem}
|
||||
}
|
||||
}
|
||||
req.TravelDocuments = form.File["documents"]
|
||||
req.TravelDocuments = form.File["travel_documents"]
|
||||
if len(req.TravelDocuments) == 0 {
|
||||
req.TravelDocuments = form.File["documents"]
|
||||
}
|
||||
result, err := ctrl.service.ReceiveProducts(c, uint(id), req)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -999,6 +999,22 @@ func (s *purchaseService) uploadTravelDocument(
|
||||
return "", errors.New("document service not available")
|
||||
}
|
||||
|
||||
documents, err := s.DocumentSvc.ListByTarget(ctx, string(utils.DocumentableTypePurchaseItem), uint64(itemID))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(documents) > 0 {
|
||||
var ids []uint
|
||||
for _, doc := range documents {
|
||||
if doc.Type == string(utils.DocumentTypePurchaseTravel) {
|
||||
ids = append(ids, doc.Id)
|
||||
}
|
||||
}
|
||||
if err := s.DocumentSvc.DeleteDocuments(ctx, ids, true); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
documentFiles := []commonSvc.DocumentFile{{
|
||||
File: file,
|
||||
Type: string(utils.DocumentTypePurchaseTravel),
|
||||
@@ -1015,7 +1031,7 @@ func (s *purchaseService) uploadTravelDocument(
|
||||
if len(results) == 0 {
|
||||
return "", errors.New("upload result is empty")
|
||||
}
|
||||
return results[0].URL, nil
|
||||
return results[0].Document.Path, nil
|
||||
}
|
||||
|
||||
func (s *purchaseService) DeleteItems(c *fiber.Ctx, id uint, req *validation.DeletePurchaseItemsRequest) (*entity.Purchase, error) {
|
||||
@@ -1499,10 +1515,56 @@ func (s *purchaseService) loadPurchase(
|
||||
if err := s.attachLatestApproval(ctx, purchase); err != nil {
|
||||
s.Log.Warnf("Unable to attach latest approval for purchase %d: %+v", id, err)
|
||||
}
|
||||
s.applyTravelDocumentURLs(ctx, purchase)
|
||||
|
||||
return purchase, nil
|
||||
}
|
||||
|
||||
func (s *purchaseService) applyTravelDocumentURLs(ctx context.Context, purchase *entity.Purchase) {
|
||||
if purchase == nil || s.DocumentSvc == nil {
|
||||
return
|
||||
}
|
||||
|
||||
for i := range purchase.Items {
|
||||
item := &purchase.Items[i]
|
||||
documents, err := s.DocumentSvc.ListByTarget(ctx, string(utils.DocumentableTypePurchaseItem), uint64(item.Id))
|
||||
if err != nil {
|
||||
s.Log.Warnf("Unable to load travel documents for purchase item %d: %+v", item.Id, err)
|
||||
} else {
|
||||
var targetDoc *entity.Document
|
||||
for j := len(documents) - 1; j >= 0; j-- {
|
||||
if documents[j].Type == string(utils.DocumentTypePurchaseTravel) {
|
||||
targetDoc = &documents[j]
|
||||
break
|
||||
}
|
||||
}
|
||||
if targetDoc != nil {
|
||||
url, err := s.DocumentSvc.PresignURL(ctx, *targetDoc, 15*time.Minute)
|
||||
if err != nil {
|
||||
s.Log.Warnf("Unable to presign travel document for purchase item %d: %+v", item.Id, err)
|
||||
} else if url != "" {
|
||||
item.TravelNumberDocs = &url
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
path := item.TravelNumberDocs
|
||||
if path == nil || strings.TrimSpace(*path) == "" {
|
||||
continue
|
||||
}
|
||||
url, err := commonSvc.ResolveDocumentURL(ctx, s.DocumentSvc, *path, 15*time.Minute)
|
||||
if err != nil {
|
||||
s.Log.Warnf("Unable to presign travel document for purchase item %d: %+v", item.Id, err)
|
||||
continue
|
||||
}
|
||||
if url == "" {
|
||||
continue
|
||||
}
|
||||
item.TravelNumberDocs = &url
|
||||
}
|
||||
}
|
||||
|
||||
func collectPFKIDsFromPurchase(p *entity.Purchase) []uint {
|
||||
seen := make(map[uint]struct{})
|
||||
ids := make([]uint, 0)
|
||||
|
||||
Reference in New Issue
Block a user