Skip to content

Commit

Permalink
Merge pull request #67 from Codeit-part4-team3/pq-58
Browse files Browse the repository at this point in the history
[Pq-58] 이메일 초대 기능 구현
  • Loading branch information
SiWooJinSeok authored May 7, 2024
2 parents c54c360 + 7d1f50e commit 2224aa3
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ 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: [
LoggerModule,
AuthModule,
ConfigModule.forRoot({ isGlobal: true }),
FriendModule,
InternalModule,
],
controllers: [UserController, AppController],
providers: [PrismaService, UserService, AppService, AuthService],
Expand Down
13 changes: 13 additions & 0 deletions src/dto/internal.dto.ts
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;
}
28 changes: 28 additions & 0 deletions src/internal/internal.controller.spec.ts
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();
});
});
20 changes: 20 additions & 0 deletions src/internal/internal.controller.ts
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);
}
}
10 changes: 10 additions & 0 deletions src/internal/internal.module.ts
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 {}
26 changes: 26 additions & 0 deletions src/internal/internal.service.spec.ts
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();
});
});
30 changes: 30 additions & 0 deletions src/internal/internal.service.ts
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 },
});
}
}
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function bootstrap() {
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();

0 comments on commit 2224aa3

Please sign in to comment.