2019-09-22 05:20:37 +00:00
|
|
|
'use strict'
|
|
|
|
const express = require('express')
|
|
|
|
const router = express.Router()
|
2018-09-25 03:10:39 +00:00
|
|
|
|
|
|
|
router.get('/:guid', function (req, res) {
|
2019-09-22 05:20:37 +00:00
|
|
|
const guid = req.params.guid
|
2018-09-25 03:10:39 +00:00
|
|
|
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)
|
2019-03-26 07:01:34 +00:00
|
|
|
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-03-26 07:01:34 +00:00
|
|
|
}
|
2018-09-25 03:10:39 +00:00
|
|
|
}
|
2019-09-22 05:20:37 +00:00
|
|
|
})
|
2018-09-25 03:10:39 +00:00
|
|
|
|
2019-09-22 05:20:37 +00:00
|
|
|
module.exports = router
|