Skip to content

Commit df467c5

Browse files
Merge branch 'develop' of github.com:NIAEFEUP/nijobs-be into 224-confirmation-email-when-companies-register
2 parents 46d86fd + 82886d0 commit df467c5

File tree

7 files changed

+746
-6595
lines changed

7 files changed

+746
-6595
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,6 @@ $RECYCLE.BIN/
159159

160160
# Ignore public folder
161161
/static
162+
163+
# Ignore data dumps from MongoDB
164+
dump/

package-lock.json

Lines changed: 684 additions & 6554 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"babel-plugin-transform-import-meta": "^2.2.0",
2929
"eslint": "^8.29.0",
3030
"jest": "^29.3.1",
31-
"nodemon": "^2.0.20",
31+
"nodemon": "^3.0.1",
3232
"npm-audit-helper": "^3.1.1",
3333
"supertest": "^6.3.3"
3434
},

seed.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
mongorestore --uri mongodb://localhost:27017

src/api/middleware/validators/company.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ export const edit = useExpressValidators([
131131
.withMessage(ValidationReasons.ARRAY_SIZE(CompanyConstants.contacts.min_length, CompanyConstants.contacts.max_length)),
132132
body("logo", ValidationReasons.DEFAULT)
133133
.optional()
134-
.isString().withMessage(ValidationReasons.STRING).bail()
135-
.isURL().withMessage(ValidationReasons.URL),
136134
]);
137135

138136
export const getApplication = useExpressValidators([

src/api/routes/company.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { concurrentOffersNotExceeded } from "../middleware/validators/validatorU
1313

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

16-
import * as fileMiddleware from "../middleware/files.js";
16+
import * as fileMiddleware from "../middleware/files.js";
1717
import OfferService from "../../services/offer.js";
1818
import AccountService from "../../services/account.js";
1919
import Offer from "../../models/Offer.js";
@@ -248,7 +248,8 @@ export default (app) => {
248248
try {
249249
const companyService = new CompanyService();
250250
const offerService = new OfferService();
251-
const company = await companyService.changeAttributes(req.params.companyId, req.body);
251+
const logo = req.file && (req?.file?.url || `${config.webserver_host}/static/${req.file.filename}`);
252+
const company = await companyService.changeAttributes(req.params.companyId, { ...req.body, logo });
252253
await offerService.updateAllOffersByCompanyId(company);
253254
return res.json(company);
254255
} catch (err) {

src/services/offer.js

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import mongoose from "mongoose";
2-
import Company from "../models/Company.js";
3-
import Offer from "../models/Offer.js";
4-
import Account from "../models/Account.js";
5-
import EmailService from "../lib/emailService.js";
6-
import { OFFER_DISABLED_NOTIFICATION } from "../email-templates/companyOfferDisabled.js";
7-
import OfferConstants from "../models/constants/Offer.js";
2+
import Company from "../models/Company.js";
3+
import Offer from "../models/Offer.js";
4+
import Account from "../models/Account.js";
5+
import EmailService from "../lib/emailService.js";
6+
import { OFFER_DISABLED_NOTIFICATION } from "../email-templates/companyOfferDisabled.js";
7+
import OfferConstants from "../models/constants/Offer.js";
88
import CompanyConstants from "../models/constants/Company.js";
99
import base64url from "base64url";
1010

@@ -273,10 +273,12 @@ class OfferService {
273273
* Otherwise, use _buildSearchContinuationQuery().
274274
*/
275275
_buildInitialSearchQuery(value, showHidden, showAdminReason, filters) {
276-
const offers = (value ? Offer.find({ "$and": [
277-
this._buildFilterQuery(filters),
278-
{ "$text": { "$search": value } }
279-
] }, { score: { "$meta": "textScore" } }
276+
const offers = (value ? Offer.find({
277+
"$and": [
278+
this._buildFilterQuery(filters),
279+
{ "$text": { "$search": value } }
280+
]
281+
}, { score: { "$meta": "textScore" } }
280282

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

@@ -296,26 +298,36 @@ class OfferService {
296298
offers = Offer.aggregate([
297299
{ $match: { $text: { $search: value } } },
298300
{ $match: this._buildFilterQuery(filters) },
299-
{ $addFields: {
300-
score: { $meta: "textScore" },
301-
adminReason: { $cond: [showAdminReason, "$adminReason", "$$REMOVE"] }
302-
} },
303-
{ $match: { "$or": [
304-
{ score: { "$lt": lastOfferScore } },
305-
{ score: lastOfferScore, [lastSortField]: { [sortFieldOperator]: lastSortValue } },
306-
{ score: lastOfferScore, [lastSortField]: lastSortValue, _id: { "$gt": ObjectId(lastOfferId) } }
307-
] } },
301+
{
302+
$addFields: {
303+
score: { $meta: "textScore" },
304+
adminReason: { $cond: [showAdminReason, "$adminReason", "$$REMOVE"] }
305+
}
306+
},
307+
{
308+
$match: {
309+
"$or": [
310+
{ score: { "$lt": lastOfferScore } },
311+
{ score: lastOfferScore, [lastSortField]: { [sortFieldOperator]: lastSortValue } },
312+
{ score: lastOfferScore, [lastSortField]: lastSortValue, _id: { "$gt": ObjectId(lastOfferId) } }
313+
]
314+
}
315+
},
308316
{ $match: Offer.filterCurrent() },
309317
{ $match: showHidden ? {} : Offer.filterNonHidden() }
310318
]);
311319
} else {
312-
offers = Offer.find({ "$and": [
313-
this._buildFilterQuery(filters),
314-
{ "$or": [
315-
{ [lastSortField]: { [sortFieldOperator]: lastSortValue } },
316-
{ [lastSortField]: lastSortValue, _id: { "$gt": ObjectId(lastOfferId) } }
317-
] }
318-
] });
320+
offers = Offer.find({
321+
"$and": [
322+
this._buildFilterQuery(filters),
323+
{
324+
"$or": [
325+
{ [lastSortField]: { [sortFieldOperator]: lastSortValue } },
326+
{ [lastSortField]: lastSortValue, _id: { "$gt": ObjectId(lastOfferId) } }
327+
]
328+
}
329+
]
330+
});
319331

320332
this.selectSearchOffers(offers, showHidden, showAdminReason);
321333
}
@@ -338,10 +350,12 @@ class OfferService {
338350
{
339351
"$and": [
340352
{ jobMinDuration: { "$lt": jobMinDuration } },
341-
{ "$or": [
342-
{ jobMaxDuration: { "$exists": false } },
343-
{ jobMaxDuration: { "$gte": jobMinDuration } },
344-
] }
353+
{
354+
"$or": [
355+
{ jobMaxDuration: { "$exists": false } },
356+
{ jobMaxDuration: { "$gte": jobMinDuration } },
357+
]
358+
}
345359
]
346360
},
347361
]
@@ -355,17 +369,19 @@ class OfferService {
355369
{
356370
"$and": [
357371
{ jobMaxDuration: { "$gt": jobMaxDuration } },
358-
{ "$or": [
359-
{ jobMinDuration: { "$exists": false } },
360-
{ jobMinDuration: { "$lte": jobMaxDuration } },
361-
] }
372+
{
373+
"$or": [
374+
{ jobMinDuration: { "$exists": false } },
375+
{ jobMinDuration: { "$lte": jobMaxDuration } },
376+
]
377+
}
362378
]
363379
},
364380
]
365381
});
366382
}
367-
if (fields?.length) constraints.push({ fields: { "$elemMatch": { "$in": fields } } });
368-
if (technologies?.length) constraints.push({ technologies: { "$elemMatch": { "$in": technologies } } });
383+
if (fields?.length) constraints.push({ fields: { "$elemMatch": { "$in": fields } } });
384+
if (technologies?.length) constraints.push({ technologies: { "$elemMatch": { "$in": technologies } } });
369385

370386
return constraints.length ? { "$and": constraints } : {};
371387
}

0 commit comments

Comments
 (0)