From d9cd896d333ebc4f65f6e3fa4416f273cdfebf6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1?= Date: Mon, 15 Nov 2021 19:29:41 +0000 Subject: [PATCH] feat: create batch when machine detects stacker open --- lib/machine-loader.js | 2 +- lib/routes.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/machine-loader.js b/lib/machine-loader.js index 6d3b6a10..0576dbc1 100644 --- a/lib/machine-loader.js +++ b/lib/machine-loader.js @@ -118,7 +118,7 @@ function getMachine (machineId, config) { .then(([machine, events, config]) => { const pings = checkPings([machine]) - return [machine].map(addName(pings, events, config))[0] + return addName(pings, events, config)(machine) }) } diff --git a/lib/routes.js b/lib/routes.js index 87591093..a3213242 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -10,6 +10,7 @@ const express = require('express') const nmd = require('nano-markdown') const semver = require('semver') +const cashbox = require('./cashbox-batches') const dbErrorCodes = require('./db-error-codes') const options = require('./options') const logger = require('./logger') @@ -207,11 +208,10 @@ function stateChange (req, res, next) { } function notifyCashboxRemoval (req, res, next) { - Promise.resolve() - .then(() => { - logger.log(`Device ${req.deviceId} had its cashbox removed.`) - return res.status(200).send({ status: 'OK' }) - }) + return machineLoader.getMachine(req.deviceId) + .then(machineLoader => cashbox.createCashboxBatch(req.deviceId, machineLoader.cashbox)) + .then(() => machineLoader.setMachine({ deviceId: req.deviceId, action: 'emptyCashInBills' })) + .then(() => res.status(200).send({ status: 'OK' })) .catch(next) }