Admin page for bill wit iron-session (#13)

This commit is contained in:
Thomas Ruoff
2020-10-22 00:40:09 +02:00
committed by GitHub
parent 42b2dc675b
commit c55f8f8b3a
8 changed files with 446 additions and 311 deletions

View File

@@ -1,18 +1,20 @@
import { NextApiRequest, NextApiResponse } from 'next'
import { BillDocument } from '../../../../db/bill'
import { createBill, patchBill } from '../../../../db/index'
import withSession from '../../../../lib/session'
export default async function userHandler(
req: NextApiRequest,
res: NextApiResponse
) {
export default withSession(async function billHandler(req, res) {
const {
method,
query: { uuid: uuids },
} = req
const bookingUUID = Array.isArray(uuids) ? uuids[0] : uuids
const user = req?.session.get('user')
if (!user || user.role !== 'admin') {
res.status(401).end('Your are unauthorized. Best to move along...')
return
}
let bill: BillDocument
switch (method) {
@@ -40,4 +42,4 @@ export default async function userHandler(
res.setHeader('Allow', ['POST'])
res.status(405).end(`Method ${method} Not Allowed`)
}
}
})