Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
271 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
'use strict' | ||
|
||
/* MODULE IMPORTS */ | ||
const Router = require('koa-router') | ||
|
||
const router = new Router() | ||
|
||
const dbMenu = '../databases/menu.db' | ||
|
||
/* MODULE IMPORTS */ | ||
const Order = require('../modules/order') | ||
|
||
router.get('/mainmenu', async ctx => { | ||
try{ | ||
const auth = ctx.session.authorised | ||
if(auth === 'Admin' || auth === 'Kitchen' || auth === 'Waiting') { | ||
await ctx.render('mainmenu') | ||
} else ctx.redirect('/login?msg=you need to log in') | ||
} catch(err) { | ||
await ctx.render('error', {message: err.message}) | ||
} | ||
}) | ||
|
||
router.get('/ready', async ctx => { | ||
try{ | ||
const auth = ctx.session.authorised | ||
if(auth === 'Admin' || auth === 'Kitchen') { | ||
const order = await new Order(dbMenu) | ||
const unready = await order.getNotReadyOrders() | ||
const ready = await order.getReadyOrders() | ||
await ctx.render('ready', {unreadyOrder: unready, readyOrder: ready}) | ||
} else await ctx.render('mainmenu') | ||
} catch(err) { | ||
await ctx.render('error', {message: err.message}) | ||
} | ||
}) | ||
|
||
router.post('/ready', async ctx => { | ||
try { | ||
const body = ctx.request.body | ||
const order = await new Order(dbMenu) | ||
if (body.submit === 'Ready') { | ||
await order.setReady(body.ID) | ||
} else if (body.submit === 'Unready') { | ||
await order.setUnready(body.ID) | ||
} | ||
const unready = await order.getNotReadyOrders() | ||
const ready = await order.getReadyOrders() | ||
await ctx.render('ready', {unreadyOrder: unready, readyOrder: ready}) | ||
} catch(err) { | ||
await ctx.render('error', {message: err.message}) | ||
} | ||
}) | ||
|
||
router.get('/adding', async ctx => { | ||
try{ | ||
const auth = ctx.session.authorised | ||
if(auth === 'Admin' || auth === 'Waiting') { | ||
await ctx.render('adding') | ||
} else await ctx.render('mainmenu') | ||
} catch(err) { | ||
await ctx.render('error', {message: err.message}) | ||
} | ||
}) | ||
|
||
router.post('/adding', async ctx => { | ||
try { | ||
const body = ctx.request.body | ||
const order = await new Order(dbMenu) | ||
order.createPrice(body) | ||
await order.addItem(body) | ||
await ctx.render('adding') | ||
} catch(err) { | ||
await ctx.render('error', {message: err.message}) | ||
} | ||
}) | ||
|
||
router.get('/menu', async ctx => { | ||
try{ | ||
const auth = ctx.session.authorised | ||
if(auth === 'Admin') { | ||
const order = await new Order(dbMenu) | ||
const data = await order.getItemsName() | ||
await ctx.render('menu', {items: data}) | ||
} else await ctx.render('mainmenu') | ||
} catch(err) { | ||
await ctx.render('error', {message: err.message}) | ||
} | ||
}) | ||
|
||
router.get('/edit/:itemID', async ctx => { | ||
try{ | ||
const order = await new Order(dbMenu) | ||
const data = await order.getItemInfo(ctx.params.itemID) | ||
order.splitPrice(data[0]) | ||
await ctx.render('edit', {items: data}) | ||
} catch(err) { | ||
await ctx.render('error', {message: err.message}) | ||
} | ||
}) | ||
|
||
router.post('/edit', async ctx => { | ||
try { | ||
const body = ctx.request.body | ||
const order = await new Order(dbMenu) | ||
order.createPrice(body) | ||
await order.editItem(body) | ||
const data = await order.getItemsName() | ||
await ctx.render('menu', {items: data}) | ||
} catch(err) { | ||
await ctx.render('error', {message: err.message}) | ||
} | ||
}) | ||
|
||
module.exports = router |
Oops, something went wrong.