Built motion from commit 092f8824.|2.5.49
[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 _0x80f6=['save','update','then','destroy','Pauses','UserProfileResource','end','error','stack','name','send','index','map','Pause','fieldName','key','model','keys','query','filters','intersection','fields','attributes','length','order','sort','where','pick','filter','merge','type','VIRTUAL','options','include','findAll','rows','catch','show','params','rawAttributes','includeAll','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','find','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','Content-Range','apply','reject'];(function(_0x543084,_0x4337f5){var _0x306a57=function(_0x2769ed){while(--_0x2769ed){_0x543084['push'](_0x543084['shift']());}};_0x306a57(++_0x4337f5);}(_0x80f6,0x89));var _0x680f=function(_0x17c197,_0x3bcb50){_0x17c197=_0x17c197-0x0;var _0x3d4e3f=_0x80f6[_0x17c197];return _0x3d4e3f;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x680f('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x680f('0x1'));var rp=require(_0x680f('0x2'));var moment=require('moment');var BPromise=require(_0x680f('0x3'));var Mustache=require(_0x680f('0x4'));var util=require(_0x680f('0x5'));var path=require(_0x680f('0x6'));var sox=require(_0x680f('0x7'));var csv=require(_0x680f('0x8'));var ejs=require(_0x680f('0x9'));var fs=require('fs');var fs_extra=require(_0x680f('0xa'));var _=require('lodash');var squel=require(_0x680f('0xb'));var crypto=require(_0x680f('0xc'));var jsforce=require(_0x680f('0xd'));var deskjs=require(_0x680f('0xe'));var toCsv=require(_0x680f('0x8'));var querystring=require(_0x680f('0xf'));var Papa=require(_0x680f('0x10'));var Redis=require(_0x680f('0x11'));var authService=require(_0x680f('0x12'));var qs=require(_0x680f('0x13'));var as=require(_0x680f('0x14'));var hardwareService=require(_0x680f('0x15'));var logger=require(_0x680f('0x16'))(_0x680f('0x17'));var utils=require(_0x680f('0x18'));var config=require('../../config/environment');var licenseUtil=require(_0x680f('0x19'));var db=require(_0x680f('0x1a'))['db'];function respondWithStatusCode(_0x9c8189,_0x1b7c8f){_0x1b7c8f=_0x1b7c8f||0xcc;return function(_0x382938){if(_0x382938){return _0x9c8189[_0x680f('0x1b')](_0x1b7c8f);}return _0x9c8189[_0x680f('0x1c')](_0x1b7c8f)['end']();};}function respondWithResult(_0x23f61e,_0x42ec97){_0x42ec97=_0x42ec97||0xc8;return function(_0x2deae9){if(_0x2deae9){return _0x23f61e[_0x680f('0x1c')](_0x42ec97)[_0x680f('0x1d')](_0x2deae9);}};}function respondWithFilteredResult(_0xd6ce26,_0x191a60){return function(_0x24c67b){if(_0x24c67b){var _0x29b58d=typeof _0x191a60[_0x680f('0x1e')]===_0x680f('0x1f')&&typeof _0x191a60[_0x680f('0x20')]===_0x680f('0x1f');var _0x1ecba1=_0x24c67b[_0x680f('0x21')];var _0x2f6561=_0x29b58d?0x0:_0x191a60[_0x680f('0x1e')];var _0x4008d0=_0x29b58d?_0x24c67b['count']:_0x191a60[_0x680f('0x1e')]+_0x191a60['limit'];var _0x2f7f7a;if(_0x4008d0>=_0x1ecba1){_0x4008d0=_0x1ecba1;_0x2f7f7a=0xc8;}else{_0x2f7f7a=0xce;}_0xd6ce26[_0x680f('0x1c')](_0x2f7f7a);return _0xd6ce26['set'](_0x680f('0x22'),_0x2f6561+'-'+_0x4008d0+'/'+_0x1ecba1)['json'](_0x24c67b);}return null;};}function patchUpdates(_0x2fd9cd){return function(_0x38a489){try{jsonpatch[_0x680f('0x23')](_0x38a489,_0x2fd9cd,!![]);}catch(_0x346125){return BPromise[_0x680f('0x24')](_0x346125);}return _0x38a489[_0x680f('0x25')]();};}function saveUpdates(_0x1359d3,_0x3e9be6){return function(_0xcf79e8){if(_0xcf79e8){return _0xcf79e8[_0x680f('0x26')](_0x1359d3)[_0x680f('0x27')](function(_0xe427fc){return _0xe427fc;});}return null;};}function removeEntity(_0x70da7a,_0x2c2f30){return function(_0x2f052d){if(_0x2f052d){return _0x2f052d[_0x680f('0x28')]()['then'](function(){var _0x29982e=_0x2f052d['get']({'plain':!![]});var _0x1601a5=_0x680f('0x29');return db[_0x680f('0x2a')][_0x680f('0x28')]({'where':{'type':_0x1601a5,'resourceId':_0x29982e['id']}})[_0x680f('0x27')](function(){return _0x2f052d;});})[_0x680f('0x27')](function(){_0x70da7a[_0x680f('0x1c')](0xcc)[_0x680f('0x2b')]();});}};}function handleEntityNotFound(_0x3a7ae0,_0x4352cd){return function(_0x40fe31){if(!_0x40fe31){_0x3a7ae0['sendStatus'](0x194);}return _0x40fe31;};}function handleError(_0x5a08ae,_0x8d431a){_0x8d431a=_0x8d431a||0x1f4;return function(_0x4d5f33){logger[_0x680f('0x2c')](_0x4d5f33[_0x680f('0x2d')]);if(_0x4d5f33[_0x680f('0x2e')]){delete _0x4d5f33[_0x680f('0x2e')];}_0x5a08ae[_0x680f('0x1c')](_0x8d431a)[_0x680f('0x2f')](_0x4d5f33);};}exports[_0x680f('0x30')]=function(_0x3adfa1,_0x5ac518){var _0x21bc39={},_0x203a92={},_0x468a46={'count':0x0,'rows':[]};var _0x392260=_[_0x680f('0x31')](db[_0x680f('0x32')]['rawAttributes'],function(_0x48b1d1){return{'name':_0x48b1d1[_0x680f('0x33')],'type':_0x48b1d1['type'][_0x680f('0x34')]};});_0x203a92[_0x680f('0x35')]=_['map'](_0x392260,_0x680f('0x2e'));_0x203a92['query']=_[_0x680f('0x36')](_0x3adfa1[_0x680f('0x37')]);_0x203a92[_0x680f('0x38')]=_['intersection'](_0x203a92['model'],_0x203a92[_0x680f('0x37')]);_0x21bc39['attributes']=_[_0x680f('0x39')](_0x203a92[_0x680f('0x35')],qs[_0x680f('0x3a')](_0x3adfa1[_0x680f('0x37')]['fields']));_0x21bc39[_0x680f('0x3b')]=_0x21bc39[_0x680f('0x3b')][_0x680f('0x3c')]?_0x21bc39[_0x680f('0x3b')]:_0x203a92[_0x680f('0x35')];if(!_0x3adfa1[_0x680f('0x37')]['hasOwnProperty']('nolimit')){_0x21bc39[_0x680f('0x20')]=qs[_0x680f('0x20')](_0x3adfa1['query']['limit']);_0x21bc39[_0x680f('0x1e')]=qs[_0x680f('0x1e')](_0x3adfa1[_0x680f('0x37')][_0x680f('0x1e')]);}_0x21bc39[_0x680f('0x3d')]=qs[_0x680f('0x3e')](_0x3adfa1[_0x680f('0x37')][_0x680f('0x3e')]);_0x21bc39[_0x680f('0x3f')]=qs[_0x680f('0x38')](_[_0x680f('0x40')](_0x3adfa1[_0x680f('0x37')],_0x203a92['filters']),_0x392260);if(_0x3adfa1[_0x680f('0x37')][_0x680f('0x41')]){_0x21bc39[_0x680f('0x3f')]=_[_0x680f('0x42')](_0x21bc39[_0x680f('0x3f')],{'$or':_[_0x680f('0x31')](_0x392260,function(_0x1cc20b){if(_0x1cc20b[_0x680f('0x43')]!==_0x680f('0x44')){var _0x1d8bbc={};_0x1d8bbc[_0x1cc20b[_0x680f('0x2e')]]={'$like':'%'+_0x3adfa1[_0x680f('0x37')]['filter']+'%'};return _0x1d8bbc;}})});}_0x21bc39=_[_0x680f('0x42')]({},_0x21bc39,_0x3adfa1[_0x680f('0x45')]);var _0x4fa699={'where':_0x21bc39[_0x680f('0x3f')]};return db[_0x680f('0x32')][_0x680f('0x21')](_0x4fa699)['then'](function(_0x1e4128){_0x468a46[_0x680f('0x21')]=_0x1e4128;if(_0x3adfa1[_0x680f('0x37')]['includeAll']){_0x21bc39[_0x680f('0x46')]=[{'all':!![]}];}return db[_0x680f('0x32')][_0x680f('0x47')](_0x21bc39);})[_0x680f('0x27')](function(_0x28ebf6){_0x468a46[_0x680f('0x48')]=_0x28ebf6;return _0x468a46;})['then'](respondWithFilteredResult(_0x5ac518,_0x21bc39))[_0x680f('0x49')](handleError(_0x5ac518,null));};exports[_0x680f('0x4a')]=function(_0x27e783,_0x10683c){var _0x2517eb={'raw':!![],'where':{'id':_0x27e783[_0x680f('0x4b')]['id']}},_0x5e1007={};_0x5e1007[_0x680f('0x35')]=_['keys'](db[_0x680f('0x32')][_0x680f('0x4c')]);_0x5e1007[_0x680f('0x37')]=_[_0x680f('0x36')](_0x27e783[_0x680f('0x37')]);_0x5e1007[_0x680f('0x38')]=_[_0x680f('0x39')](_0x5e1007['model'],_0x5e1007[_0x680f('0x37')]);_0x2517eb[_0x680f('0x3b')]=_[_0x680f('0x39')](_0x5e1007[_0x680f('0x35')],qs[_0x680f('0x3a')](_0x27e783[_0x680f('0x37')][_0x680f('0x3a')]));_0x2517eb[_0x680f('0x3b')]=_0x2517eb[_0x680f('0x3b')][_0x680f('0x3c')]?_0x2517eb[_0x680f('0x3b')]:_0x5e1007['model'];if(_0x27e783[_0x680f('0x37')][_0x680f('0x4d')]){_0x2517eb[_0x680f('0x46')]=[{'all':!![]}];}_0x2517eb=_[_0x680f('0x42')]({},_0x2517eb,_0x27e783[_0x680f('0x45')]);return db['Pause']['find'](_0x2517eb)['then'](handleEntityNotFound(_0x10683c,null))['then'](respondWithResult(_0x10683c,null))[_0x680f('0x49')](handleError(_0x10683c,null));};exports[_0x680f('0x4e')]=function(_0x4c44ec,_0x172a86){return db['Pause']['create'](_0x4c44ec[_0x680f('0x4f')],{})[_0x680f('0x27')](function(_0x55bc22){var _0xb5f2e4=_0x4c44ec[_0x680f('0x50')]['get']({'plain':!![]});if(!_0xb5f2e4)throw new Error(_0x680f('0x51'));if(_0xb5f2e4[_0x680f('0x52')]===_0x680f('0x50')){var _0x7f43fb=_0x55bc22['get']({'plain':!![]});var _0x348e1e=_0x680f('0x29');return db[_0x680f('0x53')]['find']({'where':{'name':_0x348e1e,'userProfileId':_0xb5f2e4['userProfileId']},'raw':!![]})[_0x680f('0x27')](function(_0x48f65c){if(_0x48f65c&&_0x48f65c[_0x680f('0x54')]===0x0){return db[_0x680f('0x2a')][_0x680f('0x4e')]({'name':_0x7f43fb[_0x680f('0x2e')],'resourceId':_0x7f43fb['id'],'type':_0x48f65c['name'],'sectionId':_0x48f65c['id']},{})[_0x680f('0x27')](function(){return _0x55bc22;});}else{return _0x55bc22;}})[_0x680f('0x49')](function(_0x5d97ff){logger[_0x680f('0x2c')](_0x680f('0x55'),_0x5d97ff);throw _0x5d97ff;});}return _0x55bc22;})[_0x680f('0x27')](respondWithResult(_0x172a86,0xc9))['catch'](handleError(_0x172a86,null));};exports[_0x680f('0x26')]=function(_0x468d1d,_0x6cf1b6){if(_0x468d1d['body']['id']){delete _0x468d1d[_0x680f('0x4f')]['id'];}return db['Pause']['find']({'where':{'id':_0x468d1d['params']['id']}})[_0x680f('0x27')](handleEntityNotFound(_0x6cf1b6,null))[_0x680f('0x27')](saveUpdates(_0x468d1d[_0x680f('0x4f')],null))['then'](respondWithResult(_0x6cf1b6,null))[_0x680f('0x49')](handleError(_0x6cf1b6,null));};exports[_0x680f('0x28')]=function(_0x1719da,_0x528d16){return db[_0x680f('0x32')][_0x680f('0x56')]({'where':{'id':_0x1719da['params']['id']}})[_0x680f('0x27')](handleEntityNotFound(_0x528d16,null))[_0x680f('0x27')](removeEntity(_0x528d16,null))[_0x680f('0x49')](handleError(_0x528d16,null));};