From cc7daae256397c6a14c2cd064ba92b4266a1a7f6 Mon Sep 17 00:00:00 2001 From: donghquinn Date: Mon, 4 Mar 2024 16:47:35 +0900 Subject: [PATCH] wip: star post --- src/controllers/geek/geek.ctl.ts | 8 ++++---- src/controllers/hacker/hacker.ctl.ts | 8 ++++---- src/controllers/machine/machine.ctl.ts | 8 ++++---- src/providers/news/geek/geek.pvd.ts | 7 ++++--- src/providers/news/hacker/hacker.pvd.ts | 5 +++-- src/providers/news/ml/machine.pvd.ts | 5 +++-- src/types/request.type.ts | 5 ++++- src/validators/hacker.validator.ts | 2 +- src/validators/hada.validator.ts | 2 +- src/validators/ml.validator.ts | 2 +- 10 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/controllers/geek/geek.ctl.ts b/src/controllers/geek/geek.ctl.ts index 4921d1e..1c2fa3d 100755 --- a/src/controllers/geek/geek.ctl.ts +++ b/src/controllers/geek/geek.ctl.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Get, Headers, Post, Query } from '@nestjs/common'; +import { Body, Controller, Get, Post, Query } from '@nestjs/common'; import { hadaNewsStarValidator, hadaNewsValidator } from '@validators/hada.validator'; import { SetErrorResponse, SetResponse } from 'dto/response.dto'; import { GeekProvider } from 'providers/news/geek/geek.pvd'; @@ -23,11 +23,11 @@ export class GeekController { } @Post('/star') - async giveStarNews(@Body() request: StarRequest, @Headers('Authorization') clientUuid: string) { + async giveStarNews(@Body() request: StarRequest) { try { - const { uuid: postUuid } = await hadaNewsStarValidator(request); + const { uuid: postUuid, email } = await hadaNewsStarValidator(request); - const result = await this.geek.giveStar(postUuid, clientUuid); + const result = await this.geek.giveStar(postUuid, email); return new SetResponse(200, { result }); } catch (error) { diff --git a/src/controllers/hacker/hacker.ctl.ts b/src/controllers/hacker/hacker.ctl.ts index a72fc4e..dccca8b 100755 --- a/src/controllers/hacker/hacker.ctl.ts +++ b/src/controllers/hacker/hacker.ctl.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Get, Headers, Post, Query } from '@nestjs/common'; +import { Body, Controller, Get, Post, Query } from '@nestjs/common'; import { hackerNewsStarValidator, hackerNewsValidator } from '@validators/hacker.validator'; import { SetErrorResponse, SetResponse } from 'dto/response.dto'; import { HackersNewsProvider } from 'providers/news/hacker/hacker.pvd'; @@ -38,11 +38,11 @@ export class HackerController { } @Post('/star') - async giveStarNews(@Body() request: StarRequest, @Headers('Authorization') clientUuid: string) { + async giveStarNews(@Body() request: StarRequest) { try { - const { uuid: PostUuid } = await hackerNewsStarValidator(request); + const { uuid: PostUuid, email } = await hackerNewsStarValidator(request); - const result = await this.hacker.giveStar(PostUuid, clientUuid); + const result = await this.hacker.giveStar(PostUuid, email); return new SetResponse(200, { result }); } catch (error) { diff --git a/src/controllers/machine/machine.ctl.ts b/src/controllers/machine/machine.ctl.ts index 92fe72a..be4451f 100644 --- a/src/controllers/machine/machine.ctl.ts +++ b/src/controllers/machine/machine.ctl.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Get, Headers, Post, Query } from '@nestjs/common'; +import { Body, Controller, Get, Post, Query } from '@nestjs/common'; import { machineLearningValidator, mlNewsStarValidator } from '@validators/ml.validator'; import { SetErrorResponse, SetResponse } from 'dto/response.dto'; import { MachineLearningProvider } from 'providers/news/ml/machine.pvd'; @@ -27,11 +27,11 @@ export class MachineLearningController { } @Post('/star') - async giveStarNews(@Body() request: StarRequest, @Headers('Authorization') clientUuid: string) { + async giveStarNews(@Body() request: StarRequest) { try { - const { uuid: postUuid } = await mlNewsStarValidator(request); + const { uuid: postUuid, email } = await mlNewsStarValidator(request); - const result = await this.mlNews.giveStar(postUuid, clientUuid); + const result = await this.mlNews.giveStar(postUuid, email); return new SetResponse(200, { result }); } catch (error) { diff --git a/src/providers/news/geek/geek.pvd.ts b/src/providers/news/geek/geek.pvd.ts index 278744c..9141681 100644 --- a/src/providers/news/geek/geek.pvd.ts +++ b/src/providers/news/geek/geek.pvd.ts @@ -88,12 +88,13 @@ export class GeekProvider { } } - async giveStar(postUuid: string, clientUuid: string) { + async giveStar(postUuid: string, email: string) { try { - const isLogined = await this.account.getItem(clientUuid); + const isLogined = await this.account.getItem(email); - if (!isLogined) throw new HadaError('[GEEK] Give Star on the Stars', 'No Logined User Found.'); + if (isLogined === null) throw new HadaError('[GEEK] Give Star on the Stars', 'No Logined User Found.'); + const { uuid: clientUuid } = isLogined; const { uuid: likedUuid, liked } = await this.prisma.checkHadaNewsIsLiked(postUuid, clientUuid); if (liked) { diff --git a/src/providers/news/hacker/hacker.pvd.ts b/src/providers/news/hacker/hacker.pvd.ts index 832978e..db13a20 100755 --- a/src/providers/news/hacker/hacker.pvd.ts +++ b/src/providers/news/hacker/hacker.pvd.ts @@ -69,12 +69,13 @@ export class HackersNewsProvider { } } - async giveStar(postUuid: string, clientUuid: string) { + async giveStar(postUuid: string, email: string) { try { - const isLogined = await this.account.getItem(clientUuid); + const isLogined = await this.account.getItem(email); if (!isLogined) throw new HackerError('[Hackers] Give Star on the Stars', 'No Logined User Found.'); + const { uuid: clientUuid } = isLogined; const { uuid: likedUuid, isLiked } = await this.prisma.checkHackerNewsIsLiked(postUuid, clientUuid); if (isLiked) { diff --git a/src/providers/news/ml/machine.pvd.ts b/src/providers/news/ml/machine.pvd.ts index 4d6d2d8..e885825 100644 --- a/src/providers/news/ml/machine.pvd.ts +++ b/src/providers/news/ml/machine.pvd.ts @@ -48,12 +48,13 @@ export class MachineLearningProvider { } } - async giveStar(postUuid: string, clientUuid: string) { + async giveStar(postUuid: string, email: string) { try { - const isLogined = await this.account.getItem(clientUuid); + const isLogined = await this.account.getItem(email); if (!isLogined) throw new MachineLearningError('[ML] Give Star on the Stars', 'No Logined User Found.'); + const { uuid: clientUuid } = isLogined; const { uuid: likedUuid, isLiked } = await this.prisma.checkIsMlNewsLiked(postUuid, clientUuid); if (!isLiked) { diff --git a/src/types/request.type.ts b/src/types/request.type.ts index 7d09b25..000787b 100755 --- a/src/types/request.type.ts +++ b/src/types/request.type.ts @@ -1,3 +1,6 @@ -export interface StarRequest { +export interface StarRequest +{ + // Post UUID uuid: string; + email: string; } diff --git a/src/validators/hacker.validator.ts b/src/validators/hacker.validator.ts index 841d387..f91c6b8 100644 --- a/src/validators/hacker.validator.ts +++ b/src/validators/hacker.validator.ts @@ -26,7 +26,7 @@ export const hackerNewsValidator = async (request: DailyHackerNewsRequest) => { export const hackerNewsStarValidator = async (request: StarRequest) => { try { - const scheme = z.object({ uuid: z.string() }); + const scheme = z.object({ uuid: z.string(), email: z.string() }); const validated = await scheme.parseAsync(request); diff --git a/src/validators/hada.validator.ts b/src/validators/hada.validator.ts index 402e265..bdb1b5b 100644 --- a/src/validators/hada.validator.ts +++ b/src/validators/hada.validator.ts @@ -26,7 +26,7 @@ export const hadaNewsValidator = async (request: DailyHadaNewsRequest) => { export const hadaNewsStarValidator = async (request: StarRequest) => { try { - const scheme = z.object({ uuid: z.string() }); + const scheme = z.object({ uuid: z.string(), email: z.string() }); const validated = await scheme.parseAsync(request); diff --git a/src/validators/ml.validator.ts b/src/validators/ml.validator.ts index 84d0cf4..a2a0290 100644 --- a/src/validators/ml.validator.ts +++ b/src/validators/ml.validator.ts @@ -26,7 +26,7 @@ export const machineLearningValidator = async (request: DailyMlNewsRequest) => { export const mlNewsStarValidator = async (request: StarRequest) => { try { - const scheme = z.object({ uuid: z.string() }); + const scheme = z.object({ uuid: z.string(), email: z.string() }); const validated = await scheme.parseAsync(request);