-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathgetCodeTaskByIdRoute.ts
More file actions
25 lines (22 loc) · 1.11 KB
/
getCodeTaskByIdRoute.ts
File metadata and controls
25 lines (22 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import type { AppFastifyInstance } from '#app/applicationTypes';
import { CodeTaskServiceImpl } from '#codeTask/codeTaskServiceImpl';
import { sendNotFound, sendServerError } from '#fastify/responses';
import { logger } from '#o11y/logger';
import { CODE_TASK_API } from '#shared/codeTask/codeTask.api';
import { currentUser } from '#user/userContext';
import { registerApiRoute } from '../routeUtils';
export async function getCodeTaskByIdRoute(fastify: AppFastifyInstance): Promise<void> {
const codeTaskService = new CodeTaskServiceImpl(fastify.codeTaskRepository);
registerApiRoute(fastify, CODE_TASK_API.getById, async (request, reply) => {
const userId = currentUser().id;
const { codeTaskId } = request.params;
try {
const codeTask = await codeTaskService.getCodeTask(userId, codeTaskId);
if (!codeTask) return sendNotFound(reply, `Code task with ID ${codeTaskId} not found`);
return reply.sendJSON(codeTask);
} catch (error: any) {
logger.error(error, `Error getting Code task ${codeTaskId} for user ${userId}`);
return sendServerError(reply, error.message || 'Failed to retrieve Code task');
}
});
}