From eb80d7386e385eef0b25cd1cf383d8143dd88455 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Tue, 20 Jun 2023 19:51:15 +0100 Subject: [PATCH] Add /api/v2/user/... Signed-off-by: Fred Boniface --- app.js | 2 ++ src/configs/version.configs.js | 2 +- src/controllers/registration.controllers.js | 13 ++++++++++++- src/routes/user2.routes.js | 10 ++++++++++ src/services/registration.services.js | 12 +++++++++++- 5 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 src/routes/user2.routes.js diff --git a/app.js b/app.js index fd2873f..8a8f0a9 100644 --- a/app.js +++ b/app.js @@ -34,6 +34,7 @@ const pis2Rtr = require('./src/routes/pis2.routes'); // API Version 2 Routes const ref2Rtr = require('./src/routes/ref2.routes'); // API Version 2 Routes const live2Rtr = require('./src/routes/live2.routes'); // API Version 2 Routes const tt2Rtr = require('./src/routes/timetable2.routes'); // API Version 2 +const user2Rtr = require('./src/routes/user2.routes'); // API Version 2 Routes const miscRtr = require('./src/routes/misc.routes'); // Non-Public API Routes // Set Server Configurations @@ -71,6 +72,7 @@ app.use('/api/v2/pis', authenticate, pis2Rtr); // API Version 2 app.use('/api/v2/live', live2Rtr); // API Version 2 app.use('/api/v2/ref', ref2Rtr); // API Version 2 app.use('/api/v2/timetable', tt2Rtr); // API Version 2 +app.use('/api/v2/user', user2Rtr); // API Version 2 app.use('/misc', miscRtr); // Non public-api endpoints (Stats, Issue, etc.) // Unauthenticated Routes diff --git a/src/configs/version.configs.js b/src/configs/version.configs.js index 6586f50..1f1018d 100644 --- a/src/configs/version.configs.js +++ b/src/configs/version.configs.js @@ -1,6 +1,6 @@ const version = { api: ['/api/v1/','/api/v2'], - app: '2023.6.10' + app: '2023.6.11' }; module.exports = version; \ No newline at end of file diff --git a/src/controllers/registration.controllers.js b/src/controllers/registration.controllers.js index 7594b88..706755f 100644 --- a/src/controllers/registration.controllers.js +++ b/src/controllers/registration.controllers.js @@ -20,7 +20,18 @@ async function request(req, res, next) { } } +async function getUser(req, res, next) { + try { + let uuid = req.params.uuid; + res.json(await reg.getUser(uuid)); + } catch (err) { + console.error(err); + next(err); + } +} + module.exports = { register, - request + request, + getUser }; \ No newline at end of file diff --git a/src/routes/user2.routes.js b/src/routes/user2.routes.js new file mode 100644 index 0000000..c455f69 --- /dev/null +++ b/src/routes/user2.routes.js @@ -0,0 +1,10 @@ +const express = require('express'); +const router = express.Router(); +const regCtr = require('../controllers/registration.controllers'); + +// User +router.get('/:uuid', regCtr.getUser); +router.post('/request', regCtr.request); +router.post('/register', regCtr.register); + +module.exports = router; \ No newline at end of file diff --git a/src/services/registration.services.js b/src/services/registration.services.js index 6754bb7..24837f4 100644 --- a/src/services/registration.services.js +++ b/src/services/registration.services.js @@ -45,7 +45,17 @@ async function regUser(req) { // Add input validation return {status: 401, errorCode: 703, errorMsg: errors[703]}; } +async function getUser(uuid) { + log.out('registrationServices: Finding user for given UUID', 'dbug'); + const filter = { + uuid: uuid + }; + const res = await db.query('users', filter, false); + return res; +} + module.exports = { regUser, - createRegKey + createRegKey, + getUser }; \ No newline at end of file