Skip to content

Commit

Permalink
add feat. to unset public feed videos
Browse files Browse the repository at this point in the history
  • Loading branch information
zeeshanakram3 committed Feb 26, 2024
1 parent 7f39a7c commit 4e77fc0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
12 changes: 7 additions & 5 deletions src/server-extension/resolvers/VideosResolver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ import {
ExcludeVideoInfo,
MostViewedVideosConnectionArgs,
ReportVideoArgs,
SetPublicFeedArgs,
SetPublicFeedResult,
SetOrUnsetPublicFeedArgs,
SetOrUnsetPublicFeedResult,
VideoReportInfo,
} from './types'

Expand Down Expand Up @@ -234,16 +234,18 @@ export class VideosResolver {
return result as VideoReturnType[]
}

@Mutation(() => SetPublicFeedResult)
@Mutation(() => SetOrUnsetPublicFeedResult)
@UseMiddleware(OperatorOnly(OperatorPermission.SET_PUBLIC_FEED_VIDEOS))
async setPublicFeedVideos(@Args() { videoIds }: SetPublicFeedArgs): Promise<SetPublicFeedResult> {
async setOrUnsetPublicFeedVideos(
@Args() { videoIds, operation }: SetOrUnsetPublicFeedArgs
): Promise<SetOrUnsetPublicFeedResult> {
const em = await this.em()

return withHiddenEntities(em, async () => {
const result = await em
.createQueryBuilder()
.update<Video>(Video)
.set({ includeInHomeFeed: true })
.set({ includeInHomeFeed: operation === 'set' })
.where({ id: In(videoIds) })
.execute()

Expand Down
18 changes: 15 additions & 3 deletions src/server-extension/resolvers/VideosResolver/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MaxLength } from 'class-validator'
import { ArgsType, Field, Int, ObjectType } from 'type-graphql'
import { ArgsType, Field, Int, ObjectType, registerEnumType } from 'type-graphql'
import { Video, VideoOrderByInput, VideoWhereInput } from '../baseTypes'
import { EntityReportInfo } from '../commonTypes'

Expand Down Expand Up @@ -115,14 +115,26 @@ export class DumbPublicFeedArgs {
limit?: number
}

export enum PublicFeedOperationType {
SET = 'set',
UNSET = 'unset',
}
registerEnumType(PublicFeedOperationType, { name: 'PublicFeedOperationType' })

@ArgsType()
export class SetPublicFeedArgs {
export class SetOrUnsetPublicFeedArgs {
@Field(() => [String], { nullable: false })
videoIds!: string[]

@Field(() => PublicFeedOperationType, {
nullable: false,
description: 'Type of operation to perform',
})
operation: PublicFeedOperationType
}

@ObjectType()
export class SetPublicFeedResult {
export class SetOrUnsetPublicFeedResult {
@Field(() => Int)
numberOfEntitiesAffected!: number
}

0 comments on commit 4e77fc0

Please sign in to comment.