import e = require('express'); import Response = e.Response; import { Billing as billingLib } from '../lib/billing'; import { ExtendedRequest } from './../lib/models/billing'; /** * /billing * get: * description: Get All Requests and ADD them to current rtb charges list tehn UPDATE original list item * responses: * 200: * description: Response after successfully getting all requests * 400: * description: Failed to get all requests * 500: * description: Unexpected server error */ async function getAll(req: ExtendedRequest, res: Response) { let data; try { const reqObj = new billingLib(req.params.facilityId || '/', req.user.username); try { data = await reqObj.getAll(); } catch (error) { res.status(400).json({ error: error.message }); } res.status(204).send(data); } catch (error) { res.status(400).json({ error: error.message }); } } /** * /filter * Put: * description: FIND specific Requests and ADD them to current rtb charges list tehn UPDATE original list item * responses: * 200: * description: Response after successfully getting specific requests * 400: * description: Failed to get all requests * 500: * description: Unexpected server error */ async function filter(req: ExtendedRequest, res: Response) { try { const reqObj = new billingLib(req.params.facilityId || '/', req.user.username); const data = await reqObj.filter(req.body); res.status(200).send(data); } catch (error) { res.status(400).json({ error: error.message }); } } /** * /readytobill * POST: * description: FIND specific Requests and create exel Spreadsheets * responses: * 200: * description: Response after successfully getting specific requests * 400: * description: Failed to get all requests * 500: * description: Unexpected server error */ async function readyToBill(req: ExtendedRequest, res: Response) { try { const reqObj = new billingLib(req.params.facilityId || '/', req.user.username); const data = await reqObj.readyToBill(req.body); res.status(200).send(data); } catch (error) { res.status(400).json({ error: error.message }); } } /** * /generatebilled * POST: * description: FIND specific Requests and create exel Spreadsheets * responses: * 200: * description: Response after successfully getting specific requests * 400: * description: Failed to get all requests * 500: * description: Unexpected server error */ async function generateBilled(req: ExtendedRequest, res: Response) { try { const reqObj = new billingLib(req.params.facilityId || '/', req.user.username); const data = await reqObj.generateBilled(req.body); res.status(200).send(data); } catch (error) { res.status(400).json({ error: error.message }); } } /** * /generatebillingsheet * POST: * description: FIND specific Requests and create exel Spreadsheets * responses: * 200: * description: Response after successfully getting specific requests * 400: * description: Failed to get all requests * 500: * description: Unexpected server error */ async function generateBillingSheet(req: ExtendedRequest, res: Response) { try { const reqObj = new billingLib(req.params.facilityId || '/', req.user.username); const data = await reqObj.generateBillingSheet(req.body); res.status(200).send(data); } catch (error) { res.status(400).json({ error: error.message }); } } /** * /getrecords * get: * description: Get All Requests * responses: * 200: * description: Response after successfully getting all requests * 400: * description: Failed to get all requests * 500: * description: Unexpected server error */ async function getRecords(req: ExtendedRequest, res: Response) { let data; try { const reqObj = new billingLib(req.params.facilityId || '/', req.user.username); data = await reqObj.getRecords(req.body); res.status(200).send(data); } catch (error) { res.status(400).json({ error: error.message }); } } export const routes = [ { path: '/:listName/billing', httpMethod: ['GET'], middleware: [getAll], accessLevel: 'user' }, { path: '/:listName/filter', httpMethod: ['PUT'], middleware: [filter], accessLevel: 'user' }, { path: '/:listName/readytobill', httpMethod: ['POST'], middleware: [readyToBill], accessLevel: 'user' }, { path: '/:listName/generatebilled', httpMethod: ['POST'], middleware: [generateBilled], accessLevel: 'user' }, { path: '/:listName/generatebillingsheet', httpMethod: ['POST'], middleware: [generateBillingSheet], accessLevel: 'user' }, { path: '/:listName/getrecords', httpMethod: ['POST'], middleware: [getRecords], accessLevel: 'user' } ];