Built motion from commit (unavailable).|2.5.21
[motion2.git] / server / api / cloudProvider / cloudProvider.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 _0x93f3=['bluebird','mustache','sox','to-csv','lodash','squel','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','save','then','destroy','stack','name','send','index','map','rawAttributes','fieldName','key','model','keys','query','intersection','fields','length','attributes','nolimit','sort','where','filters','pick','filter','merge','type','VIRTUAL','includeAll','include','CloudProvider','findAll','rows','show','params','options','find','catch','create','body','update','request-promise','moment'];(function(_0x5a0d34,_0x4f77e5){var _0x29d5e1=function(_0x53a7ff){while(--_0x53a7ff){_0x5a0d34['push'](_0x5a0d34['shift']());}};_0x29d5e1(++_0x4f77e5);}(_0x93f3,0x112));var _0x393f=function(_0x51b119,_0xbf8af0){_0x51b119=_0x51b119-0x0;var _0x59a293=_0x93f3[_0x51b119];return _0x59a293;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x393f('0x0'));var moment=require(_0x393f('0x1'));var BPromise=require(_0x393f('0x2'));var Mustache=require(_0x393f('0x3'));var util=require('util');var path=require('path');var sox=require(_0x393f('0x4'));var csv=require(_0x393f('0x5'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x393f('0x6'));var squel=require(_0x393f('0x7'));var crypto=require(_0x393f('0x8'));var jsforce=require(_0x393f('0x9'));var deskjs=require(_0x393f('0xa'));var toCsv=require(_0x393f('0x5'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x393f('0xb'));var authService=require(_0x393f('0xc'));var qs=require(_0x393f('0xd'));var as=require(_0x393f('0xe'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x393f('0xf'));var utils=require(_0x393f('0x10'));var config=require(_0x393f('0x11'));var licenseUtil=require('../../config/license/util');var db=require(_0x393f('0x12'))['db'];function respondWithStatusCode(_0x50cab9,_0x2ebc53){_0x2ebc53=_0x2ebc53||0xcc;return function(_0x4178d1){if(_0x4178d1){return _0x50cab9[_0x393f('0x13')](_0x2ebc53);}return _0x50cab9[_0x393f('0x14')](_0x2ebc53)[_0x393f('0x15')]();};}function respondWithResult(_0xbee9ad,_0x23de92){_0x23de92=_0x23de92||0xc8;return function(_0x196d50){if(_0x196d50){return _0xbee9ad[_0x393f('0x14')](_0x23de92)[_0x393f('0x16')](_0x196d50);}};}function respondWithFilteredResult(_0x4fb355,_0x17b929){return function(_0x4006f3){if(_0x4006f3){var _0x2d70ed=_0x4006f3[_0x393f('0x17')],_0x2d9498=_0x17b929['offset'],_0x37aef8=_0x17b929[_0x393f('0x18')]+_0x17b929[_0x393f('0x19')],_0x1dac3b;if(_0x37aef8>=_0x2d70ed){_0x37aef8=_0x2d70ed;_0x1dac3b=0xc8;}else{_0x1dac3b=0xce;}_0x4fb355[_0x393f('0x14')](_0x1dac3b);return _0x4fb355[_0x393f('0x1a')](_0x393f('0x1b'),_0x2d9498+'-'+_0x37aef8+'/'+_0x2d70ed)[_0x393f('0x16')](_0x4006f3);}return null;};}function patchUpdates(_0x4bd661){return function(_0xc86a59){try{jsonpatch[_0x393f('0x1c')](_0xc86a59,_0x4bd661,!![]);}catch(_0x369f4c){return BPromise['reject'](_0x369f4c);}return _0xc86a59[_0x393f('0x1d')]();};}function saveUpdates(_0x4815a3,_0x4e3031){return function(_0x5e25d1){if(_0x5e25d1){return _0x5e25d1['update'](_0x4815a3)[_0x393f('0x1e')](function(_0x50f8cc){return _0x50f8cc;});}return null;};}function removeEntity(_0x33c6c3,_0x422ec0){return function(_0x2eb923){if(_0x2eb923){return _0x2eb923[_0x393f('0x1f')]()['then'](function(){_0x33c6c3[_0x393f('0x14')](0xcc)[_0x393f('0x15')]();});}};}function handleEntityNotFound(_0x4c2402,_0x2edbf5){return function(_0x478d31){if(!_0x478d31){_0x4c2402['sendStatus'](0x194);}return _0x478d31;};}function handleError(_0x2395c2,_0x27856b){_0x27856b=_0x27856b||0x1f4;return function(_0x544267){logger['error'](_0x544267[_0x393f('0x20')]);if(_0x544267[_0x393f('0x21')]){delete _0x544267[_0x393f('0x21')];}_0x2395c2[_0x393f('0x14')](_0x27856b)[_0x393f('0x22')](_0x544267);};}exports[_0x393f('0x23')]=function(_0x5198ce,_0x15745e){var _0x391586={},_0x239dc4={},_0x412199={'count':0x0,'rows':[]};var _0x5d4a58=_[_0x393f('0x24')](db['CloudProvider'][_0x393f('0x25')],function(_0xfd9a37){return{'name':_0xfd9a37[_0x393f('0x26')],'type':_0xfd9a37['type'][_0x393f('0x27')]};});_0x239dc4[_0x393f('0x28')]=_[_0x393f('0x24')](_0x5d4a58,'name');_0x239dc4['query']=_[_0x393f('0x29')](_0x5198ce[_0x393f('0x2a')]);_0x239dc4['filters']=_[_0x393f('0x2b')](_0x239dc4['model'],_0x239dc4[_0x393f('0x2a')]);_0x391586['attributes']=_[_0x393f('0x2b')](_0x239dc4[_0x393f('0x28')],qs['fields'](_0x5198ce[_0x393f('0x2a')][_0x393f('0x2c')]));_0x391586['attributes']=_0x391586['attributes'][_0x393f('0x2d')]?_0x391586[_0x393f('0x2e')]:_0x239dc4[_0x393f('0x28')];if(!_0x5198ce[_0x393f('0x2a')]['hasOwnProperty'](_0x393f('0x2f'))){_0x391586[_0x393f('0x19')]=qs[_0x393f('0x19')](_0x5198ce[_0x393f('0x2a')][_0x393f('0x19')]);_0x391586['offset']=qs[_0x393f('0x18')](_0x5198ce['query'][_0x393f('0x18')]);}_0x391586['order']=qs[_0x393f('0x30')](_0x5198ce[_0x393f('0x2a')][_0x393f('0x30')]);_0x391586[_0x393f('0x31')]=qs[_0x393f('0x32')](_[_0x393f('0x33')](_0x5198ce[_0x393f('0x2a')],_0x239dc4['filters']),_0x5d4a58);if(_0x5198ce[_0x393f('0x2a')][_0x393f('0x34')]){_0x391586['where']=_[_0x393f('0x35')](_0x391586[_0x393f('0x31')],{'$or':_[_0x393f('0x24')](_0x5d4a58,function(_0x17971e){if(_0x17971e[_0x393f('0x36')]!==_0x393f('0x37')){var _0x27e374={};_0x27e374[_0x17971e['name']]={'$like':'%'+_0x5198ce[_0x393f('0x2a')][_0x393f('0x34')]+'%'};return _0x27e374;}})});}_0x391586=_[_0x393f('0x35')]({},_0x391586,_0x5198ce['options']);var _0x3dbcaf={'where':_0x391586['where']};return db['CloudProvider'][_0x393f('0x17')](_0x3dbcaf)['then'](function(_0x21c4ab){_0x412199['count']=_0x21c4ab;if(_0x5198ce[_0x393f('0x2a')][_0x393f('0x38')]){_0x391586[_0x393f('0x39')]=[{'all':!![]}];}return db[_0x393f('0x3a')][_0x393f('0x3b')](_0x391586);})['then'](function(_0x553410){_0x412199[_0x393f('0x3c')]=_0x553410;return _0x412199;})['then'](respondWithFilteredResult(_0x15745e,_0x391586))['catch'](handleError(_0x15745e,null));};exports[_0x393f('0x3d')]=function(_0x236863,_0x30e178){var _0x18a07a={'raw':!![],'where':{'id':_0x236863[_0x393f('0x3e')]['id']}},_0x4742a2={};_0x4742a2['model']=_['keys'](db[_0x393f('0x3a')][_0x393f('0x25')]);_0x4742a2[_0x393f('0x2a')]=_[_0x393f('0x29')](_0x236863[_0x393f('0x2a')]);_0x4742a2[_0x393f('0x32')]=_['intersection'](_0x4742a2[_0x393f('0x28')],_0x4742a2[_0x393f('0x2a')]);_0x18a07a[_0x393f('0x2e')]=_[_0x393f('0x2b')](_0x4742a2[_0x393f('0x28')],qs[_0x393f('0x2c')](_0x236863['query']['fields']));_0x18a07a[_0x393f('0x2e')]=_0x18a07a[_0x393f('0x2e')][_0x393f('0x2d')]?_0x18a07a['attributes']:_0x4742a2[_0x393f('0x28')];if(_0x236863[_0x393f('0x2a')]['includeAll']){_0x18a07a['include']=[{'all':!![]}];}_0x18a07a=_[_0x393f('0x35')]({},_0x18a07a,_0x236863[_0x393f('0x3f')]);return db[_0x393f('0x3a')][_0x393f('0x40')](_0x18a07a)[_0x393f('0x1e')](handleEntityNotFound(_0x30e178,null))[_0x393f('0x1e')](respondWithResult(_0x30e178,null))[_0x393f('0x41')](handleError(_0x30e178,null));};exports['create']=function(_0x2e6765,_0x5a7095){return db[_0x393f('0x3a')][_0x393f('0x42')](_0x2e6765[_0x393f('0x43')],{})['then'](respondWithResult(_0x5a7095,0xc9))[_0x393f('0x41')](handleError(_0x5a7095,null));};exports[_0x393f('0x44')]=function(_0x582fa3,_0x31be28){if(_0x582fa3[_0x393f('0x43')]['id']){delete _0x582fa3[_0x393f('0x43')]['id'];}return db['CloudProvider'][_0x393f('0x40')]({'where':{'id':_0x582fa3[_0x393f('0x3e')]['id']}})[_0x393f('0x1e')](handleEntityNotFound(_0x31be28,null))['then'](saveUpdates(_0x582fa3[_0x393f('0x43')],null))[_0x393f('0x1e')](respondWithResult(_0x31be28,null))[_0x393f('0x41')](handleError(_0x31be28,null));};exports[_0x393f('0x1f')]=function(_0x1be7b9,_0x1dd2a3){return db[_0x393f('0x3a')]['find']({'where':{'id':_0x1be7b9[_0x393f('0x3e')]['id']}})[_0x393f('0x1e')](handleEntityNotFound(_0x1dd2a3,null))['then'](removeEntity(_0x1dd2a3,null))['catch'](handleError(_0x1dd2a3,null));};