Skip to content

Commit

Permalink
Merge pull request #299 from tnpfldyd/BE-fix/name-length
Browse files Browse the repository at this point in the history
네임 최대 길이 설정 및 스키마 변경
  • Loading branch information
Conut-1 authored Dec 13, 2023
2 parents 50ab58c + c276211 commit 8270104
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ CREATE TABLE `USER_TB` (

-- CreateTable
CREATE TABLE `REFRESH_TOKEN_TB` (
`token` VARCHAR(32) NOT NULL,
`uuid` VARCHAR(32) NOT NULL,
`expiry_date` DATETIME(3) NOT NULL,
`user_id` VARCHAR(191) NOT NULL,

PRIMARY KEY (`token`)
PRIMARY KEY (`uuid`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
Expand Down
6 changes: 3 additions & 3 deletions nestjs-BE/server/prisma/mysql.schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ model USER_TB {
}

model REFRESH_TOKEN_TB {
token String @id @db.VarChar(32)
uuid String @id @db.VarChar(32)
expiry_date DateTime
user_id String
user USER_TB @relation(fields: [user_id], references: [uuid], onDelete: Cascade)
Expand All @@ -28,14 +28,14 @@ model PROFILE_TB {
uuid String @id @db.VarChar(32)
user_id String @unique @db.VarChar(32)
image String
nickname String
nickname String @db.VarChar(20)
user USER_TB @relation(fields: [user_id], references: [uuid], onDelete: Cascade)
spaces PROFILE_SPACE_TB[]
}

model SPACE_TB {
uuid String @id @db.VarChar(32)
name String
name String @db.VarChar(20)
icon String
profiles PROFILE_SPACE_TB[]
invite_codes INVITE_CODE_TB[]
Expand Down
17 changes: 11 additions & 6 deletions nestjs-BE/server/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import { ResponseUtils } from 'src/utils/response';
const { BASE_IMAGE_URL } = customEnv;

export interface TokenData {
uuid?: string;
token: string;
uuid: string;
expiry_date: Date;
user_id: string;
}
Expand All @@ -36,12 +35,12 @@ export class AuthService extends BaseService<TokenData> {
temporaryDatabaseService,
cacheSize: REFRESH_TOKEN_CACHE_SIZE,
className: 'REFRESH_TOKEN_TB',
field: 'token',
field: 'uuid',
});
}

generateKey(data: TokenData): string {
return data.token;
return data.uuid;
}

async getKakaoAccount(kakaoUserId: number) {
Expand Down Expand Up @@ -83,7 +82,7 @@ export class AuthService extends BaseService<TokenData> {
const expiryDate = new Date(currentDate);
expiryDate.setDate(currentDate.getDate() + REFRESH_TOKEN_EXPIRY_DAYS);
const refreshTokenData: TokenData = {
token: refreshTokenUuid,
uuid: refreshTokenUuid,
expiry_date: expiryDate,
user_id: userUuid,
};
Expand Down Expand Up @@ -126,7 +125,7 @@ export class AuthService extends BaseService<TokenData> {
}

async findUser(usersService: UsersService, email: string, provider: string) {
const key = `email:${email}+provider:${provider}`;
const key = usersService.generateKey({ email, provider });
const findUserData = await usersService.getDataFromCacheOrDB(key);
return findUserData?.uuid;
}
Expand All @@ -146,4 +145,10 @@ export class AuthService extends BaseService<TokenData> {
profilesService.create(profileData);
return userUuid;
}

remove(refreshToken: string) {
const decodedToken = this.jwtService.decode(refreshToken);
const uuid = decodedToken?.uuid;
return super.remove(uuid);
}
}
3 changes: 3 additions & 0 deletions nestjs-BE/server/src/profiles/dto/create-profile.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';
import { MaxLength } from 'class-validator';
import { MAX_NAME_LENGTH } from 'src/config/magic-number';

export class CreateProfileDto {
user_id: string;
Expand All @@ -9,6 +11,7 @@ export class CreateProfileDto {
})
image: string;

@MaxLength(MAX_NAME_LENGTH)
@ApiProperty({
example: 'Sample nickname',
description: 'Nickname for the profile',
Expand Down
4 changes: 3 additions & 1 deletion nestjs-BE/server/src/spaces/dto/create-space.dto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString } from 'class-validator';
import { IsNotEmpty, IsString, MaxLength } from 'class-validator';
import { MAX_NAME_LENGTH } from 'src/config/magic-number';

export class CreateSpaceDto {
@IsString()
@IsNotEmpty()
@MaxLength(MAX_NAME_LENGTH)
@ApiProperty({ example: 'Sample Space', description: 'Name of the space' })
name: string;

Expand Down

0 comments on commit 8270104

Please sign in to comment.