Skip to content
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

講義色変更機能の実装 #3

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions __tests__/usecase/getTags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { deepContaining } from '../_deepContaining'

const userId = v4()
const data = [
{ id: v4(), userId, name: 'test tag1', position: 0 },
{ id: v4(), userId, name: 'test tag2', position: 1 },
{ id: v4(), userId, name: 'test tag1', position: 0, colorHex: 'ffffff' },
{ id: v4(), userId, name: 'test tag2', position: 1, colorHex: '000000' },
]

beforeAll(async () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/usecase/updateTags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { deepContaining } from '../_deepContaining'

const userId = v4()
const data = [
{ id: v4(), userId, name: 'test tag1', position: 0 },
{ id: v4(), userId, name: 'test tag2', position: 1 },
{ id: v4(), userId, name: 'test tag1', position: 0, colorHex: 'ffffff' },
{ id: v4(), userId, name: 'test tag2', position: 1, colorHex: '000000' },
]

beforeAll(async () => {
Expand Down
3 changes: 2 additions & 1 deletion protos/Message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ message Tag {
string userId = 2;
string name = 3; // update時に限って空文字の場合は変更なしとみなされる
int32 position = 4; // update時に限って<0の場合は変更なしとみなされる
string colorHex = 5;
}

/* タグ情報 id未確定(作成時) */
Expand Down Expand Up @@ -105,4 +106,4 @@ message RegisteredCourseWithoutId {
NullableCourseMethodArray methods = 8;
NullableCourseScheduleArray schedules = 9;
repeated TagId tags = 10;
}
}
8 changes: 7 additions & 1 deletion src/database/model/tag.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
Column,
Entity,
Index,
JoinTable,
ManyToMany,
PrimaryColumn,
Expand Down Expand Up @@ -49,4 +48,11 @@ export class Tag {
},
})
courses!: RegisteredCourse[]

@Column({
name: 'color_hex',
type: 'text',
default: '#ed7f93',
})
colorHex!: string
}
4 changes: 3 additions & 1 deletion src/usecase/updateTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Input = {
userId: string
name: string
position: number
colorHex: string
}

export async function updateTagsUseCase(tags: Input[]) {
Expand All @@ -22,11 +23,12 @@ export async function updateTagsUseCase(tags: Input[]) {
)

return repository.save(
tags.map(({ name, position, ...tag }) => ({
tags.map(({ name, position, colorHex, ...tag }) => ({
...tag,
position:
position < 0 ? target.find((t) => t.id === tag.id)!.position : position, // < 0 の場合は変更なしとみなす
name: name || target.find((t) => t.id === tag.id)!.name, // 空文字の場合は変更なしとみなす
colorHex: colorHex || target.find((t) => t.id === tag.id)!.colorHex, // 空文字の場合は変更なしとみなす
}))
)
}