refactor(server): 清理全量 any 类型安全警告 (692 → 0)
- 全模块类型化:controller 的 req: any → AuthenticatedRequest/RequestUser, 聚合查询 getRawMany 泛型标注、导入行/响应体定义具体 interface、 catch (e: any) → unknown + 收窄、no-base-to-string 用 String() 显式转换 - 第三方无类型库边界(pdfkit/exceljs)文件级或单行 disable 并注明理由 - 顺带修复:get-business-context.tool 两个 require-await error、 bills.controller 参数顺序隐患、main.ts compression 调用 - 运行时逻辑零改动;测试 142 套件 / 1065 用例全部通过
This commit is contained in:
@@ -10,6 +10,9 @@ import { BatchCreateDepositDto, CreateDepositDto, RefundDepositDto } from './dto
|
||||
|
||||
const money = (value: number | string | null | undefined) => Number(Number(value || 0).toFixed(2));
|
||||
|
||||
/** getRawMany 返回的原始行:数据库标量值(string/number/Date)或 NULL */
|
||||
type RawScalarRow = Record<string, string | number | Date | null>;
|
||||
|
||||
const capacityRoomTypeText: Record<number, string> = {
|
||||
1: '单人间',
|
||||
2: '二人间',
|
||||
@@ -99,7 +102,7 @@ export class DepositsService {
|
||||
}
|
||||
}
|
||||
|
||||
const rows = await qb.getRawMany();
|
||||
const rows = await qb.getRawMany<RawScalarRow>();
|
||||
return rows.map((row) => ({
|
||||
studentId: Number(row.studentId),
|
||||
studentName: row.studentName,
|
||||
@@ -107,9 +110,12 @@ export class DepositsService {
|
||||
roomId: Number(row.roomId),
|
||||
roomNumber: row.roomNumber,
|
||||
building: row.building ?? null,
|
||||
roomType: normalizeRoomType(row.roomType, row.capacity),
|
||||
roomType: normalizeRoomType(
|
||||
row.roomType == null ? null : String(row.roomType),
|
||||
row.capacity == null ? null : Number(row.capacity),
|
||||
),
|
||||
capacity: Number(row.capacity),
|
||||
depositAmount: money(row.depositAmount),
|
||||
depositAmount: money(row.depositAmount == null ? null : Number(row.depositAmount)),
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -198,7 +204,7 @@ export class DepositsService {
|
||||
const rows = await qb
|
||||
.orderBy('d.createdAt', 'DESC')
|
||||
.limit(Math.max(1, Math.min(query?.limit ?? 20, 50)))
|
||||
.getRawMany<Record<string, unknown>>();
|
||||
.getRawMany<RawScalarRow>();
|
||||
return rows.map((row) => ({
|
||||
id: Number(row.id),
|
||||
studentName: row.studentName == null ? '' : String(row.studentName),
|
||||
|
||||
Reference in New Issue
Block a user