refactor: Simplify API calls

API calls can now make with a simple wrapper function.

Additionally, the error code "200" now means success for all API calls.
This commit is contained in:
Alexander Polynomdivision
2018-10-17 18:28:29 +02:00
parent 7de3cedb15
commit 3b7e55d957
14 changed files with 410 additions and 234 deletions

View File

@@ -1,11 +1,15 @@
import { dayInNDays } from "../../utils/date";
export interface ISchedulingData {
easiness: number;
consecutiveCorrectAnswers: number;
nextDueDate: number;
};
function dateInNDays(n: number): number {
let today = new Date();
today.setDate(today.getDate() + n);
return Date.parse(today.toString());
}
export enum AnswerType {
CORRECT,
WRONG,
@@ -28,8 +32,8 @@ export function updateSchedulingData(data: ISchedulingData, answer: AnswerType):
data.consecutiveCorrectAnswers + 1
) : 0;
data.nextDueDate = answer === AnswerType.CORRECT ? (
dayInNDays(6 * Math.pow(data.easiness, data.consecutiveCorrectAnswers - 1))
) : dayInNDays(1);
dateInNDays(6 * Math.pow(data.easiness, data.consecutiveCorrectAnswers - 1))
) : dateInNDays(1);
return data;
}