886c2349e9a40c8fcdf9eebfdd959c470bb19381
[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 _0xf408=['apply','reject','destroy','error','stack','name','send','index','map','Integration','rawAttributes','type','key','query','filters','model','intersection','fields','attributes','length','nolimit','sort','where','pick','filter','merge','VIRTUAL','options','then','includeAll','include','findAll','rows','show','params','keys','find','catch','create','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','end','count','offset','limit','status','Content-Range','json'];(function(_0x52c942,_0x328ff8){var _0x269b14=function(_0xfe7e76){while(--_0xfe7e76){_0x52c942['push'](_0x52c942['shift']());}};_0x269b14(++_0x328ff8);}(_0xf408,0x1f0));var _0x8f40=function(_0x302b72,_0x483f35){_0x302b72=_0x302b72-0x0;var _0x48aa64=_0xf408[_0x302b72];return _0x48aa64;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x8f40('0x0'));var rimraf=require(_0x8f40('0x1'));var zipdir=require(_0x8f40('0x2'));var jsonpatch=require(_0x8f40('0x3'));var rp=require(_0x8f40('0x4'));var moment=require(_0x8f40('0x5'));var BPromise=require(_0x8f40('0x6'));var Mustache=require(_0x8f40('0x7'));var util=require(_0x8f40('0x8'));var path=require(_0x8f40('0x9'));var sox=require(_0x8f40('0xa'));var csv=require(_0x8f40('0xb'));var ejs=require(_0x8f40('0xc'));var fs=require('fs');var _=require(_0x8f40('0xd'));var squel=require(_0x8f40('0xe'));var crypto=require(_0x8f40('0xf'));var jsforce=require(_0x8f40('0x10'));var deskjs=require(_0x8f40('0x11'));var toCsv=require('to-csv');var querystring=require(_0x8f40('0x12'));var Papa=require('papaparse');var Redis=require(_0x8f40('0x13'));var authService=require(_0x8f40('0x14'));var qs=require(_0x8f40('0x15'));var as=require(_0x8f40('0x16'));var hardwareService=require(_0x8f40('0x17'));var logger=require(_0x8f40('0x18'))('api');var utils=require(_0x8f40('0x19'));var config=require(_0x8f40('0x1a'));var db=require(_0x8f40('0x1b'))['db'];function respondWithStatusCode(_0x42a7f0,_0x24532a){_0x24532a=_0x24532a||0xcc;return function(_0xe17f2e){if(_0xe17f2e){return _0x42a7f0[_0x8f40('0x1c')](_0x24532a);}return _0x42a7f0['status'](_0x24532a)[_0x8f40('0x1d')]();};}function respondWithResult(_0x332618,_0x4855a6){_0x4855a6=_0x4855a6||0xc8;return function(_0x251b83){if(_0x251b83){return _0x332618['status'](_0x4855a6)['json'](_0x251b83);}};}function respondWithFilteredResult(_0x19d7da,_0x8bbac8){return function(_0x5ae5b){if(_0x5ae5b){var _0xee800=_0x5ae5b[_0x8f40('0x1e')],_0x31f633=_0x8bbac8['offset'],_0x2f4f11=_0x8bbac8[_0x8f40('0x1f')]+_0x8bbac8[_0x8f40('0x20')],_0x3bbaf2;if(_0x2f4f11>=_0xee800){_0x2f4f11=_0xee800;_0x3bbaf2=0xc8;}else{_0x3bbaf2=0xce;}_0x19d7da[_0x8f40('0x21')](_0x3bbaf2);return _0x19d7da['set'](_0x8f40('0x22'),_0x31f633+'-'+_0x2f4f11+'/'+_0xee800)[_0x8f40('0x23')](_0x5ae5b);}return null;};}function patchUpdates(_0xd6abf){return function(_0x3a35ce){try{jsonpatch[_0x8f40('0x24')](_0x3a35ce,_0xd6abf,!![]);}catch(_0x408051){return BPromise[_0x8f40('0x25')](_0x408051);}return _0x3a35ce['save']();};}function saveUpdates(_0x26ffb1,_0xcab187){return function(_0xb0d5f3){if(_0xb0d5f3){return _0xb0d5f3['update'](_0x26ffb1)['then'](function(_0x574b4d){return _0x574b4d;});}return null;};}function removeEntity(_0x114fad,_0x26791c){return function(_0x5f145b){if(_0x5f145b){return _0x5f145b[_0x8f40('0x26')]()['then'](function(){_0x114fad[_0x8f40('0x21')](0xcc)[_0x8f40('0x1d')]();});}};}function handleEntityNotFound(_0x163c73,_0x311f38){return function(_0x511fce){if(!_0x511fce){_0x163c73['sendStatus'](0x194);}return _0x511fce;};}function handleError(_0x25544b,_0x1598c0){_0x1598c0=_0x1598c0||0x1f4;return function(_0x16e3e5){logger[_0x8f40('0x27')](_0x16e3e5[_0x8f40('0x28')]);if(_0x16e3e5[_0x8f40('0x29')]){delete _0x16e3e5[_0x8f40('0x29')];}_0x25544b[_0x8f40('0x21')](_0x1598c0)[_0x8f40('0x2a')](_0x16e3e5);};}exports[_0x8f40('0x2b')]=function(_0x3d93be,_0x14e950){var _0xccd2f6={},_0x4fc8df={},_0x4a18a5={'count':0x0,'rows':[]};var _0x6f8860=_[_0x8f40('0x2c')](db[_0x8f40('0x2d')][_0x8f40('0x2e')],function(_0x11c7ba){return{'name':_0x11c7ba['fieldName'],'type':_0x11c7ba[_0x8f40('0x2f')][_0x8f40('0x30')]};});_0x4fc8df['model']=_[_0x8f40('0x2c')](_0x6f8860,_0x8f40('0x29'));_0x4fc8df[_0x8f40('0x31')]=_['keys'](_0x3d93be['query']);_0x4fc8df[_0x8f40('0x32')]=_['intersection'](_0x4fc8df[_0x8f40('0x33')],_0x4fc8df[_0x8f40('0x31')]);_0xccd2f6['attributes']=_[_0x8f40('0x34')](_0x4fc8df['model'],qs[_0x8f40('0x35')](_0x3d93be[_0x8f40('0x31')][_0x8f40('0x35')]));_0xccd2f6['attributes']=_0xccd2f6[_0x8f40('0x36')][_0x8f40('0x37')]?_0xccd2f6[_0x8f40('0x36')]:_0x4fc8df[_0x8f40('0x33')];if(!_0x3d93be[_0x8f40('0x31')]['hasOwnProperty'](_0x8f40('0x38'))){_0xccd2f6[_0x8f40('0x20')]=qs['limit'](_0x3d93be['query'][_0x8f40('0x20')]);_0xccd2f6['offset']=qs[_0x8f40('0x1f')](_0x3d93be[_0x8f40('0x31')]['offset']);}_0xccd2f6['order']=qs[_0x8f40('0x39')](_0x3d93be[_0x8f40('0x31')][_0x8f40('0x39')]);_0xccd2f6[_0x8f40('0x3a')]=qs[_0x8f40('0x32')](_[_0x8f40('0x3b')](_0x3d93be[_0x8f40('0x31')],_0x4fc8df['filters']));if(_0x3d93be[_0x8f40('0x31')][_0x8f40('0x3c')]){_0xccd2f6[_0x8f40('0x3a')]=_[_0x8f40('0x3d')](_0xccd2f6['where'],{'$or':_['map'](_0x6f8860,function(_0x40d219){if(_0x40d219[_0x8f40('0x2f')]!==_0x8f40('0x3e')){var _0x5aae30={};_0x5aae30[_0x40d219[_0x8f40('0x29')]]={'$like':'%'+_0x3d93be[_0x8f40('0x31')][_0x8f40('0x3c')]+'%'};return _0x5aae30;}})});}_0xccd2f6=_[_0x8f40('0x3d')]({},_0xccd2f6,_0x3d93be[_0x8f40('0x3f')]);var _0x268825={'where':_0xccd2f6[_0x8f40('0x3a')]};return db['Integration']['count'](_0x268825)[_0x8f40('0x40')](function(_0x189ea9){_0x4a18a5[_0x8f40('0x1e')]=_0x189ea9;if(_0x3d93be['query'][_0x8f40('0x41')]){_0xccd2f6[_0x8f40('0x42')]=[{'all':!![]}];}return db[_0x8f40('0x2d')][_0x8f40('0x43')](_0xccd2f6);})['then'](function(_0x1fe82c){_0x4a18a5[_0x8f40('0x44')]=_0x1fe82c;return _0x4a18a5;})[_0x8f40('0x40')](respondWithFilteredResult(_0x14e950,_0xccd2f6))['catch'](handleError(_0x14e950,null));};exports[_0x8f40('0x45')]=function(_0x545a5b,_0x19ff5d){var _0x435251={'raw':![],'where':{'id':_0x545a5b[_0x8f40('0x46')]['id']}},_0x101a09={};_0x101a09['model']=_[_0x8f40('0x47')](db['Integration'][_0x8f40('0x2e')]);_0x101a09[_0x8f40('0x31')]=_[_0x8f40('0x47')](_0x545a5b[_0x8f40('0x31')]);_0x101a09[_0x8f40('0x32')]=_['intersection'](_0x101a09[_0x8f40('0x33')],_0x101a09[_0x8f40('0x31')]);_0x435251[_0x8f40('0x36')]=_[_0x8f40('0x34')](_0x101a09[_0x8f40('0x33')],qs[_0x8f40('0x35')](_0x545a5b['query']['fields']));_0x435251[_0x8f40('0x36')]=_0x435251[_0x8f40('0x36')][_0x8f40('0x37')]?_0x435251[_0x8f40('0x36')]:_0x101a09[_0x8f40('0x33')];if(_0x545a5b[_0x8f40('0x31')][_0x8f40('0x41')]){_0x435251[_0x8f40('0x42')]=[{'all':!![]}];}_0x435251=_[_0x8f40('0x3d')]({},_0x435251,_0x545a5b['options']);return db[_0x8f40('0x2d')][_0x8f40('0x48')](_0x435251)['then'](handleEntityNotFound(_0x19ff5d,null))[_0x8f40('0x40')](respondWithResult(_0x19ff5d,null))[_0x8f40('0x49')](handleError(_0x19ff5d,null));};exports[_0x8f40('0x4a')]=function(_0x2ffa64,_0x2515b0){return db[_0x8f40('0x2d')][_0x8f40('0x4a')](_0x2ffa64[_0x8f40('0x4b')],{})['then'](respondWithResult(_0x2515b0,0xc9))[_0x8f40('0x49')](handleError(_0x2515b0,null));};exports['update']=function(_0x1a02c4,_0x1bd2d5){if(_0x1a02c4[_0x8f40('0x4b')]['id']){delete _0x1a02c4[_0x8f40('0x4b')]['id'];}return db['Integration'][_0x8f40('0x48')]({'where':{'id':_0x1a02c4['params']['id']}})['then'](handleEntityNotFound(_0x1bd2d5,null))['then'](saveUpdates(_0x1a02c4[_0x8f40('0x4b')],null))[_0x8f40('0x40')](respondWithResult(_0x1bd2d5,null))['catch'](handleError(_0x1bd2d5,null));};exports['destroy']=function(_0x271448,_0x26bde5){return db['Integration'][_0x8f40('0x48')]({'where':{'id':_0x271448[_0x8f40('0x46')]['id']}})[_0x8f40('0x40')](handleEntityNotFound(_0x26bde5,null))[_0x8f40('0x40')](removeEntity(_0x26bde5,null))[_0x8f40('0x49')](handleError(_0x26bde5,null));};