fix: 优化后台体验与导出日志交互
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsInt, IsOptional, IsString } from 'class-validator';
|
||||
import { IsEnum, IsInt, IsOptional, IsString } from 'class-validator';
|
||||
import { RoleType } from '@artveris/shared';
|
||||
import { PaginationDto } from '../../common/dto/pagination.dto';
|
||||
|
||||
export class QueryOperationLogDto extends PaginationDto {
|
||||
@@ -10,6 +11,11 @@ export class QueryOperationLogDto extends PaginationDto {
|
||||
@IsInt()
|
||||
userId?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: '角色', enum: RoleType })
|
||||
@IsOptional()
|
||||
@IsEnum(RoleType)
|
||||
role?: RoleType;
|
||||
|
||||
@ApiPropertyOptional({ description: '模块' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Prisma } from '@prisma/client';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { buildPage } from '../common/utils/pagination.util';
|
||||
import { QueryOperationLogDto } from './dto/query-operation-log.dto';
|
||||
import { buildOrderBy } from '../common/utils/sort.util';
|
||||
|
||||
export interface OperationLogInput {
|
||||
userId?: number | null;
|
||||
@@ -49,6 +50,7 @@ export class OperationLogService {
|
||||
async list(query: QueryOperationLogDto) {
|
||||
const where: Prisma.OperationLogWhereInput = {};
|
||||
if (query.userId) where.userId = query.userId;
|
||||
if (query.role) where.role = query.role as any;
|
||||
if (query.module) where.module = query.module;
|
||||
if (query.action) where.action = query.action;
|
||||
if (query.status) where.status = query.status;
|
||||
@@ -65,10 +67,11 @@ export class OperationLogService {
|
||||
if (query.startTime) where.createdAt.gte = new Date(query.startTime);
|
||||
if (query.endTime) where.createdAt.lte = new Date(query.endTime);
|
||||
}
|
||||
const orderBy = buildOrderBy(query.sortField, query.sortOrder, ['createdAt'] as const, { id: 'desc' });
|
||||
const [list, total] = await this.prisma.$transaction([
|
||||
this.prisma.operationLog.findMany({
|
||||
where,
|
||||
orderBy: { id: 'desc' },
|
||||
orderBy,
|
||||
skip: query.skip,
|
||||
take: query.take,
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user