Create Job Offer, not complete yet

This commit is contained in:
xfarrow 2024-03-18 12:20:19 +01:00
parent 8543b0db52
commit 9cd0ba795d
7 changed files with 136 additions and 2 deletions

View File

@ -24,6 +24,7 @@ const personRoutes = require('./routes/person_routes.js');
const organizationRoutes = require('./routes/organization_routes.js');
const organizationAdminRoutes = require('./routes/organization_admin_routes.js');
const organizationPostRoutes = require('./routes/organization_post_routes.js');
const jobOffersRoutes = require('./routes/job_offer_routes.js');
/*
===== END IMPORTING MODULES =====
@ -59,6 +60,7 @@ app.use('/api', personRoutes.protectedRoutes);
app.use('/api', organizationRoutes.protectedRoutes);
app.use('/api', organizationAdminRoutes.protectedRoutes);
app.use('/api', organizationPostRoutes.protectedRoutes);
app.use('/api', jobOffersRoutes.protectedRoutes);
/*
===== END ROUTE HANDLING =====

View File

@ -0,0 +1,37 @@
/*
This code is part of Blink
licensed under GPLv3
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
const knex = require('../utils/knex_config');
const OrganizationAdmin = require('../models/organization_admin_model');
async function insert(requester, organizationId, title, description, requirements, salary, salary_frequency, location) {
const isAdmin = OrganizationAdmin.isAdmin(requester, organizationId);
if (isAdmin) {
const result = await knex('JobOffer').insert({
title,
description,
requirements,
salary,
salary_frequency,
location,
organization_id: organizationId
})
.returning('*');
return result[0];
}
return null;
}
module.exports = {
insert
}

View File

@ -30,7 +30,7 @@ async function isAdmin(personId, organizationId) {
}
/**
* Add the specified Person as the Organization administrator, if thr requester is already
* Add the specified Person as the Organization administrator, if the requester is already
* an administrator
* @param {*} personId Id of the person to add as administrator
* @param {*} organizationId
@ -88,7 +88,7 @@ async function remove(personId, organizationId) {
}
module.exports = {
isOrganizationAdmin: isAdmin,
isAdmin,
insert,
remove
};

View File

@ -0,0 +1,54 @@
/*
This code is part of Blink
licensed under GPLv3
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
const JobOffer = require('../models/job_offer_model');
const jwtUtils = require('../utils/jwt_utils');
const express = require('express');
async function insert(req, res) {
try {
const insertedJobOffer = await JobOffer.insert(
req.jwt.person_id,
req.body.organization_id,
req.body.title,
req.body.description,
req.body.requirements,
req.body.salary,
req.body.salary_frequency,
req.body.location);
console.log(insertedJobOffer);
if (insertedJobOffer) {
res.set('Location', `/api/joboffers/${insertedJobOffer.id}`);
return res.status(201).json(insertedJobOffer);
} else {
return res.status(401).json({
error: 'Forbidden'
});
}
} catch (error) {
console.error(`Error in function ${insert.name}: ${error}`);
res.status(500).json({
error: 'Internal server error'
});
}
}
const protectedRoutes = express.Router(); // Routes requiring token
protectedRoutes.use(jwtUtils.verifyToken);
protectedRoutes.post('/joboffers', insert);
module.exports = {
protectedRoutes
}

15
backend/sql/7-tag.sql Normal file
View File

@ -0,0 +1,15 @@
-- Table: public.Tag
-- DROP TABLE IF EXISTS public."Tag";
CREATE TABLE IF NOT EXISTS public."Tag"
(
id SERIAL,
tag character varying(256) NOT NULL,
CONSTRAINT "Tag_pkey" PRIMARY KEY (id)
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."Tag"
OWNER to postgres;

View File

@ -0,0 +1,26 @@
-- Table: public.JobOffer
-- DROP TABLE IF EXISTS public."JobOffer";
CREATE TABLE IF NOT EXISTS public."JobOffer"
(
id SERIAL,
title character varying(2048) NOT NULL,
description character varying(4096),
requirements character varying(4096),
salary money NOT NULL,
salary_frequency character varying(64) NOT NULL,
location character varying(256),
organization_id integer,
CONSTRAINT "JobOffer_pkey" PRIMARY KEY (id),
CONSTRAINT "OrganizationFK" FOREIGN KEY (organization_id)
REFERENCES public."Organization" (id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE
NOT VALID
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."JobOffer"
OWNER to postgres;

Binary file not shown.