Guest User

Untitled

a guest
Aug 17th, 2020
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. async function increaseSalary() {
  2. let newUsersSalary = 0;
  3. let success = 0;
  4. try {
  5. const users = await api.getEmployees();
  6. const middleSalary = users.reduce((acc, item) => (acc += item.salary), 0) / users.length;
  7. for (let user of users) {
  8. try {
  9. const newUser = await api.setEmployeeSalary(user.id, user.salary < middleSalary ? user.salary * 1.2 : user.salary * 1.1);
  10. await api.notifyEmployee(newUser.id, `Hello, ${newUser.name}! Congratulations, your new salary is ${newUser.salary}!`);
  11. newUsersSalary += newUser.salary;
  12. success += 1;
  13. } catch (e) {
  14. api.notifyAdmin(e);
  15. }
  16. }
  17. } catch (e) {
  18. api.notifyAdmin(e);
  19. } finally {
  20. api.sendBudgetToAccounting(newUsersSalary);
  21. return new Promise((res) => res(success));
  22. }
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment