*/
export class AbstractRunQuery {
- protected sequelize: Sequelize
-
protected query: string
protected replacements: any = {}
- protected runQuery (options: { transaction?: Transaction, logging?: boolean } = {}) {
+ constructor (protected readonly sequelize: Sequelize) {
+
+ }
+
+ protected runQuery (options: { nest?: boolean, transaction?: Transaction, logging?: boolean } = {}) {
const queryOptions = {
transaction: options.transaction,
logging: options.logging,
replacements: this.replacements,
type: QueryTypes.SELECT as QueryTypes.SELECT,
- nest: false
+ nest: options.nest ?? false
}
return this.sequelize.query<any>(this.query, queryOptions)
+export * from './abstract-run-query'
export * from './model-builder'
export * from './query'
export * from './update'
-import { QueryTypes, Sequelize } from 'sequelize'
-import { ModelBuilder } from '@server/models/shared'
+import { Sequelize } from 'sequelize'
+import { AbstractRunQuery, ModelBuilder } from '@server/models/shared'
import { getSort } from '@server/models/utils'
import { UserNotificationModelForApi } from '@server/types/models'
import { ActorImageType } from '@shared/models'
sort: string
offset: number
limit: number
- sequelize: Sequelize
}
-export class UserNotificationListQueryBuilder {
+export class UserNotificationListQueryBuilder extends AbstractRunQuery {
private innerQuery: string
- private replacements: any = {}
- private query: string
-
- constructor (private readonly options: ListNotificationsOptions) {
+ constructor (
+ protected readonly sequelize: Sequelize,
+ private readonly options: ListNotificationsOptions
+ ) {
+ super(sequelize)
}
async listNotifications () {
this.buildQuery()
- const results = await this.options.sequelize.query(this.query, {
- replacements: this.replacements,
- type: QueryTypes.SELECT,
- nest: true
- })
-
- const modelBuilder = new ModelBuilder<UserNotificationModelForApi>(this.options.sequelize)
+ const results = await this.runQuery({ nest: true })
+ const modelBuilder = new ModelBuilder<UserNotificationModelForApi>(this.sequelize)
return modelBuilder.createModels(results, 'UserNotification')
}
offset: start,
limit: count,
sort,
- where,
- sequelize: this.sequelize
+ where
}
if (unread !== undefined) query.where['read'] = !unread
count === 0
? [] as UserNotificationModelForApi[]
- : new UserNotificationListQueryBuilder(query).listNotifications()
+ : new UserNotificationListQueryBuilder(this.sequelize, query).listNotifications()
]).then(([ total, data ]) => ({ total, data }))
}
+import { Sequelize } from 'sequelize'
+import validator from 'validator'
import { createSafeIn } from '@server/models/utils'
import { MUserAccountId } from '@server/types/models'
import { ActorImageType } from '@shared/models'
-import validator from 'validator'
-import { AbstractRunQuery } from './abstract-run-query'
+import { AbstractRunQuery } from '../../../../shared/abstract-run-query'
import { VideoTableAttributes } from './video-table-attributes'
/**
protected tables: VideoTableAttributes
- constructor (protected readonly mode: 'list' | 'get') {
- super()
+ constructor (
+ protected readonly sequelize: Sequelize,
+ protected readonly mode: 'list' | 'get'
+ ) {
+ super(sequelize)
this.tables = new VideoTableAttributes(this.mode)
}
protected attributes: { [key: string]: string }
constructor (protected readonly sequelize: Sequelize) {
- super('get')
+ super(sequelize, 'get')
}
queryWebTorrentVideos (options: BuildVideoGetQueryOptions) {
private readonly buildOpts = { raw: true, isNewRecord: false }
constructor (
- readonly mode: 'get' | 'list',
- readonly tables: VideoTableAttributes
+ private readonly mode: 'get' | 'list',
+ private readonly tables: VideoTableAttributes
) {
}
*/
export class VideoTableAttributes {
- constructor (readonly mode: 'get' | 'list') {
+ constructor (private readonly mode: 'get' | 'list') {
}
])
constructor (protected readonly sequelize: Sequelize) {
- super('get')
+ super(sequelize, 'get')
}
queryVideos (options: BuildVideoGetQueryOptions) {
import { buildDirectionAndField, createSafeIn } from '@server/models/utils'
import { MUserAccountId, MUserId } from '@server/types/models'
import { VideoInclude, VideoPrivacy, VideoState } from '@shared/models'
-import { AbstractRunQuery } from './shared/abstract-run-query'
+import { AbstractRunQuery } from '../../../shared/abstract-run-query'
/**
*
private offset = ''
constructor (protected readonly sequelize: Sequelize) {
- super()
+ super(sequelize)
}
queryVideoIds (options: BuildVideosListQueryOptions) {
private readonly videoModelBuilder: VideoModelBuilder
constructor (protected readonly sequelize: Sequelize) {
- super('list')
+ super(sequelize, 'list')
this.videoModelBuilder = new VideoModelBuilder(this.mode, this.tables)
}