mirror of
https://github.com/jorgev259/soc_site-astro.git
synced 2025-06-29 07:57:41 +00:00
Album API consistency
This commit is contained in:
parent
deb47c52e1
commit
63affb6b7f
2 changed files with 6 additions and 7 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 }))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue