9fbeaee1630a9b9af8d5a0122a95b6cc2a412022
[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 _0xb3f3=['includeAll','find','create','body','update','catch','html-pdf','rimraf','fast-json-patch','request-promise','bluebird','mustache','path','to-csv','lodash','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','count','offset','limit','set','Content-Range','apply','reject','save','destroy','error','stack','name','send','map','CloudProvider','rawAttributes','fieldName','type','query','keys','filters','intersection','model','fields','attributes','hasOwnProperty','order','sort','filter','where','merge','VIRTUAL','options','include','findAll','then','rows','show','params'];(function(_0x3cea78,_0x4a6751){var _0x33b66b=function(_0x1f45cd){while(--_0x1f45cd){_0x3cea78['push'](_0x3cea78['shift']());}};_0x33b66b(++_0x4a6751);}(_0xb3f3,0x92));var _0x3b3f=function(_0x309df4,_0x3391db){_0x309df4=_0x309df4-0x0;var _0x4be8fc=_0xb3f3[_0x309df4];return _0x4be8fc;};'use strict';var pdf=require(_0x3b3f('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x3b3f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x3b3f('0x2'));var rp=require(_0x3b3f('0x3'));var moment=require('moment');var BPromise=require(_0x3b3f('0x4'));var Mustache=require(_0x3b3f('0x5'));var util=require('util');var path=require(_0x3b3f('0x6'));var sox=require('sox');var csv=require(_0x3b3f('0x7'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x3b3f('0x8'));var squel=require('squel');var crypto=require(_0x3b3f('0x9'));var jsforce=require(_0x3b3f('0xa'));var deskjs=require('desk.js');var toCsv=require(_0x3b3f('0x7'));var querystring=require(_0x3b3f('0xb'));var Papa=require(_0x3b3f('0xc'));var Redis=require(_0x3b3f('0xd'));var authService=require(_0x3b3f('0xe'));var qs=require('../../components/parsers/qs');var as=require(_0x3b3f('0xf'));var hardwareService=require(_0x3b3f('0x10'));var logger=require(_0x3b3f('0x11'))(_0x3b3f('0x12'));var utils=require(_0x3b3f('0x13'));var config=require(_0x3b3f('0x14'));var db=require(_0x3b3f('0x15'))['db'];function respondWithStatusCode(_0x3cad50,_0xcbd6af){_0xcbd6af=_0xcbd6af||0xcc;return function(_0x5be39d){if(_0x5be39d){return _0x3cad50[_0x3b3f('0x16')](_0xcbd6af);}return _0x3cad50[_0x3b3f('0x17')](_0xcbd6af)[_0x3b3f('0x18')]();};}function respondWithResult(_0x3a198f,_0x46f9aa){_0x46f9aa=_0x46f9aa||0xc8;return function(_0x535f04){if(_0x535f04){return _0x3a198f[_0x3b3f('0x17')](_0x46f9aa)['json'](_0x535f04);}};}function respondWithFilteredResult(_0x855057,_0x21b29f){return function(_0x119e19){if(_0x119e19){var _0x3cba88=_0x119e19[_0x3b3f('0x19')],_0x2dbb0d=_0x21b29f[_0x3b3f('0x1a')],_0x26b5ac=_0x21b29f[_0x3b3f('0x1a')]+_0x21b29f[_0x3b3f('0x1b')],_0x1896f5;if(_0x26b5ac>=_0x3cba88){_0x26b5ac=_0x3cba88;_0x1896f5=0xc8;}else{_0x1896f5=0xce;}_0x855057[_0x3b3f('0x17')](_0x1896f5);return _0x855057[_0x3b3f('0x1c')](_0x3b3f('0x1d'),_0x2dbb0d+'-'+_0x26b5ac+'/'+_0x3cba88)['json'](_0x119e19);}return null;};}function patchUpdates(_0x4208bd){return function(_0x1e68c3){try{jsonpatch[_0x3b3f('0x1e')](_0x1e68c3,_0x4208bd,!![]);}catch(_0x15b4f0){return BPromise[_0x3b3f('0x1f')](_0x15b4f0);}return _0x1e68c3[_0x3b3f('0x20')]();};}function saveUpdates(_0x81294,_0x167e91){return function(_0x63c40c){if(_0x63c40c){return _0x63c40c['update'](_0x81294)['then'](function(_0x34696a){return _0x34696a;});}return null;};}function removeEntity(_0x3b833f,_0x9318f1){return function(_0x573e61){if(_0x573e61){return _0x573e61[_0x3b3f('0x21')]()['then'](function(){_0x3b833f[_0x3b3f('0x17')](0xcc)[_0x3b3f('0x18')]();});}};}function handleEntityNotFound(_0x459119,_0x1bb01e){return function(_0x2ea457){if(!_0x2ea457){_0x459119['sendStatus'](0x194);}return _0x2ea457;};}function handleError(_0x243d69,_0x4b05f7){_0x4b05f7=_0x4b05f7||0x1f4;return function(_0x2165fb){logger[_0x3b3f('0x22')](_0x2165fb[_0x3b3f('0x23')]);if(_0x2165fb['name']){delete _0x2165fb[_0x3b3f('0x24')];}_0x243d69['status'](_0x4b05f7)[_0x3b3f('0x25')](_0x2165fb);};}exports['index']=function(_0x2ca58d,_0x425d99){var _0x583d76={},_0xb954c1={},_0x5867d8={'count':0x0,'rows':[]};var _0x45accd=_[_0x3b3f('0x26')](db[_0x3b3f('0x27')][_0x3b3f('0x28')],function(_0x4d5f62){return{'name':_0x4d5f62[_0x3b3f('0x29')],'type':_0x4d5f62[_0x3b3f('0x2a')]['key']};});_0xb954c1['model']=_[_0x3b3f('0x26')](_0x45accd,_0x3b3f('0x24'));_0xb954c1[_0x3b3f('0x2b')]=_[_0x3b3f('0x2c')](_0x2ca58d[_0x3b3f('0x2b')]);_0xb954c1[_0x3b3f('0x2d')]=_[_0x3b3f('0x2e')](_0xb954c1[_0x3b3f('0x2f')],_0xb954c1['query']);_0x583d76['attributes']=_['intersection'](_0xb954c1[_0x3b3f('0x2f')],qs[_0x3b3f('0x30')](_0x2ca58d['query']['fields']));_0x583d76[_0x3b3f('0x31')]=_0x583d76[_0x3b3f('0x31')]['length']?_0x583d76[_0x3b3f('0x31')]:_0xb954c1[_0x3b3f('0x2f')];if(!_0x2ca58d[_0x3b3f('0x2b')][_0x3b3f('0x32')]('nolimit')){_0x583d76[_0x3b3f('0x1b')]=qs[_0x3b3f('0x1b')](_0x2ca58d[_0x3b3f('0x2b')][_0x3b3f('0x1b')]);_0x583d76[_0x3b3f('0x1a')]=qs[_0x3b3f('0x1a')](_0x2ca58d[_0x3b3f('0x2b')][_0x3b3f('0x1a')]);}_0x583d76[_0x3b3f('0x33')]=qs[_0x3b3f('0x34')](_0x2ca58d[_0x3b3f('0x2b')]['sort']);_0x583d76['where']=qs[_0x3b3f('0x2d')](_['pick'](_0x2ca58d[_0x3b3f('0x2b')],_0xb954c1[_0x3b3f('0x2d')]),_0x45accd);if(_0x2ca58d['query'][_0x3b3f('0x35')]){_0x583d76[_0x3b3f('0x36')]=_[_0x3b3f('0x37')](_0x583d76['where'],{'$or':_[_0x3b3f('0x26')](_0x45accd,function(_0x2a3204){if(_0x2a3204['type']!==_0x3b3f('0x38')){var _0x59ed63={};_0x59ed63[_0x2a3204[_0x3b3f('0x24')]]={'$like':'%'+_0x2ca58d['query'][_0x3b3f('0x35')]+'%'};return _0x59ed63;}})});}_0x583d76=_[_0x3b3f('0x37')]({},_0x583d76,_0x2ca58d[_0x3b3f('0x39')]);var _0xcedb09={'where':_0x583d76['where']};return db['CloudProvider'][_0x3b3f('0x19')](_0xcedb09)['then'](function(_0x4322be){_0x5867d8[_0x3b3f('0x19')]=_0x4322be;if(_0x2ca58d[_0x3b3f('0x2b')]['includeAll']){_0x583d76[_0x3b3f('0x3a')]=[{'all':!![]}];}return db['CloudProvider'][_0x3b3f('0x3b')](_0x583d76);})[_0x3b3f('0x3c')](function(_0x374da4){_0x5867d8[_0x3b3f('0x3d')]=_0x374da4;return _0x5867d8;})[_0x3b3f('0x3c')](respondWithFilteredResult(_0x425d99,_0x583d76))['catch'](handleError(_0x425d99,null));};exports[_0x3b3f('0x3e')]=function(_0x5dfdb1,_0x3507c9){var _0x2faa29={'raw':!![],'where':{'id':_0x5dfdb1[_0x3b3f('0x3f')]['id']}},_0x3e39fe={};_0x3e39fe[_0x3b3f('0x2f')]=_[_0x3b3f('0x2c')](db[_0x3b3f('0x27')][_0x3b3f('0x28')]);_0x3e39fe[_0x3b3f('0x2b')]=_['keys'](_0x5dfdb1['query']);_0x3e39fe[_0x3b3f('0x2d')]=_[_0x3b3f('0x2e')](_0x3e39fe[_0x3b3f('0x2f')],_0x3e39fe[_0x3b3f('0x2b')]);_0x2faa29[_0x3b3f('0x31')]=_[_0x3b3f('0x2e')](_0x3e39fe[_0x3b3f('0x2f')],qs[_0x3b3f('0x30')](_0x5dfdb1[_0x3b3f('0x2b')][_0x3b3f('0x30')]));_0x2faa29[_0x3b3f('0x31')]=_0x2faa29[_0x3b3f('0x31')]['length']?_0x2faa29[_0x3b3f('0x31')]:_0x3e39fe[_0x3b3f('0x2f')];if(_0x5dfdb1[_0x3b3f('0x2b')][_0x3b3f('0x40')]){_0x2faa29['include']=[{'all':!![]}];}_0x2faa29=_[_0x3b3f('0x37')]({},_0x2faa29,_0x5dfdb1[_0x3b3f('0x39')]);return db[_0x3b3f('0x27')][_0x3b3f('0x41')](_0x2faa29)[_0x3b3f('0x3c')](handleEntityNotFound(_0x3507c9,null))[_0x3b3f('0x3c')](respondWithResult(_0x3507c9,null))['catch'](handleError(_0x3507c9,null));};exports['create']=function(_0x34c825,_0x2c8587){return db[_0x3b3f('0x27')][_0x3b3f('0x42')](_0x34c825[_0x3b3f('0x43')],{})[_0x3b3f('0x3c')](respondWithResult(_0x2c8587,0xc9))['catch'](handleError(_0x2c8587,null));};exports[_0x3b3f('0x44')]=function(_0x520d3b,_0x16ed98){if(_0x520d3b['body']['id']){delete _0x520d3b[_0x3b3f('0x43')]['id'];}return db[_0x3b3f('0x27')][_0x3b3f('0x41')]({'where':{'id':_0x520d3b['params']['id']}})[_0x3b3f('0x3c')](handleEntityNotFound(_0x16ed98,null))[_0x3b3f('0x3c')](saveUpdates(_0x520d3b[_0x3b3f('0x43')],null))[_0x3b3f('0x3c')](respondWithResult(_0x16ed98,null))['catch'](handleError(_0x16ed98,null));};exports[_0x3b3f('0x21')]=function(_0x263004,_0x15459e){return db['CloudProvider']['find']({'where':{'id':_0x263004[_0x3b3f('0x3f')]['id']}})[_0x3b3f('0x3c')](handleEntityNotFound(_0x15459e,null))[_0x3b3f('0x3c')](removeEntity(_0x15459e,null))[_0x3b3f('0x45')](handleError(_0x15459e,null));};