zs vor 1 Jahr
Ursprung
Commit
e5cd2ec7ff

+ 4 - 2
src/controller/core/opinion.controller.ts

@@ -23,8 +23,9 @@ export class OpinionController extends BaseController {
   @ApiResponse({ type: QVO_opinion })
   async query(@Query() filter: QDTO_opinion, @Query('skip') skip: number, @Query('limit') limit: number) {
     const list = await this.service.query(filter, { skip, limit });
+    const arr = await this.service.list(list);
     const data = [];
-    for (const i of list) {
+    for (const i of arr) {
       const newData = new QVO_opinion(i);
       data.push(newData);
     }
@@ -36,7 +37,8 @@ export class OpinionController extends BaseController {
   @ApiResponse({ type: FVO_opinion })
   async fetch(@Param('id') id: string) {
     const data = await this.service.fetch(id);
-    const result = new FVO_opinion(data);
+    const info = await this.service.detail(data);
+    const result = new FVO_opinion(info);
     return result;
   }
 

+ 7 - 1
src/interface/core/opinion.interface.ts

@@ -16,6 +16,8 @@ export class FVO_opinion {
   _id: string = undefined;
   @ApiProperty({ description: '用户id' })
   'user': string = undefined;
+  @ApiProperty({ description: '用户昵称' })
+  'user_name': string = undefined;
   @ApiProperty({ description: '用户类型' })
   'userType': string = undefined;
   @ApiProperty({ description: '问题类型' })
@@ -33,12 +35,16 @@ export class FVO_opinion {
 export class QDTO_opinion extends SearchBase {
   constructor() {
     const like_prop = [];
-    const props = ['userType'];
+    const props = ['userType', 'type', 'status'];
     const mapping = [];
     super({ like_prop, props, mapping });
   }
   @ApiProperty({ description: '用户类型' })
   'userType': string = undefined;
+  @ApiProperty({ description: '问题类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
 }
 
 export class QVO_opinion extends FVO_opinion {

+ 27 - 0
src/service/core/opinion.service.ts

@@ -3,9 +3,36 @@ import { InjectEntityModel } from '@midwayjs/typegoose';
 import { ReturnModelType } from '@typegoose/typegoose';
 import { BaseService } from 'free-midway-component';
 import { Opinion } from '../../entity/core/opinion.entity';
+import { Teacher } from '../../entity/core/teacher.entity';
+import { Student } from '../../entity/core/student.entity';
 type modelType = ReturnModelType<typeof Opinion>;
 @Provide()
 export class OpinionService extends BaseService<modelType> {
   @InjectEntityModel(Opinion)
   model: modelType;
+  @InjectEntityModel(Teacher)
+  tModel: ReturnModelType<typeof Teacher>;
+
+  @InjectEntityModel(Student)
+  sModel: ReturnModelType<typeof Student>;
+
+  async list(data) {
+    for (const val of data) {
+      const { userType, user } = val;
+      let userInfo;
+      if (userType === '0') userInfo = await this.tModel.findById(user).lean();
+      if (userType === '1') userInfo = await this.sModel.findById(user).lean();
+      if (userInfo && userInfo._id) val.user_name = userInfo.nick_name;
+    }
+    return data;
+  }
+
+  async detail(data) {
+    const { userType, user } = data;
+    let userInfo;
+    if (userType === '0') userInfo = await this.tModel.findById(user).lean();
+    if (userType === '1') userInfo = await this.sModel.findById(user).lean();
+    if (userInfo && userInfo._id) data.user_name = userInfo.nick_name;
+    return data;
+  }
 }