4679e7b433538f031bac6ee0f8017efee183b1d3
[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 _0xc4c9=['update','Dispositions','UserProfileResource','then','stack','name','index','map','Disposition','rawAttributes','fieldName','type','query','keys','filters','intersection','attributes','model','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','include','catch','show','params','includeAll','options','create','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','find','autoAssociation','error','body','destroy','rimraf','zip-dir','fast-json-patch','moment','mustache','path','to-csv','ejs','lodash','squel','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save'];(function(_0x592edb,_0x491569){var _0x432253=function(_0x45beca){while(--_0x45beca){_0x592edb['push'](_0x592edb['shift']());}};_0x432253(++_0x491569);}(_0xc4c9,0xcf));var _0x9c4c=function(_0x144150,_0x264032){_0x144150=_0x144150-0x0;var _0x2aaecd=_0xc4c9[_0x144150];return _0x2aaecd;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x9c4c('0x0'));var zipdir=require(_0x9c4c('0x1'));var jsonpatch=require(_0x9c4c('0x2'));var rp=require('request-promise');var moment=require(_0x9c4c('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x9c4c('0x4'));var util=require('util');var path=require(_0x9c4c('0x5'));var sox=require('sox');var csv=require(_0x9c4c('0x6'));var ejs=require(_0x9c4c('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x9c4c('0x8'));var squel=require(_0x9c4c('0x9'));var crypto=require('crypto');var jsforce=require(_0x9c4c('0xa'));var deskjs=require('desk.js');var toCsv=require(_0x9c4c('0x6'));var querystring=require(_0x9c4c('0xb'));var Papa=require(_0x9c4c('0xc'));var Redis=require(_0x9c4c('0xd'));var authService=require(_0x9c4c('0xe'));var qs=require(_0x9c4c('0xf'));var as=require(_0x9c4c('0x10'));var hardwareService=require(_0x9c4c('0x11'));var logger=require(_0x9c4c('0x12'))(_0x9c4c('0x13'));var utils=require(_0x9c4c('0x14'));var config=require(_0x9c4c('0x15'));var licenseUtil=require(_0x9c4c('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x53b745,_0x4481be){_0x4481be=_0x4481be||0xcc;return function(_0x10b83d){if(_0x10b83d){return _0x53b745[_0x9c4c('0x17')](_0x4481be);}return _0x53b745[_0x9c4c('0x18')](_0x4481be)[_0x9c4c('0x19')]();};}function respondWithResult(_0x34b69c,_0x2ce2cc){_0x2ce2cc=_0x2ce2cc||0xc8;return function(_0x183290){if(_0x183290){return _0x34b69c['status'](_0x2ce2cc)[_0x9c4c('0x1a')](_0x183290);}};}function respondWithFilteredResult(_0x4a0bb6,_0x28d807){return function(_0x1b3fca){if(_0x1b3fca){var _0x119e1b=typeof _0x28d807[_0x9c4c('0x1b')]===_0x9c4c('0x1c')&&typeof _0x28d807[_0x9c4c('0x1d')]===_0x9c4c('0x1c');var _0x27b29d=_0x1b3fca[_0x9c4c('0x1e')];var _0x43af71=_0x119e1b?0x0:_0x28d807[_0x9c4c('0x1b')];var _0x1f0742=_0x119e1b?_0x1b3fca[_0x9c4c('0x1e')]:_0x28d807[_0x9c4c('0x1b')]+_0x28d807[_0x9c4c('0x1d')];var _0xeab0fa;if(_0x1f0742>=_0x27b29d){_0x1f0742=_0x27b29d;_0xeab0fa=0xc8;}else{_0xeab0fa=0xce;}_0x4a0bb6['status'](_0xeab0fa);return _0x4a0bb6[_0x9c4c('0x1f')](_0x9c4c('0x20'),_0x43af71+'-'+_0x1f0742+'/'+_0x27b29d)[_0x9c4c('0x1a')](_0x1b3fca);}return null;};}function patchUpdates(_0x38b495){return function(_0x536685){try{jsonpatch[_0x9c4c('0x21')](_0x536685,_0x38b495,!![]);}catch(_0x47919a){return BPromise[_0x9c4c('0x22')](_0x47919a);}return _0x536685[_0x9c4c('0x23')]();};}function saveUpdates(_0x183642,_0x3ed7d7){return function(_0x416076){if(_0x416076){return _0x416076[_0x9c4c('0x24')](_0x183642)['then'](function(_0xe428b){return _0xe428b;});}return null;};}function removeEntity(_0x1ecdd5,_0x511999){return function(_0x30db94){if(_0x30db94){return _0x30db94['destroy']()['then'](function(){var _0xd4e102=_0x30db94['get']({'plain':!![]});var _0xea3261=_0x9c4c('0x25');return db[_0x9c4c('0x26')]['destroy']({'where':{'type':_0xea3261,'resourceId':_0xd4e102['id']}})[_0x9c4c('0x27')](function(){return _0x30db94;});})[_0x9c4c('0x27')](function(){_0x1ecdd5['status'](0xcc)[_0x9c4c('0x19')]();});}};}function handleEntityNotFound(_0x87b212,_0x3b6248){return function(_0x4227d8){if(!_0x4227d8){_0x87b212[_0x9c4c('0x17')](0x194);}return _0x4227d8;};}function handleError(_0x280c0f,_0x63de71){_0x63de71=_0x63de71||0x1f4;return function(_0x33c730){logger['error'](_0x33c730[_0x9c4c('0x28')]);if(_0x33c730['name']){delete _0x33c730[_0x9c4c('0x29')];}_0x280c0f[_0x9c4c('0x18')](_0x63de71)['send'](_0x33c730);};}exports[_0x9c4c('0x2a')]=function(_0x2d6952,_0x4b41ce){var _0xa5df51={},_0x156f1a={},_0x347eff={'count':0x0,'rows':[]};var _0x579338=_[_0x9c4c('0x2b')](db[_0x9c4c('0x2c')][_0x9c4c('0x2d')],function(_0x1a5b61){return{'name':_0x1a5b61[_0x9c4c('0x2e')],'type':_0x1a5b61[_0x9c4c('0x2f')]['key']};});_0x156f1a['model']=_[_0x9c4c('0x2b')](_0x579338,_0x9c4c('0x29'));_0x156f1a[_0x9c4c('0x30')]=_[_0x9c4c('0x31')](_0x2d6952[_0x9c4c('0x30')]);_0x156f1a[_0x9c4c('0x32')]=_[_0x9c4c('0x33')](_0x156f1a['model'],_0x156f1a[_0x9c4c('0x30')]);_0xa5df51[_0x9c4c('0x34')]=_[_0x9c4c('0x33')](_0x156f1a[_0x9c4c('0x35')],qs['fields'](_0x2d6952[_0x9c4c('0x30')][_0x9c4c('0x36')]));_0xa5df51['attributes']=_0xa5df51['attributes'][_0x9c4c('0x37')]?_0xa5df51['attributes']:_0x156f1a[_0x9c4c('0x35')];if(!_0x2d6952[_0x9c4c('0x30')][_0x9c4c('0x38')](_0x9c4c('0x39'))){_0xa5df51[_0x9c4c('0x1d')]=qs[_0x9c4c('0x1d')](_0x2d6952[_0x9c4c('0x30')][_0x9c4c('0x1d')]);_0xa5df51[_0x9c4c('0x1b')]=qs[_0x9c4c('0x1b')](_0x2d6952[_0x9c4c('0x30')][_0x9c4c('0x1b')]);}_0xa5df51[_0x9c4c('0x3a')]=qs[_0x9c4c('0x3b')](_0x2d6952[_0x9c4c('0x30')][_0x9c4c('0x3b')]);_0xa5df51[_0x9c4c('0x3c')]=qs['filters'](_[_0x9c4c('0x3d')](_0x2d6952[_0x9c4c('0x30')],_0x156f1a[_0x9c4c('0x32')]),_0x579338);if(_0x2d6952[_0x9c4c('0x30')][_0x9c4c('0x3e')]){_0xa5df51[_0x9c4c('0x3c')]=_['merge'](_0xa5df51[_0x9c4c('0x3c')],{'$or':_[_0x9c4c('0x2b')](_0x579338,function(_0x5e531e){if(_0x5e531e[_0x9c4c('0x2f')]!=='VIRTUAL'){var _0x37210e={};_0x37210e[_0x5e531e[_0x9c4c('0x29')]]={'$like':'%'+_0x2d6952[_0x9c4c('0x30')][_0x9c4c('0x3e')]+'%'};return _0x37210e;}})});}_0xa5df51=_[_0x9c4c('0x3f')]({},_0xa5df51,_0x2d6952['options']);var _0x5044c6={'where':_0xa5df51[_0x9c4c('0x3c')]};return db[_0x9c4c('0x2c')][_0x9c4c('0x1e')](_0x5044c6)[_0x9c4c('0x27')](function(_0xe146f9){_0x347eff['count']=_0xe146f9;if(_0x2d6952[_0x9c4c('0x30')]['includeAll']){_0xa5df51[_0x9c4c('0x40')]=[{'all':!![]}];}return db[_0x9c4c('0x2c')]['findAll'](_0xa5df51);})['then'](function(_0x34e04a){_0x347eff['rows']=_0x34e04a;return _0x347eff;})['then'](respondWithFilteredResult(_0x4b41ce,_0xa5df51))[_0x9c4c('0x41')](handleError(_0x4b41ce,null));};exports[_0x9c4c('0x42')]=function(_0x54bd8c,_0x11d88f){var _0x4d4b01={'raw':!![],'where':{'id':_0x54bd8c[_0x9c4c('0x43')]['id']}},_0x56bf78={};_0x56bf78[_0x9c4c('0x35')]=_[_0x9c4c('0x31')](db[_0x9c4c('0x2c')]['rawAttributes']);_0x56bf78[_0x9c4c('0x30')]=_[_0x9c4c('0x31')](_0x54bd8c[_0x9c4c('0x30')]);_0x56bf78[_0x9c4c('0x32')]=_['intersection'](_0x56bf78[_0x9c4c('0x35')],_0x56bf78[_0x9c4c('0x30')]);_0x4d4b01[_0x9c4c('0x34')]=_[_0x9c4c('0x33')](_0x56bf78['model'],qs['fields'](_0x54bd8c['query'][_0x9c4c('0x36')]));_0x4d4b01[_0x9c4c('0x34')]=_0x4d4b01[_0x9c4c('0x34')]['length']?_0x4d4b01[_0x9c4c('0x34')]:_0x56bf78[_0x9c4c('0x35')];if(_0x54bd8c[_0x9c4c('0x30')][_0x9c4c('0x44')]){_0x4d4b01[_0x9c4c('0x40')]=[{'all':!![]}];}_0x4d4b01=_[_0x9c4c('0x3f')]({},_0x4d4b01,_0x54bd8c[_0x9c4c('0x45')]);return db[_0x9c4c('0x2c')]['find'](_0x4d4b01)[_0x9c4c('0x27')](handleEntityNotFound(_0x11d88f,null))['then'](respondWithResult(_0x11d88f,null))['catch'](handleError(_0x11d88f,null));};exports['create']=function(_0x2934dc,_0x5673fc){return db[_0x9c4c('0x2c')][_0x9c4c('0x46')](_0x2934dc['body'],{})[_0x9c4c('0x27')](function(_0x122b94){var _0xaf1ab0=_0x2934dc['user'][_0x9c4c('0x47')]({'plain':!![]});if(!_0xaf1ab0)throw new Error(_0x9c4c('0x48'));if(_0xaf1ab0[_0x9c4c('0x49')]===_0x9c4c('0x4a')){var _0x59f656=_0x122b94[_0x9c4c('0x47')]({'plain':!![]});var _0x43b483='Dispositions';return db[_0x9c4c('0x4b')][_0x9c4c('0x4c')]({'where':{'name':_0x43b483,'userProfileId':_0xaf1ab0['userProfileId']},'raw':!![]})[_0x9c4c('0x27')](function(_0x54c808){if(_0x54c808&&_0x54c808[_0x9c4c('0x4d')]===0x0){return db[_0x9c4c('0x26')][_0x9c4c('0x46')]({'name':_0x59f656[_0x9c4c('0x29')],'resourceId':_0x59f656['id'],'type':_0x54c808[_0x9c4c('0x29')],'sectionId':_0x54c808['id']},{})[_0x9c4c('0x27')](function(){return _0x122b94;});}else{return _0x122b94;}})[_0x9c4c('0x41')](function(_0x17087f){logger[_0x9c4c('0x4e')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x17087f);throw _0x17087f;});}return _0x122b94;})[_0x9c4c('0x27')](respondWithResult(_0x5673fc,0xc9))[_0x9c4c('0x41')](handleError(_0x5673fc,null));};exports[_0x9c4c('0x24')]=function(_0x250a15,_0x122140){if(_0x250a15[_0x9c4c('0x4f')]['id']){delete _0x250a15['body']['id'];}return db[_0x9c4c('0x2c')]['find']({'where':{'id':_0x250a15[_0x9c4c('0x43')]['id']}})['then'](handleEntityNotFound(_0x122140,null))[_0x9c4c('0x27')](saveUpdates(_0x250a15['body'],null))['then'](respondWithResult(_0x122140,null))[_0x9c4c('0x41')](handleError(_0x122140,null));};exports[_0x9c4c('0x50')]=function(_0x5ae547,_0x180147){return db[_0x9c4c('0x2c')][_0x9c4c('0x4c')]({'where':{'id':_0x5ae547['params']['id']}})[_0x9c4c('0x27')](handleEntityNotFound(_0x180147,null))[_0x9c4c('0x27')](removeEntity(_0x180147,null))['catch'](handleError(_0x180147,null));};