Please, help pass the last test. Need to send a notification to the Admin. await api.notifyAdmin(error)
isn't working properly, I guess. Expected 0 number of calls - I recieve 1 :(
my code:
async function increaseSalary() {
try {
let data = await api.getEmployees();
let salary = 0;
let id = '';
let min = Math.min(...data.map((e) => e.salary));
data.forEach(async (e) => {
if(e.salary === min) {
e.salary *= 1.2;
id = e.id;
salary = e.salary;
api.notifyEmployee(e.id, `Hello, ${e.name}! Congratulations, your new salary is ${e.salary}!`)
}
});
await api.setEmployeeSalary(id, salary);
return true;
} catch (error) {
await api.notifyAdmin(error);
return false;
}
}
// All functions for receiving/changing data are asynchronous and return promises.
const api = {
_employees: [
{ id: 1, name: 'Alex', salary: 120000 },
{ id: 2, name: 'Fred', salary: 110000 },
{ id: 3, name: 'Bob', salary: 80000 },
],
getEmployees() {
return new Promise((resolve) => {
resolve(this._employees.slice());
});
},
setEmployeeSalary(employeeId, newSalary) {
return new Promise((resolve) => {
this._employees = this._employees.map((employee) =>
employee.id !== employeeId
? employee
: {
...employee,
salary: newSalary,
}
);
resolve(this._employees.find(({ id }) => id === employeeId));
});
},
notifyEmployee(employeeId, text) {
return new Promise((resolve) => {
resolve(true);
});
},
notifyAdmin(error) {
return new Promise((resolve) => {
resolve(true);
});
},
setEmployees(newEmployees) {
return new Promise((resolve) => {
this._employees = newEmployees;
resolve();
});
},
};
I need to pass this test:
✕ in case of an increase salary error, you should send a notification to the administrator (not user)
successfully passed: ✓ the function must return a promise (5ms) ✓ must correctly increase the employee's salary with the lowest salary (9ms) ✓ must send a notification to the employee