Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: LBA-2415 ajout des schémas de validation mongo #1435

Merged
merged 7 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion server/src/common/utils/mongodbUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,18 @@ export const configureDbSchemaValidation = async (modelDescriptors: IModelDescri
await db.command({
collMod: collectionName,
validationLevel: "strict",
validationAction: "error",
validationAction: config.env === "production" ? "warn" : "error",
validator: {
$jsonSchema: {
title: `${collectionName} validation schema`,
...convertedSchema,
},
},
})

logger.info(`Validation rule for collection ${collectionName} updated`)
} catch (error) {
logger.error(`Error adding validation rule for collection ${collectionName}`)
captureException(error)
logger.error(error)
}
Expand Down
5 changes: 4 additions & 1 deletion server/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { connectToMongodb } from "@/common/utils/mongodbUtils"
import { modelDescriptors } from "shared/models/models"

import { connectToMongodb, configureDbSchemaValidation } from "@/common/utils/mongodbUtils"

import { startCLI } from "./commands"
import { logger } from "./common/logger"
Expand All @@ -11,6 +13,7 @@ process.on("uncaughtException", (err) => logger.error(err, "uncaughtException"))
try {
logger.warn("starting application")
await connectToMongodb(config.mongodb.uri)
await configureDbSchemaValidation(modelDescriptors)
await setupJobProcessor()
await startCLI()
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"BTS, DEUST, autres formations niveau (Bac+2)",
"Licence, Maîtrise, autres formations niveaux 6 (Bac+3 à Bac+4)",
"Master, titre ingénieur, autres formations niveau (Bac+5)",
"Indifférent",
],
"type": [
"string",
Expand Down Expand Up @@ -9031,7 +9030,6 @@ Limite : 5 appel(s) / 1 seconde(s)
"BTS, DEUST, autres formations niveau (Bac+2)",
"Licence, Maîtrise, autres formations niveaux 6 (Bac+3 à Bac+4)",
"Master, titre ingénieur, autres formations niveau (Bac+5)",
"Indifférent",
],
"type": [
"string",
Expand Down Expand Up @@ -9203,7 +9201,6 @@ Limite : 5 appel(s) / 1 seconde(s)
"BTS, DEUST, autres formations niveau (Bac+2)",
"Licence, Maîtrise, autres formations niveaux 6 (Bac+3 à Bac+4)",
"Master, titre ingénieur, autres formations niveau (Bac+5)",
"Indifférent",
],
"type": [
"string",
Expand Down
2 changes: 1 addition & 1 deletion shared/models/applications.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const ZApplication = z
example: "38 RUE DES HAMECONS, 75021 PARIS-21",
}),
job_origin: z
.enum([allLbaItemType[0], ...allLbaItemType.slice(1), ...allLbaItemTypeOLD])
.enum([allLbaItemType[0], ...allLbaItemType.slice(1), ...allLbaItemTypeOLD.slice(1)]) // suppression intentionnelle du premier élément de allLbaItemTypeOLD pour éviter un duplicat
.nullable()
.openapi({
description: "Le type de société selon la nomenclature La bonne alternance. Fourni par La bonne alternance.",
Expand Down
2 changes: 1 addition & 1 deletion shared/models/job.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export enum JOB_STATUS {
}

const allJobRythm = Object.values(TRAINING_RYTHM)
const allJobLevel = [...Object.values(NIVEAUX_POUR_LBA), "Indifférent"] as const
const allJobLevel = [...Object.values(NIVEAUX_POUR_LBA)] as const
const allJobStatus = Object.values(JOB_STATUS)
const allJobType = Object.values(TRAINING_CONTRACT_TYPE)
export const ZJobType = z.array(z.enum([allJobType[0], ...allJobType.slice(1)])).describe("Type de contrat")
Expand Down
Loading