Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2770-getUserTasks #2833

Merged
merged 19 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add jsdoc for this

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

const tasks = prisma.task.findMany({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can find the user then get assigned tasks from there. Though this might be trivial in reality and if this works then we can keep it as is. What are your thoughts?

where: {
assignees: {
some: {
userId
}
},
wbsElement: {
organizationId: organization.organizationId
}
},
...getTaskQueryArgs(organization.organizationId)
});

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