Calculate door lock charges
This commit is contained in:
37
controllers/integration.js
Normal file
37
controllers/integration.js
Normal file
@@ -0,0 +1,37 @@
|
||||
'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,
|
||||
};
|
||||
Reference in New Issue
Block a user