Delete User

This commit is contained in:
xfarrow 2023-10-17 11:50:03 +02:00
parent f43f76c7ec
commit 29be3b7658
3 changed files with 20 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@ -20,6 +20,7 @@ app.use(express.json()); // Middleware which parses JSON for POST requests
app.post('/blinkapi/register', api_controller.registerPerson); // Register a Person app.post('/blinkapi/register', api_controller.registerPerson); // Register a Person
app.post('/blinkapi/login', api_controller.login); // Login app.post('/blinkapi/login', api_controller.login); // Login
app.get('/blinkapi/person/:id', api_controller.verifyToken, api_controller.getPerson); // Obtain Person's details app.get('/blinkapi/person/:id', api_controller.verifyToken, api_controller.getPerson); // Obtain Person's details
app.delete('/blinkapi/person/:id', api_controller.verifyToken, api_controller.deletePerson); // Delete a Person
app.post('/blinkapi/organization', api_controller.verifyToken, api_controller.createOrganization); // Create organization app.post('/blinkapi/organization', api_controller.verifyToken, api_controller.createOrganization); // Create organization
app.delete('/blinkapi/organization/:id', api_controller.verifyToken, api_controller.deleteOrganization); // Delete organization app.delete('/blinkapi/organization/:id', api_controller.verifyToken, api_controller.deleteOrganization); // Delete organization
app.post('/blinkapi/organization/post', api_controller.verifyToken, api_controller.createOrganizationPost); // Create a organization's post app.post('/blinkapi/organization/post', api_controller.verifyToken, api_controller.createOrganizationPost); // Create a organization's post

View File

@ -117,6 +117,24 @@ async function getPerson(req, res){
} }
} }
// GET
async function deletePerson(req, res){
if(req.params.id != req.jwt.person_id){
return res.status(403).json({error: "Forbidden"});
}
try {
await knex('Person')
.where({id : req.jwt.person_id})
.del();
return res.status(200).json({success: true});
} catch (error) {
console.log("Error deleting a Person: " + error);
return res.status(500).json({error : "Internal server error"});
}
}
// POST // POST
async function createOrganization(req, res){ async function createOrganization(req, res){
@ -318,6 +336,7 @@ module.exports = {
registerPerson, registerPerson,
login, login,
getPerson, getPerson,
deletePerson,
verifyToken, verifyToken,
createOrganization, createOrganization,
deleteOrganization, deleteOrganization,