Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict'
- var mongoose = require('mongoose');
- var Schema = mongoose.Schema;
- var Comment = require('./comment_model');
- var User = require('./user_model');
- var eventSchema = new Schema({
- picture: {
- type: String,
- default: null
- },
- eventDate: {
- type: Date
- },
- location: {
- type: String,
- required: true
- },
- distance: {
- type: String,
- required: true
- },
- pace: {
- type: String,
- required: true
- },
- author: {
- type: Schema.Types.ObjectId,
- ref: 'User'
- },
- likes: [{
- type: Schema.Types.ObjectId,
- ref: 'User'
- }],
- runners: [{
- type: Schema.Types.ObjectId,
- ref: 'User'
- }],
- comments: [{
- type: Schema.Types.ObjectId,
- ref: 'Comment'
- }]
- }, {
- timestamps: true //auto generation time of creation and last update
- });
- //*********************************************************** */
- // MIDDLEWARE REMOVE COMMENTS REF TO THIS EVENT
- // ************************************************************
- // eventSchema.pre('remove', async function (next) {
- // try {
- // await Comment.remove({
- // "_id": {
- // $in: this.comments
- // }
- // });
- // next();
- // } catch (err) {
- // next(err)
- // }
- // });
- //*********************************************************** */
- // MIDDLEWARE REMOVE REF IN USER TO THIS EVENT
- // ************************************************************
- // eventSchema.pre('remove', async function (next) {
- // try {
- // var event = this;
- // await User.update({
- // createdEvent: event._id
- // }, {
- // $pull: {
- // createdEvent: event._id
- // }
- // }, {
- // multi: true
- // });
- // next();
- // } catch (err) {
- // next(err)
- // }
- // });
- module.exports = mongoose.model('Event', eventSchema);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement