- [ScopeNames.FOR_API]: (options: {
- // search
- search?: string
- searchReporter?: string
- searchReportee?: string
-
- // video releated
- searchVideo?: string
- searchVideoChannel?: string
- videoIs?: AbuseVideoIs
-
- // filters
- id?: number
- predefinedReasonId?: number
- filter?: AbuseFilter
-
- state?: AbuseState
-
- // accountIds
- serverAccountId: number
- userAccountId: number
- }) => {
- const onlyBlacklisted = options.videoIs === 'blacklisted'
- const videoRequired = !!(onlyBlacklisted || options.searchVideo || options.searchVideoChannel)
-
- const where = {
- reporterAccountId: {
- [Op.notIn]: literal('(' + buildBlockedAccountSQL([ options.serverAccountId, options.userAccountId ]) + ')')
- }
- }
-
- if (options.search) {
- const escapedSearch = AbuseModel.sequelize.escape('%' + options.search + '%')
-
- Object.assign(where, {
- [Op.or]: [
- {
- [Op.and]: [
- { '$VideoAbuse.videoId$': { [Op.not]: null } },
- searchAttribute(options.search, '$VideoAbuse.Video.name$')
- ]
- },
- {
- [Op.and]: [
- { '$VideoAbuse.videoId$': { [Op.not]: null } },
- searchAttribute(options.search, '$VideoAbuse.Video.VideoChannel.name$')
- ]
- },
- {
- [Op.and]: [
- { '$VideoAbuse.deletedVideo$': { [Op.not]: null } },
- literal(`"VideoAbuse"."deletedVideo"->>'name' ILIKE ${escapedSearch}`)
- ]
- },
- {
- [Op.and]: [
- { '$VideoAbuse.deletedVideo$': { [Op.not]: null } },
- literal(`"VideoAbuse"."deletedVideo"->'channel'->>'displayName' ILIKE ${escapedSearch}`)
- ]
- },
- searchAttribute(options.search, '$ReporterAccount.name$'),
- searchAttribute(options.search, '$FlaggedAccount.name$')
- ]
- })
- }
-
- if (options.id) Object.assign(where, { id: options.id })
- if (options.state) Object.assign(where, { state: options.state })
-
- if (options.videoIs === 'deleted') {
- Object.assign(where, {
- '$VideoAbuse.deletedVideo$': {
- [Op.not]: null
- }
- })
- }
-
- if (options.predefinedReasonId) {
- Object.assign(where, {
- predefinedReasons: {
- [Op.contains]: [ options.predefinedReasonId ]
- }
- })
- }
-