Trigger opening of door if card is valid

This commit is contained in:
Dana Woodman 2018-07-10 16:28:36 -07:00
parent 710f7953b6
commit 3205070d2b
2 changed files with 12 additions and 13 deletions

View File

@ -1,9 +1,9 @@
module.exports = class Door {
static open() {
console.log('OPEN')
console.log('OPEN DOOR!!!!!!!!!!!!!!')
}
static close() {
console.log('CLOSE')
}
// static close() {
// console.log('CLOSE DOOR!!!!!!!!!!!!')
// }
}

View File

@ -1,4 +1,5 @@
const Cards = require('../models/cards')
const Door = require('../models/door')
const Logs = require('../models/logs')
module.exports = (req, res) => {
@ -7,14 +8,12 @@ module.exports = (req, res) => {
Cards.validate(rfid).then(card => {
console.log('CARD:', card)
// TODO: add to log if success
if (card) {
res.redirect('/success?name=' + card.name)
Logs.log({ timestamp: new Date().getTime(), card }).then(() =>
console.log('Logged!')
)
} else {
res.redirect('/failure')
}
if (!card) return res.redirect('/failure')
Door.open()
res.redirect('/success?name=' + card.name)
Logs.log({ timestamp: new Date().getTime(), card }).then(() =>
console.log('Logged!')
)
})
}