From 30f26b2f6a5917957855a3192c17b7f2797526f7 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 5 Dec 2025 23:38:18 +0100 Subject: [PATCH] Allow insert without original translation --- api/src/controllers/seed/images.ts | 4 ++-- api/src/controllers/seed/insert/shows.ts | 8 ++++---- api/src/controllers/seed/movies.ts | 25 ++++++++++++------------ api/src/controllers/seed/series.ts | 25 ++++++++++++------------ api/src/models/utils/original.ts | 10 ++++++---- api/tests/series/get-staff.test.ts | 3 +++ api/tests/series/seed-serie.test.ts | 3 ++- 7 files changed, 41 insertions(+), 37 deletions(-) diff --git a/api/src/controllers/seed/images.ts b/api/src/controllers/seed/images.ts index cfe87f7a..f7174096 100644 --- a/api/src/controllers/seed/images.ts +++ b/api/src/controllers/seed/images.ts @@ -30,8 +30,8 @@ export type ImageTask = { export const enqueueOptImage = ( imgQueue: ImageTask[], img: - | { url: string | null; column: PgColumn } - | { url: string | null; table: PgTable; column: SQL }, + | { url?: string | null; column: PgColumn } + | { url?: string | null; table: PgTable; column: SQL }, ): Image | null => { if (!img.url) return null; diff --git a/api/src/controllers/seed/insert/shows.ts b/api/src/controllers/seed/insert/shows.ts index a1fc5d19..38cf2200 100644 --- a/api/src/controllers/seed/insert/shows.ts +++ b/api/src/controllers/seed/insert/shows.ts @@ -33,10 +33,10 @@ export const insertShow = record( async ( show: Omit, original: Original & { - poster: string | null; - thumbnail: string | null; - banner: string | null; - logo: string | null; + poster?: string | null; + thumbnail?: string | null; + banner?: string | null; + logo?: string | null; }, translations: | SeedMovie["translations"] diff --git a/api/src/controllers/seed/movies.ts b/api/src/controllers/seed/movies.ts index 1cb7fc3c..5fb92f71 100644 --- a/api/src/controllers/seed/movies.ts +++ b/api/src/controllers/seed/movies.ts @@ -55,20 +55,13 @@ export const seedMovie = async ( const { translations, videos, collection, studios, staff, ...movie } = seed; const nextRefresh = guessNextRefresh(movie.airDate ?? new Date()); - const original = translations[movie.originalLanguage]; - if (!original) { - return { - status: 422, - message: "No translation available in the original language.", - }; - } - const col = await insertCollection(collection, { kind: "movie", nextRefresh, ...seed, }); + const original = translations[movie.originalLanguage]; const show = await insertShow( { kind: "movie", @@ -78,11 +71,17 @@ export const seedMovie = async ( entriesCount: 1, ...movie, }, - { - ...original, - latinName: original.latinName ?? null, - language: movie.originalLanguage, - }, + original + ? { + ...original, + latinName: original.latinName ?? null, + language: movie.originalLanguage, + } + : { + name: null, + latinName: null, + language: movie.originalLanguage, + }, translations, ); if ("status" in show) return show; diff --git a/api/src/controllers/seed/series.ts b/api/src/controllers/seed/series.ts index 99a169f2..36df2a8b 100644 --- a/api/src/controllers/seed/series.ts +++ b/api/src/controllers/seed/series.ts @@ -91,20 +91,13 @@ export const seedSerie = async ( } = seed; const nextRefresh = guessNextRefresh(serie.startAir ?? new Date()); - const original = translations[serie.originalLanguage]; - if (!original) { - return { - status: 422, - message: "No translation available in the original language.", - }; - } - const col = await insertCollection(collection, { kind: "serie", nextRefresh, ...seed, }); + const original = translations[serie.originalLanguage]; const show = await insertShow( { kind: "serie", @@ -113,11 +106,17 @@ export const seedSerie = async ( entriesCount: entries.length, ...serie, }, - { - ...original, - latinName: original.latinName ?? null, - language: serie.originalLanguage, - }, + original + ? { + ...original, + latinName: original.latinName ?? null, + language: serie.originalLanguage, + } + : { + name: null, + latinName: null, + language: serie.originalLanguage, + }, translations, ); if ("status" in show) return show; diff --git a/api/src/models/utils/original.ts b/api/src/models/utils/original.ts index e7f18821..d4551d20 100644 --- a/api/src/models/utils/original.ts +++ b/api/src/models/utils/original.ts @@ -7,10 +7,12 @@ export const Original = t.Object({ description: "The language code this was made in.", examples: ["ja"], }), - name: t.String({ - description: "The name in the original language", - examples: ["進撃の巨人"], - }), + name: t.Nullable( + t.String({ + description: "The name in the original language", + examples: ["進撃の巨人"], + }), + ), latinName: t.Nullable( t.String({ description: comment` diff --git a/api/tests/series/get-staff.test.ts b/api/tests/series/get-staff.test.ts index 63786d62..64dcb8f6 100644 --- a/api/tests/series/get-staff.test.ts +++ b/api/tests/series/get-staff.test.ts @@ -6,9 +6,12 @@ import { getStaffRoles, } from "tests/helpers"; import { expectStatus } from "tests/utils"; +import { db } from "~/db"; +import { staff } from "~/db/schema"; import { madeInAbyss } from "~/models/examples"; beforeAll(async () => { + await db.delete(staff); await createSerie(madeInAbyss); }); diff --git a/api/tests/series/seed-serie.test.ts b/api/tests/series/seed-serie.test.ts index 523d5c61..5532de2f 100644 --- a/api/tests/series/seed-serie.test.ts +++ b/api/tests/series/seed-serie.test.ts @@ -2,7 +2,7 @@ import { beforeAll, describe, expect, it } from "bun:test"; import { eq } from "drizzle-orm"; import { expectStatus } from "tests/utils"; import { db } from "~/db"; -import { seasons, shows, videos } from "~/db/schema"; +import { entries, seasons, shows, videos } from "~/db/schema"; import { madeInAbyss, madeInAbyssVideo } from "~/models/examples"; import { createSerie } from "../helpers"; @@ -106,6 +106,7 @@ describe("Serie seeding", () => { }); it("Can create a serie with quotes", async () => { + await db.delete(entries); const [resp, body] = await createSerie({ ...madeInAbyss, slug: "quote-test",