Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Comment model
- //***********************************************************************************
- 'use strict'
- var mongoose = require('mongoose');
- var Schema = mongoose.Schema;
- var Event = require('./event_model');
- var User = require('./user_model');
- var commentSchema = new Schema({
- content: String,
- author: { type: Schema.Types.ObjectId, ref: 'User' },
- event: { type: Schema.Types.ObjectId, ref: 'Event' }
- },
- {
- timestamps: true //auto generation time of creation and last update
- });
- commentSchema.pre('remove', async function (next) {
- var comment = this;
- try {
- await Event.update({
- comments: comment._id
- }, {
- $pull: {
- comments: comment._id
- }
- });
- console.log('MIDDLEWARE REMOVE 1');
- await User.update({
- comment: comment._id
- }, {
- $pull: {
- comment: comment._id
- }
- });
- console.log('MIDDLEWARE REMOVE 2');
- // next();
- } catch (err) {
- console.log('err');
- console.log(err);
- next(err)
- }
- })
- module.exports = mongoose.model('Comment', commentSchema);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement