Skip to content

Commit

Permalink
Initial pass at inserting bill run in db
Browse files Browse the repository at this point in the history
We update our `createBillRun` controller to create a record for the bill run in the db. We initially hardcode the financial year fields just to get it working, with the intention of pulling these through properly from the request in a later commit
  • Loading branch information
StuAA78 committed Dec 16, 2022
1 parent 03c94ba commit 818543e
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions app/controllers/bill-runs.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,41 @@ const Boom = require('@hapi/boom')

const CreateBillRunValidator = require('../validators/bill-runs/create-bill-run.validator')

const BillingBatchModel = require('../models/billing-batch.model')

async function createBillRun (request, _h) {
const validatedData = CreateBillRunValidator.go(request.payload)

if (validatedData.error) {
return _formattedValidationError(validatedData.error)
}

const { type, scheme, region } = validatedData.value

let billRun

try {
billRun = await BillingBatchModel
.query()
.insert({
batchType: type,
scheme,
regionId: region,
fromFinancialYearEnding: 2022,
toFinancialYearEnding: 2022,
status: 'ready'
})
.returning('*')
} catch (error) {
console.log('🚀 ~ file: bill-runs.controller.js:34 ~ createBillRun ~ error', error)
}

return {
id: 'DUMMY_SROC_BATCH',
region: validatedData.value.region,
scheme: validatedData.value.scheme,
type: validatedData.value.type,
status: 'ready'
id: billRun.billingBatchId,
region: billRun.regionId,
scheme: billRun.scheme,
type: billRun.batchType,
status: billRun.status
}
}

Expand Down

0 comments on commit 818543e

Please sign in to comment.