Feat: implement per operator settings cache

Fix: fix linter-found issues

Chore: move findOperatorId to own middleware file

Chore: delete old routes.js file and rename new-routes.js to routes.js

Fix: PR fixes
This commit is contained in:
Cesar 2021-01-13 19:04:40 +00:00 committed by Josh Harvey
parent 85235eaa13
commit 558317e9f3
30 changed files with 232 additions and 860 deletions

View file

@ -7,14 +7,7 @@ const compliance = require('../compliance')
const complianceTriggers = require('../compliance-triggers')
const configManager = require('../new-config-manager')
const customers = require('../customers')
function httpError (msg, code) {
const err = new Error(msg)
err.name = 'HTTPError'
err.code = code || 500
return err
}
const httpError = require('../route-helpers').httpError
function updateCustomer (req, res, next) {
const id = req.params.id
@ -54,10 +47,8 @@ function triggerSanctions (req, res, next) {
customers.getById(id)
.then(customer => {
if (!customer) { throw httpError('Not Found', 404) }
return compliance.validationPatch(req.deviceId, true, customer)
.then(patch => customers.update(id, patch))
})
.then(customer => res.status(200).json({ customer }))
.catch(next)
@ -81,7 +72,7 @@ function triggerSuspend (req, res, next) {
const days = triggerId === 'no-ff-camera' ? 1 : getSuspendDays(triggers)
const date = new Date()
date.setDate(date.getDate() + days);
date.setDate(date.getDate() + days)
customers.update(id, { suspendedUntil: date })
.then(customer => res.status(200).json({ customer }))
.catch(next)
@ -92,4 +83,4 @@ router.patch('/:id/sanctions', triggerSanctions)
router.patch('/:id/block', triggerBlock)
router.patch('/:id/suspend', triggerSuspend)
module.exports = router
module.exports = router