Refactor code

This commit is contained in:
2026-02-03 13:12:31 +01:00
parent 8572e22c5d
commit 531bb8750e
23 changed files with 106 additions and 48 deletions

View File

@ -54,12 +54,12 @@ function centroidFromPaletteHexes(
};
const fallbackHex =
hexByType["Vibrant"] ||
hexByType["Muted"] ||
hexByType["DarkVibrant"] ||
hexByType["DarkMuted"] ||
hexByType["LightVibrant"] ||
hexByType["LightMuted"];
hexByType.Vibrant ||
hexByType.Muted ||
hexByType.DarkVibrant ||
hexByType.DarkMuted ||
hexByType.LightVibrant ||
hexByType.LightMuted;
let L = 0,
A = 0,
@ -123,7 +123,9 @@ export async function generateArtworkColorsForArtwork(artworkId: string) {
for (const { type, hex } of vibrantHexes) {
if (!hex) continue;
const [r, g, b] = hex.match(/\w\w/g)!.map((h) => parseInt(h, 16));
const match = hex.match(/\w\w/g);
if (!match) continue;
const [r, g, b] = match.map((h) => parseInt(h, 16));
const name = generateColorName(hex);
const color = await prisma.color.upsert({

View File

@ -3,7 +3,7 @@
import { prisma } from "@/lib/prisma";
import { artworkSchema } from "@/schemas/artworks/imageSchema";
import { normalizeNames, slugify } from "@/utils/artworkHelpers";
import { z } from "zod/v4";
import type { z } from "zod/v4";
// Updates an artwork and its tag/category relationships.
export async function updateArtwork(

View File

@ -2,9 +2,9 @@
import { auth } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import type { SignUpResponse } from "@/types/auth";
import { registerFirstUserSchema } from "@/schemas/auth";
import type { RegisterFirstUserInput } from "@/schemas/auth";
import { registerFirstUserSchema } from "@/schemas/auth";
import type { SignUpResponse } from "@/types/auth";
// Registers the very first user and upgrades them to admin.
export async function registerFirstUser(input: RegisterFirstUserInput) {

View File

@ -2,9 +2,9 @@
import { auth } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { headers } from "next/headers";
import type { SessionWithRole } from "@/types/auth";
import type { UsersListRow } from "@/types/users";
import type { UserRole, UsersListRow } from "@/types/users";
import { headers } from "next/headers";
// Returns all users for the admin users table.
export async function getUsers(): Promise<UsersListRow[]> {
@ -28,9 +28,16 @@ export async function getUsers(): Promise<UsersListRow[]> {
},
});
return rows.map((r) => ({
...r,
createdAt: r.createdAt.toISOString(),
updatedAt: r.updatedAt.toISOString(),
}));
return rows.map((r) => {
if (r.role !== "admin" && r.role !== "user") {
throw new Error(`Unexpected user role: ${r.role}`);
}
return {
...r,
role: r.role as UserRole,
createdAt: r.createdAt.toISOString(),
updatedAt: r.updatedAt.toISOString(),
};
});
}