Reserve the random slug

This commit is contained in:
Zoe Roux 2025-01-12 16:39:27 +01:00
parent 46570410ea
commit b6f996139f
No known key found for this signature in database

View File

@ -13,6 +13,7 @@ import { conflictUpdateAllExcept } from "~/db/schema/utils";
import type { SeedMovie } from "~/models/movie";
import { processOptImage } from "./images";
import { guessNextRefresh } from "./refresh";
import { KErrorT } from "~/models/error";
type Show = typeof shows.$inferInsert;
type ShowTrans = typeof showTranslations.$inferInsert;
@ -29,11 +30,18 @@ export type SeedMovieResponse = typeof SeedMovieResponse.static;
export const seedMovie = async (
seed: SeedMovie,
): Promise<
SeedMovieResponse & { status: "Created" | "OK" | "Conflict" }
> => {
): Promise<SeedMovieResponse & {
status: "Created" | "OK" | "Conflict";
}> => {
const { translations, videos: vids, ...bMovie } = seed;
if (seed.slug === "random") {
if (seed.airDate === null) {
throw new KErrorT("`random` is a reserved slug. Use something else.");
}
seed.slug = `random-${getYear(seed.airDate)}`;
}
const ret = await db.transaction(async (tx) => {
const movie: Show = {
kind: "movie",