refactor(server): 清理无用导入与类型转换

- 移除测试/控制器中未使用的导入与实例
- bills/classroom-rentals 改用 ESM 导入替代 require
- bills.service 去掉多余断言、backfill 显式转字符串、main.ts void bootstrap
This commit is contained in:
2026-08-05 21:14:17 +08:00
parent 1a1e90c72f
commit d1c933f032
8 changed files with 8 additions and 33 deletions

View File

@@ -24,7 +24,7 @@ import type { AuthenticatedUser } from '../authorization';
import { AiAttachmentService } from './ai-attachment.service';
import { AiChatService } from './ai-chat.service';
import type { AiSseEventName } from './ai-chat.types';
import type { AiReviewSection, AiReviewSectionType } from './entities';
import type { AiReviewSectionType } from './entities';
import {
CreateConversationDto,
EditMessageDto,
@@ -248,7 +248,7 @@ export class AiChatController {
data: await this.service.confirmReviewStep(
req.user,
reviewId,
sectionKey as AiReviewSection['key'],
sectionKey,
),
};
}

View File

@@ -1,15 +1,4 @@
import { BadRequestException, NotFoundException } from '@nestjs/common';
import { DataSource } from 'typeorm';
import * as allEntities from '../entities';
import { Bed } from '../entities/bed.entity';
import { Occupancy } from '../entities/occupancy.entity';
import { Organization } from '../entities/organization.entity';
import { Room } from '../entities/room.entity';
import { Student } from '../entities/student.entity';
import { AiConversation } from './entities/ai-conversation.entity';
import { AiMessage } from './entities/ai-message.entity';
import { AiReview } from './entities/ai-review.entity';
import { User } from '../entities/user.entity';
import { AiReviewService } from './ai-review.service';
import type { ExcelSheetRows } from './ai-excel-reader.service';
@@ -636,4 +625,3 @@ describe('AiReviewService', () => {
});
});
});

View File

@@ -23,24 +23,10 @@ describe('AttendanceRecordsController — DingTalk import scope', () => {
can: jest.fn().mockReturnValue(false),
};
let controller: AttendanceController;
let recordsController: AttendanceRecordsController;
let importController: AttendanceImportController;
beforeEach(() => {
jest.clearAllMocks();
controller = new AttendanceController(
attendanceService as unknown as AttendanceService,
importService as unknown as AttendanceImportService,
logService as unknown as OperationLogsService,
authzService as never,
);
recordsController = new AttendanceRecordsController(
attendanceService as unknown as AttendanceService,
importService as unknown as AttendanceImportService,
logService as unknown as OperationLogsService,
authzService as never,
);
importController = new AttendanceImportController(
attendanceService as unknown as AttendanceService,
importService as unknown as AttendanceImportService,

View File

@@ -7,6 +7,7 @@ import { Deposit } from '../entities/deposit.entity';
import * as ExcelJS from 'exceljs';
import * as PDFDocument from 'pdfkit';
import { Response } from 'express';
import fs from 'fs';
@Injectable()
export class BillsExportService {
@@ -149,7 +150,6 @@ export class BillsExportService {
'/usr/share/fonts/truetype/wqy/wqy-microhei.ttc',
];
let fontRegistered = false;
const fs = require('fs');
for (const fp of fontPaths) {
try {
if (fs.existsSync(fp)) {

View File

@@ -45,7 +45,7 @@ export class BillsService {
*/
async generateBills(dto: GenerateBillsDto) {
const { operationId, ...request } = dto;
const work = () => this.generation.generateBillsOnce(request as GenerateBillsDto);
const work = () => this.generation.generateBillsOnce(request);
return this.financialOperations
? this.financialOperations.run(operationId, 'bill.generate', work)
: work();

View File

@@ -17,6 +17,7 @@ import { RentalScheduleService } from './rental-schedule.service';
import * as path from 'path';
import * as fs from 'fs';
import { randomBytes } from 'crypto';
// 预设色板(与 organizations.service 保持一致,作为颜色兜底)
function rentalConflictError(
@@ -347,7 +348,7 @@ export class ClassroomRentalsService {
const ext = path.extname(file.originalname).toLowerCase();
if (ext !== '.pdf') throw new BadRequestException('文件扩展名必须为 .pdf');
// UUID 文件名
const uuid = require('crypto').randomBytes(16).toString('hex');
const uuid = randomBytes(16).toString('hex');
const filename = `${uuid}.pdf`;
const fullPath = path.join(this.uploadDir, filename);
// 路径遍历防护

View File

@@ -53,7 +53,7 @@ export async function backfillOrganizations(
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)`,
[
uuidV7(),
`ORG_${legacy.id}`,
`ORG_${String(legacy.id)}`,
name,
0,
legacy.contact || null,

View File

@@ -15,4 +15,4 @@ async function bootstrap() {
await app.listen(process.env.PORT ?? 3000);
}
bootstrap();
void bootstrap();