Skip to content

Commit

Permalink
Added extra validator for alpha numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulCooperWorkJustice committed Aug 20, 2024
1 parent 477da7c commit 95b44d7
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public static class SubmitToProviderQa
public class Command : IRequest<Result>
{
public required string ParticipantId { get; set; }

}

public class Handler(IUnitOfWork unitOfWork) : IRequestHandler<Command, Result>
Expand All @@ -36,9 +35,9 @@ public A_ParticipantMustExistValidator(IUnitOfWork unitOfWork)
.MinimumLength(9)
.MaximumLength(9)
.WithMessage("Invalid Participant Id")
.Matches(ValidationConstants.AlphaNumeric).WithMessage(string.Format(ValidationConstants.AlphaNumericMessage, "Participant Id"))
.MustAsync(MustExist)
.WithMessage("Participant does not exist")
.Matches(ValidationConstants.AlphaNumeric).WithMessage(string.Format(ValidationConstants.AlphaNumericMessage, "Participant Id"));
.WithMessage("Participant does not exist");
}
private async Task<bool> MustExist(string identifier, CancellationToken cancellationToken)
=> await _unitOfWork.DbContext.Participants.AnyAsync(e => e.Id == identifier, cancellationToken);
Expand Down Expand Up @@ -81,8 +80,7 @@ private async Task<bool> MustBeScored(string identifier, CancellationToken cance
var assessments = await _unitOfWork.DbContext.ParticipantAssessments
.Include(pa => pa.Scores)
.Where(pa => pa.ParticipantId == identifier)
.ToArrayAsync(cancellationToken)
;
.ToArrayAsync(cancellationToken);

var latest = assessments.MaxBy(a => a.Created);

Expand Down Expand Up @@ -117,5 +115,4 @@ private async Task<bool> MustHaveTwoReds(string identifier, CancellationToken ca
&& latest.Scores.Count(s => s.Score is >= 0 and < 10) > 1;
}
}

}

0 comments on commit 95b44d7

Please sign in to comment.