Refactor code
This commit is contained in:
@ -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({
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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(),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user