Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:NIAEFEUP/nijobs-be into 224-conf…
Browse files Browse the repository at this point in the history
…irmation-email-when-companies-register
  • Loading branch information
FranciscoCardoso913 committed Mar 13, 2024
2 parents 46d86fd + 82886d0 commit df467c5
Show file tree
Hide file tree
Showing 7 changed files with 746 additions and 6,595 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/
7,238 changes: 684 additions & 6,554 deletions package-lock.json

Large diffs are not rendered by default.

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,8 +131,6 @@ 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),
]);

export const getApplication = useExpressValidators([
Expand Down
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 @@ -248,7 +248,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 @@ -273,10 +273,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 @@ -296,26 +298,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 @@ -338,10 +350,12 @@ class OfferService {
{
"$and": [
{ jobMinDuration: { "$lt": jobMinDuration } },
{ "$or": [
{ jobMaxDuration: { "$exists": false } },
{ jobMaxDuration: { "$gte": jobMinDuration } },
] }
{
"$or": [
{ jobMaxDuration: { "$exists": false } },
{ jobMaxDuration: { "$gte": jobMinDuration } },
]
}
]
},
]
Expand All @@ -355,17 +369,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 df467c5

Please sign in to comment.