Files
old-psihologija/controllers/integration.js

61 lines
1.6 KiB
JavaScript
Raw Normal View History

'use strict';
const { getMappingsFromDatabase, fetchOffices, fetchResources, saveNewMappingToDatabase } = require('../services/officeRnD/resources');
const { getAllDoorLockIncidents } = require('../services/integration/reports');
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);
});
}
};
const getAllIncidents = (req, res) => {
getAllDoorLockIncidents()
.then((incidents) => {
res.send(incidents);
})
.catch((error) => {
console.log(error);
res.send([]);
});
};
const getUnlockedIncidents = (req, res) => {
};
const getUnscheduledIncidents = (req, res) => {
};
module.exports = {
getKnownOfficeResourceMappings,
addNewMapping,
getAllIncidents,
getUnscheduledIncidents,
getUnlockedIncidents,
};