Просмотр исходного кода

chatRole增加pic,comments增加get

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

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

@@ -14,6 +14,9 @@ export class ChatRole {
     @Column()
     describe: string
 
+    @Column()
+    pic: String
+
     @Column()
     chatted: number
 

+ 10 - 1
src/moments/moments.controller.ts

@@ -1,4 +1,4 @@
-import { Body, Controller, Post } from "@nestjs/common";
+import { BadRequestException, Body, Controller, Get, Param, Post } from "@nestjs/common";
 import { ApiBearerAuth, ApiTags } from "@nestjs/swagger";
 import { MomentsService } from "./moments.service";
 import { PageRequest } from "src/common/dto/page-request";
@@ -16,4 +16,13 @@ export class MomentsController {
         return await this.momentsService.findAll(page)
     }
 
+    @Get('/get/:id')
+    public async get(@Param('id') id: string) {
+        try {
+            return await this.momentsService.findById(Number(id))
+        } catch (err) {
+            throw  new BadRequestException(err, 'Error: Moments not existent!')
+        }
+    }
+
 }

+ 8 - 0
src/moments/moments.service.ts

@@ -14,6 +14,7 @@ import { Moments } from './entities/moments.entity'
 import { paginate, Pagination } from 'nestjs-typeorm-paginate'
 import { PageRequest } from '../common/dto/page-request'
 import { ChatRoleService } from 'src/chat-role/chat-role.service'
+import { ro } from 'date-fns/locale'
 
 @Injectable()
 export class MomentsService {
@@ -40,4 +41,11 @@ export class MomentsService {
         return page
     }
 
+    async findById(id: number): Promise<Moments> {
+        const moments = await this.momentsRepository.findOneBy({ id: +id })
+        const chatRole = await this.chatRoleService.findById(moments.userId)
+        moments.chatRole = chatRole
+        return moments
+    }
+
 }