Skip to content

Commit

Permalink
refactor: Update PlanController to handle deep linking for plan invites
Browse files Browse the repository at this point in the history
  • Loading branch information
PleBea committed Jul 13, 2024
1 parent 2d7496d commit 7252802
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/modules/plan/plan.controller.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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()
Expand Down Expand Up @@ -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<string>('BACKEND_URL')!}/plan/invite/${inviteId}`,
);
}

res.redirect(`adego-by-seogaemo://invite/${inviteId}`);
}

@Post('invite/:userId')
@ApiBearerAuth()
@UseGuards(AuthGuard('access'))
Expand All @@ -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' })
Expand Down

0 comments on commit 7252802

Please sign in to comment.