960b6098ee46593d385a255b978691de7f9d9df5
[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 _0xfc0c=['ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','count','offset','limit','set','Content-Range','json','apply','reject','save','update','destroy','then','get','Dispositions','UserProfileResource','end','error','stack','name','index','Disposition','rawAttributes','type','key','map','query','filters','intersection','model','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','options','includeAll','include','findAll','catch','show','keys','filtears','create','body','user','role','UserProfileSection','find','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse'];(function(_0x4946e8,_0x2ae2ad){var _0x2f2926=function(_0x5c6288){while(--_0x5c6288){_0x4946e8['push'](_0x4946e8['shift']());}};_0x2f2926(++_0x2ae2ad);}(_0xfc0c,0x1e8));var _0xcfc0=function(_0x21df79,_0x551a7d){_0x21df79=_0x21df79-0x0;var _0x5a793c=_0xfc0c[_0x21df79];return _0x5a793c;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xcfc0('0x0'));var rp=require(_0xcfc0('0x1'));var moment=require(_0xcfc0('0x2'));var BPromise=require(_0xcfc0('0x3'));var Mustache=require(_0xcfc0('0x4'));var util=require(_0xcfc0('0x5'));var path=require(_0xcfc0('0x6'));var sox=require(_0xcfc0('0x7'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xcfc0('0x8'));var squel=require(_0xcfc0('0x9'));var crypto=require(_0xcfc0('0xa'));var jsforce=require(_0xcfc0('0xb'));var deskjs=require(_0xcfc0('0xc'));var toCsv=require(_0xcfc0('0xd'));var querystring=require(_0xcfc0('0xe'));var Papa=require(_0xcfc0('0xf'));var Redis=require(_0xcfc0('0x10'));var authService=require('../../components/auth/service');var qs=require(_0xcfc0('0x11'));var as=require(_0xcfc0('0x12'));var hardwareService=require(_0xcfc0('0x13'));var logger=require(_0xcfc0('0x14'))(_0xcfc0('0x15'));var utils=require(_0xcfc0('0x16'));var config=require(_0xcfc0('0x17'));var licenseUtil=require(_0xcfc0('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x383203,_0x17f36e){_0x17f36e=_0x17f36e||0xcc;return function(_0x5a9216){if(_0x5a9216){return _0x383203[_0xcfc0('0x19')](_0x17f36e);}return _0x383203[_0xcfc0('0x1a')](_0x17f36e)['end']();};}function respondWithResult(_0xf66a42,_0x3db728){_0x3db728=_0x3db728||0xc8;return function(_0x389b5a){if(_0x389b5a){return _0xf66a42['status'](_0x3db728)['json'](_0x389b5a);}};}function respondWithFilteredResult(_0x52d36e,_0x124c1c){return function(_0x53ee67){if(_0x53ee67){var _0x497608=_0x53ee67[_0xcfc0('0x1b')],_0x4c9b41=_0x124c1c[_0xcfc0('0x1c')],_0x33396c=_0x124c1c[_0xcfc0('0x1c')]+_0x124c1c[_0xcfc0('0x1d')],_0x460f68;if(_0x33396c>=_0x497608){_0x33396c=_0x497608;_0x460f68=0xc8;}else{_0x460f68=0xce;}_0x52d36e[_0xcfc0('0x1a')](_0x460f68);return _0x52d36e[_0xcfc0('0x1e')](_0xcfc0('0x1f'),_0x4c9b41+'-'+_0x33396c+'/'+_0x497608)[_0xcfc0('0x20')](_0x53ee67);}return null;};}function patchUpdates(_0x1bdd44){return function(_0x39bdd2){try{jsonpatch[_0xcfc0('0x21')](_0x39bdd2,_0x1bdd44,!![]);}catch(_0x3b61b8){return BPromise[_0xcfc0('0x22')](_0x3b61b8);}return _0x39bdd2[_0xcfc0('0x23')]();};}function saveUpdates(_0x401222,_0x1611bb){return function(_0x53bc01){if(_0x53bc01){return _0x53bc01[_0xcfc0('0x24')](_0x401222)['then'](function(_0x2d44d9){return _0x2d44d9;});}return null;};}function removeEntity(_0x1864cf,_0x2652f9){return function(_0x1a1260){if(_0x1a1260){return _0x1a1260[_0xcfc0('0x25')]()[_0xcfc0('0x26')](function(){var _0x269507=_0x1a1260[_0xcfc0('0x27')]({'plain':!![]});var _0x4c10b6=_0xcfc0('0x28');return db[_0xcfc0('0x29')][_0xcfc0('0x25')]({'where':{'type':_0x4c10b6,'resourceId':_0x269507['id']}})[_0xcfc0('0x26')](function(){return _0x1a1260;});})[_0xcfc0('0x26')](function(){_0x1864cf[_0xcfc0('0x1a')](0xcc)[_0xcfc0('0x2a')]();});}};}function handleEntityNotFound(_0x41de40,_0x22e70a){return function(_0x3b2905){if(!_0x3b2905){_0x41de40[_0xcfc0('0x19')](0x194);}return _0x3b2905;};}function handleError(_0x16072c,_0x4f30e7){_0x4f30e7=_0x4f30e7||0x1f4;return function(_0x391760){logger[_0xcfc0('0x2b')](_0x391760[_0xcfc0('0x2c')]);if(_0x391760[_0xcfc0('0x2d')]){delete _0x391760['name'];}_0x16072c[_0xcfc0('0x1a')](_0x4f30e7)['send'](_0x391760);};}exports[_0xcfc0('0x2e')]=function(_0x1c3e04,_0x2f3dfa){var _0x3b8b09={},_0x1a28c8={},_0x1dbe3c={'count':0x0,'rows':[]};var _0x4190a2=_['map'](db[_0xcfc0('0x2f')][_0xcfc0('0x30')],function(_0x29b6fa){return{'name':_0x29b6fa['fieldName'],'type':_0x29b6fa[_0xcfc0('0x31')][_0xcfc0('0x32')]};});_0x1a28c8['model']=_[_0xcfc0('0x33')](_0x4190a2,_0xcfc0('0x2d'));_0x1a28c8['query']=_['keys'](_0x1c3e04[_0xcfc0('0x34')]);_0x1a28c8[_0xcfc0('0x35')]=_[_0xcfc0('0x36')](_0x1a28c8['model'],_0x1a28c8['query']);_0x3b8b09['attributes']=_[_0xcfc0('0x36')](_0x1a28c8[_0xcfc0('0x37')],qs[_0xcfc0('0x38')](_0x1c3e04['query']['fields']));_0x3b8b09[_0xcfc0('0x39')]=_0x3b8b09[_0xcfc0('0x39')][_0xcfc0('0x3a')]?_0x3b8b09[_0xcfc0('0x39')]:_0x1a28c8[_0xcfc0('0x37')];if(!_0x1c3e04[_0xcfc0('0x34')][_0xcfc0('0x3b')](_0xcfc0('0x3c'))){_0x3b8b09[_0xcfc0('0x1d')]=qs[_0xcfc0('0x1d')](_0x1c3e04[_0xcfc0('0x34')][_0xcfc0('0x1d')]);_0x3b8b09[_0xcfc0('0x1c')]=qs[_0xcfc0('0x1c')](_0x1c3e04[_0xcfc0('0x34')]['offset']);}_0x3b8b09[_0xcfc0('0x3d')]=qs[_0xcfc0('0x3e')](_0x1c3e04['query'][_0xcfc0('0x3e')]);_0x3b8b09[_0xcfc0('0x3f')]=qs[_0xcfc0('0x35')](_[_0xcfc0('0x40')](_0x1c3e04[_0xcfc0('0x34')],_0x1a28c8[_0xcfc0('0x35')]),_0x4190a2);if(_0x1c3e04[_0xcfc0('0x34')][_0xcfc0('0x41')]){_0x3b8b09[_0xcfc0('0x3f')]=_['merge'](_0x3b8b09[_0xcfc0('0x3f')],{'$or':_['map'](_0x4190a2,function(_0x20dd58){if(_0x20dd58[_0xcfc0('0x31')]!=='VIRTUAL'){var _0x34a3b7={};_0x34a3b7[_0x20dd58['name']]={'$like':'%'+_0x1c3e04[_0xcfc0('0x34')][_0xcfc0('0x41')]+'%'};return _0x34a3b7;}})});}_0x3b8b09=_[_0xcfc0('0x42')]({},_0x3b8b09,_0x1c3e04[_0xcfc0('0x43')]);var _0x569385={'where':_0x3b8b09[_0xcfc0('0x3f')]};return db['Disposition'][_0xcfc0('0x1b')](_0x569385)[_0xcfc0('0x26')](function(_0x4ddf3f){_0x1dbe3c[_0xcfc0('0x1b')]=_0x4ddf3f;if(_0x1c3e04['query'][_0xcfc0('0x44')]){_0x3b8b09[_0xcfc0('0x45')]=[{'all':!![]}];}return db['Disposition'][_0xcfc0('0x46')](_0x3b8b09);})[_0xcfc0('0x26')](function(_0x35f292){_0x1dbe3c['rows']=_0x35f292;return _0x1dbe3c;})['then'](respondWithFilteredResult(_0x2f3dfa,_0x3b8b09))[_0xcfc0('0x47')](handleError(_0x2f3dfa,null));};exports[_0xcfc0('0x48')]=function(_0x753833,_0x277652){var _0x4dfe9d={'raw':!![],'where':{'id':_0x753833['params']['id']}},_0x2779b2={};_0x2779b2['model']=_[_0xcfc0('0x49')](db[_0xcfc0('0x2f')][_0xcfc0('0x30')]);_0x2779b2['query']=_[_0xcfc0('0x49')](_0x753833[_0xcfc0('0x34')]);_0x2779b2[_0xcfc0('0x4a')]=_[_0xcfc0('0x36')](_0x2779b2[_0xcfc0('0x37')],_0x2779b2[_0xcfc0('0x34')]);_0x4dfe9d['attributes']=_['intersection'](_0x2779b2['model'],qs[_0xcfc0('0x38')](_0x753833[_0xcfc0('0x34')][_0xcfc0('0x38')]));_0x4dfe9d[_0xcfc0('0x39')]=_0x4dfe9d[_0xcfc0('0x39')]['length']?_0x4dfe9d[_0xcfc0('0x39')]:_0x2779b2[_0xcfc0('0x37')];if(_0x753833[_0xcfc0('0x34')]['includeAll']){_0x4dfe9d[_0xcfc0('0x45')]=[{'all':!![]}];}_0x4dfe9d=_['merge']({},_0x4dfe9d,_0x753833[_0xcfc0('0x43')]);return db[_0xcfc0('0x2f')]['find'](_0x4dfe9d)[_0xcfc0('0x26')](handleEntityNotFound(_0x277652,null))[_0xcfc0('0x26')](respondWithResult(_0x277652,null))[_0xcfc0('0x47')](handleError(_0x277652,null));};exports['create']=function(_0x57b2b7,_0x398a3d){return db[_0xcfc0('0x2f')][_0xcfc0('0x4b')](_0x57b2b7[_0xcfc0('0x4c')],{})[_0xcfc0('0x26')](function(_0x30a92f){var _0x501846=_0x57b2b7[_0xcfc0('0x4d')][_0xcfc0('0x27')]({'plain':!![]});if(!_0x501846)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x501846[_0xcfc0('0x4e')]===_0xcfc0('0x4d')){var _0xa5591d=_0x30a92f[_0xcfc0('0x27')]({'plain':!![]});var _0x3c2049='Dispositions';return db[_0xcfc0('0x4f')][_0xcfc0('0x50')]({'where':{'name':_0x3c2049,'userProfileId':_0x501846['userProfileId']},'raw':!![]})['then'](function(_0x33af2f){if(_0x33af2f&&_0x33af2f[_0xcfc0('0x51')]===0x0){return db[_0xcfc0('0x29')][_0xcfc0('0x4b')]({'name':_0xa5591d[_0xcfc0('0x2d')],'resourceId':_0xa5591d['id'],'type':_0x33af2f[_0xcfc0('0x2d')],'sectionId':_0x33af2f['id']},{})['then'](function(){return _0x30a92f;});}else{return _0x30a92f;}})[_0xcfc0('0x47')](function(_0x4a6bee){logger['error'](_0xcfc0('0x52'),_0x4a6bee);throw _0x4a6bee;});}return _0x30a92f;})['then'](respondWithResult(_0x398a3d,0xc9))['catch'](handleError(_0x398a3d,null));};exports[_0xcfc0('0x24')]=function(_0x27f34f,_0x14b934){if(_0x27f34f[_0xcfc0('0x4c')]['id']){delete _0x27f34f['body']['id'];}return db[_0xcfc0('0x2f')][_0xcfc0('0x50')]({'where':{'id':_0x27f34f[_0xcfc0('0x53')]['id']}})[_0xcfc0('0x26')](handleEntityNotFound(_0x14b934,null))[_0xcfc0('0x26')](saveUpdates(_0x27f34f[_0xcfc0('0x4c')],null))[_0xcfc0('0x26')](respondWithResult(_0x14b934,null))[_0xcfc0('0x47')](handleError(_0x14b934,null));};exports[_0xcfc0('0x25')]=function(_0x2fe0fa,_0x47ec80){return db[_0xcfc0('0x2f')][_0xcfc0('0x50')]({'where':{'id':_0x2fe0fa[_0xcfc0('0x53')]['id']}})[_0xcfc0('0x26')](handleEntityNotFound(_0x47ec80,null))[_0xcfc0('0x26')](removeEntity(_0x47ec80,null))[_0xcfc0('0x47')](handleError(_0x47ec80,null));};