const increaseSalary = async () => {
try {
const employees = await api.getEmployees();
const employee = employees.reduce(
(acc, cur) => (acc.salary > cur.salary ? cur : acc),
{ salary: Infinity },
);
const newSalary = (employee.salary * 1.2) | 0;
const result = await api.setEmployeeSalary(employee.id, newSalary);
if (result.salary !== newSalary) {
throw 'API Error, salary has not increased';
}
await api.notifyEmployee(
employee.id,
`Hello, ${employee.name}! Congratulations, your new salary is ${newSalary}!`,
);
return true;
} catch (e) {
api.notifyAdmin(e.message);
return false;
}
});