Built motion from commit (unavailable).|2.5.1
[motion2.git] / server / api / schedule / schedule.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 _0x332f=['name','send','index','map','Schedule','fieldName','key','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','order','sort','where','pick','filter','merge','type','VIRTUAL','count','includeAll','include','findAll','rows','catch','show','params','keys','rawAttributes','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','Scheduler','autoAssociation','run','../../config/schedule','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','lodash','squel','crypto','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','get','UserProfileResource','error'];(function(_0x48ab04,_0x160f27){var _0x1904e4=function(_0x8bacd9){while(--_0x8bacd9){_0x48ab04['push'](_0x48ab04['shift']());}};_0x1904e4(++_0x160f27);}(_0x332f,0x1da));var _0xf332=function(_0x33f3e7,_0x57d963){_0x33f3e7=_0x33f3e7-0x0;var _0x5a9d31=_0x332f[_0x33f3e7];return _0x5a9d31;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xf332('0x0'));var rimraf=require(_0xf332('0x1'));var zipdir=require(_0xf332('0x2'));var jsonpatch=require(_0xf332('0x3'));var rp=require(_0xf332('0x4'));var moment=require(_0xf332('0x5'));var BPromise=require(_0xf332('0x6'));var Mustache=require(_0xf332('0x7'));var util=require(_0xf332('0x8'));var path=require(_0xf332('0x9'));var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xf332('0xa'));var squel=require(_0xf332('0xb'));var crypto=require(_0xf332('0xc'));var jsforce=require('jsforce');var deskjs=require(_0xf332('0xd'));var toCsv=require(_0xf332('0xe'));var querystring=require(_0xf332('0xf'));var Papa=require(_0xf332('0x10'));var Redis=require(_0xf332('0x11'));var authService=require(_0xf332('0x12'));var qs=require(_0xf332('0x13'));var as=require(_0xf332('0x14'));var hardwareService=require(_0xf332('0x15'));var logger=require(_0xf332('0x16'))('api');var utils=require('../../config/utils');var config=require(_0xf332('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0xf332('0x18'))['db'];function respondWithStatusCode(_0x4fc738,_0x236724){_0x236724=_0x236724||0xcc;return function(_0x1faad1){if(_0x1faad1){return _0x4fc738[_0xf332('0x19')](_0x236724);}return _0x4fc738[_0xf332('0x1a')](_0x236724)[_0xf332('0x1b')]();};}function respondWithResult(_0x30fa1a,_0x2a1291){_0x2a1291=_0x2a1291||0xc8;return function(_0x48365a){if(_0x48365a){return _0x30fa1a[_0xf332('0x1a')](_0x2a1291)[_0xf332('0x1c')](_0x48365a);}};}function respondWithFilteredResult(_0x2c6984,_0x1a0fdd){return function(_0x3f8a4f){if(_0x3f8a4f){var _0x4a1675=_0x3f8a4f['count'],_0x218be4=_0x1a0fdd[_0xf332('0x1d')],_0x20329b=_0x1a0fdd[_0xf332('0x1d')]+_0x1a0fdd[_0xf332('0x1e')],_0x24e270;if(_0x20329b>=_0x4a1675){_0x20329b=_0x4a1675;_0x24e270=0xc8;}else{_0x24e270=0xce;}_0x2c6984[_0xf332('0x1a')](_0x24e270);return _0x2c6984[_0xf332('0x1f')](_0xf332('0x20'),_0x218be4+'-'+_0x20329b+'/'+_0x4a1675)[_0xf332('0x1c')](_0x3f8a4f);}return null;};}function patchUpdates(_0x54d105){return function(_0x5eafa3){try{jsonpatch[_0xf332('0x21')](_0x5eafa3,_0x54d105,!![]);}catch(_0x1f6bee){return BPromise[_0xf332('0x22')](_0x1f6bee);}return _0x5eafa3[_0xf332('0x23')]();};}function saveUpdates(_0x4b719f,_0x223a19){return function(_0x541785){if(_0x541785){return _0x541785[_0xf332('0x24')](_0x4b719f)[_0xf332('0x25')](function(_0x1f1b43){return _0x1f1b43;});}return null;};}function removeEntity(_0x2e5e54,_0x3fcc8c){return function(_0x38f898){if(_0x38f898){return _0x38f898[_0xf332('0x26')]()[_0xf332('0x25')](function(){var _0x480964=_0x38f898[_0xf332('0x27')]({'plain':!![]});var _0xbc4207='Scheduler';return db[_0xf332('0x28')][_0xf332('0x26')]({'where':{'type':_0xbc4207,'resourceId':_0x480964['id']}})[_0xf332('0x25')](function(){return _0x38f898;});})[_0xf332('0x25')](function(){_0x2e5e54[_0xf332('0x1a')](0xcc)[_0xf332('0x1b')]();});}};}function handleEntityNotFound(_0x48cf28,_0x1f187d){return function(_0x5e6332){if(!_0x5e6332){_0x48cf28[_0xf332('0x19')](0x194);}return _0x5e6332;};}function handleError(_0x357fdc,_0x3931e9){_0x3931e9=_0x3931e9||0x1f4;return function(_0x2c3720){logger[_0xf332('0x29')](_0x2c3720['stack']);if(_0x2c3720[_0xf332('0x2a')]){delete _0x2c3720[_0xf332('0x2a')];}_0x357fdc[_0xf332('0x1a')](_0x3931e9)[_0xf332('0x2b')](_0x2c3720);};}exports[_0xf332('0x2c')]=function(_0x1d019a,_0x102cb0){var _0x2b6c67={},_0x42d4f6={},_0x3f8be2={'count':0x0,'rows':[]};var _0x28b773=_[_0xf332('0x2d')](db[_0xf332('0x2e')]['rawAttributes'],function(_0x327d44){return{'name':_0x327d44[_0xf332('0x2f')],'type':_0x327d44['type'][_0xf332('0x30')]};});_0x42d4f6[_0xf332('0x31')]=_[_0xf332('0x2d')](_0x28b773,'name');_0x42d4f6[_0xf332('0x32')]=_['keys'](_0x1d019a[_0xf332('0x32')]);_0x42d4f6[_0xf332('0x33')]=_['intersection'](_0x42d4f6[_0xf332('0x31')],_0x42d4f6['query']);_0x2b6c67['attributes']=_[_0xf332('0x34')](_0x42d4f6[_0xf332('0x31')],qs[_0xf332('0x35')](_0x1d019a[_0xf332('0x32')][_0xf332('0x35')]));_0x2b6c67[_0xf332('0x36')]=_0x2b6c67[_0xf332('0x36')][_0xf332('0x37')]?_0x2b6c67[_0xf332('0x36')]:_0x42d4f6[_0xf332('0x31')];if(!_0x1d019a[_0xf332('0x32')][_0xf332('0x38')]('nolimit')){_0x2b6c67[_0xf332('0x1e')]=qs['limit'](_0x1d019a[_0xf332('0x32')][_0xf332('0x1e')]);_0x2b6c67['offset']=qs['offset'](_0x1d019a[_0xf332('0x32')][_0xf332('0x1d')]);}_0x2b6c67[_0xf332('0x39')]=qs[_0xf332('0x3a')](_0x1d019a[_0xf332('0x32')]['sort']);_0x2b6c67[_0xf332('0x3b')]=qs[_0xf332('0x33')](_[_0xf332('0x3c')](_0x1d019a[_0xf332('0x32')],_0x42d4f6[_0xf332('0x33')]),_0x28b773);if(_0x1d019a[_0xf332('0x32')][_0xf332('0x3d')]){_0x2b6c67[_0xf332('0x3b')]=_[_0xf332('0x3e')](_0x2b6c67[_0xf332('0x3b')],{'$or':_['map'](_0x28b773,function(_0x687f95){if(_0x687f95[_0xf332('0x3f')]!==_0xf332('0x40')){var _0x2fb401={};_0x2fb401[_0x687f95['name']]={'$like':'%'+_0x1d019a[_0xf332('0x32')][_0xf332('0x3d')]+'%'};return _0x2fb401;}})});}_0x2b6c67=_[_0xf332('0x3e')]({},_0x2b6c67,_0x1d019a['options']);var _0x470c14={'where':_0x2b6c67['where']};return db[_0xf332('0x2e')][_0xf332('0x41')](_0x470c14)['then'](function(_0x44b24c){_0x3f8be2[_0xf332('0x41')]=_0x44b24c;if(_0x1d019a[_0xf332('0x32')][_0xf332('0x42')]){_0x2b6c67[_0xf332('0x43')]=[{'all':!![]}];}return db[_0xf332('0x2e')][_0xf332('0x44')](_0x2b6c67);})[_0xf332('0x25')](function(_0x3994f2){_0x3f8be2[_0xf332('0x45')]=_0x3994f2;return _0x3f8be2;})[_0xf332('0x25')](respondWithFilteredResult(_0x102cb0,_0x2b6c67))[_0xf332('0x46')](handleError(_0x102cb0,null));};exports[_0xf332('0x47')]=function(_0x4ee78b,_0x4f1411){var _0x17475e={'raw':![],'where':{'id':_0x4ee78b[_0xf332('0x48')]['id']}},_0x315280={};_0x315280[_0xf332('0x31')]=_[_0xf332('0x49')](db[_0xf332('0x2e')][_0xf332('0x4a')]);_0x315280['query']=_[_0xf332('0x49')](_0x4ee78b[_0xf332('0x32')]);_0x315280[_0xf332('0x33')]=_[_0xf332('0x34')](_0x315280['model'],_0x315280[_0xf332('0x32')]);_0x17475e[_0xf332('0x36')]=_[_0xf332('0x34')](_0x315280[_0xf332('0x31')],qs[_0xf332('0x35')](_0x4ee78b[_0xf332('0x32')]['fields']));_0x17475e[_0xf332('0x36')]=_0x17475e[_0xf332('0x36')][_0xf332('0x37')]?_0x17475e[_0xf332('0x36')]:_0x315280['model'];if(_0x4ee78b[_0xf332('0x32')][_0xf332('0x42')]){_0x17475e[_0xf332('0x43')]=[{'all':!![]}];}_0x17475e=_[_0xf332('0x3e')]({},_0x17475e,_0x4ee78b[_0xf332('0x4b')]);return db['Schedule'][_0xf332('0x4c')](_0x17475e)[_0xf332('0x25')](handleEntityNotFound(_0x4f1411,null))[_0xf332('0x25')](respondWithResult(_0x4f1411,null))[_0xf332('0x46')](handleError(_0x4f1411,null));};exports['create']=function(_0xad2158,_0x213b46){return db[_0xf332('0x2e')][_0xf332('0x4d')](_0xad2158[_0xf332('0x4e')],{})[_0xf332('0x25')](function(_0x23b2ff){var _0x2d1afb=_0xad2158[_0xf332('0x4f')][_0xf332('0x27')]({'plain':!![]});if(!_0x2d1afb)throw new Error(_0xf332('0x50'));if(_0x2d1afb[_0xf332('0x51')]==='user'){var _0x3495c1=_0x23b2ff[_0xf332('0x27')]({'plain':!![]});var _0x525249=_0xf332('0x52');return db['UserProfileSection'][_0xf332('0x4c')]({'where':{'name':_0x525249,'userProfileId':_0x2d1afb['userProfileId']},'raw':!![]})[_0xf332('0x25')](function(_0x31c86f){if(_0x31c86f&&_0x31c86f[_0xf332('0x53')]===0x0){return db[_0xf332('0x28')][_0xf332('0x4d')]({'name':_0x3495c1[_0xf332('0x2a')],'resourceId':_0x3495c1['id'],'type':_0x31c86f[_0xf332('0x2a')],'sectionId':_0x31c86f['id']},{})[_0xf332('0x25')](function(){return _0x23b2ff;});}else{return _0x23b2ff;}})['catch'](function(_0x32ac0d){logger[_0xf332('0x29')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x32ac0d);throw _0x32ac0d;});}return _0x23b2ff;})[_0xf332('0x25')](respondWithResult(_0x213b46,0xc9))['catch'](handleError(_0x213b46,null));};exports[_0xf332('0x24')]=function(_0x372d0f,_0x360355){if(_0x372d0f[_0xf332('0x4e')]['id']){delete _0x372d0f[_0xf332('0x4e')]['id'];}return db[_0xf332('0x2e')]['find']({'where':{'id':_0x372d0f[_0xf332('0x48')]['id']}})[_0xf332('0x25')](handleEntityNotFound(_0x360355,null))[_0xf332('0x25')](saveUpdates(_0x372d0f['body'],null))[_0xf332('0x25')](respondWithResult(_0x360355,null))[_0xf332('0x46')](handleError(_0x360355,null));};exports[_0xf332('0x26')]=function(_0x48e69a,_0x5711d2){return db['Schedule'][_0xf332('0x4c')]({'where':{'id':_0x48e69a['params']['id']}})[_0xf332('0x25')](handleEntityNotFound(_0x5711d2,null))[_0xf332('0x25')](removeEntity(_0x5711d2,null))[_0xf332('0x46')](handleError(_0x5711d2,null));};exports[_0xf332('0x54')]=function(_0x5099da,_0x15964d,_0x3ccf81){var _0x29843e=require(_0xf332('0x55'));return db[_0xf332('0x2e')][_0xf332('0x4c')]({'where':{'id':_0x5099da[_0xf332('0x48')]['id']},'raw':!![]})[_0xf332('0x25')](handleEntityNotFound(_0x15964d,null))[_0xf332('0x25')](function(){_0x29843e[_0xf332('0x54')](_0x5099da['params']['id']);})[_0xf332('0x25')](respondWithStatusCode(_0x15964d,null))[_0xf332('0x46')](handleError(_0x15964d,null));};