Skip to content

Commit

Permalink
Make course insertion into database sequential
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotcorreia committed Sep 19, 2022
1 parent 81c5994 commit 2d383fc
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions src/modules/courses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,37 +498,35 @@ export async function importCoursesFromDegree(
});
}

await Promise.all(
degreeCourses.map(async (course) => {
const globalCourse = await prisma.course.findUnique({
where: { acronym: course.acronym },
});

if (!globalCourse) {
// Create global course since it doesn't exist
for (const course of degreeCourses) {
const globalCourse = await prisma.course.findUnique({
where: { acronym: course.acronym },
});

await prisma.course.create({
data: {
acronym: course.acronym,
displayAcronym: course.acronym,
name: course.name,
},
});
}
if (!globalCourse) {
// Create global course since it doesn't exist

await prisma.degreeCourse.create({
await prisma.course.create({
data: {
id: `${degreeId}-${course.acronym}`,
degreeFenixId: degreeId,
courseAcronym: course.acronym,
year: course.year,
semester: course.semester,
announcementsFeedUrl: course.announcementsFeedUrl,
color: utils.generateHexCode(),
acronym: course.acronym,
displayAcronym: course.acronym,
name: course.name,
},
});
})
);
}

await prisma.degreeCourse.create({
data: {
id: `${degreeId}-${course.acronym}`,
degreeFenixId: degreeId,
courseAcronym: course.acronym,
year: course.year,
semester: course.semester,
announcementsFeedUrl: course.announcementsFeedUrl,
color: utils.generateHexCode(),
},
});
}
}

export async function refreshCourses(
Expand Down

0 comments on commit 2d383fc

Please sign in to comment.