ea347b6d2ddb37af96e8c52132f383cf2aa4884e
[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 _0xdb76=['../../config/environment','../../mysqldb','sendStatus','end','json','offset','limit','undefined','count','status','set','Content-Range','apply','reject','save','then','destroy','get','Scheduler','UserProfileResource','error','stack','name','index','map','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','where','pick','filter','merge','VIRTUAL','options','Schedule','includeAll','include','findAll','rows','show','catch','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','userProfileId','autoAssociation','update','find','params','run','rimraf','request-promise','moment','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0xdb76,0xe5));var _0x6db7=function(_0x364857,_0x2bef71){_0x364857=_0x364857-0x0;var _0x40ae99=_0xdb76[_0x364857];return _0x40ae99;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x6db7('0x0'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x6db7('0x1'));var moment=require(_0x6db7('0x2'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require('util');var path=require(_0x6db7('0x3'));var sox=require(_0x6db7('0x4'));var csv=require(_0x6db7('0x5'));var ejs=require(_0x6db7('0x6'));var fs=require('fs');var fs_extra=require(_0x6db7('0x7'));var _=require(_0x6db7('0x8'));var squel=require('squel');var crypto=require(_0x6db7('0x9'));var jsforce=require(_0x6db7('0xa'));var deskjs=require(_0x6db7('0xb'));var toCsv=require(_0x6db7('0x5'));var querystring=require(_0x6db7('0xc'));var Papa=require(_0x6db7('0xd'));var Redis=require(_0x6db7('0xe'));var authService=require(_0x6db7('0xf'));var qs=require(_0x6db7('0x10'));var as=require(_0x6db7('0x11'));var hardwareService=require(_0x6db7('0x12'));var logger=require('../../config/logger')(_0x6db7('0x13'));var utils=require('../../config/utils');var config=require(_0x6db7('0x14'));var licenseUtil=require('../../config/license/util');var db=require(_0x6db7('0x15'))['db'];function respondWithStatusCode(_0x1697c7,_0x267915){_0x267915=_0x267915||0xcc;return function(_0x3b0efc){if(_0x3b0efc){return _0x1697c7[_0x6db7('0x16')](_0x267915);}return _0x1697c7['status'](_0x267915)[_0x6db7('0x17')]();};}function respondWithResult(_0x455e20,_0x537262){_0x537262=_0x537262||0xc8;return function(_0x5dfd65){if(_0x5dfd65){return _0x455e20['status'](_0x537262)[_0x6db7('0x18')](_0x5dfd65);}};}function respondWithFilteredResult(_0x22004e,_0x1edbb2){return function(_0x1c79ac){if(_0x1c79ac){var _0x47a95f=typeof _0x1edbb2[_0x6db7('0x19')]==='undefined'&&typeof _0x1edbb2[_0x6db7('0x1a')]===_0x6db7('0x1b');var _0x54f81d=_0x1c79ac[_0x6db7('0x1c')];var _0x1bffe2=_0x47a95f?0x0:_0x1edbb2['offset'];var _0xbe0d91=_0x47a95f?_0x1c79ac[_0x6db7('0x1c')]:_0x1edbb2[_0x6db7('0x19')]+_0x1edbb2['limit'];var _0x4e3839;if(_0xbe0d91>=_0x54f81d){_0xbe0d91=_0x54f81d;_0x4e3839=0xc8;}else{_0x4e3839=0xce;}_0x22004e[_0x6db7('0x1d')](_0x4e3839);return _0x22004e[_0x6db7('0x1e')](_0x6db7('0x1f'),_0x1bffe2+'-'+_0xbe0d91+'/'+_0x54f81d)['json'](_0x1c79ac);}return null;};}function patchUpdates(_0x565b5b){return function(_0x53178e){try{jsonpatch[_0x6db7('0x20')](_0x53178e,_0x565b5b,!![]);}catch(_0x496fae){return BPromise[_0x6db7('0x21')](_0x496fae);}return _0x53178e[_0x6db7('0x22')]();};}function saveUpdates(_0x19d022,_0x50ce44){return function(_0x3f3c25){if(_0x3f3c25){return _0x3f3c25['update'](_0x19d022)[_0x6db7('0x23')](function(_0x29a227){return _0x29a227;});}return null;};}function removeEntity(_0x4988f6,_0x549725){return function(_0x2018e4){if(_0x2018e4){return _0x2018e4[_0x6db7('0x24')]()[_0x6db7('0x23')](function(){var _0x4ddeb4=_0x2018e4[_0x6db7('0x25')]({'plain':!![]});var _0x2c97e3=_0x6db7('0x26');return db[_0x6db7('0x27')][_0x6db7('0x24')]({'where':{'type':_0x2c97e3,'resourceId':_0x4ddeb4['id']}})['then'](function(){return _0x2018e4;});})[_0x6db7('0x23')](function(){_0x4988f6[_0x6db7('0x1d')](0xcc)[_0x6db7('0x17')]();});}};}function handleEntityNotFound(_0x1684bc,_0xa5ad82){return function(_0x4f48ff){if(!_0x4f48ff){_0x1684bc[_0x6db7('0x16')](0x194);}return _0x4f48ff;};}function handleError(_0x449ecc,_0x47b0f1){_0x47b0f1=_0x47b0f1||0x1f4;return function(_0x4774a8){logger[_0x6db7('0x28')](_0x4774a8[_0x6db7('0x29')]);if(_0x4774a8[_0x6db7('0x2a')]){delete _0x4774a8[_0x6db7('0x2a')];}_0x449ecc[_0x6db7('0x1d')](_0x47b0f1)['send'](_0x4774a8);};}exports[_0x6db7('0x2b')]=function(_0x5b2b7d,_0x5d34a3){var _0x1e9e5c={},_0x40f5d2={},_0x19de92={'count':0x0,'rows':[]};var _0xe6d076=_[_0x6db7('0x2c')](db['Schedule'][_0x6db7('0x2d')],function(_0x51a299){return{'name':_0x51a299[_0x6db7('0x2e')],'type':_0x51a299[_0x6db7('0x2f')][_0x6db7('0x30')]};});_0x40f5d2[_0x6db7('0x31')]=_[_0x6db7('0x2c')](_0xe6d076,_0x6db7('0x2a'));_0x40f5d2[_0x6db7('0x32')]=_[_0x6db7('0x33')](_0x5b2b7d['query']);_0x40f5d2[_0x6db7('0x34')]=_[_0x6db7('0x35')](_0x40f5d2[_0x6db7('0x31')],_0x40f5d2[_0x6db7('0x32')]);_0x1e9e5c[_0x6db7('0x36')]=_[_0x6db7('0x35')](_0x40f5d2[_0x6db7('0x31')],qs[_0x6db7('0x37')](_0x5b2b7d[_0x6db7('0x32')][_0x6db7('0x37')]));_0x1e9e5c['attributes']=_0x1e9e5c[_0x6db7('0x36')][_0x6db7('0x38')]?_0x1e9e5c[_0x6db7('0x36')]:_0x40f5d2['model'];if(!_0x5b2b7d[_0x6db7('0x32')][_0x6db7('0x39')](_0x6db7('0x3a'))){_0x1e9e5c[_0x6db7('0x1a')]=qs[_0x6db7('0x1a')](_0x5b2b7d[_0x6db7('0x32')]['limit']);_0x1e9e5c['offset']=qs[_0x6db7('0x19')](_0x5b2b7d['query'][_0x6db7('0x19')]);}_0x1e9e5c[_0x6db7('0x3b')]=qs['sort'](_0x5b2b7d[_0x6db7('0x32')]['sort']);_0x1e9e5c[_0x6db7('0x3c')]=qs['filters'](_[_0x6db7('0x3d')](_0x5b2b7d[_0x6db7('0x32')],_0x40f5d2['filters']),_0xe6d076);if(_0x5b2b7d[_0x6db7('0x32')][_0x6db7('0x3e')]){_0x1e9e5c[_0x6db7('0x3c')]=_[_0x6db7('0x3f')](_0x1e9e5c[_0x6db7('0x3c')],{'$or':_[_0x6db7('0x2c')](_0xe6d076,function(_0x42b246){if(_0x42b246[_0x6db7('0x2f')]!==_0x6db7('0x40')){var _0x549b15={};_0x549b15[_0x42b246[_0x6db7('0x2a')]]={'$like':'%'+_0x5b2b7d['query'][_0x6db7('0x3e')]+'%'};return _0x549b15;}})});}_0x1e9e5c=_[_0x6db7('0x3f')]({},_0x1e9e5c,_0x5b2b7d[_0x6db7('0x41')]);var _0x2c7f16={'where':_0x1e9e5c[_0x6db7('0x3c')]};return db[_0x6db7('0x42')]['count'](_0x2c7f16)[_0x6db7('0x23')](function(_0x465fda){_0x19de92[_0x6db7('0x1c')]=_0x465fda;if(_0x5b2b7d['query'][_0x6db7('0x43')]){_0x1e9e5c[_0x6db7('0x44')]=[{'all':!![]}];}return db[_0x6db7('0x42')][_0x6db7('0x45')](_0x1e9e5c);})[_0x6db7('0x23')](function(_0x5ebdf7){_0x19de92[_0x6db7('0x46')]=_0x5ebdf7;return _0x19de92;})[_0x6db7('0x23')](respondWithFilteredResult(_0x5d34a3,_0x1e9e5c))['catch'](handleError(_0x5d34a3,null));};exports[_0x6db7('0x47')]=function(_0x13ec2a,_0x286465){var _0x146f80={'raw':![],'where':{'id':_0x13ec2a['params']['id']}},_0x52afcd={};_0x52afcd['model']=_[_0x6db7('0x33')](db[_0x6db7('0x42')]['rawAttributes']);_0x52afcd[_0x6db7('0x32')]=_['keys'](_0x13ec2a[_0x6db7('0x32')]);_0x52afcd['filters']=_[_0x6db7('0x35')](_0x52afcd[_0x6db7('0x31')],_0x52afcd[_0x6db7('0x32')]);_0x146f80[_0x6db7('0x36')]=_[_0x6db7('0x35')](_0x52afcd[_0x6db7('0x31')],qs[_0x6db7('0x37')](_0x13ec2a[_0x6db7('0x32')][_0x6db7('0x37')]));_0x146f80[_0x6db7('0x36')]=_0x146f80[_0x6db7('0x36')][_0x6db7('0x38')]?_0x146f80[_0x6db7('0x36')]:_0x52afcd[_0x6db7('0x31')];if(_0x13ec2a['query'][_0x6db7('0x43')]){_0x146f80['include']=[{'all':!![]}];}_0x146f80=_[_0x6db7('0x3f')]({},_0x146f80,_0x13ec2a[_0x6db7('0x41')]);return db[_0x6db7('0x42')]['find'](_0x146f80)[_0x6db7('0x23')](handleEntityNotFound(_0x286465,null))[_0x6db7('0x23')](respondWithResult(_0x286465,null))[_0x6db7('0x48')](handleError(_0x286465,null));};exports[_0x6db7('0x49')]=function(_0x1b7a5c,_0x2073c2){return db[_0x6db7('0x42')][_0x6db7('0x49')](_0x1b7a5c[_0x6db7('0x4a')],{})[_0x6db7('0x23')](function(_0x2bd23b){var _0x4c4553=_0x1b7a5c[_0x6db7('0x4b')][_0x6db7('0x25')]({'plain':!![]});if(!_0x4c4553)throw new Error(_0x6db7('0x4c'));if(_0x4c4553['role']===_0x6db7('0x4b')){var _0x43af9e=_0x2bd23b['get']({'plain':!![]});var _0x5d266d=_0x6db7('0x26');return db['UserProfileSection']['find']({'where':{'name':_0x5d266d,'userProfileId':_0x4c4553[_0x6db7('0x4d')]},'raw':!![]})[_0x6db7('0x23')](function(_0x5970ff){if(_0x5970ff&&_0x5970ff[_0x6db7('0x4e')]===0x0){return db['UserProfileResource'][_0x6db7('0x49')]({'name':_0x43af9e[_0x6db7('0x2a')],'resourceId':_0x43af9e['id'],'type':_0x5970ff[_0x6db7('0x2a')],'sectionId':_0x5970ff['id']},{})[_0x6db7('0x23')](function(){return _0x2bd23b;});}else{return _0x2bd23b;}})[_0x6db7('0x48')](function(_0x2d8316){logger[_0x6db7('0x28')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x2d8316);throw _0x2d8316;});}return _0x2bd23b;})[_0x6db7('0x23')](respondWithResult(_0x2073c2,0xc9))['catch'](handleError(_0x2073c2,null));};exports[_0x6db7('0x4f')]=function(_0x346f89,_0x2833a6){if(_0x346f89[_0x6db7('0x4a')]['id']){delete _0x346f89[_0x6db7('0x4a')]['id'];}return db[_0x6db7('0x42')][_0x6db7('0x50')]({'where':{'id':_0x346f89[_0x6db7('0x51')]['id']}})[_0x6db7('0x23')](handleEntityNotFound(_0x2833a6,null))[_0x6db7('0x23')](saveUpdates(_0x346f89[_0x6db7('0x4a')],null))[_0x6db7('0x23')](respondWithResult(_0x2833a6,null))['catch'](handleError(_0x2833a6,null));};exports[_0x6db7('0x24')]=function(_0x5ce41d,_0x28602e){return db[_0x6db7('0x42')][_0x6db7('0x50')]({'where':{'id':_0x5ce41d['params']['id']}})[_0x6db7('0x23')](handleEntityNotFound(_0x28602e,null))[_0x6db7('0x23')](removeEntity(_0x28602e,null))[_0x6db7('0x48')](handleError(_0x28602e,null));};exports[_0x6db7('0x52')]=function(_0x3ed5a6,_0x47d3c2,_0x3a7c68){var _0x42713d=require('../../config/schedule');return db[_0x6db7('0x42')][_0x6db7('0x50')]({'where':{'id':_0x3ed5a6['params']['id']},'raw':!![]})[_0x6db7('0x23')](handleEntityNotFound(_0x47d3c2,null))[_0x6db7('0x23')](function(){_0x42713d[_0x6db7('0x52')](_0x3ed5a6['params']['id']);})['then'](respondWithStatusCode(_0x47d3c2,null))[_0x6db7('0x48')](handleError(_0x47d3c2,null));};