Built motion from commit (unavailable).|2.5.10
[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 _0x68ce=['find','catch','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','run','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','count','offset','limit','set','Content-Range','apply','save','then','destroy','get','Scheduler','UserProfileResource','end','sendStatus','error','stack','name','send','index','map','Schedule','rawAttributes','type','key','keys','intersection','model','query','attributes','fields','length','hasOwnProperty','order','sort','filters','pick','filter','where','merge','VIRTUAL','options','includeAll','findAll','rows','show','params','include'];(function(_0x3c2b4a,_0x228907){var _0x44d5dc=function(_0x19a56e){while(--_0x19a56e){_0x3c2b4a['push'](_0x3c2b4a['shift']());}};_0x44d5dc(++_0x228907);}(_0x68ce,0x161));var _0xe68c=function(_0x4c0ebb,_0x1e7eae){_0x4c0ebb=_0x4c0ebb-0x0;var _0xfc4dc1=_0x68ce[_0x4c0ebb];return _0xfc4dc1;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0xe68c('0x0'));var zipdir=require(_0xe68c('0x1'));var jsonpatch=require(_0xe68c('0x2'));var rp=require(_0xe68c('0x3'));var moment=require('moment');var BPromise=require(_0xe68c('0x4'));var Mustache=require(_0xe68c('0x5'));var util=require(_0xe68c('0x6'));var path=require(_0xe68c('0x7'));var sox=require(_0xe68c('0x8'));var csv=require(_0xe68c('0x9'));var ejs=require(_0xe68c('0xa'));var fs=require('fs');var _=require(_0xe68c('0xb'));var squel=require(_0xe68c('0xc'));var crypto=require(_0xe68c('0xd'));var jsforce=require(_0xe68c('0xe'));var deskjs=require(_0xe68c('0xf'));var toCsv=require(_0xe68c('0x9'));var querystring=require('querystring');var Papa=require(_0xe68c('0x10'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0xe68c('0x11'));var hardwareService=require(_0xe68c('0x12'));var logger=require('../../config/logger')(_0xe68c('0x13'));var utils=require(_0xe68c('0x14'));var config=require(_0xe68c('0x15'));var licenseUtil=require(_0xe68c('0x16'));var db=require(_0xe68c('0x17'))['db'];function respondWithStatusCode(_0x14435d,_0x1d9a22){_0x1d9a22=_0x1d9a22||0xcc;return function(_0x2f9c37){if(_0x2f9c37){return _0x14435d['sendStatus'](_0x1d9a22);}return _0x14435d[_0xe68c('0x18')](_0x1d9a22)['end']();};}function respondWithResult(_0x3a117d,_0x50831f){_0x50831f=_0x50831f||0xc8;return function(_0xdbf5f0){if(_0xdbf5f0){return _0x3a117d[_0xe68c('0x18')](_0x50831f)['json'](_0xdbf5f0);}};}function respondWithFilteredResult(_0xdbfe18,_0x4b1bd8){return function(_0x473c97){if(_0x473c97){var _0x4af879=_0x473c97[_0xe68c('0x19')],_0x247ec9=_0x4b1bd8['offset'],_0x5e3b47=_0x4b1bd8[_0xe68c('0x1a')]+_0x4b1bd8[_0xe68c('0x1b')],_0x1e23ae;if(_0x5e3b47>=_0x4af879){_0x5e3b47=_0x4af879;_0x1e23ae=0xc8;}else{_0x1e23ae=0xce;}_0xdbfe18[_0xe68c('0x18')](_0x1e23ae);return _0xdbfe18[_0xe68c('0x1c')](_0xe68c('0x1d'),_0x247ec9+'-'+_0x5e3b47+'/'+_0x4af879)['json'](_0x473c97);}return null;};}function patchUpdates(_0x267a19){return function(_0x21cece){try{jsonpatch[_0xe68c('0x1e')](_0x21cece,_0x267a19,!![]);}catch(_0x155a25){return BPromise['reject'](_0x155a25);}return _0x21cece[_0xe68c('0x1f')]();};}function saveUpdates(_0xecfab9,_0xcf3b2b){return function(_0x3f36bc){if(_0x3f36bc){return _0x3f36bc['update'](_0xecfab9)[_0xe68c('0x20')](function(_0xbcee40){return _0xbcee40;});}return null;};}function removeEntity(_0x116e45,_0x68830e){return function(_0x5942de){if(_0x5942de){return _0x5942de[_0xe68c('0x21')]()[_0xe68c('0x20')](function(){var _0xb18477=_0x5942de[_0xe68c('0x22')]({'plain':!![]});var _0x388d82=_0xe68c('0x23');return db[_0xe68c('0x24')][_0xe68c('0x21')]({'where':{'type':_0x388d82,'resourceId':_0xb18477['id']}})['then'](function(){return _0x5942de;});})['then'](function(){_0x116e45[_0xe68c('0x18')](0xcc)[_0xe68c('0x25')]();});}};}function handleEntityNotFound(_0x356907,_0x3250df){return function(_0x4d1588){if(!_0x4d1588){_0x356907[_0xe68c('0x26')](0x194);}return _0x4d1588;};}function handleError(_0x19df93,_0x1bf1ef){_0x1bf1ef=_0x1bf1ef||0x1f4;return function(_0x470d7e){logger[_0xe68c('0x27')](_0x470d7e[_0xe68c('0x28')]);if(_0x470d7e['name']){delete _0x470d7e[_0xe68c('0x29')];}_0x19df93['status'](_0x1bf1ef)[_0xe68c('0x2a')](_0x470d7e);};}exports[_0xe68c('0x2b')]=function(_0x561bd0,_0x5ce4a0){var _0x54a9cc={},_0x287504={},_0x474c6a={'count':0x0,'rows':[]};var _0x5e4b66=_[_0xe68c('0x2c')](db[_0xe68c('0x2d')][_0xe68c('0x2e')],function(_0x59b50d){return{'name':_0x59b50d['fieldName'],'type':_0x59b50d[_0xe68c('0x2f')][_0xe68c('0x30')]};});_0x287504['model']=_[_0xe68c('0x2c')](_0x5e4b66,_0xe68c('0x29'));_0x287504['query']=_[_0xe68c('0x31')](_0x561bd0['query']);_0x287504['filters']=_[_0xe68c('0x32')](_0x287504[_0xe68c('0x33')],_0x287504[_0xe68c('0x34')]);_0x54a9cc[_0xe68c('0x35')]=_[_0xe68c('0x32')](_0x287504[_0xe68c('0x33')],qs[_0xe68c('0x36')](_0x561bd0[_0xe68c('0x34')][_0xe68c('0x36')]));_0x54a9cc[_0xe68c('0x35')]=_0x54a9cc[_0xe68c('0x35')][_0xe68c('0x37')]?_0x54a9cc[_0xe68c('0x35')]:_0x287504[_0xe68c('0x33')];if(!_0x561bd0[_0xe68c('0x34')][_0xe68c('0x38')]('nolimit')){_0x54a9cc['limit']=qs[_0xe68c('0x1b')](_0x561bd0[_0xe68c('0x34')][_0xe68c('0x1b')]);_0x54a9cc[_0xe68c('0x1a')]=qs[_0xe68c('0x1a')](_0x561bd0[_0xe68c('0x34')][_0xe68c('0x1a')]);}_0x54a9cc[_0xe68c('0x39')]=qs[_0xe68c('0x3a')](_0x561bd0[_0xe68c('0x34')]['sort']);_0x54a9cc['where']=qs[_0xe68c('0x3b')](_[_0xe68c('0x3c')](_0x561bd0[_0xe68c('0x34')],_0x287504[_0xe68c('0x3b')]),_0x5e4b66);if(_0x561bd0[_0xe68c('0x34')][_0xe68c('0x3d')]){_0x54a9cc[_0xe68c('0x3e')]=_[_0xe68c('0x3f')](_0x54a9cc[_0xe68c('0x3e')],{'$or':_[_0xe68c('0x2c')](_0x5e4b66,function(_0xafd528){if(_0xafd528['type']!==_0xe68c('0x40')){var _0x2dc400={};_0x2dc400[_0xafd528['name']]={'$like':'%'+_0x561bd0[_0xe68c('0x34')][_0xe68c('0x3d')]+'%'};return _0x2dc400;}})});}_0x54a9cc=_[_0xe68c('0x3f')]({},_0x54a9cc,_0x561bd0[_0xe68c('0x41')]);var _0x358779={'where':_0x54a9cc[_0xe68c('0x3e')]};return db[_0xe68c('0x2d')][_0xe68c('0x19')](_0x358779)[_0xe68c('0x20')](function(_0x3396a4){_0x474c6a['count']=_0x3396a4;if(_0x561bd0['query'][_0xe68c('0x42')]){_0x54a9cc['include']=[{'all':!![]}];}return db[_0xe68c('0x2d')][_0xe68c('0x43')](_0x54a9cc);})[_0xe68c('0x20')](function(_0x44fa7e){_0x474c6a[_0xe68c('0x44')]=_0x44fa7e;return _0x474c6a;})[_0xe68c('0x20')](respondWithFilteredResult(_0x5ce4a0,_0x54a9cc))['catch'](handleError(_0x5ce4a0,null));};exports[_0xe68c('0x45')]=function(_0x710687,_0x3e0c54){var _0x24fbe9={'raw':![],'where':{'id':_0x710687[_0xe68c('0x46')]['id']}},_0x2f260c={};_0x2f260c[_0xe68c('0x33')]=_[_0xe68c('0x31')](db[_0xe68c('0x2d')][_0xe68c('0x2e')]);_0x2f260c[_0xe68c('0x34')]=_[_0xe68c('0x31')](_0x710687[_0xe68c('0x34')]);_0x2f260c[_0xe68c('0x3b')]=_[_0xe68c('0x32')](_0x2f260c['model'],_0x2f260c[_0xe68c('0x34')]);_0x24fbe9[_0xe68c('0x35')]=_[_0xe68c('0x32')](_0x2f260c[_0xe68c('0x33')],qs[_0xe68c('0x36')](_0x710687[_0xe68c('0x34')][_0xe68c('0x36')]));_0x24fbe9[_0xe68c('0x35')]=_0x24fbe9['attributes']['length']?_0x24fbe9[_0xe68c('0x35')]:_0x2f260c[_0xe68c('0x33')];if(_0x710687[_0xe68c('0x34')]['includeAll']){_0x24fbe9[_0xe68c('0x47')]=[{'all':!![]}];}_0x24fbe9=_[_0xe68c('0x3f')]({},_0x24fbe9,_0x710687[_0xe68c('0x41')]);return db[_0xe68c('0x2d')][_0xe68c('0x48')](_0x24fbe9)[_0xe68c('0x20')](handleEntityNotFound(_0x3e0c54,null))[_0xe68c('0x20')](respondWithResult(_0x3e0c54,null))[_0xe68c('0x49')](handleError(_0x3e0c54,null));};exports[_0xe68c('0x4a')]=function(_0x577acb,_0x193af6){return db[_0xe68c('0x2d')]['create'](_0x577acb[_0xe68c('0x4b')],{})[_0xe68c('0x20')](function(_0x3aef61){var _0x27b1c2=_0x577acb[_0xe68c('0x4c')][_0xe68c('0x22')]({'plain':!![]});if(!_0x27b1c2)throw new Error(_0xe68c('0x4d'));if(_0x27b1c2[_0xe68c('0x4e')]===_0xe68c('0x4c')){var _0x9be9ce=_0x3aef61[_0xe68c('0x22')]({'plain':!![]});var _0x5bd906='Scheduler';return db[_0xe68c('0x4f')][_0xe68c('0x48')]({'where':{'name':_0x5bd906,'userProfileId':_0x27b1c2[_0xe68c('0x50')]},'raw':!![]})[_0xe68c('0x20')](function(_0x332180){if(_0x332180&&_0x332180[_0xe68c('0x51')]===0x0){return db[_0xe68c('0x24')]['create']({'name':_0x9be9ce[_0xe68c('0x29')],'resourceId':_0x9be9ce['id'],'type':_0x332180[_0xe68c('0x29')],'sectionId':_0x332180['id']},{})['then'](function(){return _0x3aef61;});}else{return _0x3aef61;}})[_0xe68c('0x49')](function(_0x361696){logger[_0xe68c('0x27')](_0xe68c('0x52'),_0x361696);throw _0x361696;});}return _0x3aef61;})[_0xe68c('0x20')](respondWithResult(_0x193af6,0xc9))[_0xe68c('0x49')](handleError(_0x193af6,null));};exports[_0xe68c('0x53')]=function(_0x264c51,_0x25ff9a){if(_0x264c51[_0xe68c('0x4b')]['id']){delete _0x264c51[_0xe68c('0x4b')]['id'];}return db['Schedule'][_0xe68c('0x48')]({'where':{'id':_0x264c51[_0xe68c('0x46')]['id']}})['then'](handleEntityNotFound(_0x25ff9a,null))[_0xe68c('0x20')](saveUpdates(_0x264c51[_0xe68c('0x4b')],null))['then'](respondWithResult(_0x25ff9a,null))[_0xe68c('0x49')](handleError(_0x25ff9a,null));};exports[_0xe68c('0x21')]=function(_0x3503fa,_0x15039d){return db['Schedule'][_0xe68c('0x48')]({'where':{'id':_0x3503fa[_0xe68c('0x46')]['id']}})['then'](handleEntityNotFound(_0x15039d,null))[_0xe68c('0x20')](removeEntity(_0x15039d,null))[_0xe68c('0x49')](handleError(_0x15039d,null));};exports[_0xe68c('0x54')]=function(_0x33bbde,_0x3f4842,_0x2b6bf4){var _0x11e806=require('../../config/schedule');return db[_0xe68c('0x2d')][_0xe68c('0x48')]({'where':{'id':_0x33bbde[_0xe68c('0x46')]['id']},'raw':!![]})[_0xe68c('0x20')](handleEntityNotFound(_0x3f4842,null))[_0xe68c('0x20')](function(){_0x11e806['run'](_0x33bbde[_0xe68c('0x46')]['id']);})[_0xe68c('0x20')](respondWithStatusCode(_0x3f4842,null))[_0xe68c('0x49')](handleError(_0x3f4842,null));};