Skip to content

Commit 58fb6c2

Browse files
committed
fix: User 모델에 맞춰서 수정
1 parent 89032fd commit 58fb6c2

File tree

4 files changed

+48
-57
lines changed

4 files changed

+48
-57
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- RenameColumn
2+
ALTER TABLE `Profile` RENAME COLUMN `user_id` TO `userId`;
3+
4+
-- AlterTable
5+
ALTER TABLE `Profile`
6+
MODIFY `userId` VARCHAR(36) NOT NULL,
7+
MODIFY `uuid` VARCHAR(36) NOT NULL,
8+
RENAME INDEX `Profile_user_id_key` TO `Profile_userId_key`;
9+
10+
-- RenameForeignKey
11+
ALTER TABLE `Profile`
12+
DROP FOREIGN KEY `Profile_user_id_fkey`,
13+
ADD CONSTRAINT `Profile_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`uuid`) ON DELETE CASCADE ON UPDATE CASCADE;

nestjs-BE/server/prisma/schema.prisma

+6-6
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ model RefreshToken {
3131
}
3232

3333
model Profile {
34-
uuid String @id @db.VarChar(32)
35-
user_id String @unique @db.VarChar(32)
36-
image String
37-
nickname String @db.VarChar(20)
38-
user User @relation(fields: [user_id], references: [uuid], onDelete: Cascade)
39-
spaces Profile_space[]
34+
uuid String @id @db.VarChar(36)
35+
userId String @unique @db.VarChar(36)
36+
image String
37+
nickname String @db.VarChar(20)
38+
user User @relation(fields: [userId], references: [uuid], onDelete: Cascade)
39+
spaces Profile_space[]
4040
}
4141

4242
model Space {

nestjs-BE/server/src/profiles/profiles.service.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class ProfilesService {
1010
constructor(private prisma: PrismaService) {}
1111

1212
async findProfile(userUuid: string): Promise<Profile | null> {
13-
return this.prisma.profile.findUnique({ where: { user_id: userUuid } });
13+
return this.prisma.profile.findUnique({ where: { userId: userUuid } });
1414
}
1515

1616
async findProfiles(profileUuids: string[]): Promise<Profile[]> {
@@ -21,11 +21,11 @@ export class ProfilesService {
2121

2222
async getOrCreateProfile(data: CreateProfileDto): Promise<Profile> {
2323
return this.prisma.profile.upsert({
24-
where: { user_id: data.user_id },
24+
where: { userId: data.user_id },
2525
update: {},
2626
create: {
2727
uuid: generateUuid(),
28-
user_id: data.user_id,
28+
userId: data.user_id,
2929
image: data.image,
3030
nickname: data.nickname,
3131
},
@@ -38,7 +38,7 @@ export class ProfilesService {
3838
): Promise<Profile | null> {
3939
try {
4040
return await this.prisma.profile.update({
41-
where: { user_id: userUuid },
41+
where: { userId: userUuid },
4242
data: { ...updateProfileDto },
4343
});
4444
} catch (err) {

nestjs-BE/server/test/spaces.e2e-spec.ts

+25-47
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,44 @@ import * as request from 'supertest';
66
import { ConfigModule, ConfigService } from '@nestjs/config';
77
import { PrismaService } from '../src/prisma/prisma.service';
88
import { sign } from 'jsonwebtoken';
9-
import { Profile, Space } from '@prisma/client';
9+
import { Space } from '@prisma/client';
10+
import { PrismaModule } from '../src/prisma/prisma.module';
11+
import { v4 as uuid } from 'uuid';
1012

1113
describe('SpacesController (e2e)', () => {
1214
let app: INestApplication;
1315
let testToken: string;
1416
let testSpace: Space;
15-
let testProfile: Profile;
1617
let configService: ConfigService;
18+
let prisma: PrismaService;
1719

1820
beforeAll(async () => {
1921
const module: TestingModule = await Test.createTestingModule({
20-
imports: [ConfigModule],
22+
imports: [ConfigModule, PrismaModule],
2123
}).compile();
2224

2325
const configService: ConfigService =
2426
module.get<ConfigService>(ConfigService);
27+
prisma = module.get<PrismaService>(PrismaService);
28+
29+
await prisma.profile.deleteMany({});
30+
await prisma.user.deleteMany({});
31+
32+
const testUser = await prisma.user.create({ data: { uuid: uuid() } });
33+
await prisma.profile.create({
34+
data: {
35+
uuid: uuid(),
36+
userId: testUser.uuid,
37+
image: 'test image',
38+
nickname: 'test nickname',
39+
},
40+
});
41+
2542
testToken = sign(
26-
{ sub: 'test uuid' },
43+
{ sub: testUser.uuid },
2744
configService.get<string>('JWT_ACCESS_SECRET'),
2845
{ expiresIn: '5m' },
2946
);
30-
testSpace = {
31-
uuid: 'space-uuid',
32-
name: 'test space',
33-
icon: 'test space icon',
34-
};
35-
testProfile = {
36-
uuid: 'profile uuid',
37-
user_id: 'test uuid',
38-
image: configService.get<string>('BASE_IMAGE_URL'),
39-
nickname: 'test nickname',
40-
};
4147
});
4248

4349
beforeEach(async () => {
@@ -57,38 +63,10 @@ describe('SpacesController (e2e)', () => {
5763
moduleFixture.get<PrismaService>(PrismaService);
5864
configService = moduleFixture.get<ConfigService>(ConfigService);
5965

60-
const testUser = { email: '[email protected]', provider: 'kakao' };
61-
await prisma.user.upsert({
62-
where: {
63-
email_provider: { email: testUser.email, provider: testUser.provider },
64-
},
65-
update: {},
66-
create: {
67-
uuid: 'test uuid',
68-
email: testUser.email,
69-
provider: testUser.provider,
70-
},
71-
});
72-
await prisma.profile.upsert({
73-
where: { user_id: 'test uuid' },
74-
update: {},
75-
create: {
76-
uuid: testProfile.uuid,
77-
user_id: testProfile.user_id,
78-
image: testProfile.image,
79-
nickname: testProfile.nickname,
80-
},
81-
});
82-
await prisma.space.upsert({
83-
where: {
84-
uuid: testSpace.uuid,
85-
},
86-
update: {},
87-
create: {
88-
uuid: testSpace.uuid,
89-
name: testSpace.name,
90-
icon: testSpace.icon,
91-
},
66+
await prisma.space.deleteMany({});
67+
68+
testSpace = await prisma.space.create({
69+
data: { uuid: 'space-uuid', name: 'test space', icon: 'test icon' },
9270
});
9371
});
9472

0 commit comments

Comments
 (0)