mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 15:25:43 +00:00
Feat[BE]: refactor document handling in transfer service and introduce document type constants
This commit is contained in:
@@ -76,8 +76,8 @@ func (s transferService) withRelations(db *gorm.DB) *gorm.DB {
|
||||
Preload("Details.Product").
|
||||
Preload("Deliveries.Items").
|
||||
Preload("Deliveries.Supplier").
|
||||
Preload("Documents", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Where("documentable_type = ?", "STOCK_TRANSFER")
|
||||
Preload("Deliveries.Documents", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Where("documentable_type = ?", string(utils.DocumentableTypeTransfer))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -258,29 +258,26 @@ func (s *transferService) CreateOne(c *fiber.Ctx, req *validation.TransferReques
|
||||
return err
|
||||
}
|
||||
|
||||
actorIDCopy := actorID
|
||||
if s.DocumentSvc != nil && len(files) > 0 {
|
||||
s.Log.Infof("Starting document upload for %d files", len(files))
|
||||
documentFiles := make([]commonSvc.DocumentFile, 0, len(files))
|
||||
// Upload documents for each delivery
|
||||
for idx, file := range files {
|
||||
docIndex := idx
|
||||
documentFiles = append(documentFiles, commonSvc.DocumentFile{
|
||||
File: file,
|
||||
Type: "STOCK_TRANSFER_DOCUMENT",
|
||||
Index: &docIndex,
|
||||
documentFiles := []commonSvc.DocumentFile{
|
||||
{
|
||||
File: file,
|
||||
Type: string(utils.DocumentTypeTransfer),
|
||||
Index: &idx,
|
||||
},
|
||||
}
|
||||
_, err := s.DocumentSvc.UploadDocuments(c.Context(), commonSvc.DocumentUploadRequest{
|
||||
DocumentableType: string(utils.DocumentableTypeTransfer),
|
||||
DocumentableID: deliveries[idx].Id,
|
||||
CreatedBy: &actorID,
|
||||
Files: documentFiles,
|
||||
})
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, fmt.Sprintf("Failed to upload document for delivery %d", idx+1))
|
||||
}
|
||||
}
|
||||
_, err := s.DocumentSvc.UploadDocuments(c.Context(), commonSvc.DocumentUploadRequest{
|
||||
DocumentableType: "STOCK_TRANSFER",
|
||||
DocumentableID: entityTransfer.Id,
|
||||
CreatedBy: &actorIDCopy,
|
||||
Files: documentFiles,
|
||||
})
|
||||
if err != nil {
|
||||
s.Log.Errorf("Failed to upload documents for transfer %d: %+v", entityTransfer.Id, err)
|
||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to upload transfer documents")
|
||||
}
|
||||
s.Log.Infof("Successfully uploaded documents for transfer ID %d", entityTransfer.Id)
|
||||
}
|
||||
|
||||
for _, product := range req.Products {
|
||||
|
||||
Reference in New Issue
Block a user