@@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from 'next/server'
22import { z } from 'zod'
33import { prisma } from '~/prisma'
44import { kunParseGetQuery } from '../utils/parseQuery'
5+ import type { PatchCharacterDetail } from '~/types/api/character'
56
67const characterIdSchema = z . object ( { characterId : z . coerce . number ( ) . min ( 1 ) } )
78
@@ -12,7 +13,9 @@ export const getCharacterById = async (
1213 const char = await prisma . patch_char . findUnique ( {
1314 where : { id : characterId }
1415 } )
15- if ( ! char ) return '未找到角色'
16+ if ( ! char ) {
17+ return '未找到角色'
18+ }
1619
1720 const aliases = await prisma . patch_char_alias
1821 . findMany ( { where : { patch_char_id : characterId } , select : { name : true } } )
@@ -24,7 +27,9 @@ export const getCharacterById = async (
2427 } )
2528 const patches = patchRelations . map ( ( pr ) => ( {
2629 id : pr . patch . id ,
27- name : pr . patch . name ,
30+ name_zh_cn : pr . patch . name_zh_cn ,
31+ name_ja_jp : pr . patch . name_ja_jp ,
32+ name_en_us : pr . patch . name_en_us ,
2833 banner : pr . patch . banner
2934 } ) )
3035
@@ -34,12 +39,16 @@ export const getCharacterById = async (
3439 gender : char . gender ,
3540 role : char . role ,
3641 roles : char . roles ,
37- name_zh_cn : char . name_zh_cn ,
38- name_ja_jp : char . name_ja_jp ,
39- name_en_us : char . name_en_us ,
40- description_zh_cn : char . description_zh_cn ,
41- description_ja_jp : char . description_ja_jp ,
42- description_en_us : char . description_en_us ,
42+ name : {
43+ 'zh-cn' : char . name_zh_cn ,
44+ 'ja-jp' : char . name_ja_jp ,
45+ 'en-us' : char . name_en_us
46+ } ,
47+ description : {
48+ 'zh-cn' : char . description_zh_cn ,
49+ 'ja-jp' : char . description_ja_jp ,
50+ 'en-us' : char . description_en_us
51+ } ,
4352 birthday : char . birthday ,
4453 height : char . height ,
4554 weight : char . weight ,
@@ -50,15 +59,24 @@ export const getCharacterById = async (
5059 age : char . age ,
5160 infobox : char . infobox ,
5261 alias : aliases ,
53- patches
54- }
62+ patches : patches . map ( ( p ) => ( {
63+ id : p . id ,
64+ name : {
65+ 'zh-cn' : p . name_zh_cn ,
66+ 'ja-jp' : p . name_ja_jp ,
67+ 'en-us' : p . name_en_us
68+ } ,
69+ banner : p . banner
70+ } ) )
71+ } satisfies PatchCharacterDetail
5572}
5673
5774export const GET = async ( req : NextRequest ) => {
5875 const input = kunParseGetQuery ( req , characterIdSchema )
5976 if ( typeof input === 'string' ) {
6077 return NextResponse . json ( input )
6178 }
79+
6280 const res = await getCharacterById ( input )
6381 return NextResponse . json ( res )
6482}
0 commit comments