diff --git a/server/src/v1/work.ts b/server/src/v1/work.ts index e12e49047dca30a4660b5b50ea94ed1a1dc92dcb..680e3e79e2fc958ed95e83888a30e50696a5f12e 100644 --- a/server/src/v1/work.ts +++ b/server/src/v1/work.ts @@ -93,7 +93,7 @@ work.put('/finish', async (req, res) => { status: 'success', }); } else { - res.status(200).json({ + res.status(404).json({ status: 'error', message: 'no work to finish', }); @@ -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;