aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/pods.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-10-21 11:20:45 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-10-21 11:20:45 +0200
commit80a6c9e76fda57f01e37fe4620771ae70738a211 (patch)
tree7381a94285c11d954efca2be8103c8b86df3e832 /server/models/pods.js
parent792b893ed414301c060391ed8a00368d68688236 (diff)
downloadPeerTube-80a6c9e76fda57f01e37fe4620771ae70738a211.tar.gz
PeerTube-80a6c9e76fda57f01e37fe4620771ae70738a211.tar.zst
PeerTube-80a6c9e76fda57f01e37fe4620771ae70738a211.zip
Server: pod removing refractoring
Diffstat (limited to 'server/models/pods.js')
-rw-r--r--server/models/pods.js14
1 files changed, 14 insertions, 0 deletions
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 @@
1'use strict' 1'use strict'
2 2
3const each = require('async/each')
3const mongoose = require('mongoose') 4const mongoose = require('mongoose')
4const map = require('lodash/map') 5const map = require('lodash/map')
5const validator = require('express-validator').validator 6const validator = require('express-validator').validator
6 7
7const constants = require('../initializers/constants') 8const constants = require('../initializers/constants')
8 9
10const Video = mongoose.model('Video')
11
9// --------------------------------------------------------------------------- 12// ---------------------------------------------------------------------------
10 13
11const PodSchema = mongoose.Schema({ 14const PodSchema = mongoose.Schema({
@@ -51,6 +54,17 @@ PodSchema.pre('save', function (next) {
51 }) 54 })
52}) 55})
53 56
57PodSchema.pre('remove', function (next) {
58 // Remove the videos owned by this pod too
59 Video.listByUrl(this.url, function (err, videos) {
60 if (err) return next(err)
61
62 each(videos, function (video, callbackEach) {
63 video.remove(callbackEach)
64 }, next)
65 })
66})
67
54const Pod = mongoose.model('Pod', PodSchema) 68const Pod = mongoose.model('Pod', PodSchema)
55 69
56// ------------------------------ METHODS ------------------------------ 70// ------------------------------ METHODS ------------------------------