🐛 Fix non-required field poll validate incorrect
This commit is contained in:
@@ -91,10 +91,10 @@ public class PollController(AppDatabase db, PollService polls, Publisher.Publish
|
|||||||
var answerQuery = db.PollAnswers
|
var answerQuery = db.PollAnswers
|
||||||
.Where(a => a.PollId == id)
|
.Where(a => a.PollId == id)
|
||||||
.AsQueryable();
|
.AsQueryable();
|
||||||
|
|
||||||
var total = await answerQuery.CountAsync();
|
var total = await answerQuery.CountAsync();
|
||||||
Response.Headers.Append("X-Total", total.ToString());
|
Response.Headers.Append("X-Total", total.ToString());
|
||||||
|
|
||||||
var answers = await answerQuery
|
var answers = await answerQuery
|
||||||
.OrderByDescending(a => a.CreatedAt)
|
.OrderByDescending(a => a.CreatedAt)
|
||||||
.Skip(offset)
|
.Skip(offset)
|
||||||
@@ -325,4 +325,4 @@ public class PollController(AppDatabase db, PollService polls, Publisher.Publish
|
|||||||
return StatusCode(500, "An error occurred while deleting the poll... " + ex.Message);
|
return StatusCode(500, "An error occurred while deleting the poll... " + ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -75,6 +75,8 @@ public class PollService(AppDatabase db, ICacheService cache)
|
|||||||
var questionId = question.Id.ToString();
|
var questionId = question.Id.ToString();
|
||||||
if (question.IsRequired && !answer.ContainsKey(questionId))
|
if (question.IsRequired && !answer.ContainsKey(questionId))
|
||||||
throw new Exception($"Missing required field: {question.Title}");
|
throw new Exception($"Missing required field: {question.Title}");
|
||||||
|
else if (!answer.ContainsKey(questionId))
|
||||||
|
continue;
|
||||||
switch (question.Type)
|
switch (question.Type)
|
||||||
{
|
{
|
||||||
case PollQuestionType.Rating when answer[questionId].ValueKind != JsonValueKind.Number:
|
case PollQuestionType.Rating when answer[questionId].ValueKind != JsonValueKind.Number:
|
||||||
|
Reference in New Issue
Block a user