Built motion from commit (unavailable).|2.4.18
[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 _0xf070=['../../config/environment','../../mysqldb','sendStatus','status','count','offset','limit','set','Content-Range','json','apply','reject','update','destroy','then','get','end','error','send','Pause','fieldName','map','name','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','order','sort','pick','filter','where','merge','type','options','includeAll','include','findAll','catch','show','params','rawAttributes','find','create','body','user','role','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','sox','ejs','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils'];(function(_0x1fbe05,_0x780c12){var _0x19ae69=function(_0x12a86c){while(--_0x12a86c){_0x1fbe05['push'](_0x1fbe05['shift']());}};_0x19ae69(++_0x780c12);}(_0xf070,0x172));var _0x0f07=function(_0x481da7,_0x3a90b6){_0x481da7=_0x481da7-0x0;var _0x1addf1=_0xf070[_0x481da7];return _0x1addf1;};'use strict';var pdf=require(_0x0f07('0x0'));var emlformat=require(_0x0f07('0x1'));var rimraf=require(_0x0f07('0x2'));var zipdir=require(_0x0f07('0x3'));var jsonpatch=require(_0x0f07('0x4'));var rp=require(_0x0f07('0x5'));var moment=require(_0x0f07('0x6'));var BPromise=require(_0x0f07('0x7'));var Mustache=require(_0x0f07('0x8'));var util=require('util');var path=require('path');var sox=require(_0x0f07('0x9'));var csv=require('to-csv');var ejs=require(_0x0f07('0xa'));var fs=require('fs');var _=require(_0x0f07('0xb'));var squel=require(_0x0f07('0xc'));var crypto=require(_0x0f07('0xd'));var jsforce=require(_0x0f07('0xe'));var deskjs=require(_0x0f07('0xf'));var toCsv=require(_0x0f07('0x10'));var querystring=require(_0x0f07('0x11'));var Papa=require(_0x0f07('0x12'));var Redis=require(_0x0f07('0x13'));var authService=require('../../components/auth/service');var qs=require(_0x0f07('0x14'));var as=require(_0x0f07('0x15'));var hardwareService=require(_0x0f07('0x16'));var logger=require('../../config/logger')(_0x0f07('0x17'));var utils=require(_0x0f07('0x18'));var config=require(_0x0f07('0x19'));var db=require(_0x0f07('0x1a'))['db'];function respondWithStatusCode(_0x252fa1,_0x5156eb){_0x5156eb=_0x5156eb||0xcc;return function(_0x4d9474){if(_0x4d9474){return _0x252fa1[_0x0f07('0x1b')](_0x5156eb);}return _0x252fa1['status'](_0x5156eb)['end']();};}function respondWithResult(_0x3574b4,_0x2e12e9){_0x2e12e9=_0x2e12e9||0xc8;return function(_0x2340fd){if(_0x2340fd){return _0x3574b4[_0x0f07('0x1c')](_0x2e12e9)['json'](_0x2340fd);}};}function respondWithFilteredResult(_0x28cb78,_0x9b027a){return function(_0x14bf77){if(_0x14bf77){var _0x4b035d=_0x14bf77[_0x0f07('0x1d')],_0x159c0b=_0x9b027a['offset'],_0x2ab5ca=_0x9b027a[_0x0f07('0x1e')]+_0x9b027a[_0x0f07('0x1f')],_0x7cf90;if(_0x2ab5ca>=_0x4b035d){_0x2ab5ca=_0x4b035d;_0x7cf90=0xc8;}else{_0x7cf90=0xce;}_0x28cb78['status'](_0x7cf90);return _0x28cb78[_0x0f07('0x20')](_0x0f07('0x21'),_0x159c0b+'-'+_0x2ab5ca+'/'+_0x4b035d)[_0x0f07('0x22')](_0x14bf77);}return null;};}function patchUpdates(_0x2d6a7c){return function(_0x317108){try{jsonpatch[_0x0f07('0x23')](_0x317108,_0x2d6a7c,!![]);}catch(_0xa0c97c){return BPromise[_0x0f07('0x24')](_0xa0c97c);}return _0x317108['save']();};}function saveUpdates(_0x4e6544,_0x18da0c){return function(_0x15dfc7){if(_0x15dfc7){return _0x15dfc7[_0x0f07('0x25')](_0x4e6544)['then'](function(_0x28a6dd){return _0x28a6dd;});}return null;};}function removeEntity(_0x295307,_0x3244de){return function(_0x1f29b8){if(_0x1f29b8){return _0x1f29b8[_0x0f07('0x26')]()[_0x0f07('0x27')](function(){var _0x311cf6=_0x1f29b8[_0x0f07('0x28')]({'plain':!![]});var _0xda7afc='Pauses';return db['UserProfileResource']['destroy']({'where':{'type':_0xda7afc,'resourceId':_0x311cf6['id']}})['then'](function(){return _0x1f29b8;});})[_0x0f07('0x27')](function(){_0x295307[_0x0f07('0x1c')](0xcc)[_0x0f07('0x29')]();});}};}function handleEntityNotFound(_0x28a5c6,_0x3f845f){return function(_0x17da82){if(!_0x17da82){_0x28a5c6[_0x0f07('0x1b')](0x194);}return _0x17da82;};}function handleError(_0x9e6a02,_0x38a527){_0x38a527=_0x38a527||0x1f4;return function(_0x3d3a59){logger[_0x0f07('0x2a')](_0x3d3a59['stack']);if(_0x3d3a59['name']){delete _0x3d3a59['name'];}_0x9e6a02[_0x0f07('0x1c')](_0x38a527)[_0x0f07('0x2b')](_0x3d3a59);};}exports['index']=function(_0x2d400d,_0x262acb){var _0x11b170={},_0x3aa207={},_0x5a3796={'count':0x0,'rows':[]};var _0x324cac=_['map'](db[_0x0f07('0x2c')]['rawAttributes'],function(_0x2f745d){return{'name':_0x2f745d[_0x0f07('0x2d')],'type':_0x2f745d['type']['key']};});_0x3aa207['model']=_[_0x0f07('0x2e')](_0x324cac,_0x0f07('0x2f'));_0x3aa207[_0x0f07('0x30')]=_[_0x0f07('0x31')](_0x2d400d[_0x0f07('0x30')]);_0x3aa207[_0x0f07('0x32')]=_[_0x0f07('0x33')](_0x3aa207[_0x0f07('0x34')],_0x3aa207[_0x0f07('0x30')]);_0x11b170[_0x0f07('0x35')]=_[_0x0f07('0x33')](_0x3aa207[_0x0f07('0x34')],qs[_0x0f07('0x36')](_0x2d400d[_0x0f07('0x30')][_0x0f07('0x36')]));_0x11b170[_0x0f07('0x35')]=_0x11b170[_0x0f07('0x35')][_0x0f07('0x37')]?_0x11b170[_0x0f07('0x35')]:_0x3aa207[_0x0f07('0x34')];if(!_0x2d400d[_0x0f07('0x30')][_0x0f07('0x38')]('nolimit')){_0x11b170[_0x0f07('0x1f')]=qs['limit'](_0x2d400d['query'][_0x0f07('0x1f')]);_0x11b170[_0x0f07('0x1e')]=qs[_0x0f07('0x1e')](_0x2d400d[_0x0f07('0x30')][_0x0f07('0x1e')]);}_0x11b170[_0x0f07('0x39')]=qs[_0x0f07('0x3a')](_0x2d400d['query'][_0x0f07('0x3a')]);_0x11b170['where']=qs[_0x0f07('0x32')](_[_0x0f07('0x3b')](_0x2d400d['query'],_0x3aa207[_0x0f07('0x32')]));if(_0x2d400d[_0x0f07('0x30')][_0x0f07('0x3c')]){_0x11b170[_0x0f07('0x3d')]=_[_0x0f07('0x3e')](_0x11b170[_0x0f07('0x3d')],{'$or':_['map'](_0x324cac,function(_0x207021){if(_0x207021[_0x0f07('0x3f')]!=='VIRTUAL'){var _0x338564={};_0x338564[_0x207021[_0x0f07('0x2f')]]={'$like':'%'+_0x2d400d[_0x0f07('0x30')][_0x0f07('0x3c')]+'%'};return _0x338564;}})});}_0x11b170=_[_0x0f07('0x3e')]({},_0x11b170,_0x2d400d[_0x0f07('0x40')]);var _0x22bfff={'where':_0x11b170[_0x0f07('0x3d')]};return db['Pause'][_0x0f07('0x1d')](_0x22bfff)['then'](function(_0x4bd54e){_0x5a3796[_0x0f07('0x1d')]=_0x4bd54e;if(_0x2d400d[_0x0f07('0x30')][_0x0f07('0x41')]){_0x11b170[_0x0f07('0x42')]=[{'all':!![]}];}return db['Pause'][_0x0f07('0x43')](_0x11b170);})['then'](function(_0x43ff5e){_0x5a3796['rows']=_0x43ff5e;return _0x5a3796;})[_0x0f07('0x27')](respondWithFilteredResult(_0x262acb,_0x11b170))[_0x0f07('0x44')](handleError(_0x262acb,null));};exports[_0x0f07('0x45')]=function(_0x315a8a,_0xe33416){var _0x480ff6={'raw':!![],'where':{'id':_0x315a8a[_0x0f07('0x46')]['id']}},_0x543f08={};_0x543f08[_0x0f07('0x34')]=_['keys'](db[_0x0f07('0x2c')][_0x0f07('0x47')]);_0x543f08['query']=_[_0x0f07('0x31')](_0x315a8a['query']);_0x543f08[_0x0f07('0x32')]=_['intersection'](_0x543f08[_0x0f07('0x34')],_0x543f08[_0x0f07('0x30')]);_0x480ff6[_0x0f07('0x35')]=_[_0x0f07('0x33')](_0x543f08[_0x0f07('0x34')],qs[_0x0f07('0x36')](_0x315a8a[_0x0f07('0x30')][_0x0f07('0x36')]));_0x480ff6['attributes']=_0x480ff6['attributes']['length']?_0x480ff6[_0x0f07('0x35')]:_0x543f08[_0x0f07('0x34')];if(_0x315a8a[_0x0f07('0x30')]['includeAll']){_0x480ff6[_0x0f07('0x42')]=[{'all':!![]}];}_0x480ff6=_[_0x0f07('0x3e')]({},_0x480ff6,_0x315a8a['options']);return db[_0x0f07('0x2c')][_0x0f07('0x48')](_0x480ff6)[_0x0f07('0x27')](handleEntityNotFound(_0xe33416,null))['then'](respondWithResult(_0xe33416,null))[_0x0f07('0x44')](handleError(_0xe33416,null));};exports[_0x0f07('0x49')]=function(_0x3a98bd,_0x27ceec){return db[_0x0f07('0x2c')][_0x0f07('0x49')](_0x3a98bd[_0x0f07('0x4a')],{})['then'](function(_0xcf1f38){var _0x2eb0f7=_0x3a98bd[_0x0f07('0x4b')]['get']({'plain':!![]});if(!_0x2eb0f7)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x2eb0f7[_0x0f07('0x4c')]==='user'){var _0xabd54c=_0xcf1f38[_0x0f07('0x28')]({'plain':!![]});var _0x36a24d='Pauses';return db['UserProfileSection'][_0x0f07('0x48')]({'where':{'name':_0x36a24d,'userProfileId':_0x2eb0f7['userProfileId']},'raw':!![]})[_0x0f07('0x27')](function(_0x8d5400){if(_0x8d5400&&_0x8d5400[_0x0f07('0x4d')]===0x0){return db['UserProfileResource'][_0x0f07('0x49')]({'name':_0xabd54c['name'],'resourceId':_0xabd54c['id'],'type':_0x8d5400[_0x0f07('0x2f')],'sectionId':_0x8d5400['id']},{})[_0x0f07('0x27')](function(){return _0xcf1f38;});}else{return _0xcf1f38;}})[_0x0f07('0x44')](function(_0x15e90a){logger[_0x0f07('0x2a')](_0x0f07('0x4e'),_0x15e90a);throw _0x15e90a;});}return _0xcf1f38;})['then'](respondWithResult(_0x27ceec,0xc9))[_0x0f07('0x44')](handleError(_0x27ceec,null));};exports['update']=function(_0x37401e,_0x1e5d8f){if(_0x37401e[_0x0f07('0x4a')]['id']){delete _0x37401e[_0x0f07('0x4a')]['id'];}return db['Pause'][_0x0f07('0x48')]({'where':{'id':_0x37401e[_0x0f07('0x46')]['id']}})[_0x0f07('0x27')](handleEntityNotFound(_0x1e5d8f,null))[_0x0f07('0x27')](saveUpdates(_0x37401e['body'],null))[_0x0f07('0x27')](respondWithResult(_0x1e5d8f,null))['catch'](handleError(_0x1e5d8f,null));};exports[_0x0f07('0x26')]=function(_0x36ba4d,_0x56e0b0){return db['Pause'][_0x0f07('0x48')]({'where':{'id':_0x36ba4d[_0x0f07('0x46')]['id']}})['then'](handleEntityNotFound(_0x56e0b0,null))['then'](removeEntity(_0x56e0b0,null))[_0x0f07('0x44')](handleError(_0x56e0b0,null));};