Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YPP: Dev endpoint for deleting channel #228

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/services/httpApi/controllers/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,32 @@ export class ChannelsController {
}
}

@Delete(':joystreamChannelId')
@ApiResponse({ type: ChannelDto })
@ApiOperation({ description: 'Retrieves channel by joystreamChannelId' })
async delete(
@Headers('authorization') authorizationHeader: string,
@Param('joystreamChannelId', ParseIntPipe) id: number
) {
const yppOwnerKey = authorizationHeader ? authorizationHeader.split(' ')[1] : ''
// TODO: fix this YT_SYNCH__HTTP_API__OWNER_KEY config value
if (yppOwnerKey !== process.env.YT_SYNCH__HTTP_API__OWNER_KEY) {
throw new UnauthorizedException('Invalid YPP owner key')
}

try {
// Get records
const channel = await this.dynamodbService.channels.getByJoystreamId(id)

// Delete records
await this.dynamodbService.repo.channels.delete(channel.id, channel.userId)
await this.dynamodbService.repo.users.delete(channel.userId)
} catch (error) {
const message = error instanceof Error ? error.message : error
throw new NotFoundException(message)
}
}

@Get()
@ApiResponse({ type: ChannelDto })
@ApiOperation({ description: 'Retrieves the most recently verified 30 channels desc by date' })
Expand Down