Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions nuxt-app/server/middleware/rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ export default eventHandler(async function(event) {
}

let slug = match[1];
let vote = match[2];
let voteString = match[2];

// Type narrowing: the regex already validated this is "up" or "down"
// We use a type guard to make TypeScript aware of this
if (voteString !== 'up' && voteString !== 'down') {
// This should never happen due to regex validation, but satisfies TypeScript
throw createError({ statusCode: 400, message: 'Invalid vote value' });
}
const vote = voteString;

const directus = useDirectus();

Expand All @@ -24,7 +32,6 @@ export default eventHandler(async function(event) {
throw createError({ statusCode: 404, message: 'Podcast not found' });
}

// @ts-ignore (Type-safety is enforced by regex)
try {
await directus.createRating(vote, podcast);

Expand Down