-import * as Sequelize from 'sequelize'
+import { FindOptions, literal, Op, QueryTypes } from 'sequelize'
import {
AfterDestroy,
AfterUpdate,
WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL'
}
-@DefaultScope({
+@DefaultScope(() => ({
include: [
{
- model: () => AccountModel,
+ model: AccountModel,
required: true
},
{
- model: () => UserNotificationSettingModel,
+ model: UserNotificationSettingModel,
required: true
}
]
-})
-@Scopes({
+}))
+@Scopes(() => ({
[ScopeNames.WITH_VIDEO_CHANNEL]: {
include: [
{
- model: () => AccountModel,
+ model: AccountModel,
required: true,
- include: [ () => VideoChannelModel ]
+ include: [ VideoChannelModel ]
},
{
- model: () => UserNotificationSettingModel,
+ model: UserNotificationSettingModel,
required: true
}
- ] as any // FIXME: sequelize typings
+ ]
}
-})
+}))
@Table({
tableName: 'user',
indexes: [
let where = undefined
if (search) {
where = {
- [Sequelize.Op.or]: [
+ [Op.or]: [
{
email: {
- [Sequelize.Op.iLike]: '%' + search + '%'
+ [Op.iLike]: '%' + search + '%'
}
},
{
username: {
- [ Sequelize.Op.iLike ]: '%' + search + '%'
+ [ Op.iLike ]: '%' + search + '%'
}
}
]
}
}
- const query = {
+ const query: FindOptions = {
attributes: {
include: [
[
- Sequelize.literal(
+ literal(
'(' +
'SELECT COALESCE(SUM("size"), 0) ' +
'FROM (' +
')'
),
'videoQuotaUsed'
- ] as any // FIXME: typings
+ ]
]
},
offset: start,
const query = {
where: {
role: {
- [Sequelize.Op.in]: roles
+ [Op.in]: roles
}
}
}
const query = {
where: {
- [ Sequelize.Op.or ]: [ { username }, { email } ]
+ [ Op.or ]: [ { username }, { email } ]
}
}
const query = {
where: {
username: {
- [ Sequelize.Op.like ]: `%${search}%`
+ [ Op.like ]: `%${search}%`
}
},
limit: 10
const uploadedTotal = videoFile.size + totalBytes
const uploadedDaily = videoFile.size + totalBytesDaily
- if (this.videoQuotaDaily === -1) {
- return uploadedTotal < this.videoQuota
- }
- if (this.videoQuota === -1) {
- return uploadedDaily < this.videoQuotaDaily
- }
- return (uploadedTotal < this.videoQuota) &&
- (uploadedDaily < this.videoQuotaDaily)
+ if (this.videoQuotaDaily === -1) return uploadedTotal < this.videoQuota
+ if (this.videoQuota === -1) return uploadedDaily < this.videoQuotaDaily
+
+ return uploadedTotal < this.videoQuota && uploadedDaily < this.videoQuotaDaily
}
private static generateUserQuotaBaseSQL (where?: string) {
private static getTotalRawQuery (query: string, userId: number) {
const options = {
bind: { userId },
- type: Sequelize.QueryTypes.SELECT as Sequelize.QueryTypes.SELECT
+ type: QueryTypes.SELECT as QueryTypes.SELECT
}
- return UserModel.sequelize.query<{ total: number }>(query, options)
+ return UserModel.sequelize.query<{ total: string }>(query, options)
.then(([ { total } ]) => {
if (total === null) return 0
- return parseInt(total + '', 10)
+ return parseInt(total, 10)
})
}
}