mirror of
https://github.com/xfarrow/blink
synced 2025-02-18 08:20:36 +01:00
add getMyself
This commit is contained in:
parent
a31e6b4c66
commit
468ca5224c
@ -35,6 +35,7 @@ publicRoutes.post('/login', apiController.login);
|
|||||||
const protectedRoutes = express.Router();
|
const protectedRoutes = express.Router();
|
||||||
protectedRoutes.use(apiController.verifyToken);
|
protectedRoutes.use(apiController.verifyToken);
|
||||||
protectedRoutes.get('/person/:id', apiController.getPerson);
|
protectedRoutes.get('/person/:id', apiController.getPerson);
|
||||||
|
protectedRoutes.get('/person/myself', apiController.getMyself);
|
||||||
protectedRoutes.put('/person/:id', apiController.updatePerson);
|
protectedRoutes.put('/person/:id', apiController.updatePerson);
|
||||||
protectedRoutes.delete('/person/delete', apiController.deletePerson);
|
protectedRoutes.delete('/person/delete', apiController.deletePerson);
|
||||||
protectedRoutes.post('/organization/admin', apiController.addOrganizationAdmin);
|
protectedRoutes.post('/organization/admin', apiController.addOrganizationAdmin);
|
||||||
|
@ -140,7 +140,7 @@ async function getPerson(req, res){
|
|||||||
try {
|
try {
|
||||||
const user = await knex('Person')
|
const user = await knex('Person')
|
||||||
.select('*')
|
.select('*')
|
||||||
.where({ id: req.params.id, enabled: true })
|
.where({ id: req.params.id })
|
||||||
.first();
|
.first();
|
||||||
|
|
||||||
if(user){
|
if(user){
|
||||||
@ -158,6 +158,33 @@ async function getPerson(req, res){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* GET Request
|
||||||
|
*
|
||||||
|
* Get myself, from the JWT token
|
||||||
|
*
|
||||||
|
* @returns Person's details
|
||||||
|
*/
|
||||||
|
async function getMyself(req, res){
|
||||||
|
try{
|
||||||
|
const person = await knex('Person')
|
||||||
|
.select('*')
|
||||||
|
.where({ id: req.jwt.person_id })
|
||||||
|
.first();
|
||||||
|
|
||||||
|
if(person){
|
||||||
|
delete person['password'];
|
||||||
|
return res.status(200).send(person);
|
||||||
|
}
|
||||||
|
return res.status(404).json({error: "Not found"});
|
||||||
|
}
|
||||||
|
catch (error){
|
||||||
|
console.log("Error while getting myself: " + error);
|
||||||
|
return res.status(500).json({error : "Internal server error"});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PUT request
|
* PUT request
|
||||||
*
|
*
|
||||||
@ -243,6 +270,8 @@ async function deletePerson(req, res) {
|
|||||||
.where({id : req.jwt.person_id})
|
.where({id : req.jwt.person_id})
|
||||||
.del();
|
.del();
|
||||||
return res.status(200).json({success: true});
|
return res.status(200).json({success: true});
|
||||||
|
|
||||||
|
// TODO: Delete Organization if this user was its only administrator
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.log("Error deleting a Person: " + error);
|
console.log("Error deleting a Person: " + error);
|
||||||
@ -687,6 +716,7 @@ module.exports = {
|
|||||||
registerPerson,
|
registerPerson,
|
||||||
login,
|
login,
|
||||||
getPerson,
|
getPerson,
|
||||||
|
getMyself,
|
||||||
updatePerson,
|
updatePerson,
|
||||||
deletePerson,
|
deletePerson,
|
||||||
verifyToken,
|
verifyToken,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user