Skip to content

Commit bd2d666

Browse files
committed
fix test cases
1 parent 5c5665e commit bd2d666

File tree

4 files changed

+48
-55
lines changed

4 files changed

+48
-55
lines changed

frontend/src/app/my/mentorship/programs/[programKey]/edit/page.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ErrorDisplay, handleAppError } from 'app/global-error'
99
import { UPDATE_PROGRAM } from 'server/mutations/programsMutations'
1010
import { GET_PROGRAM_DETAILS, GET_PROGRAM_AND_MODULES } from 'server/queries/programsQueries'
1111
import type { ExtendedSession } from 'types/auth'
12+
import { Program } from 'types/mentorship'
1213
import { formatDateForInput } from 'utils/dateFormatter'
1314
import { parseCommaSeparated } from 'utils/parser'
1415
import slugify from 'utils/slugify'
@@ -113,19 +114,17 @@ const EditProgramPage = () => {
113114
variables: { programKey: input.key },
114115
data: { getProgram: updated },
115116
})
116-
try {
117-
const existing = cache.readQuery({
117+
const existing = cache.readQuery({
118+
query: GET_PROGRAM_AND_MODULES,
119+
variables: { programKey: input.key },
120+
}) as { getProgram: Program }
121+
if (existing?.getProgram) {
122+
cache.writeQuery({
118123
query: GET_PROGRAM_AND_MODULES,
119124
variables: { programKey: input.key },
120-
}) as any
121-
if (existing?.getProgram) {
122-
cache.writeQuery({
123-
query: GET_PROGRAM_AND_MODULES,
124-
variables: { programKey: input.key },
125-
data: { ...existing, getProgram: { ...existing.getProgram, ...updated } },
126-
})
127-
}
128-
} catch {}
125+
data: { ...existing, getProgram: { ...existing.getProgram, ...updated } },
126+
})
127+
}
129128
},
130129
})
131130

frontend/src/app/my/mentorship/programs/[programKey]/modules/[moduleKey]/edit/page.tsx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { UPDATE_MODULE } from 'server/mutations/moduleMutations'
1010
import { GET_PROGRAM_ADMINS_AND_MODULES } from 'server/queries/moduleQueries'
1111
import { GET_PROGRAM_AND_MODULES } from 'server/queries/programsQueries'
1212
import type { ExtendedSession } from 'types/auth'
13-
import { EXPERIENCE_LEVELS, type ModuleFormData } from 'types/mentorship'
13+
import { EXPERIENCE_LEVELS, Module, type ModuleFormData } from 'types/mentorship'
1414
import { formatDateForInput } from 'utils/dateFormatter'
1515
import { parseCommaSeparated } from 'utils/parser'
1616
import LoadingSpinner from 'components/LoadingSpinner'
@@ -114,22 +114,20 @@ const EditModulePage = () => {
114114
update: (cache, { data: mutationData }) => {
115115
const updated = mutationData?.updateModule
116116
if (!updated) return
117-
try {
118-
const existing = cache.readQuery({
117+
const existing = cache.readQuery({
118+
query: GET_PROGRAM_AND_MODULES,
119+
variables: { programKey },
120+
}) as { getProgramModules: Module[] }
121+
if (existing?.getProgramModules) {
122+
const nextModules = existing.getProgramModules.map((m: Module) =>
123+
m.key === updated.key ? { ...m, ...updated } : m
124+
)
125+
cache.writeQuery({
119126
query: GET_PROGRAM_AND_MODULES,
120127
variables: { programKey },
121-
}) as any
122-
if (existing?.getProgramModules) {
123-
const nextModules = existing.getProgramModules.map((m: any) =>
124-
m.key === updated.key ? { ...m, ...updated } : m
125-
)
126-
cache.writeQuery({
127-
query: GET_PROGRAM_AND_MODULES,
128-
variables: { programKey },
129-
data: { ...existing, getProgramModules: nextModules },
130-
})
131-
}
132-
} catch {}
128+
data: { ...existing, getProgramModules: nextModules },
129+
})
130+
}
133131
},
134132
})
135133

frontend/src/app/my/mentorship/programs/[programKey]/modules/create/page.tsx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ErrorDisplay } from 'app/global-error'
99
import { CREATE_MODULE } from 'server/mutations/moduleMutations'
1010
import { GET_PROGRAM_ADMIN_DETAILS, GET_PROGRAM_AND_MODULES } from 'server/queries/programsQueries'
1111
import type { ExtendedSession } from 'types/auth'
12-
import { EXPERIENCE_LEVELS } from 'types/mentorship'
12+
import { EXPERIENCE_LEVELS, Module } from 'types/mentorship'
1313
import { parseCommaSeparated } from 'utils/parser'
1414
import LoadingSpinner from 'components/LoadingSpinner'
1515
import ModuleForm from 'components/ModuleForm'
@@ -99,22 +99,20 @@ const CreateModulePage = () => {
9999
update: (cache, { data: mutationData }) => {
100100
const created = mutationData?.createModule
101101
if (!created) return
102-
try {
103-
const existing = cache.readQuery({
102+
const existing = cache.readQuery({
103+
query: GET_PROGRAM_AND_MODULES,
104+
variables: { programKey },
105+
}) as { getProgramModules: Module[] }
106+
if (existing?.getProgramModules) {
107+
cache.writeQuery({
104108
query: GET_PROGRAM_AND_MODULES,
105109
variables: { programKey },
106-
}) as any
107-
if (existing?.getProgramModules) {
108-
cache.writeQuery({
109-
query: GET_PROGRAM_AND_MODULES,
110-
variables: { programKey },
111-
data: {
112-
...existing,
113-
getProgramModules: [created, ...existing.getProgramModules],
114-
},
115-
})
116-
}
117-
} catch {}
110+
data: {
111+
...existing,
112+
getProgramModules: [created, ...existing.getProgramModules],
113+
},
114+
})
115+
}
118116
},
119117
})
120118

frontend/src/app/my/mentorship/programs/[programKey]/page.tsx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,20 @@ const ProgramDetailsPage = () => {
7171
update: (cache, { data: mutationData }) => {
7272
const updated = mutationData?.updateProgramStatus
7373
if (!updated) return
74-
try {
75-
const existing = cache.readQuery({
74+
const existing = cache.readQuery({
75+
query: GET_PROGRAM_AND_MODULES,
76+
variables: { programKey },
77+
}) as { getProgram: Program }
78+
if (existing?.getProgram) {
79+
cache.writeQuery({
7680
query: GET_PROGRAM_AND_MODULES,
7781
variables: { programKey },
78-
}) as any
79-
if (existing?.getProgram) {
80-
cache.writeQuery({
81-
query: GET_PROGRAM_AND_MODULES,
82-
variables: { programKey },
83-
data: {
84-
...existing,
85-
getProgram: { ...existing.getProgram, status: updated.status },
86-
},
87-
})
88-
}
89-
} catch {}
82+
data: {
83+
...existing,
84+
getProgram: { ...existing.getProgram, status: updated.status },
85+
},
86+
})
87+
}
9088
},
9189
})
9290

0 commit comments

Comments
 (0)