Enhance company document management with file ID sanitization and detachment functionality
continuous-integration/drone/push Build is passing

- Updated the `UploadDocuments` method to sanitize document file IDs before saving, ensuring only valid references are stored.
- Introduced `DetachDocumentFileID` method in the `companyService` to remove file IDs from all companies referencing a deleted file, improving data integrity.
- Enhanced the `companyRepository` with a new method to handle the removal of document file IDs from the database.
- Updated the `filestore` handler to utilize the new detachment functionality when files are deleted, ensuring consistent state across domain entities.

This update improves the management of document file IDs within the company domain, enhancing data integrity and reference handling.
This commit is contained in:
Mazyar
2026-06-22 22:37:50 +03:30
parent 3bfed0dc74
commit 5fbfcd4149
5 changed files with 113 additions and 14 deletions
+9 -2
View File
@@ -35,6 +35,9 @@ type Service interface {
// UploadDocuments uploads files and attaches them to a company
UploadDocuments(ctx context.Context, companyID, uploadedBy string, files []*multipart.FileHeader) (*UploadDocumentsResponse, error)
// DetachDocumentFileID removes a file ID from companies when the file is deleted
DetachDocumentFileID(ctx context.Context, fileID string) error
// StartAIOnboarding sends company data to the AI team for recommendation onboarding
StartAIOnboarding(ctx context.Context, companyID string) (*OnboardingResponse, error)
@@ -121,7 +124,7 @@ func (s *companyService) Create(ctx context.Context, form *CompanyForm) (*Compan
Address: s.convertAddressForm(form.Address),
Phone: form.Phone,
Email: form.Email,
DocumentFileIDs: form.DocumentFileIDs,
DocumentFileIDs: s.sanitizeDocumentFileIDs(form.DocumentFileIDs),
Tags: s.convertCompanyTagsForm(form.Tags),
IsVerified: false,
IsCompliant: false,
@@ -183,6 +186,8 @@ func (s *companyService) GetByID(ctx context.Context, id string) (*CompanyRespon
})
}
company.DocumentFileIDs = s.sanitizeDocumentFileIDs(company.DocumentFileIDs)
return company.ToResponse(convertedCategories), nil
}
@@ -284,7 +289,7 @@ func (s *companyService) Update(ctx context.Context, id string, form *CompanyFor
}
if form.DocumentFileIDs != nil {
company.DocumentFileIDs = form.DocumentFileIDs
company.DocumentFileIDs = s.sanitizeDocumentFileIDs(form.DocumentFileIDs)
}
if form.Tags != nil {
@@ -497,6 +502,8 @@ func (s *companyService) GetMyCompany(ctx context.Context, id string) (*CompanyP
return nil, errors.New("company not found")
}
company.DocumentFileIDs = s.sanitizeDocumentFileIDs(company.DocumentFileIDs)
return company.ToProfileResponse(), nil
}