Skip to content

Commit

Permalink
EDF: [premieroctet#176] fix attachments field in event schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastien-Wappizy committed Dec 30, 2024
1 parent 6dda9b8 commit 964a03c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 6 additions & 0 deletions backend/web/server/plugins/entreprisedufutur/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,12 @@ declareComputedField({model: 'event', field: 'registered_users_count', getterFn:
declareComputedField({model: 'event', field: 'available_tickets', getterFn: getReservableTickets})
declareComputedField({model: 'event', field: 'is_registered', getterFn: getIsRegistered})
declareComputedField({model: 'event', field: 'waiting_list', getterFn: getStatus('waiting')})
declareVirtualField({model: 'event', field: 'attachments', multiple: true, instance: 'Array',
caster: {
instance: 'ObjectID',
options: {ref: 'attachment'}
}
})

// Mission declaration
declareEnumField({model: 'mission', field: 'estimation_duration_unit', enumValues: ESTIMATED_DURATION_UNITS})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,6 @@ const EventSchema = new Schema({
ref: 'eventCategory',
required: false
},
attachments: {
type: [{
type: Schema.Types.ObjectId,
ref: 'attachment',
required: true,
}],
required: false,
default: []
},
partners: {
type: [{
type: Schema.Types.ObjectId,
Expand Down Expand Up @@ -273,6 +264,12 @@ EventSchema.virtual('status', DUMMY_REF).get(function() {
return moment().isBefore(this.start_date) ? EVENT_STATUS_FUTUR : EVENT_STATUS_PAST
})

EventSchema.virtual('attachments', {
ref: 'attachment',
localField: '_id',
foreignField: 'event'
})

/* eslint-enable prefer-arrow-callback */

module.exports = EventSchema

0 comments on commit 964a03c

Please sign in to comment.