Skip to content

Instantly share code, notes, and snippets.

@paulodutra
Created August 12, 2024 01:57
Show Gist options
  • Save paulodutra/e9593a9e5a53dd65b255d6b7112cd051 to your computer and use it in GitHub Desktop.
Save paulodutra/e9593a9e5a53dd65b255d6b7112cd051 to your computer and use it in GitHub Desktop.
The method of controller that filter the tasks.
import { Controller, Get, Query, Req, Res, HttpStatus } from '@nestjs/common';
import type { Request, Response } from 'express';
import { TaskService } from '@/modules/task/task.service';
@Controller('tasks')
export class TaskController {
constructor(private readonly taskService: TaskService) {}
@Get()
async searchTaskByState(
@Query('done') done: string,
@Req() _req: Request,
@Res() res: Response,
): Promise<void> {
const doneParam = done !== undefined ? Number(done) : 1;
const data = await this.taskService.execute(doneParam);
if (data) {
res.status(HttpStatus.OK).json(data);
} else {
res.status(HttpStatus.NOT_FOUND).json({
message: 'No tasks found with this state',
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment