Skip to content

Commit

Permalink
feat: lbac 2112 update api job (#1181)
Browse files Browse the repository at this point in the history
* feat: update model & route

* feat: add migration

* feat: add caller control

* feat: add test openapi control

* feat: update v2

* feat: export PE update

* fix: lint
  • Loading branch information
kevbarns authored May 2, 2024
1 parent 4e4dfeb commit b5edeb1
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 35 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"postinstall": "husky install",
"talisman:add-exception": "yarn node-talisman --githook pre-commit -i",
"test": "vitest",
"test:openapi": "vitest helpers/openapi/generateOpenapi.test.ts",
"test:ci": "yarn test --run",
"test:ci:coverage": "yarn test:ci --coverage.include='ui' --coverage.include='server/src' --coverage.include='shared' --coverage.provider='v8' --coverage.enabled --coverage.all --coverage.exclude='**/tests' --coverage.exclude='**/.next'",
"test:watch": "vitest --watch",
Expand Down
9 changes: 7 additions & 2 deletions server/src/common/model/schema/jobs/jobs.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ export const jobsSchema = new Schema<IJob>(
},
is_multi_published: {
type: Boolean,
default: null,
description: "Definit si l'offre est diffusée sur d'autres jobboard que La bonne alternance",
default: true,
description: "Definit si l'offre doit être diffusée sur d'autres jobboard que La bonne alternance",
},
job_delegation_count: {
type: Number,
Expand Down Expand Up @@ -145,6 +145,11 @@ export const jobsSchema = new Schema<IJob>(
default: null,
description: "Latitude/Longitude de l'adresse personnalisée de l'entreprise",
},
custom_job_title: {
type: String,
default: null,
description: "Titre personnalisée de l'offre",
},
stats_detail_view: {
type: Number,
description: "Nombre de vues de la page de détail",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Db } from "mongodb"

export const up = async (db: Db) => {
await db.collection("recruiters").updateMany({}, { $set: { "jobs.$[].is_multi_published": true } })
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export const exportToFranceTravail = async (): Promise<void> => {
geo_coordinates: { $nin: ["NOT FOUND", null] },
job_update_date: { $gte: threshold },
address_detail: { $ne: null },
is_multi_published: true,
})
.toArray()

Expand Down
4 changes: 2 additions & 2 deletions server/src/services/jobOpportunity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { trackApiCall } from "../common/utils/sendTrackingEvent"
import { getSomeFtJobs } from "./ftjob.service"
import { TJobSearchQuery, TLbaItemResult } from "./jobOpportunity.service.types"
import { getSomeCompanies } from "./lbacompany.service"
import { ILbaItemLbaCompany, ILbaItemLbaJob, ILbaItemFtJob } from "./lbaitem.shared.service.types"
import { ILbaItemFtJob, ILbaItemLbaCompany, ILbaItemLbaJob } from "./lbaitem.shared.service.types"
import { getLbaJobs, incrementLbaJobsViewCount } from "./lbajob.service"
import { jobsQueryValidator } from "./queryValidator.service"

/**
* Retourn la compilation d'opportunités d'emploi au format unifié
* @description Retourn la compilation d'opportunités d'emploi au format unifié
* chaque type d'opportunités d'emploi peut être émis en succès même si d'autres groupes sont en erreur
*/
export const getJobsFromApi = async ({
Expand Down
57 changes: 31 additions & 26 deletions server/src/services/lbajob.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,27 @@ import { filterJobsByOpco } from "./opco.service"
const { ObjectId } = pkg

const JOB_SEARCH_LIMIT = 250

const coordinatesOfFrance = [2.213749, 46.227638]
const FRANCE_LATITUDE = 46.227638
const FRANCE_LONGITUDE = 2.213749

/**
* @description get filtered jobs from mongo
* @param {Object} payload
* @param {number} payload.distance
* @param {string} payload.lat
* @param {string} payload.long
* @param {string[]} payload.romes
* @param {string} payload.niveau
* @returns {Promise<IRecruiter[]>}
* @description get OFFRES_EMPLOI_LBA
*/
export const getJobs = async ({ distance, lat, lon, romes, niveau }: { distance: number; lat: string; lon: string; romes: string[]; niveau: string }): Promise<IRecruiter[]> => {
export const getJobs = async ({
distance,
lat,
lon,
romes,
niveau,
caller,
}: {
distance: number
lat: number
lon: number
romes: string[]
niveau: string
caller?: string | null
}): Promise<IRecruiter[]> => {
const clauses: any[] = [{ "jobs.job_status": JOB_STATUS.ACTIVE }, { "jobs.rome_code": { $in: romes } }, { status: RECRUITER_STATUS.ACTIF }]

if (niveau && niveau !== "Indifférent") {
Expand All @@ -51,6 +58,10 @@ export const getJobs = async ({ distance, lat, lon, romes, niveau }: { distance:
})
}

if (caller) {
clauses.push({ "jobs.is_multi_published": true })
}

const stages: any[] = [
{
$limit: JOB_SEARCH_LIMIT,
Expand Down Expand Up @@ -103,7 +114,7 @@ export const getJobs = async ({ distance, lat, lon, romes, niveau }: { distance:
}

/**
* Retourne les offres LBA correspondantes aux critères de recherche
* @description Retourne les OFFRES_EMPLOI_LBA correspondantes aux critères de recherche
*/
export const getLbaJobs = async ({
romes = "",
Expand Down Expand Up @@ -132,24 +143,18 @@ export const getLbaJobs = async ({
radius = 10
}
try {
const hasLocation = Boolean(latitude)

const distance = hasLocation ? radius : 21000

const params: any = {
const params = {
caller,
romes: romes?.split(","),
distance,
lat: hasLocation ? latitude : coordinatesOfFrance[1],
lon: hasLocation ? longitude : coordinatesOfFrance[0],
}

if (diploma) {
params.niveau = NIVEAUX_POUR_LBA[diploma]
distance: radius ?? 21000,
lat: latitude ?? FRANCE_LATITUDE,
lon: longitude ?? FRANCE_LONGITUDE,
niveau: diploma ? NIVEAUX_POUR_LBA[diploma] : undefined,
}

const jobs = await getJobs(params)

const ids: string[] = jobs.flatMap((recruiter) => (recruiter?.jobs ? recruiter.jobs.map(({ _id }) => _id.toString()) : []))
const ids = jobs.flatMap((recruiter) => (recruiter?.jobs ? recruiter.jobs.map(({ _id }) => _id.toString()) : []))

const applicationCountByJob = await getApplicationByJobCount(ids)

Expand All @@ -160,7 +165,7 @@ export const getLbaJobs = async ({
matchas.results = await filterJobsByOpco({ opco, opcoUrl, jobs: matchas.results })
}

if (!hasLocation && matchas.results) {
if (!latitude && matchas.results) {
sortLbaJobs(matchas)
}

Expand Down
40 changes: 36 additions & 4 deletions shared/helpers/openapi/__snapshots__/generateOpenapi.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,13 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"null",
],
},
"custom_job_title": {
"description": "Titre personnalisée de l'offre",
"type": [
"string",
"null",
],
},
"delegations": {
"description": "Liste des délégations",
"items": {
Expand All @@ -710,11 +717,9 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
],
},
"is_multi_published": {
"default": true,
"description": "Definit si l'offre est diffusée sur d'autres jobboard que La bonne alternance",
"type": [
"boolean",
"null",
],
"type": "boolean",
},
"job_count": {
"default": 1,
Expand Down Expand Up @@ -908,6 +913,7 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"rome_code",
"job_status",
"job_type",
"is_multi_published",
],
"type": "object",
},
Expand Down Expand Up @@ -5479,6 +5485,13 @@ Limite : 5 appel(s) / 1 seconde(s)
"null",
],
},
"custom_job_title": {
"description": "Titre personnalisée de l'offre",
"type": [
"string",
"null",
],
},
"is_disabled_elligible": {
"default": false,
"description": "Poste ouvert aux personnes en situation de handicap",
Expand All @@ -5487,6 +5500,11 @@ Limite : 5 appel(s) / 1 seconde(s)
"null",
],
},
"is_multi_published": {
"default": true,
"description": "Definit si l'offre est diffusée sur d'autres jobboard que La bonne alternance",
"type": "boolean",
},
"job_count": {
"default": 1,
"description": "Nombre de poste(s) ouvert(s) pour cette offre",
Expand Down Expand Up @@ -5566,6 +5584,7 @@ Limite : 5 appel(s) / 1 seconde(s)
},
"required": [
"job_type",
"is_multi_published",
"job_start_date",
"appellation_code",
],
Expand Down Expand Up @@ -9042,6 +9061,13 @@ Limite : 5 appel(s) / 1 seconde(s)
"null",
],
},
"custom_job_title": {
"description": "Titre personnalisée de l'offre",
"type": [
"string",
"null",
],
},
"is_disabled_elligible": {
"default": false,
"description": "Poste ouvert aux personnes en situation de handicap",
Expand All @@ -9050,6 +9076,11 @@ Limite : 5 appel(s) / 1 seconde(s)
"null",
],
},
"is_multi_published": {
"default": true,
"description": "Definit si l'offre est diffusée sur d'autres jobboard que La bonne alternance",
"type": "boolean",
},
"job_count": {
"default": 1,
"description": "Nombre de poste(s) ouvert(s) pour cette offre",
Expand Down Expand Up @@ -9129,6 +9160,7 @@ Limite : 5 appel(s) / 1 seconde(s)
},
"required": [
"job_type",
"is_multi_published",
"job_start_date",
"appellation_code",
],
Expand Down
3 changes: 2 additions & 1 deletion shared/models/job.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const ZJobFields = z
job_status: z.enum([allJobStatus[0], ...allJobStatus.slice(1)]).describe("Statut de l'offre"),
job_status_comment: z.string().nullish().describe("Raison de la suppression de l'offre"),
job_type: ZJobType,
is_multi_published: z.boolean().nullish().describe("Definit si l'offre est diffusée sur d'autres jobboard que La bonne alternance"),
is_multi_published: z.boolean().default(true).describe("Definit si l'offre est diffusée sur d'autres jobboard que La bonne alternance"),
job_delegation_count: z.number().nullish().describe("Nombre de délégations"),
delegations: z.array(ZDelegation).nullish().describe("Liste des délégations"),
is_disabled_elligible: z.boolean().nullish().default(false).describe("Poste ouvert aux personnes en situation de handicap"),
Expand All @@ -63,6 +63,7 @@ export const ZJobFields = z
.describe("Répartition de la présence de l'alternant en formation/entreprise"),
custom_address: z.string().nullish().describe("Adresse personnalisée de l'entreprise"),
custom_geo_coordinates: z.string().nullish().describe("Latitude/Longitude de l'adresse personnalisée de l'entreprise"),
custom_job_title: z.string().nullish().describe("Titre personnalisée de l'offre"),
stats_detail_view: z.number().nullish().describe("Nombre de vues de la page de détail"),
stats_search_view: z.number().nullish().describe("Nombre de vues sur une page de recherche"),
managed_by: zObjectId.nullish().describe("Id de l'utilisateur gérant l'offre"),
Expand Down
2 changes: 2 additions & 0 deletions shared/routes/jobs.routes.v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ export const zJobsRoutesV2 = {
is_disabled_elligible: true,
custom_address: true,
custom_geo_coordinates: true,
is_multi_published: true,
custom_job_title: true,
})
.extend({
job_start_date: ZJobStartDateCreate(),
Expand Down
2 changes: 2 additions & 0 deletions shared/routes/v1Jobs.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ export const zV1JobsRoutes = {
is_disabled_elligible: true,
custom_address: true,
custom_geo_coordinates: true,
is_multi_published: true,
custom_job_title: true,
})
.extend({
job_start_date: ZJobStartDateCreate(),
Expand Down

0 comments on commit b5edeb1

Please sign in to comment.