22 lines
802 B
TypeScript
22 lines
802 B
TypeScript
|
import { AnyTypedQuizQuestion, UntypedQuizQuestion } from "@model/questionTypes/shared";
|
||
|
import { Quiz } from "@model/quiz/quiz";
|
||
|
import { updateSomeWorkBackend } from "@root/uiTools/actions";
|
||
|
import { DeleteFunction } from "@utils/deleteFunc";
|
||
|
|
||
|
type allQuestionsTypes = AnyTypedQuizQuestion | UntypedQuizQuestion
|
||
|
|
||
|
export const deleteTimeoutedQuestions = async (questions: allQuestionsTypes[], quiz: Quiz|undefined) => {
|
||
|
const questionsForDeletion = questions.filter(
|
||
|
({ type, deleted }) => type && type !== "result" && deleted
|
||
|
) as AnyTypedQuizQuestion[];
|
||
|
if (questionsForDeletion.length > 0) {
|
||
|
updateSomeWorkBackend(true)
|
||
|
|
||
|
|
||
|
await Promise.allSettled(
|
||
|
questionsForDeletion.map(question => DeleteFunction(questions, question, quiz))
|
||
|
)
|
||
|
|
||
|
updateSomeWorkBackend(false)
|
||
|
}
|
||
|
};
|