Skip to content

Commit

Permalink
Merge pull request #64 from Boost-Coder/feature/RegistTotal-#60
Browse files Browse the repository at this point in the history
[#60] 종합 점수 등록 및 업데이트
  • Loading branch information
namewhat99 authored Apr 15, 2024
2 parents 3028fc7 + 5a752eb commit 38a5f94
Show file tree
Hide file tree
Showing 28 changed files with 299 additions and 253 deletions.
40 changes: 0 additions & 40 deletions src/algorithm/algorithm.controller.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/algorithm/algorithm.module.ts

This file was deleted.

12 changes: 2 additions & 10 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ import { AppService } from './app.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { TypeOrmConfigService } from './Config/typeorm.config';
import { ConfigModule } from '@nestjs/config';
import { AlgorithmModule } from './algorithm/algorithm.module';
import { AuthModule } from './auth/auth.module';
import { UserModule } from './user/user.module';
import { GithubModule } from './github/github.module';
import { GradeController } from './grade/grade.controller';
import { GradeService } from './grade/grade.service';
import { GradeModule } from './grade/grade.module';
import { RankModule } from './rank/rank.module';
import { StatModule } from './stat/stat.module';
import * as process from 'process';

@Module({
Expand All @@ -23,12 +18,9 @@ import * as process from 'process';
isGlobal: true,
envFilePath: `${process.cwd()}/envs/${process.env.NODE_ENV}.env`,
}),
AlgorithmModule,
AuthModule,
UserModule,
GithubModule,
GradeModule,
RankModule,
StatModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
7 changes: 6 additions & 1 deletion src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import { JwtConfig } from '../Config/jwt.config';
import { JwtModule } from '@nestjs/jwt';
import { UserModule } from '../user/user.module';
import { JwtStrategy } from './strategy/jwt.strategy';
import { StatModule } from '../stat/stat.module';

@Module({
imports: [JwtModule.registerAsync({ useClass: JwtConfig }), UserModule],
imports: [
JwtModule.registerAsync({ useClass: JwtConfig }),
UserModule,
StatModule,
],
controllers: [AuthController],
providers: [AuthService, JwtStrategy],
})
Expand Down
15 changes: 14 additions & 1 deletion src/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { UserService } from '../user/user.service';
import { JwtService } from '@nestjs/jwt';
import { ConfigService } from '@nestjs/config';
import { User } from '../Entity/user';
import { TotalService } from '../stat/service/total.service';

const mockUserService = {
findUserByProviderId: jest.fn(),
Expand All @@ -18,6 +19,10 @@ const mockConfigService = {
get: jest.fn(),
};

const mockTotalService = {
createTotalPoint: jest.fn(),
};

describe('AuthService', () => {
let service: AuthService;

Expand All @@ -37,6 +42,10 @@ describe('AuthService', () => {
provide: ConfigService,
useValue: mockConfigService,
},
{
provide: TotalService,
useValue: mockTotalService,
},
],
}).compile();

Expand Down Expand Up @@ -76,6 +85,7 @@ describe('AuthService', () => {
const result = await service.logInOrSignUp(providerId);

expect(mockUserService.createUser).not.toHaveBeenCalled();
expect(mockTotalService.createTotalPoint).not.toHaveBeenCalled();
expect(result.isMember).toEqual(true);
});

Expand All @@ -86,6 +96,7 @@ describe('AuthService', () => {
const result = await service.logInOrSignUp(providerId);

expect(mockUserService.createUser).toHaveBeenCalled();
expect(mockTotalService.createTotalPoint).toHaveBeenCalled();
expect(result.isMember).toEqual(false);
});

Expand All @@ -102,8 +113,10 @@ describe('AuthService', () => {
mockUserService.createUser.mockResolvedValue(user);

const result = await service.logInOrSignUp(providerId);

mockUserService.createUser.mockClear();
mockTotalService.createTotalPoint.mockClear();
expect(mockUserService.createUser).not.toHaveBeenCalled();
expect(mockTotalService.createTotalPoint).not.toHaveBeenCalled();
expect(result.isMember).toEqual(false);
});
});
Expand Down
3 changes: 3 additions & 0 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@ import { ConfigService } from '@nestjs/config';
import { SejongAuthDto } from './sejongAuth.dto';
import { UpdateUserInfoDto } from '../user/dto/update-user-info.dto';
import { TokenExpiredError } from 'jsonwebtoken';
import { TotalService } from '../stat/service/total.service';

@Injectable()
export class AuthService {
constructor(
private userService: UserService,
private jwtService: JwtService,
private configService: ConfigService,
private totalService: TotalService,
) {}

async logInOrSignUp(providerId: string) {
let user = await this.userService.findUserByProviderId(providerId);
const isMember = this.isMember(user);
if (!user) {
user = await this.userService.createUser(providerId);
await this.totalService.createTotalPoint(user.userId);
}
const accessToken = this.generateAccessToken(user);
const refreshToken = this.generateRefreshToken(user);
Expand Down
45 changes: 0 additions & 45 deletions src/github/github.controller.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/github/github.module.ts

This file was deleted.

41 changes: 0 additions & 41 deletions src/grade/grade.controller.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/grade/grade.module.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/rank/rank.controller.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/rank/rank.module.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/rank/rank.service.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BaseRepository } from '../utils/base.repository';
import { BaseRepository } from '../../utils/base.repository';
import { Inject, Injectable, Scope } from '@nestjs/common';
import { DataSource, Repository } from 'typeorm';
import { REQUEST } from '@nestjs/core';
import { Algorithm } from '../Entity/algorithm';
import { Algorithm } from '../../Entity/algorithm';

@Injectable({ scope: Scope.REQUEST })
export class AlgorithmRepository extends BaseRepository {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseRepository } from '../utils/base.repository';
import { BaseRepository } from '../../utils/base.repository';
import { Inject, Injectable, Scope } from '@nestjs/common';
import { Github } from '../Entity/github';
import { Github } from '../../Entity/github';
import { DataSource, Repository } from 'typeorm';
import { REQUEST } from '@nestjs/core';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { BaseRepository } from '../utils/base.repository';
import { BaseRepository } from '../../utils/base.repository';
import { Inject, Injectable } from '@nestjs/common';
import { DataSource, Repository } from 'typeorm';
import { Github } from '../Entity/github';
import { Github } from '../../Entity/github';
import { REQUEST } from '@nestjs/core';
import { Grade } from '../Entity/grade';
import { Grade } from '../../Entity/grade';

@Injectable()
export class GradeRepository extends BaseRepository {
Expand Down
Loading

0 comments on commit 38a5f94

Please sign in to comment.