diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-10-21 11:20:45 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-10-21 11:20:45 +0200 |
commit | 80a6c9e76fda57f01e37fe4620771ae70738a211 (patch) | |
tree | 7381a94285c11d954efca2be8103c8b86df3e832 /server/models/pods.js | |
parent | 792b893ed414301c060391ed8a00368d68688236 (diff) | |
download | PeerTube-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.js | 14 |
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 | ||
3 | const each = require('async/each') | ||
3 | const mongoose = require('mongoose') | 4 | const mongoose = require('mongoose') |
4 | const map = require('lodash/map') | 5 | const map = require('lodash/map') |
5 | const validator = require('express-validator').validator | 6 | const validator = require('express-validator').validator |
6 | 7 | ||
7 | const constants = require('../initializers/constants') | 8 | const constants = require('../initializers/constants') |
8 | 9 | ||
10 | const Video = mongoose.model('Video') | ||
11 | |||
9 | // --------------------------------------------------------------------------- | 12 | // --------------------------------------------------------------------------- |
10 | 13 | ||
11 | const PodSchema = mongoose.Schema({ | 14 | const PodSchema = mongoose.Schema({ |
@@ -51,6 +54,17 @@ PodSchema.pre('save', function (next) { | |||
51 | }) | 54 | }) |
52 | }) | 55 | }) |
53 | 56 | ||
57 | PodSchema.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 | |||
54 | const Pod = mongoose.model('Pod', PodSchema) | 68 | const Pod = mongoose.model('Pod', PodSchema) |
55 | 69 | ||
56 | // ------------------------------ METHODS ------------------------------ | 70 | // ------------------------------ METHODS ------------------------------ |