diff --git a/contentcuration/contentcuration/frontend/channelEdit/vuex/assessmentItem/actions.js b/contentcuration/contentcuration/frontend/channelEdit/vuex/assessmentItem/actions.js index d421396433..8452cc0641 100644 --- a/contentcuration/contentcuration/frontend/channelEdit/vuex/assessmentItem/actions.js +++ b/contentcuration/contentcuration/frontend/channelEdit/vuex/assessmentItem/actions.js @@ -41,16 +41,20 @@ export function addAssessmentItem(context, assessmentItem) { hints: JSON.stringify(assessmentItem.hints || []), }; - return db.transaction('rw', [TABLE_NAMES.CONTENTNODE, TABLE_NAMES.ASSESSMENTITEM], () => { - return AssessmentItem.add(stringifiedAssessmentItem).then(([contentnode, assessment_id]) => { - context.commit('UPDATE_ASSESSMENTITEM', { - ...assessmentItem, - contentnode, - assessment_id, + return db.transaction( + 'rw', + [TABLE_NAMES.CONTENTNODE, TABLE_NAMES.ASSESSMENTITEM, TABLE_NAMES.CHANGES_TABLE], + () => { + return AssessmentItem.add(stringifiedAssessmentItem).then(([contentnode, assessment_id]) => { + context.commit('UPDATE_ASSESSMENTITEM', { + ...assessmentItem, + contentnode, + assessment_id, + }); + return updateNodeComplete(contentnode, context); }); - return updateNodeComplete(contentnode, context); - }); - }); + } + ); } export function updateAssessmentItem(context, assessmentItem) { return updateAssessmentItems(context, [assessmentItem]); @@ -65,38 +69,46 @@ export function updateAssessmentItems(context, assessmentItems) { context.commit('UPDATE_ASSESSMENTITEM', assessmentItem); }); - return db.transaction('rw', [TABLE_NAMES.CONTENTNODE, TABLE_NAMES.ASSESSMENTITEM], () => { - return Promise.all( - assessmentItems.map(assessmentItem => { - // API accepts answers and hints as strings - const stringifiedAssessmentItem = { - ...assessmentItem, - }; - if (assessmentItem.answers) { - stringifiedAssessmentItem.answers = JSON.stringify(assessmentItem.answers); - } - if (assessmentItem.hints) { - stringifiedAssessmentItem.hints = JSON.stringify(assessmentItem.hints); - } - return AssessmentItem.update( - [assessmentItem.contentnode, assessmentItem.assessment_id], - stringifiedAssessmentItem - ).then(() => { - updateNodeComplete(assessmentItem.contentnode, context); - }); - }) - ); - }); + return db.transaction( + 'rw', + [TABLE_NAMES.CONTENTNODE, TABLE_NAMES.ASSESSMENTITEM, TABLE_NAMES.CHANGES_TABLE], + () => { + return Promise.all( + assessmentItems.map(assessmentItem => { + // API accepts answers and hints as strings + const stringifiedAssessmentItem = { + ...assessmentItem, + }; + if (assessmentItem.answers) { + stringifiedAssessmentItem.answers = JSON.stringify(assessmentItem.answers); + } + if (assessmentItem.hints) { + stringifiedAssessmentItem.hints = JSON.stringify(assessmentItem.hints); + } + return AssessmentItem.update( + [assessmentItem.contentnode, assessmentItem.assessment_id], + stringifiedAssessmentItem + ).then(() => { + updateNodeComplete(assessmentItem.contentnode, context); + }); + }) + ); + } + ); } export function deleteAssessmentItem(context, assessmentItem) { - return db.transaction('rw', [TABLE_NAMES.CONTENTNODE, TABLE_NAMES.ASSESSMENTITEM], () => { - return AssessmentItem.delete([assessmentItem.contentnode, assessmentItem.assessment_id]).then( - () => { - context.commit('DELETE_ASSESSMENTITEM', assessmentItem); - const contentnode = assessmentItem.contentnode; - return updateNodeComplete(contentnode, context); - } - ); - }); + return db.transaction( + 'rw', + [TABLE_NAMES.CONTENTNODE, TABLE_NAMES.ASSESSMENTITEM, TABLE_NAMES.CHANGES_TABLE], + () => { + return AssessmentItem.delete([assessmentItem.contentnode, assessmentItem.assessment_id]).then( + () => { + context.commit('DELETE_ASSESSMENTITEM', assessmentItem); + const contentnode = assessmentItem.contentnode; + return updateNodeComplete(contentnode, context); + } + ); + } + ); } diff --git a/contentcuration/contentcuration/frontend/shared/data/resources.js b/contentcuration/contentcuration/frontend/shared/data/resources.js index 73fe19f3a3..e0c7d088b0 100644 --- a/contentcuration/contentcuration/frontend/shared/data/resources.js +++ b/contentcuration/contentcuration/frontend/shared/data/resources.js @@ -1802,18 +1802,20 @@ export const AssessmentItem = new Resource({ }); }); }, + // Retain super's delete method + _delete: Resource.prototype.delete, delete(id) { const nodeId = id[0]; - return this.transaction({ mode: 'rw' }, () => { - return this.table.delete(id); - }).then(data => { + return this._delete(id).then(data => { return this.modifyAssessmentItemCount(nodeId, -1).then(() => { return data; }); }); }, + // Retain super's add method + _add: Resource.prototype.add, add(obj) { - return super.add(obj).then(id => { + return this._add(obj).then(id => { return this.modifyAssessmentItemCount(obj.contentnode, 1).then(() => { return id; });