diff --git a/server/src/v1/comment.ts b/server/src/v1/comment.ts index f7739b9536f7cbc83d913707aac12a9380466559..66fef84296a7f62fd91f5aeef727bc0a12bf7813 100644 --- a/server/src/v1/comment.ts +++ b/server/src/v1/comment.ts @@ -70,12 +70,12 @@ comment.post('/', async (req, res) => { }); interface UpdateCommentBody { - text?: string; + text: string; token: Token; } comment.put('/:uuid', async (req, res) => { - if (isOfType<UpdateCommentBody>(req.body, [])) { + if (isOfType<UpdateCommentBody>(req.body, [['text', 'string']])) { try { const comment_id = req.params.uuid; if (validate(comment_id)) { diff --git a/server/src/v1/project.ts b/server/src/v1/project.ts index 77240ab3c83c52a977bbc333c46718f037ea05f8..e93d40e869ed5716607d78bf4cbad908818fddef 100644 --- a/server/src/v1/project.ts +++ b/server/src/v1/project.ts @@ -338,16 +338,18 @@ project.put('/:uuid', async (req, res) => { }); if (projects.length >= 1) { await database.transaction(async transaction => { - await transaction('projects') - .update({ - name: req.body.name, - text: req.body.text, - color: req.body.color, - status: req.body.status, - deadline: req.body.deadline, - }).where({ - id: id, - }); + if (req.body.name || req.body.text || req.body.color || req.body.status || req.body.deadline) { + await transaction('projects') + .update({ + name: req.body.name, + text: req.body.text, + color: req.body.color, + status: req.body.status, + deadline: req.body.deadline, + }).where({ + id: id, + }); + } if (remove_team_ids.length !== 0) { await transaction('team_projects') .delete() diff --git a/server/src/v1/task.ts b/server/src/v1/task.ts index 3662b6e65532c6114d1f04d34d9f1f9f5e92407b..e00c3ce06c063c8e6985112d914f2ef0ce389fd6 100644 --- a/server/src/v1/task.ts +++ b/server/src/v1/task.ts @@ -546,18 +546,20 @@ task.put('/:uuid', async (req, res) => { }); if (task.length >= 1) { await database.transaction(async transaction => { - await transaction('tasks') - .update({ - name: req.body.name, - text: req.body.text, - icon: req.body.icon, - priority: req.body.priority, - status: req.body.status, - edited: new Date(), - }) - .where({ - 'tasks.id': task_id, - }); + if (req.body.name || req.body.text || req.body.icon || req.body.priority || req.body.status) { + await transaction('tasks') + .update({ + name: req.body.name, + text: req.body.text, + icon: req.body.icon, + priority: req.body.priority, + status: req.body.status, + edited: new Date(), + }) + .where({ + 'tasks.id': task_id, + }); + } if (remove_requirement_ids.length !== 0) { await transaction('task_requirements') .delete() diff --git a/server/src/v1/user.ts b/server/src/v1/user.ts index d4ffdbb1ad808dea9837e4c1ca925b865b8fe818..2fa51c76ca96331a1cc3224b4caf296bade1ba6a 100644 --- a/server/src/v1/user.ts +++ b/server/src/v1/user.ts @@ -145,25 +145,29 @@ interface UserUpdateBody { } user.put('/', async (req, res) => { - if ( - isOfType<UserUpdateBody>(req.body, [['realname', 'string']]) - || isOfType<UserUpdateBody>(req.body, [['email', 'string']]) - ) { + if (isOfType<UserUpdateBody>(req.body, [])) { try { - const updated = await database('users') - .update({ - email: req.body.email, - real_name: req.body.realname, - }) - .where({ id: req.body.token.id }); - if (updated >= 1) { + if (req.body.realname || req.body.email) { + const updated = await database('users') + .update({ + email: req.body.email, + real_name: req.body.realname, + }) + .where({ id: req.body.token.id }); + if (updated >= 1) { + res.status(200).json({ + status: 'success', + }); + } else { + res.status(404).json({ + status: 'error', + message: 'user not found', + }); + } + } else { res.status(200).json({ status: 'success', - }); - } else { - res.status(404).json({ - status: 'error', - message: 'user not found', + message: 'nothing to do', }); } } catch (e) { diff --git a/server/src/v1/work.ts b/server/src/v1/work.ts index 680e3e79e2fc958ed95e83888a30e50696a5f12e..65e32237c409d9c7586702dd10ac8a1900e53c57 100644 --- a/server/src/v1/work.ts +++ b/server/src/v1/work.ts @@ -109,7 +109,13 @@ work.put('/finish', async (req, res) => { work.get('/', async (req, res) => { try { const work = await database('workhours') - .select() + .select({ + id: 'workhours.id', + task: 'workhours.task_id', + user: 'workhours.user_id', + started: 'workhours.started', + finished: 'workhours.finished', + }) .where({ user_id: req.body.token.id, finished: null,