REST API - Gradebook Column Course reference

Idea created by mb23565 on Jul 12, 2017
    Under review
    Score0

    Hello, I would like to suggest that when making calls sub routes to routes such as: Grades, that the courseId reference be included. What is happening currently is that the API allows you to make a call to a course and requests for the gradebook/columns, but when you receive the data it does not contain the courseId reference.

     

        {
          "_id": "59666fe35a01ea0765f78a57",
          "updatedAt": "2017-07-12T18:52:19.891Z",
          "createdAt": "2017-07-12T18:52:19.891Z",
          "id": "_578658_1",
          "name": "Injection Test",
          "__v": 0,
          "score": {
            "possible": 0
          },
          "availability": {
            "available": "No"
          }
        },
    
    

     

     

    What I have manged to do is use a series of promises that are resolve in succession to do some calls:

     

    Load the course,

    Load the Columns where the courseId is the current courseId

     

    I added in my model the courseId and I am injecting this upon my retrieval from the BbRestAPI data.

     

     

    How the flow works: (NodeJS + Typescript + Bluebird for promises)

    I have a GradebookController that exports a Express Route View called columns.

      // ...code...
      columns: (req: any, res: any) => {
        let Column = res.app.locals.bb.models.columns
        let BbCourse = res.app.locals.bb.models.courses
        let params = extractParam(req.params.courseId)
        console.log(params)
        promise.all([
          req.query.myRefresh == 'true',
          BbCourse.load2({ criteria: params })
        ])
          .then(([refresh, course]: any) => {
            if (typeof refresh == 'boolean' && course != undefined) {
              return [refresh, course]
            } else {
              console.log('Should be getting data from Bb.')
              return [refresh, bbRestApi.getDataFromBb2(req, BbCourse).then((_doc: any) => _doc)]
            }
          }).then(([refresh, course]: any) => {
            console.log('Course Info Retrieved:', course.externalId)
            return promise.all([
              refresh,
              course,
              Column.list({ criteria: { courseId: course.id } })
            ])
          })
          .then(([refresh, course, columns]: any) => {
            console.log('Trying to retrieve columns for course:', course.externalId)
            console.log('Columns:', columns)
            console.log(columns.length)
            if (columns.length > 0) {
              return [refresh, course, columns]
            } else {
              console.log('NO COLUMNS!!')
              return promise.all([refresh, course, bbRestApi.getDataFromBb2(req, Column, null, { courseId: course.id })])
            }
          })
          .then(([refresh, course, columns]: any) => {
            console.log(refresh)
            console.log(course)
            console.log(columns)
            sendJson(res, null, { refresh, course, columns })
          })
          .catch((err: any) => sendJson(res, err, {}))
      }, 
      // ...code...
    
    

     

    Result: (Note: courseId has been added to the result)

     

        {
          "_id": "59666fe35a01ea0765f78a57",
          "updatedAt": "2017-07-12T18:52:19.891Z",
          "createdAt": "2017-07-12T18:52:19.891Z",
          "id": "_578658_1",
          "name": "Injection Test",
          "courseId": "_2841_1",
          "__v": 0,
          "score": {
            "possible": 0
          },
          "availability": {
            "available": "No"
          }
        },
    
    

     

     

    I think that this would be a great addition to the these calls; adding the main references (i.e. courseId). As of right now, the current methodology is forcing the end developer to do more heavy lifting than they should. By adding the main route ids to the end route data will simply a lot of things.

     

    This could also be solved by the implementation of population:

    "Populate" BB REST API option to return pre-populated data as full rendered documents

    Product Version (if applicable):0