Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / api / intFreshdeskField / intFreshdeskField.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 _0xf4eb=['query','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','filters','pick','filter','VIRTUAL','merge','includeAll','include','findAll','rows','show','params','options','find','create','body','catch','update','eml-format','moment','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/environment','../../config/license/util','sendStatus','status','end','offset','undefined','limit','count','Content-Range','json','apply','reject','save','then','destroy','error','name','send','map','FreshdeskField','rawAttributes','fieldName','type','key','model','keys'];(function(_0x46f7f0,_0x220b57){var _0x24f190=function(_0x1f64e8){while(--_0x1f64e8){_0x46f7f0['push'](_0x46f7f0['shift']());}};_0x24f190(++_0x220b57);}(_0xf4eb,0xec));var _0xbf4e=function(_0x45605f,_0x45e5f1){_0x45605f=_0x45605f-0x0;var _0x4d4b22=_0xf4eb[_0x45605f];return _0x4d4b22;};'use strict';var emlformat=require(_0xbf4e('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xbf4e('0x1'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xbf4e('0x2'));var path=require(_0xbf4e('0x3'));var sox=require(_0xbf4e('0x4'));var csv=require(_0xbf4e('0x5'));var ejs=require(_0xbf4e('0x6'));var fs=require('fs');var fs_extra=require(_0xbf4e('0x7'));var _=require(_0xbf4e('0x8'));var squel=require('squel');var crypto=require(_0xbf4e('0x9'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xbf4e('0x5'));var querystring=require(_0xbf4e('0xa'));var Papa=require(_0xbf4e('0xb'));var Redis=require(_0xbf4e('0xc'));var authService=require(_0xbf4e('0xd'));var qs=require(_0xbf4e('0xe'));var as=require(_0xbf4e('0xf'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xbf4e('0x10'));var utils=require('../../config/utils');var config=require(_0xbf4e('0x11'));var licenseUtil=require(_0xbf4e('0x12'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x17fd01,_0x5a3035){_0x5a3035=_0x5a3035||0xcc;return function(_0x56d185){if(_0x56d185){return _0x17fd01[_0xbf4e('0x13')](_0x5a3035);}return _0x17fd01[_0xbf4e('0x14')](_0x5a3035)[_0xbf4e('0x15')]();};}function respondWithResult(_0x302841,_0x3b74bd){_0x3b74bd=_0x3b74bd||0xc8;return function(_0x61bd54){if(_0x61bd54){return _0x302841['status'](_0x3b74bd)['json'](_0x61bd54);}};}function respondWithFilteredResult(_0x180432,_0x1735ae){return function(_0x28fc6b){if(_0x28fc6b){var _0x542909=typeof _0x1735ae[_0xbf4e('0x16')]===_0xbf4e('0x17')&&typeof _0x1735ae[_0xbf4e('0x18')]===_0xbf4e('0x17');var _0x5a631e=_0x28fc6b[_0xbf4e('0x19')];var _0x577c27=_0x542909?0x0:_0x1735ae['offset'];var _0x566ec3=_0x542909?_0x28fc6b['count']:_0x1735ae[_0xbf4e('0x16')]+_0x1735ae[_0xbf4e('0x18')];var _0x1fc800;if(_0x566ec3>=_0x5a631e){_0x566ec3=_0x5a631e;_0x1fc800=0xc8;}else{_0x1fc800=0xce;}_0x180432['status'](_0x1fc800);return _0x180432['set'](_0xbf4e('0x1a'),_0x577c27+'-'+_0x566ec3+'/'+_0x5a631e)[_0xbf4e('0x1b')](_0x28fc6b);}return null;};}function patchUpdates(_0x3be138){return function(_0x3a875b){try{jsonpatch[_0xbf4e('0x1c')](_0x3a875b,_0x3be138,!![]);}catch(_0x1e2a68){return BPromise[_0xbf4e('0x1d')](_0x1e2a68);}return _0x3a875b[_0xbf4e('0x1e')]();};}function saveUpdates(_0xd09e12,_0x376832){return function(_0x30539b){if(_0x30539b){return _0x30539b['update'](_0xd09e12)[_0xbf4e('0x1f')](function(_0x2e7673){return _0x2e7673;});}return null;};}function removeEntity(_0x51648c,_0x31e3f5){return function(_0x30994d){if(_0x30994d){return _0x30994d[_0xbf4e('0x20')]()[_0xbf4e('0x1f')](function(){_0x51648c[_0xbf4e('0x14')](0xcc)['end']();});}};}function handleEntityNotFound(_0x90635e,_0x36688a){return function(_0x3d6863){if(!_0x3d6863){_0x90635e['sendStatus'](0x194);}return _0x3d6863;};}function handleError(_0x2fb490,_0x5e08b1){_0x5e08b1=_0x5e08b1||0x1f4;return function(_0x5bcf71){logger[_0xbf4e('0x21')](_0x5bcf71['stack']);if(_0x5bcf71[_0xbf4e('0x22')]){delete _0x5bcf71[_0xbf4e('0x22')];}_0x2fb490[_0xbf4e('0x14')](_0x5e08b1)[_0xbf4e('0x23')](_0x5bcf71);};}exports['index']=function(_0x2d4686,_0x8e0ab5){var _0x43879d={},_0x4cd4a1={},_0x681c3b={'count':0x0,'rows':[]};var _0x590c85=_[_0xbf4e('0x24')](db[_0xbf4e('0x25')][_0xbf4e('0x26')],function(_0x498dbd){return{'name':_0x498dbd[_0xbf4e('0x27')],'type':_0x498dbd[_0xbf4e('0x28')][_0xbf4e('0x29')]};});_0x4cd4a1[_0xbf4e('0x2a')]=_[_0xbf4e('0x24')](_0x590c85,_0xbf4e('0x22'));_0x4cd4a1['query']=_[_0xbf4e('0x2b')](_0x2d4686[_0xbf4e('0x2c')]);_0x4cd4a1['filters']=_[_0xbf4e('0x2d')](_0x4cd4a1[_0xbf4e('0x2a')],_0x4cd4a1['query']);_0x43879d[_0xbf4e('0x2e')]=_['intersection'](_0x4cd4a1[_0xbf4e('0x2a')],qs['fields'](_0x2d4686[_0xbf4e('0x2c')][_0xbf4e('0x2f')]));_0x43879d[_0xbf4e('0x2e')]=_0x43879d['attributes'][_0xbf4e('0x30')]?_0x43879d[_0xbf4e('0x2e')]:_0x4cd4a1[_0xbf4e('0x2a')];if(!_0x2d4686[_0xbf4e('0x2c')][_0xbf4e('0x31')](_0xbf4e('0x32'))){_0x43879d['limit']=qs[_0xbf4e('0x18')](_0x2d4686[_0xbf4e('0x2c')][_0xbf4e('0x18')]);_0x43879d[_0xbf4e('0x16')]=qs[_0xbf4e('0x16')](_0x2d4686['query']['offset']);}_0x43879d['order']=qs['sort'](_0x2d4686[_0xbf4e('0x2c')][_0xbf4e('0x33')]);_0x43879d[_0xbf4e('0x34')]=qs[_0xbf4e('0x35')](_[_0xbf4e('0x36')](_0x2d4686[_0xbf4e('0x2c')],_0x4cd4a1[_0xbf4e('0x35')]),_0x590c85);if(_0x2d4686[_0xbf4e('0x2c')][_0xbf4e('0x37')]){_0x43879d['where']=_['merge'](_0x43879d[_0xbf4e('0x34')],{'$or':_[_0xbf4e('0x24')](_0x590c85,function(_0x2cf1b0){if(_0x2cf1b0['type']!==_0xbf4e('0x38')){var _0x4e72a2={};_0x4e72a2[_0x2cf1b0[_0xbf4e('0x22')]]={'$like':'%'+_0x2d4686[_0xbf4e('0x2c')][_0xbf4e('0x37')]+'%'};return _0x4e72a2;}})});}_0x43879d=_[_0xbf4e('0x39')]({},_0x43879d,_0x2d4686['options']);var _0x31d8dc={'where':_0x43879d[_0xbf4e('0x34')]};return db[_0xbf4e('0x25')][_0xbf4e('0x19')](_0x31d8dc)['then'](function(_0x3d08d5){_0x681c3b[_0xbf4e('0x19')]=_0x3d08d5;if(_0x2d4686[_0xbf4e('0x2c')][_0xbf4e('0x3a')]){_0x43879d[_0xbf4e('0x3b')]=[{'all':!![]}];}return db[_0xbf4e('0x25')][_0xbf4e('0x3c')](_0x43879d);})['then'](function(_0x176166){_0x681c3b[_0xbf4e('0x3d')]=_0x176166;return _0x681c3b;})['then'](respondWithFilteredResult(_0x8e0ab5,_0x43879d))['catch'](handleError(_0x8e0ab5,null));};exports[_0xbf4e('0x3e')]=function(_0x35bd69,_0x495e53){var _0x5bfc4d={'raw':!![],'where':{'id':_0x35bd69[_0xbf4e('0x3f')]['id']}},_0x2b1bf4={};_0x2b1bf4[_0xbf4e('0x2a')]=_[_0xbf4e('0x2b')](db[_0xbf4e('0x25')][_0xbf4e('0x26')]);_0x2b1bf4['query']=_[_0xbf4e('0x2b')](_0x35bd69[_0xbf4e('0x2c')]);_0x2b1bf4['filters']=_['intersection'](_0x2b1bf4['model'],_0x2b1bf4['query']);_0x5bfc4d[_0xbf4e('0x2e')]=_['intersection'](_0x2b1bf4[_0xbf4e('0x2a')],qs[_0xbf4e('0x2f')](_0x35bd69['query']['fields']));_0x5bfc4d[_0xbf4e('0x2e')]=_0x5bfc4d[_0xbf4e('0x2e')][_0xbf4e('0x30')]?_0x5bfc4d[_0xbf4e('0x2e')]:_0x2b1bf4[_0xbf4e('0x2a')];if(_0x35bd69['query'][_0xbf4e('0x3a')]){_0x5bfc4d[_0xbf4e('0x3b')]=[{'all':!![]}];}_0x5bfc4d=_[_0xbf4e('0x39')]({},_0x5bfc4d,_0x35bd69[_0xbf4e('0x40')]);return db[_0xbf4e('0x25')][_0xbf4e('0x41')](_0x5bfc4d)[_0xbf4e('0x1f')](handleEntityNotFound(_0x495e53,null))[_0xbf4e('0x1f')](respondWithResult(_0x495e53,null))['catch'](handleError(_0x495e53,null));};exports[_0xbf4e('0x42')]=function(_0xb55a98,_0x1833c1){return db[_0xbf4e('0x25')][_0xbf4e('0x42')](_0xb55a98[_0xbf4e('0x43')],{})[_0xbf4e('0x1f')](respondWithResult(_0x1833c1,0xc9))[_0xbf4e('0x44')](handleError(_0x1833c1,null));};exports[_0xbf4e('0x45')]=function(_0x3447ab,_0x2fdba9){if(_0x3447ab[_0xbf4e('0x43')]['id']){delete _0x3447ab[_0xbf4e('0x43')]['id'];}return db[_0xbf4e('0x25')][_0xbf4e('0x41')]({'where':{'id':_0x3447ab[_0xbf4e('0x3f')]['id']}})[_0xbf4e('0x1f')](handleEntityNotFound(_0x2fdba9,null))['then'](saveUpdates(_0x3447ab[_0xbf4e('0x43')],null))[_0xbf4e('0x1f')](respondWithResult(_0x2fdba9,null))[_0xbf4e('0x44')](handleError(_0x2fdba9,null));};exports['destroy']=function(_0x33ab9a,_0x5ed838){return db['FreshdeskField'][_0xbf4e('0x41')]({'where':{'id':_0x33ab9a[_0xbf4e('0x3f')]['id']}})['then'](handleEntityNotFound(_0x5ed838,null))[_0xbf4e('0x1f')](removeEntity(_0x5ed838,null))[_0xbf4e('0x44')](handleError(_0x5ed838,null));};