Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

obojobo-sections-assessment

Package Overview
Dependencies
Maintainers
1
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

obojobo-sections-assessment - npm Package Compare versions

Comparing version 5.0.0-alpha.2 to 5.0.0-alpha.3

6

package.json
{
"name": "obojobo-sections-assessment",
"version": "5.0.0-alpha.2",
"version": "5.0.0-alpha.3",
"license": "AGPL-3.0-only",

@@ -34,3 +34,3 @@ "description": "Assessment section for Obojobo",

"dependencies": {
"obojobo-lib-utils": "^5.0.0-alpha.2"
"obojobo-lib-utils": "^5.0.0-alpha.3"
},

@@ -70,3 +70,3 @@ "devDependencies": {

},
"gitHead": "4a2eb66286c48f8cd5ae00376417413baecb1b9e"
"gitHead": "a56f03de0e094e642d577b7140ed5f1f003b12f5"
}

@@ -110,105 +110,99 @@ const router = require('express').Router() //eslint-disable-line new-cap

// @TODO: should take an assessmentID in the url
router
.route('/api/assessments/clear-preview-scores')
.post([requireCurrentUser, requireCurrentVisit, requireCurrentDocument])
.post((req, res) => {
let assessmentScoreIds
let attemptIds
const deletePreviewScores = ({ transaction, userId, draftId, resourceLinkId }) => {
return transaction
.manyOrNone(
`
SELECT assessment_scores.id
FROM assessment_scores
JOIN attempts
ON attempts.id = assessment_scores.attempt_id
WHERE assessment_scores.user_id = $[userId]
AND assessment_scores.draft_id = $[draftId]
AND attempts.resource_link_id = $[resourceLinkId]
AND assessment_scores.is_preview = true
`,
{ userId, draftId, resourceLinkId }
)
.then(assessmentScoreIdsResult => {
const ids = assessmentScoreIdsResult.map(i => i.id)
if (ids.length < 1) return []
return Promise.resolve()
.then(() => {
if (!req.currentVisit.is_preview) throw 'Not in preview mode'
return db.manyOrNone(
return [
transaction.none(
`
SELECT assessment_scores.id
FROM assessment_scores
JOIN attempts
ON attempts.id = assessment_scores.attempt_id
WHERE assessment_scores.user_id = $[userId]
AND assessment_scores.draft_id = $[draftId]
AND attempts.resource_link_id = $[resourceLinkId]
AND assessment_scores.is_preview = true
`,
{
userId: req.currentUser.id,
draftId: req.currentDocument.draftId,
resourceLinkId: req.currentVisit.resource_link_id
}
DELETE FROM lti_assessment_scores
WHERE assessment_score_id IN ($[ids:csv])
`,
{ ids }
),
transaction.none(
`
DELETE FROM assessment_scores
WHERE id IN ($[ids:csv])
`,
{ ids }
)
})
.then(assessmentScoreIdsResult => {
assessmentScoreIds = assessmentScoreIdsResult.map(i => i.id)
]
})
}
return db.manyOrNone(
const deletePreviewAttempts = ({ transaction, userId, draftId, resourceLinkId }) => {
return transaction
.manyOrNone(
`
SELECT id
FROM attempts
WHERE user_id = $[userId]
AND draft_id = $[draftId]
AND resource_link_id = $[resourceLinkId]
AND is_preview = true
`,
{ userId, draftId, resourceLinkId }
)
.then(attemptIdsResult => {
const ids = attemptIdsResult.map(i => i.id)
if (ids.length < 1) return []
return [
transaction.none(
`
SELECT id
FROM attempts
WHERE user_id = $[userId]
AND draft_id = $[draftId]
AND resource_link_id = $[resourceLinkId]
AND is_preview = true
`,
{
userId: req.currentUser.id,
draftId: req.currentDocument.draftId,
resourceLinkId: req.currentVisit.resource_link_id
}
DELETE FROM attempts_question_responses
WHERE attempt_id IN ($[ids:csv])
`,
{ ids }
),
transaction.none(
`
DELETE FROM attempts
WHERE id IN ($[ids:csv])
`,
{ ids }
)
})
.then(attemptIdsResult => {
attemptIds = attemptIdsResult.map(i => i.id)
]
})
}
return db.tx(transaction => {
const queries = []
if (assessmentScoreIds.length > 0) {
queries.push(
transaction.none(
`
DELETE FROM lti_assessment_scores
WHERE assessment_score_id IN ($[ids:csv])
`,
{ ids: assessmentScoreIds }
)
)
}
router
.route('/api/assessments/clear-preview-scores')
.post([requireCurrentUser, requireCurrentVisit, requireCurrentDocument])
.post((req, res) => {
if (!req.currentVisit.is_preview) return res.notAuthorized('Not in preview mode')
if (attemptIds.length > 0) {
queries.push(
transaction.none(
`
DELETE FROM attempts_question_responses
WHERE attempt_id IN ($[ids:csv])
`,
{ ids: attemptIds }
)
)
return db
.tx(transaction => {
const args = {
transaction,
userId: req.currentUser.id,
draftId: req.currentDocument.draftId,
resourceLinkId: req.currentVisit.resource_link_id
}
return Promise.all([deletePreviewScores(args), deletePreviewAttempts(args)]).then(
([scoreQueries, attemptQueries]) => {
return transaction.batch(scoreQueries.concat(attemptQueries))
}
queries.push(
transaction.none(
`
DELETE FROM assessment_scores
WHERE id IN ($[ids:csv])
`,
{ ids: assessmentScoreIds }
),
transaction.none(
`
DELETE FROM attempts
WHERE id IN ($[ids:csv])
`,
{ ids: attemptIds }
)
)
return transaction.batch(queries)
})
)
})
.then(() => res.success())
.catch(error => {
if (error === 'Not in preview mode') {
return res.notAuthorized(error)
}
logAndRespondToUnexpected('Unexpected error clearing preview scores', res, req, error)

@@ -215,0 +209,0 @@ })

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc