Plan stuff. Log stuff.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

77 lines
1.9 KiB

export default class Period {
constructor(data) {
this.id = data.id || null;
this.userId = data.userId || null;
this.from = new Date(data.from);
this.to = new Date(data.to);
this.name = data.name || "";
this.tags = data.tags || [];
this.goals = (data.goals || []).map(d => new PeriodGoal(d));
this.logs = (data.logs || []).map(d => new PeriodLog(d));
}
goal(id) {
return this.goals.find(g => g.id === id);
}
subGoal(goalId, id) {
const goal = this.goal(goalId);
if (goal == null) {
return null;
}
return goal.subGoal(id);
}
}
export class PeriodGoal {
constructor(data) {
this.id = data.id || null;
this.activityId = data.activityId || null;
this.pointCount = data.pointCount || 0;
this.subGoals = (data.subGoals || []).map(d => new PeriodSubGoal(d));
}
subGoal(id) {
return this.subGoals.find(s => s.id === id);
}
}
export class PeriodSubGoal {
constructor(data) {
this.id = data.id || null;
this.name = data.name || "";
this.multiplier = data.multiplier || 1;
}
}
export class PeriodLog {
constructor(data) {
this.id = data.id || null;
this.date = new Date(data.date || "0000-00-00T00:00:00Z");
this.subActivityId = data.subActivityId || null;
this.goalId = data.goalId || null;
this.subGoalId = data.subGoalId || null;
this.description = data.description || "";
this.amount = data.amount || 0;
this.score = (data.score ? new PeriodLogScore(data.score) : null);
}
}
export class PeriodLogScore {
constructor(data) {
this.amount = data.amount;
this.activityScore = data.activityScore;
this.subGoalMultiplier = data.subGoalMultiplier;
this.dailyBonus = data.dailyBonus;
this.total = data.total;
}
}
export const PeriodUpdate = class PeriodUpdateDummyForTyping{
constructor() {
console.warn(new Error("PeriodUpdate is a dummy, don't instantiate."));
}
};