Built motion from commit 3c2ce842.|2.6.31
[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 _0xba6e=['pick','filter','where','merge','options','include','findAll','rows','catch','show','params','includeAll','find','create','body','user','role','UserProfileSection','userProfileId','autoAssociation','eml-format','rimraf','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','end','status','json','offset','undefined','count','limit','set','Content-Range','apply','update','then','destroy','get','Dispositions','UserProfileResource','stack','name','send','index','map','Disposition','rawAttributes','fieldName','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort'];(function(_0x382c73,_0x199cab){var _0x1dd0bf=function(_0x358747){while(--_0x358747){_0x382c73['push'](_0x382c73['shift']());}};_0x1dd0bf(++_0x199cab);}(_0xba6e,0x168));var _0xeba6=function(_0xf9ce28,_0x3571a5){_0xf9ce28=_0xf9ce28-0x0;var _0x96578e=_0xba6e[_0xf9ce28];return _0x96578e;};'use strict';var emlformat=require(_0xeba6('0x0'));var rimraf=require(_0xeba6('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xeba6('0x2'));var rp=require('request-promise');var moment=require(_0xeba6('0x3'));var BPromise=require(_0xeba6('0x4'));var Mustache=require(_0xeba6('0x5'));var util=require(_0xeba6('0x6'));var path=require(_0xeba6('0x7'));var sox=require(_0xeba6('0x8'));var csv=require(_0xeba6('0x9'));var ejs=require(_0xeba6('0xa'));var fs=require('fs');var fs_extra=require(_0xeba6('0xb'));var _=require(_0xeba6('0xc'));var squel=require(_0xeba6('0xd'));var crypto=require(_0xeba6('0xe'));var jsforce=require(_0xeba6('0xf'));var deskjs=require('desk.js');var toCsv=require(_0xeba6('0x9'));var querystring=require(_0xeba6('0x10'));var Papa=require(_0xeba6('0x11'));var Redis=require(_0xeba6('0x12'));var authService=require(_0xeba6('0x13'));var qs=require(_0xeba6('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xeba6('0x15'));var logger=require(_0xeba6('0x16'))(_0xeba6('0x17'));var utils=require(_0xeba6('0x18'));var config=require(_0xeba6('0x19'));var licenseUtil=require('../../config/license/util');var db=require(_0xeba6('0x1a'))['db'];function respondWithStatusCode(_0xc6c95f,_0x2847cf){_0x2847cf=_0x2847cf||0xcc;return function(_0x9b58c9){if(_0x9b58c9){return _0xc6c95f[_0xeba6('0x1b')](_0x2847cf);}return _0xc6c95f['status'](_0x2847cf)[_0xeba6('0x1c')]();};}function respondWithResult(_0x48abfc,_0x2a9607){_0x2a9607=_0x2a9607||0xc8;return function(_0x232ac1){if(_0x232ac1){return _0x48abfc[_0xeba6('0x1d')](_0x2a9607)[_0xeba6('0x1e')](_0x232ac1);}};}function respondWithFilteredResult(_0x25d2f9,_0x32c8aa){return function(_0x41c36f){if(_0x41c36f){var _0x4c82d2=typeof _0x32c8aa[_0xeba6('0x1f')]===_0xeba6('0x20')&&typeof _0x32c8aa['limit']===_0xeba6('0x20');var _0x1948f3=_0x41c36f[_0xeba6('0x21')];var _0xd632dc=_0x4c82d2?0x0:_0x32c8aa[_0xeba6('0x1f')];var _0x346d44=_0x4c82d2?_0x41c36f[_0xeba6('0x21')]:_0x32c8aa[_0xeba6('0x1f')]+_0x32c8aa[_0xeba6('0x22')];var _0x44ed37;if(_0x346d44>=_0x1948f3){_0x346d44=_0x1948f3;_0x44ed37=0xc8;}else{_0x44ed37=0xce;}_0x25d2f9[_0xeba6('0x1d')](_0x44ed37);return _0x25d2f9[_0xeba6('0x23')](_0xeba6('0x24'),_0xd632dc+'-'+_0x346d44+'/'+_0x1948f3)[_0xeba6('0x1e')](_0x41c36f);}return null;};}function patchUpdates(_0x5a7c69){return function(_0x46856f){try{jsonpatch[_0xeba6('0x25')](_0x46856f,_0x5a7c69,!![]);}catch(_0x33ce8a){return BPromise['reject'](_0x33ce8a);}return _0x46856f['save']();};}function saveUpdates(_0x43e6c4,_0x1264fc){return function(_0x1b61da){if(_0x1b61da){return _0x1b61da[_0xeba6('0x26')](_0x43e6c4)[_0xeba6('0x27')](function(_0x2c55a4){return _0x2c55a4;});}return null;};}function removeEntity(_0x2423ee,_0x5d0889){return function(_0x2d77e3){if(_0x2d77e3){return _0x2d77e3[_0xeba6('0x28')]()[_0xeba6('0x27')](function(){var _0x57d141=_0x2d77e3[_0xeba6('0x29')]({'plain':!![]});var _0x3a7e81=_0xeba6('0x2a');return db[_0xeba6('0x2b')][_0xeba6('0x28')]({'where':{'type':_0x3a7e81,'resourceId':_0x57d141['id']}})[_0xeba6('0x27')](function(){return _0x2d77e3;});})['then'](function(){_0x2423ee[_0xeba6('0x1d')](0xcc)[_0xeba6('0x1c')]();});}};}function handleEntityNotFound(_0x2b6017,_0xfabfd2){return function(_0x57a506){if(!_0x57a506){_0x2b6017[_0xeba6('0x1b')](0x194);}return _0x57a506;};}function handleError(_0x555d74,_0x4e09d9){_0x4e09d9=_0x4e09d9||0x1f4;return function(_0x288a08){logger['error'](_0x288a08[_0xeba6('0x2c')]);if(_0x288a08[_0xeba6('0x2d')]){delete _0x288a08['name'];}_0x555d74['status'](_0x4e09d9)[_0xeba6('0x2e')](_0x288a08);};}exports[_0xeba6('0x2f')]=function(_0x5c5d5f,_0x42e7d0){var _0x3327dc={},_0x5c6797={},_0x2f8ef6={'count':0x0,'rows':[]};var _0x5dc9a7=_[_0xeba6('0x30')](db[_0xeba6('0x31')][_0xeba6('0x32')],function(_0x56bcde){return{'name':_0x56bcde[_0xeba6('0x33')],'type':_0x56bcde['type'][_0xeba6('0x34')]};});_0x5c6797[_0xeba6('0x35')]=_['map'](_0x5dc9a7,_0xeba6('0x2d'));_0x5c6797[_0xeba6('0x36')]=_[_0xeba6('0x37')](_0x5c5d5f[_0xeba6('0x36')]);_0x5c6797[_0xeba6('0x38')]=_[_0xeba6('0x39')](_0x5c6797[_0xeba6('0x35')],_0x5c6797[_0xeba6('0x36')]);_0x3327dc[_0xeba6('0x3a')]=_[_0xeba6('0x39')](_0x5c6797['model'],qs[_0xeba6('0x3b')](_0x5c5d5f[_0xeba6('0x36')][_0xeba6('0x3b')]));_0x3327dc[_0xeba6('0x3a')]=_0x3327dc[_0xeba6('0x3a')][_0xeba6('0x3c')]?_0x3327dc[_0xeba6('0x3a')]:_0x5c6797[_0xeba6('0x35')];if(!_0x5c5d5f['query'][_0xeba6('0x3d')](_0xeba6('0x3e'))){_0x3327dc[_0xeba6('0x22')]=qs['limit'](_0x5c5d5f[_0xeba6('0x36')][_0xeba6('0x22')]);_0x3327dc[_0xeba6('0x1f')]=qs[_0xeba6('0x1f')](_0x5c5d5f['query'][_0xeba6('0x1f')]);}_0x3327dc[_0xeba6('0x3f')]=qs[_0xeba6('0x40')](_0x5c5d5f[_0xeba6('0x36')][_0xeba6('0x40')]);_0x3327dc['where']=qs[_0xeba6('0x38')](_[_0xeba6('0x41')](_0x5c5d5f[_0xeba6('0x36')],_0x5c6797[_0xeba6('0x38')]),_0x5dc9a7);if(_0x5c5d5f[_0xeba6('0x36')][_0xeba6('0x42')]){_0x3327dc[_0xeba6('0x43')]=_[_0xeba6('0x44')](_0x3327dc[_0xeba6('0x43')],{'$or':_['map'](_0x5dc9a7,function(_0x3ab15a){if(_0x3ab15a['type']!=='VIRTUAL'){var _0x55770a={};_0x55770a[_0x3ab15a['name']]={'$like':'%'+_0x5c5d5f['query'][_0xeba6('0x42')]+'%'};return _0x55770a;}})});}_0x3327dc=_[_0xeba6('0x44')]({},_0x3327dc,_0x5c5d5f[_0xeba6('0x45')]);var _0x55cb23={'where':_0x3327dc[_0xeba6('0x43')]};return db[_0xeba6('0x31')][_0xeba6('0x21')](_0x55cb23)[_0xeba6('0x27')](function(_0x2af9c0){_0x2f8ef6[_0xeba6('0x21')]=_0x2af9c0;if(_0x5c5d5f[_0xeba6('0x36')]['includeAll']){_0x3327dc[_0xeba6('0x46')]=[{'all':!![]}];}return db[_0xeba6('0x31')][_0xeba6('0x47')](_0x3327dc);})[_0xeba6('0x27')](function(_0x1b4538){_0x2f8ef6[_0xeba6('0x48')]=_0x1b4538;return _0x2f8ef6;})[_0xeba6('0x27')](respondWithFilteredResult(_0x42e7d0,_0x3327dc))[_0xeba6('0x49')](handleError(_0x42e7d0,null));};exports[_0xeba6('0x4a')]=function(_0x45edc1,_0x59b8f3){var _0x270272={'raw':!![],'where':{'id':_0x45edc1[_0xeba6('0x4b')]['id']}},_0x2c294c={};_0x2c294c['model']=_['keys'](db[_0xeba6('0x31')][_0xeba6('0x32')]);_0x2c294c[_0xeba6('0x36')]=_[_0xeba6('0x37')](_0x45edc1['query']);_0x2c294c[_0xeba6('0x38')]=_[_0xeba6('0x39')](_0x2c294c[_0xeba6('0x35')],_0x2c294c['query']);_0x270272['attributes']=_[_0xeba6('0x39')](_0x2c294c[_0xeba6('0x35')],qs[_0xeba6('0x3b')](_0x45edc1['query'][_0xeba6('0x3b')]));_0x270272['attributes']=_0x270272['attributes']['length']?_0x270272[_0xeba6('0x3a')]:_0x2c294c[_0xeba6('0x35')];if(_0x45edc1[_0xeba6('0x36')][_0xeba6('0x4c')]){_0x270272['include']=[{'all':!![]}];}_0x270272=_[_0xeba6('0x44')]({},_0x270272,_0x45edc1[_0xeba6('0x45')]);return db[_0xeba6('0x31')][_0xeba6('0x4d')](_0x270272)[_0xeba6('0x27')](handleEntityNotFound(_0x59b8f3,null))[_0xeba6('0x27')](respondWithResult(_0x59b8f3,null))['catch'](handleError(_0x59b8f3,null));};exports[_0xeba6('0x4e')]=function(_0x1b3e28,_0x1ce105){return db[_0xeba6('0x31')][_0xeba6('0x4e')](_0x1b3e28[_0xeba6('0x4f')],{})[_0xeba6('0x27')](function(_0x3c314e){var _0x3cc7fd=_0x1b3e28[_0xeba6('0x50')][_0xeba6('0x29')]({'plain':!![]});if(!_0x3cc7fd)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x3cc7fd[_0xeba6('0x51')]==='user'){var _0x2cc00c=_0x3c314e[_0xeba6('0x29')]({'plain':!![]});var _0x5a997d=_0xeba6('0x2a');return db[_0xeba6('0x52')]['find']({'where':{'name':_0x5a997d,'userProfileId':_0x3cc7fd[_0xeba6('0x53')]},'raw':!![]})[_0xeba6('0x27')](function(_0x181577){if(_0x181577&&_0x181577[_0xeba6('0x54')]===0x0){return db[_0xeba6('0x2b')]['create']({'name':_0x2cc00c[_0xeba6('0x2d')],'resourceId':_0x2cc00c['id'],'type':_0x181577[_0xeba6('0x2d')],'sectionId':_0x181577['id']},{})[_0xeba6('0x27')](function(){return _0x3c314e;});}else{return _0x3c314e;}})[_0xeba6('0x49')](function(_0xbb03d5){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0xbb03d5);throw _0xbb03d5;});}return _0x3c314e;})[_0xeba6('0x27')](respondWithResult(_0x1ce105,0xc9))[_0xeba6('0x49')](handleError(_0x1ce105,null));};exports[_0xeba6('0x26')]=function(_0x6ddbb3,_0x4c8677){if(_0x6ddbb3['body']['id']){delete _0x6ddbb3['body']['id'];}return db['Disposition']['find']({'where':{'id':_0x6ddbb3[_0xeba6('0x4b')]['id']}})[_0xeba6('0x27')](handleEntityNotFound(_0x4c8677,null))[_0xeba6('0x27')](saveUpdates(_0x6ddbb3['body'],null))[_0xeba6('0x27')](respondWithResult(_0x4c8677,null))[_0xeba6('0x49')](handleError(_0x4c8677,null));};exports[_0xeba6('0x28')]=function(_0x50f873,_0x314363){return db[_0xeba6('0x31')][_0xeba6('0x4d')]({'where':{'id':_0x50f873[_0xeba6('0x4b')]['id']}})['then'](handleEntityNotFound(_0x314363,null))[_0xeba6('0x27')](removeEntity(_0x314363,null))['catch'](handleError(_0x314363,null));};