-
-
Save Cvmcosta/2a503dd3df6905cd635d26d188f99c13 to your computer and use it in GitHub Desktop.
| const lti = require('ltijs').Provider | |
| /** | |
| * sendGrade | |
| */ | |
| lti.app.post('/grade', async (req, res) => { | |
| try { | |
| const idtoken = res.locals.token // IdToken | |
| const score = req.body.grade // User numeric score sent in the body | |
| // Creating Grade object | |
| const gradeObj = { | |
| userId: idtoken.user, | |
| scoreGiven: score, | |
| scoreMaximum: 100, | |
| activityProgress: 'Completed', | |
| gradingProgress: 'FullyGraded' | |
| } | |
| // Selecting linetItem ID | |
| let lineItemId = idtoken.platformContext.endpoint.lineitem // Attempting to retrieve it from idtoken | |
| if (!lineItemId) { | |
| const response = await lti.Grade.getLineItems(idtoken, { resourceLinkId: true }) | |
| const lineItems = response.lineItems | |
| if (lineItems.length === 0) { | |
| // Creating line item if there is none | |
| console.log('Creating new line item') | |
| const newLineItem = { | |
| scoreMaximum: 100, | |
| label: 'Grade', | |
| tag: 'grade', | |
| resourceLinkId: idtoken.platformContext.resource.id | |
| } | |
| const lineItem = await lti.Grade.createLineItem(idtoken, newLineItem) | |
| lineItemId = lineItem.id | |
| } else lineItemId = lineItems[0].id | |
| } | |
| // Sending Grade | |
| const responseGrade = await lti.Grade.submitScore(idtoken, lineItemId, gradeObj) | |
| return res.send(responseGrade) | |
| } catch (err) { | |
| return res.status(500).send({ err: err.message }) | |
| } | |
| }) |
provider:gradeService Access_token retrieved for [http://localhost/moodle42] +58ms
provider:gradeService Sending score to: http://localhost/moodle42/mod/lti/services.php/2/lineitems/44/lineitem/scores?type_id=12 +0ms
provider:gradeService {
provider:gradeService userId: '2',
provider:gradeService scoreGiven: 20,
provider:gradeService scoreMaximum: 100,
provider:gradeService activityProgress: 'Completed',
provider:gradeService gradingProgress: 'FullyGraded',
provider:gradeService timestamp: '2025-06-27T09:45:14.540Z'
provider:gradeService } +0ms
error = Response code 400 (Incorrect score received"{"userId":"2","scoreGiven":20,"scoreMaximum":100,"activityProgress":"Completed","gradingProgress":"FullyGraded","timestamp":"2025-06-27T09:45:14.540Z"}")
Grade submission is throwing this error. Please help
The new process consists of: