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:
@@ -1,10 +1,21 @@
|
||||
import { Injectable, BadRequestException } from '@nestjs/common';
|
||||
import { DataSource, IsNull } from 'typeorm';
|
||||
import { DataSource, IsNull, DeepPartial } from 'typeorm';
|
||||
import { Occupancy, Room, Student, Deposit, Bed, Locker, Organization } from '../entities';
|
||||
import { RoomsService } from '../rooms/rooms.service';
|
||||
|
||||
class ImportRowSkipped extends Error {}
|
||||
|
||||
type StudentUpdateFields = Pick<
|
||||
Student,
|
||||
| 'studentNo'
|
||||
| 'idNumber'
|
||||
| 'gender'
|
||||
| 'ethnicity'
|
||||
| 'emergencyContact'
|
||||
| 'emergencyPhone'
|
||||
| 'supervisor'
|
||||
>;
|
||||
|
||||
@Injectable()
|
||||
export class OccupancyImportService {
|
||||
constructor(private dataSource: DataSource) {}
|
||||
@@ -87,7 +98,7 @@ export class OccupancyImportService {
|
||||
);
|
||||
} else {
|
||||
// 更新已有学生的缺失信息
|
||||
const updates: any = {};
|
||||
const updates: Partial<StudentUpdateFields> = {};
|
||||
if (!student.studentNo && row.studentNo?.trim())
|
||||
updates.studentNo = row.studentNo.trim();
|
||||
if (!student.idNumber && row.idNumber?.trim()) updates.idNumber = row.idNumber.trim();
|
||||
@@ -191,7 +202,7 @@ export class OccupancyImportService {
|
||||
}
|
||||
|
||||
// 6. 创建入住记录
|
||||
const occData: any = {
|
||||
const occData: DeepPartial<Occupancy> = {
|
||||
studentId: student.id,
|
||||
roomId: room.id,
|
||||
checkInDate,
|
||||
@@ -258,11 +269,11 @@ export class OccupancyImportService {
|
||||
|
||||
imported++;
|
||||
depositsCreated += result.depositsCreated;
|
||||
} catch (e: any) {
|
||||
} catch (e: unknown) {
|
||||
errors.push(
|
||||
e instanceof ImportRowSkipped
|
||||
? e.message
|
||||
: `第${rowNum}行: ${row.name} 导入失败 - ${e.message}`,
|
||||
: `第${rowNum}行: ${row.name} 导入失败 - ${e instanceof Error ? e.message : String(e)}`,
|
||||
);
|
||||
skipped++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user