mirror of https://github.com/xfarrow/blink
Delete a organization's post
This commit is contained in:
parent
ea5413d2e2
commit
2beb0fd266
|
@ -23,6 +23,7 @@ app.get('/blinkapi/person/:id', api_controller.verifyToken, api_controller.getPe
|
|||
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.post('/blinkapi/organization/post', api_controller.verifyToken, api_controller.createOrganizationPost); // Create a organization's post
|
||||
app.delete('/blinkapi/organization/post/:id', api_controller.verifyToken, api_controller.deleteOrganizationPost); // Delete a organization's post
|
||||
|
||||
// Start the server
|
||||
app.listen(process.env.API_SERVER_PORT, () => {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
*/
|
||||
const bcrypt = require('bcrypt');
|
||||
const crypto = require('crypto');
|
||||
const pgp = require('pg-promise')();
|
||||
const pgp = require('pg-promise')(); // In the future I'd like to use knex.js to avoid raw sql
|
||||
const jwt = require('jsonwebtoken');
|
||||
require('dotenv').config();
|
||||
|
||||
|
@ -116,11 +116,11 @@ async function getPerson(req, res){
|
|||
return res.status(200).send(user);
|
||||
}
|
||||
}
|
||||
return res.status(403);
|
||||
return res.status(403).json("Forbidden");
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error);
|
||||
return res.status(500);
|
||||
return res.status(500).json("Internal server error");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ async function deleteOrganization(req, res){
|
|||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500);
|
||||
return res.status(500).json("Internal server error");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,6 +216,30 @@ async function createOrganizationPost(req, res){
|
|||
}
|
||||
}
|
||||
|
||||
// DELETE
|
||||
async function deleteOrganizationPost(req, res){
|
||||
const organizationPostIdToDelete = req.params.id;
|
||||
try {
|
||||
if(await db.oneOrNone(' SELECT *' +
|
||||
' FROM "OrganizationPost"' +
|
||||
' JOIN "OrganizationAdministrator"' +
|
||||
' ON "OrganizationPost".organization_id = "OrganizationAdministrator".id_organization' +
|
||||
' WHERE "OrganizationPost".id = $1 and "OrganizationAdministrator".id_person = $2',
|
||||
[organizationPostIdToDelete, req.jwt.person_id])){
|
||||
await db.none('DELETE FROM "OrganizationPost" WHERE id = $1', [organizationPostIdToDelete]);
|
||||
return res.status(200).json("Ok");
|
||||
}
|
||||
else{
|
||||
return res.status(403).json("Forbidden");
|
||||
}
|
||||
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).json("Internal server error");
|
||||
}
|
||||
}
|
||||
|
||||
// ======== END API ENDPOINTS ========
|
||||
|
||||
async function checkUserCredentials(email, password){
|
||||
|
@ -285,5 +309,6 @@ module.exports = {
|
|||
verifyToken,
|
||||
createOrganization,
|
||||
deleteOrganization,
|
||||
createOrganizationPost
|
||||
createOrganizationPost,
|
||||
deleteOrganizationPost
|
||||
};
|
Loading…
Reference in New Issue