корректное убирание строк с пробелами, корректная отправка файла

This commit is contained in:
Nastya 2023-12-30 04:04:33 +03:00
parent fac59c4986
commit d68285fa3d
3 changed files with 17 additions and 4 deletions

@ -16,7 +16,7 @@ export function getData(quizId: string) {
export function sendAnswer({ questionId, body, qid }: any) {
const formData = new FormData();
console.log(qid)
const answers = [{
question_id: questionId,
content: body, //тут массив с ответом
@ -40,7 +40,7 @@ export function sendFile({ questionId, body, qid }: any) {
content: body.name,
}
fd[body.name] = body.filen //target.files[0]
fd[body.name] = body.file //target.files[0]
const answers = [fd]
formData.append("answers", JSON.stringify(answers));

@ -18,7 +18,7 @@ const QID =
process.env.NODE_ENV === "production" ?
window.location.pathname.replace(/\//g, '')
:
"6e96e958-d30e-49f6-aa85-32aaef975733"
"2363ad2c-0c19-4f51-80c0-ed2242daa0c4"
export const ViewPage = () => {
@ -67,6 +67,19 @@ export const ViewPage = () => {
//@ts-ignore
cnt: data.cnt
}
parseData.items = parseData.items.map((question:any) => {
let data = question
for (let key in question) {
if (question[key] === " ") data[key] = ""
}
return data
})
useQuestionsStore.setState(parseData)
} catch (e) {

@ -11,7 +11,7 @@ export const replaceSpacesToEmptyLines = <T = unknown>(object: T): T => {
for (const [key, value] of Object.entries(object)) {
if (typeof value === "string") {
result[key] = value.replace(/ /g, "");
result[key] = value.replace(/\" \"/g, '""');
continue;
}