Built motion from commit (unavailable).|2.5.13
[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 _0x8aad=['ZendeskField','rawAttributes','fieldName','key','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','type','VIRTUAL','filter','options','count','includeAll','include','findAll','catch','show','params','find','create','update','body','html-pdf','eml-format','zip-dir','request-promise','moment','util','to-csv','ejs','lodash','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','offset','limit','set','json','apply','reject','save','then','destroy','end','error','name','send','index','map'];(function(_0x4d9cb9,_0x33bee3){var _0x5189b3=function(_0x4ed0d4){while(--_0x4ed0d4){_0x4d9cb9['push'](_0x4d9cb9['shift']());}};_0x5189b3(++_0x33bee3);}(_0x8aad,0x146));var _0xd8aa=function(_0x1594e2,_0x43c161){_0x1594e2=_0x1594e2-0x0;var _0x4efbe5=_0x8aad[_0x1594e2];return _0x4efbe5;};'use strict';var pdf=require(_0xd8aa('0x0'));var emlformat=require(_0xd8aa('0x1'));var rimraf=require('rimraf');var zipdir=require(_0xd8aa('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xd8aa('0x3'));var moment=require(_0xd8aa('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xd8aa('0x5'));var path=require('path');var sox=require('sox');var csv=require(_0xd8aa('0x6'));var ejs=require(_0xd8aa('0x7'));var fs=require('fs');var _=require(_0xd8aa('0x8'));var squel=require('squel');var crypto=require(_0xd8aa('0x9'));var jsforce=require(_0xd8aa('0xa'));var deskjs=require(_0xd8aa('0xb'));var toCsv=require(_0xd8aa('0x6'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xd8aa('0xc'));var authService=require(_0xd8aa('0xd'));var qs=require(_0xd8aa('0xe'));var as=require(_0xd8aa('0xf'));var hardwareService=require(_0xd8aa('0x10'));var logger=require('../../config/logger')(_0xd8aa('0x11'));var utils=require(_0xd8aa('0x12'));var config=require(_0xd8aa('0x13'));var licenseUtil=require(_0xd8aa('0x14'));var db=require(_0xd8aa('0x15'))['db'];function respondWithStatusCode(_0x6ec0eb,_0x549fad){_0x549fad=_0x549fad||0xcc;return function(_0x1e7db8){if(_0x1e7db8){return _0x6ec0eb[_0xd8aa('0x16')](_0x549fad);}return _0x6ec0eb[_0xd8aa('0x17')](_0x549fad)['end']();};}function respondWithResult(_0x5a8c79,_0x275eff){_0x275eff=_0x275eff||0xc8;return function(_0x319ffe){if(_0x319ffe){return _0x5a8c79[_0xd8aa('0x17')](_0x275eff)['json'](_0x319ffe);}};}function respondWithFilteredResult(_0x2678ed,_0x180c56){return function(_0x39b5bc){if(_0x39b5bc){var _0x404ed6=_0x39b5bc['count'],_0x47a0e3=_0x180c56[_0xd8aa('0x18')],_0x476930=_0x180c56[_0xd8aa('0x18')]+_0x180c56[_0xd8aa('0x19')],_0xa9ba1b;if(_0x476930>=_0x404ed6){_0x476930=_0x404ed6;_0xa9ba1b=0xc8;}else{_0xa9ba1b=0xce;}_0x2678ed[_0xd8aa('0x17')](_0xa9ba1b);return _0x2678ed[_0xd8aa('0x1a')]('Content-Range',_0x47a0e3+'-'+_0x476930+'/'+_0x404ed6)[_0xd8aa('0x1b')](_0x39b5bc);}return null;};}function patchUpdates(_0x266308){return function(_0xb156e6){try{jsonpatch[_0xd8aa('0x1c')](_0xb156e6,_0x266308,!![]);}catch(_0x56936b){return BPromise[_0xd8aa('0x1d')](_0x56936b);}return _0xb156e6[_0xd8aa('0x1e')]();};}function saveUpdates(_0x46d69b,_0x3588ee){return function(_0x16694e){if(_0x16694e){return _0x16694e['update'](_0x46d69b)[_0xd8aa('0x1f')](function(_0x1366ce){return _0x1366ce;});}return null;};}function removeEntity(_0xc4f55c,_0x5910b3){return function(_0xa7cf85){if(_0xa7cf85){return _0xa7cf85[_0xd8aa('0x20')]()[_0xd8aa('0x1f')](function(){_0xc4f55c[_0xd8aa('0x17')](0xcc)[_0xd8aa('0x21')]();});}};}function handleEntityNotFound(_0x16758a,_0x1f64f8){return function(_0x34d957){if(!_0x34d957){_0x16758a[_0xd8aa('0x16')](0x194);}return _0x34d957;};}function handleError(_0x210176,_0x6614ab){_0x6614ab=_0x6614ab||0x1f4;return function(_0x370d6f){logger[_0xd8aa('0x22')](_0x370d6f['stack']);if(_0x370d6f[_0xd8aa('0x23')]){delete _0x370d6f[_0xd8aa('0x23')];}_0x210176[_0xd8aa('0x17')](_0x6614ab)[_0xd8aa('0x24')](_0x370d6f);};}exports[_0xd8aa('0x25')]=function(_0x3696fd,_0x26ab06){var _0x19edee={},_0x3bba1d={},_0xbe531={'count':0x0,'rows':[]};var _0x4cdb90=_[_0xd8aa('0x26')](db[_0xd8aa('0x27')][_0xd8aa('0x28')],function(_0x49a7c8){return{'name':_0x49a7c8[_0xd8aa('0x29')],'type':_0x49a7c8['type'][_0xd8aa('0x2a')]};});_0x3bba1d[_0xd8aa('0x2b')]=_[_0xd8aa('0x26')](_0x4cdb90,_0xd8aa('0x23'));_0x3bba1d[_0xd8aa('0x2c')]=_[_0xd8aa('0x2d')](_0x3696fd[_0xd8aa('0x2c')]);_0x3bba1d[_0xd8aa('0x2e')]=_['intersection'](_0x3bba1d[_0xd8aa('0x2b')],_0x3bba1d[_0xd8aa('0x2c')]);_0x19edee[_0xd8aa('0x2f')]=_[_0xd8aa('0x30')](_0x3bba1d[_0xd8aa('0x2b')],qs[_0xd8aa('0x31')](_0x3696fd[_0xd8aa('0x2c')][_0xd8aa('0x31')]));_0x19edee['attributes']=_0x19edee[_0xd8aa('0x2f')][_0xd8aa('0x32')]?_0x19edee[_0xd8aa('0x2f')]:_0x3bba1d['model'];if(!_0x3696fd[_0xd8aa('0x2c')][_0xd8aa('0x33')](_0xd8aa('0x34'))){_0x19edee[_0xd8aa('0x19')]=qs[_0xd8aa('0x19')](_0x3696fd[_0xd8aa('0x2c')][_0xd8aa('0x19')]);_0x19edee[_0xd8aa('0x18')]=qs[_0xd8aa('0x18')](_0x3696fd['query'][_0xd8aa('0x18')]);}_0x19edee[_0xd8aa('0x35')]=qs[_0xd8aa('0x36')](_0x3696fd[_0xd8aa('0x2c')][_0xd8aa('0x36')]);_0x19edee[_0xd8aa('0x37')]=qs[_0xd8aa('0x2e')](_[_0xd8aa('0x38')](_0x3696fd[_0xd8aa('0x2c')],_0x3bba1d['filters']),_0x4cdb90);if(_0x3696fd[_0xd8aa('0x2c')]['filter']){_0x19edee[_0xd8aa('0x37')]=_[_0xd8aa('0x39')](_0x19edee['where'],{'$or':_[_0xd8aa('0x26')](_0x4cdb90,function(_0x1a4f2c){if(_0x1a4f2c[_0xd8aa('0x3a')]!==_0xd8aa('0x3b')){var _0x7cd3a9={};_0x7cd3a9[_0x1a4f2c['name']]={'$like':'%'+_0x3696fd['query'][_0xd8aa('0x3c')]+'%'};return _0x7cd3a9;}})});}_0x19edee=_['merge']({},_0x19edee,_0x3696fd[_0xd8aa('0x3d')]);var _0x7a6df2={'where':_0x19edee[_0xd8aa('0x37')]};return db[_0xd8aa('0x27')][_0xd8aa('0x3e')](_0x7a6df2)[_0xd8aa('0x1f')](function(_0x3e79b6){_0xbe531[_0xd8aa('0x3e')]=_0x3e79b6;if(_0x3696fd[_0xd8aa('0x2c')][_0xd8aa('0x3f')]){_0x19edee[_0xd8aa('0x40')]=[{'all':!![]}];}return db['ZendeskField'][_0xd8aa('0x41')](_0x19edee);})[_0xd8aa('0x1f')](function(_0x1d8d59){_0xbe531['rows']=_0x1d8d59;return _0xbe531;})[_0xd8aa('0x1f')](respondWithFilteredResult(_0x26ab06,_0x19edee))[_0xd8aa('0x42')](handleError(_0x26ab06,null));};exports[_0xd8aa('0x43')]=function(_0x2fedbe,_0x3a0284){var _0x3bbb17={'raw':!![],'where':{'id':_0x2fedbe[_0xd8aa('0x44')]['id']}},_0x2b28f9={};_0x2b28f9[_0xd8aa('0x2b')]=_[_0xd8aa('0x2d')](db[_0xd8aa('0x27')][_0xd8aa('0x28')]);_0x2b28f9[_0xd8aa('0x2c')]=_[_0xd8aa('0x2d')](_0x2fedbe[_0xd8aa('0x2c')]);_0x2b28f9[_0xd8aa('0x2e')]=_[_0xd8aa('0x30')](_0x2b28f9[_0xd8aa('0x2b')],_0x2b28f9['query']);_0x3bbb17[_0xd8aa('0x2f')]=_[_0xd8aa('0x30')](_0x2b28f9[_0xd8aa('0x2b')],qs[_0xd8aa('0x31')](_0x2fedbe[_0xd8aa('0x2c')][_0xd8aa('0x31')]));_0x3bbb17['attributes']=_0x3bbb17[_0xd8aa('0x2f')]['length']?_0x3bbb17[_0xd8aa('0x2f')]:_0x2b28f9['model'];if(_0x2fedbe[_0xd8aa('0x2c')]['includeAll']){_0x3bbb17['include']=[{'all':!![]}];}_0x3bbb17=_[_0xd8aa('0x39')]({},_0x3bbb17,_0x2fedbe[_0xd8aa('0x3d')]);return db[_0xd8aa('0x27')][_0xd8aa('0x45')](_0x3bbb17)[_0xd8aa('0x1f')](handleEntityNotFound(_0x3a0284,null))[_0xd8aa('0x1f')](respondWithResult(_0x3a0284,null))['catch'](handleError(_0x3a0284,null));};exports[_0xd8aa('0x46')]=function(_0x473318,_0x22325c){return db[_0xd8aa('0x27')][_0xd8aa('0x46')](_0x473318['body'],{})['then'](respondWithResult(_0x22325c,0xc9))['catch'](handleError(_0x22325c,null));};exports[_0xd8aa('0x47')]=function(_0x2a24ae,_0x131012){if(_0x2a24ae[_0xd8aa('0x48')]['id']){delete _0x2a24ae[_0xd8aa('0x48')]['id'];}return db[_0xd8aa('0x27')]['find']({'where':{'id':_0x2a24ae[_0xd8aa('0x44')]['id']}})[_0xd8aa('0x1f')](handleEntityNotFound(_0x131012,null))['then'](saveUpdates(_0x2a24ae[_0xd8aa('0x48')],null))[_0xd8aa('0x1f')](respondWithResult(_0x131012,null))[_0xd8aa('0x42')](handleError(_0x131012,null));};exports['destroy']=function(_0xee55b3,_0x625df9){return db[_0xd8aa('0x27')][_0xd8aa('0x45')]({'where':{'id':_0xee55b3[_0xd8aa('0x44')]['id']}})[_0xd8aa('0x1f')](handleEntityNotFound(_0x625df9,null))['then'](removeEntity(_0x625df9,null))['catch'](handleError(_0x625df9,null));};