Skip to content

Commit

Permalink
Sosynpl[premieroctet#101]: fixed profile completion, changed customer…
Browse files Browse the repository at this point in the history
… profile completion logic
  • Loading branch information
SeghirOumo committed Jul 26, 2024
1 parent c29faa2 commit b100e77
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 28 deletions.
18 changes: 2 additions & 16 deletions backend/web/server/plugins/sosynpl/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,31 +440,17 @@ const FREELANCE_OUTPUT_ATTRIBUTES = {
}

//Customer profile completion
const CUSTOMER_REQUIRED_ATTRIBUTES = ['firstname','lastname','position','phone','email','password','siren','company_name']
const CUSTOMER_ANNOUNCE_ATTRIBUTES = ['company_logo','sector','description','company_size']
const CUSTOMER_CONTRACT_ATTRIBUTES = ['legal_status','registration_city','social_capital','headquarter_address','billing_contact_address','billing_contact_firstname','billing_contact_lastname','billing_contact_email']
const CUSTOMER_REQUIRED_ATTRIBUTES = ['siren','company_size','description','company_logo','headquarter_address','legal_status','company_name']

const CUSTOMER_OUTPUT_ATTRIBUTES = {
firstname:'Prénom',
lastname:'Nom',
position:'Intitulé du poste',
phone:'Numéro de téléphone',
mail:'Adresse mail',
password:'Mot de passe',
siren:'SIREN',
company_name:`Nom de l'entreprise`,
company_logo:'Logo',
sector:`Secteur d'activité`,
description:`Description de l'entreprise`,
company_size:`Taille de l'entreprise`,
legal_status:`Statut de l'entreprise`,
registration_city:`Ville d'immatriculation`,
social_capital:`Capital de l'entreprise`,
headquarter_address:`Adresse du siège de l'entreprise`,
billing_contact_address:`Àdresse de facturation`,
billing_contact_firstname:`Prénom du contact de facturation`,
billing_contact_lastname:`Nom du contact de facturation`,
billing_contact_email:`Email du contact de facturation`,
}

module.exports={
Expand All @@ -487,6 +473,6 @@ module.exports={
SEARCH_MODE, DEFAULT_SEARCH_RADIUS, DURATION_UNIT_DAYS, DURATION_FILTERS, DURATION_MONTH,SOURCE_RECOMMANDATION, EVALUATION_MIN, EVALUATION_MAX, DURATION_MONTH, CF_MAX_GOLD_SOFT_SKILLS, CF_MAX_SILVER_SOFT_SKILLS, CF_MAX_BRONZE_SOFT_SKILLS,
COMPANY_SIZE_LESS_10,MISSION_STATUS_CLOSED,
FREELANCE_REQUIRED_ATTRIBUTES, SOFT_SKILLS_ATTR, FREELANCE_MANDATORY_ATTRIBUTES, FREELANCE_OUTPUT_ATTRIBUTES,
CUSTOMER_REQUIRED_ATTRIBUTES, CUSTOMER_ANNOUNCE_ATTRIBUTES, CUSTOMER_CONTRACT_ATTRIBUTES, CUSTOMER_OUTPUT_ATTRIBUTES
CUSTOMER_REQUIRED_ATTRIBUTES, CUSTOMER_OUTPUT_ATTRIBUTES
}

8 changes: 4 additions & 4 deletions backend/web/server/plugins/sosynpl/customer.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const { CUSTOMER_ANNOUNCE_ATTRIBUTES, CUSTOMER_CONTRACT_ATTRIBUTES, CUSTOMER_REQUIRED_ATTRIBUTES, CUSTOMER_OUTPUT_ATTRIBUTES } = require("./consts")
const { CUSTOMER_REQUIRED_ATTRIBUTES, CUSTOMER_OUTPUT_ATTRIBUTES } = require("./consts")


const customerProfileCompletion = (user) => {
if (!user['customer_missing_attributes'] || user['customer_missing_attributes'].length === 0) return 1
const attrCount = [...CUSTOMER_ANNOUNCE_ATTRIBUTES, ...CUSTOMER_CONTRACT_ATTRIBUTES, ...CUSTOMER_REQUIRED_ATTRIBUTES].length
const attrCount = CUSTOMER_REQUIRED_ATTRIBUTES.length
const missingCount = user['customer_missing_attributes'].length
return Math.floor(1-missingCount/attrCount)
return Math.floor(100-missingCount/attrCount*100)/100
}

const customerMissingAttributes = (user) => {
let missingAttr = []
const allAttributes = [...CUSTOMER_REQUIRED_ATTRIBUTES, ...CUSTOMER_ANNOUNCE_ATTRIBUTES, ...CUSTOMER_CONTRACT_ATTRIBUTES]
const allAttributes = [...CUSTOMER_REQUIRED_ATTRIBUTES]
allAttributes.forEach((attr, index) => {
if (!user[attr]) {
const attributeString = index === allAttributes.length - 1 ? CUSTOMER_OUTPUT_ATTRIBUTES[attr] : `${CUSTOMER_OUTPUT_ATTRIBUTES[attr]} `
Expand Down
7 changes: 3 additions & 4 deletions backend/web/server/plugins/sosynpl/freelance.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ const { CF_MAX_GOLD_SOFT_SKILLS, CF_MAX_SILVER_SOFT_SKILLS, CF_MAX_BRONZE_SOFT_S

const freelanceProfileCompletion = (user) => {
if (!user['freelance_missing_attributes'] || user['freelance_missing_attributes'].length === 0) return 1
const missing = user['freelance_missing_attributes']
const missing = user['freelance_missing_attributes'].map(attribute => attribute.trim())
let result = 0
const requiredMissing = FREELANCE_REQUIRED_ATTRIBUTES.filter(attr => missing.includes(attr)).length
if (requiredMissing === 0) result += 40
else result += 5 * (FREELANCE_REQUIRED_ATTRIBUTES.length - requiredMissing)

const mandatoryMissing = FREELANCE_MANDATORY_ATTRIBUTES.filter(attr => missing.includes(attr)).length
const mandatoryMissing = FREELANCE_MANDATORY_ATTRIBUTES.filter(attr => missing.includes(FREELANCE_OUTPUT_ATTRIBUTES[attr])).length
const mandatoryPenalty = Math.floor((60 / FREELANCE_MANDATORY_ATTRIBUTES.length) * mandatoryMissing)

result += 60 - mandatoryPenalty

console.log(result, '**', mandatoryMissing, requiredMissing)
return result/100
}

Expand Down
6 changes: 3 additions & 3 deletions backend/web/server/plugins/sosynpl/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const Announce = require("../../models/Announce")
const Search = require("../../models/Search")
const { declareVirtualField, declareEnumField, callPostCreateData, setPostCreateData, setPreprocessGet, setPreCreateData, declareFieldDependencies, declareComputedField, setFilterDataUser, idEqual, setPrePutData, getModel } = require("../../utils/database");
const { addAction } = require("../../utils/studio/actions");
const { WORK_MODE, SOURCE, EXPERIENCE, ROLES, ROLE_CUSTOMER, ROLE_FREELANCE, WORK_DURATION, COMPANY_SIZE, LEGAL_STATUS, DEACTIVATION_REASON, SUSPEND_REASON, ACTIVITY_STATE, MOBILITY, AVAILABILITY, SOFT_SKILLS, SS_PILAR, DURATION_UNIT, ANNOUNCE_MOBILITY, ANNOUNCE_STATUS, APPLICATION_STATUS, AVAILABILITY_ON, SOSYNPL_LANGUAGES, ANNOUNCE_SUGGESTION, REFUSE_REASON, QUOTATION_STATUS, APPLICATION_REFUSE_REASON, MISSION_STATUS, REPORT_STATUS, SEARCH_MODE, FREELANCE_REQUIRED_ATTRIBUTES, SOFT_SKILLS_ATTR, FREELANCE_MANDATORY_ATTRIBUTES, CUSTOMER_REQUIRED_ATTRIBUTES, CUSTOMER_ANNOUNCE_ATTRIBUTES, CUSTOMER_CONTRACT_ATTRIBUTES } = require("./consts")
const { WORK_MODE, SOURCE, EXPERIENCE, ROLES, ROLE_CUSTOMER, ROLE_FREELANCE, WORK_DURATION, COMPANY_SIZE, LEGAL_STATUS, DEACTIVATION_REASON, SUSPEND_REASON, ACTIVITY_STATE, MOBILITY, AVAILABILITY, SOFT_SKILLS, SS_PILAR, DURATION_UNIT, ANNOUNCE_MOBILITY, ANNOUNCE_STATUS, APPLICATION_STATUS, AVAILABILITY_ON, SOSYNPL_LANGUAGES, ANNOUNCE_SUGGESTION, REFUSE_REASON, QUOTATION_STATUS, APPLICATION_REFUSE_REASON, MISSION_STATUS, REPORT_STATUS, SEARCH_MODE, FREELANCE_REQUIRED_ATTRIBUTES, SOFT_SKILLS_ATTR, FREELANCE_MANDATORY_ATTRIBUTES, CUSTOMER_REQUIRED_ATTRIBUTES } = require("./consts")
const Freelance=require('../../models/Freelance')
const CustomerFreelance=require('../../models/CustomerFreelance')
const HardSkillCategory=require('../../models/HardSkillCategory')
Expand Down Expand Up @@ -477,9 +477,9 @@ CUSTOMERFREELANCEMODELS.forEach(model => {
instance: 'String',
},
})
declareVirtualField({model, field: 'customer_profile_completion', requires:[...CUSTOMER_REQUIRED_ATTRIBUTES, ...CUSTOMER_ANNOUNCE_ATTRIBUTES, ...CUSTOMER_CONTRACT_ATTRIBUTES, 'customer_missing_attributes'].join(','), instance: 'Number'})
declareVirtualField({model, field: 'customer_profile_completion', requires:[...CUSTOMER_REQUIRED_ATTRIBUTES, 'customer_missing_attributes'].join(','), instance: 'Number'})
declareVirtualField({
model, field: 'customer_missing_attributes', instance: 'Array', multiple: true, requires:[...CUSTOMER_REQUIRED_ATTRIBUTES, ...CUSTOMER_ANNOUNCE_ATTRIBUTES, ...CUSTOMER_CONTRACT_ATTRIBUTES].join(','),
model, field: 'customer_missing_attributes', instance: 'Array', multiple: true, requires:[...CUSTOMER_REQUIRED_ATTRIBUTES].join(','),
caster: {
instance: 'String',
},
Expand Down
2 changes: 1 addition & 1 deletion backend/web/tests/sosynpl/profileCompletion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ describe('Profile Completion', ()=> {
const fields = ['freelance_profile_completion']
const [user] = await loadFromDb({model:'customerFreelance', id: freelance._id, fields})
expect(user.freelance_profile_completion).toBeGreaterThanOrEqual(0)
console.log(user.freelance_profile_completion)
})

it.only('checks for customer missing attributes', async() => {
const fields = ['customer_missing_attributes']
const [user] = await loadFromDb({model:'customer', id: customer._id, fields})
expect(user.customer_missing_attributes.length).toBeGreaterThanOrEqual(0)
console.table(user.customer_missing_attributes)
})

it.only('checks for customer profile completion', async() => {
Expand Down

0 comments on commit b100e77

Please sign in to comment.