3 var _ = require('lodash');
4 var ReportIntegration = require('../../models').ReportIntegration;
6 // Get list of report_integrations
7 exports.index = function(req, res) {
10 .then(function(report_integrations) {
11 return res.status(200).send(report_integrations);
13 .catch(function(err) {
14 return handleError(res, err);
18 // Get a single report_integration
19 exports.show = function(req, res) {
21 .findById(req.params.id)
22 .then(function(report_integration) {
23 if (!report_integration) {
24 return res.sendStatus(404);
26 return res.send(report_integration);
28 .catch(function(err) {
29 return handleError(res, err);
33 // Creates a new report_integration in the DB.
34 exports.create = function(req, res) {
37 .then(function(report_integration) {
38 return res.status(201).send(report_integration);
40 .catch(function(err) {
41 return handleError(res, err);
45 // Updates an existing report_integration in the DB.
46 exports.update = function(req, res) {
51 .findById(req.params.id)
52 .then(function(report_integration) {
53 if (!report_integration) {
54 return res.sendStatus(404);
56 var updated = _.merge(report_integration, req.body);
59 return res.status(200).send(report_integration);
61 .catch(function(err) {
62 return handleError(res, err);
65 .catch(function(err) {
66 return handleError(res, err);
70 // Deletes a report_integration from the DB.
71 exports.destroy = function(req, res) {
73 .findById(req.params.id)
74 .then(function(report_integration) {
75 if (!report_integration) {
76 return res.sendStatus(404);
78 report_integration.destroy()
80 return res.sendStatus(204);
82 .catch(function(err) {
83 return handleError(res, err);
86 .catch(function(err) {
87 return handleError(res, err);
91 function handleError(res, err) {
92 return res.status(500).send(err);