Skip to content

Commit

Permalink
Sosynpl[premieroctet#120]: Finished mobility filter on suggested_free…
Browse files Browse the repository at this point in the history
…lances
  • Loading branch information
SeghirOumo committed Jul 15, 2024
1 parent 7248574 commit 5343d8e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 9 deletions.
1 change: 1 addition & 0 deletions backend/web/server/plugins/sosynpl/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ declareVirtualField({model: 'announce', field: 'received_applications_count', in
declareEnumField({model: 'announce', field: 'experience', enumValues: EXPERIENCE})
declareVirtualField({model: 'announce', field: 'average_daily_rate', instance: 'Number', requires:'duration,duration_unit,budget'})
declareVirtualField({model: 'announce', field: '_duration_days', instance: 'Number'})
declareEnumField({model: 'announce', field: 'regions', enumValues: REGIONS})
// SOFT SKILLS
declareComputedField({model: 'announce', field: 'available_gold_soft_skills', getterFn: computeAvailableGoldSoftSkills})
declareComputedField({model: 'announce', field: 'available_silver_soft_skills', requires: 'gold_soft_skills', getterFn: computeAvailableSilverSoftSkills})
Expand Down
32 changes: 31 additions & 1 deletion backend/web/server/plugins/sosynpl/schemas/AnnounceSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ const mongoose = require('mongoose')
const lodash = require('lodash')
const moment = require('moment')
const autoIncrement = require('mongoose-auto-increment')
const {DURATION_UNIT, ANNOUNCE_MOBILITY, MOBILITY_NONE, COMMISSION, SS_PILAR, ANNOUNCE_STATUS_DRAFT, EXPERIENCE, ANNOUNCE_STATUS_ACTIVE, DURATION_UNIT_WORK_DAYS, ANNOUNCE_STATUS, DURATION_UNIT_DAYS, APPLICATION_STATUS_SENT} = require('../consts')
const {DURATION_UNIT, ANNOUNCE_MOBILITY, MOBILITY_NONE, COMMISSION, SS_PILAR, ANNOUNCE_STATUS_DRAFT, EXPERIENCE, ANNOUNCE_STATUS_ACTIVE, DURATION_UNIT_WORK_DAYS, ANNOUNCE_STATUS, DURATION_UNIT_DAYS, APPLICATION_STATUS_SENT, MOBILITY_REGIONS} = require('../consts')
const {schemaOptions} = require('../../../utils/schemas')
const AddressSchema = require('../../../models/AddressSchema')
const { DUMMY_REF } = require('../../../utils/database')
const { computePilar } = require('../soft_skills')
const { REGIONS } = require('../../../../utils/consts')

const Schema = mongoose.Schema

Expand Down Expand Up @@ -100,6 +101,35 @@ const AnnounceSchema = new Schema({
type: Number,
required: [function() { return this.mobility!=MOBILITY_NONE}, `Le nombre de jours de déplacements par mois est obligatoire`],
},
regions: {
type: [{
type: String,
enum: Object.keys(REGIONS)
}],
required: true,
default: [],
validate: [
{
validator: function(value) {
if (this.mobility === MOBILITY_REGIONS) {
return value.length >= 1
}
return true
},
message: 'Le nombre de régions minimum est 1',
},
{
validator: function(value) {
if (this.mobility === MOBILITY_REGIONS) {
return value.length <= 3
}
return true
},
message: 'Le nombre de régions maximum est 3',
}
]
},

budget: {
type: Number,
required: [true, `Le budget est obligatoire`]
Expand Down
10 changes: 9 additions & 1 deletion backend/web/server/plugins/sosynpl/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,23 @@ const computeSuggestedFreelances = async (userId, params, data) => {
],
}
const suggestions = await CustomerFreelance.find(filter)
const regionKey = getRegionFromZipcode(data.city.zip_code)
if (data.mobility === MOBILITY_NONE) {
const regionKey = getRegionFromZipcode(data.city.zip_code);
return suggestions.filter(s => {
return (
(s.mobility === MOBILITY_CITY && computeDistanceKm(data.city, s.mobility_city) < s.mobility_city_distance) ||
(s.mobility === MOBILITY_REGIONS && s.mobility_regions.includes(regionKey))
)
})
}
if(data.mobility === MOBILITY_REGIONS) {
return suggestions.filter(s => {
return (
(s.mobility === MOBILITY_REGIONS && s.mobility_regions.includes(data.regions)) ||
(s.mobility === MOBILITY_CITY && data.regions.includes(getRegionFromZipcode(s.mobility_city.zip_code)))
)
})
}
return suggestions
}

Expand Down
22 changes: 15 additions & 7 deletions backend/web/tests/sosynpl/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const LanguageLevel = require('../../server/models/LanguageLevel')
const CustomerFreelance = require('../../server/models/CustomerFreelance')
const SoftSkill = require('../../server/models/SoftSkill')
const JobFile = require('../../server/models/JobFile')
const { LANGUAGE_LEVEL_ADVANCED } = require('../../utils/consts')
const { EXPERIENCE_EXPERT, DURATION_MONTH, MOBILITY_FRANCE, SOURCE_RECOMMANDATION, WORK_MODE_REMOTE_SITE, WORK_DURATION__1_TO_6_MONTHS, AVAILABILITY_ON, AVAILABILITY_OFF, MOBILITY_CITY, MOBILITY_NONE } = require('../../server/plugins/sosynpl/consts')
const { LANGUAGE_LEVEL_ADVANCED, REGIONS } = require('../../utils/consts')
const { EXPERIENCE_EXPERT, DURATION_MONTH, MOBILITY_FRANCE, SOURCE_RECOMMANDATION, WORK_MODE_REMOTE_SITE, WORK_DURATION__1_TO_6_MONTHS, AVAILABILITY_ON, AVAILABILITY_OFF, MOBILITY_CITY, MOBILITY_NONE, MOBILITY_REGIONS } = require('../../server/plugins/sosynpl/consts')
const { computeDistanceKm } = require('../../utils/functions')
require('../../server/plugins/sosynpl/functions')
require('../../server/plugins/sosynpl/announce')
Expand All @@ -20,7 +20,7 @@ require('../../server/models/Application')


describe('Search', () => {
let job, sector, expertise1, expertise2, expertise3, software, language, announce, customerFreelance, rouen, msa, dieppe
let job, sector, expertise1, expertise2, expertise3, software, language, announce, customerFreelance, rouen, msa, dieppe, lyon
let softSkillComm, softSkillConflict, softSkillTeamWork

beforeAll(async () => {
Expand Down Expand Up @@ -62,6 +62,14 @@ describe('Search', () => {
latitude: 49.9225,
longitude: 1.0781,
}
lyon = {
address: 'Place Bellecour',
city: 'Lyon',
zip_code: '69002',
country: 'France',
latitude: 45.7579,
longitude: 4.8321,
}
announce = await Announce.create({
user: new mongoose.Types.ObjectId(),
job: job._id,
Expand All @@ -72,7 +80,8 @@ describe('Search', () => {
duration_unit: DURATION_MONTH,
sectors: [sector._id],
homework_days: 3,
mobility: MOBILITY_NONE,
mobility: MOBILITY_REGIONS,
regions: [Object.keys(REGIONS)[2], Object.keys(REGIONS)[3]],
mobility_days_per_month: 10,
budget: 5000,
budget_hidden: false,
Expand Down Expand Up @@ -115,6 +124,7 @@ describe('Search', () => {
work_duration: [WORK_DURATION__1_TO_6_MONTHS],
mobility: MOBILITY_CITY,
mobility_city: rouen,
mobility_regions: [Object.keys(REGIONS)[3]],
mobility_city_distance: 10,
cgu_accepted: true,
phone: '0606060606',
Expand All @@ -134,11 +144,9 @@ describe('Search', () => {

test('should find suggested freelances based on announce criteria', async () => {
const loadedAnnounce = await loadFromDb({model:'announce', id:announce._id,
fields:'city,mobility,suggested_freelances,gold_soft_skills,silver_soft_skills,bronze_soft_skills,start_date,job,sectors,expertises,softwares,languages,experience,_duration_days,duration_unit,duration'.split(',')
fields:'regions,city,mobility,suggested_freelances,gold_soft_skills,silver_soft_skills,bronze_soft_skills,start_date,job,sectors,expertises,softwares,languages,experience,_duration_days,duration_unit,duration'.split(',')
})
const suggestion = loadedAnnounce[0].suggested_freelances[0]
// console.dir(customerFreelance, { depth: null, colors: true, maxArrayLength: null })
// console.dir(announce, { depth: null, colors: true, maxArrayLength: null })
expect(String(customerFreelance._id)).toMatch(String(suggestion.id))
})
})

0 comments on commit 5343d8e

Please sign in to comment.