@@ -9,9 +9,9 @@ import { UserStore } from '@/store/modules/user'
9
9
import classData from '@/types/store/classData'
10
10
import { API , Auth , graphqlOperation } from 'aws-amplify'
11
11
import { GRAPHQL_AUTH_MODE , GraphQLResult } from '@aws-amplify/api'
12
- import { getClass , listLessons } from '@/graphql/queries'
12
+ import { getClass , listLessonsByClass } from '@/graphql/queries'
13
13
import { createClass , createLesson , updateLesson } from '@/graphql/mutations'
14
- import { GetClassQuery , ListLessonsQuery } from '@/API'
14
+ import { GetClassQuery , ListLessonsByClassQuery } from '@/API'
15
15
import { vxm } from '@/store'
16
16
17
17
type LessonsGroupedBy = {
@@ -37,6 +37,20 @@ const generateUniqueId = (): string => {
37
37
c [ Math . floor ( Math . random ( ) * cl ) ]
38
38
return result + ''
39
39
}
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
+ }
40
54
41
55
export class ClassDataStore extends VuexModule implements classData . ClassData {
42
56
classId : classData . ClassId = ''
@@ -45,47 +59,33 @@ export class ClassDataStore extends VuexModule implements classData.ClassData {
45
59
46
60
@action
47
61
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
+ }
59
74
75
+ @action
76
+ public async lessonsOnCurrentDateAuthModeAPIKEY ( date : Date ) {
60
77
const lessons = ( await API . graphql ( {
61
- query : listLessons ,
78
+ query : listLessonsByClass ,
62
79
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 ) ,
81
83
} ,
82
84
} ,
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 >
87
87
88
- return lessons . data ?. listLessons ?. items as any [ ]
88
+ return lessons . data ?. listLessonsByClass ?. items as any [ ]
89
89
}
90
90
91
91
public get isLoaded ( ) : boolean {
@@ -227,7 +227,10 @@ export class ClassDataStore extends VuexModule implements classData.ClassData {
227
227
@action
228
228
public async getLessonsByCurrentDate ( ) {
229
229
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 )
231
234
await this . setLessonsGroupByPeriod ( lessons )
232
235
}
233
236
0 commit comments