From 5ff522311e80017bd09705fbe030b8249e80b491 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Sun, 27 Oct 2024 22:51:04 +0100 Subject: [PATCH] Fixed movie duration returned as string, therefore failing formatting. --- src/movies.js | 2 +- utils/format.js | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/movies.js b/src/movies.js index 3953bbc..84bc6f7 100644 --- a/src/movies.js +++ b/src/movies.js @@ -79,7 +79,7 @@ export async function fetchMoviesById(movieIds, reqUser) { stashes, } = await promiseProps({ movies: knex('movies') - .select('movies.*', knex.raw('sum(releases.duration) as duration')) + .select('movies.*', knex.raw('cast(sum(releases.duration) as integer) as duration')) .leftJoin('movies_scenes', 'movies_scenes.movie_id', 'movies.id') .leftJoin('releases', 'releases.id', 'movies_scenes.scene_id') .whereIn('movies.id', movieIds) diff --git a/utils/format.js b/utils/format.js index 6c75d27..95968a1 100644 --- a/utils/format.js +++ b/utils/format.js @@ -1,8 +1,10 @@ import { format } from 'date-fns'; -export function formatDuration(duration, forceHours) { - if (typeof duration !== 'number') { - return duration; +export function formatDuration(rawDuration, forceHours) { + const duration = Number(rawDuration); + + if (Number.isNaN(duration)) { + return rawDuration; } const hours = Math.floor(duration / 3600);