'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({
PodSchema.path('score').validate(function (value) { return !isNaN(value) })
PodSchema.methods = {
- toFormatedJSON: toFormatedJSON
+ toFormatedJSON
}
PodSchema.statics = {
- countAll: countAll,
- incrementScores: incrementScores,
- list: list,
- listAllIds: listAllIds,
- listBadPods: listBadPods,
- load: load,
- loadByUrl: loadByUrl,
- removeAll: removeAll
+ countAll,
+ incrementScores,
+ list,
+ listAllIds,
+ listBadPods,
+ load,
+ loadByUrl,
+ removeAll
}
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 ------------------------------