-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathupdateCodeRoute.ts
More file actions
26 lines (23 loc) · 1.18 KB
/
updateCodeRoute.ts
File metadata and controls
26 lines (23 loc) · 1.18 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
26
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 updateCodeRoute(fastify: AppFastifyInstance): Promise<void> {
const codeTaskService = new CodeTaskServiceImpl(fastify.codeTaskRepository);
registerApiRoute(fastify, CODE_TASK_API.updateCode, async (request, reply) => {
const userId = currentUser().id;
const { codeTaskId } = request.params;
const data = request.body;
try {
await codeTaskService.updateCodeWithComments(userId, codeTaskId, data);
return reply.sendJSON({});
} catch (error: any) {
logger.error(error, `Error triggering code update for codeTask ${codeTaskId}, user ${userId}`);
if (error.message?.includes('not found')) return sendNotFound(reply, `Code task with ID ${codeTaskId} not found`);
return sendServerError(reply, error.message || 'Failed to trigger code update');
}
});
}