Skip to content

Commit f508a2e

Browse files
committed
null許容の削除、一部の型の修正・削除、エラーの返し方の変更
1 parent bbaaef0 commit f508a2e

File tree

3 files changed

+44
-42
lines changed

3 files changed

+44
-42
lines changed

src/pages/user/registered.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { vxm } from '@/store'
3030
export default Vue.extend({
3131
components: { BottomSheetLayer, ActionButton },
3232
layout: 'background',
33-
middleware: ['authenticated', 'checkClassData'],
33+
middleware: 'authenticated',
3434
data() {
3535
return {
3636
classId: vxm.classData.classId

src/store/modules/classData.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ const VuexModule = createModule({
1515
target: 'nuxt'
1616
})
1717

18+
const generateUniqueId = (): string => {
19+
const c =
20+
'あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん'
21+
const cl = c.length
22+
const result =
23+
c[Math.floor(Math.random() * cl)] +
24+
c[Math.floor(Math.random() * cl)] +
25+
c[Math.floor(Math.random() * cl)] +
26+
c[Math.floor(Math.random() * cl)] +
27+
c[Math.floor(Math.random() * cl)] +
28+
c[Math.floor(Math.random() * cl)]
29+
return result + ''
30+
}
31+
1832
export class ClassDataStore extends VuexModule implements classData.ClassData {
1933
classId: classData.ClassId = ''
2034
className: string = ''
@@ -101,9 +115,9 @@ export class ClassDataStore extends VuexModule implements classData.ClassData {
101115
className: string
102116
schoolName: string
103117
}) {
104-
let classId = this.generateUniqueId()
105-
if (!vxm.user.uid) {
106-
return Promise.reject(new Error('ユーザーが正しくログインされていません'))
118+
let classId = generateUniqueId()
119+
if (!vxm.user.isAuthenticated) {
120+
throw new Error('ユーザーが正しくログインされていません')
107121
}
108122
try {
109123
const doc = await firebase
@@ -112,10 +126,10 @@ export class ClassDataStore extends VuexModule implements classData.ClassData {
112126
.doc(classId)
113127
.get()
114128
if (doc.exists) {
115-
classId = this.generateUniqueId()
129+
classId = generateUniqueId()
116130
}
117131
} catch {
118-
return Promise.reject(new Error('エラーによって処理に失敗しました'))
132+
throw new Error('エラーによって処理に失敗しました')
119133
}
120134
try {
121135
await firebase
@@ -143,6 +157,11 @@ export class ClassDataStore extends VuexModule implements classData.ClassData {
143157
} catch {
144158
return Promise.reject(new Error('エラーによって処理に失敗しました'))
145159
}
160+
this.setClassData({
161+
classId,
162+
className,
163+
lessons: []
164+
})
146165
}
147166

148167
@action
@@ -180,20 +199,6 @@ export class ClassDataStore extends VuexModule implements classData.ClassData {
180199
this.loadClassData(this.classId)
181200
}
182201

183-
private generateUniqueId(): string {
184-
const c =
185-
'あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん'
186-
const cl = c.length
187-
const result =
188-
c[Math.floor(Math.random() * cl)] +
189-
c[Math.floor(Math.random() * cl)] +
190-
c[Math.floor(Math.random() * cl)] +
191-
c[Math.floor(Math.random() * cl)] +
192-
c[Math.floor(Math.random() * cl)] +
193-
c[Math.floor(Math.random() * cl)]
194-
return result + ''
195-
}
196-
197202
@mutation
198203
private setClassData({ classId, className, lessons }: classData.ClassData) {
199204
this.classId = classId

src/store/modules/user.ts

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,17 @@ const VuexModule = createModule({
66
strict: false,
77
target: 'nuxt'
88
})
9-
type Email = string | null
9+
type Email = string
1010
type EmailVerified = boolean
11-
type DisplayName = string | null
11+
type DisplayName = string
1212
type AllowAccess = AllowAccessData[]
1313
type AllowAccessData = {
1414
classId: string
1515
schoolName: string
1616
className: string
1717
}
18-
type AllowAccessFromUsers = {
19-
classId: string
20-
schoolName: string
21-
}
22-
type Uid = string | null
18+
19+
type Uid = string
2320

2421
interface User {
2522
email: Email
@@ -35,11 +32,11 @@ interface userData {
3532
}
3633

3734
export class UserStore extends VuexModule implements User {
38-
email: Email = null
35+
email: Email = ''
3936
emailVerified: EmailVerified = false
40-
displayName: DisplayName = null
37+
displayName: DisplayName = ''
4138
allowAccess: AllowAccess = []
42-
uid: Uid = null
39+
uid: Uid = ''
4340

4441
public get isAuthenticated(): boolean {
4542
return !!this.email && !!this.uid
@@ -71,28 +68,28 @@ export class UserStore extends VuexModule implements User {
7168
.doc(user.uid)
7269
.get()
7370

74-
const allowAccessData: AllowAccessFromUsers[] = data.get('allow_access')
71+
const allowAccessData: string[] = data.get('allow_access')
7572
const allowAccess = []
7673
for (const value of allowAccessData) {
7774
const classData = await firebase
7875
.firestore()
7976
.collection('classData')
80-
.doc(value.classId)
77+
.doc(value)
8178
.get()
8279
const editorClassData = await firebase
8380
.firestore()
8481
.collection('editorClassData')
85-
.doc(value.classId)
82+
.doc(value)
8683
.get()
8784
allowAccess.push({
88-
classId: value.classId,
85+
classId: value,
8986
schoolName: editorClassData.get('schoolName'),
9087
className: classData.get('className')
9188
})
9289
}
9390

9491
this.setUser({
95-
email: user.email,
92+
email: user.email ? user.email : '',
9693
emailVerified: user.emailVerified,
9794
displayName: data.get('username'),
9895
allowAccess,
@@ -108,21 +105,21 @@ export class UserStore extends VuexModule implements User {
108105
.doc(user.user_id)
109106
.get()
110107

111-
const allowAccessData: AllowAccessFromUsers[] = data.get('allow_access')
108+
const allowAccessData: string[] = data.get('allow_access')
112109
const allowAccess = []
113110
for (const value of allowAccessData) {
114111
const classData = await firebase
115112
.firestore()
116113
.collection('classData')
117-
.doc(value.classId)
114+
.doc(value)
118115
.get()
119116
const editorClassData = await firebase
120117
.firestore()
121118
.collection('editorClassData')
122-
.doc(value.classId)
119+
.doc(value)
123120
.get()
124121
allowAccess.push({
125-
classId: value.classId,
122+
classId: value,
126123
schoolName: editorClassData.get('schoolName'),
127124
className: classData.get('className')
128125
})
@@ -141,10 +138,10 @@ export class UserStore extends VuexModule implements User {
141138
public async logout() {
142139
await firebase.auth().signOut()
143140
this.setUser({
144-
uid: null,
145-
email: null,
141+
uid: '',
142+
email: '',
146143
emailVerified: false,
147-
displayName: null,
144+
displayName: '',
148145
allowAccess: []
149146
})
150147
}

0 commit comments

Comments
 (0)