2023-12-31 02:53:25 +00:00
|
|
|
import {
|
|
|
|
AnyTypedQuizQuestion,
|
|
|
|
UntypedQuizQuestion,
|
|
|
|
} from "@model/questionTypes/shared";
|
2023-12-27 07:25:30 +00:00
|
|
|
import { Quiz } from "@model/quiz/quiz";
|
|
|
|
import { updateSomeWorkBackend } from "@root/uiTools/actions";
|
|
|
|
import { DeleteFunction } from "@utils/deleteFunc";
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
type allQuestionsTypes = AnyTypedQuizQuestion | UntypedQuizQuestion;
|
2023-12-27 07:25:30 +00:00
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
export const deleteTimeoutedQuestions = async (
|
|
|
|
questions: allQuestionsTypes[],
|
|
|
|
quiz: Quiz | undefined,
|
|
|
|
) => {
|
2023-12-27 07:25:30 +00:00
|
|
|
const questionsForDeletion = questions.filter(
|
2023-12-31 02:53:25 +00:00
|
|
|
({ type, deleted }) => type && type !== "result" && deleted,
|
2023-12-27 07:25:30 +00:00
|
|
|
) as AnyTypedQuizQuestion[];
|
|
|
|
if (questionsForDeletion.length > 0) {
|
2023-12-31 02:53:25 +00:00
|
|
|
updateSomeWorkBackend(true);
|
2023-12-27 07:25:30 +00:00
|
|
|
|
|
|
|
await Promise.allSettled(
|
2023-12-31 02:53:25 +00:00
|
|
|
questionsForDeletion.map((question) =>
|
|
|
|
DeleteFunction(questions, question, quiz),
|
|
|
|
),
|
|
|
|
);
|
2023-12-27 07:25:30 +00:00
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
updateSomeWorkBackend(false);
|
2023-12-27 07:25:30 +00:00
|
|
|
}
|
2023-12-31 02:53:25 +00:00
|
|
|
};
|