mirror of
https://github.com/xfarrow/blink
synced 2025-06-27 09:03:02 +02:00
update
This commit is contained in:
@ -15,7 +15,7 @@ const knex = require('../utils/knex_config');
|
||||
const OrganizationAdmin = require('../models/organization_admin_model');
|
||||
|
||||
async function insert(requester, organizationId, title, description, requirements, salary, salaryFrequency, salaryCurrency, location, tags) {
|
||||
const isAdmin = OrganizationAdmin.isAdmin(requester, organizationId);
|
||||
const isAdmin = await OrganizationAdmin.isAdmin(requester, organizationId);
|
||||
if (isAdmin) {
|
||||
return await knex.transaction(async (tr) => {
|
||||
const jobOffer = await tr('JobOffer').insert({
|
||||
@ -32,10 +32,10 @@ async function insert(requester, organizationId, title, description, requirement
|
||||
|
||||
// Insert in the JobOfferTag table all the relevant tags.
|
||||
if (tags.length !== 0) {
|
||||
await Promise.all(tags.map(tagId =>
|
||||
await Promise.all(tags.map(tag =>
|
||||
tr('JobOfferTag').insert({
|
||||
job_offer_id: jobOffer[0].id,
|
||||
tag_id: tagId
|
||||
tag_id: tag.id
|
||||
})
|
||||
));
|
||||
}
|
||||
@ -45,6 +45,26 @@ async function insert(requester, organizationId, title, description, requirement
|
||||
return null;
|
||||
}
|
||||
|
||||
async function remove(requester, jobOfferId) {
|
||||
const jobOffer = await findById(jobOfferId);
|
||||
const isAdmin = await OrganizationAdmin.isAdmin(requester, jobOffer.organization_id);
|
||||
if (isAdmin) {
|
||||
const deletedRows = await knex('JobOffer')
|
||||
.where({
|
||||
id: jobOfferId
|
||||
}).del();
|
||||
return deletedRows === 1;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function findById(jobOfferId) {
|
||||
return await knex('JobOffer').where({
|
||||
id: jobOfferId
|
||||
}).select().first();
|
||||
}
|
||||
|
||||
// test
|
||||
async function filter(title, description, requirements, salary, salaryOperator, salaryFrequency, location, tags) {
|
||||
let query = knex('JobOffer');
|
||||
@ -77,5 +97,6 @@ async function filter(title, description, requirements, salary, salaryOperator,
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
insert
|
||||
insert,
|
||||
remove
|
||||
}
|
@ -119,5 +119,5 @@ module.exports = {
|
||||
createOrganization,
|
||||
insert,
|
||||
update,
|
||||
deleteOrganization: remove
|
||||
remove
|
||||
};
|
26
backend/apis/nodejs/src/models/tags_model.js
Normal file
26
backend/apis/nodejs/src/models/tags_model.js
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
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');
|
||||
|
||||
async function findByTags(tags) {
|
||||
tags = tags.map(tag => tag.toLowerCase());
|
||||
const result = await knex('Tag')
|
||||
.whereIn('tag', tags)
|
||||
.select();
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
findByTags
|
||||
}
|
Reference in New Issue
Block a user