swd-be/routes/v1/person.js

54 lines
1.2 KiB
JavaScript

const express = require('express');
const router = express.Router();
var cors = require('cors');
const bcrypt = require('bcrypt');
const randToken = require('rand-token');
const DEBUG = true;
router.param('personId', function(req, res, next, id) {
req.personId = id;
let query = " Select * from v_person ";
query += " WHERE id = $1";
if(DEBUG) console.log(query);
if(DEBUG) console.log(req.personId);
req.db.query(query, [req.personId], (err, rs) => {
if (err) {
return next(err)
}
req.person = rs.rows[0];
next();
})
});
/* GET recepies listing. */
router.get('/', function(req, res, next) {
let query = " Select * from v_person ";
if(DEBUG) console.log(query);
req.db.query(query, (err, rs) => {
if (err){
console.log(query);
next(err);
} else {
let result = {};
<<<<<<< HEAD
result['items'] = rs.rows;
=======
result['person'] = rs.rows;
>>>>>>> 0db45ce44687f68654bfe595345fd32498cbe665
console.log(result);
res.status(200).json(result);
}
});
});
/* Methods with id */
router.get('/:personId', function(req, res, next) {
res.status(200).json(req.person);
});
module.exports = router;