Show organization

This commit is contained in:
xfarrow 2024-02-29 12:20:08 +01:00
parent 69bc104b68
commit dacf750633
4 changed files with 49 additions and 19 deletions

View File

@ -24,7 +24,7 @@ const personRoutes = require('./routes/person_routes.js');
const organizationRoutes = require('./routes/organization_routes.js'); const organizationRoutes = require('./routes/organization_routes.js');
const organizationAdminRoutes = require('./routes/organization_admin_routes.js'); const organizationAdminRoutes = require('./routes/organization_admin_routes.js');
const organizationPostRoutes = require('./routes/organization_post_routes.js'); const organizationPostRoutes = require('./routes/organization_post_routes.js');
const jwt_utils = require('./utils/middleware_utils.js'); const jwtUtils = require('./utils/middleware_utils.js');
/* /*
===== END IMPORTING MODULES ===== END IMPORTING MODULES
@ -54,17 +54,17 @@ app.use(rateLimit({
const publicRoutes = express.Router(); const publicRoutes = express.Router();
publicRoutes.post('/register', personRoutes.registerPerson); publicRoutes.post('/register', personRoutes.registerPerson);
publicRoutes.post('/login', personRoutes.login); publicRoutes.post('/login', personRoutes.login);
publicRoutes.get('/person/:id/details', personRoutes.getPerson);
publicRoutes.get('/organization/:id', organizationRoutes.getOrganization);
const protectedRoutes = express.Router(); const protectedRoutes = express.Router();
protectedRoutes.use(jwt_utils.verifyToken); protectedRoutes.use(jwtUtils.verifyToken);
protectedRoutes.get('/person/myself', personRoutes.getMyself); protectedRoutes.get('/person/myself', personRoutes.getMyself);
protectedRoutes.get('/person/:id', personRoutes.getPerson);
protectedRoutes.put('/person/:id', personRoutes.updatePerson); protectedRoutes.put('/person/:id', personRoutes.updatePerson);
protectedRoutes.delete('/person/delete', personRoutes.deletePerson); protectedRoutes.delete('/person/delete', personRoutes.deletePerson);
protectedRoutes.post('/organization/admin', organizationAdminRoutes.addOrganizationAdmin); protectedRoutes.post('/organization/admin', organizationAdminRoutes.addOrganizationAdmin);
protectedRoutes.delete('/organization/removeadmin', organizationAdminRoutes.removeOrganizationAdmin); protectedRoutes.delete('/organization/removeadmin', organizationAdminRoutes.removeOrganizationAdmin);
protectedRoutes.post('/organization', organizationRoutes.createOrganization); protectedRoutes.post('/organization', organizationRoutes.createOrganization);
protectedRoutes.get('/organization/:id', organizationRoutes.getOrganization);
protectedRoutes.put('/organization/:id', organizationRoutes.updateOrganization); protectedRoutes.put('/organization/:id', organizationRoutes.updateOrganization);
protectedRoutes.delete('/organization/:id', organizationRoutes.deleteOrganization); protectedRoutes.delete('/organization/:id', organizationRoutes.deleteOrganization);
protectedRoutes.post('/organization/post', organizationPostRoutes.createOrganizationPost); protectedRoutes.post('/organization/post', organizationPostRoutes.createOrganizationPost);

View File

@ -108,12 +108,9 @@ async function login (req, res) {
async function getPerson (req, res) { async function getPerson (req, res) {
try { try {
const person = await personModel.getPersonById(req.params.id); const person = await personModel.getPersonById(req.params.id);
if (person) { if (person && person.enabled) {
// I am retrieving either myself or an enabled user delete person.password; // remove password field for security reasons
if (person.id == req.jwt.person_id || person.enabled) { return res.status(200).send(person);
delete person.password; // remove password field for security reasons
return res.status(200).send(person);
}
} }
return res.status(404).json({ error: 'Not found' }); return res.status(404).json({ error: 'Not found' });
} catch (error) { } catch (error) {

View File

@ -6,15 +6,15 @@
<title>Title</title> <title>Title</title>
<link rel="stylesheet" href="../css/organization.css"> <link rel="stylesheet" href="../css/organization.css">
</head> </head>
<body> <body style="display: none;">
<div class="container"> <div class="container">
<div class="hiring-badge">Now Hiring</div> <div class="hiring-badge" style="display: none;" id="isHiringBadge">Now Hiring</div>
<div class="logo-div"> <div class="logo-div">
<img class="logo" src="../content/blink-logo-small.jpg" alt="Company Logo"> <img class="logo" src="../content/blink-logo-small.jpg" alt="Company Logo">
</div> </div>
<h1>Blink</h1> <h1 id="organizationName">Blink</h1>
<div class="organization-details"> <div class="organization-details">
<p><b>Location: </b><label id="address">Naples, Italy</label></p> <p><b>Location: </b><label id="location">Naples, Italy</label></p>
<p><b>Email: </b><label id="email">contacts@blink-corporation.com</label></p> <p><b>Email: </b><label id="email">contacts@blink-corporation.com</label></p>
<p><b>Hiring: </b><label id="isHiring">Yes</label></p> <p><b>Hiring: </b><label id="isHiring">Yes</label></p>
</div> </div>
@ -30,8 +30,42 @@
loadOrganization(); loadOrganization();
}); });
function loadOrganization (){ async function loadOrganization (){
const idToDisplay = new URLSearchParams(window.location.search).get('id'); const idToDisplay = new URLSearchParams(window.location.search).get('id');
if(!idToDisplay){
alert("Invalid URL.");
return;
}
const response = await fetch(`${API_URL}/organization/${idToDisplay}`, {
headers: {
"Content-type": "application/json; charset=UTF-8",
}
});
const data = await response.json();
if(response.ok) {
populateFields(data.name, data.location, data.description, data.is_hiring);
document.body.style.display = "block"; // Show page
}
else {
alert(data.error);
}
}
function populateFields (name, location, description, isHiring) {
document.getElementById('organizationName').textContent = name;
document.getElementById('location').textContent = location;
document.getElementById('description').textContent = description;
if(isHiring === true) {
document.getElementById('isHiring').textContent = 'Yes';
document.getElementById('isHiringBadge').style.display = 'block';
}
else if (isHiring === false) {
document.getElementById('isHiring').textContent = 'No';
}
else {
document.getElementById('isHiring').textContent = 'Not specified';
}
} }
</script> </script>

View File

@ -46,7 +46,7 @@
<script> <script>
window.addEventListener("load", async function() { window.addEventListener("load", async function() {
await loadProfile(); loadProfile();
}); });
async function loadProfile (){ async function loadProfile (){
@ -55,7 +55,7 @@
let response; let response;
// Retrieving the logged in user's profile // Retrieving the logged in user's profile
if(idToDisplay === 'myself'){ if(!idToDisplay || idToDisplay === 'myself'){
const token = getCookie('token'); const token = getCookie('token');
// Check whether the token exists // Check whether the token exists
if(!token){ if(!token){
@ -69,8 +69,7 @@
}); });
} }
else { else {
// To implement response = await fetch(`${API_URL}/person/${idToDisplay}/details`, {
response = await fetch(`${API_URL}/person/${idToDisplay}`, {
headers: { headers: {
"Content-type": "application/json; charset=UTF-8", "Content-type": "application/json; charset=UTF-8",
} }