Skip to content

Commit

Permalink
add undefined check to calculateCurrentPrecentage
Browse files Browse the repository at this point in the history
  • Loading branch information
nevio18324 committed Dec 19, 2024
1 parent 70be250 commit e1b6a5d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion frontend/src/app/shared/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ export function optionalValue (param: object): Record<string, any> {
return true;
}));
}

export function isLastCheckInNegative (baseline: number, stretchGoal: number, value: number): boolean {
return value > baseline && baseline > stretchGoal || value < baseline && baseline <= stretchGoal;
}

export function calculateCurrentPercentage (keyResultMetric: KeyResultMetricMin): number {
const value: number = +keyResultMetric.lastCheckIn?.value;
const value: number = +(keyResultMetric.lastCheckIn?.value ?? 0);
const baseline: number = +keyResultMetric.baseline;
const stretchGoal: number = +keyResultMetric.stretchGoal;
if (isLastCheckInNegative(baseline,
Expand All @@ -52,6 +53,7 @@ export function calculateCurrentPercentage (keyResultMetric: KeyResultMetricMin)

return Math.abs(value - baseline) / Math.abs(stretchGoal - baseline) * 100;
}

export function sanitize (query: string) {
return query.trim()
.toLowerCase();
Expand All @@ -61,6 +63,7 @@ export function getQueryString (query?: string) {
const queryString = query || "";
return sanitize(decodeURI(queryString));
}

export function optionalReplaceWithNulls (param: object): Record<string, any> {
const clearObject = optionalValue(param);
return Object.fromEntries(Object.entries(param)
Expand Down

0 comments on commit e1b6a5d

Please sign in to comment.