mirror of https://github.com/xfarrow/blink
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 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 =====
|
||||
|
|
|
@ -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
|
||||
* @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
|
||||
};
|
|
@ -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
|
||||
}
|
|
@ -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;
|
|
@ -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.
Loading…
Reference in New Issue