b4e0ee5bd905e904fb95b28a5b19f7aba36dc609
[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 _0x730f=['moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','sendStatus','status','json','count','offset','set','Content-Range','apply','update','destroy','end','error','stack','name','send','index','map','Integration','rawAttributes','type','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','limit','order','sort','where','pick','filter','merge','options','then','includeAll','include','catch','params','length','find','body','html-pdf','eml-format','zip-dir','request-promise'];(function(_0x4f99a5,_0x2a6c5d){var _0x1fb6c2=function(_0x2e28d7){while(--_0x2e28d7){_0x4f99a5['push'](_0x4f99a5['shift']());}};_0x1fb6c2(++_0x2a6c5d);}(_0x730f,0xce));var _0xf730=function(_0x2244dd,_0x44633f){_0x2244dd=_0x2244dd-0x0;var _0x143a95=_0x730f[_0x2244dd];return _0x143a95;};'use strict';var pdf=require(_0xf730('0x0'));var emlformat=require(_0xf730('0x1'));var rimraf=require('rimraf');var zipdir=require(_0xf730('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf730('0x3'));var moment=require(_0xf730('0x4'));var BPromise=require(_0xf730('0x5'));var Mustache=require(_0xf730('0x6'));var util=require(_0xf730('0x7'));var path=require(_0xf730('0x8'));var sox=require(_0xf730('0x9'));var csv=require(_0xf730('0xa'));var ejs=require(_0xf730('0xb'));var fs=require('fs');var _=require(_0xf730('0xc'));var squel=require('squel');var crypto=require(_0xf730('0xd'));var jsforce=require(_0xf730('0xe'));var deskjs=require(_0xf730('0xf'));var toCsv=require(_0xf730('0xa'));var querystring=require(_0xf730('0x10'));var Papa=require(_0xf730('0x11'));var Redis=require('ioredis');var authService=require(_0xf730('0x12'));var qs=require(_0xf730('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf730('0x14'));var logger=require(_0xf730('0x15'))(_0xf730('0x16'));var utils=require('../../config/utils');var config=require(_0xf730('0x17'));var db=require(_0xf730('0x18'))['db'];function respondWithStatusCode(_0x47e33d,_0x43fd56){_0x43fd56=_0x43fd56||0xcc;return function(_0x19558e){if(_0x19558e){return _0x47e33d[_0xf730('0x19')](_0x43fd56);}return _0x47e33d['status'](_0x43fd56)['end']();};}function respondWithResult(_0x31c8cc,_0x4085bc){_0x4085bc=_0x4085bc||0xc8;return function(_0xde8c1c){if(_0xde8c1c){return _0x31c8cc[_0xf730('0x1a')](_0x4085bc)[_0xf730('0x1b')](_0xde8c1c);}};}function respondWithFilteredResult(_0x14ba66,_0x2bd9c7){return function(_0x2ff1bb){if(_0x2ff1bb){var _0x34a83d=_0x2ff1bb[_0xf730('0x1c')],_0x1f605b=_0x2bd9c7[_0xf730('0x1d')],_0x1f3a9c=_0x2bd9c7[_0xf730('0x1d')]+_0x2bd9c7['limit'],_0x1ee6de;if(_0x1f3a9c>=_0x34a83d){_0x1f3a9c=_0x34a83d;_0x1ee6de=0xc8;}else{_0x1ee6de=0xce;}_0x14ba66[_0xf730('0x1a')](_0x1ee6de);return _0x14ba66[_0xf730('0x1e')](_0xf730('0x1f'),_0x1f605b+'-'+_0x1f3a9c+'/'+_0x34a83d)[_0xf730('0x1b')](_0x2ff1bb);}return null;};}function patchUpdates(_0xd2b9d6){return function(_0x22d1e2){try{jsonpatch[_0xf730('0x20')](_0x22d1e2,_0xd2b9d6,!![]);}catch(_0x8c4030){return BPromise['reject'](_0x8c4030);}return _0x22d1e2['save']();};}function saveUpdates(_0xe50901,_0x4beb9a){return function(_0xf2c5a){if(_0xf2c5a){return _0xf2c5a[_0xf730('0x21')](_0xe50901)['then'](function(_0x53486a){return _0x53486a;});}return null;};}function removeEntity(_0x5572fc,_0x329334){return function(_0x50beb6){if(_0x50beb6){return _0x50beb6[_0xf730('0x22')]()['then'](function(){_0x5572fc['status'](0xcc)[_0xf730('0x23')]();});}};}function handleEntityNotFound(_0x5bf59c,_0x12940e){return function(_0x53965f){if(!_0x53965f){_0x5bf59c[_0xf730('0x19')](0x194);}return _0x53965f;};}function handleError(_0x23bdd2,_0x5d1d87){_0x5d1d87=_0x5d1d87||0x1f4;return function(_0x1d3f3a){logger[_0xf730('0x24')](_0x1d3f3a[_0xf730('0x25')]);if(_0x1d3f3a[_0xf730('0x26')]){delete _0x1d3f3a[_0xf730('0x26')];}_0x23bdd2[_0xf730('0x1a')](_0x5d1d87)[_0xf730('0x27')](_0x1d3f3a);};}exports[_0xf730('0x28')]=function(_0x344ed4,_0x2f5f89){var _0x29d09a={},_0x51e208={},_0x1a3083={'count':0x0,'rows':[]};var _0x4c88bd=_[_0xf730('0x29')](db[_0xf730('0x2a')][_0xf730('0x2b')],function(_0x46bdc7){return{'name':_0x46bdc7['fieldName'],'type':_0x46bdc7[_0xf730('0x2c')]['key']};});_0x51e208[_0xf730('0x2d')]=_[_0xf730('0x29')](_0x4c88bd,_0xf730('0x26'));_0x51e208[_0xf730('0x2e')]=_[_0xf730('0x2f')](_0x344ed4['query']);_0x51e208[_0xf730('0x30')]=_[_0xf730('0x31')](_0x51e208[_0xf730('0x2d')],_0x51e208[_0xf730('0x2e')]);_0x29d09a[_0xf730('0x32')]=_[_0xf730('0x31')](_0x51e208[_0xf730('0x2d')],qs[_0xf730('0x33')](_0x344ed4['query'][_0xf730('0x33')]));_0x29d09a[_0xf730('0x32')]=_0x29d09a[_0xf730('0x32')]['length']?_0x29d09a['attributes']:_0x51e208['model'];if(!_0x344ed4['query'][_0xf730('0x34')](_0xf730('0x35'))){_0x29d09a['limit']=qs[_0xf730('0x36')](_0x344ed4[_0xf730('0x2e')][_0xf730('0x36')]);_0x29d09a[_0xf730('0x1d')]=qs['offset'](_0x344ed4['query']['offset']);}_0x29d09a[_0xf730('0x37')]=qs['sort'](_0x344ed4[_0xf730('0x2e')][_0xf730('0x38')]);_0x29d09a[_0xf730('0x39')]=qs[_0xf730('0x30')](_[_0xf730('0x3a')](_0x344ed4['query'],_0x51e208[_0xf730('0x30')]),_0x4c88bd);if(_0x344ed4[_0xf730('0x2e')]['filter']){_0x29d09a[_0xf730('0x39')]=_['merge'](_0x29d09a[_0xf730('0x39')],{'$or':_[_0xf730('0x29')](_0x4c88bd,function(_0x24e59){if(_0x24e59['type']!=='VIRTUAL'){var _0x371b62={};_0x371b62[_0x24e59['name']]={'$like':'%'+_0x344ed4[_0xf730('0x2e')][_0xf730('0x3b')]+'%'};return _0x371b62;}})});}_0x29d09a=_[_0xf730('0x3c')]({},_0x29d09a,_0x344ed4[_0xf730('0x3d')]);var _0x591b55={'where':_0x29d09a[_0xf730('0x39')]};return db[_0xf730('0x2a')][_0xf730('0x1c')](_0x591b55)[_0xf730('0x3e')](function(_0x1c83ad){_0x1a3083[_0xf730('0x1c')]=_0x1c83ad;if(_0x344ed4[_0xf730('0x2e')][_0xf730('0x3f')]){_0x29d09a[_0xf730('0x40')]=[{'all':!![]}];}return db['Integration']['findAll'](_0x29d09a);})[_0xf730('0x3e')](function(_0x14cbd3){_0x1a3083['rows']=_0x14cbd3;return _0x1a3083;})[_0xf730('0x3e')](respondWithFilteredResult(_0x2f5f89,_0x29d09a))[_0xf730('0x41')](handleError(_0x2f5f89,null));};exports['show']=function(_0x2fd172,_0x577f38){var _0x22f42a={'raw':![],'where':{'id':_0x2fd172[_0xf730('0x42')]['id']}},_0x222a2e={};_0x222a2e[_0xf730('0x2d')]=_[_0xf730('0x2f')](db[_0xf730('0x2a')][_0xf730('0x2b')]);_0x222a2e[_0xf730('0x2e')]=_[_0xf730('0x2f')](_0x2fd172['query']);_0x222a2e[_0xf730('0x30')]=_['intersection'](_0x222a2e[_0xf730('0x2d')],_0x222a2e['query']);_0x22f42a['attributes']=_[_0xf730('0x31')](_0x222a2e[_0xf730('0x2d')],qs[_0xf730('0x33')](_0x2fd172[_0xf730('0x2e')][_0xf730('0x33')]));_0x22f42a[_0xf730('0x32')]=_0x22f42a['attributes'][_0xf730('0x43')]?_0x22f42a[_0xf730('0x32')]:_0x222a2e[_0xf730('0x2d')];if(_0x2fd172[_0xf730('0x2e')]['includeAll']){_0x22f42a[_0xf730('0x40')]=[{'all':!![]}];}_0x22f42a=_[_0xf730('0x3c')]({},_0x22f42a,_0x2fd172['options']);return db[_0xf730('0x2a')][_0xf730('0x44')](_0x22f42a)[_0xf730('0x3e')](handleEntityNotFound(_0x577f38,null))[_0xf730('0x3e')](respondWithResult(_0x577f38,null))[_0xf730('0x41')](handleError(_0x577f38,null));};exports['create']=function(_0x21c715,_0x4e4608){return db[_0xf730('0x2a')]['create'](_0x21c715[_0xf730('0x45')],{})[_0xf730('0x3e')](respondWithResult(_0x4e4608,0xc9))[_0xf730('0x41')](handleError(_0x4e4608,null));};exports[_0xf730('0x21')]=function(_0x32fb1a,_0x1c3581){if(_0x32fb1a[_0xf730('0x45')]['id']){delete _0x32fb1a[_0xf730('0x45')]['id'];}return db[_0xf730('0x2a')][_0xf730('0x44')]({'where':{'id':_0x32fb1a[_0xf730('0x42')]['id']}})[_0xf730('0x3e')](handleEntityNotFound(_0x1c3581,null))[_0xf730('0x3e')](saveUpdates(_0x32fb1a[_0xf730('0x45')],null))['then'](respondWithResult(_0x1c3581,null))[_0xf730('0x41')](handleError(_0x1c3581,null));};exports['destroy']=function(_0x13556e,_0x28bbeb){return db[_0xf730('0x2a')][_0xf730('0x44')]({'where':{'id':_0x13556e[_0xf730('0x42')]['id']}})[_0xf730('0x3e')](handleEntityNotFound(_0x28bbeb,null))[_0xf730('0x3e')](removeEntity(_0x28bbeb,null))['catch'](handleError(_0x28bbeb,null));};