-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
授業追加時の重複チェックを実装 #665
授業追加時の重複チェックを実装 #665
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,7 +194,7 @@ | |
</p> | ||
<div class="modal__courses"> | ||
<div | ||
v-for="duplicateCourse in duplicateCourses" | ||
v-for="duplicateCourse in duplicatedScheduleCourses" | ||
:key="duplicateCourse.name" | ||
class="duplicated-course" | ||
> | ||
|
@@ -286,8 +286,9 @@ import TextFieldSingleLine from "~/ui/components/TextFieldSingleLine.vue"; | |
import ToggleButton from "~/ui/components/ToggleButton.vue"; | ||
import { useSwitch } from "~/ui/hooks/useSwitch"; | ||
import { addCoursesByCodes } from "~/ui/store/course"; | ||
import { displayToast } from "~/ui/store/toast"; | ||
import { getApplicableYear } from "~/ui/store/year"; | ||
import { deleteElementInArray } from "~/utils"; | ||
import { asyncFilter, deleteElementInArray } from "~/utils"; | ||
import type { Schedule } from "~/domain/schedule"; | ||
import type { DisplayCourse } from "~/presentation/viewmodels/course"; | ||
|
||
|
@@ -469,19 +470,44 @@ const buttonState = computed(() => | |
selectedSearchResults.length > 0 ? "default" : "disabled" | ||
); | ||
|
||
const duplicateCourses = ref<DisplayCourse[]>([]); | ||
const duplicatedScheduleCourses = ref<DisplayCourse[]>([]); | ||
|
||
const addCourses = async (warning = true) => { | ||
duplicateCourses.value = ( | ||
await Promise.all( | ||
selectedSearchResults.filter( | ||
({ schedules }) => | ||
!Usecase.checkScheduleDuplicate(ports)(year.value, schedules) | ||
) | ||
const registeredCourse = await Usecase.getRegisteredCoursesByYear(ports)( | ||
year.value | ||
); | ||
|
||
if (isResultError(registeredCourse)) throw registeredCourse; | ||
|
||
const duplicatedCourses = selectedSearchResults | ||
.filter(({ course: { code: selectedCourseCode } }) => { | ||
return registeredCourse.some( | ||
({ code: registeredCourseCode }) => | ||
registeredCourseCode === selectedCourseCode | ||
); | ||
}) | ||
.map(({ course }) => course); | ||
Comment on lines
+482
to
+489
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ここらへんを There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usecaseにした方がいいかなと思いました。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ありがとうございます!エラー数が増えてきたので一旦これで Merge しますが、後ほど UseCase に直します。 Ref: #666 |
||
|
||
if (duplicatedCourses.length > 0) { | ||
const text = | ||
`以下のコースはすでに登録されているため追加できません。\n` + | ||
duplicatedCourses | ||
.map(({ code, name }) => `【${code}】${name}`) | ||
.join("\n"); | ||
displayToast(text, { type: "danger" }); | ||
gtm?.trackEvent({ event: "duplicated-courses-error" }); | ||
return; | ||
} | ||
|
||
duplicatedScheduleCourses.value = await ( | ||
await asyncFilter( | ||
selectedSearchResults, | ||
async ({ schedules }) => | ||
!(await Usecase.checkScheduleDuplicate(ports)(year.value, schedules)) | ||
) | ||
).map(({ course }) => course); | ||
|
||
if (warning && duplicateCourses.value.length > 0) { | ||
if (warning && duplicatedScheduleCourses.value.length > 0) { | ||
openDuplicateModal(); | ||
return; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
以下の理由で常に
!Usecase.checkScheduleDuplicate
が false になっていました