Section aggregate endpoints (/section/courses & /section/professors) use 2 Mongo pipelines, sectionCoursePipeline & sectionProfessorPipeline for aggregating data.
They are functional, but are hardcoded in each endpoint. Since the 2 pipelines share lots of stage, it would be more managable for us to write a single function that returns the appropriate pipeline based on the types of endpoints.
Moreover, improve the pipeline to aggregate /section/courses & /section/:id/course so that it should return an array of courses for the former and only a single course for the latter (instead of an array of one course).
Section aggregate endpoints (
/section/courses&/section/professors) use 2 Mongo pipelines,sectionCoursePipeline§ionProfessorPipelinefor aggregating data.They are functional, but are hardcoded in each endpoint. Since the 2 pipelines share lots of stage, it would be more managable for us to write a single function that returns the appropriate pipeline based on the types of endpoints.
Moreover, improve the pipeline to aggregate
/section/courses&/section/:id/courseso that it should return an array of courses for the former and only a single course for the latter (instead of an array of one course).