Skip to content

Commit 8e274b6

Browse files
some additional comments for clarity
1 parent 00c1435 commit 8e274b6

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

controllers/nestedDataController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const getNestedCourse_Helper = async (course_id, given_course_data = undefined)
5959
* @returns {Promise<PathData>} the full nested data for the requested path
6060
* @throws {ErrorWithHttpStatus} errors if things aren't found
6161
*/
62-
const getNestedPath_Helper = async (path_id, given_path_data) => {
62+
const getNestedPath_Helper = async (path_id, given_path_data = undefined) => {
6363
const path_data = given_path_data
6464
? { ...given_path_data }
6565
: await getElementById(Path, path_id);

db/seedContent.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,11 @@ async function seedContent(seed_data) {
109109
// time/order later, to ensure that all of the paths get seeded before all of the
110110
// courses, and all of the courses get seeded before all of the lessons while still
111111
// enabling the lessons to have access to the correct course ids and courses the path ids
112-
const course_funcs = [];
113112
const lesson_funcs = [];
113+
const course_funcs = [];
114114
const path_funcs = [];
115115
// set up each path seed to be triggered later
116+
// this forEach loop fills the path_funcs array with callbacks
116117
seed_data.forEach(path => {
117118
path_funcs.push(async () => {
118119
const { uuid: path_id } = await seedPath(path);
@@ -130,11 +131,15 @@ async function seedContent(seed_data) {
130131
});
131132
// TODO: error handling/graceful failure
132133
// map actually triggers the functions to start resolving
133-
await Promise.all(path_funcs.map(func => func()));
134+
// now the path_funcs array is full of callbacks, the course_funcs and lesson_funcs arrays are empty
135+
await Promise.all(path_funcs.map(pathFunc => pathFunc()));
134136
console.log('Finished seeding all paths');
135-
await Promise.all(course_funcs.map(func => func()));
137+
// now path_funcs are all executed, so course_funcs now full of callbacks, lesson_funcs still empty
138+
await Promise.all(course_funcs.map(courseFunc => courseFunc()));
136139
console.log('Finished seeding all courses');
137-
await Promise.all(lesson_funcs.map(func => func()));
140+
// now path)funcs and course_funcs all executed, lesson_funcs now full of callbacks
141+
await Promise.all(lesson_funcs.map(lessonFunc => lessonFunc()));
142+
// now all functions have been executed
138143
console.log('Finished seeding all lessons');
139144
console.log('Seeding completed.');
140145
}

0 commit comments

Comments
 (0)