mirror of
https://github.com/xfarrow/blink
synced 2025-02-19 08:30:36 +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 knex = require('../utils/knex_config');
|
||||||
const OrganizationAdmin = require('../models/organization_admin_model');
|
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);
|
const isAdmin = OrganizationAdmin.isAdmin(requester, organizationId);
|
||||||
if (isAdmin) {
|
if (isAdmin) {
|
||||||
const result = await knex('JobOffer').insert({
|
return await knex.transaction(async (tr) => {
|
||||||
|
const jobOffer = await tr('JobOffer').insert({
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
requirements,
|
requirements,
|
||||||
salary,
|
salary,
|
||||||
salary_frequency,
|
salary_frequency: salaryFrequency,
|
||||||
location,
|
location,
|
||||||
organization_id: organizationId
|
organization_id: organizationId,
|
||||||
|
salary_currency: salaryCurrency
|
||||||
})
|
})
|
||||||
.returning('*');
|
.returning('*');
|
||||||
return result[0];
|
|
||||||
|
// 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;
|
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 = {
|
module.exports = {
|
||||||
insert
|
insert
|
||||||
}
|
}
|
@ -19,13 +19,15 @@ async function insert(req, res) {
|
|||||||
try {
|
try {
|
||||||
const insertedJobOffer = await JobOffer.insert(
|
const insertedJobOffer = await JobOffer.insert(
|
||||||
req.jwt.person_id,
|
req.jwt.person_id,
|
||||||
req.body.organization_id,
|
req.params.id, // organization id
|
||||||
req.body.title,
|
req.body.title,
|
||||||
req.body.description,
|
req.body.description,
|
||||||
req.body.requirements,
|
req.body.requirements,
|
||||||
req.body.salary,
|
req.body.salary,
|
||||||
req.body.salary_frequency,
|
req.body.salary_frequency,
|
||||||
req.body.location);
|
req.body.salary_currency,
|
||||||
|
req.body.location,
|
||||||
|
req.body.tags);
|
||||||
|
|
||||||
if (insertedJobOffer) {
|
if (insertedJobOffer) {
|
||||||
res.set('Location', `/api/joboffers/${insertedJobOffer.id}`);
|
res.set('Location', `/api/joboffers/${insertedJobOffer.id}`);
|
||||||
@ -45,7 +47,7 @@ async function insert(req, res) {
|
|||||||
|
|
||||||
const protectedRoutes = express.Router(); // Routes requiring token
|
const protectedRoutes = express.Router(); // Routes requiring token
|
||||||
protectedRoutes.use(jwtUtils.verifyToken);
|
protectedRoutes.use(jwtUtils.verifyToken);
|
||||||
protectedRoutes.post('/joboffers', insert);
|
protectedRoutes.post('/organizations/:id/joboffers', insert);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
protectedRoutes
|
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