mirror of
https://github.com/xfarrow/blink
synced 2025-02-18 08:20:36 +01:00
Create Job Offer, not complete yet
This commit is contained in:
parent
8543b0db52
commit
9cd0ba795d
@ -24,6 +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 jobOffersRoutes = require('./routes/job_offer_routes.js');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
===== END IMPORTING MODULES =====
|
===== END IMPORTING MODULES =====
|
||||||
@ -59,6 +60,7 @@ app.use('/api', personRoutes.protectedRoutes);
|
|||||||
app.use('/api', organizationRoutes.protectedRoutes);
|
app.use('/api', organizationRoutes.protectedRoutes);
|
||||||
app.use('/api', organizationAdminRoutes.protectedRoutes);
|
app.use('/api', organizationAdminRoutes.protectedRoutes);
|
||||||
app.use('/api', organizationPostRoutes.protectedRoutes);
|
app.use('/api', organizationPostRoutes.protectedRoutes);
|
||||||
|
app.use('/api', jobOffersRoutes.protectedRoutes);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
===== END ROUTE HANDLING =====
|
===== END ROUTE HANDLING =====
|
||||||
|
37
backend/apis/nodejs/src/models/job_offer_model.js
Normal file
37
backend/apis/nodejs/src/models/job_offer_model.js
Normal 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
|
||||||
|
}
|
@ -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
|
* an administrator
|
||||||
* @param {*} personId Id of the person to add as administrator
|
* @param {*} personId Id of the person to add as administrator
|
||||||
* @param {*} organizationId
|
* @param {*} organizationId
|
||||||
@ -88,7 +88,7 @@ async function remove(personId, organizationId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
isOrganizationAdmin: isAdmin,
|
isAdmin,
|
||||||
insert,
|
insert,
|
||||||
remove
|
remove
|
||||||
};
|
};
|
54
backend/apis/nodejs/src/routes/job_offer_routes.js
Normal file
54
backend/apis/nodejs/src/routes/job_offer_routes.js
Normal 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
15
backend/sql/7-tag.sql
Normal 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;
|
26
backend/sql/8-create_job_offer.sql
Normal file
26
backend/sql/8-create_job_offer.sql
Normal 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;
|
BIN
backend/sql/InsertIntoTag.7z
Normal file
BIN
backend/sql/InsertIntoTag.7z
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user