Skip to content

Commit

Permalink
Sosynpl[premieroctet#120]: changed announce regions to mobility_regio…
Browse files Browse the repository at this point in the history
…ns, test if mobility_city is known
  • Loading branch information
SeghirOumo committed Jul 16, 2024
1 parent fa60d5c commit 79e4fad
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/web/server/plugins/sosynpl/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,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})
declareEnumField({model: 'announce', field: 'mobility_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
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ 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: {
mobility_regions: {
type: [{
type: String,
enum: Object.keys(REGIONS)
Expand Down
9 changes: 5 additions & 4 deletions backend/web/server/plugins/sosynpl/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const computeSuggestedFreelances = async (userId, params, data) => {
: WORK_DURATION__1_TO_6_MONTHS

const getRegionFromZipcode = (zipcode) => {
const departmentCode = zipcode.toString().substring(0, 2)
const departmentCode = String(zipcode).substring(0, 2)
const region = lodash.pickBy(REGIONS_FULL, (region) =>
region.departements.includes(departmentCode)
)
Expand Down Expand Up @@ -71,7 +71,8 @@ const computeSuggestedFreelances = async (userId, params, data) => {
],
}
const suggestions = await CustomerFreelance.find(filter)
const regionKey = getRegionFromZipcode(data.city.zip_code)
let regionKey
if(data.city && data.city.zip_code) regionKey = getRegionFromZipcode(data.city.zip_code)
if (data.mobility === MOBILITY_NONE) {
return suggestions.filter(s => {
return (
Expand All @@ -83,8 +84,8 @@ const computeSuggestedFreelances = async (userId, params, data) => {
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)))
(s.mobility === MOBILITY_REGIONS && s.mobility_regions.includes(data.mobility_regions)) ||
(s.mobility === MOBILITY_CITY && data.mobility_regions.includes(getRegionFromZipcode(s.mobility_city.zip_code)))
)
})
}
Expand Down
64 changes: 64 additions & 0 deletions backend/web/tests/sosynpl/evaluation.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const mongoose = require('mongoose')
const lodash = require('lodash')
const { MONGOOSE_OPTIONS } = require('../../server/utils/database')
const Freelance = require('../../server/models/Freelance')
const JobFile = require('../../server/models/JobFile')
const { JOB_FILE_DATA, JOB_DATA, SECTOR_DATA, CATEGORY_DATA, FREELANCE_DATA, CUSTOMER_DATA } = require('./data/base_data')
const Job = require('../../server/models/Job')
const Sector = require('../../server/models/Sector')
const HardSkillCategory = require('../../server/models/HardSkillCategory')
const HardSkill = require('../../server/models/HardSkill')
const Customer = require('../../server/models/Customer')
const Announce = require('../../server/models/Announce')
const { EXPERIENCE, DURATION_UNIT_DAYS, DURATION_UNIT, MOBILITY_NONE, DURATION_MONTH } = require('../../server/plugins/sosynpl/consts')

jest.setTimeout(30000000)

describe('Evaluation', ()=> {
let freelanceId, customerId, announce, application, evaluation, sector
beforeAll(async () => {
const DBNAME=`evalTest`
await mongoose.connect(`mongodb://localhost/${DBNAME}`, MONGOOSE_OPTIONS)
console.log('Opened database', DBNAME)
const jobFile=await JobFile.create({...JOB_FILE_DATA})
const job=await Job.create({...JOB_DATA, job_file: jobFile})
const sector=await Sector.create({...SECTOR_DATA})
const category1=await HardSkillCategory.create({...CATEGORY_DATA, name: `Catégorie 1`})
const category2=await HardSkillCategory.create({...CATEGORY_DATA, name: `Catégorie 2`})
freelanceId=(await Freelance.create({...FREELANCE_DATA, main_job: job, work_sector: [sector]}))._id
await Promise.all(lodash.range(4).map(idx => HardSkill.create({name: `Skill 1-${idx}`, code: '12', job_file: jobFile, category: category1})))
await Promise.all(lodash.range(2).map(idx => HardSkill.create({name: `Skill 2-${idx}`, code: '12', job_file: jobFile, category: category2})))

const rouen = {
address: 'Place du Vieux-Marché',
city: 'Rouen',
zip_code: '76000',
country: 'France',
latitude: 49.4431,
longitude: 1.0993,
}

customerId=await Customer.create({...CUSTOMER_DATA})._id

const announce=await Announce.create({
user:customerId,
title:'dev',
experience: Object.keys(EXPERIENCE)[0],
duration: 2,
duration_unit: DURATION_MONTH,
budget: '6969669',
mobility_days_per_month : 2,
mobility: MOBILITY_NONE,
city: rouen,
sectors: [sector._id]
})
})

afterAll(async () => {
await mongoose.connection.dropDatabase()
await mongoose.connection.close()
})

it('must get evaluations', async()=>{
})
})
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"jodit-react": "^4.1.2"
}
}
22 changes: 22 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


autobind-decorator@^2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/autobind-decorator/-/autobind-decorator-2.4.0.tgz#ea9e1c98708cf3b5b356f7cf9f10f265ff18239c"
integrity sha512-OGYhWUO72V6DafbF8PM8rm3EPbfuyMZcJhtm5/n26IDwO18pohE4eNazLoCGhPiXOCD0gEGmrbU3849QvM8bbw==

jodit-react@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/jodit-react/-/jodit-react-4.1.2.tgz#61ef1d6fa1f37cde7b71f666da8be9f6fb70f913"
integrity sha512-Hs1evpM1IK5zvy/5m5Gk819L8aC+9EmEdQvCoLHVUr/R3vtH4nYFD6wsMRj3ur3J4ZHhaSBjt0N3R7ggwP405Q==
dependencies:
jodit "^4.2.10"

jodit@^4.2.10:
version "4.2.27"
resolved "https://registry.yarnpkg.com/jodit/-/jodit-4.2.27.tgz#fd6b39a968bd474210e8ab78fc463cdb206d3a6d"
integrity sha512-cqqeunB3HMElnocVhs5Qq2bhgpMIT2vKQPBpKcOTWKvX6GJ0GYAIneMEf43lphJuo+119CvBE8YgljD5iTfsAQ==
dependencies:
autobind-decorator "^2.4.0"

0 comments on commit 79e4fad

Please sign in to comment.