tl-esa-tools/survey/src/api/Api.ts

38 lines
776 B
TypeScript
Raw Permalink Normal View History

2023-04-29 22:45:52 +03:00
export interface SettingsDto {
randomizeQuestions: boolean,
randomizeOptions: boolean
}
export interface OptionDto {
option: string,
value: number
}
export interface QuestionDto {
group: string,
title: string,
question: string,
options: OptionDto[]
}
export interface SurveyDto {
title: string,
intro: string,
settings: SettingsDto,
2024-02-16 23:24:48 +03:00
questions: QuestionDto[],
2024-02-16 23:54:47 +03:00
resultsInfo: string
2023-04-29 22:45:52 +03:00
}
const Api = {
loadSurvey: (uri: string,
onSuccess: (survey: SurveyDto) => void,
onError: (failure: string) => void) => {
fetch(uri)
.then(res => res.json())
.then(out => onSuccess(out as SurveyDto))
.catch(err => onError(err))
}
};
export default Api;