Skip to content

Commit

Permalink
#2770-added get user tasks endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
caiodasilva2005 committed Sep 12, 2024
1 parent 81a5e9c commit 5c10c8f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/backend/src/controllers/users.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,16 @@ export default class UsersController {
return next(error);
}
}

static async getUserTasks(req: Request, res: Response, next: NextFunction) {
try {
const { userId } = req.params;
const { organization } = req;

const userTasks = await UsersService.getUserTasks(userId, organization);
return res.status(200).json(userTasks);
} catch (error: unknown) {
return next(error);
}
}
}
1 change: 1 addition & 0 deletions src/backend/src/routes/users.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ userRouter.post(

userRouter.get('/:userId/secure-settings', UsersController.getUserSecureSettings);
userRouter.get('/:userId/schedule-settings', UsersController.getUserScheduleSettings);
userRouter.get('/:userId/tasks', UsersController.getUserTasks);

export default userRouter;
23 changes: 23 additions & 0 deletions src/backend/src/services/users.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
} from '../prisma-query-args/user.query-args';
import { getAuthUserQueryArgs } from '../prisma-query-args/auth-user.query-args';
import authenticatedUserTransformer from '../transformers/auth-user.transformer';
import { getTaskQueryArgs } from '../prisma-query-args/tasks.query-args';

export default class UsersService {
/**
Expand Down Expand Up @@ -538,4 +539,26 @@ export default class UsersService {

return userScheduleSettingsTransformer(newUserScheduleSettings);
}

static async getUserTasks(userId: string, organization: Organization) {
const requestedUser = await prisma.user.findUnique({ where: { userId } });
if (!requestedUser) throw new NotFoundException('User', userId);

const tasks = prisma.task.findMany({
where: {
assignees: {
some: {
userId
}
},
wbsElement: {
organizationId: organization.organizationId
}
},
...getTaskQueryArgs(organization.organizationId)
});

if (!tasks) throw new HttpException(404, 'User tasks Not Found');
return tasks;
}
}

0 comments on commit 5c10c8f

Please sign in to comment.