Built motion from commit (unavailable).|2.4.4
[motion2.git] / server / api / disposition / disposition.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 _0xf852=['json','count','offset','limit','set','Content-Range','apply','reject','save','update','destroy','get','Dispositions','UserProfileResource','then','error','name','index','Disposition','model','query','keys','filters','intersection','fields','length','attributes','nolimit','order','sort','where','pick','filter','map','type','VIRTUAL','field','merge','options','includeAll','findAll','rows','catch','show','params','rawAttributes','include','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','end','status'];(function(_0x1e5a6b,_0x125d7d){var _0x581c51=function(_0x52cfef){while(--_0x52cfef){_0x1e5a6b['push'](_0x1e5a6b['shift']());}};_0x581c51(++_0x125d7d);}(_0xf852,0x1d3));var _0x2f85=function(_0x4ff0d6,_0x368b2b){_0x4ff0d6=_0x4ff0d6-0x0;var _0xebfb05=_0xf852[_0x4ff0d6];return _0xebfb05;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x2f85('0x0'));var rp=require('request-promise');var moment=require(_0x2f85('0x1'));var BPromise=require(_0x2f85('0x2'));var Mustache=require(_0x2f85('0x3'));var util=require(_0x2f85('0x4'));var path=require(_0x2f85('0x5'));var sox=require(_0x2f85('0x6'));var csv=require(_0x2f85('0x7'));var ejs=require(_0x2f85('0x8'));var fs=require('fs');var _=require(_0x2f85('0x9'));var squel=require(_0x2f85('0xa'));var crypto=require(_0x2f85('0xb'));var jsforce=require(_0x2f85('0xc'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x2f85('0xd'));var Papa=require(_0x2f85('0xe'));var Redis=require('ioredis');var authService=require(_0x2f85('0xf'));var qs=require(_0x2f85('0x10'));var hardwareService=require(_0x2f85('0x11'));var logger=require(_0x2f85('0x12'))('api');var utils=require(_0x2f85('0x13'));var config=require(_0x2f85('0x14'));var db=require(_0x2f85('0x15'))['db'];function respondWithStatusCode(_0x4d397d,_0x127014){_0x127014=_0x127014||0xcc;return function(_0x2afe36){if(_0x2afe36){return _0x4d397d[_0x2f85('0x16')](_0x127014);}return _0x4d397d['status'](_0x127014)[_0x2f85('0x17')]();};}function respondWithResult(_0x2e6f34,_0x17beb4){_0x17beb4=_0x17beb4||0xc8;return function(_0x1596ce){if(_0x1596ce){return _0x2e6f34[_0x2f85('0x18')](_0x17beb4)[_0x2f85('0x19')](_0x1596ce);}};}function respondWithFilteredResult(_0x4b94d4,_0x37ff88){return function(_0x4224dc){if(_0x4224dc){var _0xa63543=_0x4224dc[_0x2f85('0x1a')],_0x19fae3=_0x37ff88[_0x2f85('0x1b')],_0x4a1a0c=_0x37ff88['offset']+_0x37ff88[_0x2f85('0x1c')],_0x5f0d1d;if(_0x4a1a0c>=_0xa63543){_0x4a1a0c=_0xa63543;_0x5f0d1d=0xc8;}else{_0x5f0d1d=0xce;}_0x4b94d4[_0x2f85('0x18')](_0x5f0d1d);return _0x4b94d4[_0x2f85('0x1d')](_0x2f85('0x1e'),_0x19fae3+'-'+_0x4a1a0c+'/'+_0xa63543)[_0x2f85('0x19')](_0x4224dc);}return null;};}function patchUpdates(_0x2c919a){return function(_0x1a4d13){try{jsonpatch[_0x2f85('0x1f')](_0x1a4d13,_0x2c919a,!![]);}catch(_0x2b647f){return BPromise[_0x2f85('0x20')](_0x2b647f);}return _0x1a4d13[_0x2f85('0x21')]();};}function saveUpdates(_0x43b7d0,_0x1a6842){return function(_0x2fe5d7){if(_0x2fe5d7){return _0x2fe5d7[_0x2f85('0x22')](_0x43b7d0)['then'](function(_0x5c9780){return _0x5c9780;});}return null;};}function removeEntity(_0x2d3b6f,_0x484ebd){return function(_0x37111e){if(_0x37111e){return _0x37111e[_0x2f85('0x23')]()['then'](function(){var _0x4991b2=_0x37111e[_0x2f85('0x24')]({'plain':!![]});var _0x9e8f8e=_0x2f85('0x25');return db[_0x2f85('0x26')][_0x2f85('0x23')]({'where':{'type':_0x9e8f8e,'resourceId':_0x4991b2['id']}})[_0x2f85('0x27')](function(){return _0x37111e;});})['then'](function(){_0x2d3b6f['status'](0xcc)[_0x2f85('0x17')]();});}};}function handleEntityNotFound(_0x30d261,_0x344e0c){return function(_0xbe0a18){if(!_0xbe0a18){_0x30d261[_0x2f85('0x16')](0x194);}return _0xbe0a18;};}function handleError(_0x5c6470,_0x89c9b3){_0x89c9b3=_0x89c9b3||0x1f4;return function(_0x53ab71){logger[_0x2f85('0x28')](_0x53ab71['stack']);if(_0x53ab71[_0x2f85('0x29')]){delete _0x53ab71[_0x2f85('0x29')];}_0x5c6470[_0x2f85('0x18')](_0x89c9b3)['send'](_0x53ab71);};}exports[_0x2f85('0x2a')]=function(_0x5b7352,_0x3cac18){var _0x20e5da={},_0x7a6507={},_0x3cb32e={'count':0x0,'rows':[]};var _0x21b175=db[_0x2f85('0x2b')]['rawAttributes'];_0x7a6507[_0x2f85('0x2c')]=_['keys'](_0x21b175);_0x7a6507[_0x2f85('0x2d')]=_[_0x2f85('0x2e')](_0x5b7352[_0x2f85('0x2d')]);_0x7a6507[_0x2f85('0x2f')]=_[_0x2f85('0x30')](_0x7a6507[_0x2f85('0x2c')],_0x7a6507[_0x2f85('0x2d')]);_0x20e5da['attributes']=_['intersection'](_0x7a6507[_0x2f85('0x2c')],qs['fields'](_0x5b7352[_0x2f85('0x2d')][_0x2f85('0x31')]));_0x20e5da['attributes']=_0x20e5da['attributes'][_0x2f85('0x32')]?_0x20e5da[_0x2f85('0x33')]:_0x7a6507[_0x2f85('0x2c')];if(!_0x5b7352[_0x2f85('0x2d')]['hasOwnProperty'](_0x2f85('0x34'))){_0x20e5da[_0x2f85('0x1c')]=qs[_0x2f85('0x1c')](_0x5b7352[_0x2f85('0x2d')][_0x2f85('0x1c')]);_0x20e5da['offset']=qs[_0x2f85('0x1b')](_0x5b7352['query'][_0x2f85('0x1b')]);}_0x20e5da[_0x2f85('0x35')]=qs[_0x2f85('0x36')](_0x5b7352[_0x2f85('0x2d')][_0x2f85('0x36')]);_0x20e5da[_0x2f85('0x37')]=qs['filters'](_[_0x2f85('0x38')](_0x5b7352[_0x2f85('0x2d')],_0x7a6507[_0x2f85('0x2f')]));if(_0x5b7352[_0x2f85('0x2d')][_0x2f85('0x39')]){_0x20e5da[_0x2f85('0x37')]=_['merge'](_0x20e5da['where'],{'$or':_[_0x2f85('0x3a')](_0x21b175,function(_0x597fe9){if(_0x597fe9[_0x2f85('0x3b')]['key']!==_0x2f85('0x3c')){var _0x452786={};_0x452786[_0x597fe9[_0x2f85('0x3d')]]={'$like':'%'+_0x5b7352[_0x2f85('0x2d')]['filter']+'%'};return _0x452786;}})});}_0x20e5da=_[_0x2f85('0x3e')]({},_0x20e5da,_0x5b7352[_0x2f85('0x3f')]);var _0x285d14={'where':_0x20e5da[_0x2f85('0x37')]};return db[_0x2f85('0x2b')][_0x2f85('0x1a')](_0x285d14)[_0x2f85('0x27')](function(_0x109509){_0x3cb32e['count']=_0x109509;if(_0x5b7352[_0x2f85('0x2d')][_0x2f85('0x40')]){_0x20e5da['include']=[{'all':!![]}];}return db['Disposition'][_0x2f85('0x41')](_0x20e5da);})[_0x2f85('0x27')](function(_0x448a4d){_0x3cb32e[_0x2f85('0x42')]=_0x448a4d;return _0x3cb32e;})['then'](respondWithFilteredResult(_0x3cac18,_0x20e5da))[_0x2f85('0x43')](handleError(_0x3cac18,null));};exports[_0x2f85('0x44')]=function(_0x1cb828,_0x250253){var _0x4a3261={'raw':!![],'where':{'id':_0x1cb828[_0x2f85('0x45')]['id']}},_0x3ad7ab={};_0x3ad7ab[_0x2f85('0x2c')]=_[_0x2f85('0x2e')](db[_0x2f85('0x2b')][_0x2f85('0x46')]);_0x3ad7ab[_0x2f85('0x2d')]=_[_0x2f85('0x2e')](_0x1cb828[_0x2f85('0x2d')]);_0x3ad7ab[_0x2f85('0x2f')]=_['intersection'](_0x3ad7ab[_0x2f85('0x2c')],_0x3ad7ab[_0x2f85('0x2d')]);_0x4a3261[_0x2f85('0x33')]=_['intersection'](_0x3ad7ab['model'],qs[_0x2f85('0x31')](_0x1cb828[_0x2f85('0x2d')][_0x2f85('0x31')]));_0x4a3261['attributes']=_0x4a3261['attributes']['length']?_0x4a3261[_0x2f85('0x33')]:_0x3ad7ab[_0x2f85('0x2c')];if(_0x1cb828[_0x2f85('0x2d')][_0x2f85('0x40')]){_0x4a3261[_0x2f85('0x47')]=[{'all':!![]}];}_0x4a3261=_[_0x2f85('0x3e')]({},_0x4a3261,_0x1cb828['options']);return db[_0x2f85('0x2b')][_0x2f85('0x48')](_0x4a3261)[_0x2f85('0x27')](handleEntityNotFound(_0x250253,null))['then'](respondWithResult(_0x250253,null))[_0x2f85('0x43')](handleError(_0x250253,null));};exports[_0x2f85('0x49')]=function(_0x4b9890,_0x5cc028){return db['Disposition'][_0x2f85('0x49')](_0x4b9890[_0x2f85('0x4a')],{})[_0x2f85('0x27')](function(_0x666cae){var _0x25446b=_0x4b9890[_0x2f85('0x4b')][_0x2f85('0x24')]({'plain':!![]});if(!_0x25446b)throw new Error(_0x2f85('0x4c'));if(_0x25446b[_0x2f85('0x4d')]===_0x2f85('0x4b')){var _0x1efc54=_0x666cae['get']({'plain':!![]});var _0xdfb34b=_0x2f85('0x25');return db[_0x2f85('0x4e')]['find']({'where':{'name':_0xdfb34b,'userProfileId':_0x25446b[_0x2f85('0x4f')]},'raw':!![]})['then'](function(_0x308afd){if(_0x308afd&&_0x308afd[_0x2f85('0x50')]===0x0){return db[_0x2f85('0x26')]['create']({'name':_0x1efc54[_0x2f85('0x29')],'resourceId':_0x1efc54['id'],'type':_0x308afd[_0x2f85('0x29')],'sectionId':_0x308afd['id']},{})['then'](function(){return _0x666cae;});}else{return _0x666cae;}})['catch'](function(_0x2ba399){logger[_0x2f85('0x28')](_0x2f85('0x51'),_0x2ba399);throw _0x2ba399;});}return _0x666cae;})['then'](respondWithResult(_0x5cc028,0xc9))['catch'](handleError(_0x5cc028,null));};exports[_0x2f85('0x22')]=function(_0xdaaa9a,_0x49d312){if(_0xdaaa9a['body']['id']){delete _0xdaaa9a[_0x2f85('0x4a')]['id'];}return db[_0x2f85('0x2b')]['find']({'where':{'id':_0xdaaa9a['params']['id']}})[_0x2f85('0x27')](handleEntityNotFound(_0x49d312,null))[_0x2f85('0x27')](saveUpdates(_0xdaaa9a['body'],null))[_0x2f85('0x27')](respondWithResult(_0x49d312,null))[_0x2f85('0x43')](handleError(_0x49d312,null));};exports[_0x2f85('0x23')]=function(_0x221355,_0x29a3e3){return db[_0x2f85('0x2b')][_0x2f85('0x48')]({'where':{'id':_0x221355[_0x2f85('0x45')]['id']}})[_0x2f85('0x27')](handleEntityNotFound(_0x29a3e3,null))[_0x2f85('0x27')](removeEntity(_0x29a3e3,null))[_0x2f85('0x43')](handleError(_0x29a3e3,null));};