Skip to content

fix: 스토리에서 rankValue가 에픽이 아닌 프로젝트내에서 고유하도록 수정 #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/src/project/entity/story.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export enum StoryStatus {
}

@Entity()
@Unique('STORY_UQ_RANK_VALUE_AND_EPIC_ID', ['rankValue', 'epicId'])
@Unique('STORY_UQ_RANK_VALUE_AND_PROJECT_ID', ['rankValue', 'projectId'])
export class Story {
@PrimaryGeneratedColumn('increment', { type: 'int' })
id: number;
Expand Down
8 changes: 4 additions & 4 deletions backend/src/project/project.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,17 @@ export class ProjectRepository {
} catch (e) {
if (
e.code === 'ER_DUP_ENTRY' &&
e.sqlMessage.includes('STORY_UQ_RANK_VALUE_AND_EPIC_ID')
e.sqlMessage.includes('STORY_UQ_RANK_VALUE_AND_PROJECT_ID')
)
throw new Error('DUPLICATED RANK VALUE');
throw e;
}
}

getNextStoryByRankValue(epicId: number, rankValue: string) {
getNextStoryByRankValue(projectId: number, rankValue: string) {
return this.storyRepository.findOne({
where: {
epicId,
projectId,
rankValue: MoreThan(rankValue),
},
order: { rankValue: 'ASC' },
Expand Down Expand Up @@ -259,7 +259,7 @@ export class ProjectRepository {
} catch (e) {
if (
e.code === 'ER_DUP_ENTRY' &&
e.sqlMessage.includes('STORY_UQ_RANK_VALUE_AND_EPIC_ID')
e.sqlMessage.includes('STORY_UQ_RANK_VALUE_AND_PROJECT_ID')
)
throw new Error('DUPLICATED RANK VALUE');
throw e;
Expand Down
20 changes: 10 additions & 10 deletions backend/src/project/service/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class ProjectService {
return result ? true : false;
}

private async getAdjustedEpicRankValue(
private async getAdjustedRankValue(
currentRankValue: string,
nextRankValue: string | null,
): Promise<string> {
Expand Down Expand Up @@ -127,7 +127,7 @@ export class ProjectService {
newEpic.projectId,
newEpic.rankValue,
);
newEpic.rankValue = await this.getAdjustedEpicRankValue(
newEpic.rankValue = await this.getAdjustedRankValue(
newEpic.rankValue,
nextEpic?.rankValue,
);
Expand Down Expand Up @@ -173,7 +173,7 @@ export class ProjectService {
project.id,
updatedRankValue,
);
updatedRankValue = await this.getAdjustedEpicRankValue(
updatedRankValue = await this.getAdjustedRankValue(
updatedRankValue,
nextEpic?.rankValue,
);
Expand Down Expand Up @@ -205,10 +205,10 @@ export class ProjectService {
if (e.message === 'DUPLICATED RANK VALUE') {
const nextStory =
await this.projectRepository.getNextStoryByRankValue(
newStory.epicId,
newStory.projectId,
newStory.rankValue,
);
newStory.rankValue = await this.getAdjustedEpicRankValue(
newStory.rankValue = await this.getAdjustedRankValue(
newStory.rankValue,
nextStory?.rankValue,
);
Expand Down Expand Up @@ -239,7 +239,7 @@ export class ProjectService {
if (!epic) throw new Error('epic id not found');
}

const maxRetries = 100;
const maxRetries = 10;
let attempts = 0;

let updatedRankValue = rankValue;
Expand All @@ -266,7 +266,7 @@ export class ProjectService {
updatedRankValue,
);

updatedRankValue = await this.getAdjustedEpicRankValue(
updatedRankValue = await this.getAdjustedRankValue(
updatedRankValue,
nextStory?.rankValue,
);
Expand Down Expand Up @@ -314,7 +314,7 @@ export class ProjectService {
newTask.storyId,
newTask.rankValue,
);
newTask.rankValue = await this.getAdjustedEpicRankValue(
newTask.rankValue = await this.getAdjustedRankValue(
newTask.rankValue,
nextTask?.rankValue,
);
Expand Down Expand Up @@ -347,7 +347,7 @@ export class ProjectService {
if (!story) throw new Error('story id not found');
}

const maxRetries = 100;
const maxRetries = 10;
let attempts = 0;

let updatedRankValue = rankValue;
Expand Down Expand Up @@ -375,7 +375,7 @@ export class ProjectService {
updatedRankValue,
);

updatedRankValue = await this.getAdjustedEpicRankValue(
updatedRankValue = await this.getAdjustedRankValue(
updatedRankValue,
nextTask?.rankValue,
);
Expand Down
63 changes: 0 additions & 63 deletions backend/test/project/ws-backlog-page/ws-story.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,69 +294,6 @@ describe('WS story', () => {
socket.close();
});

it('should return updated story data when update rankValue within different epic', async () => {
const socket = await getMemberJoinedLandingPage();
socket.emit('joinBacklog');
await initBacklog(socket);

const name = '회원';
const color = 'yellow';
const middleRankValue = LexoRank.middle().toString();

const requestData1: any = {
action: 'create',
content: { name, color, rankValue: middleRankValue },
};
socket.emit('epic', requestData1);
const epicId1 = await getEpicId(socket);

const requestData2: any = {
action: 'create',
content: {
name,
color,
rankValue: LexoRank.parse(middleRankValue).genNext().toString(),
},
};
socket.emit('epic', requestData2);
const epicId2 = await getEpicId(socket);

const title = '타이틀';
const point = 2;
const status = '시작전';
const requestData3 = {
action: 'create',
content: {
title,
point,
status,
epicId: epicId1,
rankValue: middleRankValue,
},
};
socket.emit('story', requestData3);
const storyId = await getStoryId(socket);

//변경햘 에픽에서의 첫번째 스토리이기 때문에 middle 메서드를 사용한다.
const newRankValue = LexoRank.middle().toString();
const requestData4 = {
action: 'update',
content: { id: storyId, epicId: epicId2, rankValue: newRankValue },
};
socket.emit('story', requestData4);
await new Promise<void>((resolve) => {
socket.once('backlog', (data) => {
const { content, action, domain } = data;
expect(domain).toBe('story');
expect(action).toBe('update');
expect(content?.id).toBe(storyId);
expect(content?.rankValue).toBe(newRankValue);
resolve();
});
});
socket.close();
});

it('should return updated story data when updating multiple stories simultaneously', async () => {
const socket = await getMemberJoinedLandingPage();
socket.emit('joinBacklog');
Expand Down
Loading