Built motion from commit 753c950e.|2.5.42
[motion2.git] / server / api / openchannelApplication / openchannelApplication.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 _0xae4f=['end','status','undefined','limit','offset','count','set','Content-Range','json','apply','reject','save','then','error','stack','send','map','OpenchannelApplication','fieldName','type','key','model','name','keys','query','filters','intersection','fields','attributes','length','hasOwnProperty','order','sort','pick','filter','where','merge','VIRTUAL','findAll','catch','show','params','rawAttributes','includeAll','include','options','find','create','body','update','destroy','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','fs-extra','lodash','squel','jsforce','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus'];(function(_0x24f1ff,_0x4014c9){var _0x349109=function(_0x253267){while(--_0x253267){_0x24f1ff['push'](_0x24f1ff['shift']());}};_0x349109(++_0x4014c9);}(_0xae4f,0x16b));var _0xfae4=function(_0x2e4b91,_0x8db0e5){_0x2e4b91=_0x2e4b91-0x0;var _0x572d95=_0xae4f[_0x2e4b91];return _0x572d95;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xfae4('0x0'));var zipdir=require(_0xfae4('0x1'));var jsonpatch=require(_0xfae4('0x2'));var rp=require(_0xfae4('0x3'));var moment=require(_0xfae4('0x4'));var BPromise=require(_0xfae4('0x5'));var Mustache=require(_0xfae4('0x6'));var util=require(_0xfae4('0x7'));var path=require(_0xfae4('0x8'));var sox=require(_0xfae4('0x9'));var csv=require('to-csv');var ejs=require(_0xfae4('0xa'));var fs=require('fs');var fs_extra=require(_0xfae4('0xb'));var _=require(_0xfae4('0xc'));var squel=require(_0xfae4('0xd'));var crypto=require('crypto');var jsforce=require(_0xfae4('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xfae4('0xf'));var querystring=require('querystring');var Papa=require(_0xfae4('0x10'));var Redis=require(_0xfae4('0x11'));var authService=require(_0xfae4('0x12'));var qs=require(_0xfae4('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xfae4('0x14'));var logger=require(_0xfae4('0x15'))(_0xfae4('0x16'));var utils=require(_0xfae4('0x17'));var config=require(_0xfae4('0x18'));var licenseUtil=require(_0xfae4('0x19'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0xb4e8f4,_0x247f4c){_0x247f4c=_0x247f4c||0xcc;return function(_0xdeb964){if(_0xdeb964){return _0xb4e8f4[_0xfae4('0x1a')](_0x247f4c);}return _0xb4e8f4['status'](_0x247f4c)[_0xfae4('0x1b')]();};}function respondWithResult(_0x331463,_0x3862c9){_0x3862c9=_0x3862c9||0xc8;return function(_0x529ed2){if(_0x529ed2){return _0x331463[_0xfae4('0x1c')](_0x3862c9)['json'](_0x529ed2);}};}function respondWithFilteredResult(_0x334df2,_0x42d7a8){return function(_0x52e5c8){if(_0x52e5c8){var _0x212424=typeof _0x42d7a8['offset']===_0xfae4('0x1d')&&typeof _0x42d7a8[_0xfae4('0x1e')]==='undefined';var _0x49837c=_0x52e5c8['count'];var _0x482ee3=_0x212424?0x0:_0x42d7a8[_0xfae4('0x1f')];var _0x3f428c=_0x212424?_0x52e5c8[_0xfae4('0x20')]:_0x42d7a8[_0xfae4('0x1f')]+_0x42d7a8[_0xfae4('0x1e')];var _0x2f2f74;if(_0x3f428c>=_0x49837c){_0x3f428c=_0x49837c;_0x2f2f74=0xc8;}else{_0x2f2f74=0xce;}_0x334df2[_0xfae4('0x1c')](_0x2f2f74);return _0x334df2[_0xfae4('0x21')](_0xfae4('0x22'),_0x482ee3+'-'+_0x3f428c+'/'+_0x49837c)[_0xfae4('0x23')](_0x52e5c8);}return null;};}function patchUpdates(_0x2eae5e){return function(_0x55a274){try{jsonpatch[_0xfae4('0x24')](_0x55a274,_0x2eae5e,!![]);}catch(_0x258f84){return BPromise[_0xfae4('0x25')](_0x258f84);}return _0x55a274[_0xfae4('0x26')]();};}function saveUpdates(_0x11e96c,_0x4f9f65){return function(_0x13132e){if(_0x13132e){return _0x13132e['update'](_0x11e96c)[_0xfae4('0x27')](function(_0x20fb44){return _0x20fb44;});}return null;};}function removeEntity(_0x1b3725,_0x3fb146){return function(_0x588cb5){if(_0x588cb5){return _0x588cb5['destroy']()['then'](function(){_0x1b3725[_0xfae4('0x1c')](0xcc)[_0xfae4('0x1b')]();});}};}function handleEntityNotFound(_0x1a81a1,_0xa48a2c){return function(_0x5b3c71){if(!_0x5b3c71){_0x1a81a1[_0xfae4('0x1a')](0x194);}return _0x5b3c71;};}function handleError(_0x5a8606,_0x5c8ce3){_0x5c8ce3=_0x5c8ce3||0x1f4;return function(_0x116f2d){logger[_0xfae4('0x28')](_0x116f2d[_0xfae4('0x29')]);if(_0x116f2d['name']){delete _0x116f2d['name'];}_0x5a8606[_0xfae4('0x1c')](_0x5c8ce3)[_0xfae4('0x2a')](_0x116f2d);};}exports['index']=function(_0x241547,_0x405ab0){var _0x10af5e={},_0x4563d2={},_0x2ca6a5={'count':0x0,'rows':[]};var _0x22e53a=_[_0xfae4('0x2b')](db[_0xfae4('0x2c')]['rawAttributes'],function(_0x2466ca){return{'name':_0x2466ca[_0xfae4('0x2d')],'type':_0x2466ca[_0xfae4('0x2e')][_0xfae4('0x2f')]};});_0x4563d2[_0xfae4('0x30')]=_['map'](_0x22e53a,_0xfae4('0x31'));_0x4563d2['query']=_[_0xfae4('0x32')](_0x241547[_0xfae4('0x33')]);_0x4563d2[_0xfae4('0x34')]=_[_0xfae4('0x35')](_0x4563d2[_0xfae4('0x30')],_0x4563d2['query']);_0x10af5e['attributes']=_[_0xfae4('0x35')](_0x4563d2[_0xfae4('0x30')],qs[_0xfae4('0x36')](_0x241547[_0xfae4('0x33')][_0xfae4('0x36')]));_0x10af5e[_0xfae4('0x37')]=_0x10af5e[_0xfae4('0x37')][_0xfae4('0x38')]?_0x10af5e['attributes']:_0x4563d2[_0xfae4('0x30')];if(!_0x241547[_0xfae4('0x33')][_0xfae4('0x39')]('nolimit')){_0x10af5e[_0xfae4('0x1e')]=qs[_0xfae4('0x1e')](_0x241547['query'][_0xfae4('0x1e')]);_0x10af5e[_0xfae4('0x1f')]=qs[_0xfae4('0x1f')](_0x241547[_0xfae4('0x33')][_0xfae4('0x1f')]);}_0x10af5e[_0xfae4('0x3a')]=qs['sort'](_0x241547[_0xfae4('0x33')][_0xfae4('0x3b')]);_0x10af5e['where']=qs[_0xfae4('0x34')](_[_0xfae4('0x3c')](_0x241547[_0xfae4('0x33')],_0x4563d2[_0xfae4('0x34')]),_0x22e53a);if(_0x241547[_0xfae4('0x33')][_0xfae4('0x3d')]){_0x10af5e[_0xfae4('0x3e')]=_[_0xfae4('0x3f')](_0x10af5e[_0xfae4('0x3e')],{'$or':_[_0xfae4('0x2b')](_0x22e53a,function(_0x5406b5){if(_0x5406b5[_0xfae4('0x2e')]!==_0xfae4('0x40')){var _0x39204c={};_0x39204c[_0x5406b5[_0xfae4('0x31')]]={'$like':'%'+_0x241547[_0xfae4('0x33')][_0xfae4('0x3d')]+'%'};return _0x39204c;}})});}_0x10af5e=_['merge']({},_0x10af5e,_0x241547['options']);var _0x711b4={'where':_0x10af5e[_0xfae4('0x3e')]};return db[_0xfae4('0x2c')][_0xfae4('0x20')](_0x711b4)[_0xfae4('0x27')](function(_0x41038d){_0x2ca6a5['count']=_0x41038d;if(_0x241547[_0xfae4('0x33')]['includeAll']){_0x10af5e['include']=[{'all':!![]}];}return db[_0xfae4('0x2c')][_0xfae4('0x41')](_0x10af5e);})[_0xfae4('0x27')](function(_0x4ff2c8){_0x2ca6a5['rows']=_0x4ff2c8;return _0x2ca6a5;})[_0xfae4('0x27')](respondWithFilteredResult(_0x405ab0,_0x10af5e))[_0xfae4('0x42')](handleError(_0x405ab0,null));};exports[_0xfae4('0x43')]=function(_0xa91e89,_0x473f80){var _0x374f0b={'raw':!![],'where':{'id':_0xa91e89[_0xfae4('0x44')]['id']}},_0x3694be={};_0x3694be['model']=_[_0xfae4('0x32')](db[_0xfae4('0x2c')][_0xfae4('0x45')]);_0x3694be[_0xfae4('0x33')]=_[_0xfae4('0x32')](_0xa91e89[_0xfae4('0x33')]);_0x3694be[_0xfae4('0x34')]=_[_0xfae4('0x35')](_0x3694be[_0xfae4('0x30')],_0x3694be[_0xfae4('0x33')]);_0x374f0b[_0xfae4('0x37')]=_[_0xfae4('0x35')](_0x3694be[_0xfae4('0x30')],qs[_0xfae4('0x36')](_0xa91e89[_0xfae4('0x33')][_0xfae4('0x36')]));_0x374f0b[_0xfae4('0x37')]=_0x374f0b[_0xfae4('0x37')][_0xfae4('0x38')]?_0x374f0b[_0xfae4('0x37')]:_0x3694be[_0xfae4('0x30')];if(_0xa91e89['query'][_0xfae4('0x46')]){_0x374f0b[_0xfae4('0x47')]=[{'all':!![]}];}_0x374f0b=_[_0xfae4('0x3f')]({},_0x374f0b,_0xa91e89[_0xfae4('0x48')]);return db[_0xfae4('0x2c')][_0xfae4('0x49')](_0x374f0b)['then'](handleEntityNotFound(_0x473f80,null))['then'](respondWithResult(_0x473f80,null))[_0xfae4('0x42')](handleError(_0x473f80,null));};exports['create']=function(_0x2a3012,_0x5eafcf){return db[_0xfae4('0x2c')][_0xfae4('0x4a')](_0x2a3012[_0xfae4('0x4b')],{})['then'](respondWithResult(_0x5eafcf,0xc9))['catch'](handleError(_0x5eafcf,null));};exports[_0xfae4('0x4c')]=function(_0xb12d7d,_0x1f9f6c){if(_0xb12d7d[_0xfae4('0x4b')]['id']){delete _0xb12d7d[_0xfae4('0x4b')]['id'];}return db[_0xfae4('0x2c')][_0xfae4('0x49')]({'where':{'id':_0xb12d7d[_0xfae4('0x44')]['id']}})[_0xfae4('0x27')](handleEntityNotFound(_0x1f9f6c,null))[_0xfae4('0x27')](saveUpdates(_0xb12d7d[_0xfae4('0x4b')],null))[_0xfae4('0x27')](respondWithResult(_0x1f9f6c,null))['catch'](handleError(_0x1f9f6c,null));};exports[_0xfae4('0x4d')]=function(_0x442768,_0x1d655d){return db[_0xfae4('0x2c')][_0xfae4('0x49')]({'where':{'id':_0x442768[_0xfae4('0x44')]['id']}})['then'](handleEntityNotFound(_0x1d655d,null))[_0xfae4('0x27')](removeEntity(_0x1d655d,null))[_0xfae4('0x42')](handleError(_0x1d655d,null));};