Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function increaseSalary() {
- let newUsersSalary = 0;
- let success = 0;
- try {
- const users = await api.getEmployees();
- const middleSalary = users.reduce((acc, item) => (acc += item.salary), 0) / users.length;
- for (let user of users) {
- try {
- const newUser = await api.setEmployeeSalary(user.id, user.salary < middleSalary ? user.salary * 1.2 : user.salary * 1.1);
- await api.notifyEmployee(newUser.id, `Hello, ${newUser.name}! Congratulations, your new salary is ${newUser.salary}!`);
- newUsersSalary += newUser.salary;
- success += 1;
- } catch (e) {
- api.notifyAdmin(e);
- }
- }
- } catch (e) {
- api.notifyAdmin(e);
- } finally {
- api.sendBudgetToAccounting(newUsersSalary);
- return new Promise((res) => res(success));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment