-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathexecuteDesignRoute.ts
More file actions
26 lines (24 loc) · 1.22 KB
/
executeDesignRoute.ts
File metadata and controls
26 lines (24 loc) · 1.22 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 executeDesignRoute(fastify: AppFastifyInstance): Promise<void> {
const codeTaskService = new CodeTaskServiceImpl(fastify.codeTaskRepository);
registerApiRoute(fastify, CODE_TASK_API.executeDesign, async (request, reply) => {
const userId = currentUser().id;
const { codeTaskId } = request.params;
try {
await codeTaskService.executeDesign(userId, codeTaskId);
return reply.sendJSON({ message: 'Design execution accepted and processing started.' });
} catch (error: any) {
logger.error(error, `Error triggering design execution 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 design execution');
}
});
}