3 var _ = require('lodash');
4 var ReportAgent = require('../../models').ReportAgent;
6 // Get list of report_agents
7 exports.index = function(req, res) {
10 .then(function(report_agents) {
11 return res.status(200).send(report_agents);
13 .catch(function(err) {
14 return handleError(res, err);
19 exports.describe = function(req, res) {
22 .then(function(fields) {
23 return res.status(200).send(fields);
25 .catch(function(err) {
26 return handleError(res, err);
30 // Get a single report_agent
31 exports.show = function(req, res) {
33 .findById(req.params.id)
34 .then(function(report_agent) {
36 return res.sendStatus(404);
38 return res.send(report_agent);
40 .catch(function(err) {
41 return handleError(res, err);
45 // Creates a new report_agent in the DB.
46 exports.create = function(req, res) {
49 .then(function(report_agent) {
50 return res.status(201).send(report_agent);
52 .catch(function(err) {
53 return handleError(res, err);
57 // Updates an existing report_agent in the DB.
58 exports.update = function(req, res) {
63 .findById(req.params.id)
64 .then(function(report_agent) {
66 return res.sendStatus(404);
68 var updated = _.merge(report_agent, req.body);
71 return res.status(200).send(report_agent);
73 .catch(function(err) {
74 return handleError(res, err);
77 .catch(function(err) {
78 return handleError(res, err);
82 // Deletes a report_agent from the DB.
83 exports.destroy = function(req, res) {
85 .findById(req.params.id)
86 .then(function(report_agent) {
88 return res.sendStatus(404);
90 report_agent.destroy()
92 return res.sendStatus(204);
94 .catch(function(err) {
95 return handleError(res, err);
98 .catch(function(err) {
99 return handleError(res, err);
103 function handleError(res, err) {
104 return res.status(500).send(err);