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