mirror of
https://github.com/xfarrow/blink
synced 2025-02-14 07:50:34 +01:00
create job offer tag + some fixes
This commit is contained in:
parent
06a548eb55
commit
8fdef6f510
File diff suppressed because one or more lines are too long
@ -14,24 +14,68 @@
|
||||
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) {
|
||||
async function insert(requester, organizationId, title, description, requirements, salary, salaryFrequency, salaryCurrency, location, tags) {
|
||||
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 await knex.transaction(async (tr) => {
|
||||
const jobOffer = await tr('JobOffer').insert({
|
||||
title,
|
||||
description,
|
||||
requirements,
|
||||
salary,
|
||||
salary_frequency: salaryFrequency,
|
||||
location,
|
||||
organization_id: organizationId,
|
||||
salary_currency: salaryCurrency
|
||||
})
|
||||
.returning('*');
|
||||
|
||||
// Insert in the JobOfferTag table all the relevant tags.
|
||||
if (tags.length !== 0) {
|
||||
await Promise.all(tags.map(tagId =>
|
||||
tr('JobOfferTag').insert({
|
||||
job_offer_id: jobOffer[0].id,
|
||||
tag_id: tagId
|
||||
})
|
||||
));
|
||||
}
|
||||
return jobOffer[0];
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// test
|
||||
async function filter(title, description, requirements, salary, salaryOperator, salaryFrequency, location, tags) {
|
||||
let query = knex('JobOffer');
|
||||
if (title) {
|
||||
query.where('title', 'ilike', `%${title}%`); //ilike = insensitive like
|
||||
}
|
||||
if (description) {
|
||||
query.where('description', 'ilike', `%${description}%`);
|
||||
}
|
||||
if (requirements) {
|
||||
query.where('requirements', 'ilike', `%${requirements}%`);
|
||||
}
|
||||
if (salary && salaryOperator) {
|
||||
query.where('salary', salaryOperator, salary);
|
||||
}
|
||||
if (salaryFrequency) {
|
||||
query.where({
|
||||
salary_frequency: salaryFrequency
|
||||
});
|
||||
}
|
||||
if (location) {
|
||||
query.where('location', 'ilike', `%${location}%`);
|
||||
}
|
||||
if (tags) {
|
||||
tags.forEach((tag) => {
|
||||
// query = query.where({});
|
||||
});
|
||||
}
|
||||
return await query.select();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
insert
|
||||
}
|
@ -19,13 +19,15 @@ async function insert(req, res) {
|
||||
try {
|
||||
const insertedJobOffer = await JobOffer.insert(
|
||||
req.jwt.person_id,
|
||||
req.body.organization_id,
|
||||
req.params.id, // organization id
|
||||
req.body.title,
|
||||
req.body.description,
|
||||
req.body.requirements,
|
||||
req.body.salary,
|
||||
req.body.salary_frequency,
|
||||
req.body.location);
|
||||
req.body.salary_currency,
|
||||
req.body.location,
|
||||
req.body.tags);
|
||||
|
||||
if (insertedJobOffer) {
|
||||
res.set('Location', `/api/joboffers/${insertedJobOffer.id}`);
|
||||
@ -45,7 +47,7 @@ async function insert(req, res) {
|
||||
|
||||
const protectedRoutes = express.Router(); // Routes requiring token
|
||||
protectedRoutes.use(jwtUtils.verifyToken);
|
||||
protectedRoutes.post('/joboffers', insert);
|
||||
protectedRoutes.post('/organizations/:id/joboffers', insert);
|
||||
|
||||
module.exports = {
|
||||
protectedRoutes
|
||||
|
25
backend/sql/9-create_job_offer_tag.sql
Normal file
25
backend/sql/9-create_job_offer_tag.sql
Normal file
@ -0,0 +1,25 @@
|
||||
-- Table: public.JobOfferTag
|
||||
-- This table allows to create a N-to-N map between Tag and JobOffer
|
||||
|
||||
-- DROP TABLE IF EXISTS public."JobOfferTag";
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public."JobOfferTag"
|
||||
(
|
||||
id integer NOT NULL DEFAULT nextval('"JobOfferTag_id_seq"'::regclass),
|
||||
job_offer_id integer NOT NULL,
|
||||
tag_id integer NOT NULL,
|
||||
CONSTRAINT "JobOfferTag_pkey" PRIMARY KEY (id),
|
||||
CONSTRAINT "JobOfferFk" FOREIGN KEY (job_offer_id)
|
||||
REFERENCES public."JobOffer" (id) MATCH SIMPLE
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE,
|
||||
CONSTRAINT "TagFk" FOREIGN KEY (tag_id)
|
||||
REFERENCES public."Tag" (id) MATCH SIMPLE
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
)
|
||||
|
||||
TABLESPACE pg_default;
|
||||
|
||||
ALTER TABLE IF EXISTS public."JobOfferTag"
|
||||
OWNER to postgres;
|
Loading…
x
Reference in New Issue
Block a user