Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add activities tasks routes #145

Merged
merged 26 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ad53f5f
feat: add activity table and employee role
Metololo May 21, 2024
bbca6c3
feat: add route to add employee in activity team
Metololo May 21, 2024
0a8ba12
feat: add activity team route
Metololo May 22, 2024
a54586a
feat: get one activity team
Metololo May 23, 2024
96c313f
Merge branch 'main' into admin/feat/tournaments
Metololo May 23, 2024
ac455ec
feat: modify activities database schema
Metololo May 23, 2024
464c37e
feat: modify activities schema
Metololo May 23, 2024
ee6c8cd
fix: activities types
Metololo May 24, 2024
7abb96f
fix: pnpm-lock
Metololo May 24, 2024
9a32898
feat: enhance activity routes
Metololo May 25, 2024
4708252
fix: activities test
Metololo May 25, 2024
289f23c
Merge branch 'main' into feat/activity-task-management
Metololo May 25, 2024
bc888c3
fix: update migrations
Metololo May 25, 2024
49532ce
fix: lint project
Metololo May 25, 2024
4e61833
feat: add activity occurence route and tasks
Metololo May 26, 2024
712bcd3
feat: add tasks route for insertion and get all
Metololo May 27, 2024
27da0ae
feat: enhance task creation and add get one task route
Metololo May 28, 2024
dea0867
Merge branch 'main' into feat/activity-task-management
Metololo May 28, 2024
5705e76
fix: update pnpm
Metololo May 28, 2024
9ed1436
feat: add tests for activities and teams
Metololo May 28, 2024
c3223a9
fix: lint for pull request
Metololo May 28, 2024
d49f42f
fix: spelling error
Metololo May 28, 2024
726562c
feat: add delete task
Metololo May 28, 2024
3b7f1a0
feat: add tasks patch route
Metololo May 28, 2024
beeba72
feat: add tasks tests
Metololo May 28, 2024
4cdbdc6
Merge branch 'main' into feat/activity-task-management
Metololo May 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion apps/api/src/handlers/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OpenAPIHono } from '@hono/zod-openapi';
import { supabase } from '../libs/supabase.js';
import { zodErrorHook } from '../libs/zodError.js';
import { createTask, getAllTasks, getOneTask } from '../routes/tasks.js';
import { createTask, deleteTask, getAllTasks, getOneTask, updateTask } from '../routes/tasks.js';
import { checkRole } from '../utils/context.js';
import { getPagination } from '../utils/pagnination.js';
import { Role, type Variables } from '../validators/general.js';
Expand Down Expand Up @@ -113,3 +113,39 @@ tasks.openapi(createTask, async (c) => {

return c.json(data, 201);
});

tasks.openapi(deleteTask, async (c) => {
const { id } = c.req.valid('param');
const user = c.get('user');
const roles = user.roles;
await checkRole(roles, false);

const { error } = await supabase.from('ACTIVITIES_TASKS').delete().eq('id', id);

if (error) {
return c.json({ error: 'Task not found' }, 404);
}

return c.json({ message: `Task with id ${id} deleted` }, 200);
});

tasks.openapi(updateTask, async (c) => {
const { id } = c.req.valid('param');
const { title, description, status, priority, id_employee } = c.req.valid('json');
const user = c.get('user');
const roles = user.roles;
await checkRole(roles, false);

const { data, error } = await supabase
.from('ACTIVITIES_TASKS')
.update({ title, description, status, priority, id_employee })
.eq('id', id)
.select()
.single();

if (error || !data) {
return c.json({ error: 'Failed to update task' }, 400);
}

return c.json(data, 200);
});
64 changes: 62 additions & 2 deletions apps/api/src/routes/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { createRoute, z } from '@hono/zod-openapi';
import authMiddleware from '../middlewares/auth.js';
import { queryAllSchema } from '../utils/pagnination.js';
import { badRequestSchema, notFoundSchema, serverErrorSchema } from '../validators/general.js';
import { badRequestSchema, idParamValidator, notFoundSchema, serverErrorSchema } from '../validators/general.js';
import { taskSchema } from '../validators/tasks.js';

export const getAllTasks = createRoute({
method: 'get',
path: '/activities_exceptions/{id}/tasks',
summary: 'Get all activity occurence tasks',
summary: 'Get all tasks of an activity occurence',
description: 'Get all activity occurence tasks',
request: {
params: z.object({ id: z.coerce.number().min(1) }),
Expand Down Expand Up @@ -86,3 +86,63 @@ export const createTask = createRoute({
},
tags: ['task'],
});

export const deleteTask = createRoute({
method: 'delete',
path: '/tasks/{id}',
summary: 'Delete a task',
description: 'Delete a task',
security: [{ Bearer: [] }],
middleware: authMiddleware,
request: {
params: z.object({ id: z.coerce.number().min(1) }),
},
responses: {
200: {
description: 'Successful response',
content: {
'application/json': {
schema: z.object({
message: z.string(),
}),
},
},
},
500: serverErrorSchema,
404: notFoundSchema,
},
tags: ['task'],
});

export const updateTask = createRoute({
method: 'patch',
path: '/tasks/{id}',
summary: 'Update a task',
description: 'Update a task',
security: [{ Bearer: [] }],
middleware: authMiddleware,
request: {
params: idParamValidator,
body: {
content: {
'application/json': {
schema: taskSchema.omit({ id: true, created_at: true, id_activity_exception: true }).partial(),
},
},
},
},
responses: {
200: {
description: 'Successful response',
content: {
'application/json': {
schema: taskSchema,
},
},
},
500: serverErrorSchema,
400: badRequestSchema,
404: notFoundSchema,
},
tags: ['task'],
});
Loading
Loading