3 var _ = require('lodash');
4 var ZendeskField = require('../../models').ZendeskField;
6 // Get list of zendesk_fields
7 exports.index = function(req, res) {
12 .then(function(zendesk_fields) {
13 return res.status(200).send(zendesk_fields);
15 .catch(function(err) {
16 return handleError(res, err);
20 // Get a single zendesk_field
21 exports.show = function(req, res) {
23 .findById(req.params.id)
24 .then(function(zendesk_field) {
26 return res.sendStatus(404);
28 return res.send(zendesk_field);
30 .catch(function(err) {
31 return handleError(res, err);
35 // Creates a new zendesk_field in the DB.
36 exports.create = function(req, res) {
39 .then(function(zendesk_field) {
40 return res.status(201).send(zendesk_field);
42 .catch(function(err) {
43 return handleError(res, err);
47 // Updates an existing zendesk_field in the DB.
48 exports.update = function(req, res) {
53 .findById(req.params.id)
54 .then(function(zendesk_field) {
56 return res.sendStatus(404);
58 var updated = _.merge(zendesk_field, req.body);
61 return res.status(200).send(zendesk_field);
63 .catch(function(err) {
64 return handleError(res, err);
67 .catch(function(err) {
68 return handleError(res, err);
72 // Deletes a zendesk_field from the DB.
73 exports.destroy = function(req, res) {
75 .findById(req.params.id)
76 .then(function(zendesk_field) {
78 return res.sendStatus(404);
80 zendesk_field.destroy()
82 return res.sendStatus(204);
84 .catch(function(err) {
85 return handleError(res, err);
88 .catch(function(err) {
89 return handleError(res, err);
93 exports.zendeskValidation = function(req, res) {
95 where[req.params.field] = req.body.value;
96 where.ZendeskAccountId = req.params.accountId;
101 .then(function(result) {
103 return res.status(200).send({
105 value: req.body.value
108 return res.status(200).send({
110 value: req.body.value
113 .catch(function(err) {
114 return handleError(res, err);
119 function handleError(res, err) {
120 return res.status(500).send(err);