aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/pods.js2
-rw-r--r--server/controllers/api/users.js32
-rw-r--r--server/controllers/api/videos.js24
3 files changed, 9 insertions, 49 deletions
diff --git a/server/controllers/api/pods.js b/server/controllers/api/pods.js
index 79f3f9d8d..d9279f1d9 100644
--- a/server/controllers/api/pods.js
+++ b/server/controllers/api/pods.js
@@ -113,7 +113,7 @@ function removePods (req, res, next) {
113 db.Pod.loadByHost(host, callback) 113 db.Pod.loadByHost(host, callback)
114 }, 114 },
115 115
116 function removePod (pod, callback) { 116 function deletePod (pod, callback) {
117 pod.destroy().asCallback(callback) 117 pod.destroy().asCallback(callback)
118 } 118 }
119 ], function (err) { 119 ], function (err) {
diff --git a/server/controllers/api/users.js b/server/controllers/api/users.js
index 890028b36..e4423680c 100644
--- a/server/controllers/api/users.js
+++ b/server/controllers/api/users.js
@@ -90,39 +90,11 @@ function listUsers (req, res, next) {
90 90
91function removeUser (req, res, next) { 91function removeUser (req, res, next) {
92 waterfall([ 92 waterfall([
93 function getUser (callback) { 93 function loadUser (callback) {
94 db.User.loadById(req.params.id, callback) 94 db.User.loadById(req.params.id, callback)
95 }, 95 },
96 96
97 // TODO: use foreignkey? 97 function deleteUser (user, callback) {
98 function getVideos (user, callback) {
99 db.Video.listOwnedByAuthor(user.username, function (err, videos) {
100 return callback(err, user, videos)
101 })
102 },
103
104 function removeVideosFromDB (user, videos, callback) {
105 each(videos, function (video, callbackEach) {
106 video.destroy().asCallback(callbackEach)
107 }, function (err) {
108 return callback(err, user, videos)
109 })
110 },
111
112 function sendInformationToFriends (user, videos, callback) {
113 videos.forEach(function (video) {
114 const params = {
115 name: video.name,
116 remoteId: video.id
117 }
118
119 friends.removeVideoToFriends(params)
120 })
121
122 return callback(null, user)
123 },
124
125 function removeUserFromDB (user, callback) {
126 user.destroy().asCallback(callback) 98 user.destroy().asCallback(callback)
127 } 99 }
128 ], function andFinally (err) { 100 ], function andFinally (err) {
diff --git a/server/controllers/api/videos.js b/server/controllers/api/videos.js
index 170224634..ddf85d77d 100644
--- a/server/controllers/api/videos.js
+++ b/server/controllers/api/videos.js
@@ -249,27 +249,15 @@ function removeVideo (req, res, next) {
249 const videoId = req.params.id 249 const videoId = req.params.id
250 250
251 waterfall([ 251 waterfall([
252 function getVideo (callback) { 252 function loadVideo (callback) {
253 db.Video.load(videoId, callback) 253 db.Video.load(videoId, function (err, video) {
254 }, 254 return callback(err, video)
255
256 function removeFromDB (video, callback) {
257 video.destroy().asCallback(function (err) {
258 if (err) return callback(err)
259
260 return callback(null, video)
261 }) 255 })
262 }, 256 },
263 257
264 function sendInformationToFriends (video, callback) { 258 function deleteVideo (video, callback) {
265 const params = { 259 // Informations to other pods will be sent by the afterDestroy video hook
266 name: video.name, 260 video.destroy().asCallback(callback)
267 remoteId: video.id
268 }
269
270 friends.removeVideoToFriends(params)
271
272 return callback(null)
273 } 261 }
274 ], function andFinally (err) { 262 ], function andFinally (err) {
275 if (err) { 263 if (err) {