119 lines
3.3 KiB
TypeScript
119 lines
3.3 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Body,
|
|
Patch,
|
|
Param,
|
|
Query,
|
|
UseGuards,
|
|
Request,
|
|
ParseIntPipe,
|
|
} from '@nestjs/common';
|
|
import { ReviewsService } from './reviews.service';
|
|
import { AssignWorkDto } from './dto/assign-work.dto';
|
|
import { CreateScoreDto } from './dto/create-score.dto';
|
|
import { BatchAssignDto } from './dto/batch-assign.dto';
|
|
import { JwtAuthGuard } from '../../auth/guards/jwt-auth.guard';
|
|
import { RequirePermission } from '../../auth/decorators/require-permission.decorator';
|
|
|
|
@Controller('contests/reviews')
|
|
@UseGuards(JwtAuthGuard)
|
|
export class ReviewsController {
|
|
constructor(private readonly reviewsService: ReviewsService) {}
|
|
|
|
@Post('assign')
|
|
@RequirePermission('review:assign')
|
|
assignWork(
|
|
@Body() assignWorkDto: AssignWorkDto,
|
|
@Query('contestId', ParseIntPipe) contestId: number,
|
|
@Request() req,
|
|
) {
|
|
const creatorId = req.user?.id;
|
|
return this.reviewsService.assignWork(assignWorkDto, contestId, creatorId);
|
|
}
|
|
|
|
@Post('batch-assign')
|
|
@RequirePermission('review:assign')
|
|
batchAssignWorks(
|
|
@Body() batchAssignDto: BatchAssignDto,
|
|
@Query('contestId', ParseIntPipe) contestId: number,
|
|
@Request() req,
|
|
) {
|
|
const creatorId = req.user?.id;
|
|
return this.reviewsService.batchAssignWorks(
|
|
contestId,
|
|
batchAssignDto.workIds,
|
|
batchAssignDto.judgeIds,
|
|
creatorId,
|
|
);
|
|
}
|
|
|
|
@Post('auto-assign')
|
|
@RequirePermission('review:assign')
|
|
autoAssignWorks(
|
|
@Query('contestId', ParseIntPipe) contestId: number,
|
|
@Request() req,
|
|
) {
|
|
const creatorId = req.user?.id;
|
|
return this.reviewsService.autoAssignWorks(contestId, creatorId);
|
|
}
|
|
|
|
@Post('score')
|
|
@RequirePermission('review:score')
|
|
score(@Body() createScoreDto: CreateScoreDto, @Request() req) {
|
|
const tenantId = req.tenantId || req.user?.tenantId;
|
|
if (!tenantId) {
|
|
throw new Error('无法确定租户信息');
|
|
}
|
|
const judgeId = req.user?.id;
|
|
return this.reviewsService.score(createScoreDto, judgeId, tenantId);
|
|
}
|
|
|
|
@Patch('score/:id')
|
|
@RequirePermission('review:score')
|
|
updateScore(
|
|
@Param('id', ParseIntPipe) scoreId: number,
|
|
@Body() updateScoreDto: Partial<CreateScoreDto>,
|
|
@Request() req,
|
|
) {
|
|
const judgeId = req.user?.id;
|
|
return this.reviewsService.updateScore(scoreId, updateScoreDto, judgeId);
|
|
}
|
|
|
|
@Get('assigned')
|
|
@RequirePermission('review:read')
|
|
getAssignedWorks(
|
|
@Query('contestId', ParseIntPipe) contestId: number,
|
|
@Request() req,
|
|
) {
|
|
const judgeId = req.user?.id;
|
|
return this.reviewsService.getAssignedWorks(judgeId, contestId);
|
|
}
|
|
|
|
@Get('progress/:contestId')
|
|
@RequirePermission('review:read')
|
|
getReviewProgress(@Param('contestId', ParseIntPipe) contestId: number) {
|
|
return this.reviewsService.getReviewProgress(contestId);
|
|
}
|
|
|
|
@Get('work-status/:contestId')
|
|
@RequirePermission('review:read')
|
|
getWorkStatusStats(@Param('contestId', ParseIntPipe) contestId: number) {
|
|
return this.reviewsService.getWorkStatusStats(contestId);
|
|
}
|
|
|
|
@Get('work/:workId/scores')
|
|
@RequirePermission('review:read')
|
|
getWorkScores(@Param('workId', ParseIntPipe) workId: number) {
|
|
return this.reviewsService.getWorkScores(workId);
|
|
}
|
|
|
|
@Get('work/:workId/final-score')
|
|
@RequirePermission('review:read')
|
|
calculateFinalScore(@Param('workId', ParseIntPipe) workId: number) {
|
|
return this.reviewsService.calculateFinalScore(workId);
|
|
}
|
|
}
|
|
|