Skip to content
Permalink
fcb8f39e7c
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
115 lines (102 sloc) 2.94 KB
'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