-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Compensations): display salary for selected location, degree and…
… examination year
- Loading branch information
Showing
8 changed files
with
114 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { | ||
isSalariesType, | ||
Salaries, | ||
} from "studio/components/salariesInput/utils/parseSalaries"; | ||
import { SalariesByLocation } from "../../../studio/lib/payloads/compensations"; | ||
import { Result, ResultError, ResultOk } from "../../../studio/utils/result"; | ||
|
||
export function calculateSalary( | ||
examinationYear: number, | ||
degree: string, | ||
salaries: Salaries, | ||
): number | undefined { | ||
const degreeValue = degree === "bachelor" ? 1 : 0; | ||
const adjustedYear = examinationYear + degreeValue; | ||
return salaries[adjustedYear]; | ||
} | ||
|
||
export function calculatePension(salary: number): number { | ||
return Math.round(salary * 0.07); | ||
} | ||
|
||
function examinationYearsFromSalaries(salaries: Salaries) { | ||
return Object.keys(salaries).map(Number); | ||
} | ||
|
||
export function minSalariesExaminationYear(salaries: Salaries): number { | ||
return Math.min(...examinationYearsFromSalaries(salaries)); | ||
} | ||
|
||
export function maxSalariesExaminationYear(salaries: Salaries): number { | ||
return Math.max(...examinationYearsFromSalaries(salaries)); | ||
} | ||
|
||
export function salariesFromLocation( | ||
year: number, | ||
locationId: string, | ||
salariesByLocation: SalariesByLocation[], | ||
): Result<Salaries, string> { | ||
const yearlySalaries = salariesByLocation.find( | ||
(s) => s.location._ref === locationId, | ||
)?.yearlySalaries; | ||
if (yearlySalaries === undefined) { | ||
return ResultError(`Could not find salaries for location '${locationId}'`); | ||
} | ||
const salariesData = yearlySalaries.find((s) => s.year === year); | ||
if (salariesData === undefined) { | ||
return ResultError(`Could not find salaries for year ${year}`); | ||
} | ||
const parsedSalaries = JSON.parse(salariesData.salaries); | ||
if (!isSalariesType(parsedSalaries)) { | ||
return ResultError("Parsed salaries data was not valid"); | ||
} | ||
return ResultOk(parsedSalaries); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters