-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathresetSelectionRoute.ts
More file actions
31 lines (29 loc) · 1.33 KB
/
resetSelectionRoute.ts
File metadata and controls
31 lines (29 loc) · 1.33 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
27
28
29
30
31
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 resetSelectionRoute(fastify: AppFastifyInstance): Promise<void> {
const codeTaskService = new CodeTaskServiceImpl(fastify.codeTaskRepository);
registerApiRoute(fastify, CODE_TASK_API.resetSelection, async (request, reply) => {
const userId = currentUser().id;
const { codeTaskId } = request.params;
try {
await codeTaskService.resetFileSelection(userId, codeTaskId);
return reply.sendJSON({ message: 'File selection reset accepted.' });
} catch (error: any) {
logger.error(error, `Error resetting file selection for codeTask ${codeTaskId}, user ${userId}`);
if (error.message?.includes('not found')) {
return sendNotFound(reply, error.message);
}
// if (error.message?.includes('state')) {
// // HTTP 409 Conflict for state issues
// reply.code(409);
// return reply.send({ error: error.message });
// }
return sendServerError(reply, 'Failed to reset file selection');
}
});
}