From 4712081f2a5f48749cf125d729e78b926ab28d6d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 29 Dec 2016 10:33:36 +0100 Subject: Server: add association between author and user --- server/controllers/api/remote.js | 6 ++++-- server/controllers/api/videos.js | 17 ++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/api/remote.js b/server/controllers/api/remote.js index 2cf916ff3..94d6e740e 100644 --- a/server/controllers/api/remote.js +++ b/server/controllers/api/remote.js @@ -84,11 +84,13 @@ function addRemoteVideo (videoToCreateData, fromHost, finalCallback) { const query = { where: { name: username, - podId: pod.id + podId: pod.id, + userId: null }, defaults: { name: username, - podId: pod.id + podId: pod.id, + userId: null }, transaction: t } diff --git a/server/controllers/api/videos.js b/server/controllers/api/videos.js index 992f03db0..170224634 100644 --- a/server/controllers/api/videos.js +++ b/server/controllers/api/videos.js @@ -95,23 +95,26 @@ function addVideo (req, res, next) { }, function findOrCreateAuthor (t, callback) { - const username = res.locals.oauth.token.user.username + const user = res.locals.oauth.token.User const query = { where: { - name: username, - podId: null + name: user.username, + podId: null, + userId: user.id }, defaults: { - name: username, - podId: null // null because it is OUR pod + name: user.username, + podId: null, // null because it is OUR pod + userId: user.id }, transaction: t } db.Author.findOrCreate(query).asCallback(function (err, result) { - // [ instance, wasCreated ] - return callback(err, t, result[0]) + const authorInstance = result[0] + + return callback(err, t, authorInstance) }) }, -- cgit v1.2.3