v2 user routes complete
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
eb80d7386e
commit
72444e9fc9
@ -1,4 +1,5 @@
|
||||
const statusCodes = {
|
||||
400: 'data not found',
|
||||
700: 'no authentication attempt',
|
||||
701: 'invalid credentials',
|
||||
702: 'domain not whitelisted',
|
||||
@ -6,7 +7,9 @@ const statusCodes = {
|
||||
800: 'location code not found',
|
||||
801: 'unable to fetch location data',
|
||||
900: 'invalid request format',
|
||||
901: 'email not provided',
|
||||
950: 'upstream server error',
|
||||
951: 'unknown server error'
|
||||
};
|
||||
|
||||
module.exports = statusCodes;
|
@ -23,7 +23,12 @@ async function request(req, res, next) {
|
||||
async function getUser(req, res, next) {
|
||||
try {
|
||||
let uuid = req.params.uuid;
|
||||
res.json(await reg.getUser(uuid));
|
||||
let data = await reg.getUser(uuid);
|
||||
if (data.status) {
|
||||
res.status(data.status).json(data);
|
||||
} else {
|
||||
res.json(data);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
next(err);
|
||||
|
@ -4,6 +4,7 @@ const regCtr = require('../controllers/registration.controllers');
|
||||
|
||||
// User
|
||||
router.get('/:uuid', regCtr.getUser);
|
||||
// Not Implemented router.delete('/:uuid', regCtr.deleteUser);
|
||||
router.post('/request', regCtr.request);
|
||||
router.post('/register', regCtr.register);
|
||||
|
||||
|
@ -8,10 +8,11 @@ const errors = require('../configs/errorCodes.configs');
|
||||
|
||||
async function createRegKey(body) {
|
||||
log.out('registerServices.createRegKey: Incoming request', 'INFO');
|
||||
if (body.email) {
|
||||
const domain = await clean.getDomainFromEmail(body.email);
|
||||
log.out(`registerServices: Registration request from: ${domain}`, 'info');
|
||||
if (domains.includes(domain)) {
|
||||
log.out(`registerServices.createRegKey: Key from valid domain: ${domain}`);
|
||||
log.out(`registerServices.createRegKey: Key from valid: ${domain}`,'info');
|
||||
const uuid = await auth.generateKey();
|
||||
db.addRegReq(uuid, domain);
|
||||
const message = await auth.generateConfirmationEmail(body.email, uuid);
|
||||
@ -27,6 +28,9 @@ async function createRegKey(body) {
|
||||
return {status: 500, errorCode: 950, errorMsg: errors[950]};
|
||||
}
|
||||
return {status: 403, errorCode: 702, errorMsg: errors[702]};
|
||||
} else {
|
||||
return {status: 400, errorCode: 901, errorMsg: errors[902]};
|
||||
}
|
||||
}
|
||||
|
||||
async function regUser(req) { // Add input validation
|
||||
@ -47,11 +51,20 @@ async function regUser(req) { // Add input validation
|
||||
|
||||
async function getUser(uuid) {
|
||||
log.out('registrationServices: Finding user for given UUID', 'dbug');
|
||||
try {
|
||||
const filter = {
|
||||
uuid: uuid
|
||||
};
|
||||
const res = await db.query('users', filter, false);
|
||||
if (res.length) {
|
||||
return res;
|
||||
} else {
|
||||
return {status: 404, errorCode:400, errorMsg: errors[400]};
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
return {status: 500, errorCode: 951, errorMsg: errors[951]};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
Loading…
Reference in New Issue
Block a user