Album API consistency

This commit is contained in:
Jorge Vargas 2025-04-07 12:27:08 -06:00
parent deb47c52e1
commit 63affb6b7f
2 changed files with 6 additions and 7 deletions

View file

@ -22,7 +22,9 @@ export const POST: APIRoute = async ({ request, locals }) => {
try { try {
const albumRow = await prismaClient.$transaction(async (tx) => { const albumRow = await prismaClient.$transaction(async (tx) => {
const artistRows = body.artists.map((name: string) => ({ slug: slug(name), name })) const artistRows = body.artists
?.split(',')
.map((name: string) => ({ slug: slug(name.trim()), name: name.trim() }))
const albumRow = await tx.albums.create({ const albumRow = await tx.albums.create({
data: { data: {
@ -36,7 +38,7 @@ export const POST: APIRoute = async ({ request, locals }) => {
status: body.status, status: body.status,
animations: { create: body.animations.map((id) => ({ animation: { connect: { id } } })) }, animations: { create: body.animations.map((id) => ({ animation: { connect: { id } } })) },
artists: { artists: {
create: artistRows.map((a) => ({ create: artistRows?.map((a) => ({
artist: { artist: {
connectOrCreate: { connectOrCreate: {
create: a, create: a,

View file

@ -28,7 +28,7 @@ export const AlbumBase = s.object({
description: s.optional(s.string()), description: s.optional(s.string()),
status: s.defaulted(s.enums(Object.values(AlbumStatus)), AlbumStatus.HIDDEN), status: s.defaulted(s.enums(Object.values(AlbumStatus)), AlbumStatus.HIDDEN),
animations: s.defaulted(s.array(coerceInt), []), animations: s.defaulted(s.array(coerceInt), []),
artists: s.defaulted(s.array(s.string()), []), artists: s.defaulted(s.optional(s.string()), ''),
categories: s.defaulted(s.array(s.string()), []), categories: s.defaulted(s.array(s.string()), []),
classifications: s.defaulted(s.array(s.string()), []), classifications: s.defaulted(s.array(s.string()), []),
games: s.defaulted(s.array(s.string()), []), games: s.defaulted(s.array(s.string()), []),
@ -40,7 +40,4 @@ export const AlbumBase = s.object({
request: s.optional(coerceInt) request: s.optional(coerceInt)
}) })
export const EditAlbum = s.assign( export const EditAlbum = s.assign(s.partial(AlbumBase), s.object({ albumId: coerceInt }))
s.partial(AlbumBase),
s.object({ albumId: coerceInt, artists: s.optional(s.string()) })
)