wuyi 2 лет назад
Родитель
Сommit
dc4d2ade53

+ 5 - 1
src/chat-role/chat-role.controller.ts

@@ -29,10 +29,14 @@ export class ChatRoleController {
 
 
     @Post()
     @Post()
     public async list(@Body() page: PageRequest<ChatRole>) {
     public async list(@Body() page: PageRequest<ChatRole>) {
-
         return await this.chatRoleService.findAll(page)
         return await this.chatRoleService.findAll(page)
     }
     }
 
 
+    @Post('/findByPlayName')
+    public async findByPlayName(@Body() chatRole: ChatRole) {
+        return await this.chatRoleService.findByPlayerName(chatRole.playerName)
+    }
+
     @Get('/getRandom/:num')
     @Get('/getRandom/:num')
     public async randomQuery(@Param('num') num: number) {
     public async randomQuery(@Param('num') num: number) {
         return await this.chatRoleService.randomQuery(num)
         return await this.chatRoleService.randomQuery(num)

+ 8 - 0
src/chat-role/chat-role.service.ts

@@ -23,6 +23,14 @@ export class ChatRoleService {
         return await paginate<ChatRole>(this.chatRoleRepository, req.page, req.search)
         return await paginate<ChatRole>(this.chatRoleRepository, req.page, req.search)
     }
     }
 
 
+    async findByPlayerName(playerName: string): Promise<ChatRole> {
+        const chatRole = await this.chatRoleRepository.findOneBy({ playerName: playerName })
+        if (!chatRole) {
+            throw new NotFoundException(`Associated ChatRole ${playerName} not found`)
+        }
+        return chatRole
+    }
+
     async findMapByIds(ids: number[]): Promise<Map<number, ChatRole>> {
     async findMapByIds(ids: number[]): Promise<Map<number, ChatRole>> {
         const chatRoleList = await this.chatRoleRepository.createQueryBuilder('chatRole')
         const chatRoleList = await this.chatRoleRepository.createQueryBuilder('chatRole')
             .where({
             .where({

+ 3 - 0
src/chat-role/entities/chat-role.entity.ts

@@ -11,6 +11,9 @@ export class ChatRole {
     @Column()
     @Column()
     name: string
     name: string
 
 
+    @Column()
+    playerName: string
+
     @Column()
     @Column()
     describe: string
     describe: string