From 7252802c2440516f1a67f6a3988d950e9b0a7592 Mon Sep 17 00:00:00 2001 From: PleBea Date: Sat, 13 Jul 2024 19:25:55 +0900 Subject: [PATCH] refactor: Update PlanController to handle deep linking for plan invites --- src/modules/plan/plan.controller.ts | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/modules/plan/plan.controller.ts b/src/modules/plan/plan.controller.ts index 3d2d1b6..c86bd3e 100644 --- a/src/modules/plan/plan.controller.ts +++ b/src/modules/plan/plan.controller.ts @@ -1,6 +1,8 @@ import { User } from '@prisma/client'; +import { Request, Response } from 'express'; -import { Body, Controller, Delete, Get, Param, Post, Put, UseGuards } from '@nestjs/common'; +import { Body, Controller, Delete, Get, Param, Post, Put, Req, Res, UseGuards } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; import { AuthGuard } from '@nestjs/passport'; import { ApiBearerAuth, ApiBody, ApiOkResponse, ApiOperation, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger'; @@ -13,7 +15,10 @@ import { PlanService } from './plan.service'; @ApiTags('plan') @Controller('plan') export class PlanController { - constructor(private readonly planService: PlanService) {} + constructor( + private readonly planService: PlanService, + private readonly configService: ConfigService, + ) {} @Get() @ApiBearerAuth() @@ -58,6 +63,22 @@ export class PlanController { return await this.planService.getInvite(user); } + @Get('invite/:inviteId') + @ApiBearerAuth() + @UseGuards(AuthGuard('access')) + @ApiOperation({ summary: 'Deep link to plan invite' }) + @ApiOkResponse({ description: 'Plan invite', type: PlanResponseDTO }) + @ApiUnauthorizedResponse({ description: 'Unauthorized' }) + async getInviteById(@Req() req: Request, @Param('inviteId') inviteId: string, @Res() res: Response) { + if (req.headers['user-agent']?.toLocaleLowerCase().includes('kakaotalk')) { + return res.redirect( + `kakaotalk://web/openExternal?url=${this.configService.get('BACKEND_URL')!}/plan/invite/${inviteId}`, + ); + } + + res.redirect(`adego-by-seogaemo://invite/${inviteId}`); + } + @Post('invite/:userId') @ApiBearerAuth() @UseGuards(AuthGuard('access')) @@ -68,7 +89,7 @@ export class PlanController { return await this.planService.inviteUser(user, userId); } - @Put('accept/:inviteId') + @Put('invite/:inviteId') @ApiBearerAuth() @UseGuards(AuthGuard('access')) @ApiOperation({ summary: 'Accept a plan invite' })