061bd4e12955f4bc97d0b6433062b556d140ad4e
[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 _0x1bbb=['crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','count','offset','Content-Range','apply','update','then','get','Pauses','UserProfileResource','error','stack','name','send','index','Pause','fieldName','type','key','map','query','filters','intersection','model','fields','attributes','hasOwnProperty','nolimit','limit','order','where','pick','filter','merge','options','includeAll','include','findAll','catch','show','params','keys','length','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','destroy','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','path','sox','to-csv'];(function(_0x4b68aa,_0x2c5035){var _0x112bd3=function(_0x3c4fd7){while(--_0x3c4fd7){_0x4b68aa['push'](_0x4b68aa['shift']());}};_0x112bd3(++_0x2c5035);}(_0x1bbb,0x97));var _0xb1bb=function(_0x1e5f19,_0x50e1bf){_0x1e5f19=_0x1e5f19-0x0;var _0x857e87=_0x1bbb[_0x1e5f19];return _0x857e87;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xb1bb('0x0'));var rimraf=require(_0xb1bb('0x1'));var zipdir=require(_0xb1bb('0x2'));var jsonpatch=require(_0xb1bb('0x3'));var rp=require(_0xb1bb('0x4'));var moment=require('moment');var BPromise=require(_0xb1bb('0x5'));var Mustache=require('mustache');var util=require('util');var path=require(_0xb1bb('0x6'));var sox=require(_0xb1bb('0x7'));var csv=require(_0xb1bb('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0xb1bb('0x9'));var jsforce=require(_0xb1bb('0xa'));var deskjs=require(_0xb1bb('0xb'));var toCsv=require(_0xb1bb('0x8'));var querystring=require(_0xb1bb('0xc'));var Papa=require(_0xb1bb('0xd'));var Redis=require(_0xb1bb('0xe'));var authService=require(_0xb1bb('0xf'));var qs=require(_0xb1bb('0x10'));var as=require(_0xb1bb('0x11'));var hardwareService=require(_0xb1bb('0x12'));var logger=require(_0xb1bb('0x13'))('api');var utils=require(_0xb1bb('0x14'));var config=require(_0xb1bb('0x15'));var licenseUtil=require(_0xb1bb('0x16'));var db=require(_0xb1bb('0x17'))['db'];function respondWithStatusCode(_0x32898d,_0x23a2ed){_0x23a2ed=_0x23a2ed||0xcc;return function(_0x3e577b){if(_0x3e577b){return _0x32898d[_0xb1bb('0x18')](_0x23a2ed);}return _0x32898d[_0xb1bb('0x19')](_0x23a2ed)['end']();};}function respondWithResult(_0x4f4a49,_0x3b053f){_0x3b053f=_0x3b053f||0xc8;return function(_0x527d6c){if(_0x527d6c){return _0x4f4a49[_0xb1bb('0x19')](_0x3b053f)[_0xb1bb('0x1a')](_0x527d6c);}};}function respondWithFilteredResult(_0x5e5e53,_0x19a030){return function(_0x152430){if(_0x152430){var _0xc50000=_0x152430[_0xb1bb('0x1b')],_0x1182c7=_0x19a030[_0xb1bb('0x1c')],_0x10b914=_0x19a030[_0xb1bb('0x1c')]+_0x19a030['limit'],_0x358b27;if(_0x10b914>=_0xc50000){_0x10b914=_0xc50000;_0x358b27=0xc8;}else{_0x358b27=0xce;}_0x5e5e53[_0xb1bb('0x19')](_0x358b27);return _0x5e5e53['set'](_0xb1bb('0x1d'),_0x1182c7+'-'+_0x10b914+'/'+_0xc50000)[_0xb1bb('0x1a')](_0x152430);}return null;};}function patchUpdates(_0xeaedb){return function(_0xe26bc0){try{jsonpatch[_0xb1bb('0x1e')](_0xe26bc0,_0xeaedb,!![]);}catch(_0x566f61){return BPromise['reject'](_0x566f61);}return _0xe26bc0['save']();};}function saveUpdates(_0x20d57c,_0x3461b9){return function(_0x38f863){if(_0x38f863){return _0x38f863[_0xb1bb('0x1f')](_0x20d57c)[_0xb1bb('0x20')](function(_0xd15510){return _0xd15510;});}return null;};}function removeEntity(_0x23813b,_0x4d337c){return function(_0xa94d3a){if(_0xa94d3a){return _0xa94d3a['destroy']()[_0xb1bb('0x20')](function(){var _0x2becbd=_0xa94d3a[_0xb1bb('0x21')]({'plain':!![]});var _0x584454=_0xb1bb('0x22');return db[_0xb1bb('0x23')]['destroy']({'where':{'type':_0x584454,'resourceId':_0x2becbd['id']}})['then'](function(){return _0xa94d3a;});})[_0xb1bb('0x20')](function(){_0x23813b[_0xb1bb('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x556445,_0x1cb2b6){return function(_0x71043b){if(!_0x71043b){_0x556445[_0xb1bb('0x18')](0x194);}return _0x71043b;};}function handleError(_0x3f7114,_0x58f4bd){_0x58f4bd=_0x58f4bd||0x1f4;return function(_0x2aa6ee){logger[_0xb1bb('0x24')](_0x2aa6ee[_0xb1bb('0x25')]);if(_0x2aa6ee[_0xb1bb('0x26')]){delete _0x2aa6ee[_0xb1bb('0x26')];}_0x3f7114[_0xb1bb('0x19')](_0x58f4bd)[_0xb1bb('0x27')](_0x2aa6ee);};}exports[_0xb1bb('0x28')]=function(_0x3f0126,_0x38474f){var _0x27c022={},_0x532905={},_0x49d28a={'count':0x0,'rows':[]};var _0x43320c=_['map'](db[_0xb1bb('0x29')]['rawAttributes'],function(_0x1dc6be){return{'name':_0x1dc6be[_0xb1bb('0x2a')],'type':_0x1dc6be[_0xb1bb('0x2b')][_0xb1bb('0x2c')]};});_0x532905['model']=_[_0xb1bb('0x2d')](_0x43320c,_0xb1bb('0x26'));_0x532905[_0xb1bb('0x2e')]=_['keys'](_0x3f0126[_0xb1bb('0x2e')]);_0x532905[_0xb1bb('0x2f')]=_[_0xb1bb('0x30')](_0x532905[_0xb1bb('0x31')],_0x532905[_0xb1bb('0x2e')]);_0x27c022['attributes']=_['intersection'](_0x532905[_0xb1bb('0x31')],qs[_0xb1bb('0x32')](_0x3f0126[_0xb1bb('0x2e')][_0xb1bb('0x32')]));_0x27c022[_0xb1bb('0x33')]=_0x27c022[_0xb1bb('0x33')]['length']?_0x27c022[_0xb1bb('0x33')]:_0x532905[_0xb1bb('0x31')];if(!_0x3f0126['query'][_0xb1bb('0x34')](_0xb1bb('0x35'))){_0x27c022[_0xb1bb('0x36')]=qs[_0xb1bb('0x36')](_0x3f0126[_0xb1bb('0x2e')]['limit']);_0x27c022[_0xb1bb('0x1c')]=qs[_0xb1bb('0x1c')](_0x3f0126[_0xb1bb('0x2e')][_0xb1bb('0x1c')]);}_0x27c022[_0xb1bb('0x37')]=qs['sort'](_0x3f0126[_0xb1bb('0x2e')]['sort']);_0x27c022[_0xb1bb('0x38')]=qs[_0xb1bb('0x2f')](_[_0xb1bb('0x39')](_0x3f0126['query'],_0x532905[_0xb1bb('0x2f')]),_0x43320c);if(_0x3f0126['query'][_0xb1bb('0x3a')]){_0x27c022[_0xb1bb('0x38')]=_['merge'](_0x27c022['where'],{'$or':_[_0xb1bb('0x2d')](_0x43320c,function(_0x1f64b0){if(_0x1f64b0[_0xb1bb('0x2b')]!=='VIRTUAL'){var _0x4faa07={};_0x4faa07[_0x1f64b0[_0xb1bb('0x26')]]={'$like':'%'+_0x3f0126[_0xb1bb('0x2e')][_0xb1bb('0x3a')]+'%'};return _0x4faa07;}})});}_0x27c022=_[_0xb1bb('0x3b')]({},_0x27c022,_0x3f0126[_0xb1bb('0x3c')]);var _0x364e4e={'where':_0x27c022[_0xb1bb('0x38')]};return db[_0xb1bb('0x29')]['count'](_0x364e4e)[_0xb1bb('0x20')](function(_0x36f5d3){_0x49d28a['count']=_0x36f5d3;if(_0x3f0126[_0xb1bb('0x2e')][_0xb1bb('0x3d')]){_0x27c022[_0xb1bb('0x3e')]=[{'all':!![]}];}return db[_0xb1bb('0x29')][_0xb1bb('0x3f')](_0x27c022);})[_0xb1bb('0x20')](function(_0x476a23){_0x49d28a['rows']=_0x476a23;return _0x49d28a;})[_0xb1bb('0x20')](respondWithFilteredResult(_0x38474f,_0x27c022))[_0xb1bb('0x40')](handleError(_0x38474f,null));};exports[_0xb1bb('0x41')]=function(_0x48d345,_0x231ec4){var _0x3717b7={'raw':!![],'where':{'id':_0x48d345[_0xb1bb('0x42')]['id']}},_0x36d29a={};_0x36d29a[_0xb1bb('0x31')]=_[_0xb1bb('0x43')](db[_0xb1bb('0x29')]['rawAttributes']);_0x36d29a['query']=_[_0xb1bb('0x43')](_0x48d345[_0xb1bb('0x2e')]);_0x36d29a[_0xb1bb('0x2f')]=_['intersection'](_0x36d29a['model'],_0x36d29a[_0xb1bb('0x2e')]);_0x3717b7[_0xb1bb('0x33')]=_['intersection'](_0x36d29a[_0xb1bb('0x31')],qs[_0xb1bb('0x32')](_0x48d345['query'][_0xb1bb('0x32')]));_0x3717b7['attributes']=_0x3717b7[_0xb1bb('0x33')][_0xb1bb('0x44')]?_0x3717b7[_0xb1bb('0x33')]:_0x36d29a[_0xb1bb('0x31')];if(_0x48d345[_0xb1bb('0x2e')][_0xb1bb('0x3d')]){_0x3717b7[_0xb1bb('0x3e')]=[{'all':!![]}];}_0x3717b7=_[_0xb1bb('0x3b')]({},_0x3717b7,_0x48d345[_0xb1bb('0x3c')]);return db[_0xb1bb('0x29')][_0xb1bb('0x45')](_0x3717b7)[_0xb1bb('0x20')](handleEntityNotFound(_0x231ec4,null))[_0xb1bb('0x20')](respondWithResult(_0x231ec4,null))[_0xb1bb('0x40')](handleError(_0x231ec4,null));};exports[_0xb1bb('0x46')]=function(_0xca2c79,_0x4cec54){return db[_0xb1bb('0x29')][_0xb1bb('0x46')](_0xca2c79[_0xb1bb('0x47')],{})[_0xb1bb('0x20')](function(_0x396806){var _0x158d91=_0xca2c79[_0xb1bb('0x48')]['get']({'plain':!![]});if(!_0x158d91)throw new Error(_0xb1bb('0x49'));if(_0x158d91[_0xb1bb('0x4a')]===_0xb1bb('0x48')){var _0x5ded73=_0x396806[_0xb1bb('0x21')]({'plain':!![]});var _0x3f5d75=_0xb1bb('0x22');return db[_0xb1bb('0x4b')][_0xb1bb('0x45')]({'where':{'name':_0x3f5d75,'userProfileId':_0x158d91[_0xb1bb('0x4c')]},'raw':!![]})[_0xb1bb('0x20')](function(_0x2bed54){if(_0x2bed54&&_0x2bed54[_0xb1bb('0x4d')]===0x0){return db[_0xb1bb('0x23')][_0xb1bb('0x46')]({'name':_0x5ded73['name'],'resourceId':_0x5ded73['id'],'type':_0x2bed54[_0xb1bb('0x26')],'sectionId':_0x2bed54['id']},{})[_0xb1bb('0x20')](function(){return _0x396806;});}else{return _0x396806;}})['catch'](function(_0x316723){logger['error'](_0xb1bb('0x4e'),_0x316723);throw _0x316723;});}return _0x396806;})[_0xb1bb('0x20')](respondWithResult(_0x4cec54,0xc9))[_0xb1bb('0x40')](handleError(_0x4cec54,null));};exports[_0xb1bb('0x1f')]=function(_0x38b895,_0x51c5f1){if(_0x38b895[_0xb1bb('0x47')]['id']){delete _0x38b895[_0xb1bb('0x47')]['id'];}return db[_0xb1bb('0x29')][_0xb1bb('0x45')]({'where':{'id':_0x38b895[_0xb1bb('0x42')]['id']}})[_0xb1bb('0x20')](handleEntityNotFound(_0x51c5f1,null))[_0xb1bb('0x20')](saveUpdates(_0x38b895[_0xb1bb('0x47')],null))['then'](respondWithResult(_0x51c5f1,null))[_0xb1bb('0x40')](handleError(_0x51c5f1,null));};exports[_0xb1bb('0x4f')]=function(_0x196e86,_0x3d25c3){return db[_0xb1bb('0x29')][_0xb1bb('0x45')]({'where':{'id':_0x196e86['params']['id']}})[_0xb1bb('0x20')](handleEntityNotFound(_0x3d25c3,null))[_0xb1bb('0x20')](removeEntity(_0x3d25c3,null))['catch'](handleError(_0x3d25c3,null));};