| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- import { Body, Controller, Delete, Get, Param, Post, Put, Req } from '@nestjs/common'
- import { PageRequest } from 'src/common/dto/page-request'
- import { Task } from './entities/task.entity'
- import { TaskService } from './task.service'
- import { TaskItem } from './entities/task-item.entity'
- import { UsersService } from '../users/users.service'
- import { In } from 'typeorm'
- @Controller('task')
- export class TaskController {
- constructor(
- private readonly taskService: TaskService,
- private readonly userService: UsersService
- ) {
- }
- @Post('/')
- async findAllTask(@Req() req, @Body() page: PageRequest<Task>) {
- if (req.user.roles.includes('api') || req.user.roles.includes('superApi')) {
- const userIds = await this.userService.getInvitesIds(req.user.id)
- ;(page.search as any).where.userId = In(userIds)
- } else if (!req.user.roles.includes('admin')) {
- ;(page.search as any).where.userId = (req.user.id)
- }
- if ((page.search as any).where.status === 'run') {
- (page.search as any).where.status = In(['pending', 'queued', 'cutting'])
- }
- return await this.taskService.findAllTask(page)
- }
- @Put('/')
- async createTask(@Req() req, @Body() body) {
- body.userId = req.user.id
- return await this.taskService.createTask(body)
- }
- @Put('/:id')
- async updateTask(@Param('id') id: string, @Req() req, @Body() body) {
- return await this.taskService.updateTask(parseInt(id), req.user, body)
- }
- @Get('/verification/:id')
- async balanceVerification(@Param('id') id: string) {
- return await this.taskService.balanceVerification(parseInt(id))
- }
- @Delete('/:id')
- async delTask(@Param('id') id: string) {
- return await this.taskService.delTask(parseInt(id))
- }
- @Post('/:id/start')
- async startTask(@Param('id') id: string) {
- return await this.taskService.startTask(parseInt(id))
- }
- @Post('/:id/queueCutting')
- async queueCutting(@Param('id') id: string) {
- return await this.taskService.queueCutting(parseInt(id))
- }
- @Post('/:id/pause')
- async pauseTask(@Param('id') id: string) {
- return await this.taskService.pauseTask(parseInt(id))
- }
- @Get('/:id/forceCompletion')
- async forceCompletion(@Param('id') id: string) {
- return await this.taskService.forceCompletion(parseInt(id))
- }
- @Post('/item')
- async findAllTaskItem(@Body() page: PageRequest<TaskItem>) {
- (page.search as any).where.embed = false
- return await this.taskService.findAllTaskItem(page)
- }
- @Post('/item/:taskId/receipt')
- async exportTaskItem(@Param('taskId') taskId: number) {
- try {
- return await this.taskService.exportTaskItem(taskId)
- } catch (error) {
- console.error(error)
- }
- }
- @Get('/toBeSentNum/:taskId')
- async getTobeSentNum(@Param('taskId') taskId: number) {
- return await this.taskService.getToBeSentNum(taskId)
- }
- @Get('/num/:taskId')
- async getSuccessNum(@Param('taskId') taskId: number) {
- return await this.taskService.getSuccessNum(taskId)
- }
- @Post('/export')
- async exportTask(@Req() req, @Body() data) {
- return await this.taskService.exportTask(req, data)
- }
- @Get('/statistics')
- async homeStatistics(@Req() req) {
- return await this.taskService.homeStatistics(req)
- }
- @Get('/adminStatistics')
- async adminStatistics(@Req() req) {
- return await this.taskService.adminStatistics()
- }
- }
|