Built motion from commit (unavailable).|2.4.4
[motion2.git] / server / api / crmActionsList / crmActionsList.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 _0x54ef=['../../config/environment','../../mysqldb','status','end','json','offset','limit','set','Content-Range','apply','update','then','destroy','sendStatus','error','stack','name','send','index','rawAttributes','model','keys','query','filters','attributes','intersection','fields','length','hasOwnProperty','order','sort','where','merge','map','type','key','field','filter','options','CrmActionsList','count','includeAll','include','findAll','rows','catch','show','create','body','params','find','describe','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','ejs','lodash','squel','jsforce','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils'];(function(_0x5e33f6,_0x2e18e6){var _0x20cb0f=function(_0x358e5c){while(--_0x358e5c){_0x5e33f6['push'](_0x5e33f6['shift']());}};_0x20cb0f(++_0x2e18e6);}(_0x54ef,0x112));var _0xf54e=function(_0x4ba6a9,_0x34122e){_0x4ba6a9=_0x4ba6a9-0x0;var _0x4a3997=_0x54ef[_0x4ba6a9];return _0x4a3997;};'use strict';var pdf=require(_0xf54e('0x0'));var emlformat=require(_0xf54e('0x1'));var rimraf=require(_0xf54e('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0xf54e('0x3'));var rp=require(_0xf54e('0x4'));var moment=require(_0xf54e('0x5'));var BPromise=require(_0xf54e('0x6'));var Mustache=require(_0xf54e('0x7'));var util=require(_0xf54e('0x8'));var path=require(_0xf54e('0x9'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xf54e('0xa'));var fs=require('fs');var _=require(_0xf54e('0xb'));var squel=require(_0xf54e('0xc'));var crypto=require('crypto');var jsforce=require(_0xf54e('0xd'));var deskjs=require('desk.js');var toCsv=require(_0xf54e('0xe'));var querystring=require(_0xf54e('0xf'));var Papa=require('papaparse');var Redis=require(_0xf54e('0x10'));var authService=require(_0xf54e('0x11'));var qs=require(_0xf54e('0x12'));var hardwareService=require(_0xf54e('0x13'));var logger=require('../../config/logger')(_0xf54e('0x14'));var utils=require(_0xf54e('0x15'));var config=require(_0xf54e('0x16'));var db=require(_0xf54e('0x17'))['db'];function respondWithStatusCode(_0x553759,_0x358c88){_0x358c88=_0x358c88||0xcc;return function(_0x4b0ee1){if(_0x4b0ee1){return _0x553759['sendStatus'](_0x358c88);}return _0x553759[_0xf54e('0x18')](_0x358c88)[_0xf54e('0x19')]();};}function respondWithResult(_0x28f776,_0x380f26){_0x380f26=_0x380f26||0xc8;return function(_0x5644aa){if(_0x5644aa){return _0x28f776[_0xf54e('0x18')](_0x380f26)[_0xf54e('0x1a')](_0x5644aa);}};}function respondWithFilteredResult(_0x1855fe,_0x15f639){return function(_0x56828e){if(_0x56828e){var _0x2366ee=_0x56828e['count'],_0x389abc=_0x15f639[_0xf54e('0x1b')],_0x3eb415=_0x15f639[_0xf54e('0x1b')]+_0x15f639[_0xf54e('0x1c')],_0x5c5d00;if(_0x3eb415>=_0x2366ee){_0x3eb415=_0x2366ee;_0x5c5d00=0xc8;}else{_0x5c5d00=0xce;}_0x1855fe[_0xf54e('0x18')](_0x5c5d00);return _0x1855fe[_0xf54e('0x1d')](_0xf54e('0x1e'),_0x389abc+'-'+_0x3eb415+'/'+_0x2366ee)[_0xf54e('0x1a')](_0x56828e);}return null;};}function patchUpdates(_0x1ef06e){return function(_0x1dcc04){try{jsonpatch[_0xf54e('0x1f')](_0x1dcc04,_0x1ef06e,!![]);}catch(_0x226c96){return BPromise['reject'](_0x226c96);}return _0x1dcc04['save']();};}function saveUpdates(_0x23e14,_0x59f338){return function(_0x3e1556){if(_0x3e1556){return _0x3e1556[_0xf54e('0x20')](_0x23e14)[_0xf54e('0x21')](function(_0x9903fc){return _0x9903fc;});}return null;};}function removeEntity(_0xf64f12,_0x3887b0){return function(_0x388aa0){if(_0x388aa0){return _0x388aa0[_0xf54e('0x22')]()[_0xf54e('0x21')](function(){_0xf64f12[_0xf54e('0x18')](0xcc)[_0xf54e('0x19')]();});}};}function handleEntityNotFound(_0x5b83df,_0x6f6d29){return function(_0x54f914){if(!_0x54f914){_0x5b83df[_0xf54e('0x23')](0x194);}return _0x54f914;};}function handleError(_0x272df6,_0x335492){_0x335492=_0x335492||0x1f4;return function(_0x474b61){logger[_0xf54e('0x24')](_0x474b61[_0xf54e('0x25')]);if(_0x474b61[_0xf54e('0x26')]){delete _0x474b61[_0xf54e('0x26')];}_0x272df6[_0xf54e('0x18')](_0x335492)[_0xf54e('0x27')](_0x474b61);};}exports[_0xf54e('0x28')]=function(_0x39c0ae,_0x2ea001){var _0x5390b8={},_0xb3706e={},_0x4cbf7c={'count':0x0,'rows':[]};var _0x282c63=db['CrmActionsList'][_0xf54e('0x29')];_0xb3706e[_0xf54e('0x2a')]=_[_0xf54e('0x2b')](_0x282c63);_0xb3706e[_0xf54e('0x2c')]=_[_0xf54e('0x2b')](_0x39c0ae[_0xf54e('0x2c')]);_0xb3706e[_0xf54e('0x2d')]=_['intersection'](_0xb3706e['model'],_0xb3706e[_0xf54e('0x2c')]);_0x5390b8[_0xf54e('0x2e')]=_[_0xf54e('0x2f')](_0xb3706e[_0xf54e('0x2a')],qs[_0xf54e('0x30')](_0x39c0ae[_0xf54e('0x2c')][_0xf54e('0x30')]));_0x5390b8[_0xf54e('0x2e')]=_0x5390b8[_0xf54e('0x2e')][_0xf54e('0x31')]?_0x5390b8['attributes']:_0xb3706e['model'];if(!_0x39c0ae[_0xf54e('0x2c')][_0xf54e('0x32')]('nolimit')){_0x5390b8[_0xf54e('0x1c')]=qs[_0xf54e('0x1c')](_0x39c0ae[_0xf54e('0x2c')][_0xf54e('0x1c')]);_0x5390b8['offset']=qs['offset'](_0x39c0ae['query'][_0xf54e('0x1b')]);}_0x5390b8[_0xf54e('0x33')]=qs[_0xf54e('0x34')](_0x39c0ae[_0xf54e('0x2c')][_0xf54e('0x34')]);_0x5390b8[_0xf54e('0x35')]=qs['filters'](_['pick'](_0x39c0ae['query'],_0xb3706e[_0xf54e('0x2d')]));if(_0x39c0ae[_0xf54e('0x2c')]['filter']){_0x5390b8['where']=_[_0xf54e('0x36')](_0x5390b8[_0xf54e('0x35')],{'$or':_[_0xf54e('0x37')](_0x282c63,function(_0x4a347a){if(_0x4a347a[_0xf54e('0x38')][_0xf54e('0x39')]!=='VIRTUAL'){var _0x38d7a0={};_0x38d7a0[_0x4a347a[_0xf54e('0x3a')]]={'$like':'%'+_0x39c0ae[_0xf54e('0x2c')][_0xf54e('0x3b')]+'%'};return _0x38d7a0;}})});}_0x5390b8=_[_0xf54e('0x36')]({},_0x5390b8,_0x39c0ae[_0xf54e('0x3c')]);var _0x4e00b7={'where':_0x5390b8['where']};return db[_0xf54e('0x3d')][_0xf54e('0x3e')](_0x4e00b7)[_0xf54e('0x21')](function(_0x4b1f84){_0x4cbf7c[_0xf54e('0x3e')]=_0x4b1f84;if(_0x39c0ae[_0xf54e('0x2c')][_0xf54e('0x3f')]){_0x5390b8[_0xf54e('0x40')]=[{'all':!![]}];}return db[_0xf54e('0x3d')][_0xf54e('0x41')](_0x5390b8);})[_0xf54e('0x21')](function(_0x1345b0){_0x4cbf7c[_0xf54e('0x42')]=_0x1345b0;return _0x4cbf7c;})[_0xf54e('0x21')](respondWithFilteredResult(_0x2ea001,_0x5390b8))[_0xf54e('0x43')](handleError(_0x2ea001,null));};exports[_0xf54e('0x44')]=function(_0x3dfd4e,_0x2625fd){var _0x2043a8={'raw':![],'where':{'id':_0x3dfd4e['params']['id']}},_0x5085c1={};_0x5085c1['model']=_[_0xf54e('0x2b')](db[_0xf54e('0x3d')]['rawAttributes']);_0x5085c1[_0xf54e('0x2c')]=_[_0xf54e('0x2b')](_0x3dfd4e[_0xf54e('0x2c')]);_0x5085c1['filters']=_[_0xf54e('0x2f')](_0x5085c1[_0xf54e('0x2a')],_0x5085c1[_0xf54e('0x2c')]);_0x2043a8[_0xf54e('0x2e')]=_[_0xf54e('0x2f')](_0x5085c1[_0xf54e('0x2a')],qs[_0xf54e('0x30')](_0x3dfd4e[_0xf54e('0x2c')][_0xf54e('0x30')]));_0x2043a8['attributes']=_0x2043a8[_0xf54e('0x2e')][_0xf54e('0x31')]?_0x2043a8[_0xf54e('0x2e')]:_0x5085c1[_0xf54e('0x2a')];if(_0x3dfd4e[_0xf54e('0x2c')][_0xf54e('0x3f')]){_0x2043a8['include']=[{'all':!![]}];}_0x2043a8=_[_0xf54e('0x36')]({},_0x2043a8,_0x3dfd4e['options']);return db[_0xf54e('0x3d')]['find'](_0x2043a8)[_0xf54e('0x21')](handleEntityNotFound(_0x2625fd,null))[_0xf54e('0x21')](respondWithResult(_0x2625fd,null))[_0xf54e('0x43')](handleError(_0x2625fd,null));};exports['create']=function(_0x1af35d,_0x40b21c){return db[_0xf54e('0x3d')][_0xf54e('0x45')](_0x1af35d[_0xf54e('0x46')],{})['then'](respondWithResult(_0x40b21c,0xc9))[_0xf54e('0x43')](handleError(_0x40b21c,null));};exports[_0xf54e('0x20')]=function(_0x346bb4,_0x45592b){if(_0x346bb4['body']['id']){delete _0x346bb4[_0xf54e('0x46')]['id'];}return db[_0xf54e('0x3d')]['find']({'where':{'id':_0x346bb4[_0xf54e('0x47')]['id']}})[_0xf54e('0x21')](handleEntityNotFound(_0x45592b,null))[_0xf54e('0x21')](saveUpdates(_0x346bb4[_0xf54e('0x46')],null))['then'](respondWithResult(_0x45592b,null))[_0xf54e('0x43')](handleError(_0x45592b,null));};exports[_0xf54e('0x22')]=function(_0x2527f6,_0xb4654f){return db[_0xf54e('0x3d')][_0xf54e('0x48')]({'where':{'id':_0x2527f6[_0xf54e('0x47')]['id']}})[_0xf54e('0x21')](handleEntityNotFound(_0xb4654f,null))[_0xf54e('0x21')](removeEntity(_0xb4654f,null))[_0xf54e('0x43')](handleError(_0xb4654f,null));};exports[_0xf54e('0x49')]=function(_0x1f4cf8,_0x2deb0c){return db[_0xf54e('0x3d')][_0xf54e('0x49')]()[_0xf54e('0x21')](respondWithResult(_0x2deb0c,null))[_0xf54e('0x43')](handleError(_0x2deb0c,null));};