Add /api/v2/user/...

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-06-20 19:51:15 +01:00
parent a4d82b0aa7
commit eb80d7386e
5 changed files with 36 additions and 3 deletions

2
app.js
View File

@ -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

View File

@ -1,6 +1,6 @@
const version = {
api: ['/api/v1/','/api/v2'],
app: '2023.6.10'
app: '2023.6.11'
};
module.exports = version;

View File

@ -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
};

View File

@ -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;

View File

@ -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
};