Built motion from commit (unavailable).|2.5.31
[motion2.git] / server / api / integration / integration.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 _0xc257=['Content-Range','apply','reject','save','update','destroy','stack','name','send','map','rawAttributes','fieldName','type','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','options','Integration','then','includeAll','include','findAll','rows','show','find','create','body','catch','params','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','sox','ejs','fs-extra','squel','crypto','jsforce','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','limit','undefined','count','offset'];(function(_0x4b055c,_0x4b870b){var _0x4b62bb=function(_0x4884c2){while(--_0x4884c2){_0x4b055c['push'](_0x4b055c['shift']());}};_0x4b62bb(++_0x4b870b);}(_0xc257,0x146));var _0x7c25=function(_0x6131cd,_0x4c26a1){_0x6131cd=_0x6131cd-0x0;var _0x47e916=_0xc257[_0x6131cd];return _0x47e916;};'use strict';var emlformat=require(_0x7c25('0x0'));var rimraf=require(_0x7c25('0x1'));var zipdir=require(_0x7c25('0x2'));var jsonpatch=require(_0x7c25('0x3'));var rp=require(_0x7c25('0x4'));var moment=require(_0x7c25('0x5'));var BPromise=require(_0x7c25('0x6'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0x7c25('0x7'));var csv=require('to-csv');var ejs=require(_0x7c25('0x8'));var fs=require('fs');var fs_extra=require(_0x7c25('0x9'));var _=require('lodash');var squel=require(_0x7c25('0xa'));var crypto=require(_0x7c25('0xb'));var jsforce=require(_0x7c25('0xc'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x7c25('0xd'));var Redis=require(_0x7c25('0xe'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x7c25('0xf'));var hardwareService=require(_0x7c25('0x10'));var logger=require('../../config/logger')(_0x7c25('0x11'));var utils=require('../../config/utils');var config=require(_0x7c25('0x12'));var licenseUtil=require(_0x7c25('0x13'));var db=require(_0x7c25('0x14'))['db'];function respondWithStatusCode(_0x270fc4,_0xb355d4){_0xb355d4=_0xb355d4||0xcc;return function(_0x53800b){if(_0x53800b){return _0x270fc4[_0x7c25('0x15')](_0xb355d4);}return _0x270fc4[_0x7c25('0x16')](_0xb355d4)[_0x7c25('0x17')]();};}function respondWithResult(_0x1c2de7,_0x180cb9){_0x180cb9=_0x180cb9||0xc8;return function(_0x28df09){if(_0x28df09){return _0x1c2de7[_0x7c25('0x16')](_0x180cb9)[_0x7c25('0x18')](_0x28df09);}};}function respondWithFilteredResult(_0x447ba0,_0xade3fb){return function(_0x403eea){if(_0x403eea){var _0x3d4c94=typeof _0xade3fb['offset']==='undefined'&&typeof _0xade3fb[_0x7c25('0x19')]===_0x7c25('0x1a');var _0x1034b4=_0x403eea[_0x7c25('0x1b')];var _0x4859e7=_0x3d4c94?0x0:_0xade3fb[_0x7c25('0x1c')];var _0xeb6c56=_0x3d4c94?_0x403eea[_0x7c25('0x1b')]:_0xade3fb[_0x7c25('0x1c')]+_0xade3fb[_0x7c25('0x19')];var _0x1421fc;if(_0xeb6c56>=_0x1034b4){_0xeb6c56=_0x1034b4;_0x1421fc=0xc8;}else{_0x1421fc=0xce;}_0x447ba0[_0x7c25('0x16')](_0x1421fc);return _0x447ba0['set'](_0x7c25('0x1d'),_0x4859e7+'-'+_0xeb6c56+'/'+_0x1034b4)['json'](_0x403eea);}return null;};}function patchUpdates(_0xa848e0){return function(_0x3a33dd){try{jsonpatch[_0x7c25('0x1e')](_0x3a33dd,_0xa848e0,!![]);}catch(_0x16f0ea){return BPromise[_0x7c25('0x1f')](_0x16f0ea);}return _0x3a33dd[_0x7c25('0x20')]();};}function saveUpdates(_0x58047f,_0x30e7fa){return function(_0x80ffdf){if(_0x80ffdf){return _0x80ffdf[_0x7c25('0x21')](_0x58047f)['then'](function(_0xb49d2c){return _0xb49d2c;});}return null;};}function removeEntity(_0xaee1fc,_0x3f92e2){return function(_0x387a88){if(_0x387a88){return _0x387a88[_0x7c25('0x22')]()['then'](function(){_0xaee1fc[_0x7c25('0x16')](0xcc)[_0x7c25('0x17')]();});}};}function handleEntityNotFound(_0xabcfe7,_0x12a83b){return function(_0x148414){if(!_0x148414){_0xabcfe7[_0x7c25('0x15')](0x194);}return _0x148414;};}function handleError(_0x597ad5,_0x1c727f){_0x1c727f=_0x1c727f||0x1f4;return function(_0x1e5e36){logger['error'](_0x1e5e36[_0x7c25('0x23')]);if(_0x1e5e36[_0x7c25('0x24')]){delete _0x1e5e36['name'];}_0x597ad5[_0x7c25('0x16')](_0x1c727f)[_0x7c25('0x25')](_0x1e5e36);};}exports['index']=function(_0x530feb,_0x257cc4){var _0x12bcf9={},_0x6fe3b9={},_0x209fb8={'count':0x0,'rows':[]};var _0x41a9cd=_[_0x7c25('0x26')](db['Integration'][_0x7c25('0x27')],function(_0x8514a5){return{'name':_0x8514a5[_0x7c25('0x28')],'type':_0x8514a5[_0x7c25('0x29')]['key']};});_0x6fe3b9['model']=_[_0x7c25('0x26')](_0x41a9cd,_0x7c25('0x24'));_0x6fe3b9[_0x7c25('0x2a')]=_[_0x7c25('0x2b')](_0x530feb['query']);_0x6fe3b9[_0x7c25('0x2c')]=_[_0x7c25('0x2d')](_0x6fe3b9[_0x7c25('0x2e')],_0x6fe3b9[_0x7c25('0x2a')]);_0x12bcf9[_0x7c25('0x2f')]=_[_0x7c25('0x2d')](_0x6fe3b9[_0x7c25('0x2e')],qs[_0x7c25('0x30')](_0x530feb[_0x7c25('0x2a')][_0x7c25('0x30')]));_0x12bcf9['attributes']=_0x12bcf9['attributes'][_0x7c25('0x31')]?_0x12bcf9[_0x7c25('0x2f')]:_0x6fe3b9['model'];if(!_0x530feb['query'][_0x7c25('0x32')](_0x7c25('0x33'))){_0x12bcf9[_0x7c25('0x19')]=qs[_0x7c25('0x19')](_0x530feb[_0x7c25('0x2a')][_0x7c25('0x19')]);_0x12bcf9[_0x7c25('0x1c')]=qs[_0x7c25('0x1c')](_0x530feb[_0x7c25('0x2a')]['offset']);}_0x12bcf9[_0x7c25('0x34')]=qs[_0x7c25('0x35')](_0x530feb['query'][_0x7c25('0x35')]);_0x12bcf9[_0x7c25('0x36')]=qs[_0x7c25('0x2c')](_[_0x7c25('0x37')](_0x530feb[_0x7c25('0x2a')],_0x6fe3b9[_0x7c25('0x2c')]),_0x41a9cd);if(_0x530feb['query'][_0x7c25('0x38')]){_0x12bcf9['where']=_[_0x7c25('0x39')](_0x12bcf9[_0x7c25('0x36')],{'$or':_[_0x7c25('0x26')](_0x41a9cd,function(_0x40c471){if(_0x40c471[_0x7c25('0x29')]!=='VIRTUAL'){var _0x3731f8={};_0x3731f8[_0x40c471[_0x7c25('0x24')]]={'$like':'%'+_0x530feb[_0x7c25('0x2a')][_0x7c25('0x38')]+'%'};return _0x3731f8;}})});}_0x12bcf9=_[_0x7c25('0x39')]({},_0x12bcf9,_0x530feb[_0x7c25('0x3a')]);var _0x43e55c={'where':_0x12bcf9['where']};return db[_0x7c25('0x3b')][_0x7c25('0x1b')](_0x43e55c)[_0x7c25('0x3c')](function(_0x2a4104){_0x209fb8[_0x7c25('0x1b')]=_0x2a4104;if(_0x530feb[_0x7c25('0x2a')][_0x7c25('0x3d')]){_0x12bcf9[_0x7c25('0x3e')]=[{'all':!![]}];}return db[_0x7c25('0x3b')][_0x7c25('0x3f')](_0x12bcf9);})[_0x7c25('0x3c')](function(_0x4db4f3){_0x209fb8[_0x7c25('0x40')]=_0x4db4f3;return _0x209fb8;})[_0x7c25('0x3c')](respondWithFilteredResult(_0x257cc4,_0x12bcf9))['catch'](handleError(_0x257cc4,null));};exports[_0x7c25('0x41')]=function(_0x4c73d4,_0x504c4d){var _0x1a5223={'raw':![],'where':{'id':_0x4c73d4['params']['id']}},_0x3d17b7={};_0x3d17b7[_0x7c25('0x2e')]=_[_0x7c25('0x2b')](db[_0x7c25('0x3b')]['rawAttributes']);_0x3d17b7[_0x7c25('0x2a')]=_[_0x7c25('0x2b')](_0x4c73d4['query']);_0x3d17b7['filters']=_['intersection'](_0x3d17b7[_0x7c25('0x2e')],_0x3d17b7['query']);_0x1a5223['attributes']=_[_0x7c25('0x2d')](_0x3d17b7[_0x7c25('0x2e')],qs[_0x7c25('0x30')](_0x4c73d4[_0x7c25('0x2a')][_0x7c25('0x30')]));_0x1a5223[_0x7c25('0x2f')]=_0x1a5223[_0x7c25('0x2f')][_0x7c25('0x31')]?_0x1a5223[_0x7c25('0x2f')]:_0x3d17b7['model'];if(_0x4c73d4[_0x7c25('0x2a')][_0x7c25('0x3d')]){_0x1a5223['include']=[{'all':!![]}];}_0x1a5223=_[_0x7c25('0x39')]({},_0x1a5223,_0x4c73d4['options']);return db[_0x7c25('0x3b')][_0x7c25('0x42')](_0x1a5223)[_0x7c25('0x3c')](handleEntityNotFound(_0x504c4d,null))[_0x7c25('0x3c')](respondWithResult(_0x504c4d,null))['catch'](handleError(_0x504c4d,null));};exports['create']=function(_0x2b0dc9,_0x15ce2d){return db[_0x7c25('0x3b')][_0x7c25('0x43')](_0x2b0dc9[_0x7c25('0x44')],{})[_0x7c25('0x3c')](respondWithResult(_0x15ce2d,0xc9))[_0x7c25('0x45')](handleError(_0x15ce2d,null));};exports[_0x7c25('0x21')]=function(_0x3f26a1,_0x188dc1){if(_0x3f26a1[_0x7c25('0x44')]['id']){delete _0x3f26a1[_0x7c25('0x44')]['id'];}return db[_0x7c25('0x3b')][_0x7c25('0x42')]({'where':{'id':_0x3f26a1[_0x7c25('0x46')]['id']}})[_0x7c25('0x3c')](handleEntityNotFound(_0x188dc1,null))[_0x7c25('0x3c')](saveUpdates(_0x3f26a1['body'],null))['then'](respondWithResult(_0x188dc1,null))['catch'](handleError(_0x188dc1,null));};exports[_0x7c25('0x22')]=function(_0x5ed750,_0x532023){return db[_0x7c25('0x3b')]['find']({'where':{'id':_0x5ed750[_0x7c25('0x46')]['id']}})[_0x7c25('0x3c')](handleEntityNotFound(_0x532023,null))[_0x7c25('0x3c')](removeEntity(_0x532023,null))[_0x7c25('0x45')](handleError(_0x532023,null));};