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

Added a API request to get currently open work

parent 8669c676
No related branches found
No related tags found
No related merge requests found
...@@ -93,7 +93,7 @@ work.put('/finish', async (req, res) => { ...@@ -93,7 +93,7 @@ work.put('/finish', async (req, res) => {
status: 'success', status: 'success',
}); });
} else { } else {
res.status(200).json({ res.status(404).json({
status: 'error', status: 'error',
message: 'no work to finish', message: 'no work to finish',
}); });
...@@ -106,5 +106,32 @@ work.put('/finish', async (req, res) => { ...@@ -106,5 +106,32 @@ work.put('/finish', async (req, res) => {
} }
}); });
work.get('/', async (req, res) => {
try {
const work = await database('workhours')
.select()
.where({
user_id: req.body.token.id,
finished: null,
});
if (work.length >= 1) {
res.status(200).json({
status: 'success',
work: work[0],
});
} else {
res.status(404).json({
status: 'error',
message: 'no open work',
});
}
} catch (e) {
res.status(400).json({
status: 'error',
message: 'failed to get work',
});
}
});
export default work; export default work;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment