Skip to content

Commit

Permalink
Cyberleague: [premieroctet#120] Add enum field level to score schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastien-Wappizy committed Sep 6, 2024
1 parent 3f77603 commit 67a2fa2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
11 changes: 10 additions & 1 deletion backend/web/server/plugins/cyberleague/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ const QUESTION_CATEGORIES = {
[QUESTION_CATEGORY_DEVICE_AND_FACTORY_NETWORK_SECURITY] : `SECURITE DES EQUIPEMENTS ET RESEAUX INDUSTRIELS (OT)`
}

const SCORE_LEVEL_1 = `SCORE_LEVEL_1`
const SCORE_LEVEL_2 = `SCORE_LEVEL_2`
const SCORE_LEVEL_3 = `SCORE_LEVEL_3`

const SCORE_LEVELS = {
[SCORE_LEVEL_1] : `Niveau 1`,
[SCORE_LEVEL_2] : `Niveau 2`,
[SCORE_LEVEL_3] : `Niveau 3`
}

module.exports = {
DISC_ADMIN, DISC_MEMBER, DISC_PARTNER, DISCRIMINATOR_KEY,
Expand All @@ -241,5 +250,5 @@ module.exports = {
QUESTION_CATEGORY_OWN_AND_THIRD_PARTY_ASSET_MANAGEMENT, QUESTION_CATEGORY_IDENTITY_AND_CLEARANCE_MANAGEMENT, QUESTION_CATEGORY_LOG_AND_SUPERVISION, QUESTION_CATEGORY_SAVE_AND_RECOVERY,
QUESTION_CATEGORY_DATA_PRIVACY, QUESTION_CATEGORY_PERSONAL_DATA_PROCESSING, QUESTION_CATEGORY_PHYSICAL_SECURITY, QUESTION_CATEGORY_NETWORK_SECURITY_AND_ADMINISTRATIVE_ENVIRONMENT,
QUESTION_CATEGORY_ANTIVIRUS_PROTECTION, QUESTION_CATEGORY_ENDPOINT_SECURITY, QUESTION_CATEGORY_MONITORING_AND_UPDATE_MANAGEMENT, QUESTION_CATEGORY_DEVELOPMENT_AND_APP_SECURITY, QUESTION_CATEGORY_BANK_TRANSACTION_SECURITY, QUESTION_CATEGORY_DEVICE_AND_FACTORY_NETWORK_SECURITY,

SCORE_LEVELS,SCORE_LEVEL_1, SCORE_LEVEL_2, SCORE_LEVEL_3
}
11 changes: 8 additions & 3 deletions backend/web/server/plugins/cyberleague/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
setPostPutData,
idEqual,
} = require('../../utils/database')
const { ROLES, SECTOR, EXPERTISE_CATEGORIES, CONTENT_TYPE, JOBS, COMPANY_SIZE, ROLE_PARTNER, ROLE_ADMIN, ROLE_MEMBER, ESTIMATED_DURATION_UNITS, LOOKING_FOR_MISSION, CONTENT_VISIBILITY, EVENT_VISIBILITY, ANSWERS, QUESTION_CATEGORIES } = require('./consts')
const { ROLES, SECTOR, EXPERTISE_CATEGORIES, CONTENT_TYPE, JOBS, COMPANY_SIZE, ROLE_PARTNER, ROLE_ADMIN, ROLE_MEMBER, ESTIMATED_DURATION_UNITS, LOOKING_FOR_MISSION, CONTENT_VISIBILITY, EVENT_VISIBILITY, ANSWERS, QUESTION_CATEGORIES, SCORE_LEVELS } = require('./consts')
const { PURCHASE_STATUS } = require('../../../utils/consts')
const Company = require('../../models/Company')
const { BadRequestError } = require('../../utils/errors')
Expand All @@ -27,6 +27,8 @@ const ExpertiseCategory = require('../../models/ExpertiseCategory')
const { computeScores } = require('./score')
const Conversation = require('../../models/Conversation')
const User = require('../../models/User')
const Question = require('../../models/Question')
const Answer = require('../../models/Answer')
const { isMineForPost } = require('./post')

//User declarations
Expand Down Expand Up @@ -240,8 +242,11 @@ declareEnumField({model: 'mission', field: 'estimation_duration_unit', enumValue
declareVirtualField({model: 'expertiseSet', field: 'display_categories', requires: 'expertises,categories', instance: 'Array', multiple: true})

//Score declarations
declareVirtualField({model: 'score', field: 'deviation', requires: 'questions.answer', instance: 'Number'})
declareEnumField( {model: 'score', field: 'questions.answer', enumValues: ANSWERS})
declareVirtualField({model: 'score', field: 'deviation', requires: 'answers.answer', instance: 'Number'})
declareEnumField( {model: 'score', field: 'level', enumValues: SCORE_LEVELS})

//Answer declaration
declareEnumField( {model: 'answer', field: 'answer', enumValues: ANSWERS})

//questionCategory declarations
declareVirtualField({model: 'questionCategory', field: 'questions', instance: 'Array', multiple: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const mongoose = require('mongoose')
const {schemaOptions} = require('../../../utils/schemas')
const { ANSWER_NO, ANSWERS } = require('../consts')
const { ANSWER_NO, SCORE_LEVELS } = require('../consts')
const { DUMMY_REF } = require('../../../utils/database')

const Schema = mongoose.Schema
Expand Down Expand Up @@ -50,6 +50,11 @@ const ScoreSchema = new Schema({
}
}],
default: []
},
level: {
type: String,
enum: Object.keys(SCORE_LEVELS),
required: [true, `Le niveau du score est obligatoire`]
}
}, {...schemaOptions})

Expand Down

0 comments on commit 67a2fa2

Please sign in to comment.