feat: 完善后台导入日志权限与备份恢复
This commit is contained in:
@@ -2,6 +2,7 @@ import { Controller, Get, Param, Query } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { JobsService } from './jobs.service';
|
||||
import { QueryJobDto } from './dto/query-job.dto';
|
||||
import { CurrentUser, AuthUser } from '../common/decorators/current-user.decorator';
|
||||
|
||||
@ApiTags('异步任务')
|
||||
@ApiBearerAuth()
|
||||
@@ -11,13 +12,13 @@ export class JobsController {
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: '任务列表' })
|
||||
list(@Query() query: QueryJobDto) {
|
||||
return this.jobsService.list(query);
|
||||
list(@Query() query: QueryJobDto, @CurrentUser() user: AuthUser) {
|
||||
return this.jobsService.list(query, user);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: '任务进度详情' })
|
||||
get(@Param('id') id: string) {
|
||||
return this.jobsService.get(id);
|
||||
get(@Param('id') id: string, @CurrentUser() user: AuthUser) {
|
||||
return this.jobsService.get(id, user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { ErrorCode, JobStatus, JobType } from '@artveris/shared';
|
||||
import { ErrorCode, JobStatus, JobType, RoleType } from '@artveris/shared';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { BusinessException } from '../common/exceptions/business.exception';
|
||||
import { buildPage } from '../common/utils/pagination.util';
|
||||
import { AuthUser } from '../common/decorators/current-user.decorator';
|
||||
import { QueryJobDto } from './dto/query-job.dto';
|
||||
|
||||
@Injectable()
|
||||
@@ -37,18 +38,20 @@ export class JobsService {
|
||||
return this.prisma.job.update({ where: { id }, data });
|
||||
}
|
||||
|
||||
async get(id: string) {
|
||||
async get(id: string, user?: AuthUser) {
|
||||
const job = await this.prisma.job.findUnique({ where: { id } });
|
||||
if (!job) {
|
||||
throw new BusinessException(ErrorCode.JOB_NOT_FOUND, '任务不存在', 404);
|
||||
if (!job) throw new BusinessException(ErrorCode.JOB_NOT_FOUND, '任务不存在', 404);
|
||||
if (user && user.role !== RoleType.SUPER_ADMIN && job.createdBy !== user.id) {
|
||||
throw new BusinessException(ErrorCode.FORBIDDEN, '没有访问该任务的权限', 403);
|
||||
}
|
||||
return job;
|
||||
}
|
||||
|
||||
async list(query: QueryJobDto) {
|
||||
async list(query: QueryJobDto, user?: AuthUser) {
|
||||
const where: Prisma.JobWhereInput = {};
|
||||
if (query.type) where.type = query.type;
|
||||
if (query.status) where.status = query.status;
|
||||
if (user && user.role !== RoleType.SUPER_ADMIN) where.createdBy = user.id;
|
||||
const [list, total] = await this.prisma.$transaction([
|
||||
this.prisma.job.findMany({
|
||||
where,
|
||||
|
||||
Reference in New Issue
Block a user