-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from Codeit-part4-team3/pq-58
[Pq-58] 이메일 초대 기능 구현
- Loading branch information
Showing
8 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { IsArray, IsEmail, IsNotEmpty } from 'class-validator'; | ||
|
||
export class UserByIdsDto { | ||
@IsNotEmpty() | ||
@IsArray() | ||
ids: number[]; | ||
} | ||
|
||
export class VerifyEmailDto { | ||
@IsNotEmpty() | ||
@IsEmail() | ||
email: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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; | ||
|
||
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>(InternalController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Body, Controller, HttpCode, Post } from '@nestjs/common'; | ||
import { InternalService } from './internal.service'; | ||
import { UserByIdsDto, VerifyEmailDto } from '../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<User[]> { | ||
return this.internalService.getUserByIds(userDto.ids); | ||
} | ||
|
||
@Post('verifyEmail') | ||
@HttpCode(200) | ||
async verifyEmail(@Body() verifyEmailDto: VerifyEmailDto): Promise<User> { | ||
return this.internalService.verifyEmail(verifyEmailDto.email); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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, PrismaService], | ||
imports: [ | ||
WinstonModule.forRoot({ | ||
transports: [new winston.transports.Console()], | ||
}), | ||
], | ||
}).compile(); | ||
|
||
service = module.get<InternalService>(InternalService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { User } from '@prisma/client'; | ||
import { WINSTON_MODULE_PROVIDER } from 'nest-winston'; | ||
import { PrismaService } from '../prisma.service'; | ||
import { Logger } from 'winston'; | ||
|
||
@Injectable() | ||
export class InternalService { | ||
constructor( | ||
private readonly prismaService: PrismaService, | ||
@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger, | ||
) {} | ||
|
||
async getUserByIds(userIds: number[]): Promise<User[]> { | ||
const users = await Promise.all( | ||
userIds.map((userId) => | ||
this.prismaService.user.findUnique({ | ||
where: { id: userId }, | ||
}), | ||
), | ||
); | ||
return users; | ||
} | ||
|
||
async verifyEmail(email: string): Promise<User> { | ||
return this.prismaService.user.findUnique({ | ||
where: { email: email }, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters