MCPcopy Create free account
hub / github.com/codecombat/codecombat / fetchClassroomsForTeacher

Function fetchClassroomsForTeacher

app/core/store/modules/classrooms.js:265–310  ·  view source on GitHub ↗
({ commit, state }, { teacherId, project })

Source from the content-addressed store, hash-verified

263
264 actions: {
265 async fetchClassroomsForTeacher ({ commit, state }, { teacherId, project }) {
266 if (state.loaded.byTeacher[teacherId]) return;
267 if (state.loading.byTeacher[teacherId]) {
268 await new Promise(resolve => {
269 const unwatch = this.watch(
270 () => {
271 return state.loaded.byTeacher[teacherId]
272 },
273 () => {
274 if (state.loaded.byTeacher[teacherId]) {
275 unwatch();
276 resolve();
277 }
278 }
279 );
280 });
281 } else {
282 commit('toggleLoadingForTeacher', teacherId)
283
284 // We used to limit the default projection in Ozaria but not in CodeCombat, but it was easy to miss new properties, and Ozaria still fetched almost all the data, so now both products fetch all fields by default.
285 project = project || null
286
287 await classroomsApi.fetchByOwner(teacherId, {
288 project,
289 includeShared: true,
290 })
291 .then(async res => {
292 if (res) {
293 commit('addClassroomsForTeacher', {
294 teacherId,
295 classrooms: res
296 })
297 commit('setLoadedForTeacher', { teacherId, loaded: true });
298 } else {
299 throw new Error('Unexpected response from fetch classrooms API.')
300 }
301 })
302 .catch((e) => {
303 console.error('Failed to fetch classrooms for teacher', e)
304 noty({ text: 'Fetch classrooms failure' + e, type: 'error', layout: 'topCenter', timeout: 2000 })
305 })
306 .finally(() => {
307 commit('toggleLoadingForTeacher', teacherId)
308 })
309 }
310 },
311 fetchClassroomForId: async ({ commit, getters }, classroomID) => {
312 if (getters.getClassroomById(classroomID)) {
313 return

Callers

nothing calls this directly

Calls 3

watchMethod · 0.80
fetchByOwnerMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected