From 77a5501f6413aff2f2a626b929dfda486fa9a3e6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 6 Sep 2017 16:35:40 +0200 Subject: Fix tests and user quota --- server/models/user/user.ts | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'server/models/user/user.ts') diff --git a/server/models/user/user.ts b/server/models/user/user.ts index 9bf13ad24..79a595528 100644 --- a/server/models/user/user.ts +++ b/server/models/user/user.ts @@ -242,25 +242,26 @@ loadByUsernameOrEmail = function (username: string, email: string) { // --------------------------------------------------------------------------- function getOriginalVideoFileTotalFromUser (user: UserInstance) { + // attributes = [] because we don't want other fields than the sum const query = { - attributes: [ - Sequelize.fn('COUNT', Sequelize.col('User.Author.Video.VideoFile.size'), 'totalVideoBytes') - ], where: { - id: user.id + resolution: 0 // Original, TODO: improve readability }, include: [ { - model: User['sequelize'].models.Author, - required: true, + attributes: [], + model: User['sequelize'].models.Video, include: [ { - model: User['sequelize'].models.Video, - required: true, + attributes: [], + model: User['sequelize'].models.Author, include: [ { - model: User['sequelize'].models.VideoFile, - required: true + attributes: [], + model: User['sequelize'].models.User, + where: { + id: user.id + } } ] } @@ -269,8 +270,5 @@ function getOriginalVideoFileTotalFromUser (user: UserInstance) { ] } - // FIXME: cast to any because of bad typing... - return User.findAll(query).then((res: any) => { - return res.totalVideoBytes - }) + return User['sequelize'].models.VideoFile.sum('size', query) } -- cgit v1.2.3