Skip to content
Snippets Groups Projects
Commit 8669c676 authored by Bernard Roland (Student Com20)'s avatar Bernard Roland (Student Com20)
Browse files

Added more API paths

parent 6d5a4534
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,7 @@ export async function up(database: Knex): Promise<void> { ...@@ -32,6 +32,7 @@ export async function up(database: Knex): Promise<void> {
table.text('text').notNullable(); table.text('text').notNullable();
table.string('color').notNullable(); table.string('color').notNullable();
table.enum('status', [ 'open', 'closed', 'suspended' ]).notNullable(); table.enum('status', [ 'open', 'closed', 'suspended' ]).notNullable();
table.date('deadline');
}) })
.createTable('team_projects', table => { .createTable('team_projects', table => {
table.uuid('project_id').notNullable().references('projects.id'); table.uuid('project_id').notNullable().references('projects.id');
...@@ -65,6 +66,7 @@ export async function up(database: Knex): Promise<void> { ...@@ -65,6 +66,7 @@ export async function up(database: Knex): Promise<void> {
table.uuid('task_id').notNullable().references('tasks.id'); table.uuid('task_id').notNullable().references('tasks.id');
table.primary(['user_id', 'task_id']); table.primary(['user_id', 'task_id']);
table.integer('time').notNullable(); table.integer('time').notNullable();
table.boolean('finished').notNullable();
}) })
.createTable('comments', table => { .createTable('comments', table => {
table.uuid('id').notNullable().primary(); table.uuid('id').notNullable().primary();
......
...@@ -112,6 +112,7 @@ project.get('/:uuid/tasks', async (req, res) => { ...@@ -112,6 +112,7 @@ project.get('/:uuid/tasks', async (req, res) => {
requirement_time: 'task_requirements.time', requirement_time: 'task_requirements.time',
assigned_user: 'task_assignees.user_id', assigned_user: 'task_assignees.user_id',
assigned_time: 'task_assignees.time', assigned_time: 'task_assignees.time',
assigned_finished: 'task_assignees.finished',
dependentcy: 'task_dependencies.requires_id', dependentcy: 'task_dependencies.requires_id',
}) })
.where({ .where({
...@@ -168,7 +169,6 @@ project.get('/:uuid/assigned', async (req, res) => { ...@@ -168,7 +169,6 @@ project.get('/:uuid/assigned', async (req, res) => {
}); });
} }
} catch (e) { } catch (e) {
console.log(e);
res.status(400).json({ res.status(400).json({
status: 'error', status: 'error',
message: 'failed to get assignees', message: 'failed to get assignees',
...@@ -221,6 +221,7 @@ interface AddProjectBody { ...@@ -221,6 +221,7 @@ interface AddProjectBody {
name: string; name: string;
text: string; text: string;
color: string; color: string;
deadline?: string;
token: Token; token: Token;
} }
...@@ -258,8 +259,9 @@ project.post('/', async (req, res) => { ...@@ -258,8 +259,9 @@ project.post('/', async (req, res) => {
name: req.body.name, name: req.body.name,
text: req.body.text, text: req.body.text,
color: req.body.color, color: req.body.color,
deadline: req.body.deadline ? new Date(req.body.deadline) : null,
status: 'open', status: 'open',
}); })
await transaction('team_projects').insert( await transaction('team_projects').insert(
team_ids.map(team_id => ({ team_ids.map(team_id => ({
project_id: project_id, project_id: project_id,
......
...@@ -14,6 +14,7 @@ interface TaskRequirement { ...@@ -14,6 +14,7 @@ interface TaskRequirement {
interface TaskAssignment { interface TaskAssignment {
user: string; user: string;
time: number; time: number;
finished: boolean;
} }
export interface Task { export interface Task {
...@@ -68,6 +69,7 @@ export function generateFromFlatResult(results: any[]): Task[] { ...@@ -68,6 +69,7 @@ export function generateFromFlatResult(results: any[]): Task[] {
grouped_tasks[row.id].assigned.push({ grouped_tasks[row.id].assigned.push({
user: row.assigned_user, user: row.assigned_user,
time: row.assigned_time, time: row.assigned_time,
finished: row.assigned_finished,
}); });
} }
} }
...@@ -112,6 +114,7 @@ task.get('/', async (req, res) => { ...@@ -112,6 +114,7 @@ task.get('/', async (req, res) => {
requirement_time: 'task_requirements.time', requirement_time: 'task_requirements.time',
assigned_user: 'task_assignees.user_id', assigned_user: 'task_assignees.user_id',
assigned_time: 'task_assignees.time', assigned_time: 'task_assignees.time',
assigned_finished: 'task_assignees.finished',
dependentcy: 'task_dependencies.requires_id', dependentcy: 'task_dependencies.requires_id',
}) })
.where({ .where({
...@@ -151,6 +154,7 @@ task.get('/:status(open|closed|suspended)', async (req, res) => { ...@@ -151,6 +154,7 @@ task.get('/:status(open|closed|suspended)', async (req, res) => {
requirement_time: 'task_requirements.time', requirement_time: 'task_requirements.time',
assigned_user: 'task_assignees.user_id', assigned_user: 'task_assignees.user_id',
assigned_time: 'task_assignees.time', assigned_time: 'task_assignees.time',
assigned_finished: 'task_assignees.finished',
dependentcy: 'task_dependencies.requires_id', dependentcy: 'task_dependencies.requires_id',
}) })
.where({ .where({
...@@ -192,6 +196,7 @@ task.get('/possible', async (req, res) => { ...@@ -192,6 +196,7 @@ task.get('/possible', async (req, res) => {
requirement_time: 'task_requirements.time', requirement_time: 'task_requirements.time',
assigned_user: 'task_assignees.user_id', assigned_user: 'task_assignees.user_id',
assigned_time: 'task_assignees.time', assigned_time: 'task_assignees.time',
assigned_finished: 'task_assignees.finished',
dependentcy: 'task_dependencies.requires_id', dependentcy: 'task_dependencies.requires_id',
dependentcy_status: 'require.status', dependentcy_status: 'require.status',
}) })
...@@ -204,7 +209,6 @@ task.get('/possible', async (req, res) => { ...@@ -204,7 +209,6 @@ task.get('/possible', async (req, res) => {
tasks: generateFromFlatResult(tasks), tasks: generateFromFlatResult(tasks),
}); });
} catch (e) { } catch (e) {
console.log(e);
res.status(400).json({ res.status(400).json({
status: 'error', status: 'error',
message: 'failed get tasks', message: 'failed get tasks',
...@@ -324,6 +328,7 @@ task.get('/:uuid', async (req, res) => { ...@@ -324,6 +328,7 @@ task.get('/:uuid', async (req, res) => {
.select({ .select({
user: 'task_assignees.user_id', user: 'task_assignees.user_id',
time: 'task_assignees.time', time: 'task_assignees.time',
finished: 'task_assignees.finished',
}) })
.where({ .where({
'task_assignees.task_id': id, 'task_assignees.task_id': id,
...@@ -350,6 +355,7 @@ task.get('/:uuid', async (req, res) => { ...@@ -350,6 +355,7 @@ task.get('/:uuid', async (req, res) => {
assigned: assigned.map(row => ({ assigned: assigned.map(row => ({
user: row.user, user: row.user,
time: row.time, time: row.time,
finished: row.finished,
})), })),
dependentcies: dependentcies.map(row => row.id), dependentcies: dependentcies.map(row => row.id),
requirements: requirements.map(row => ({ requirements: requirements.map(row => ({
...@@ -456,6 +462,7 @@ task.post('/', async (req, res) => { ...@@ -456,6 +462,7 @@ task.post('/', async (req, res) => {
task_id: task_id, task_id: task_id,
user_id: assigned.user, user_id: assigned.user,
time: assigned.time, time: assigned.time,
finished: assigned.finished ?? false,
})) }))
); );
} }
...@@ -598,6 +605,7 @@ task.put('/:uuid', async (req, res) => { ...@@ -598,6 +605,7 @@ task.put('/:uuid', async (req, res) => {
task_id: task_id, task_id: task_id,
user_id: assigned.user, user_id: assigned.user,
time: assigned.time, time: assigned.time,
finished: assigned.finished ?? false,
})) }))
); );
} }
......
...@@ -123,7 +123,6 @@ team.get('/:uuid/', async (req, res) => { ...@@ -123,7 +123,6 @@ team.get('/:uuid/', async (req, res) => {
}); });
} }
} catch (e) { } catch (e) {
console.log(e);
res.status(400).json({ res.status(400).json({
status: 'error', status: 'error',
message: 'failed get team', message: 'failed get team',
...@@ -186,6 +185,55 @@ team.get('/:uuid/members', async (req, res) => { ...@@ -186,6 +185,55 @@ team.get('/:uuid/members', async (req, res) => {
} }
}); });
team.delete('/:teamid/members/:userid', async (req, res) => {
try {
const team_id = req.params.teamid;
const user_id = req.params.userid;
if (validate(team_id) && validate(user_id)) {
const team = await database('team_members')
.select({ id: 'team_members.team_id' })
.where({
'team_members.user_id': req.body.token.id,
'team_members.team_id': team_id,
});
if (team.length === 1) {
const deleted = await database('team_members')
.delete()
.where({
'team_members.user_id': user_id,
'team_members.team_id': team_id,
});
if (deleted >= 1) {
res.status(200).json({
status: 'success',
});
} else {
res.status(404).json({
status: 'error',
message: 'role not found',
});
}
} else {
res.status(404).json({
status: 'error',
message: 'team not found',
});
}
} else {
res.status(400).json({
status: 'error',
message: 'malformed uuid',
});
}
} catch (e) {
res.status(400).json({
status: 'error',
message: 'failed remove members',
});
}
});
team.get('/:uuid/roles', async (req, res) => { team.get('/:uuid/roles', async (req, res) => {
try { try {
const id = req.params.uuid; const id = req.params.uuid;
...@@ -399,7 +447,7 @@ team.delete('/:teamid/roles/:roleid', async (req, res) => { ...@@ -399,7 +447,7 @@ team.delete('/:teamid/roles/:roleid', async (req, res) => {
} catch (e) { } catch (e) {
res.status(400).json({ res.status(400).json({
status: 'error', status: 'error',
message: 'failed to add role', message: 'failed to delete role',
}); });
} }
}); });
...@@ -521,24 +569,22 @@ team.delete('/:uuid/', async (req, res) => { ...@@ -521,24 +569,22 @@ team.delete('/:uuid/', async (req, res) => {
try { try {
const id = req.params.uuid; const id = req.params.uuid;
if (validate(id)) { if (validate(id)) {
await database.transaction(async transaction => { const deleted = await database('team_members')
const deleted = await transaction('team_members') .delete()
.delete() .where({
.where({ 'team_members.user_id': req.body.token.id,
'team_members.user_id': req.body.token.id, 'team_members.team_id': id,
'team_members.team_id': id, });
}); if (deleted >= 1) {
if (deleted >= 1) { res.status(200).json({
res.status(200).json({ status: 'success',
status: 'success', });
}); } else {
} else { res.status(404).json({
res.status(404).json({ status: 'error',
status: 'error', message: 'team not found',
message: 'team not found', });
}); }
}
});
} else { } else {
res.status(400).json({ res.status(400).json({
status: 'error', status: 'error',
......
...@@ -91,10 +91,12 @@ user.get('/tasks', async (req, res) => { ...@@ -91,10 +91,12 @@ user.get('/tasks', async (req, res) => {
requirement_time: 'task_requirements.time', requirement_time: 'task_requirements.time',
assigned_user: 'task_assignees.user_id', assigned_user: 'task_assignees.user_id',
assigned_time: 'task_assignees.time', assigned_time: 'task_assignees.time',
assigned_finished: 'task_assignees.finished',
dependentcy: 'task_dependencies.requires_id', dependentcy: 'task_dependencies.requires_id',
}) })
.where({ .where({
'ut.user_id': req.body.token.id, 'ut.user_id': req.body.token.id,
'task_assignees.finished': false,
}); });
res.status(200).json({ res.status(200).json({
status: 'success', status: 'success',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment