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 e18e361
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion app/routes/graphkb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ const express = require('express');

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 +63,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 e18e361

Please sign in to comment.