From 2fbf329182db3e8bab2151af420573aa0b96eae9 Mon Sep 17 00:00:00 2001 From: Mazyar Date: Wed, 8 Jul 2026 03:02:57 +0330 Subject: [PATCH] Refactor tender approval logic to streamline submission mode handling - Removed the resetting of `SubmissionMode` in the `Reject` method of the `TenderApproval` entity, ensuring that the submission mode is preserved upon rejection. - Updated the `GetCompanyTenderApprovalStats` method in the repository to count submissions by mode without filtering by status, enhancing the accuracy of statistics. - Adjusted the `ToggleTenderApproval` method in the service to set the `SubmissionMode` when rejecting a tender, ensuring consistent handling of submission modes across approval states. This update improves the clarity and functionality of tender approval processes, ensuring that submission modes are correctly managed during approval and rejection scenarios. --- internal/tender_approval/entity.go | 1 - internal/tender_approval/repository.go | 6 +++--- internal/tender_approval/service.go | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/tender_approval/entity.go b/internal/tender_approval/entity.go index d166589..d2e6682 100644 --- a/internal/tender_approval/entity.go +++ b/internal/tender_approval/entity.go @@ -148,7 +148,6 @@ func (ta *TenderApproval) Submit() { // Reject rejects the tender with a reason func (ta *TenderApproval) Reject() { ta.Status = ApprovalStatusRejected - ta.SubmissionMode = "" ta.CreatedAt = time.Now().Unix() } diff --git a/internal/tender_approval/repository.go b/internal/tender_approval/repository.go index cad62a7..75033d0 100644 --- a/internal/tender_approval/repository.go +++ b/internal/tender_approval/repository.go @@ -516,11 +516,11 @@ func (r *tenderApprovalRepository) GetCompanyTenderApprovalStats(ctx context.Con rejectedFilter := bson.M{"company_id": companyID, "status": string(ApprovalStatusRejected)} rejectedTenders, _ := r.ormRepo.Count(ctx, rejectedFilter) - // Count by submission mode for this company - selfApplyFilter := bson.M{"company_id": companyID, "status": string(ApprovalStatusSubmitted), "submission_mode": string(SubmissionModeSelfApply)} + // Count by submission mode for this company (includes submitted and rejected decisions). + selfApplyFilter := bson.M{"company_id": companyID, "submission_mode": string(SubmissionModeSelfApply)} selfApplyCount, _ := r.ormRepo.Count(ctx, selfApplyFilter) - partnershipFilter := bson.M{"company_id": companyID, "status": string(ApprovalStatusSubmitted), "submission_mode": string(SubmissionModePartnership)} + partnershipFilter := bson.M{"company_id": companyID, "submission_mode": string(SubmissionModePartnership)} partnershipCount, _ := r.ormRepo.Count(ctx, partnershipFilter) stats := &CompanyTenderApprovalStatsResponse{ diff --git a/internal/tender_approval/service.go b/internal/tender_approval/service.go index 58c0d77..5394c69 100644 --- a/internal/tender_approval/service.go +++ b/internal/tender_approval/service.go @@ -925,6 +925,7 @@ func (s *tenderApprovalService) ToggleTenderApproval(ctx context.Context, req *T existing.SubmissionMode = req.SubmissionMode } else if existing.Status == ApprovalStatusSubmitted && req.Status == ApprovalStatusRejected { existing.Reject() + existing.SubmissionMode = req.SubmissionMode } else { existing.Status = req.Status existing.SubmissionMode = req.SubmissionMode