Prevent duplicated staff members

This commit is contained in:
Zoe Roux
2025-12-04 12:48:11 +01:00
parent 20e6fbbc33
commit c2c9bbe555
7 changed files with 85 additions and 12 deletions
+12 -8
View File
@@ -4,6 +4,7 @@ import { roles, staff } from "~/db/schema";
import { conflictUpdateAllExcept, unnestValues } from "~/db/utils";
import type { SeedStaff } from "~/models/staff";
import { record } from "~/otel";
import { uniqBy } from "~/utils";
import { enqueueOptImage, flushImageQueue, type ImageTask } from "../images";
export const insertStaff = record(
@@ -13,13 +14,16 @@ export const insertStaff = record(
return await db.transaction(async (tx) => {
const imgQueue: ImageTask[] = [];
const people = seed.map((x) => ({
...x.staff,
image: enqueueOptImage(imgQueue, {
url: x.staff.image,
column: staff.image,
}),
}));
const people = uniqBy(
seed.map((x) => ({
...x.staff,
image: enqueueOptImage(imgQueue, {
url: x.staff.image,
column: staff.image,
}),
})),
(x) => x.slug,
);
const ret = await tx
.insert(staff)
.select(unnestValues(people, staff))
@@ -36,7 +40,7 @@ export const insertStaff = record(
const rval = seed.map((x, i) => ({
showPk,
staffPk: ret[i].pk,
staffPk: ret.find(y => y.slug === x.staff.slug)!.pk,
kind: x.kind,
order: i,
character: {
+4
View File
@@ -831,6 +831,9 @@ export const videosWriteH = new Elysia({ prefix: "/videos", tags: ["videos"] })
.post(
"",
async ({ body, status }) => {
if (body.length === 0) {
return status(422, { status: 422, message: "No videos" });
}
return await db.transaction(async (tx) => {
let vids: { pk: number; id: string; path: string; guess: Guess }[] = [];
try {
@@ -925,6 +928,7 @@ export const videosWriteH = new Elysia({ prefix: "/videos", tags: ["videos"] })
description:
"Invalid rendering specified. (conflicts with an existing video)",
},
422: KError,
},
},
)