Fix for loading

This commit is contained in:
Senad Uka
2019-07-25 06:53:32 +02:00
parent a691ab94c7
commit 2db47e95e1
26 changed files with 838 additions and 400 deletions

View File

@@ -45,6 +45,30 @@ const fetchResources = () => {
});
};
const getResourceMappings = () => {
return new Promise((resolve, reject) => {
const fetchJobs = [fetchOffices(), fetchResources()];
Promise.all(fetchJobs)
.then((mappings) => {
const offices = mappings[0];
const resources = mappings[1];
const officesMap = {};
const resourcesMap = {};
offices.forEach((office) => officesMap[office.officeId] = office);
resources.forEach((resource) => resourcesMap[resource.resourceId] = resource);
resolve({
officesMap,
resourcesMap,
});
})
.catch((error) => reject(error));
});
};
const getMappingsFromDatabase = () => {
return db.officeResourceMapping.findAll();
};
@@ -57,5 +81,6 @@ module.exports = {
getMappingsFromDatabase,
fetchOffices,
fetchResources,
getResourceMappings,
saveNewMappingToDatabase,
};