Skip to content

Commit

Permalink
feat: add POST route to gkb user creation
Browse files Browse the repository at this point in the history
DEVSU-2468
  • Loading branch information
kttkjl committed Nov 27, 2024
1 parent f0d452f commit 031c5a6
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion app/routes/graphkb/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
const {StatusCodes} = require('http-status-codes');
const express = require('express');
const jwt = require('jsonwebtoken');

Check failure on line 3 in app/routes/graphkb/index.js

View workflow job for this annotation

GitHub Actions / eslint

'jwt' is assigned a value but never used

const logger = require('../../log');
const loginMiddleware = require('../../middleware/graphkb');
const {graphkbAutocomplete, graphkbEvidenceLevels, graphkbStatement} = require('../../api/graphkb');
const {
graphkbAutocomplete,
graphkbEvidenceLevels,
graphkbStatement,
graphkbAddUser,
graphkbGetReadonlyGroupId,
} = require('../../api/graphkb');

const router = express.Router({mergeParams: true});

Expand Down Expand Up @@ -57,4 +64,21 @@ router.get('/statements/:statementId', async (req, res) => {
}
});

router.post('/new-user', async (req, res) => {
try {
const {graphkbToken, body: {email, username}} = req;
const groupId = await graphkbGetReadonlyGroupId(graphkbToken);
const gkbCreateResp = await graphkbAddUser(graphkbToken, username, email, groupId);
if (/error/i.test(gkbCreateResp.name)) {
throw new Error(gkbCreateResp.message);
}
return res.status(StatusCodes.CREATED).json();
} catch (error) {
logger.error(error);
return res.status(StatusCodes.SERVICE_UNAVAILABLE).json({
message: 'GraphKB user creation error',
});
}
});

module.exports = router;

0 comments on commit 031c5a6

Please sign in to comment.