mirror of https://github.com/xfarrow/blink
update
This commit is contained in:
parent
072d659425
commit
86bb9717d8
|
@ -54,13 +54,14 @@ app.use(rateLimit({
|
|||
===== BEGIN ROUTE HANDLING =====
|
||||
*/
|
||||
|
||||
app.use('/api', personRoutes.publicRoutes);
|
||||
app.use('/api', organizationRoutes.publicRoutes);
|
||||
app.use('/api', personRoutes.protectedRoutes);
|
||||
app.use('/api', organizationRoutes.protectedRoutes);
|
||||
app.use('/api', organizationAdminRoutes.protectedRoutes);
|
||||
app.use('/api', organizationPostRoutes.protectedRoutes);
|
||||
// app.use('/api', personRoutes.publicRoutes);
|
||||
// app.use('/api', personRoutes.protectedRoutes);
|
||||
app.use('/api', jobOffersRoutes.publicRoutes);
|
||||
app.use('/api', jobOffersRoutes.protectedRoutes);
|
||||
app.use('/api', organizationRoutes.publicRoutes);
|
||||
app.use('/api', organizationRoutes.protectedRoutes);
|
||||
// app.use('/api', organizationPostRoutes.protectedRoutes);
|
||||
// app.use('/api', organizationAdminRoutes.protectedRoutes);
|
||||
|
||||
/*
|
||||
===== END ROUTE HANDLING =====
|
||||
|
|
|
@ -72,6 +72,14 @@ async function findById(jobOfferId) {
|
|||
}).select().first();
|
||||
}
|
||||
|
||||
async function findByOrganizationId(organizationId){
|
||||
const result = await knex('JobOffer')
|
||||
.where({organization_id: organizationId})
|
||||
.select();
|
||||
console.log(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
// test
|
||||
async function filter(title, description, requirements, salary, salaryOperator, salaryFrequency, location, tags) {
|
||||
let query = knex('JobOffer');
|
||||
|
@ -105,5 +113,6 @@ async function filter(title, description, requirements, salary, salaryOperator,
|
|||
|
||||
module.exports = {
|
||||
insert,
|
||||
remove
|
||||
remove,
|
||||
findByOrganizationId
|
||||
}
|
|
@ -80,11 +80,33 @@ async function remove(req, res) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET Request
|
||||
* @param {*} req
|
||||
* @param {*} res
|
||||
* @returns
|
||||
*/
|
||||
async function findByOrganizationId(req, res) {
|
||||
try {
|
||||
const result = await JobOffer.findByOrganizationId(req.params.id);
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
console.error(`Error in function ${insert.name}: ${error}`);
|
||||
res.status(500).json({
|
||||
error: 'Internal server error'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const publicRoutes = express.Router();
|
||||
publicRoutes.get('/organizations/:id/joboffers', findByOrganizationId);
|
||||
|
||||
const protectedRoutes = express.Router();
|
||||
protectedRoutes.use(jwtUtils.verifyToken);
|
||||
protectedRoutes.post('/organizations/:id/joboffers', insert);
|
||||
protectedRoutes.delete('/organizations/joboffers/:jobOfferId', remove);
|
||||
|
||||
module.exports = {
|
||||
publicRoutes,
|
||||
protectedRoutes
|
||||
}
|
|
@ -38,14 +38,14 @@
|
|||
alert("Invalid URL.");
|
||||
return;
|
||||
}
|
||||
const response = await fetch(`${API_URL}/organization/${idToDisplay}`, {
|
||||
const response = await fetch(`${API_URL}/organizations/${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);
|
||||
populateFields(data.name, data.location, data.description, isOrganizationHiring(idToDisplay));
|
||||
document.body.style.display = "block"; // Show page
|
||||
} else {
|
||||
alert(data.error);
|
||||
|
@ -67,6 +67,16 @@
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
async function isOrganizationHiring(organizationId) {
|
||||
const response = await fetch(`${API_URL}/organizations/${organizationId}/joboffers`, {
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8",
|
||||
}
|
||||
});
|
||||
const data = await response.json();
|
||||
return data.length > 0;
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
|
Loading…
Reference in New Issue