Skip to content

Commit

Permalink
get tasks belong to the current user
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaalanMarwan committed May 1, 2022
1 parent 810bff8 commit 927a557
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/tasks/task.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import { Task } from './task.entity';

@EntityRepository(Task)
export class TaskRepository extends Repository<Task> {
async getTasks(filterDto: GetTasksDto): Promise<Task[]> {
async getTasks(filterDto: GetTasksDto, user: User): Promise<Task[]> {
const { q, status } = filterDto;
const query = this.createQueryBuilder('task');
query.where({ user });
if (status) {
query.andWhere('task.status = :status', { status });
}
Expand Down
7 changes: 5 additions & 2 deletions src/tasks/tasks.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ export class TasksController {
return this.tasksService.createTask(createTaskDto, user);
}
@Get()
getTasks(@Query() filterDto: GetTasksDto): Promise<Task[]> {
return this.tasksService.getTasks(filterDto);
getTasks(
@Query() filterDto: GetTasksDto,
@GetUser() user: User,
): Promise<Task[]> {
return this.tasksService.getTasks(filterDto, user);
}
@Get(':id')
getTaskById(@Param('id') id: string): Promise<Task> {
Expand Down
4 changes: 2 additions & 2 deletions src/tasks/tasks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export class TasksService {
private taskRepository: TaskRepository,
) {}

async getTasks(filterDto: GetTasksDto): Promise<Task[]> {
return this.taskRepository.getTasks(filterDto);
async getTasks(filterDto: GetTasksDto, user: User): Promise<Task[]> {
return this.taskRepository.getTasks(filterDto, user);
}

async getTaskById(id: string): Promise<Task> {
Expand Down

0 comments on commit 927a557

Please sign in to comment.