返回 AiToEarn
feedback.controller.ts
根目录 / project / aitoearn-electron / server / src / modules / other / feedback.controller.ts
1 /*
2 * @Author: nevin
3 * @Date: 2024-06-17 19:19:20
4 * @LastEditTime: 2024-12-23 12:45:22
5 * @LastEditors: nevin
6 * @Description: 反馈
7 */
8 import { Body, Controller, Post, Sse } from '@nestjs/common';
9 import { ApiOperation, ApiTags } from '@nestjs/swagger';
10 import { ParamsValidationPipe } from 'src/validation.pipe';
11 import { FeedbackService } from './feedback.service';
12 import { CreateFeedBackDto } from './dto/feedback.dto';
13 import { TokenInfo } from 'src/auth/interfaces/auth.interfaces';
14 import { UserService } from 'src/user/user.service';
15 import { interval, map, Observable } from 'rxjs';
16 import { GetToken } from 'src/auth/auth.guard';
17 import { Feedback } from 'src/db/schema/feedback.schema';
18
19 @ApiTags('反馈')
20 @Controller('feedback')
21 export class FeedbackController {
22 constructor(
23 private readonly feedbackService: FeedbackService,
24 private readonly userService: UserService,
25 ) {}
26
27 @ApiOperation({
28 description: '提交反馈',
29 summary: '提交反馈',
30 })
31 @Post()
32 async createFeedback(
33 @GetToken() token: TokenInfo,
34 @Body(new ParamsValidationPipe()) body: CreateFeedBackDto,
35 ) {
36 const { fileUrlList, content, type, tagList } = body;
37 const userInfo = await this.userService.getUserInfoById(token.id);
38 const newData = new Feedback();
39 newData.content = content;
40 newData.userId = userInfo.id;
41 newData.userName = userInfo.name;
42 newData.fileUrlList = fileUrlList; // TODO: 去除临时目录
43 newData.type = type;
44 newData.tagList = tagList;
45
46 const res = await this.feedbackService.createFeedback(newData);
47 return res;
48 }
49
50 @ApiOperation({
51 description: 'sse接口测试',
52 summary: 'sse接口测试',
53 })
54 @Post('sse')
55 @Sse('sse')
56 sse2(): Observable<any> {
57 const text = [
58 '这是第一句话',
59 '这是第二句话',
60 '这是第三句话',
61 '这是第四句话',
62 ];
63 console.log(text);
64 return interval(1000).pipe(
65 map((i) => {
66 return {
67 data: text[i],
68 };
69 }),
70 );
71 }
72 }
73
73 lines TYPESCRIPT