feat: cashbox batch creation on machine cashbox removal

fix: cashbox batch creation with empty cashbox
This commit is contained in:
Sérgio Salgado 2021-04-28 16:41:27 +01:00 committed by Josh Harvey
parent 482e1afc3a
commit 61cc772816
5 changed files with 15 additions and 13 deletions

View file

@ -2,8 +2,8 @@ const db = require('./db')
const _ = require('lodash/fp')
const uuid = require('uuid')
function createCashboxBatch (deviceId) {
console.log('herererere')
function createCashboxBatch (deviceId, cashboxCount) {
if (_.isEqual(0, cashboxCount)) throw new Error('Cashbox is empty. Cashbox batch could not be created')
const sql = `INSERT INTO cashbox_batches (id, device_id, created, operation_type) VALUES ($1, $2, now(), 'cash-in-empty') RETURNING *`
const sql2 = `
UPDATE bills SET cashbox_batch_id=$1

View file

@ -5,7 +5,7 @@ const resolvers = {
cashboxBatches: () => cashbox.getBatches()
},
Mutation: {
createBatch: (...[, { deviceId }]) => cashbox.createCashboxBatch(deviceId),
createBatch: (...[, { deviceId, cashboxCount }]) => cashbox.createCashboxBatch(deviceId, cashboxCount),
editBatch: (...[, { id, performedBy }]) => cashbox.editBatchById(id, performedBy)
}
}

View file

@ -16,7 +16,7 @@ const typeDef = gql`
}
type Mutation {
createBatch(deviceId: ID): CashboxBatch
createBatch(deviceId: ID, cashboxCount: Int): CashboxBatch
editBatch(id: ID, performedBy: String): CashboxBatch
}
`

View file

@ -1,12 +1,15 @@
const express = require('express')
const router = express.Router()
const cashbox = require('../cashbox-batches')
const machine = require('../machine-loader')
function notifyCashboxRemoval (req, res, next) {
Promise.resolve()
.then(() => {
console.log(`Device ${req.deviceId} had its cashbox removed.`)
return res.status(200).send({ status: 'OK' })
})
.then(() => machine.getMachine(req.deviceId))
.then(machine => cashbox.createCashboxBatch(req.deviceId, machine.cashbox))
.then(() => machine.emptyCashInBills(req))
.then(() => res.status(200).send({ status: 'OK' }))
.catch(next)
}

View file

@ -14,8 +14,8 @@ const MODAL_HEIGHT = 520
const CASHBOX_DEFAULT_CAPACITY = 500
const CREATE_BATCH = gql`
mutation createBatch($deviceId: ID) {
createBatch(deviceId: $deviceId) {
mutation createBatch($deviceId: ID, $cashboxCount: Int) {
createBatch(deviceId: $deviceId, cashboxCount: $cashboxCount) {
id
}
}
@ -38,7 +38,6 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
const isLastStep = step === LAST_STEP
const onContinue = it => {
console.log('it?.wasCashboxEmptied', it?.wasCashboxEmptied)
const wasCashboxEmptied = it?.wasCashboxEmptied === 'YES'
const cashbox = wasCashboxEmptied ? 0 : machine?.cashbox
@ -46,10 +45,10 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
const newConfig = R.merge(config, it)
if (isLastStep) {
if (wasCashboxEmptied) {
console.log('cashbox was emptied')
createBatch({
variables: {
deviceId: machine.id
deviceId: machine.id,
cashboxCount: machine.cashbox
}
})
}