- waterfall([
- function addPod (callback) {
- const pod = db.Pod.build(informations)
- pod.save().asCallback(function (err, podCreated) {
- // Be sure about the number of parameters for the callback
- return callback(err, podCreated)
- })
- },
-
- function sendMyVideos (podCreated, callback) {
- sendOwnedVideosToPod(podCreated.id)
-
- callback(null)
- },
-
- function fetchMyCertificate (callback) {
- getMyPublicCert(function (err, cert) {
- if (err) {
- logger.error('Cannot read cert file.')
- return callback(err)
- }
-
- return callback(null, cert)
- })
- }
- ], function (err, cert) {
- if (err) return next(err)
-
- return res.json({ cert: cert, email: CONFIG.ADMIN.EMAIL })
- })
+ const pod = db.Pod.build(informations)
+ pod.save()
+ .then(podCreated => {
+ return sendOwnedVideosToPod(podCreated.id)
+ })
+ .then(() => {
+ return getMyPublicCert()
+ })
+ .then(cert => {
+ return res.json({ cert: cert, email: CONFIG.ADMIN.EMAIL })
+ })
+ .catch(err => next(err))