Skip to content

Commit

Permalink
feat: update api job routes
Browse files Browse the repository at this point in the history
  • Loading branch information
kevbarns committed Nov 16, 2023
1 parent 451d931 commit c9acaa6
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 78 deletions.
49 changes: 23 additions & 26 deletions server/src/http/controllers/jobs/jobs.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,18 @@ export default (server: Server) => {
},
async (req, res) => {
const { jobId } = req.params
const jobExists = await getOffre(jobId.toString())
const recruiter = await getOffre(jobId.toString())

if (!jobExists) {
return res.status(400).send({ error: true, message: "Job does not exists" })
if (!recruiter) {
throw Boom.badRequest("Job does not exists")
}

if (!jobExists.geo_coordinates) {
throw Boom.internal("geo_coordinates is empty", { jobId: jobExists._id })
if (!recruiter.geo_coordinates) {
throw Boom.internal("geo_coordinates is empty", { jobId: recruiter._id })
}

const [latitude = "", longitude = ""] = jobExists.geo_coordinates.split(",")
const { rome_code } = jobExists.jobs.filter(({ _id }) => _id == jobId)[0]
const [latitude = "", longitude = ""] = recruiter.geo_coordinates.split(",")
const { rome_code } = recruiter.jobs.filter(({ _id }) => _id.toString() === jobId.toString())[0]

// Get related establishment from a job offer
const etablissements = await getNearEtablissementsFromRomes({
Expand All @@ -225,6 +225,10 @@ export default (server: Server) => {
},
})

if (!etablissements.length) {
throw Boom.notFound("No delegations found")
}

const top10 = etablissements.slice(0, 10)

return res.status(200).send(top10)
Expand All @@ -242,13 +246,12 @@ export default (server: Server) => {
const jobExists = await getOffre(jobId.toString())

if (!jobExists) {
return res.status(400).send({ error: true, message: "Job does not exists" })
throw Boom.badRequest("Job does not exists")
}

const updatedRecruiter = await createJobDelegations({ jobId: jobId.toString(), etablissementCatalogueIds: req.body.establishmentIds })

res.status(200)
return res.send(updatedRecruiter)
return res.status(200).send(updatedRecruiter)
}
)

Expand All @@ -264,16 +267,16 @@ export default (server: Server) => {
const job = await getJob(jobId.toString())

if (!job) {
return res.status(400).send({ error: true, message: "Job does not exists" })
throw Boom.badRequest("Job does not exists")
}

if (job.job_status === POURVUE) {
return res.status(400).send({ error: true, message: "Job is already provided" })
throw Boom.badRequest("Job is already provided")
}

await provideOffre(jobId)

return res.status(204).send({})
return res.status(204).send()
}
)

Expand All @@ -289,18 +292,16 @@ export default (server: Server) => {
const job = await getJob(jobId.toString())

if (!job) {
res.status(400)
return res.send({ error: true, message: "Job does not exists" })
throw Boom.badRequest("Job does not exists")
}

if (job.job_status === ANNULEE) {
res.status(400)
return res.send({ error: true, message: "Job is already canceled" })
throw Boom.badRequest("Job is already canceled")
}

await cancelOffre(jobId)

return res.status(204).send({})
return res.status(204).send()
}
)

Expand All @@ -316,24 +317,20 @@ export default (server: Server) => {
const job = await getJob(jobId.toString())

if (!job) {
res.status(400)
return res.send({ error: true, message: "Job does not exists" })
throw Boom.badRequest("Job does not exists")
}

if (addExpirationPeriod(dayjs()).isSame(dayjs(job.job_expiration_date), "day")) {
res.status(400)
return res.send({ error: true, message: "Job is already extended up to a month" })
throw Boom.badRequest("Job is already extended up to a month")
}

if (job.job_status !== ACTIVE) {
res.status(400)
return res.send({ error: true, message: "Job cannot be extended as it is not enabled" })
throw Boom.badRequest("Job cannot be extended as it is not active")
}

await extendOffre(jobId)

res.status(204)
return res.send({})
return res.status(204).send()
}
)
server.get(
Expand Down
90 changes: 51 additions & 39 deletions shared/helpers/openapi/__snapshots__/generateOpenapi.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"phone": {
"description": "Le numéro de téléphone du contact de référence",
"example": "0X XX XX XX XX",
"pattern": "^0[1-9]\\\\d{8}$",
"type": [
"string",
"null",
Expand Down Expand Up @@ -3127,6 +3128,7 @@ L'email est envoyé depuis l'adresse générique \\"Ne pas répondre\\" de La bo
"applicant_phone": {
"description": "Le numéro de téléphone du candidat.",
"example": "0101010101",
"pattern": "^0[1-9]\\\\d{8}$",
"type": "string",
},
"caller": {
Expand Down Expand Up @@ -4338,47 +4340,56 @@ L'email est envoyé depuis l'adresse générique \\"Ne pas répondre\\" de La bo
"content": {
"application/json": {
"schema": {
"additionalProperties": false,
"properties": {
"_id": {
"description": "Identifiant unique",
},
"code_postal": {
"type": "string",
},
"distance_en_km": {
"type": "number",
},
"entreprise_raison_sociale": {
"type": "string",
},
"geo_coordonnees": {
"type": "string",
},
"nom_departement": {
"type": "string",
},
"nom_voie": {
"type": "string",
},
"numero_voie": {
"type": "string",
},
"type_voie": {
"type": "string",
"items": {
"additionalProperties": false,
"properties": {
"_id": {
"description": "Identifiant unique",
},
"code_postal": {
"type": "string",
},
"distance_en_km": {
"type": "number",
},
"entreprise_raison_sociale": {
"type": "string",
},
"geo_coordonnees": {
"type": "string",
},
"nom_departement": {
"type": "string",
},
"nom_voie": {
"type": [
"string",
"null",
],
},
"numero_voie": {
"type": [
"string",
"null",
],
},
"type_voie": {
"type": [
"string",
"null",
],
},
},
"required": [
"code_postal",
"nom_departement",
"entreprise_raison_sociale",
"geo_coordonnees",
"distance_en_km",
],
"type": "object",
},
"required": [
"numero_voie",
"type_voie",
"nom_voie",
"code_postal",
"nom_departement",
"entreprise_raison_sociale",
"geo_coordonnees",
"distance_en_km",
],
"type": "object",
"type": "array",
},
},
},
Expand Down Expand Up @@ -4586,6 +4597,7 @@ L'email est envoyé depuis l'adresse générique \\"Ne pas répondre\\" de La bo
"type": "string",
},
"phone": {
"pattern": "^0[1-9]\\\\d{8}$",
"type": "string",
},
},
Expand Down
28 changes: 15 additions & 13 deletions shared/routes/v1Jobs.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,21 @@ export const zV1JobsRoutes = {
})
.strict(),
response: {
"200": z
.object({
_id: zObjectId,
numero_voie: z.string(),
type_voie: z.string(),
nom_voie: z.string(),
code_postal: z.string(),
nom_departement: z.string(),
entreprise_raison_sociale: z.string(),
geo_coordonnees: z.string(),
distance_en_km: z.number(),
})
.strict(),
"200": z.array(
z
.object({
_id: zObjectId,
numero_voie: z.string().nullish(),
type_voie: z.string().nullish(),
nom_voie: z.string().nullish(),
code_postal: z.string(),
nom_departement: z.string(),
entreprise_raison_sociale: z.string(),
geo_coordonnees: z.string(),
distance_en_km: z.number(),
})
.strict()
),
"4xx": z.union([ZLbarError, ZResError]),
},
securityScheme: {
Expand Down

0 comments on commit c9acaa6

Please sign in to comment.