From 6a0578ce6cdcafcb1b81e1d852c999afabf1081d Mon Sep 17 00:00:00 2001 From: Josua Frank Date: Mon, 17 Aug 2026 11:34:59 +0200 Subject: [PATCH] Dont ignore skipped values + prettier --- src/actions/candidate-action.ts | 9 +++++++-- src/actions/party-action.ts | 9 +++++++-- src/app/[locale]/faq/faq-search-launcher.tsx | 6 +----- src/app/[locale]/faq/faq-search-widget.tsx | 4 +++- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/actions/candidate-action.ts b/src/actions/candidate-action.ts index d5a6ae1..9d6b2f1 100644 --- a/src/actions/candidate-action.ts +++ b/src/actions/candidate-action.ts @@ -10,7 +10,7 @@ import { genders, } from "@/db/schema"; import { Candidate, Candidates, Status } from "@/types/candidate"; -import { Ratings } from "@/types/ratings"; +import { Ratings, RatingValue } from "@/types/ratings"; import { safeParseUrl } from "@/lib/url-utils"; export async function getVotedCandidates( @@ -100,7 +100,7 @@ export async function getVotedCandidates( .filter((vote) => vote.candidateId === candidate.id) .reduce((r, vote) => { r[String(vote.statementId)] = { - value: Math.max(0, Math.min(vote.value, 100)) / 100, + value: convertRatingValue(vote.value), isFavorite: false, explanation: vote.explanation, }; @@ -134,3 +134,8 @@ function convertGender(genderId: number): Candidate["gender"] { return "prefer-not-to-say"; } } + +function convertRatingValue(value: number): RatingValue { + if (value < 0) return "skipped"; + return Math.max(0, Math.min(value, 100)) / 100; +} diff --git a/src/actions/party-action.ts b/src/actions/party-action.ts index 52890c7..8376105 100644 --- a/src/actions/party-action.ts +++ b/src/actions/party-action.ts @@ -4,7 +4,7 @@ import { eq, and } from "drizzle-orm"; import { db } from "@/db/drizzle"; import { parties, partyVotes } from "@/db/schema"; import { Parties, Status } from "@/types/party"; -import { Ratings } from "@/types/ratings"; +import { Ratings, RatingValue } from "@/types/ratings"; import { safeParseUrl } from "@/lib/url-utils"; export async function getVotedParties(instanceId: number): Promise { @@ -56,7 +56,7 @@ export async function getVotedParties(instanceId: number): Promise { .filter((vote) => vote.partyId === party.id) .reduce((r, vote) => { r[String(vote.statementId)] = { - value: Math.max(0, Math.min(vote.value, 100)) / 100, + value: convertRatingValue(vote.value), isFavorite: false, explanation: vote.explanation, }; @@ -76,3 +76,8 @@ function getStatusFromNumber(statusNum: number): Status { return statusMap[statusNum] || "created"; } + +function convertRatingValue(value: number): RatingValue { + if (value < 0) return "skipped"; + return Math.max(0, Math.min(value, 100)) / 100; +} diff --git a/src/app/[locale]/faq/faq-search-launcher.tsx b/src/app/[locale]/faq/faq-search-launcher.tsx index 576d48f..78c1c53 100644 --- a/src/app/[locale]/faq/faq-search-launcher.tsx +++ b/src/app/[locale]/faq/faq-search-launcher.tsx @@ -32,11 +32,7 @@ export default function FAQSearchLauncher({
{configId ? (