import { User, UserRole } from '../../../shared/models/users'
import {
isUserAutoPlayVideoValid,
+ isUserBlockedReasonValid,
isUserBlockedValid,
isUserNSFWPolicyValid,
isUserPasswordValid,
@Column
blocked: boolean
+ @AllowNull(true)
+ @Default(null)
+ @Is('UserBlockedReason', value => throwIfNotValid(value, isUserBlockedReasonValid, 'blocked reason'))
+ @Column
+ blockedReason: string
+
@AllowNull(false)
@Is('UserRole', value => throwIfNotValid(value, isUserRoleValid, 'role'))
@Column
static listForApi (start: number, count: number, sort: string) {
const query = {
+ attributes: {
+ include: [
+ [
+ Sequelize.literal(
+ '(' +
+ 'SELECT COALESCE(SUM("size"), 0) FROM ' +
+ '(' +
+ 'SELECT MAX("videoFile"."size") AS "size" FROM "videoFile" ' +
+ 'INNER JOIN "video" ON "videoFile"."videoId" = "video"."id" ' +
+ 'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
+ 'INNER JOIN "account" ON "videoChannel"."accountId" = "account"."id" ' +
+ 'WHERE "account"."userId" = "UserModel"."id" GROUP BY "video"."id"' +
+ ') t' +
+ ')'
+ ),
+ 'videoQuotaUsed'
+ ] as any // FIXME: typings
+ ]
+ },
offset: start,
limit: count,
order: getSort(sort)
return UserModel.findAndCountAll(query)
.then(({ rows, count }) => {
+ console.log(rows[0])
+ console.log(rows[0]['videoQuotaUsed'])
+ console.log(rows[0].get('videoQuotaUsed'))
return {
data: rows,
total: count
'INNER JOIN "video" ON "videoFile"."videoId" = "video"."id" ' +
'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
'INNER JOIN "account" ON "videoChannel"."accountId" = "account"."id" ' +
- 'INNER JOIN "user" ON "account"."userId" = "user"."id" ' +
- 'WHERE "user"."id" = $userId GROUP BY "video"."id") t'
+ 'WHERE "account"."userId" = $userId GROUP BY "video"."id") t'
const options = {
bind: { userId: user.id },
}
toFormattedJSON (): User {
+ const videoQuotaUsed = this.get('videoQuotaUsed')
+
const json = {
id: this.id,
username: this.username,
roleLabel: USER_ROLE_LABELS[ this.role ],
videoQuota: this.videoQuota,
createdAt: this.createdAt,
+ blocked: this.blocked,
+ blockedReason: this.blockedReason,
account: this.Account.toFormattedJSON(),
- videoChannels: []
+ videoChannels: [],
+ videoQuotaUsed: videoQuotaUsed !== undefined ? parseInt(videoQuotaUsed, 10) : undefined
}
if (Array.isArray(this.Account.VideoChannels) === true) {