Created
February 7, 2022 08:28
-
-
Save iMichaelOwolabi/2486e581802918d03010ec057879019a to your computer and use it in GitHub Desktop.
Sample dependent promise data/record
This file contains hidden or 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
/** | |
* Dependent promise example | |
*/ | |
// Employee records in the DB | |
const employee = [ | |
{ id: 1, firstName: 'Ayo', lastName: 'Tunmise', dob: '1980-07-28' }, | |
{ id: 2, firstName: 'Dayo', lastName: 'Owolabi', dob: '2000-03-08' }, | |
{ id: 3, firstName: 'Michael', lastName: 'Ikechukwu', dob: '1997-01-31' }, | |
{ id: 4, firstName: 'Hammed', lastName: 'Tukur', dob: '1900-08-07' }, | |
{ id: 5, firstName: 'Bukola', lastName: 'Agbabiaka', dob: '2001-12-09' }, | |
]; | |
// Function to get employee records from the DB | |
const getAllEmployees = () => { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve(employee) | |
}, 1000); | |
}) | |
}; | |
// Employee next of kin records in the DB | |
const nextOfKin = [ | |
{ id: 2, employeeId: 2, fullName: 'Ikoyi Obalende', email: '[email protected]' }, | |
{ id: 3, employeeId: 3, fullName: 'Allen Ikeja', email: '[email protected]' }, | |
{ id: 4, employeeId: 4, fullName: 'Oluyole Ife', email: '[email protected]' }, | |
{ id: 5, employeeId: 5, fullName: 'Chinagoromu Ahmed', email: '[email protected]' }, | |
{ id: 1, employeeId: 1, fullName: 'Mokola Ibadan', email: '[email protected]' }, | |
] | |
// Function to get individual employee next of kin data from the DB | |
const getEmployeeNextOfKin = (employeeId) => { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve(nextOfKin.find(nextOfKin => nextOfKin.employeeId === employeeId)); | |
}, 1000); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment