Skip to content

Commit

Permalink
Merge branch 'develop' into 299-custom-reason-for-application-rejection
Browse files Browse the repository at this point in the history
  • Loading branch information
jose-carlos-sousa authored Apr 9, 2024
2 parents 8992eff + 82886d0 commit f038ecc
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 41 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,6 @@ $RECYCLE.BIN/

# Ignore public folder
/static

# Ignore data dumps from MongoDB
dump/
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"babel-plugin-transform-import-meta": "^2.2.0",
"eslint": "^8.29.0",
"jest": "^29.3.1",
"nodemon": "^2.0.20",
"nodemon": "^3.0.1",
"npm-audit-helper": "^3.1.1",
"supertest": "^6.3.3"
},
Expand Down
3 changes: 3 additions & 0 deletions seed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

mongorestore --uri mongodb://localhost:27017
2 changes: 0 additions & 2 deletions src/api/middleware/validators/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,4 @@ export const edit = useExpressValidators([
.withMessage(ValidationReasons.ARRAY_SIZE(CompanyConstants.contacts.min_length, CompanyConstants.contacts.max_length)),
body("logo", ValidationReasons.DEFAULT)
.optional()
.isString().withMessage(ValidationReasons.STRING).bail()
.isURL().withMessage(ValidationReasons.URL),
]);
5 changes: 3 additions & 2 deletions src/api/routes/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { concurrentOffersNotExceeded } from "../middleware/validators/validatorU

import { or } from "../middleware/utils.js";

import * as fileMiddleware from "../middleware/files.js";
import * as fileMiddleware from "../middleware/files.js";
import OfferService from "../../services/offer.js";
import AccountService from "../../services/account.js";
import Offer from "../../models/Offer.js";
Expand Down Expand Up @@ -245,7 +245,8 @@ export default (app) => {
try {
const companyService = new CompanyService();
const offerService = new OfferService();
const company = await companyService.changeAttributes(req.params.companyId, req.body);
const logo = req.file && (req?.file?.url || `${config.webserver_host}/static/${req.file.filename}`);
const company = await companyService.changeAttributes(req.params.companyId, { ...req.body, logo });
await offerService.updateAllOffersByCompanyId(company);
return res.json(company);
} catch (err) {
Expand Down
88 changes: 52 additions & 36 deletions src/services/offer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import mongoose from "mongoose";
import Company from "../models/Company.js";
import Offer from "../models/Offer.js";
import Account from "../models/Account.js";
import EmailService from "../lib/emailService.js";
import { OFFER_DISABLED_NOTIFICATION } from "../email-templates/companyOfferDisabled.js";
import OfferConstants from "../models/constants/Offer.js";
import Company from "../models/Company.js";
import Offer from "../models/Offer.js";
import Account from "../models/Account.js";
import EmailService from "../lib/emailService.js";
import { OFFER_DISABLED_NOTIFICATION } from "../email-templates/companyOfferDisabled.js";
import OfferConstants from "../models/constants/Offer.js";
import CompanyConstants from "../models/constants/Company.js";
import base64url from "base64url";

Expand Down Expand Up @@ -271,10 +271,12 @@ class OfferService {
* Otherwise, use _buildSearchContinuationQuery().
*/
_buildInitialSearchQuery(value, showHidden, showAdminReason, filters) {
const offers = (value ? Offer.find({ "$and": [
this._buildFilterQuery(filters),
{ "$text": { "$search": value } }
] }, { score: { "$meta": "textScore" } }
const offers = (value ? Offer.find({
"$and": [
this._buildFilterQuery(filters),
{ "$text": { "$search": value } }
]
}, { score: { "$meta": "textScore" } }

) : Offer.find(this._buildFilterQuery(filters)));

Expand All @@ -294,26 +296,36 @@ class OfferService {
offers = Offer.aggregate([
{ $match: { $text: { $search: value } } },
{ $match: this._buildFilterQuery(filters) },
{ $addFields: {
score: { $meta: "textScore" },
adminReason: { $cond: [showAdminReason, "$adminReason", "$$REMOVE"] }
} },
{ $match: { "$or": [
{ score: { "$lt": lastOfferScore } },
{ score: lastOfferScore, [lastSortField]: { [sortFieldOperator]: lastSortValue } },
{ score: lastOfferScore, [lastSortField]: lastSortValue, _id: { "$gt": ObjectId(lastOfferId) } }
] } },
{
$addFields: {
score: { $meta: "textScore" },
adminReason: { $cond: [showAdminReason, "$adminReason", "$$REMOVE"] }
}
},
{
$match: {
"$or": [
{ score: { "$lt": lastOfferScore } },
{ score: lastOfferScore, [lastSortField]: { [sortFieldOperator]: lastSortValue } },
{ score: lastOfferScore, [lastSortField]: lastSortValue, _id: { "$gt": ObjectId(lastOfferId) } }
]
}
},
{ $match: Offer.filterCurrent() },
{ $match: showHidden ? {} : Offer.filterNonHidden() }
]);
} else {
offers = Offer.find({ "$and": [
this._buildFilterQuery(filters),
{ "$or": [
{ [lastSortField]: { [sortFieldOperator]: lastSortValue } },
{ [lastSortField]: lastSortValue, _id: { "$gt": ObjectId(lastOfferId) } }
] }
] });
offers = Offer.find({
"$and": [
this._buildFilterQuery(filters),
{
"$or": [
{ [lastSortField]: { [sortFieldOperator]: lastSortValue } },
{ [lastSortField]: lastSortValue, _id: { "$gt": ObjectId(lastOfferId) } }
]
}
]
});

this.selectSearchOffers(offers, showHidden, showAdminReason);
}
Expand All @@ -336,10 +348,12 @@ class OfferService {
{
"$and": [
{ jobMinDuration: { "$lt": jobMinDuration } },
{ "$or": [
{ jobMaxDuration: { "$exists": false } },
{ jobMaxDuration: { "$gte": jobMinDuration } },
] }
{
"$or": [
{ jobMaxDuration: { "$exists": false } },
{ jobMaxDuration: { "$gte": jobMinDuration } },
]
}
]
},
]
Expand All @@ -353,17 +367,19 @@ class OfferService {
{
"$and": [
{ jobMaxDuration: { "$gt": jobMaxDuration } },
{ "$or": [
{ jobMinDuration: { "$exists": false } },
{ jobMinDuration: { "$lte": jobMaxDuration } },
] }
{
"$or": [
{ jobMinDuration: { "$exists": false } },
{ jobMinDuration: { "$lte": jobMaxDuration } },
]
}
]
},
]
});
}
if (fields?.length) constraints.push({ fields: { "$elemMatch": { "$in": fields } } });
if (technologies?.length) constraints.push({ technologies: { "$elemMatch": { "$in": technologies } } });
if (fields?.length) constraints.push({ fields: { "$elemMatch": { "$in": fields } } });
if (technologies?.length) constraints.push({ technologies: { "$elemMatch": { "$in": technologies } } });

return constraints.length ? { "$and": constraints } : {};
}
Expand Down

0 comments on commit f038ecc

Please sign in to comment.