refactor: console errors

This commit is contained in:
IlyaDoronin 2024-04-16 17:54:59 +03:00
parent 6b907e48fe
commit d970049b37
3 changed files with 40 additions and 21 deletions

@ -15,7 +15,7 @@ export async function activatePromocode(promocode: string) {
contentType: true,
body: { codeword: promocode },
});
console.log(response)
console.log(response);
return response.greetings;
} catch (nativeError) {

@ -172,18 +172,18 @@ function TariffPage() {
return tariff.privileges[0].privilegeId !== "squizHideBadge";
});
function handleApplyPromocode () {
function handleApplyPromocode() {
if (!promocodeField) return;
activatePromocode(promocodeField)
.then(async (greetings) => {
enqueueSnackbar(greetings)
enqueueSnackbar(greetings);
const discounts = await makeRequest({
method: "GET",
url: `${process.env.REACT_APP_DOMAIN}/price/discount/user/${userId}`,
});
setDiscounts(discounts.Discounts);
const discounts = await makeRequest({
method: "GET",
url: `${process.env.REACT_APP_DOMAIN}/price/discount/user/${userId}`,
});
setDiscounts(discounts.Discounts);
})
.catch(enqueueSnackbar);
}

@ -1,4 +1,3 @@
import { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
import {
clearRuleForAll,
createResult,
@ -10,6 +9,13 @@ import { useQuestionsStore } from "@root/questions/store";
import { updateRootContentId } from "@root/quizes/actions";
import { getCurrentQuiz } from "@root/quizes/hooks";
import type {
AnyTypedQuizQuestion,
QuestionBranchingRule,
QuestionBranchingRuleMain,
} from "@model/questionTypes/shared";
import { QuizQuestionResult } from "@model/questionTypes/result";
//Всё здесь нужно сделать последовательно. И пусть весь мир ждёт.
export const DeleteFunction = async (questionId: string) => {
@ -33,7 +39,9 @@ export const DeleteFunction = async (questionId: string) => {
const parentQuestion = getQuestionByContentId(
question.content.rule.parentId,
);
let startCountParentChildren = parentQuestion.content.rule.children;
let startCountParentChildren = parentQuestion?.type
? parentQuestion.content.rule.children
: null;
//записываем потомков , а их результаты удаляем
const getChildren = (parentQuestion: AnyTypedQuizQuestion) => {
@ -67,8 +75,10 @@ export const DeleteFunction = async (questionId: string) => {
}),
);
//чистим rule родителя
const newRule = {};
if (!parentQuestion?.type) {
return;
}
const parentChildren = [...parentQuestion.content.rule.children];
if (parentChildren.includes(question.content.id))
@ -77,15 +87,21 @@ export const DeleteFunction = async (questionId: string) => {
1,
);
newRule.main = parentQuestion.content.rule.main.filter(
(data) => data.next !== question.content.id,
const main = parentQuestion.content.rule.main.filter(
(data: QuestionBranchingRuleMain) => data.next !== question.content.id,
); //удаляем условия перехода от родителя к этому вопросу
newRule.parentId = parentQuestion.content.rule.parentId;
newRule.default =
const defaultValue =
parentQuestion.content.rule.parentId === question.content.id
? ""
: parentQuestion.content.rule.parentId;
newRule.children = parentChildren;
//чистим rule родителя
const newRule: QuestionBranchingRule = {
main,
default: defaultValue,
children: parentChildren,
parentId: parentQuestion.content.rule.parentId,
};
await updateQuestion(question.content.rule.parentId, (PQ) => {
PQ.content.rule = newRule;
@ -101,10 +117,13 @@ export const DeleteFunction = async (questionId: string) => {
//сделать результ родителя видимым если у него не осталось потомков
if (startCountParentChildren.length === 1) {
if (parentResult) {
await updateQuestion(parentResult.content.id, (q) => {
q.content.usage = true;
});
if (parentResult?.type) {
await updateQuestion<QuizQuestionResult>(
parentResult.content.id,
(item) => {
item.content.usage = true;
},
);
} else {
//почему-то не существует результа у родителя. Создаём. Новосозданные результы видны сразу
await createResult(quiz.backendId, parentQuestion.content.id);