Smarter survey and question deletion/duplucation
This commit is contained in:
parent
aeebddd191
commit
15bff5af96
4 changed files with 54 additions and 8 deletions
|
|
@ -120,6 +120,12 @@ export class Question {
|
|||
|
||||
async delete() {
|
||||
if (this.id) {
|
||||
// Start by deleting proposals
|
||||
const proposals = await this.getProposals();
|
||||
for (const p of proposals) {
|
||||
await p.delete();
|
||||
}
|
||||
|
||||
const res = await fetch(`api/questions/${this.id}`, {
|
||||
method: 'DELETE',
|
||||
headers: {'Accept': 'application/json'},
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { getCorrectionTemplates } from './correctionTemplates';
|
||||
import { getQuestions } from './questions';
|
||||
import { Response } from './response';
|
||||
import { Work } from './works';
|
||||
|
|
@ -101,9 +102,33 @@ export class Survey {
|
|||
// Now recopy questions
|
||||
const questions = await getQuestions(oldSurveyId);
|
||||
for (const q of questions) {
|
||||
const oldQuestionId = q.id;
|
||||
|
||||
delete q.id;
|
||||
q.id_survey = response.id;
|
||||
q.save();
|
||||
q.save().then((question) => {
|
||||
q.id = oldQuestionId;
|
||||
|
||||
// Now recopy proposals
|
||||
if (q.kind == "mcq" || q.kind == "ucq") {
|
||||
q.getProposals().then((proposals) => {
|
||||
for (const p of proposals) {
|
||||
delete p.id;
|
||||
p.id_question = question.id;
|
||||
p.save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Now recopy correction templates
|
||||
getCorrectionTemplates(oldQuestionId).then((cts) => {
|
||||
for (const ct of cts) {
|
||||
delete ct.id;
|
||||
ct.id_question = question.id;
|
||||
ct.save();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
|
|
@ -115,6 +140,12 @@ export class Survey {
|
|||
|
||||
async delete() {
|
||||
if (this.id) {
|
||||
// Start by deleting questions
|
||||
const questions = await getQuestions(this.id);
|
||||
for (const q of questions) {
|
||||
await q.delete();
|
||||
}
|
||||
|
||||
const res = await fetch(`api/surveys/${this.id}`, {
|
||||
method: 'DELETE',
|
||||
headers: {'Accept': 'application/json'},
|
||||
|
|
|
|||
Reference in a new issue