/
codiart
/
new_light_server
Обзор
Документация
Войти
/
codiart
/
new_light_server
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/presentation/controllers/TaskController.ts
58 строк
2 KB
Maxim
Initial
05 ноя 2025, 18:08
05 ноя 2025, 18:08
b73e3bd
Код
Авторство
О чём код?
import { Elysia, t } from 'elysia'; import { PostgresTaskRepository } from '../../infrastructure/database/TaskRepository'; import { AddTaskCommand } from '../../application/commands/AddTask'; import { GetTaskCommandHandler, AddTaskCommandHandler } from '../../application/handlers'; import { DeleteTaskCommandHandler } from '../../application/handlers/DeleteTask'; import { DeleteTaskCommand } from '../../application/commands/DeleteTask'; import { PatchTaskCommandHandler } from '../../application/handlers/PatchTask'; import { PatchTaskCommand } from '../../application/commands/PatchTask'; const pg = new PostgresTaskRepository(); export const tasks = new Elysia({ prefix: '/tasks' }) .get('/all', async () => { const handler = new GetTaskCommandHandler(pg); try { const response = await handler.execute(); return JSON.stringify(response); } catch (error) { return JSON.stringify({ errorInfo: 'Error fetching tasks', error }); } }) .post('/add', async ({ body }) => { const handler = new AddTaskCommandHandler(pg); const command = new AddTaskCommand(body.title, body.text, body.completed, body.priority); try { const response = await handler.execute(command); return JSON.stringify({ response }); } catch (error) { return JSON.stringify({ errorInfo: 'Error adding task', error }); } }) .patch(':id', async ({ body }, params: { id }) => { const handler = new PatchTaskCommandHandler(pg); const command = new PatchTaskCommand(body.title, body.text, body.completed, body.priority); try { const response = await handler.execute(command); return JSON.stringify({ response }); } catch (error) { return JSON.stringify({ errorInfo: 'Error adding task', error }); } }) .delete(':id', async ({ params: { id } }) => { const handler = new DeleteTaskCommandHandler(pg); const command = new DeleteTaskCommand(id); try { const response = await handler.execute(command); return JSON.stringify({ response }); } catch (error) { return JSON.stringify({ errorInfo: 'Error adding task', error }); } });