From 9ad2adc5105506244b54557a52734b73004e381a Mon Sep 17 00:00:00 2001 From: Marcus Date: Wed, 26 Feb 2020 22:50:10 -0500 Subject: [PATCH] individual identity GET --- api/identity.js | 7 ++++--- src/identity.js | 23 ++++++++++++----------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/api/identity.js b/api/identity.js index 9432b89..adecc0a 100644 --- a/api/identity.js +++ b/api/identity.js @@ -9,9 +9,10 @@ router.get('/', async (req, res) => { }); }); -router.get('/:guid', (req, res) => { - console.log(req.param.guid); - res.json({}); +router.get('/:uid', async (req, res) => { + const uid = req.params.uid; + const _return = await identity.get(uid); + res.json(_return); }) module.exports = router; \ No newline at end of file diff --git a/src/identity.js b/src/identity.js index 69c5721..74ecc84 100644 --- a/src/identity.js +++ b/src/identity.js @@ -12,21 +12,22 @@ async function createIdentity(name) { await new Promise(res => { identities.insert({ name, - type: 'public', - key: pair.exportKey('pkcs1-public-pem') - }, res); - }) - await new Promise(res => { - identities.insert({ - name, - type: 'private', - key: pair.exportKey('pkcs1-private-pem') + public: pair.exportKey('pkcs1-public-pem'), + private: pair.exportKey('pkcs1-private-pem') }, res); }); } -async function getIdentity() { - +async function getIdentity(uid) { + return await new Promise((res, rej) => { + identities.findOne({ + _id: uid + }, (err, doc) => { + if(err || !doc) return rej(err); + delete doc.private; + res(doc); + }) + }); } async function getAllIdentities() {