Skip to content

Commit daa3697

Browse files
committed
listLessonsをlistLessonsByClassに差し替え・authModeまわりを整理
1 parent 68e2217 commit daa3697

File tree

5 files changed

+55
-50
lines changed

5 files changed

+55
-50
lines changed

src/pages/classes/index.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ export default Vue.extend({
5858
},
5959
},
6060
watch: {
61-
currentDate() {
62-
this.classData.getLessonsByCurrentDate()
61+
async currentDate() {
62+
await this.classData.getLessonsByCurrentDate()
6363
},
6464
},
65-
mounted() {
66-
this.classData.getLessonsByCurrentDate()
65+
async mounted() {
66+
await this.classData.getLessonsByCurrentDate()
6767
},
6868
})
6969
</script>

src/pages/edit/index.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ export default Vue.extend({
198198
},
199199
},
200200
watch: {
201-
currentDate() {
202-
this.classData.getLessonsByCurrentDate()
201+
async currentDate() {
202+
await this.classData.getLessonsByCurrentDate()
203203
},
204204
},
205-
mounted() {
206-
this.classData.getLessonsByCurrentDate()
205+
async mounted() {
206+
await this.classData.getLessonsByCurrentDate()
207207
},
208208
methods: {
209209
onCollapseEditLessonScreen(): void {

src/pages/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export default Vue.extend({
145145
async loginToClass() {
146146
this.loading = true
147147
try {
148+
await vxm.user.setAuthModeIsAPIKEY(true)
148149
const result = (await API.graphql({
149150
query: getClass,
150151
variables: { id: this.classId },
@@ -155,7 +156,6 @@ export default Vue.extend({
155156
classId: this.classId,
156157
className,
157158
})
158-
await vxm.user.setAuthModeIsAPIKEY(true)
159159
await this.$router.push('/classes')
160160
} catch {
161161
this.loading = false

src/pages/lesson/index.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,11 @@ export default Vue.extend({
238238
},
239239
},
240240
async mounted() {
241-
const lessonList = await vxm.classData.lessonsOnCurrentDate(
242-
vxm.app.currentDate
243-
)
241+
const lessonList = vxm.user.isLoginWithAPIKEY
242+
? await vxm.classData.lessonsOnCurrentDateAuthModeAPIKEY(
243+
vxm.app.currentDate
244+
)
245+
: await vxm.classData.lessonsOnCurrentDate(vxm.app.currentDate)
244246
await this.$nextTick(function () {
245247
const data: LessonWithId | undefined = lessonList.find(
246248
(e) => this.$route.query.lessonId === e.id

src/store/modules/classData.ts

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { UserStore } from '@/store/modules/user'
99
import classData from '@/types/store/classData'
1010
import { API, Auth, graphqlOperation } from 'aws-amplify'
1111
import { GRAPHQL_AUTH_MODE, GraphQLResult } from '@aws-amplify/api'
12-
import { getClass, listLessons } from '@/graphql/queries'
12+
import { getClass, listLessonsByClass } from '@/graphql/queries'
1313
import { createClass, createLesson, updateLesson } from '@/graphql/mutations'
14-
import { GetClassQuery, ListLessonsQuery } from '@/API'
14+
import { GetClassQuery, ListLessonsByClassQuery } from '@/API'
1515
import { vxm } from '@/store'
1616

1717
type LessonsGroupedBy = {
@@ -37,6 +37,20 @@ const generateUniqueId = (): string => {
3737
c[Math.floor(Math.random() * cl)]
3838
return result + ''
3939
}
40+
// Generate a new Date object with a specified date & time
41+
const d = (date: Date, hours: number, minutes: number, seconds: number) => {
42+
const newDate = new Date(date)
43+
newDate.setHours(hours)
44+
newDate.setMinutes(minutes)
45+
newDate.setSeconds(seconds)
46+
return newDate
47+
}
48+
49+
const getFullDayArray = (date: Date) => {
50+
const start = d(date, 0, 0, 0)
51+
const end = d(date, 24, 0, 0)
52+
return [start, end]
53+
}
4054

4155
export class ClassDataStore extends VuexModule implements classData.ClassData {
4256
classId: classData.ClassId = ''
@@ -45,47 +59,33 @@ export class ClassDataStore extends VuexModule implements classData.ClassData {
4559

4660
@action
4761
public async lessonsOnCurrentDate(date: Date) {
48-
const userStore = createProxy(this.$store, UserStore)
49-
// Generate a new Date object with a specified date & time
50-
const d = (date: Date, hours: number, minutes: number, seconds: number) => {
51-
const newDate = new Date(date)
52-
newDate.setHours(hours)
53-
newDate.setMinutes(minutes)
54-
newDate.setSeconds(seconds)
55-
return newDate
56-
}
57-
const start = d(date, 0, 0, 0)
58-
const end = d(date, 23, 59, 59)
62+
const lessons = (await API.graphql({
63+
query: listLessonsByClass,
64+
variables: {
65+
classId: this.classId,
66+
startTime: {
67+
between: getFullDayArray(date),
68+
},
69+
},
70+
})) as GraphQLResult<ListLessonsByClassQuery>
71+
72+
return lessons.data?.listLessonsByClass?.items as any[]
73+
}
5974

75+
@action
76+
public async lessonsOnCurrentDateAuthModeAPIKEY(date: Date) {
6077
const lessons = (await API.graphql({
61-
query: listLessons,
78+
query: listLessonsByClass,
6279
variables: {
63-
filter: {
64-
and: [
65-
{
66-
classId: {
67-
eq: this.classId,
68-
},
69-
},
70-
{
71-
startTime: {
72-
ge: start,
73-
},
74-
},
75-
{
76-
startTime: {
77-
le: end,
78-
},
79-
},
80-
],
80+
classId: this.classId,
81+
startTime: {
82+
between: getFullDayArray(date),
8183
},
8284
},
83-
authMode: userStore.isLoginWithAPIKEY
84-
? GRAPHQL_AUTH_MODE.API_KEY
85-
: GRAPHQL_AUTH_MODE.AMAZON_COGNITO_USER_POOLS,
86-
})) as GraphQLResult<ListLessonsQuery>
85+
authMode: GRAPHQL_AUTH_MODE.API_KEY,
86+
})) as GraphQLResult<ListLessonsByClassQuery>
8787

88-
return lessons.data?.listLessons?.items as any[]
88+
return lessons.data?.listLessonsByClass?.items as any[]
8989
}
9090

9191
public get isLoaded(): boolean {
@@ -227,7 +227,10 @@ export class ClassDataStore extends VuexModule implements classData.ClassData {
227227
@action
228228
public async getLessonsByCurrentDate() {
229229
const appStore = createProxy(this.$store, AppStore)
230-
const lessons = await this.lessonsOnCurrentDate(appStore.currentDate)
230+
const userStore = createProxy(this.$store, UserStore)
231+
const lessons = userStore.isLoginWithAPIKEY
232+
? await this.lessonsOnCurrentDateAuthModeAPIKEY(appStore.currentDate)
233+
: await this.lessonsOnCurrentDate(appStore.currentDate)
231234
await this.setLessonsGroupByPeriod(lessons)
232235
}
233236

0 commit comments

Comments
 (0)