| 1 | /* |
| 2 | * @Author: nevin |
| 3 | * @Date: 2024-06-17 19:19:15 |
| 4 | * @LastEditTime: 2025-04-14 17:53:17 |
| 5 | * @LastEditors: nevin |
| 6 | * @Description: |
| 7 | */ |
| 8 | import { Injectable } from '@nestjs/common'; |
| 9 | import { InjectModel } from '@nestjs/mongoose'; |
| 10 | import { Model, RootFilterQuery } from 'mongoose'; |
| 11 | import { QaRecord } from 'src/db/schema/qaRecord.schema'; |
| 12 | import { TableDto } from 'src/global/dto/table.dto'; |
| 13 | |
| 14 | @Injectable() |
| 15 | export class QaService { |
| 16 | constructor( |
| 17 | @InjectModel(QaRecord.name) |
| 18 | private readonly qaRecordModel: Model<QaRecord>, |
| 19 | ) {} |
| 20 | |
| 21 | async createQaRecord(newData: Partial<QaRecord>) { |
| 22 | return await this.qaRecordModel.create(newData); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * 获取记录列表 |
| 27 | * @param userId |
| 28 | * @param page |
| 29 | * @returns |
| 30 | */ |
| 31 | async getQaRecordList( |
| 32 | page: TableDto, |
| 33 | query: any, |
| 34 | ): Promise<{ |
| 35 | list: QaRecord[]; |
| 36 | totalCount: number; |
| 37 | }> { |
| 38 | const filters: RootFilterQuery<QaRecord> = { |
| 39 | ...(query.type !== undefined && { type: query.type }), |
| 40 | }; |
| 41 | |
| 42 | const list = await this.qaRecordModel |
| 43 | .find(filters) |
| 44 | .skip((page.pageNo - 1) * page.pageSize) |
| 45 | .limit(page.pageSize) |
| 46 | .sort({ sort: -1 }); |
| 47 | |
| 48 | const totalCount = await this.qaRecordModel.countDocuments(filters); |
| 49 | |
| 50 | return { |
| 51 | list, |
| 52 | totalCount, |
| 53 | }; |
| 54 | } |
| 55 | } |
| 56 |