11import 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" ;
88import CompanyConstants from "../models/constants/Company.js" ;
99import 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