0af78717dcdab6924eaecae4a4dae81ec82ed09f
[motion2.git] / server / api / intZendeskField / intZendeskField.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xd461=['order','sort','pick','filter','merge','where','type','VIRTUAL','options','ZendeskField','includeAll','include','rows','catch','show','params','find','create','body','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','to-csv','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','limit','undefined','count','offset','set','Content-Range','reject','save','update','then','destroy','end','error','stack','name','send','map','rawAttributes','fieldName','key','model','query','keys','filters','intersection','fields','attributes','length','nolimit'];(function(_0x459094,_0x5e04d5){var _0x18bc8d=function(_0x31a401){while(--_0x31a401){_0x459094['push'](_0x459094['shift']());}};_0x18bc8d(++_0x5e04d5);}(_0xd461,0x13f));var _0x1d46=function(_0x1b1757,_0x56fcf5){_0x1b1757=_0x1b1757-0x0;var _0x7dd252=_0xd461[_0x1b1757];return _0x7dd252;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x1d46('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x1d46('0x1'));var rp=require(_0x1d46('0x2'));var moment=require(_0x1d46('0x3'));var BPromise=require(_0x1d46('0x4'));var Mustache=require(_0x1d46('0x5'));var util=require(_0x1d46('0x6'));var path=require('path');var sox=require('sox');var csv=require(_0x1d46('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x1d46('0x8'));var _=require(_0x1d46('0x9'));var squel=require(_0x1d46('0xa'));var crypto=require(_0x1d46('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x1d46('0xc'));var toCsv=require('to-csv');var querystring=require(_0x1d46('0xd'));var Papa=require(_0x1d46('0xe'));var Redis=require(_0x1d46('0xf'));var authService=require(_0x1d46('0x10'));var qs=require(_0x1d46('0x11'));var as=require(_0x1d46('0x12'));var hardwareService=require(_0x1d46('0x13'));var logger=require('../../config/logger')(_0x1d46('0x14'));var utils=require('../../config/utils');var config=require(_0x1d46('0x15'));var licenseUtil=require(_0x1d46('0x16'));var db=require(_0x1d46('0x17'))['db'];function respondWithStatusCode(_0xde0200,_0x486c89){_0x486c89=_0x486c89||0xcc;return function(_0x5afb26){if(_0x5afb26){return _0xde0200[_0x1d46('0x18')](_0x486c89);}return _0xde0200[_0x1d46('0x19')](_0x486c89)['end']();};}function respondWithResult(_0x37f6a4,_0x282f52){_0x282f52=_0x282f52||0xc8;return function(_0x27f3ba){if(_0x27f3ba){return _0x37f6a4[_0x1d46('0x19')](_0x282f52)[_0x1d46('0x1a')](_0x27f3ba);}};}function respondWithFilteredResult(_0x16459c,_0x368810){return function(_0x3c405a){if(_0x3c405a){var _0x10b856=typeof _0x368810['offset']==='undefined'&&typeof _0x368810[_0x1d46('0x1b')]===_0x1d46('0x1c');var _0x75d289=_0x3c405a['count'];var _0x455582=_0x10b856?0x0:_0x368810['offset'];var _0x25e788=_0x10b856?_0x3c405a[_0x1d46('0x1d')]:_0x368810[_0x1d46('0x1e')]+_0x368810[_0x1d46('0x1b')];var _0xac9de0;if(_0x25e788>=_0x75d289){_0x25e788=_0x75d289;_0xac9de0=0xc8;}else{_0xac9de0=0xce;}_0x16459c[_0x1d46('0x19')](_0xac9de0);return _0x16459c[_0x1d46('0x1f')](_0x1d46('0x20'),_0x455582+'-'+_0x25e788+'/'+_0x75d289)[_0x1d46('0x1a')](_0x3c405a);}return null;};}function patchUpdates(_0x493972){return function(_0x54cf60){try{jsonpatch['apply'](_0x54cf60,_0x493972,!![]);}catch(_0x3c3902){return BPromise[_0x1d46('0x21')](_0x3c3902);}return _0x54cf60[_0x1d46('0x22')]();};}function saveUpdates(_0x19562c,_0x1bca54){return function(_0x2ad35c){if(_0x2ad35c){return _0x2ad35c[_0x1d46('0x23')](_0x19562c)[_0x1d46('0x24')](function(_0x167687){return _0x167687;});}return null;};}function removeEntity(_0x460f80,_0x4ada6e){return function(_0xe136dc){if(_0xe136dc){return _0xe136dc[_0x1d46('0x25')]()[_0x1d46('0x24')](function(){_0x460f80['status'](0xcc)[_0x1d46('0x26')]();});}};}function handleEntityNotFound(_0x18f781,_0x6515fd){return function(_0x4aa2de){if(!_0x4aa2de){_0x18f781[_0x1d46('0x18')](0x194);}return _0x4aa2de;};}function handleError(_0x1907ea,_0x2b4761){_0x2b4761=_0x2b4761||0x1f4;return function(_0xa1cf5a){logger[_0x1d46('0x27')](_0xa1cf5a[_0x1d46('0x28')]);if(_0xa1cf5a[_0x1d46('0x29')]){delete _0xa1cf5a[_0x1d46('0x29')];}_0x1907ea['status'](_0x2b4761)[_0x1d46('0x2a')](_0xa1cf5a);};}exports['index']=function(_0x1c4b17,_0x3e483e){var _0x35de26={},_0x348696={},_0x2a2094={'count':0x0,'rows':[]};var _0x39710a=_[_0x1d46('0x2b')](db['ZendeskField'][_0x1d46('0x2c')],function(_0x9e6864){return{'name':_0x9e6864[_0x1d46('0x2d')],'type':_0x9e6864['type'][_0x1d46('0x2e')]};});_0x348696[_0x1d46('0x2f')]=_['map'](_0x39710a,_0x1d46('0x29'));_0x348696[_0x1d46('0x30')]=_[_0x1d46('0x31')](_0x1c4b17['query']);_0x348696[_0x1d46('0x32')]=_[_0x1d46('0x33')](_0x348696[_0x1d46('0x2f')],_0x348696['query']);_0x35de26['attributes']=_[_0x1d46('0x33')](_0x348696['model'],qs['fields'](_0x1c4b17[_0x1d46('0x30')][_0x1d46('0x34')]));_0x35de26[_0x1d46('0x35')]=_0x35de26[_0x1d46('0x35')][_0x1d46('0x36')]?_0x35de26[_0x1d46('0x35')]:_0x348696['model'];if(!_0x1c4b17[_0x1d46('0x30')]['hasOwnProperty'](_0x1d46('0x37'))){_0x35de26['limit']=qs[_0x1d46('0x1b')](_0x1c4b17[_0x1d46('0x30')]['limit']);_0x35de26[_0x1d46('0x1e')]=qs['offset'](_0x1c4b17[_0x1d46('0x30')][_0x1d46('0x1e')]);}_0x35de26[_0x1d46('0x38')]=qs['sort'](_0x1c4b17['query'][_0x1d46('0x39')]);_0x35de26['where']=qs[_0x1d46('0x32')](_[_0x1d46('0x3a')](_0x1c4b17[_0x1d46('0x30')],_0x348696[_0x1d46('0x32')]),_0x39710a);if(_0x1c4b17['query'][_0x1d46('0x3b')]){_0x35de26['where']=_[_0x1d46('0x3c')](_0x35de26[_0x1d46('0x3d')],{'$or':_[_0x1d46('0x2b')](_0x39710a,function(_0x1093f1){if(_0x1093f1[_0x1d46('0x3e')]!==_0x1d46('0x3f')){var _0x9910db={};_0x9910db[_0x1093f1[_0x1d46('0x29')]]={'$like':'%'+_0x1c4b17[_0x1d46('0x30')][_0x1d46('0x3b')]+'%'};return _0x9910db;}})});}_0x35de26=_[_0x1d46('0x3c')]({},_0x35de26,_0x1c4b17[_0x1d46('0x40')]);var _0x2fa96c={'where':_0x35de26[_0x1d46('0x3d')]};return db[_0x1d46('0x41')][_0x1d46('0x1d')](_0x2fa96c)[_0x1d46('0x24')](function(_0x3d43c4){_0x2a2094[_0x1d46('0x1d')]=_0x3d43c4;if(_0x1c4b17[_0x1d46('0x30')][_0x1d46('0x42')]){_0x35de26[_0x1d46('0x43')]=[{'all':!![]}];}return db['ZendeskField']['findAll'](_0x35de26);})[_0x1d46('0x24')](function(_0x5baccc){_0x2a2094[_0x1d46('0x44')]=_0x5baccc;return _0x2a2094;})[_0x1d46('0x24')](respondWithFilteredResult(_0x3e483e,_0x35de26))[_0x1d46('0x45')](handleError(_0x3e483e,null));};exports[_0x1d46('0x46')]=function(_0x387033,_0x1f2da0){var _0x2c1bf4={'raw':!![],'where':{'id':_0x387033[_0x1d46('0x47')]['id']}},_0x14679c={};_0x14679c['model']=_['keys'](db[_0x1d46('0x41')][_0x1d46('0x2c')]);_0x14679c[_0x1d46('0x30')]=_[_0x1d46('0x31')](_0x387033['query']);_0x14679c[_0x1d46('0x32')]=_[_0x1d46('0x33')](_0x14679c[_0x1d46('0x2f')],_0x14679c[_0x1d46('0x30')]);_0x2c1bf4[_0x1d46('0x35')]=_['intersection'](_0x14679c[_0x1d46('0x2f')],qs[_0x1d46('0x34')](_0x387033[_0x1d46('0x30')][_0x1d46('0x34')]));_0x2c1bf4[_0x1d46('0x35')]=_0x2c1bf4['attributes']['length']?_0x2c1bf4[_0x1d46('0x35')]:_0x14679c[_0x1d46('0x2f')];if(_0x387033[_0x1d46('0x30')][_0x1d46('0x42')]){_0x2c1bf4[_0x1d46('0x43')]=[{'all':!![]}];}_0x2c1bf4=_[_0x1d46('0x3c')]({},_0x2c1bf4,_0x387033['options']);return db[_0x1d46('0x41')][_0x1d46('0x48')](_0x2c1bf4)[_0x1d46('0x24')](handleEntityNotFound(_0x1f2da0,null))[_0x1d46('0x24')](respondWithResult(_0x1f2da0,null))['catch'](handleError(_0x1f2da0,null));};exports[_0x1d46('0x49')]=function(_0x375f55,_0x47f2a5){return db[_0x1d46('0x41')][_0x1d46('0x49')](_0x375f55[_0x1d46('0x4a')],{})[_0x1d46('0x24')](respondWithResult(_0x47f2a5,0xc9))['catch'](handleError(_0x47f2a5,null));};exports[_0x1d46('0x23')]=function(_0x32379c,_0x254b67){if(_0x32379c[_0x1d46('0x4a')]['id']){delete _0x32379c[_0x1d46('0x4a')]['id'];}return db[_0x1d46('0x41')][_0x1d46('0x48')]({'where':{'id':_0x32379c[_0x1d46('0x47')]['id']}})[_0x1d46('0x24')](handleEntityNotFound(_0x254b67,null))[_0x1d46('0x24')](saveUpdates(_0x32379c[_0x1d46('0x4a')],null))[_0x1d46('0x24')](respondWithResult(_0x254b67,null))[_0x1d46('0x45')](handleError(_0x254b67,null));};exports['destroy']=function(_0x154516,_0x14cef8){return db[_0x1d46('0x41')][_0x1d46('0x48')]({'where':{'id':_0x154516['params']['id']}})[_0x1d46('0x24')](handleEntityNotFound(_0x14cef8,null))[_0x1d46('0x24')](removeEntity(_0x14cef8,null))['catch'](handleError(_0x14cef8,null));};