Built motion from commit (unavailable).|2.4.4
[motion2.git] / server / api / crmWorkflow / crmWorkflow.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 _0xd4b3=['querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','json','offset','limit','set','reject','save','then','end','error','stack','name','send','index','CrmWorkflow','rawAttributes','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','map','type','field','options','count','includeAll','include','CrmTask','CrmActionsList','CrmWorkflowStep','CrmWorkflowNextStep','findAll','rows','catch','show','params','find','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','path','sox','to-csv','ejs','lodash','crypto','jsforce','desk.js'];(function(_0x831622,_0x490096){var _0x125ea3=function(_0x5c1c5b){while(--_0x5c1c5b){_0x831622['push'](_0x831622['shift']());}};_0x125ea3(++_0x490096);}(_0xd4b3,0x125));var _0x3d4b=function(_0xc1b0aa,_0x2e770d){_0xc1b0aa=_0xc1b0aa-0x0;var _0x2e9a84=_0xd4b3[_0xc1b0aa];return _0x2e9a84;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x3d4b('0x0'));var rimraf=require(_0x3d4b('0x1'));var zipdir=require(_0x3d4b('0x2'));var jsonpatch=require(_0x3d4b('0x3'));var rp=require(_0x3d4b('0x4'));var moment=require(_0x3d4b('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x3d4b('0x6'));var util=require('util');var path=require(_0x3d4b('0x7'));var sox=require(_0x3d4b('0x8'));var csv=require(_0x3d4b('0x9'));var ejs=require(_0x3d4b('0xa'));var fs=require('fs');var _=require(_0x3d4b('0xb'));var squel=require('squel');var crypto=require(_0x3d4b('0xc'));var jsforce=require(_0x3d4b('0xd'));var deskjs=require(_0x3d4b('0xe'));var toCsv=require(_0x3d4b('0x9'));var querystring=require(_0x3d4b('0xf'));var Papa=require('papaparse');var Redis=require(_0x3d4b('0x10'));var authService=require(_0x3d4b('0x11'));var qs=require(_0x3d4b('0x12'));var hardwareService=require(_0x3d4b('0x13'));var logger=require(_0x3d4b('0x14'))('api');var utils=require(_0x3d4b('0x15'));var config=require(_0x3d4b('0x16'));var db=require(_0x3d4b('0x17'))['db'];function respondWithStatusCode(_0x24243e,_0x137a98){_0x137a98=_0x137a98||0xcc;return function(_0x3a3ea0){if(_0x3a3ea0){return _0x24243e[_0x3d4b('0x18')](_0x137a98);}return _0x24243e[_0x3d4b('0x19')](_0x137a98)['end']();};}function respondWithResult(_0x1475a8,_0x4b4b9b){_0x4b4b9b=_0x4b4b9b||0xc8;return function(_0x20078f){if(_0x20078f){return _0x1475a8[_0x3d4b('0x19')](_0x4b4b9b)[_0x3d4b('0x1a')](_0x20078f);}};}function respondWithFilteredResult(_0x1f1b5c,_0x3ab060){return function(_0x198e8a){if(_0x198e8a){var _0x289d9e=_0x198e8a['count'],_0x500efc=_0x3ab060[_0x3d4b('0x1b')],_0x5bd648=_0x3ab060[_0x3d4b('0x1b')]+_0x3ab060[_0x3d4b('0x1c')],_0x22f058;if(_0x5bd648>=_0x289d9e){_0x5bd648=_0x289d9e;_0x22f058=0xc8;}else{_0x22f058=0xce;}_0x1f1b5c['status'](_0x22f058);return _0x1f1b5c[_0x3d4b('0x1d')]('Content-Range',_0x500efc+'-'+_0x5bd648+'/'+_0x289d9e)[_0x3d4b('0x1a')](_0x198e8a);}return null;};}function patchUpdates(_0x21f065){return function(_0x4793f8){try{jsonpatch['apply'](_0x4793f8,_0x21f065,!![]);}catch(_0x291f45){return BPromise[_0x3d4b('0x1e')](_0x291f45);}return _0x4793f8[_0x3d4b('0x1f')]();};}function saveUpdates(_0x4167be,_0x999873){return function(_0x3354b6){if(_0x3354b6){return _0x3354b6['update'](_0x4167be)[_0x3d4b('0x20')](function(_0x14ba6c){return _0x14ba6c;});}return null;};}function removeEntity(_0x30caa9,_0x5e062e){return function(_0x4e15ea){if(_0x4e15ea){return _0x4e15ea['destroy']()[_0x3d4b('0x20')](function(){_0x30caa9[_0x3d4b('0x19')](0xcc)[_0x3d4b('0x21')]();});}};}function handleEntityNotFound(_0x549379,_0x502e46){return function(_0xf76a4){if(!_0xf76a4){_0x549379['sendStatus'](0x194);}return _0xf76a4;};}function handleError(_0x49cb86,_0x9bf256){_0x9bf256=_0x9bf256||0x1f4;return function(_0x39c093){logger[_0x3d4b('0x22')](_0x39c093[_0x3d4b('0x23')]);if(_0x39c093[_0x3d4b('0x24')]){delete _0x39c093[_0x3d4b('0x24')];}_0x49cb86[_0x3d4b('0x19')](_0x9bf256)[_0x3d4b('0x25')](_0x39c093);};}exports[_0x3d4b('0x26')]=function(_0x245e2d,_0x12cc8b){var _0x456f54={},_0x3105f0={},_0x23fcdf={'count':0x0,'rows':[]};var _0x72ed99=db[_0x3d4b('0x27')][_0x3d4b('0x28')];_0x3105f0[_0x3d4b('0x29')]=_['keys'](_0x72ed99);_0x3105f0[_0x3d4b('0x2a')]=_[_0x3d4b('0x2b')](_0x245e2d[_0x3d4b('0x2a')]);_0x3105f0[_0x3d4b('0x2c')]=_['intersection'](_0x3105f0[_0x3d4b('0x29')],_0x3105f0[_0x3d4b('0x2a')]);_0x456f54[_0x3d4b('0x2d')]=_[_0x3d4b('0x2e')](_0x3105f0['model'],qs[_0x3d4b('0x2f')](_0x245e2d['query']['fields']));_0x456f54[_0x3d4b('0x2d')]=_0x456f54[_0x3d4b('0x2d')][_0x3d4b('0x30')]?_0x456f54[_0x3d4b('0x2d')]:_0x3105f0[_0x3d4b('0x29')];if(!_0x245e2d[_0x3d4b('0x2a')][_0x3d4b('0x31')](_0x3d4b('0x32'))){_0x456f54['limit']=qs[_0x3d4b('0x1c')](_0x245e2d[_0x3d4b('0x2a')]['limit']);_0x456f54[_0x3d4b('0x1b')]=qs[_0x3d4b('0x1b')](_0x245e2d['query']['offset']);}_0x456f54[_0x3d4b('0x33')]=qs[_0x3d4b('0x34')](_0x245e2d[_0x3d4b('0x2a')][_0x3d4b('0x34')]);_0x456f54[_0x3d4b('0x35')]=qs[_0x3d4b('0x2c')](_[_0x3d4b('0x36')](_0x245e2d[_0x3d4b('0x2a')],_0x3105f0[_0x3d4b('0x2c')]));if(_0x245e2d[_0x3d4b('0x2a')][_0x3d4b('0x37')]){_0x456f54['where']=_[_0x3d4b('0x38')](_0x456f54[_0x3d4b('0x35')],{'$or':_[_0x3d4b('0x39')](_0x72ed99,function(_0x2711a1){if(_0x2711a1[_0x3d4b('0x3a')]['key']!=='VIRTUAL'){var _0xcf39d0={};_0xcf39d0[_0x2711a1[_0x3d4b('0x3b')]]={'$like':'%'+_0x245e2d['query']['filter']+'%'};return _0xcf39d0;}})});}_0x456f54=_['merge']({},_0x456f54,_0x245e2d[_0x3d4b('0x3c')]);var _0xbbb368={'where':_0x456f54[_0x3d4b('0x35')]};return db[_0x3d4b('0x27')][_0x3d4b('0x3d')](_0xbbb368)[_0x3d4b('0x20')](function(_0x480290){_0x23fcdf[_0x3d4b('0x3d')]=_0x480290;if(_0x245e2d[_0x3d4b('0x2a')][_0x3d4b('0x3e')]){_0x456f54[_0x3d4b('0x3f')]=[{'model':db['CrmWorkflowStep'],'include':[{'model':db[_0x3d4b('0x40')],'include':[{'model':db[_0x3d4b('0x41')]}]},{'model':db[_0x3d4b('0x42')],'as':_0x3d4b('0x43'),'through':{'attributes':[]}}]}];}return db[_0x3d4b('0x27')][_0x3d4b('0x44')](_0x456f54);})['then'](function(_0x30dc75){_0x23fcdf[_0x3d4b('0x45')]=_0x30dc75;return _0x23fcdf;})[_0x3d4b('0x20')](respondWithFilteredResult(_0x12cc8b,_0x456f54))[_0x3d4b('0x46')](handleError(_0x12cc8b,null));};exports[_0x3d4b('0x47')]=function(_0x44fbf4,_0x5b274e){var _0x482865={'raw':![],'where':{'id':_0x44fbf4[_0x3d4b('0x48')]['id']}},_0x419c19={};_0x419c19['model']=_[_0x3d4b('0x2b')](db['CrmWorkflow'][_0x3d4b('0x28')]);_0x419c19[_0x3d4b('0x2a')]=_[_0x3d4b('0x2b')](_0x44fbf4[_0x3d4b('0x2a')]);_0x419c19[_0x3d4b('0x2c')]=_[_0x3d4b('0x2e')](_0x419c19[_0x3d4b('0x29')],_0x419c19[_0x3d4b('0x2a')]);_0x482865[_0x3d4b('0x2d')]=_[_0x3d4b('0x2e')](_0x419c19[_0x3d4b('0x29')],qs[_0x3d4b('0x2f')](_0x44fbf4['query']['fields']));_0x482865[_0x3d4b('0x2d')]=_0x482865[_0x3d4b('0x2d')][_0x3d4b('0x30')]?_0x482865[_0x3d4b('0x2d')]:_0x419c19[_0x3d4b('0x29')];if(_0x44fbf4[_0x3d4b('0x2a')][_0x3d4b('0x3e')]){_0x482865[_0x3d4b('0x3f')]=[{'all':!![]}];}_0x482865=_['merge']({},_0x482865,_0x44fbf4[_0x3d4b('0x3c')]);return db['CrmWorkflow'][_0x3d4b('0x49')](_0x482865)['then'](handleEntityNotFound(_0x5b274e,null))[_0x3d4b('0x20')](respondWithResult(_0x5b274e,null))['catch'](handleError(_0x5b274e,null));};exports[_0x3d4b('0x4a')]=function(_0xefb372,_0x3a11b1){return db[_0x3d4b('0x27')]['create'](_0xefb372[_0x3d4b('0x4b')],{})[_0x3d4b('0x20')](respondWithResult(_0x3a11b1,0xc9))['catch'](handleError(_0x3a11b1,null));};exports['update']=function(_0x15d148,_0x5ce793){if(_0x15d148[_0x3d4b('0x4b')]['id']){delete _0x15d148[_0x3d4b('0x4b')]['id'];}return db['CrmWorkflow']['find']({'where':{'id':_0x15d148[_0x3d4b('0x48')]['id']}})[_0x3d4b('0x20')](handleEntityNotFound(_0x5ce793,null))['then'](saveUpdates(_0x15d148['body'],null))[_0x3d4b('0x20')](respondWithResult(_0x5ce793,null))[_0x3d4b('0x46')](handleError(_0x5ce793,null));};exports['destroy']=function(_0x55ad0f,_0x1b56c0){return db['CrmWorkflow']['find']({'where':{'id':_0x55ad0f['params']['id']}})[_0x3d4b('0x20')](handleEntityNotFound(_0x1b56c0,null))[_0x3d4b('0x20')](removeEntity(_0x1b56c0,null))[_0x3d4b('0x46')](handleError(_0x1b56c0,null));};exports[_0x3d4b('0x4c')]=function(_0x1ced44,_0x530928){return db[_0x3d4b('0x27')][_0x3d4b('0x4c')]()[_0x3d4b('0x20')](respondWithResult(_0x530928,null))[_0x3d4b('0x46')](handleError(_0x530928,null));};