c4e2e093e9253695d9ea78d627f3d99b6cf85a95
[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 _0x00bb=['moment','bluebird','util','path','lodash','squel','crypto','jsforce','desk.js','to-csv','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','sendStatus','status','end','count','offset','limit','set','json','reject','update','then','error','stack','name','send','CrmActionsList','rawAttributes','model','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','map','type','key','field','options','includeAll','include','catch','show','params','keys','length','find','create','body','destroy','describe','html-pdf','eml-format','rimraf','fast-json-patch'];(function(_0x34f065,_0x2c0cbd){var _0x54c2fe=function(_0x59b4d6){while(--_0x59b4d6){_0x34f065['push'](_0x34f065['shift']());}};_0x54c2fe(++_0x2c0cbd);}(_0x00bb,0x1d8));var _0xb00b=function(_0x33032e,_0x31411a){_0x33032e=_0x33032e-0x0;var _0x13316b=_0x00bb[_0x33032e];return _0x13316b;};'use strict';var pdf=require(_0xb00b('0x0'));var emlformat=require(_0xb00b('0x1'));var rimraf=require(_0xb00b('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0xb00b('0x3'));var rp=require('request-promise');var moment=require(_0xb00b('0x4'));var BPromise=require(_0xb00b('0x5'));var Mustache=require('mustache');var util=require(_0xb00b('0x6'));var path=require(_0xb00b('0x7'));var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xb00b('0x8'));var squel=require(_0xb00b('0x9'));var crypto=require(_0xb00b('0xa'));var jsforce=require(_0xb00b('0xb'));var deskjs=require(_0xb00b('0xc'));var toCsv=require(_0xb00b('0xd'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xb00b('0xe'));var authService=require(_0xb00b('0xf'));var qs=require(_0xb00b('0x10'));var hardwareService=require(_0xb00b('0x11'));var logger=require(_0xb00b('0x12'))('api');var utils=require(_0xb00b('0x13'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x594075,_0x4ff792){_0x4ff792=_0x4ff792||0xcc;return function(_0x2d8ddf){if(_0x2d8ddf){return _0x594075[_0xb00b('0x14')](_0x4ff792);}return _0x594075[_0xb00b('0x15')](_0x4ff792)[_0xb00b('0x16')]();};}function respondWithResult(_0x1f1c1d,_0x4ada81){_0x4ada81=_0x4ada81||0xc8;return function(_0x218de2){if(_0x218de2){return _0x1f1c1d[_0xb00b('0x15')](_0x4ada81)['json'](_0x218de2);}};}function respondWithFilteredResult(_0x88d95e,_0x1084a6){return function(_0x540b79){if(_0x540b79){var _0x5da36b=_0x540b79[_0xb00b('0x17')],_0x9b471e=_0x1084a6[_0xb00b('0x18')],_0x4dcd45=_0x1084a6[_0xb00b('0x18')]+_0x1084a6[_0xb00b('0x19')],_0x51d136;if(_0x4dcd45>=_0x5da36b){_0x4dcd45=_0x5da36b;_0x51d136=0xc8;}else{_0x51d136=0xce;}_0x88d95e['status'](_0x51d136);return _0x88d95e[_0xb00b('0x1a')]('Content-Range',_0x9b471e+'-'+_0x4dcd45+'/'+_0x5da36b)[_0xb00b('0x1b')](_0x540b79);}return null;};}function patchUpdates(_0x5aa9a0){return function(_0x25d7a0){try{jsonpatch['apply'](_0x25d7a0,_0x5aa9a0,!![]);}catch(_0xb26ebb){return BPromise[_0xb00b('0x1c')](_0xb26ebb);}return _0x25d7a0['save']();};}function saveUpdates(_0x55770c,_0x2b0da1){return function(_0x4a334b){if(_0x4a334b){return _0x4a334b[_0xb00b('0x1d')](_0x55770c)[_0xb00b('0x1e')](function(_0x2fe48d){return _0x2fe48d;});}return null;};}function removeEntity(_0x3501af,_0x56c189){return function(_0x362ee0){if(_0x362ee0){return _0x362ee0['destroy']()[_0xb00b('0x1e')](function(){_0x3501af[_0xb00b('0x15')](0xcc)['end']();});}};}function handleEntityNotFound(_0x231293,_0x2896d1){return function(_0x520444){if(!_0x520444){_0x231293[_0xb00b('0x14')](0x194);}return _0x520444;};}function handleError(_0x1f04d3,_0x5568bb){_0x5568bb=_0x5568bb||0x1f4;return function(_0x44efe5){logger[_0xb00b('0x1f')](_0x44efe5[_0xb00b('0x20')]);if(_0x44efe5[_0xb00b('0x21')]){delete _0x44efe5['name'];}_0x1f04d3['status'](_0x5568bb)[_0xb00b('0x22')](_0x44efe5);};}exports['index']=function(_0x550587,_0x4a635e){var _0x16ac55={},_0x73b6b0={},_0x2592cf={'count':0x0,'rows':[]};var _0x3825af=db[_0xb00b('0x23')][_0xb00b('0x24')];_0x73b6b0[_0xb00b('0x25')]=_['keys'](_0x3825af);_0x73b6b0[_0xb00b('0x26')]=_['keys'](_0x550587[_0xb00b('0x26')]);_0x73b6b0[_0xb00b('0x27')]=_[_0xb00b('0x28')](_0x73b6b0['model'],_0x73b6b0[_0xb00b('0x26')]);_0x16ac55[_0xb00b('0x29')]=_[_0xb00b('0x28')](_0x73b6b0[_0xb00b('0x25')],qs[_0xb00b('0x2a')](_0x550587[_0xb00b('0x26')][_0xb00b('0x2a')]));_0x16ac55[_0xb00b('0x29')]=_0x16ac55[_0xb00b('0x29')]['length']?_0x16ac55[_0xb00b('0x29')]:_0x73b6b0[_0xb00b('0x25')];if(!_0x550587['query'][_0xb00b('0x2b')](_0xb00b('0x2c'))){_0x16ac55['limit']=qs[_0xb00b('0x19')](_0x550587['query'][_0xb00b('0x19')]);_0x16ac55[_0xb00b('0x18')]=qs[_0xb00b('0x18')](_0x550587[_0xb00b('0x26')][_0xb00b('0x18')]);}_0x16ac55[_0xb00b('0x2d')]=qs[_0xb00b('0x2e')](_0x550587['query']['sort']);_0x16ac55['where']=qs[_0xb00b('0x27')](_[_0xb00b('0x2f')](_0x550587[_0xb00b('0x26')],_0x73b6b0[_0xb00b('0x27')]));if(_0x550587['query'][_0xb00b('0x30')]){_0x16ac55[_0xb00b('0x31')]=_[_0xb00b('0x32')](_0x16ac55[_0xb00b('0x31')],{'$or':_[_0xb00b('0x33')](_0x3825af,function(_0x39da49){if(_0x39da49[_0xb00b('0x34')][_0xb00b('0x35')]!=='VIRTUAL'){var _0x55451e={};_0x55451e[_0x39da49[_0xb00b('0x36')]]={'$like':'%'+_0x550587['query'][_0xb00b('0x30')]+'%'};return _0x55451e;}})});}_0x16ac55=_[_0xb00b('0x32')]({},_0x16ac55,_0x550587[_0xb00b('0x37')]);var _0x45ca74={'where':_0x16ac55[_0xb00b('0x31')]};return db[_0xb00b('0x23')][_0xb00b('0x17')](_0x45ca74)['then'](function(_0x35f1ca){_0x2592cf[_0xb00b('0x17')]=_0x35f1ca;if(_0x550587[_0xb00b('0x26')][_0xb00b('0x38')]){_0x16ac55[_0xb00b('0x39')]=[{'all':!![]}];}return db[_0xb00b('0x23')]['findAll'](_0x16ac55);})[_0xb00b('0x1e')](function(_0x3beb8f){_0x2592cf['rows']=_0x3beb8f;return _0x2592cf;})[_0xb00b('0x1e')](respondWithFilteredResult(_0x4a635e,_0x16ac55))[_0xb00b('0x3a')](handleError(_0x4a635e,null));};exports[_0xb00b('0x3b')]=function(_0x2d8620,_0x2954e8){var _0x5636b1={'raw':![],'where':{'id':_0x2d8620[_0xb00b('0x3c')]['id']}},_0x14ff6a={};_0x14ff6a[_0xb00b('0x25')]=_[_0xb00b('0x3d')](db['CrmActionsList']['rawAttributes']);_0x14ff6a[_0xb00b('0x26')]=_[_0xb00b('0x3d')](_0x2d8620[_0xb00b('0x26')]);_0x14ff6a[_0xb00b('0x27')]=_[_0xb00b('0x28')](_0x14ff6a[_0xb00b('0x25')],_0x14ff6a[_0xb00b('0x26')]);_0x5636b1['attributes']=_[_0xb00b('0x28')](_0x14ff6a[_0xb00b('0x25')],qs[_0xb00b('0x2a')](_0x2d8620[_0xb00b('0x26')][_0xb00b('0x2a')]));_0x5636b1[_0xb00b('0x29')]=_0x5636b1[_0xb00b('0x29')][_0xb00b('0x3e')]?_0x5636b1[_0xb00b('0x29')]:_0x14ff6a[_0xb00b('0x25')];if(_0x2d8620[_0xb00b('0x26')][_0xb00b('0x38')]){_0x5636b1['include']=[{'all':!![]}];}_0x5636b1=_[_0xb00b('0x32')]({},_0x5636b1,_0x2d8620[_0xb00b('0x37')]);return db[_0xb00b('0x23')][_0xb00b('0x3f')](_0x5636b1)[_0xb00b('0x1e')](handleEntityNotFound(_0x2954e8,null))[_0xb00b('0x1e')](respondWithResult(_0x2954e8,null))[_0xb00b('0x3a')](handleError(_0x2954e8,null));};exports[_0xb00b('0x40')]=function(_0x10ba60,_0x103320){return db[_0xb00b('0x23')][_0xb00b('0x40')](_0x10ba60['body'],{})['then'](respondWithResult(_0x103320,0xc9))['catch'](handleError(_0x103320,null));};exports[_0xb00b('0x1d')]=function(_0x23d858,_0x481154){if(_0x23d858[_0xb00b('0x41')]['id']){delete _0x23d858[_0xb00b('0x41')]['id'];}return db[_0xb00b('0x23')][_0xb00b('0x3f')]({'where':{'id':_0x23d858['params']['id']}})['then'](handleEntityNotFound(_0x481154,null))[_0xb00b('0x1e')](saveUpdates(_0x23d858[_0xb00b('0x41')],null))['then'](respondWithResult(_0x481154,null))['catch'](handleError(_0x481154,null));};exports[_0xb00b('0x42')]=function(_0x3a205d,_0x4e0be4){return db[_0xb00b('0x23')]['find']({'where':{'id':_0x3a205d['params']['id']}})['then'](handleEntityNotFound(_0x4e0be4,null))[_0xb00b('0x1e')](removeEntity(_0x4e0be4,null))['catch'](handleError(_0x4e0be4,null));};exports[_0xb00b('0x43')]=function(_0x3178aa,_0x4b6482){return db[_0xb00b('0x23')][_0xb00b('0x43')]()[_0xb00b('0x1e')](respondWithResult(_0x4b6482,null))['catch'](handleError(_0x4b6482,null));};