fix: 修复10个TS类型错误 - ForbiddenException导入、sort字段、user.name、question.content、lines类型、status比较

This commit is contained in:
Developer
2026-05-15 08:22:10 +08:00
parent 6cc65f7776
commit 186423d172
3 changed files with 11 additions and 11 deletions
@@ -4,6 +4,7 @@ import {
NotFoundException, NotFoundException,
Inject, Inject,
forwardRef, forwardRef,
ForbiddenException,
} from '@nestjs/common'; } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { Repository, DeepPartial, In } from 'typeorm'; import { Repository, DeepPartial, In } from 'typeorm';
@@ -34,7 +34,7 @@ export class ExportService {
const questions = await this.questionRepository.find({ const questions = await this.questionRepository.find({
where: { sessionId }, where: { sessionId },
order: { order: 'ASC' }, order: { createdAt: 'ASC' },
}); });
const answers = await this.answerRepository.find({ const answers = await this.answerRepository.find({
@@ -46,7 +46,7 @@ export class ExportService {
const summarySheet = [ const summarySheet = [
['评估报告'], ['评估报告'],
['评估ID', session.id], ['评估ID', session.id],
['用户', session.user?.name || session.userId], ['用户', session.user?.displayName || session.user?.username || session.userId],
['状态', session.status], ['状态', session.status],
['最终分数', session.finalScore || '-'], ['最终分数', session.finalScore || '-'],
['原始分数', session.originalScore || '-'], ['原始分数', session.originalScore || '-'],
@@ -68,7 +68,7 @@ export class ExportService {
const a = answerMap.get(q.id); const a = answerMap.get(q.id);
questionRows.push([ questionRows.push([
(i + 1).toString(), (i + 1).toString(),
q.content || q.questionText || '', q.questionText || '',
a?.userAnswer || '', a?.userAnswer || '',
a?.score?.toString() || '', a?.score?.toString() || '',
a?.feedback || '', a?.feedback || '',
@@ -122,11 +122,11 @@ export class ExportService {
if ((currentLine + ' ' + word).trim().length <= maxWidth) { if ((currentLine + ' ' + word).trim().length <= maxWidth) {
currentLine = (currentLine + ' ' + word).trim(); currentLine = (currentLine + ' ' + word).trim();
} else { } else {
if (currentLine) lines.push([currentLine]); if (currentLine) lines.push(currentLine);
currentLine = word; currentLine = word;
} }
} }
if (currentLine) lines.push([currentLine]); if (currentLine) lines.push(currentLine);
} }
return lines.map((l) => [l]); return lines.map((l) => [l]);
@@ -148,7 +148,7 @@ export class ExportService {
const questions = await this.questionRepository.find({ const questions = await this.questionRepository.find({
where: { sessionId }, where: { sessionId },
order: { order: 'ASC' }, order: { createdAt: 'ASC' },
}); });
const answers = await this.answerRepository.find({ const answers = await this.answerRepository.find({
@@ -173,7 +173,7 @@ export class ExportService {
lines.push(''); lines.push('');
lines.push(`评估ID: ${session.id}`); lines.push(`评估ID: ${session.id}`);
lines.push(`用户: ${session.user?.name || session.userId}`); lines.push(`用户: ${session.user?.displayName || session.user?.username || session.userId}`);
lines.push(`状态: ${session.status === 'COMPLETED' ? '已完成' : '进行中'}`); lines.push(`状态: ${session.status === 'COMPLETED' ? '已完成' : '进行中'}`);
lines.push(`最终分数: ${session.finalScore || '-'}`); lines.push(`最终分数: ${session.finalScore || '-'}`);
lines.push(`评估模板: ${session.template?.name || session.templateJson?.name || '-'}`); lines.push(`评估模板: ${session.template?.name || session.templateJson?.name || '-'}`);
@@ -202,7 +202,7 @@ export class ExportService {
const a = answerMap.get(q.id); const a = answerMap.get(q.id);
lines.push(''); lines.push('');
lines.push(`${i + 1}题:`); lines.push(`${i + 1}题:`);
lines.push(` 题目: ${q.content || q.questionText || '-'}`); lines.push(` 题目: ${q.questionText || '-'}`);
lines.push(` 用户回答: ${a?.userAnswer || '-'}`); lines.push(` 用户回答: ${a?.userAnswer || '-'}`);
lines.push(` 得分: ${a?.score ?? '-'}`); lines.push(` 得分: ${a?.score ?? '-'}`);
lines.push(` 反馈: ${a?.feedback || '-'}`); lines.push(` 反馈: ${a?.feedback || '-'}`);
@@ -196,9 +196,9 @@ export class QuestionBankService {
if (bank.status === QuestionBankStatus.PUBLISHED) { if (bank.status === QuestionBankStatus.PUBLISHED) {
return bank; return bank;
} }
if (bank.status !== QuestionBankStatus.PUBLISHED && bank.status !== QuestionBankStatus.REJECTED) { if (bank.status !== QuestionBankStatus.REJECTED) {
throw new ForbiddenException( throw new ForbiddenException(
'Only PUBLISHED or REJECTED status can be re-published', 'Only REJECTED status can be re-published',
); );
} }
bank.status = QuestionBankStatus.PUBLISHED; bank.status = QuestionBankStatus.PUBLISHED;
@@ -424,7 +424,6 @@ export class QuestionBankService {
} }
} }
} }
}
if (selected.length < count) { if (selected.length < count) {
const remaining = allItems.filter((i) => !usedIds.has(i.id)); const remaining = allItems.filter((i) => !usedIds.has(i.id));