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 {
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({
data: {
@ -36,7 +38,7 @@ export const POST: APIRoute = async ({ request, locals }) => {
status: body.status,
animations: { create: body.animations.map((id) => ({ animation: { connect: { id } } })) },
artists: {
create: artistRows.map((a) => ({
create: artistRows?.map((a) => ({
artist: {
connectOrCreate: {
create: a,

View file

@ -28,7 +28,7 @@ export const AlbumBase = s.object({
description: s.optional(s.string()),
status: s.defaulted(s.enums(Object.values(AlbumStatus)), AlbumStatus.HIDDEN),
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()), []),
classifications: 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)
})
export const EditAlbum = s.assign(
s.partial(AlbumBase),
s.object({ albumId: coerceInt, artists: s.optional(s.string()) })
)
export const EditAlbum = s.assign(s.partial(AlbumBase), s.object({ albumId: coerceInt }))