frontPanel/src/utils/deleteTimeoutedQuestions.ts

30 lines
840 B
TypeScript
Raw Normal View History

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