From b5bb38a1fada446a2f606f6632aa5906098c93a1 Mon Sep 17 00:00:00 2001 From: Marcus Date: Wed, 26 Feb 2020 22:02:18 -0500 Subject: [PATCH] identities --- api/identity.js | 10 +++++++++- api/index.js | 9 ++------- index.js | 2 +- src/{identities.js => identity.js} | 11 +++++++++-- 4 files changed, 21 insertions(+), 11 deletions(-) rename src/{identities.js => identity.js} (84%) diff --git a/api/identity.js b/api/identity.js index 2230776..9432b89 100644 --- a/api/identity.js +++ b/api/identity.js @@ -1,9 +1,17 @@ const express = require('express'); const { Router } = express; 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) => { - console.log(req); + console.log(req.param.guid); + res.json({}); }) module.exports = router; \ No newline at end of file diff --git a/api/index.js b/api/index.js index ba9b635..fcb914a 100644 --- a/api/index.js +++ b/api/index.js @@ -2,19 +2,14 @@ const express = require('express'); const { Router } = express; const api = new Router() -api.use('/identity', ) - api.get('/', (req, res) => { res.json({ up: true, time: new Date().getTime(), - identities: [ - { - name: 'example' - } - ] + identity: '/identity' }) }) +api.use('/identity', require('./identity.js')) module.exports = api; \ No newline at end of file diff --git a/index.js b/index.js index 63c2afb..30bbb52 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ const express = require('express'); const app = express(); const api = require('./api'); -app.use('/api ', api); +app.use('/api', api); app.listen(6565); diff --git a/src/identities.js b/src/identity.js similarity index 84% rename from src/identities.js rename to src/identity.js index 841ee8f..69c5721 100644 --- a/src/identities.js +++ b/src/identity.js @@ -34,7 +34,8 @@ async function getAllIdentities() { identities.find({}, (err, docs) => { const names = docs.reduce((acc, obj) => { if(obj._id in acc) return acc; - else acc[obj._id] = obj.name; + acc[obj._id] = obj.name; + return acc; }, {}); res(names); }) @@ -46,4 +47,10 @@ module.exports = { get: Object.assign(getIdentity, { all: getAllIdentities }) -} \ No newline at end of file +}; + +(async function() { + if(Object.keys(await getAllIdentities()).length === 0) { + createIdentity('Default'); + } +})(); \ No newline at end of file