908dd2675c4f80336fc8d181927be823471ca5d3
[motion2.git] / server / api / pause / pause.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 _0x98f5=['ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','apply','save','update','then','destroy','Pauses','UserProfileResource','name','send','index','rawAttributes','type','key','model','map','query','keys','filters','intersection','attributes','fields','length','nolimit','sort','pick','filter','where','VIRTUAL','Pause','includeAll','include','findAll','rows','params','filtears','merge','options','find','create','body','user','get','role','UserProfileSection','autoAssociation','error','catch','rimraf','zip-dir','fast-json-patch','request-promise','moment','util','sox','ejs','lodash','squel','crypto','jsforce','querystring','papaparse'];(function(_0x270b28,_0x316f8d){var _0x57d73c=function(_0x3969ab){while(--_0x3969ab){_0x270b28['push'](_0x270b28['shift']());}};_0x57d73c(++_0x316f8d);}(_0x98f5,0x132));var _0x598f=function(_0x5d7fa6,_0x26faa6){_0x5d7fa6=_0x5d7fa6-0x0;var _0x5ef826=_0x98f5[_0x5d7fa6];return _0x5ef826;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x598f('0x0'));var zipdir=require(_0x598f('0x1'));var jsonpatch=require(_0x598f('0x2'));var rp=require(_0x598f('0x3'));var moment=require(_0x598f('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x598f('0x5'));var path=require('path');var sox=require(_0x598f('0x6'));var csv=require('to-csv');var ejs=require(_0x598f('0x7'));var fs=require('fs');var _=require(_0x598f('0x8'));var squel=require(_0x598f('0x9'));var crypto=require(_0x598f('0xa'));var jsforce=require(_0x598f('0xb'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x598f('0xc'));var Papa=require(_0x598f('0xd'));var Redis=require(_0x598f('0xe'));var authService=require(_0x598f('0xf'));var qs=require(_0x598f('0x10'));var as=require(_0x598f('0x11'));var hardwareService=require(_0x598f('0x12'));var logger=require(_0x598f('0x13'))(_0x598f('0x14'));var utils=require(_0x598f('0x15'));var config=require(_0x598f('0x16'));var licenseUtil=require(_0x598f('0x17'));var db=require(_0x598f('0x18'))['db'];function respondWithStatusCode(_0x43403c,_0x39bc8e){_0x39bc8e=_0x39bc8e||0xcc;return function(_0x3bcc6a){if(_0x3bcc6a){return _0x43403c[_0x598f('0x19')](_0x39bc8e);}return _0x43403c[_0x598f('0x1a')](_0x39bc8e)[_0x598f('0x1b')]();};}function respondWithResult(_0x260abb,_0x5ed69a){_0x5ed69a=_0x5ed69a||0xc8;return function(_0x12a719){if(_0x12a719){return _0x260abb[_0x598f('0x1a')](_0x5ed69a)[_0x598f('0x1c')](_0x12a719);}};}function respondWithFilteredResult(_0x3f027a,_0x5bcdbd){return function(_0x27003a){if(_0x27003a){var _0x169fe8=_0x27003a[_0x598f('0x1d')],_0x53e520=_0x5bcdbd[_0x598f('0x1e')],_0x28007e=_0x5bcdbd[_0x598f('0x1e')]+_0x5bcdbd[_0x598f('0x1f')],_0x1b6963;if(_0x28007e>=_0x169fe8){_0x28007e=_0x169fe8;_0x1b6963=0xc8;}else{_0x1b6963=0xce;}_0x3f027a[_0x598f('0x1a')](_0x1b6963);return _0x3f027a[_0x598f('0x20')]('Content-Range',_0x53e520+'-'+_0x28007e+'/'+_0x169fe8)[_0x598f('0x1c')](_0x27003a);}return null;};}function patchUpdates(_0x3dfc5b){return function(_0x18a621){try{jsonpatch[_0x598f('0x21')](_0x18a621,_0x3dfc5b,!![]);}catch(_0x4cbcb6){return BPromise['reject'](_0x4cbcb6);}return _0x18a621[_0x598f('0x22')]();};}function saveUpdates(_0x32445a,_0x584422){return function(_0x4f3825){if(_0x4f3825){return _0x4f3825[_0x598f('0x23')](_0x32445a)[_0x598f('0x24')](function(_0x23811d){return _0x23811d;});}return null;};}function removeEntity(_0x2143bf,_0xd45e79){return function(_0x170dae){if(_0x170dae){return _0x170dae[_0x598f('0x25')]()[_0x598f('0x24')](function(){var _0x56c474=_0x170dae['get']({'plain':!![]});var _0x36910b=_0x598f('0x26');return db[_0x598f('0x27')]['destroy']({'where':{'type':_0x36910b,'resourceId':_0x56c474['id']}})['then'](function(){return _0x170dae;});})[_0x598f('0x24')](function(){_0x2143bf[_0x598f('0x1a')](0xcc)[_0x598f('0x1b')]();});}};}function handleEntityNotFound(_0x3bc5c5,_0x107b87){return function(_0x1a34dd){if(!_0x1a34dd){_0x3bc5c5[_0x598f('0x19')](0x194);}return _0x1a34dd;};}function handleError(_0x417af2,_0x6180){_0x6180=_0x6180||0x1f4;return function(_0x4d5a3a){logger['error'](_0x4d5a3a['stack']);if(_0x4d5a3a[_0x598f('0x28')]){delete _0x4d5a3a[_0x598f('0x28')];}_0x417af2[_0x598f('0x1a')](_0x6180)[_0x598f('0x29')](_0x4d5a3a);};}exports[_0x598f('0x2a')]=function(_0x16d7cc,_0x3f15da){var _0x4fc1d2={},_0x3a20c8={},_0x1682cd={'count':0x0,'rows':[]};var _0x221877=_['map'](db['Pause'][_0x598f('0x2b')],function(_0x5180fd){return{'name':_0x5180fd['fieldName'],'type':_0x5180fd[_0x598f('0x2c')][_0x598f('0x2d')]};});_0x3a20c8[_0x598f('0x2e')]=_[_0x598f('0x2f')](_0x221877,'name');_0x3a20c8[_0x598f('0x30')]=_[_0x598f('0x31')](_0x16d7cc[_0x598f('0x30')]);_0x3a20c8[_0x598f('0x32')]=_[_0x598f('0x33')](_0x3a20c8[_0x598f('0x2e')],_0x3a20c8[_0x598f('0x30')]);_0x4fc1d2[_0x598f('0x34')]=_[_0x598f('0x33')](_0x3a20c8[_0x598f('0x2e')],qs['fields'](_0x16d7cc['query'][_0x598f('0x35')]));_0x4fc1d2[_0x598f('0x34')]=_0x4fc1d2[_0x598f('0x34')][_0x598f('0x36')]?_0x4fc1d2[_0x598f('0x34')]:_0x3a20c8[_0x598f('0x2e')];if(!_0x16d7cc[_0x598f('0x30')]['hasOwnProperty'](_0x598f('0x37'))){_0x4fc1d2[_0x598f('0x1f')]=qs[_0x598f('0x1f')](_0x16d7cc[_0x598f('0x30')][_0x598f('0x1f')]);_0x4fc1d2[_0x598f('0x1e')]=qs[_0x598f('0x1e')](_0x16d7cc[_0x598f('0x30')]['offset']);}_0x4fc1d2['order']=qs['sort'](_0x16d7cc[_0x598f('0x30')][_0x598f('0x38')]);_0x4fc1d2['where']=qs['filters'](_[_0x598f('0x39')](_0x16d7cc[_0x598f('0x30')],_0x3a20c8[_0x598f('0x32')]),_0x221877);if(_0x16d7cc[_0x598f('0x30')][_0x598f('0x3a')]){_0x4fc1d2[_0x598f('0x3b')]=_['merge'](_0x4fc1d2[_0x598f('0x3b')],{'$or':_[_0x598f('0x2f')](_0x221877,function(_0x2d577e){if(_0x2d577e[_0x598f('0x2c')]!==_0x598f('0x3c')){var _0xb1e927={};_0xb1e927[_0x2d577e[_0x598f('0x28')]]={'$like':'%'+_0x16d7cc['query'][_0x598f('0x3a')]+'%'};return _0xb1e927;}})});}_0x4fc1d2=_['merge']({},_0x4fc1d2,_0x16d7cc['options']);var _0x3b61ae={'where':_0x4fc1d2['where']};return db[_0x598f('0x3d')][_0x598f('0x1d')](_0x3b61ae)[_0x598f('0x24')](function(_0x116b14){_0x1682cd[_0x598f('0x1d')]=_0x116b14;if(_0x16d7cc[_0x598f('0x30')][_0x598f('0x3e')]){_0x4fc1d2[_0x598f('0x3f')]=[{'all':!![]}];}return db[_0x598f('0x3d')][_0x598f('0x40')](_0x4fc1d2);})[_0x598f('0x24')](function(_0x3b347a){_0x1682cd[_0x598f('0x41')]=_0x3b347a;return _0x1682cd;})[_0x598f('0x24')](respondWithFilteredResult(_0x3f15da,_0x4fc1d2))['catch'](handleError(_0x3f15da,null));};exports['show']=function(_0x7b54c5,_0x69e5c3){var _0x574b17={'raw':!![],'where':{'id':_0x7b54c5[_0x598f('0x42')]['id']}},_0xbfce8e={};_0xbfce8e[_0x598f('0x2e')]=_[_0x598f('0x31')](db['Pause'][_0x598f('0x2b')]);_0xbfce8e[_0x598f('0x30')]=_['keys'](_0x7b54c5[_0x598f('0x30')]);_0xbfce8e[_0x598f('0x43')]=_[_0x598f('0x33')](_0xbfce8e[_0x598f('0x2e')],_0xbfce8e[_0x598f('0x30')]);_0x574b17['attributes']=_[_0x598f('0x33')](_0xbfce8e[_0x598f('0x2e')],qs[_0x598f('0x35')](_0x7b54c5[_0x598f('0x30')][_0x598f('0x35')]));_0x574b17[_0x598f('0x34')]=_0x574b17['attributes'][_0x598f('0x36')]?_0x574b17[_0x598f('0x34')]:_0xbfce8e[_0x598f('0x2e')];if(_0x7b54c5[_0x598f('0x30')][_0x598f('0x3e')]){_0x574b17[_0x598f('0x3f')]=[{'all':!![]}];}_0x574b17=_[_0x598f('0x44')]({},_0x574b17,_0x7b54c5[_0x598f('0x45')]);return db[_0x598f('0x3d')][_0x598f('0x46')](_0x574b17)[_0x598f('0x24')](handleEntityNotFound(_0x69e5c3,null))['then'](respondWithResult(_0x69e5c3,null))['catch'](handleError(_0x69e5c3,null));};exports[_0x598f('0x47')]=function(_0x1a612e,_0x14c023){return db[_0x598f('0x3d')]['create'](_0x1a612e[_0x598f('0x48')],{})[_0x598f('0x24')](function(_0xe662c0){var _0x31296b=_0x1a612e[_0x598f('0x49')][_0x598f('0x4a')]({'plain':!![]});if(!_0x31296b)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x31296b[_0x598f('0x4b')]==='user'){var _0x37da98=_0xe662c0[_0x598f('0x4a')]({'plain':!![]});var _0x1cfc7d=_0x598f('0x26');return db[_0x598f('0x4c')]['find']({'where':{'name':_0x1cfc7d,'userProfileId':_0x31296b['userProfileId']},'raw':!![]})[_0x598f('0x24')](function(_0x53db07){if(_0x53db07&&_0x53db07[_0x598f('0x4d')]===0x0){return db[_0x598f('0x27')]['create']({'name':_0x37da98[_0x598f('0x28')],'resourceId':_0x37da98['id'],'type':_0x53db07['name'],'sectionId':_0x53db07['id']},{})[_0x598f('0x24')](function(){return _0xe662c0;});}else{return _0xe662c0;}})['catch'](function(_0x4ea11d){logger[_0x598f('0x4e')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x4ea11d);throw _0x4ea11d;});}return _0xe662c0;})[_0x598f('0x24')](respondWithResult(_0x14c023,0xc9))['catch'](handleError(_0x14c023,null));};exports[_0x598f('0x23')]=function(_0x2747e3,_0x160dec){if(_0x2747e3[_0x598f('0x48')]['id']){delete _0x2747e3[_0x598f('0x48')]['id'];}return db[_0x598f('0x3d')][_0x598f('0x46')]({'where':{'id':_0x2747e3[_0x598f('0x42')]['id']}})[_0x598f('0x24')](handleEntityNotFound(_0x160dec,null))[_0x598f('0x24')](saveUpdates(_0x2747e3[_0x598f('0x48')],null))['then'](respondWithResult(_0x160dec,null))[_0x598f('0x4f')](handleError(_0x160dec,null));};exports['destroy']=function(_0x25c3fc,_0x50ad43){return db[_0x598f('0x3d')][_0x598f('0x46')]({'where':{'id':_0x25c3fc[_0x598f('0x42')]['id']}})[_0x598f('0x24')](handleEntityNotFound(_0x50ad43,null))[_0x598f('0x24')](removeEntity(_0x50ad43,null))[_0x598f('0x4f')](handleError(_0x50ad43,null));};