aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-09-05 22:09:16 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-09-05 22:09:16 +0200
commit5c98d3bf078852043cbdd582c01e3dc4f4b5b79f (patch)
tree303d57ecc3c5d7b73cbbeb7187986a3dab87bcf0 /server/models
parent8094a8980265a0a28e508dbd7cf7c7029e6d98b6 (diff)
downloadPeerTube-5c98d3bf078852043cbdd582c01e3dc4f4b5b79f.tar.gz
PeerTube-5c98d3bf078852043cbdd582c01e3dc4f4b5b79f.tar.zst
PeerTube-5c98d3bf078852043cbdd582c01e3dc4f4b5b79f.zip
Begin tests for user quota
Diffstat (limited to 'server/models')
-rw-r--r--server/models/user/user.ts7
-rw-r--r--server/models/video/author.ts8
2 files changed, 13 insertions, 2 deletions
diff --git a/server/models/user/user.ts b/server/models/user/user.ts
index 12a7547f5..9bf13ad24 100644
--- a/server/models/user/user.ts
+++ b/server/models/user/user.ts
@@ -244,7 +244,7 @@ loadByUsernameOrEmail = function (username: string, email: string) {
244function getOriginalVideoFileTotalFromUser (user: UserInstance) { 244function getOriginalVideoFileTotalFromUser (user: UserInstance) {
245 const query = { 245 const query = {
246 attributes: [ 246 attributes: [
247 Sequelize.fn('COUNT', Sequelize.col('VideoFile.size'), 'totalVideoBytes') 247 Sequelize.fn('COUNT', Sequelize.col('User.Author.Video.VideoFile.size'), 'totalVideoBytes')
248 ], 248 ],
249 where: { 249 where: {
250 id: user.id 250 id: user.id
@@ -252,12 +252,15 @@ function getOriginalVideoFileTotalFromUser (user: UserInstance) {
252 include: [ 252 include: [
253 { 253 {
254 model: User['sequelize'].models.Author, 254 model: User['sequelize'].models.Author,
255 required: true,
255 include: [ 256 include: [
256 { 257 {
257 model: User['sequelize'].models.Video, 258 model: User['sequelize'].models.Video,
259 required: true,
258 include: [ 260 include: [
259 { 261 {
260 model: User['sequelize'].models.VideoFile 262 model: User['sequelize'].models.VideoFile,
263 required: true
261 } 264 }
262 ] 265 ]
263 } 266 }
diff --git a/server/models/video/author.ts b/server/models/video/author.ts
index c30cc306d..fd0f44f6b 100644
--- a/server/models/video/author.ts
+++ b/server/models/video/author.ts
@@ -71,6 +71,14 @@ function associate (models) {
71 }, 71 },
72 onDelete: 'cascade' 72 onDelete: 'cascade'
73 }) 73 })
74
75 Author.hasMany(models.Video, {
76 foreignKey: {
77 name: 'authorId',
78 allowNull: false
79 },
80 onDelete: 'cascade'
81 })
74} 82}
75 83
76findOrCreateAuthor = function (name: string, podId: number, userId: number, transaction: Sequelize.Transaction) { 84findOrCreateAuthor = function (name: string, podId: number, userId: number, transaction: Sequelize.Transaction) {