identities

master
Marcus 2020-02-26 22:02:18 -05:00
parent 650a69606b
commit b5bb38a1fa
4 changed files with 21 additions and 11 deletions

View File

@ -1,9 +1,17 @@
const express = require('express'); const express = require('express');
const { Router } = express; const { Router } = express;
const router = new Router() const router = new Router()
const identity = require('../src/identity.js')
router.get('/', async (req, res) => {
res.json({
identities: await identity.get.all()
});
});
router.get('/:guid', (req, res) => { router.get('/:guid', (req, res) => {
console.log(req); console.log(req.param.guid);
res.json({});
}) })
module.exports = router; module.exports = router;

View File

@ -2,19 +2,14 @@ const express = require('express');
const { Router } = express; const { Router } = express;
const api = new Router() const api = new Router()
api.use('/identity', )
api.get('/', (req, res) => { api.get('/', (req, res) => {
res.json({ res.json({
up: true, up: true,
time: new Date().getTime(), time: new Date().getTime(),
identities: [ identity: '/identity'
{
name: 'example'
}
]
}) })
}) })
api.use('/identity', require('./identity.js'))
module.exports = api; module.exports = api;

View File

@ -2,7 +2,7 @@ const express = require('express');
const app = express(); const app = express();
const api = require('./api'); const api = require('./api');
app.use('/api ', api); app.use('/api', api);
app.listen(6565); app.listen(6565);

View File

@ -34,7 +34,8 @@ async function getAllIdentities() {
identities.find({}, (err, docs) => { identities.find({}, (err, docs) => {
const names = docs.reduce((acc, obj) => { const names = docs.reduce((acc, obj) => {
if(obj._id in acc) return acc; if(obj._id in acc) return acc;
else acc[obj._id] = obj.name; acc[obj._id] = obj.name;
return acc;
}, {}); }, {});
res(names); res(names);
}) })
@ -46,4 +47,10 @@ module.exports = {
get: Object.assign(getIdentity, { get: Object.assign(getIdentity, {
all: getAllIdentities all: getAllIdentities
}) })
} };
(async function() {
if(Object.keys(await getAllIdentities()).length === 0) {
createIdentity('Default');
}
})();