/ src / server / fobtap.js
fobtap.js
 1  import express from 'express'
 2  const router = express.Router()
 3  
 4  import state from './state.js'
 5  import utils from './utils.js'
 6  import validators from './validators.js'
 7  import events from './events.js'
 8  import calculations from '../calculations.js'
 9  
10  function whatCharge(resource, notes){
11      return resource.charged
12  }
13  
14  function resourceCheck(req, res, next){
15      let member = utils.memberFromFob(req.body.fob)
16      let resource = utils.getResource(req.body.resourceId)
17      let memberCard = validators.isTaskId(member.memberId, [])
18      let charged = whatCharge(resource, req.body.notes)
19      let notes = req.body.notes || 'A'
20      if (member && resource && calculations.access(member.active, memberCard.boost ,charged)){
21          events.resourceUsed(
22            req.body.resourceId,
23            member.memberId,
24            charged,
25            notes,
26            utils.buildResCallback(res)
27          )
28      } else {
29          next()
30      }
31  }
32  
33  router.use('/fobtap', resourceCheck)
34  
35  router.use('/fobtap', (req, res)=> {
36      res.end('fobtap not handled')
37  })
38  
39  export default router