rubberguppe/routes/message.js

21 lines
541 B
JavaScript
Raw Normal View History

2019-09-22 05:20:37 +00:00
'use strict'
const express = require('express')
const router = express.Router()
router.get('/:guid', function (req, res) {
2019-09-22 05:20:37 +00:00
const guid = req.params.guid
if (!guid) {
2019-09-22 05:20:37 +00:00
return res.status(400).send('Bad request.')
} else {
const db = req.app.get('db')
const result = db.prepare('select message from messages where guid = ?').get(guid)
if (result === undefined) {
2019-09-22 05:20:37 +00:00
return res.status(404).send(`No record found for ${guid}.`)
} else {
res.json(JSON.parse(result.message))
}
}
2019-09-22 05:20:37 +00:00
})
2019-09-22 05:20:37 +00:00
module.exports = router