Make date range queries fail gracefully

This commit is contained in:
Sam Becker 2024-02-27 23:52:33 -06:00
parent ab8d088df5
commit 3f0944c104
5 changed files with 16 additions and 8 deletions

View File

@ -16,7 +16,7 @@ export default function CameraOverview({
camera: Camera,
photos: Photo[],
count: number,
dateRange: PhotoDateRange,
dateRange?: PhotoDateRange,
showMorePath?: string,
animateOnFirstLoadOnly?: boolean,
}) {

View File

@ -13,7 +13,7 @@ export default function CameraShareModal({
camera: Camera
photos: Photo[]
count: number
dateRange: PhotoDateRange,
dateRange?: PhotoDateRange,
}) {
return (
<ShareModal

View File

@ -190,14 +190,18 @@ const sqlGetPhotosDateRange = async () => sql`
SELECT MIN(taken_at_naive) as start, MAX(taken_at_naive) as end
FROM photos
WHERE hidden IS NOT TRUE
`.then(({ rows }) => rows[0] as PhotoDateRange);
`.then(({ rows }) => rows[0]?.start && rows[0]?.end
? rows[0] as PhotoDateRange
: undefined);
const sqlGetPhotosTagDateRange = async (tag: string) => sql`
SELECT MIN(taken_at_naive) as start, MAX(taken_at_naive) as end
FROM photos
WHERE ${tag}=ANY(tags) AND
hidden IS NOT TRUE
`.then(({ rows }) => rows[0] as PhotoDateRange);
`.then(({ rows }) => rows[0]?.start && rows[0]?.end
? rows[0] as PhotoDateRange
: undefined);
const sqlGetPhotosCameraDateRange = async (camera: Camera) => sql`
SELECT MIN(taken_at_naive) as start, MAX(taken_at_naive) as end
@ -206,7 +210,9 @@ const sqlGetPhotosCameraDateRange = async (camera: Camera) => sql`
LOWER(make)=${parameterize(camera.make, true)} AND
LOWER(REPLACE(model, ' ', '-'))=${parameterize(camera.model, true)} AND
hidden IS NOT TRUE
`.then(({ rows }) => rows[0] as PhotoDateRange);
`.then(({ rows }) => rows[0]?.start && rows[0]?.end
? rows[0] as PhotoDateRange
: undefined);
const sqlGetPhotosFilmSimulationDateRange = async (
simulation: FilmSimulation,
@ -215,7 +221,9 @@ const sqlGetPhotosFilmSimulationDateRange = async (
FROM photos
WHERE film_simulation=${simulation} AND
hidden IS NOT TRUE
`.then(({ rows }) => rows[0] as PhotoDateRange);
`.then(({ rows }) => rows[0]?.start && rows[0]?.end
? rows[0] as PhotoDateRange
: undefined);
const sqlGetUniqueTags = async () => sql`
SELECT DISTINCT unnest(tags) as tag, COUNT(*)

View File

@ -16,7 +16,7 @@ export default function FilmSimulationOverview({
simulation: FilmSimulation,
photos: Photo[],
count: number,
dateRange: PhotoDateRange,
dateRange?: PhotoDateRange,
showMorePath?: string,
animateOnFirstLoadOnly?: boolean,
}) {

View File

@ -15,7 +15,7 @@ export default function TagOverview({
tag: string,
photos: Photo[],
count: number,
dateRange: PhotoDateRange,
dateRange?: PhotoDateRange,
showMorePath?: string,
animateOnFirstLoadOnly?: boolean,
}) {