diff --git a/backend/web/server/plugins/entreprisedufutur/functions.js b/backend/web/server/plugins/entreprisedufutur/functions.js index fcf848cb4..3ad97c503 100644 --- a/backend/web/server/plugins/entreprisedufutur/functions.js +++ b/backend/web/server/plugins/entreprisedufutur/functions.js @@ -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}) diff --git a/backend/web/server/plugins/entreprisedufutur/schemas/EventSchema.js b/backend/web/server/plugins/entreprisedufutur/schemas/EventSchema.js index 28a308782..7c7bb137e 100644 --- a/backend/web/server/plugins/entreprisedufutur/schemas/EventSchema.js +++ b/backend/web/server/plugins/entreprisedufutur/schemas/EventSchema.js @@ -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, @@ -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 \ No newline at end of file