feat(support): verify the manual assessment request after a C3 refusal
This commit is contained in:
1 parent
6bfd7098c3
commit
68286af8b7
20 files changed
+680
-74
No files matched your search
@@ -0,0 +1,69 @@
|
||||
package supportcase
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/port/outbound"
|
||||
)
|
||||
|
||||
// A manual assessment request is an ordinary support case. This file holds the
|
||||
// rules that are specific to it:
|
||||
//
|
||||
// - It never reads, grants, or revokes any consent. A candidate who refused
|
||||
// C3, or who never answered the C3 question, reaches the same code path
|
||||
// as every other candidate, so the manual path cannot become a hidden
|
||||
// way to enable automated categorization.
|
||||
// - It never creates an attempt and never writes a grade or category. The
|
||||
// case only enters the expert queue (waiting_expert) in the creation
|
||||
// transaction.
|
||||
// - A prior attempt is optional. When the author references one it has to
|
||||
// belong to the same specialization; its outcome (including a failed
|
||||
// first test) does not matter and is never changed.
|
||||
// - The grading rubric is pinned when exactly one current reviewed category
|
||||
// answers the requested specialization and grade. Otherwise no rubric is
|
||||
// pinned and the case reports that honestly with a null rubric version.
|
||||
|
||||
// resolveManualAssessmentRubric pins the current reviewed rubric for the
|
||||
// requested target. It leaves the pin empty, without an error, when the bank
|
||||
// has no single current category for the target: the request is still
|
||||
// accepted and waits for an expert.
|
||||
func resolveManualAssessmentRubric(
|
||||
ctx context.Context,
|
||||
repositories outbound.SupportCaseRepositories,
|
||||
fields *domain.NewSupportCaseInput,
|
||||
) error {
|
||||
if fields.Type != domain.SupportCaseTypeManualAssessment || fields.AssessmentTarget == nil {
|
||||
return nil
|
||||
}
|
||||
rubric, err := repositories.SupportCaseRubrics().ResolveCurrent(
|
||||
ctx, fields.AssessmentTarget.Specialization, fields.AssessmentTarget.Grade,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s - resolve current manual assessment rubric: %w", createLocation, err)
|
||||
}
|
||||
if rubric == nil {
|
||||
return nil
|
||||
}
|
||||
if rubric.Version < 1 || rubric.OpeningID == uuid.Nil || rubric.PolicyVersionID.IsZero() {
|
||||
return fmt.Errorf("%s - rubric resolver returned an incomplete pin: %w", createLocation, domain.ErrInvalidSupportCase)
|
||||
}
|
||||
fields.RubricVersion = &rubric.Version
|
||||
fields.RubricOpeningID = &rubric.OpeningID
|
||||
fields.RubricPolicyID = &rubric.PolicyVersionID
|
||||
return nil
|
||||
}
|
||||
|
||||
// validateManualAssessmentAttempt accepts an owned attempt of the requested
|
||||
// specialization in any state. A failed or unfinished attempt is exactly the
|
||||
// case a manual assessment exists for, so only the specialization is compared.
|
||||
func validateManualAssessmentAttempt(target *domain.SupportCaseAssessmentTarget, attempt domain.AssessmentAttempt) error {
|
||||
snapshot := attempt.Snapshot()
|
||||
if target == nil || snapshot.Specialization == nil || *snapshot.Specialization != target.Specialization {
|
||||
return ErrStateConflict
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -294,32 +294,6 @@ func createSupportCaseInTransaction(
|
||||
return storeCreatedCase(ctx, unit, repositories, request, supportCase)
|
||||
}
|
||||
|
||||
func resolveManualAssessmentRubric(
|
||||
ctx context.Context,
|
||||
repositories outbound.SupportCaseRepositories,
|
||||
fields *domain.NewSupportCaseInput,
|
||||
) error {
|
||||
if fields.Type != domain.SupportCaseTypeManualAssessment || fields.AssessmentTarget == nil {
|
||||
return nil
|
||||
}
|
||||
rubric, err := repositories.SupportCaseRubrics().ResolveCurrent(
|
||||
ctx, fields.AssessmentTarget.Specialization, fields.AssessmentTarget.Grade,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s - resolve current manual assessment rubric: %w", createLocation, err)
|
||||
}
|
||||
if rubric == nil {
|
||||
return nil
|
||||
}
|
||||
if rubric.Version < 1 || rubric.OpeningID == uuid.Nil || rubric.PolicyVersionID.IsZero() {
|
||||
return fmt.Errorf("%s - rubric resolver returned an incomplete pin: %w", createLocation, domain.ErrInvalidSupportCase)
|
||||
}
|
||||
fields.RubricVersion = &rubric.Version
|
||||
fields.RubricOpeningID = &rubric.OpeningID
|
||||
fields.RubricPolicyID = &rubric.PolicyVersionID
|
||||
return nil
|
||||
}
|
||||
|
||||
func storeReferenceFailure(
|
||||
ctx context.Context,
|
||||
unit outbound.UnitOfWork,
|
||||
@@ -505,11 +479,7 @@ func validateAttemptReference(input domain.NewSupportCaseInput, attempt domain.A
|
||||
case domain.SupportCaseTypeSupport, domain.SupportCaseTypeComplaint:
|
||||
return nil
|
||||
case domain.SupportCaseTypeManualAssessment:
|
||||
target := input.AssessmentTarget
|
||||
attemptSnapshot := attempt.Snapshot()
|
||||
if target == nil || attemptSnapshot.Specialization == nil || *attemptSnapshot.Specialization != target.Specialization {
|
||||
return ErrStateConflict
|
||||
}
|
||||
return validateManualAssessmentAttempt(input.AssessmentTarget, attempt)
|
||||
case domain.SupportCaseTypeGradeAppeal:
|
||||
if attempt.State() != domain.AssessmentAttemptStateCompleted {
|
||||
return ErrStateConflict
|
||||
|
||||
Reference in new issue
Block a user