Built motion from commit da617fac.|2.6.6
[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 _0xbf2a=['moment','bluebird','mustache','util','sox','to-csv','lodash','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','status','end','offset','undefined','limit','count','Content-Range','json','apply','reject','save','update','then','destroy','stack','name','send','index','map','ZendeskField','rawAttributes','fieldName','type','keys','query','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','show','params','find','catch','create','body','eml-format','fast-json-patch','request-promise'];(function(_0x2d3d0d,_0x67ac82){var _0xca35b6=function(_0x483979){while(--_0x483979){_0x2d3d0d['push'](_0x2d3d0d['shift']());}};_0xca35b6(++_0x67ac82);}(_0xbf2a,0x165));var _0xabf2=function(_0xc905bf,_0x3fb45d){_0xc905bf=_0xc905bf-0x0;var _0x3ffd14=_0xbf2a[_0xc905bf];return _0x3ffd14;};'use strict';var emlformat=require(_0xabf2('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xabf2('0x1'));var rp=require(_0xabf2('0x2'));var moment=require(_0xabf2('0x3'));var BPromise=require(_0xabf2('0x4'));var Mustache=require(_0xabf2('0x5'));var util=require(_0xabf2('0x6'));var path=require('path');var sox=require(_0xabf2('0x7'));var csv=require(_0xabf2('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xabf2('0x9'));var squel=require('squel');var crypto=require(_0xabf2('0xa'));var jsforce=require(_0xabf2('0xb'));var deskjs=require(_0xabf2('0xc'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xabf2('0xd'));var Redis=require(_0xabf2('0xe'));var authService=require(_0xabf2('0xf'));var qs=require(_0xabf2('0x10'));var as=require(_0xabf2('0x11'));var hardwareService=require(_0xabf2('0x12'));var logger=require('../../config/logger')('api');var utils=require(_0xabf2('0x13'));var config=require(_0xabf2('0x14'));var licenseUtil=require(_0xabf2('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x63964a,_0x2e54d9){_0x2e54d9=_0x2e54d9||0xcc;return function(_0x8aa3d8){if(_0x8aa3d8){return _0x63964a['sendStatus'](_0x2e54d9);}return _0x63964a[_0xabf2('0x16')](_0x2e54d9)[_0xabf2('0x17')]();};}function respondWithResult(_0xea348e,_0x3b16f4){_0x3b16f4=_0x3b16f4||0xc8;return function(_0x4aa1c2){if(_0x4aa1c2){return _0xea348e[_0xabf2('0x16')](_0x3b16f4)['json'](_0x4aa1c2);}};}function respondWithFilteredResult(_0x425a36,_0x3fbff0){return function(_0x1b9f54){if(_0x1b9f54){var _0x11e650=typeof _0x3fbff0[_0xabf2('0x18')]===_0xabf2('0x19')&&typeof _0x3fbff0[_0xabf2('0x1a')]===_0xabf2('0x19');var _0x209dd3=_0x1b9f54[_0xabf2('0x1b')];var _0x30eeab=_0x11e650?0x0:_0x3fbff0[_0xabf2('0x18')];var _0x4933e8=_0x11e650?_0x1b9f54[_0xabf2('0x1b')]:_0x3fbff0[_0xabf2('0x18')]+_0x3fbff0[_0xabf2('0x1a')];var _0x3a89ab;if(_0x4933e8>=_0x209dd3){_0x4933e8=_0x209dd3;_0x3a89ab=0xc8;}else{_0x3a89ab=0xce;}_0x425a36[_0xabf2('0x16')](_0x3a89ab);return _0x425a36['set'](_0xabf2('0x1c'),_0x30eeab+'-'+_0x4933e8+'/'+_0x209dd3)[_0xabf2('0x1d')](_0x1b9f54);}return null;};}function patchUpdates(_0x533e1a){return function(_0x2eee0f){try{jsonpatch[_0xabf2('0x1e')](_0x2eee0f,_0x533e1a,!![]);}catch(_0xabb431){return BPromise[_0xabf2('0x1f')](_0xabb431);}return _0x2eee0f[_0xabf2('0x20')]();};}function saveUpdates(_0x12984a,_0x4f1012){return function(_0x212ad7){if(_0x212ad7){return _0x212ad7[_0xabf2('0x21')](_0x12984a)[_0xabf2('0x22')](function(_0x391099){return _0x391099;});}return null;};}function removeEntity(_0x2f7ffa,_0x252f3e){return function(_0x54a033){if(_0x54a033){return _0x54a033[_0xabf2('0x23')]()[_0xabf2('0x22')](function(){_0x2f7ffa[_0xabf2('0x16')](0xcc)['end']();});}};}function handleEntityNotFound(_0x309466,_0x2016e6){return function(_0x16994f){if(!_0x16994f){_0x309466['sendStatus'](0x194);}return _0x16994f;};}function handleError(_0x567c14,_0x25e173){_0x25e173=_0x25e173||0x1f4;return function(_0x4eed34){logger['error'](_0x4eed34[_0xabf2('0x24')]);if(_0x4eed34['name']){delete _0x4eed34[_0xabf2('0x25')];}_0x567c14[_0xabf2('0x16')](_0x25e173)[_0xabf2('0x26')](_0x4eed34);};}exports[_0xabf2('0x27')]=function(_0x345f92,_0x53fa8d){var _0x48ba8f={},_0x7dc999={},_0x2038bb={'count':0x0,'rows':[]};var _0x56bda7=_[_0xabf2('0x28')](db[_0xabf2('0x29')][_0xabf2('0x2a')],function(_0x40d577){return{'name':_0x40d577[_0xabf2('0x2b')],'type':_0x40d577[_0xabf2('0x2c')]['key']};});_0x7dc999['model']=_[_0xabf2('0x28')](_0x56bda7,_0xabf2('0x25'));_0x7dc999['query']=_[_0xabf2('0x2d')](_0x345f92[_0xabf2('0x2e')]);_0x7dc999['filters']=_[_0xabf2('0x2f')](_0x7dc999[_0xabf2('0x30')],_0x7dc999[_0xabf2('0x2e')]);_0x48ba8f[_0xabf2('0x31')]=_['intersection'](_0x7dc999[_0xabf2('0x30')],qs[_0xabf2('0x32')](_0x345f92[_0xabf2('0x2e')][_0xabf2('0x32')]));_0x48ba8f[_0xabf2('0x31')]=_0x48ba8f[_0xabf2('0x31')][_0xabf2('0x33')]?_0x48ba8f[_0xabf2('0x31')]:_0x7dc999[_0xabf2('0x30')];if(!_0x345f92[_0xabf2('0x2e')][_0xabf2('0x34')](_0xabf2('0x35'))){_0x48ba8f[_0xabf2('0x1a')]=qs[_0xabf2('0x1a')](_0x345f92[_0xabf2('0x2e')]['limit']);_0x48ba8f['offset']=qs[_0xabf2('0x18')](_0x345f92[_0xabf2('0x2e')][_0xabf2('0x18')]);}_0x48ba8f[_0xabf2('0x36')]=qs['sort'](_0x345f92[_0xabf2('0x2e')][_0xabf2('0x37')]);_0x48ba8f[_0xabf2('0x38')]=qs[_0xabf2('0x39')](_['pick'](_0x345f92[_0xabf2('0x2e')],_0x7dc999[_0xabf2('0x39')]),_0x56bda7);if(_0x345f92[_0xabf2('0x2e')][_0xabf2('0x3a')]){_0x48ba8f[_0xabf2('0x38')]=_[_0xabf2('0x3b')](_0x48ba8f[_0xabf2('0x38')],{'$or':_['map'](_0x56bda7,function(_0x210585){if(_0x210585[_0xabf2('0x2c')]!==_0xabf2('0x3c')){var _0x467b87={};_0x467b87[_0x210585[_0xabf2('0x25')]]={'$like':'%'+_0x345f92[_0xabf2('0x2e')][_0xabf2('0x3a')]+'%'};return _0x467b87;}})});}_0x48ba8f=_[_0xabf2('0x3b')]({},_0x48ba8f,_0x345f92[_0xabf2('0x3d')]);var _0x92c259={'where':_0x48ba8f[_0xabf2('0x38')]};return db[_0xabf2('0x29')][_0xabf2('0x1b')](_0x92c259)[_0xabf2('0x22')](function(_0x543e68){_0x2038bb[_0xabf2('0x1b')]=_0x543e68;if(_0x345f92['query'][_0xabf2('0x3e')]){_0x48ba8f[_0xabf2('0x3f')]=[{'all':!![]}];}return db['ZendeskField'][_0xabf2('0x40')](_0x48ba8f);})[_0xabf2('0x22')](function(_0x2e483f){_0x2038bb[_0xabf2('0x41')]=_0x2e483f;return _0x2038bb;})['then'](respondWithFilteredResult(_0x53fa8d,_0x48ba8f))['catch'](handleError(_0x53fa8d,null));};exports[_0xabf2('0x42')]=function(_0x32f226,_0x3c84ec){var _0x54b705={'raw':!![],'where':{'id':_0x32f226[_0xabf2('0x43')]['id']}},_0x30f92b={};_0x30f92b[_0xabf2('0x30')]=_['keys'](db[_0xabf2('0x29')][_0xabf2('0x2a')]);_0x30f92b[_0xabf2('0x2e')]=_['keys'](_0x32f226[_0xabf2('0x2e')]);_0x30f92b[_0xabf2('0x39')]=_['intersection'](_0x30f92b[_0xabf2('0x30')],_0x30f92b['query']);_0x54b705[_0xabf2('0x31')]=_[_0xabf2('0x2f')](_0x30f92b['model'],qs['fields'](_0x32f226[_0xabf2('0x2e')][_0xabf2('0x32')]));_0x54b705[_0xabf2('0x31')]=_0x54b705[_0xabf2('0x31')][_0xabf2('0x33')]?_0x54b705[_0xabf2('0x31')]:_0x30f92b[_0xabf2('0x30')];if(_0x32f226[_0xabf2('0x2e')]['includeAll']){_0x54b705['include']=[{'all':!![]}];}_0x54b705=_[_0xabf2('0x3b')]({},_0x54b705,_0x32f226[_0xabf2('0x3d')]);return db[_0xabf2('0x29')][_0xabf2('0x44')](_0x54b705)[_0xabf2('0x22')](handleEntityNotFound(_0x3c84ec,null))[_0xabf2('0x22')](respondWithResult(_0x3c84ec,null))[_0xabf2('0x45')](handleError(_0x3c84ec,null));};exports['create']=function(_0x46c3e5,_0x42978f){return db[_0xabf2('0x29')][_0xabf2('0x46')](_0x46c3e5['body'],{})['then'](respondWithResult(_0x42978f,0xc9))['catch'](handleError(_0x42978f,null));};exports['update']=function(_0x58a446,_0x5f2666){if(_0x58a446[_0xabf2('0x47')]['id']){delete _0x58a446[_0xabf2('0x47')]['id'];}return db['ZendeskField'][_0xabf2('0x44')]({'where':{'id':_0x58a446[_0xabf2('0x43')]['id']}})[_0xabf2('0x22')](handleEntityNotFound(_0x5f2666,null))['then'](saveUpdates(_0x58a446[_0xabf2('0x47')],null))[_0xabf2('0x22')](respondWithResult(_0x5f2666,null))[_0xabf2('0x45')](handleError(_0x5f2666,null));};exports[_0xabf2('0x23')]=function(_0x2f9a58,_0x288990){return db[_0xabf2('0x29')][_0xabf2('0x44')]({'where':{'id':_0x2f9a58[_0xabf2('0x43')]['id']}})[_0xabf2('0x22')](handleEntityNotFound(_0x288990,null))['then'](removeEntity(_0x288990,null))['catch'](handleError(_0x288990,null));};