Skip to content

Commit

Permalink
Sosynpl[premieroctet#132]: added question model and logic to get anno…
Browse files Browse the repository at this point in the history
…unce/FAQ questions and answers
  • Loading branch information
SeghirOumo committed Jul 26, 2024
1 parent b100e77 commit 95b2b68
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions backend/web/server/plugins/sosynpl/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,13 @@ declareVirtualField({model: 'mission', field: 'evaluation', instance: 'Array', m
options: { ref: 'evaluation' }
},
})
//Announce Questions
declareVirtualField({model: 'announce', field: 'questions', instance: 'Array', multiple: true,
caster :{
instance: 'ObjectID',
options: { ref: 'question' }
}
})

const soSynplRegister = props => {
console.log(`Register with ${JSON.stringify(props)}`)
Expand Down Expand Up @@ -618,6 +625,8 @@ const preProcessGet = async ({ model, fields, id, user, params }) => {
id = s._id
// }
}
//If no Id when looking for questions, it means we're looking for FAQ and not all announces' questions
if (model == 'question' && !id) params['filter.announce'] = null
return { model, fields, id, user, params }
}

Expand Down
6 changes: 6 additions & 0 deletions backend/web/server/plugins/sosynpl/schemas/AnnounceSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,10 @@ AnnounceSchema.virtual('_duration_days', DUMMY_REF).get(function() {
return this.duration*DURATION_UNIT_DAYS[this.duration_unit]
})

AnnounceSchema.virtual('questions', {
ref: 'question',
localField: '_id',
foreignField: 'announce',
})

module.exports = AnnounceSchema
25 changes: 25 additions & 0 deletions backend/web/server/plugins/sosynpl/schemas/QuestionSchema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const mongoose = require('mongoose')
const { schemaOptions } = require('../../../utils/schemas')
const Schema = mongoose.Schema

const QuestionSchema = new Schema({
title: {
type: String,
required: [true, `Le titre est obligatoire`],
},
answer: {
type: String,
required: false,
},
tag: {
type: String,
required: false,
},
announce: {
type: Schema.Types.ObjectId,
ref: 'announce',
required: false,
}
}, { ...schemaOptions })

module.exports = QuestionSchema

0 comments on commit 95b2b68

Please sign in to comment.