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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user