From 6076978cb7bd342767fca1c4ebed01484dda2489 Mon Sep 17 00:00:00 2001 From: Zeeshan Akram <97m.zeeshan@gmail.com> Date: Wed, 2 Aug 2023 10:55:13 +0000 Subject: [PATCH] (DEV) endpoint for deleting channel records --- src/services/httpApi/controllers/channels.ts | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/services/httpApi/controllers/channels.ts b/src/services/httpApi/controllers/channels.ts index fc9077e6..5e76a2ce 100644 --- a/src/services/httpApi/controllers/channels.ts +++ b/src/services/httpApi/controllers/channels.ts @@ -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' })