Built motion from commit 55091a5c.|2.6.30
[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 _0xfd3b=['limit','count','set','Content-Range','json','apply','reject','save','update','destroy','get','Pauses','UserProfileResource','then','sendStatus','error','name','send','index','map','Pause','rawAttributes','fieldName','type','key','query','keys','filters','intersection','model','attributes','fields','length','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','findAll','rows','catch','show','params','includeAll','include','find','create','body','user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','status','end','offset','undefined'];(function(_0x57b54c,_0x54ce0d){var _0x59cc19=function(_0xa33bc6){while(--_0xa33bc6){_0x57b54c['push'](_0x57b54c['shift']());}};_0x59cc19(++_0x54ce0d);}(_0xfd3b,0x147));var _0xbfd3=function(_0x385b71,_0x2ae587){_0x385b71=_0x385b71-0x0;var _0x72ac1d=_0xfd3b[_0x385b71];return _0x72ac1d;};'use strict';var emlformat=require(_0xbfd3('0x0'));var rimraf=require(_0xbfd3('0x1'));var zipdir=require(_0xbfd3('0x2'));var jsonpatch=require(_0xbfd3('0x3'));var rp=require(_0xbfd3('0x4'));var moment=require(_0xbfd3('0x5'));var BPromise=require(_0xbfd3('0x6'));var Mustache=require(_0xbfd3('0x7'));var util=require(_0xbfd3('0x8'));var path=require(_0xbfd3('0x9'));var sox=require('sox');var csv=require(_0xbfd3('0xa'));var ejs=require(_0xbfd3('0xb'));var fs=require('fs');var fs_extra=require(_0xbfd3('0xc'));var _=require(_0xbfd3('0xd'));var squel=require(_0xbfd3('0xe'));var crypto=require(_0xbfd3('0xf'));var jsforce=require(_0xbfd3('0x10'));var deskjs=require(_0xbfd3('0x11'));var toCsv=require(_0xbfd3('0xa'));var querystring=require(_0xbfd3('0x12'));var Papa=require(_0xbfd3('0x13'));var Redis=require(_0xbfd3('0x14'));var authService=require('../../components/auth/service');var qs=require(_0xbfd3('0x15'));var as=require(_0xbfd3('0x16'));var hardwareService=require(_0xbfd3('0x17'));var logger=require(_0xbfd3('0x18'))(_0xbfd3('0x19'));var utils=require(_0xbfd3('0x1a'));var config=require(_0xbfd3('0x1b'));var licenseUtil=require(_0xbfd3('0x1c'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x496426,_0x138adc){_0x138adc=_0x138adc||0xcc;return function(_0x560dc4){if(_0x560dc4){return _0x496426['sendStatus'](_0x138adc);}return _0x496426[_0xbfd3('0x1d')](_0x138adc)[_0xbfd3('0x1e')]();};}function respondWithResult(_0xeaf6a5,_0x4956d8){_0x4956d8=_0x4956d8||0xc8;return function(_0x260821){if(_0x260821){return _0xeaf6a5['status'](_0x4956d8)['json'](_0x260821);}};}function respondWithFilteredResult(_0x49ab9b,_0x1030bf){return function(_0x55e383){if(_0x55e383){var _0x39a1f1=typeof _0x1030bf[_0xbfd3('0x1f')]===_0xbfd3('0x20')&&typeof _0x1030bf[_0xbfd3('0x21')]===_0xbfd3('0x20');var _0xbb18f4=_0x55e383[_0xbfd3('0x22')];var _0x46d05c=_0x39a1f1?0x0:_0x1030bf[_0xbfd3('0x1f')];var _0x251678=_0x39a1f1?_0x55e383[_0xbfd3('0x22')]:_0x1030bf['offset']+_0x1030bf['limit'];var _0x4df81d;if(_0x251678>=_0xbb18f4){_0x251678=_0xbb18f4;_0x4df81d=0xc8;}else{_0x4df81d=0xce;}_0x49ab9b[_0xbfd3('0x1d')](_0x4df81d);return _0x49ab9b[_0xbfd3('0x23')](_0xbfd3('0x24'),_0x46d05c+'-'+_0x251678+'/'+_0xbb18f4)[_0xbfd3('0x25')](_0x55e383);}return null;};}function patchUpdates(_0x5df906){return function(_0x50e738){try{jsonpatch[_0xbfd3('0x26')](_0x50e738,_0x5df906,!![]);}catch(_0x1a534f){return BPromise[_0xbfd3('0x27')](_0x1a534f);}return _0x50e738[_0xbfd3('0x28')]();};}function saveUpdates(_0x354a36,_0x590eae){return function(_0x11bc3a){if(_0x11bc3a){return _0x11bc3a[_0xbfd3('0x29')](_0x354a36)['then'](function(_0x2e5d26){return _0x2e5d26;});}return null;};}function removeEntity(_0x203f72,_0x309986){return function(_0x4d4576){if(_0x4d4576){return _0x4d4576[_0xbfd3('0x2a')]()['then'](function(){var _0x25b4ae=_0x4d4576[_0xbfd3('0x2b')]({'plain':!![]});var _0x2439c2=_0xbfd3('0x2c');return db[_0xbfd3('0x2d')]['destroy']({'where':{'type':_0x2439c2,'resourceId':_0x25b4ae['id']}})[_0xbfd3('0x2e')](function(){return _0x4d4576;});})[_0xbfd3('0x2e')](function(){_0x203f72[_0xbfd3('0x1d')](0xcc)[_0xbfd3('0x1e')]();});}};}function handleEntityNotFound(_0x2489e5,_0xbaf44e){return function(_0x26efa9){if(!_0x26efa9){_0x2489e5[_0xbfd3('0x2f')](0x194);}return _0x26efa9;};}function handleError(_0x59769d,_0x4723d4){_0x4723d4=_0x4723d4||0x1f4;return function(_0x3d06){logger[_0xbfd3('0x30')](_0x3d06['stack']);if(_0x3d06[_0xbfd3('0x31')]){delete _0x3d06[_0xbfd3('0x31')];}_0x59769d[_0xbfd3('0x1d')](_0x4723d4)[_0xbfd3('0x32')](_0x3d06);};}exports[_0xbfd3('0x33')]=function(_0x264f85,_0x4aff34){var _0x5f4af5={},_0x151e21={},_0x2059f5={'count':0x0,'rows':[]};var _0x4ceab8=_[_0xbfd3('0x34')](db[_0xbfd3('0x35')][_0xbfd3('0x36')],function(_0x2afcba){return{'name':_0x2afcba[_0xbfd3('0x37')],'type':_0x2afcba[_0xbfd3('0x38')][_0xbfd3('0x39')]};});_0x151e21['model']=_['map'](_0x4ceab8,_0xbfd3('0x31'));_0x151e21[_0xbfd3('0x3a')]=_[_0xbfd3('0x3b')](_0x264f85['query']);_0x151e21[_0xbfd3('0x3c')]=_[_0xbfd3('0x3d')](_0x151e21[_0xbfd3('0x3e')],_0x151e21[_0xbfd3('0x3a')]);_0x5f4af5[_0xbfd3('0x3f')]=_[_0xbfd3('0x3d')](_0x151e21[_0xbfd3('0x3e')],qs['fields'](_0x264f85['query'][_0xbfd3('0x40')]));_0x5f4af5[_0xbfd3('0x3f')]=_0x5f4af5[_0xbfd3('0x3f')][_0xbfd3('0x41')]?_0x5f4af5[_0xbfd3('0x3f')]:_0x151e21[_0xbfd3('0x3e')];if(!_0x264f85[_0xbfd3('0x3a')]['hasOwnProperty'](_0xbfd3('0x42'))){_0x5f4af5[_0xbfd3('0x21')]=qs[_0xbfd3('0x21')](_0x264f85['query'][_0xbfd3('0x21')]);_0x5f4af5[_0xbfd3('0x1f')]=qs['offset'](_0x264f85[_0xbfd3('0x3a')][_0xbfd3('0x1f')]);}_0x5f4af5[_0xbfd3('0x43')]=qs[_0xbfd3('0x44')](_0x264f85['query'][_0xbfd3('0x44')]);_0x5f4af5[_0xbfd3('0x45')]=qs[_0xbfd3('0x3c')](_[_0xbfd3('0x46')](_0x264f85[_0xbfd3('0x3a')],_0x151e21[_0xbfd3('0x3c')]),_0x4ceab8);if(_0x264f85['query'][_0xbfd3('0x47')]){_0x5f4af5[_0xbfd3('0x45')]=_[_0xbfd3('0x48')](_0x5f4af5[_0xbfd3('0x45')],{'$or':_[_0xbfd3('0x34')](_0x4ceab8,function(_0x27e7c9){if(_0x27e7c9[_0xbfd3('0x38')]!==_0xbfd3('0x49')){var _0x74e8a1={};_0x74e8a1[_0x27e7c9[_0xbfd3('0x31')]]={'$like':'%'+_0x264f85[_0xbfd3('0x3a')]['filter']+'%'};return _0x74e8a1;}})});}_0x5f4af5=_[_0xbfd3('0x48')]({},_0x5f4af5,_0x264f85[_0xbfd3('0x4a')]);var _0x2cdf7a={'where':_0x5f4af5[_0xbfd3('0x45')]};return db[_0xbfd3('0x35')]['count'](_0x2cdf7a)['then'](function(_0x3a5aef){_0x2059f5['count']=_0x3a5aef;if(_0x264f85[_0xbfd3('0x3a')]['includeAll']){_0x5f4af5['include']=[{'all':!![]}];}return db[_0xbfd3('0x35')][_0xbfd3('0x4b')](_0x5f4af5);})[_0xbfd3('0x2e')](function(_0x20b4e9){_0x2059f5[_0xbfd3('0x4c')]=_0x20b4e9;return _0x2059f5;})['then'](respondWithFilteredResult(_0x4aff34,_0x5f4af5))[_0xbfd3('0x4d')](handleError(_0x4aff34,null));};exports[_0xbfd3('0x4e')]=function(_0xd3a6f0,_0x140bca){var _0x35c675={'raw':!![],'where':{'id':_0xd3a6f0[_0xbfd3('0x4f')]['id']}},_0x4faea3={};_0x4faea3['model']=_['keys'](db[_0xbfd3('0x35')][_0xbfd3('0x36')]);_0x4faea3[_0xbfd3('0x3a')]=_[_0xbfd3('0x3b')](_0xd3a6f0[_0xbfd3('0x3a')]);_0x4faea3[_0xbfd3('0x3c')]=_[_0xbfd3('0x3d')](_0x4faea3[_0xbfd3('0x3e')],_0x4faea3[_0xbfd3('0x3a')]);_0x35c675['attributes']=_[_0xbfd3('0x3d')](_0x4faea3['model'],qs[_0xbfd3('0x40')](_0xd3a6f0[_0xbfd3('0x3a')][_0xbfd3('0x40')]));_0x35c675['attributes']=_0x35c675['attributes'][_0xbfd3('0x41')]?_0x35c675[_0xbfd3('0x3f')]:_0x4faea3[_0xbfd3('0x3e')];if(_0xd3a6f0[_0xbfd3('0x3a')][_0xbfd3('0x50')]){_0x35c675[_0xbfd3('0x51')]=[{'all':!![]}];}_0x35c675=_['merge']({},_0x35c675,_0xd3a6f0[_0xbfd3('0x4a')]);return db[_0xbfd3('0x35')][_0xbfd3('0x52')](_0x35c675)[_0xbfd3('0x2e')](handleEntityNotFound(_0x140bca,null))[_0xbfd3('0x2e')](respondWithResult(_0x140bca,null))[_0xbfd3('0x4d')](handleError(_0x140bca,null));};exports[_0xbfd3('0x53')]=function(_0x2cab45,_0x46e893){return db[_0xbfd3('0x35')][_0xbfd3('0x53')](_0x2cab45[_0xbfd3('0x54')],{})[_0xbfd3('0x2e')](function(_0x323f76){var _0x5821be=_0x2cab45[_0xbfd3('0x55')][_0xbfd3('0x2b')]({'plain':!![]});if(!_0x5821be)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x5821be['role']===_0xbfd3('0x55')){var _0x1c354e=_0x323f76[_0xbfd3('0x2b')]({'plain':!![]});var _0x20741f=_0xbfd3('0x2c');return db[_0xbfd3('0x56')][_0xbfd3('0x52')]({'where':{'name':_0x20741f,'userProfileId':_0x5821be[_0xbfd3('0x57')]},'raw':!![]})[_0xbfd3('0x2e')](function(_0x38549c){if(_0x38549c&&_0x38549c[_0xbfd3('0x58')]===0x0){return db['UserProfileResource'][_0xbfd3('0x53')]({'name':_0x1c354e['name'],'resourceId':_0x1c354e['id'],'type':_0x38549c[_0xbfd3('0x31')],'sectionId':_0x38549c['id']},{})[_0xbfd3('0x2e')](function(){return _0x323f76;});}else{return _0x323f76;}})['catch'](function(_0x5c0cc6){logger[_0xbfd3('0x30')](_0xbfd3('0x59'),_0x5c0cc6);throw _0x5c0cc6;});}return _0x323f76;})[_0xbfd3('0x2e')](respondWithResult(_0x46e893,0xc9))['catch'](handleError(_0x46e893,null));};exports['update']=function(_0x4b3624,_0x3d66e8){if(_0x4b3624[_0xbfd3('0x54')]['id']){delete _0x4b3624['body']['id'];}return db[_0xbfd3('0x35')][_0xbfd3('0x52')]({'where':{'id':_0x4b3624[_0xbfd3('0x4f')]['id']}})[_0xbfd3('0x2e')](handleEntityNotFound(_0x3d66e8,null))['then'](saveUpdates(_0x4b3624[_0xbfd3('0x54')],null))['then'](respondWithResult(_0x3d66e8,null))[_0xbfd3('0x4d')](handleError(_0x3d66e8,null));};exports[_0xbfd3('0x2a')]=function(_0x39d6ac,_0xfc8225){return db[_0xbfd3('0x35')][_0xbfd3('0x52')]({'where':{'id':_0x39d6ac['params']['id']}})['then'](handleEntityNotFound(_0xfc8225,null))[_0xbfd3('0x2e')](removeEntity(_0xfc8225,null))['catch'](handleError(_0xfc8225,null));};