38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const { getMappingsFromDatabase, fetchOffices, fetchResources, saveNewMappingToDatabase } = require('../services/officeRnD/resources');
|
|
|
|
const getKnownOfficeResourceMappings = (req, res) => {
|
|
const dataToFetch = [getMappingsFromDatabase(), fetchOffices(), fetchResources() ];
|
|
|
|
Promise.all(dataToFetch)
|
|
.then(result => {
|
|
res.send({
|
|
existingMappings: result[0],
|
|
offices: result[1],
|
|
resources: result[2],
|
|
});
|
|
})
|
|
.catch(error => {
|
|
res.status(500).send();
|
|
});
|
|
};
|
|
|
|
const addNewMapping = (req, res) => {
|
|
const newMapping = req.body && req.body.mapping ? req.body.mapping : null;
|
|
if (newMapping && newMapping.officeSlug && newMapping.resourceSlug && newMapping.officeId && newMapping.resourceId){
|
|
saveNewMappingToDatabase(newMapping)
|
|
.then(() => {
|
|
res.send(newMapping);
|
|
})
|
|
.catch(error => {
|
|
res.status(500).send(error);
|
|
});
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
getKnownOfficeResourceMappings,
|
|
addNewMapping,
|
|
};
|