Skip to content

Commit

Permalink
feat/#65/프리즈마 클라언트, 프리즈마 트랜잭션 클라이언트 타입 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
gwgw123 committed Jan 21, 2025
1 parent 4f6b9c6 commit b2fd953
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/auth/services/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Injectable, InternalServerErrorException } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { PrismaService } from 'src/prisma/prisma.service';
import { CreateUserDto } from 'src/users/dtos/create-user.dto';
import { TokenService } from './token.service';
import { UsersService } from 'src/users/services/users.service';
import { RedisService } from '../redis/redis.service';
import { PrismaClientOrTransaction } from 'src/prisma/prisma.type';

@Injectable()
export class AuthService {
Expand Down Expand Up @@ -52,7 +53,7 @@ export class AuthService {
provider: string,
providerId: string,
name: string,
txOrPrisma: any = this.prisma,
txOrPrisma: PrismaClientOrTransaction = this.prisma,
) {
// 기존 유저 정보 조회
const existingUser = await txOrPrisma.user.findUnique({
Expand All @@ -74,7 +75,7 @@ export class AuthService {
private saveSocialToken(
socialAccessToken: string,
userId: number,
txOrPrisma: any = this.prisma,
txOrPrisma: PrismaClientOrTransaction = this.prisma,
) {
return txOrPrisma.token.upsert({
where: { userId },
Expand Down
3 changes: 3 additions & 0 deletions src/prisma/prisma.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Prisma, PrismaClient } from '@prisma/client';

export type PrismaClientOrTransaction = Prisma.TransactionClient | PrismaClient;
4 changes: 3 additions & 1 deletion src/users/services/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
PartStatusValues,
} from 'src/part-progress/entities/part-progress.entity';
import { Part } from 'src/parts/entities/part.entity';
import { PrismaClientOrTransaction } from 'src/prisma/prisma.type';

@Injectable()
export class UsersService {
Expand Down Expand Up @@ -39,7 +40,7 @@ export class UsersService {
provider: string,
providerId: string,
name: string,
txOrPrisma: any = this.prisma,
txOrPrisma: PrismaClientOrTransaction = this.prisma,
): Promise<ResponseUserDto> {
// 유저 생성시 디폴트 파트 진행도를 생성
const defaulPartProgress = await this.createDefaultPartProgress(txOrPrisma);
Expand All @@ -55,6 +56,7 @@ export class UsersService {
},
});

// 유저 생성 실패 시 예외 처리
if (!userResponse) {
throw new NotFoundException();
}
Expand Down

0 comments on commit b2fd953

Please sign in to comment.