obrand-admin-server/server/app/accounts.js
2016-04-06 17:02:43 +01:00

34 lines
945 B
JavaScript

var db = require('../units/db-connector').dbConnection;
var dbAccounts = require('../units/db-accounts')(db);
module.exports = function(app) {
var express = require('express');
var accountsRouter = express.Router();
accountsRouter.get('/:uid', function(req, res) {
if (/Bearer .+/.test(req.headers.authorization)) {
dbAccounts.sqlGetAccountDetails(req.params.uid)
.then(function(data) {
'use strict';
const response = {
data: {
type: 'accounts', id: data.uid, attributes: {
uid: data.uid, login: data.email, forename: data.forename,
surname: data.surname, memberof: data.member_of
}
}
};
res.status(200).send(response);
})
.catch(function(err) {
console.error(err);
res.status(401).end();
});
}
});
app.use('/accounts', accountsRouter);
};