X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fpods.js;h=6ab018c1ccc0d107323d573f74960b00453abeb4;hb=2c49ca42d14087ce8e1695759435f796a290470b;hp=4020a96034bed386feaa9723f74eb336ef685e9f;hpb=a6375e69668ea42e19531c6bc68dcd37f3f7cbd7;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/pods.js b/server/models/pods.js index 4020a9603..6ab018c1c 100644 --- a/server/models/pods.js +++ b/server/models/pods.js @@ -1,11 +1,14 @@ 'use strict' +const each = require('async/each') const mongoose = require('mongoose') const map = require('lodash/map') const validator = require('express-validator').validator const constants = require('../initializers/constants') +const Video = mongoose.model('Video') + // --------------------------------------------------------------------------- const PodSchema = mongoose.Schema({ @@ -51,6 +54,17 @@ PodSchema.pre('save', function (next) { }) }) +PodSchema.pre('remove', function (next) { + // Remove the videos owned by this pod too + Video.listByUrl(this.url, function (err, videos) { + if (err) return next(err) + + each(videos, function (video, callbackEach) { + video.remove(callbackEach) + }, next) + }) +}) + const Pod = mongoose.model('Pod', PodSchema) // ------------------------------ METHODS ------------------------------