From bfdbba1de4adba6d3798424b0159dcf1bb355973 Mon Sep 17 00:00:00 2001 From: ohddang Date: Sat, 4 May 2024 06:24:37 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=EC=84=9C=EB=B2=84=EA=B0=84=20?= =?UTF-8?q?=ED=86=B5=EC=8B=A0=EC=9D=84=20=EC=9C=84=ED=95=9C=20internal=20m?= =?UTF-8?q?odule=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.module.ts | 2 ++ src/dto/internal.dto.ts | 7 +++++++ src/internal/internal.controller.spec.ts | 18 ++++++++++++++++++ src/internal/internal.controller.ts | 14 ++++++++++++++ src/internal/internal.module.ts | 10 ++++++++++ src/internal/internal.service.spec.ts | 18 ++++++++++++++++++ src/internal/internal.service.ts | 11 +++++++++++ src/main.ts | 6 +++--- 8 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 src/dto/internal.dto.ts create mode 100644 src/internal/internal.controller.spec.ts create mode 100644 src/internal/internal.controller.ts create mode 100644 src/internal/internal.module.ts create mode 100644 src/internal/internal.service.spec.ts create mode 100644 src/internal/internal.service.ts diff --git a/src/app.module.ts b/src/app.module.ts index b9467f0..09c51da 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -10,6 +10,7 @@ import { FriendModule } from './friend/friend.module'; import { LoggerModule } from './common/logger/logger.module'; import { LoggingMiddleware } from './common/logger/logger.middleware'; import { AuthService } from './auth/auth.service'; +import { InternalModule } from './internal/internal.module'; @Module({ imports: [ @@ -17,6 +18,7 @@ import { AuthService } from './auth/auth.service'; AuthModule, ConfigModule.forRoot({ isGlobal: true }), FriendModule, + InternalModule, ], controllers: [UserController, AppController], providers: [PrismaService, UserService, AppService, AuthService], diff --git a/src/dto/internal.dto.ts b/src/dto/internal.dto.ts new file mode 100644 index 0000000..fc2fc8e --- /dev/null +++ b/src/dto/internal.dto.ts @@ -0,0 +1,7 @@ +import { IsEmail, IsNotEmpty } from 'class-validator'; + +export class VerifyEmailDto { + @IsNotEmpty() + @IsEmail() + email: string; +} diff --git a/src/internal/internal.controller.spec.ts b/src/internal/internal.controller.spec.ts new file mode 100644 index 0000000..c409752 --- /dev/null +++ b/src/internal/internal.controller.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { InternalController } from './internal.controller'; + +describe('InternalController', () => { + let controller: InternalController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [InternalController], + }).compile(); + + controller = module.get(InternalController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/src/internal/internal.controller.ts b/src/internal/internal.controller.ts new file mode 100644 index 0000000..3763667 --- /dev/null +++ b/src/internal/internal.controller.ts @@ -0,0 +1,14 @@ +import { Body, Controller, HttpCode, Post } from '@nestjs/common'; +import { InternalService } from './internal.service'; +import { VerifyEmailDto } from 'src/dto/internal.dto'; + +@Controller('internal/v1') +export class InternalController { + constructor(private readonly internalService: InternalService) {} + + @Post('verifyEmail') + @HttpCode(200) + async verifyEmail(@Body() verifyEmailDto: VerifyEmailDto): Promise { + return this.internalService.verifyEmail(verifyEmailDto.email); + } +} diff --git a/src/internal/internal.module.ts b/src/internal/internal.module.ts new file mode 100644 index 0000000..9971ab1 --- /dev/null +++ b/src/internal/internal.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { InternalService } from './internal.service'; +import { InternalController } from './internal.controller'; +import { PrismaService } from 'src/prisma.service'; + +@Module({ + providers: [InternalService, PrismaService], + controllers: [InternalController], +}) +export class InternalModule {} diff --git a/src/internal/internal.service.spec.ts b/src/internal/internal.service.spec.ts new file mode 100644 index 0000000..c73e19d --- /dev/null +++ b/src/internal/internal.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { InternalService } from './internal.service'; + +describe('InternalService', () => { + let service: InternalService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [InternalService], + }).compile(); + + service = module.get(InternalService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/src/internal/internal.service.ts b/src/internal/internal.service.ts new file mode 100644 index 0000000..056d7ae --- /dev/null +++ b/src/internal/internal.service.ts @@ -0,0 +1,11 @@ +import { Injectable } from '@nestjs/common'; +import { PrismaService } from 'src/prisma.service'; + +@Injectable() +export class InternalService { + constructor(private readonly prismaService: PrismaService) {} + + async verifyEmail(email: string): Promise { + return `Email ${email} is verified`; + } +} diff --git a/src/main.ts b/src/main.ts index 52ea444..744ca13 100644 --- a/src/main.ts +++ b/src/main.ts @@ -33,13 +33,13 @@ async function bootstrap() { }); app.enableCors({ - origin: 'https://pqsoft.net', + origin: ['https://pqsoft.net', 'http://localhost:5173'], methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', optionsSuccessStatus: 204, allowedHeaders: '*', }); - await app.listen(80); - logger.log('Application is listening on port 80'); + await app.listen(process.env.PORT); + logger.log(`Application is listening on port ${process.env.PORT}`); } bootstrap(); From 9d2bfdfbe3488f48c830f6459ccd1664e4d08568 Mon Sep 17 00:00:00 2001 From: ohddang Date: Sat, 4 May 2024 20:43:44 +0900 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20=EC=9D=B4=EB=A9=94=EC=9D=BC=20?= =?UTF-8?q?=EC=B4=88=EB=8C=80=20db=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= =?UTF-8?q?=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/internal/internal.controller.ts | 3 ++- src/internal/internal.service.ts | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/internal/internal.controller.ts b/src/internal/internal.controller.ts index 3763667..0d76420 100644 --- a/src/internal/internal.controller.ts +++ b/src/internal/internal.controller.ts @@ -1,6 +1,7 @@ import { Body, Controller, HttpCode, Post } from '@nestjs/common'; import { InternalService } from './internal.service'; import { VerifyEmailDto } from 'src/dto/internal.dto'; +import { User } from '@prisma/client'; @Controller('internal/v1') export class InternalController { @@ -8,7 +9,7 @@ export class InternalController { @Post('verifyEmail') @HttpCode(200) - async verifyEmail(@Body() verifyEmailDto: VerifyEmailDto): Promise { + async verifyEmail(@Body() verifyEmailDto: VerifyEmailDto): Promise { return this.internalService.verifyEmail(verifyEmailDto.email); } } diff --git a/src/internal/internal.service.ts b/src/internal/internal.service.ts index 056d7ae..5023558 100644 --- a/src/internal/internal.service.ts +++ b/src/internal/internal.service.ts @@ -1,11 +1,14 @@ import { Injectable } from '@nestjs/common'; +import { User } from '@prisma/client'; import { PrismaService } from 'src/prisma.service'; @Injectable() export class InternalService { constructor(private readonly prismaService: PrismaService) {} - async verifyEmail(email: string): Promise { - return `Email ${email} is verified`; + async verifyEmail(email: string): Promise { + return this.prismaService.user.findUnique({ + where: { email: email }, + }); } } From ab7bb81fa0b024fd6fe4e11d28598a10c1199c28 Mon Sep 17 00:00:00 2001 From: ohddang Date: Mon, 6 May 2024 14:58:53 +0900 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20=EC=B4=88=EB=8C=80=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EB=A6=AC=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dto/internal.dto.ts | 8 +++++++- src/internal/internal.controller.ts | 7 ++++++- src/internal/internal.service.ts | 19 +++++++++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/dto/internal.dto.ts b/src/dto/internal.dto.ts index fc2fc8e..6324abd 100644 --- a/src/dto/internal.dto.ts +++ b/src/dto/internal.dto.ts @@ -1,4 +1,10 @@ -import { IsEmail, IsNotEmpty } from 'class-validator'; +import { IsArray, IsEmail, IsNotEmpty } from 'class-validator'; + +export class UserByIdsDto { + @IsNotEmpty() + @IsArray() + ids: number[]; +} export class VerifyEmailDto { @IsNotEmpty() diff --git a/src/internal/internal.controller.ts b/src/internal/internal.controller.ts index 0d76420..7a9f131 100644 --- a/src/internal/internal.controller.ts +++ b/src/internal/internal.controller.ts @@ -1,12 +1,17 @@ import { Body, Controller, HttpCode, Post } from '@nestjs/common'; import { InternalService } from './internal.service'; -import { VerifyEmailDto } from 'src/dto/internal.dto'; +import { UserByIdsDto, VerifyEmailDto } from 'src/dto/internal.dto'; import { User } from '@prisma/client'; @Controller('internal/v1') export class InternalController { constructor(private readonly internalService: InternalService) {} + @Post('userNames') + async getUserNames(@Body() userDto: UserByIdsDto): Promise { + return this.internalService.getUserByIds(userDto.ids); + } + @Post('verifyEmail') @HttpCode(200) async verifyEmail(@Body() verifyEmailDto: VerifyEmailDto): Promise { diff --git a/src/internal/internal.service.ts b/src/internal/internal.service.ts index 5023558..75576ba 100644 --- a/src/internal/internal.service.ts +++ b/src/internal/internal.service.ts @@ -1,10 +1,25 @@ -import { Injectable } from '@nestjs/common'; +import { Inject, Injectable } from '@nestjs/common'; import { User } from '@prisma/client'; +import { WINSTON_MODULE_PROVIDER } from 'nest-winston'; import { PrismaService } from 'src/prisma.service'; +import { Logger } from 'winston'; @Injectable() export class InternalService { - constructor(private readonly prismaService: PrismaService) {} + constructor( + private readonly prismaService: PrismaService, + @Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger, + ) {} + + async getUserByIds(ids: number[]): Promise { + return this.prismaService.user.findMany({ + where: { + id: { + in: ids, + }, + }, + }); + } async verifyEmail(email: string): Promise { return this.prismaService.user.findUnique({ From cfed7bfefe6cec5c46366d0d16bd2bcd3fb47025 Mon Sep 17 00:00:00 2001 From: ohddang Date: Mon, 6 May 2024 18:04:37 +0900 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20=EB=A9=94=EC=9D=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=B4=88=EB=8C=80=ED=95=98=EA=B8=B0=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/internal/internal.service.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/internal/internal.service.ts b/src/internal/internal.service.ts index 75576ba..5c8bbee 100644 --- a/src/internal/internal.service.ts +++ b/src/internal/internal.service.ts @@ -11,14 +11,15 @@ export class InternalService { @Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger, ) {} - async getUserByIds(ids: number[]): Promise { - return this.prismaService.user.findMany({ - where: { - id: { - in: ids, - }, - }, - }); + async getUserByIds(userIds: number[]): Promise { + const users = await Promise.all( + userIds.map((userId) => + this.prismaService.user.findUnique({ + where: { id: userId }, + }), + ), + ); + return users; } async verifyEmail(email: string): Promise { From 7d1f50e43105a4cd6380caa9cd2ee6704cf6d07a Mon Sep 17 00:00:00 2001 From: ohddang Date: Mon, 6 May 2024 18:51:05 +0900 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20test=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/internal/internal.controller.spec.ts | 10 ++++++++++ src/internal/internal.controller.ts | 2 +- src/internal/internal.service.spec.ts | 10 +++++++++- src/internal/internal.service.ts | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/internal/internal.controller.spec.ts b/src/internal/internal.controller.spec.ts index c409752..7406105 100644 --- a/src/internal/internal.controller.spec.ts +++ b/src/internal/internal.controller.spec.ts @@ -1,5 +1,9 @@ import { Test, TestingModule } from '@nestjs/testing'; import { InternalController } from './internal.controller'; +import { InternalService } from './internal.service'; +import { PrismaService } from '../prisma.service'; +import { WinstonModule } from 'nest-winston'; +import * as winston from 'winston'; describe('InternalController', () => { let controller: InternalController; @@ -7,6 +11,12 @@ describe('InternalController', () => { beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ controllers: [InternalController], + providers: [InternalService, PrismaService], + imports: [ + WinstonModule.forRoot({ + transports: [new winston.transports.Console()], + }), + ], }).compile(); controller = module.get(InternalController); diff --git a/src/internal/internal.controller.ts b/src/internal/internal.controller.ts index 7a9f131..8444ae7 100644 --- a/src/internal/internal.controller.ts +++ b/src/internal/internal.controller.ts @@ -1,6 +1,6 @@ import { Body, Controller, HttpCode, Post } from '@nestjs/common'; import { InternalService } from './internal.service'; -import { UserByIdsDto, VerifyEmailDto } from 'src/dto/internal.dto'; +import { UserByIdsDto, VerifyEmailDto } from '../dto/internal.dto'; import { User } from '@prisma/client'; @Controller('internal/v1') diff --git a/src/internal/internal.service.spec.ts b/src/internal/internal.service.spec.ts index c73e19d..16176d0 100644 --- a/src/internal/internal.service.spec.ts +++ b/src/internal/internal.service.spec.ts @@ -1,12 +1,20 @@ import { Test, TestingModule } from '@nestjs/testing'; import { InternalService } from './internal.service'; +import { PrismaService } from '../prisma.service'; +import { WinstonModule } from 'nest-winston'; +import * as winston from 'winston'; describe('InternalService', () => { let service: InternalService; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ - providers: [InternalService], + providers: [InternalService, PrismaService], + imports: [ + WinstonModule.forRoot({ + transports: [new winston.transports.Console()], + }), + ], }).compile(); service = module.get(InternalService); diff --git a/src/internal/internal.service.ts b/src/internal/internal.service.ts index 5c8bbee..54b14e7 100644 --- a/src/internal/internal.service.ts +++ b/src/internal/internal.service.ts @@ -1,7 +1,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { User } from '@prisma/client'; import { WINSTON_MODULE_PROVIDER } from 'nest-winston'; -import { PrismaService } from 'src/prisma.service'; +import { PrismaService } from '../prisma.service'; import { Logger } from 'winston'; @Injectable()