Skip to content

Commit

Permalink
Reserve the random slug
Browse files Browse the repository at this point in the history
  • Loading branch information
zoriya committed Jan 13, 2025
1 parent 4657041 commit b6f9961
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions api/src/controllers/seed/movies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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",
Expand Down

0 comments on commit b6f9961

Please sign in to comment.