Built motion from commit 7158bc59.|2.5.42
[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 _0x6f67=['includeAll','include','findAll','rows','catch','params','options','find','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','eml-format','rimraf','zip-dir','fast-json-patch','moment','util','path','sox','ejs','squel','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','api','../../config/environment','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','destroy','Pauses','UserProfileResource','error','stack','name','send','index','map','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','order','sort','where','pick','filter','merge','VIRTUAL','Pause'];(function(_0x27af45,_0x1b57aa){var _0x18df21=function(_0x4b7679){while(--_0x4b7679){_0x27af45['push'](_0x27af45['shift']());}};_0x18df21(++_0x1b57aa);}(_0x6f67,0xfe));var _0x76f6=function(_0x595619,_0x3b7ea6){_0x595619=_0x595619-0x0;var _0x30a1e4=_0x6f67[_0x595619];return _0x30a1e4;};'use strict';var emlformat=require(_0x76f6('0x0'));var rimraf=require(_0x76f6('0x1'));var zipdir=require(_0x76f6('0x2'));var jsonpatch=require(_0x76f6('0x3'));var rp=require('request-promise');var moment=require(_0x76f6('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x76f6('0x5'));var path=require(_0x76f6('0x6'));var sox=require(_0x76f6('0x7'));var csv=require('to-csv');var ejs=require(_0x76f6('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x76f6('0x9'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x76f6('0xa'));var toCsv=require('to-csv');var querystring=require(_0x76f6('0xb'));var Papa=require(_0x76f6('0xc'));var Redis=require(_0x76f6('0xd'));var authService=require(_0x76f6('0xe'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x76f6('0xf'));var logger=require('../../config/logger')(_0x76f6('0x10'));var utils=require('../../config/utils');var config=require(_0x76f6('0x11'));var licenseUtil=require('../../config/license/util');var db=require(_0x76f6('0x12'))['db'];function respondWithStatusCode(_0x72e09,_0xd2ec10){_0xd2ec10=_0xd2ec10||0xcc;return function(_0x30aa9b){if(_0x30aa9b){return _0x72e09[_0x76f6('0x13')](_0xd2ec10);}return _0x72e09['status'](_0xd2ec10)['end']();};}function respondWithResult(_0x4a1a28,_0x143ada){_0x143ada=_0x143ada||0xc8;return function(_0x1c8f59){if(_0x1c8f59){return _0x4a1a28[_0x76f6('0x14')](_0x143ada)[_0x76f6('0x15')](_0x1c8f59);}};}function respondWithFilteredResult(_0x25786c,_0x566bd3){return function(_0x3ec6be){if(_0x3ec6be){var _0x44590b=typeof _0x566bd3[_0x76f6('0x16')]===_0x76f6('0x17')&&typeof _0x566bd3[_0x76f6('0x18')]===_0x76f6('0x17');var _0x3a4c23=_0x3ec6be[_0x76f6('0x19')];var _0x1db6f8=_0x44590b?0x0:_0x566bd3[_0x76f6('0x16')];var _0x5cd389=_0x44590b?_0x3ec6be[_0x76f6('0x19')]:_0x566bd3[_0x76f6('0x16')]+_0x566bd3[_0x76f6('0x18')];var _0x5d993c;if(_0x5cd389>=_0x3a4c23){_0x5cd389=_0x3a4c23;_0x5d993c=0xc8;}else{_0x5d993c=0xce;}_0x25786c[_0x76f6('0x14')](_0x5d993c);return _0x25786c[_0x76f6('0x1a')](_0x76f6('0x1b'),_0x1db6f8+'-'+_0x5cd389+'/'+_0x3a4c23)[_0x76f6('0x15')](_0x3ec6be);}return null;};}function patchUpdates(_0x32fcab){return function(_0x297ef5){try{jsonpatch[_0x76f6('0x1c')](_0x297ef5,_0x32fcab,!![]);}catch(_0x125672){return BPromise[_0x76f6('0x1d')](_0x125672);}return _0x297ef5[_0x76f6('0x1e')]();};}function saveUpdates(_0x2ccd65,_0x421fad){return function(_0x111da2){if(_0x111da2){return _0x111da2[_0x76f6('0x1f')](_0x2ccd65)[_0x76f6('0x20')](function(_0x106acc){return _0x106acc;});}return null;};}function removeEntity(_0x14bcb9,_0x7d089f){return function(_0x20cadb){if(_0x20cadb){return _0x20cadb[_0x76f6('0x21')]()[_0x76f6('0x20')](function(){var _0x5c6046=_0x20cadb['get']({'plain':!![]});var _0x41e239=_0x76f6('0x22');return db[_0x76f6('0x23')][_0x76f6('0x21')]({'where':{'type':_0x41e239,'resourceId':_0x5c6046['id']}})['then'](function(){return _0x20cadb;});})[_0x76f6('0x20')](function(){_0x14bcb9[_0x76f6('0x14')](0xcc)['end']();});}};}function handleEntityNotFound(_0x44c8ef,_0x482a4){return function(_0x4a7e23){if(!_0x4a7e23){_0x44c8ef[_0x76f6('0x13')](0x194);}return _0x4a7e23;};}function handleError(_0x19b819,_0x52a057){_0x52a057=_0x52a057||0x1f4;return function(_0x269a76){logger[_0x76f6('0x24')](_0x269a76[_0x76f6('0x25')]);if(_0x269a76[_0x76f6('0x26')]){delete _0x269a76[_0x76f6('0x26')];}_0x19b819[_0x76f6('0x14')](_0x52a057)[_0x76f6('0x27')](_0x269a76);};}exports[_0x76f6('0x28')]=function(_0x409d4b,_0x297b20){var _0x443317={},_0x435526={},_0x2b1382={'count':0x0,'rows':[]};var _0x5d2fa8=_[_0x76f6('0x29')](db['Pause'][_0x76f6('0x2a')],function(_0x5bc42e){return{'name':_0x5bc42e[_0x76f6('0x2b')],'type':_0x5bc42e[_0x76f6('0x2c')][_0x76f6('0x2d')]};});_0x435526[_0x76f6('0x2e')]=_[_0x76f6('0x29')](_0x5d2fa8,_0x76f6('0x26'));_0x435526[_0x76f6('0x2f')]=_[_0x76f6('0x30')](_0x409d4b[_0x76f6('0x2f')]);_0x435526[_0x76f6('0x31')]=_[_0x76f6('0x32')](_0x435526['model'],_0x435526[_0x76f6('0x2f')]);_0x443317[_0x76f6('0x33')]=_[_0x76f6('0x32')](_0x435526['model'],qs['fields'](_0x409d4b['query'][_0x76f6('0x34')]));_0x443317['attributes']=_0x443317[_0x76f6('0x33')][_0x76f6('0x35')]?_0x443317[_0x76f6('0x33')]:_0x435526[_0x76f6('0x2e')];if(!_0x409d4b[_0x76f6('0x2f')]['hasOwnProperty']('nolimit')){_0x443317[_0x76f6('0x18')]=qs['limit'](_0x409d4b[_0x76f6('0x2f')]['limit']);_0x443317[_0x76f6('0x16')]=qs[_0x76f6('0x16')](_0x409d4b['query'][_0x76f6('0x16')]);}_0x443317[_0x76f6('0x36')]=qs['sort'](_0x409d4b['query'][_0x76f6('0x37')]);_0x443317[_0x76f6('0x38')]=qs['filters'](_[_0x76f6('0x39')](_0x409d4b[_0x76f6('0x2f')],_0x435526[_0x76f6('0x31')]),_0x5d2fa8);if(_0x409d4b[_0x76f6('0x2f')][_0x76f6('0x3a')]){_0x443317['where']=_[_0x76f6('0x3b')](_0x443317[_0x76f6('0x38')],{'$or':_[_0x76f6('0x29')](_0x5d2fa8,function(_0x6c91de){if(_0x6c91de[_0x76f6('0x2c')]!==_0x76f6('0x3c')){var _0x43e08e={};_0x43e08e[_0x6c91de[_0x76f6('0x26')]]={'$like':'%'+_0x409d4b[_0x76f6('0x2f')][_0x76f6('0x3a')]+'%'};return _0x43e08e;}})});}_0x443317=_[_0x76f6('0x3b')]({},_0x443317,_0x409d4b['options']);var _0x2cf532={'where':_0x443317['where']};return db[_0x76f6('0x3d')][_0x76f6('0x19')](_0x2cf532)['then'](function(_0x3ec2ef){_0x2b1382['count']=_0x3ec2ef;if(_0x409d4b['query'][_0x76f6('0x3e')]){_0x443317[_0x76f6('0x3f')]=[{'all':!![]}];}return db[_0x76f6('0x3d')][_0x76f6('0x40')](_0x443317);})[_0x76f6('0x20')](function(_0x29694b){_0x2b1382[_0x76f6('0x41')]=_0x29694b;return _0x2b1382;})[_0x76f6('0x20')](respondWithFilteredResult(_0x297b20,_0x443317))[_0x76f6('0x42')](handleError(_0x297b20,null));};exports['show']=function(_0x55d7c5,_0x142a87){var _0x39e842={'raw':!![],'where':{'id':_0x55d7c5[_0x76f6('0x43')]['id']}},_0x3ccc53={};_0x3ccc53[_0x76f6('0x2e')]=_[_0x76f6('0x30')](db[_0x76f6('0x3d')][_0x76f6('0x2a')]);_0x3ccc53[_0x76f6('0x2f')]=_[_0x76f6('0x30')](_0x55d7c5['query']);_0x3ccc53[_0x76f6('0x31')]=_[_0x76f6('0x32')](_0x3ccc53['model'],_0x3ccc53[_0x76f6('0x2f')]);_0x39e842[_0x76f6('0x33')]=_['intersection'](_0x3ccc53['model'],qs[_0x76f6('0x34')](_0x55d7c5[_0x76f6('0x2f')][_0x76f6('0x34')]));_0x39e842[_0x76f6('0x33')]=_0x39e842[_0x76f6('0x33')][_0x76f6('0x35')]?_0x39e842[_0x76f6('0x33')]:_0x3ccc53[_0x76f6('0x2e')];if(_0x55d7c5['query'][_0x76f6('0x3e')]){_0x39e842[_0x76f6('0x3f')]=[{'all':!![]}];}_0x39e842=_[_0x76f6('0x3b')]({},_0x39e842,_0x55d7c5[_0x76f6('0x44')]);return db[_0x76f6('0x3d')][_0x76f6('0x45')](_0x39e842)['then'](handleEntityNotFound(_0x142a87,null))[_0x76f6('0x20')](respondWithResult(_0x142a87,null))[_0x76f6('0x42')](handleError(_0x142a87,null));};exports[_0x76f6('0x46')]=function(_0x1232ea,_0x53f4bc){return db['Pause'][_0x76f6('0x46')](_0x1232ea[_0x76f6('0x47')],{})['then'](function(_0x35a79a){var _0x40f394=_0x1232ea[_0x76f6('0x48')][_0x76f6('0x49')]({'plain':!![]});if(!_0x40f394)throw new Error(_0x76f6('0x4a'));if(_0x40f394[_0x76f6('0x4b')]===_0x76f6('0x48')){var _0x3ed792=_0x35a79a[_0x76f6('0x49')]({'plain':!![]});var _0x1fe650=_0x76f6('0x22');return db[_0x76f6('0x4c')][_0x76f6('0x45')]({'where':{'name':_0x1fe650,'userProfileId':_0x40f394[_0x76f6('0x4d')]},'raw':!![]})[_0x76f6('0x20')](function(_0xd566b2){if(_0xd566b2&&_0xd566b2[_0x76f6('0x4e')]===0x0){return db[_0x76f6('0x23')][_0x76f6('0x46')]({'name':_0x3ed792[_0x76f6('0x26')],'resourceId':_0x3ed792['id'],'type':_0xd566b2[_0x76f6('0x26')],'sectionId':_0xd566b2['id']},{})[_0x76f6('0x20')](function(){return _0x35a79a;});}else{return _0x35a79a;}})[_0x76f6('0x42')](function(_0x2b5716){logger[_0x76f6('0x24')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x2b5716);throw _0x2b5716;});}return _0x35a79a;})['then'](respondWithResult(_0x53f4bc,0xc9))['catch'](handleError(_0x53f4bc,null));};exports[_0x76f6('0x1f')]=function(_0xcaefb8,_0x171cd6){if(_0xcaefb8[_0x76f6('0x47')]['id']){delete _0xcaefb8[_0x76f6('0x47')]['id'];}return db[_0x76f6('0x3d')][_0x76f6('0x45')]({'where':{'id':_0xcaefb8[_0x76f6('0x43')]['id']}})[_0x76f6('0x20')](handleEntityNotFound(_0x171cd6,null))[_0x76f6('0x20')](saveUpdates(_0xcaefb8[_0x76f6('0x47')],null))['then'](respondWithResult(_0x171cd6,null))['catch'](handleError(_0x171cd6,null));};exports[_0x76f6('0x21')]=function(_0xd20bcd,_0x1de7dc){return db[_0x76f6('0x3d')][_0x76f6('0x45')]({'where':{'id':_0xd20bcd[_0x76f6('0x43')]['id']}})['then'](handleEntityNotFound(_0x1de7dc,null))[_0x76f6('0x20')](removeEntity(_0x1de7dc,null))[_0x76f6('0x42')](handleError(_0x1de7dc,null));};