Skip to content

Commit

Permalink
Merge pull request #350 from boostcampwm2023/BE-fix/models
Browse files Browse the repository at this point in the history
모델 변경에 맞춰서 수정
  • Loading branch information
Conut-1 authored Oct 1, 2024
2 parents 81b5cc4 + 878d2a4 commit f1e94b0
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion nestjs-BE/server/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class AuthController {
const userData = { email: kakaoUserAccount.email };
const user = await this.usersService.getOrCreateUser(userData);
const profileData = {
user_id: user.uuid,
userUuid: user.uuid,
image: this.configService.get<string>('BASE_IMAGE_URL'),
nickname: '익명의 사용자',
};
Expand Down
2 changes: 1 addition & 1 deletion nestjs-BE/server/src/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('AuthService', () => {
jest.spyOn(jwtService, 'verify').mockReturnValue({});
jest.spyOn(jwtService, 'signAsync').mockResolvedValue('access token');
jest.spyOn(refreshTokensService, 'findRefreshToken').mockResolvedValue({
user_id: 'user uuid',
userUuid: 'user uuid',
} as RefreshToken);

const token = service.renewAccessToken('refresh token');
Expand Down
12 changes: 6 additions & 6 deletions nestjs-BE/server/src/auth/refresh-tokens.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ describe('RefreshTokensService', () => {
const testToken = {
id: 0,
token: 'Token',
expiry_date: service.getExpiryDate(),
user_id: 'UserId',
expiryDate: service.getExpiryDate(),
userUuid: 'UserId',
};
jest.spyOn(prisma.refreshToken, 'findUnique').mockResolvedValue(testToken);

Expand All @@ -76,8 +76,8 @@ describe('RefreshTokensService', () => {
const testToken = {
id: 0,
token: 'Token',
expiry_date: service.getExpiryDate(),
user_id: 'userId',
expiryDate: service.getExpiryDate(),
userUuid: 'userId',
};
jest.spyOn(prisma.refreshToken, 'create').mockResolvedValue(testToken);

Expand Down Expand Up @@ -105,8 +105,8 @@ describe('RefreshTokensService', () => {
const testToken = {
id: 0,
token: 'Token',
expiry_date: service.getExpiryDate(),
user_id: 'userId',
expiryDate: service.getExpiryDate(),
userUuid: 'userId',
};
jest.spyOn(prisma.refreshToken, 'delete').mockResolvedValue(testToken);

Expand Down
4 changes: 2 additions & 2 deletions nestjs-BE/server/src/auth/refresh-tokens.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export class RefreshTokensService {
return this.prisma.refreshToken.create({
data: {
token: this.createToken(),
expiry_date: this.getExpiryDate(),
user_id: userUuid,
expiryDate: this.getExpiryDate(),
userUuid,
},
});
}
Expand Down
6 changes: 3 additions & 3 deletions nestjs-BE/server/src/invite-codes/invite-codes.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class InviteCodesController {
return {
statusCode: 201,
message: 'Created',
data: { invite_code: inviteCode.invite_code },
data: { invite_code: inviteCode.inviteCode },
};
}

Expand All @@ -66,11 +66,11 @@ export class InviteCodesController {
const inviteCodeData =
await this.inviteCodesService.findInviteCode(inviteCode);
if (!inviteCodeData) throw new NotFoundException();
if (this.inviteCodesService.checkExpiry(inviteCodeData.expiry_date)) {
if (this.inviteCodesService.checkExpiry(inviteCodeData.expiryDate)) {
this.inviteCodesService.deleteInviteCode(inviteCode);
throw new HttpException('Invite code has expired.', HttpStatus.GONE);
}
const space = await this.spacesService.findSpace(inviteCodeData.space_uuid);
const space = await this.spacesService.findSpace(inviteCodeData.spaceUuid);
return { statusCode: 200, message: 'Success', data: space };
}
}
16 changes: 8 additions & 8 deletions nestjs-BE/server/src/invite-codes/invite-codes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ import generateUuid from '../utils/uuid';
export class InviteCodesService {
constructor(protected prisma: PrismaService) {}

async findInviteCode(inviteCode: string): Promise<InviteCode> {
async findInviteCode(inviteCode: string): Promise<InviteCode | null> {
return this.prisma.inviteCode.findUnique({
where: { invite_code: inviteCode },
where: { inviteCode: inviteCode },
});
}

async createInviteCode(spaceUuid: string): Promise<InviteCode> {
return this.prisma.inviteCode.create({
data: {
uuid: generateUuid(),
invite_code: await this.generateUniqueInviteCode(INVITE_CODE_LENGTH),
space_uuid: spaceUuid,
expiry_date: this.calculateExpiryDate(),
inviteCode: await this.generateUniqueInviteCode(INVITE_CODE_LENGTH),
spaceUuid: spaceUuid,
expiryDate: this.calculateExpiryDate(),
},
});
}

async deleteInviteCode(inviteCode: string): Promise<InviteCode> {
async deleteInviteCode(inviteCode: string): Promise<InviteCode | null> {
try {
return await this.prisma.inviteCode.delete({
where: {
invite_code: inviteCode,
inviteCode: inviteCode,
},
});
} catch (err) {
Expand Down Expand Up @@ -70,7 +70,7 @@ export class InviteCodesService {

private async generateUniqueInviteCode(length: number): Promise<string> {
let inviteCode: string;
let inviteCodeData: InviteCode;
let inviteCodeData: InviteCode | null;

do {
inviteCode = this.generateShortInviteCode(length);
Expand Down
2 changes: 1 addition & 1 deletion nestjs-BE/server/src/profiles/dto/create-profile.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MaxLength } from 'class-validator';
import { MAX_NAME_LENGTH } from '../../config/magic-number';

export class CreateProfileDto {
user_id: string;
userUuid: string;

@ApiProperty({
example: 'profile-image.png',
Expand Down
4 changes: 2 additions & 2 deletions nestjs-BE/server/src/profiles/profiles.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('ProfilesController', () => {
const requestMock = { user: { uuid: 'user test uuid' } } as RequestWithUser;
const testProfile = {
uuid: 'profile test uuid',
user_id: requestMock.user.uuid,
userUuid: requestMock.user.uuid,
image: 'www.test.com/image',
nickname: 'test nickname',
};
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('ProfilesController', () => {
const testImageUrl = 'www.test.com/image';
const testProfile = {
uuid: 'profile test uuid',
user_id: requestMock.user.uuid,
userUuid: requestMock.user.uuid,
image: 'www.test.com/image',
nickname: 'test nickname',
};
Expand Down
8 changes: 4 additions & 4 deletions nestjs-BE/server/src/profiles/profiles.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('ProfilesService', () => {
const userId = generateUuid();
const testProfile = {
uuid: generateUuid(),
user_id: userId,
userUuid: userId,
image: 'www.test.com/image',
nickname: 'test nickname',
};
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('ProfilesService', () => {
const testProfiles = profileUuids.map((uuid, index) => {
return {
uuid,
user_id: generateUuid(),
userUuid: generateUuid(),
image: 'www.test.com/image',
nickname: `nickname${index}`,
};
Expand All @@ -85,7 +85,7 @@ describe('ProfilesService', () => {

it('getOrCreateProfile', async () => {
const data = {
user_id: generateUuid(),
userUuid: generateUuid(),
image: 'www.test.com/image',
nickname: 'test nickname',
};
Expand All @@ -103,7 +103,7 @@ describe('ProfilesService', () => {
nickname: 'test nickname',
};
const uuid = generateUuid();
const testProfile = { uuid: generateUuid(), user_id: uuid, ...data };
const testProfile = { uuid: generateUuid(), userUuid: uuid, ...data };
jest.spyOn(prisma.profile, 'update').mockResolvedValue(testProfile);

const profile = profilesService.updateProfile(uuid, data);
Expand Down
4 changes: 2 additions & 2 deletions nestjs-BE/server/src/profiles/profiles.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export class ProfilesService {

async getOrCreateProfile(data: CreateProfileDto): Promise<Profile> {
return this.prisma.profile.upsert({
where: { userUuid: data.user_id },
where: { userUuid: data.userUuid },
update: {},
create: {
uuid: generateUuid(),
userUuid: data.user_id,
userUuid: data.userUuid,
image: data.image,
nickname: data.nickname,
},
Expand Down

0 comments on commit f1e94b0

Please sign in to comment.