chore: commit oxfmt formatting changes and verify artifacts
This commit is contained in:
@@ -1,4 +1,19 @@
|
||||
import { Controller, Get, Post, Put, Delete, Body, Param, Query, UseGuards, Request, Res, UseInterceptors, UploadedFile, BadRequestException } from '@nestjs/common';
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Body,
|
||||
Param,
|
||||
Query,
|
||||
UseGuards,
|
||||
Request,
|
||||
Res,
|
||||
UseInterceptors,
|
||||
UploadedFile,
|
||||
BadRequestException,
|
||||
} from '@nestjs/common';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
import type { Response } from 'express';
|
||||
import * as fs from 'fs';
|
||||
@@ -12,7 +27,10 @@ import { RequirePermission } from '../auth/decorators/permission.decorator';
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('classroom-rentals')
|
||||
export class ClassroomRentalsController {
|
||||
constructor(private service: ClassroomRentalsService, private logService: OperationLogsService) {}
|
||||
constructor(
|
||||
private service: ClassroomRentalsService,
|
||||
private logService: OperationLogsService,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
@RequirePermission('rental:view')
|
||||
@@ -52,10 +70,15 @@ export class ClassroomRentalsController {
|
||||
const { ipAddress, userAgent } = extractRequestInfo(req);
|
||||
const result = await this.service.create(dto, req.user?.id);
|
||||
await this.logService.log({
|
||||
userId: req.user?.id, username: req.user?.username,
|
||||
module: '教室租赁', action: '新增租赁', targetId: result.id, targetType: 'classroom-rental',
|
||||
userId: req.user?.id,
|
||||
username: req.user?.username,
|
||||
module: '教室租赁',
|
||||
action: '新增租赁',
|
||||
targetId: result.id,
|
||||
targetType: 'classroom-rental',
|
||||
detail: `教室${dto.classroomId} 租赁方${dto.tenantId} ${dto.startDate}~${dto.endDate}`,
|
||||
ipAddress, userAgent,
|
||||
ipAddress,
|
||||
userAgent,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
@@ -66,9 +89,15 @@ export class ClassroomRentalsController {
|
||||
const { ipAddress, userAgent } = extractRequestInfo(req);
|
||||
const result = await this.service.update(+id, dto);
|
||||
await this.logService.log({
|
||||
userId: req.user?.id, username: req.user?.username,
|
||||
module: '教室租赁', action: '编辑租赁', targetId: +id, targetType: 'classroom-rental',
|
||||
detail: JSON.stringify(dto), ipAddress, userAgent,
|
||||
userId: req.user?.id,
|
||||
username: req.user?.username,
|
||||
module: '教室租赁',
|
||||
action: '编辑租赁',
|
||||
targetId: +id,
|
||||
targetType: 'classroom-rental',
|
||||
detail: JSON.stringify(dto),
|
||||
ipAddress,
|
||||
userAgent,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
@@ -79,9 +108,14 @@ export class ClassroomRentalsController {
|
||||
const { ipAddress, userAgent } = extractRequestInfo(req);
|
||||
const result = await this.service.remove(+id);
|
||||
await this.logService.log({
|
||||
userId: req.user?.id, username: req.user?.username,
|
||||
module: '教室租赁', action: '删除租赁', targetId: +id, targetType: 'classroom-rental',
|
||||
ipAddress, userAgent,
|
||||
userId: req.user?.id,
|
||||
username: req.user?.username,
|
||||
module: '教室租赁',
|
||||
action: '删除租赁',
|
||||
targetId: +id,
|
||||
targetType: 'classroom-rental',
|
||||
ipAddress,
|
||||
userAgent,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
@@ -89,23 +123,35 @@ export class ClassroomRentalsController {
|
||||
// 合同上传:multer 限制 10MB + 仅 PDF
|
||||
@Post(':id/contract')
|
||||
@RequirePermission('rental:edit')
|
||||
@UseInterceptors(FileInterceptor('file', {
|
||||
limits: { fileSize: 10 * 1024 * 1024 },
|
||||
fileFilter: (_req, file, cb) => {
|
||||
if (file.mimetype !== 'application/pdf') {
|
||||
return cb(new BadRequestException('仅支持 PDF 文件'), false);
|
||||
}
|
||||
cb(null, true);
|
||||
},
|
||||
}))
|
||||
async uploadContract(@Param('id') id: string, @UploadedFile() file: Express.Multer.File, @Request() req: any) {
|
||||
@UseInterceptors(
|
||||
FileInterceptor('file', {
|
||||
limits: { fileSize: 10 * 1024 * 1024 },
|
||||
fileFilter: (_req, file, cb) => {
|
||||
if (file.mimetype !== 'application/pdf') {
|
||||
return cb(new BadRequestException('仅支持 PDF 文件'), false);
|
||||
}
|
||||
cb(null, true);
|
||||
},
|
||||
}),
|
||||
)
|
||||
async uploadContract(
|
||||
@Param('id') id: string,
|
||||
@UploadedFile() file: Express.Multer.File,
|
||||
@Request() req: any,
|
||||
) {
|
||||
if (!file) throw new BadRequestException('请上传合同文件');
|
||||
const { ipAddress, userAgent } = extractRequestInfo(req);
|
||||
const result = await this.service.attachContract(+id, file);
|
||||
await this.logService.log({
|
||||
userId: req.user?.id, username: req.user?.username,
|
||||
module: '教室租赁', action: '上传合同', targetId: +id, targetType: 'classroom-rental',
|
||||
detail: file.originalname, ipAddress, userAgent,
|
||||
userId: req.user?.id,
|
||||
username: req.user?.username,
|
||||
module: '教室租赁',
|
||||
action: '上传合同',
|
||||
targetId: +id,
|
||||
targetType: 'classroom-rental',
|
||||
detail: file.originalname,
|
||||
ipAddress,
|
||||
userAgent,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
@@ -115,7 +161,10 @@ export class ClassroomRentalsController {
|
||||
async downloadContract(@Param('id') id: string, @Res() res: Response) {
|
||||
const { fullPath, originalName } = await this.service.getContractPath(+id);
|
||||
res.setHeader('Content-Type', 'application/pdf');
|
||||
res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(originalName)}"`);
|
||||
res.setHeader(
|
||||
'Content-Disposition',
|
||||
`attachment; filename="${encodeURIComponent(originalName)}"`,
|
||||
);
|
||||
const stream = fs.createReadStream(fullPath);
|
||||
stream.pipe(res);
|
||||
}
|
||||
@@ -126,9 +175,14 @@ export class ClassroomRentalsController {
|
||||
const { ipAddress, userAgent } = extractRequestInfo(req);
|
||||
const result = await this.service.removeContract(+id);
|
||||
await this.logService.log({
|
||||
userId: req.user?.id, username: req.user?.username,
|
||||
module: '教室租赁', action: '删除合同', targetId: +id, targetType: 'classroom-rental',
|
||||
ipAddress, userAgent,
|
||||
userId: req.user?.id,
|
||||
username: req.user?.username,
|
||||
module: '教室租赁',
|
||||
action: '删除合同',
|
||||
targetId: +id,
|
||||
targetType: 'classroom-rental',
|
||||
ipAddress,
|
||||
userAgent,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user