Built motion from commit (unavailable).|2.5.4
[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 _0x6fb0=['catch','show','params','keys','find','create','user','get','role','UserProfileSection','userProfileId','autoAssociation','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','run','../../config/schedule','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../mysqldb','status','end','json','offset','limit','set','Content-Range','apply','save','update','destroy','then','Scheduler','UserProfileResource','sendStatus','stack','name','send','index','map','rawAttributes','fieldName','type','key','model','query','intersection','attributes','fields','length','order','sort','filters','pick','where','VIRTUAL','filter','merge','options','Schedule','count','includeAll','include','findAll','rows'];(function(_0x425455,_0x473130){var _0x1556f0=function(_0x3a9906){while(--_0x3a9906){_0x425455['push'](_0x425455['shift']());}};_0x1556f0(++_0x473130);}(_0x6fb0,0xbd));var _0x06fb=function(_0x30e520,_0x4949f9){_0x30e520=_0x30e520-0x0;var _0x114706=_0x6fb0[_0x30e520];return _0x114706;};'use strict';var pdf=require(_0x06fb('0x0'));var emlformat=require(_0x06fb('0x1'));var rimraf=require(_0x06fb('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x06fb('0x3'));var rp=require(_0x06fb('0x4'));var moment=require(_0x06fb('0x5'));var BPromise=require(_0x06fb('0x6'));var Mustache=require('mustache');var util=require(_0x06fb('0x7'));var path=require(_0x06fb('0x8'));var sox=require(_0x06fb('0x9'));var csv=require(_0x06fb('0xa'));var ejs=require(_0x06fb('0xb'));var fs=require('fs');var _=require(_0x06fb('0xc'));var squel=require(_0x06fb('0xd'));var crypto=require(_0x06fb('0xe'));var jsforce=require(_0x06fb('0xf'));var deskjs=require(_0x06fb('0x10'));var toCsv=require(_0x06fb('0xa'));var querystring=require(_0x06fb('0x11'));var Papa=require('papaparse');var Redis=require(_0x06fb('0x12'));var authService=require(_0x06fb('0x13'));var qs=require(_0x06fb('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x06fb('0x15'))(_0x06fb('0x16'));var utils=require('../../config/utils');var config=require('../../config/environment');var db=require(_0x06fb('0x17'))['db'];function respondWithStatusCode(_0x39296f,_0x404bad){_0x404bad=_0x404bad||0xcc;return function(_0x446489){if(_0x446489){return _0x39296f['sendStatus'](_0x404bad);}return _0x39296f[_0x06fb('0x18')](_0x404bad)[_0x06fb('0x19')]();};}function respondWithResult(_0x467eea,_0xed98ea){_0xed98ea=_0xed98ea||0xc8;return function(_0x329820){if(_0x329820){return _0x467eea[_0x06fb('0x18')](_0xed98ea)[_0x06fb('0x1a')](_0x329820);}};}function respondWithFilteredResult(_0x5d1899,_0x4cec22){return function(_0x3d8bc2){if(_0x3d8bc2){var _0x17e11f=_0x3d8bc2['count'],_0x5c5261=_0x4cec22[_0x06fb('0x1b')],_0x594abd=_0x4cec22['offset']+_0x4cec22[_0x06fb('0x1c')],_0x256435;if(_0x594abd>=_0x17e11f){_0x594abd=_0x17e11f;_0x256435=0xc8;}else{_0x256435=0xce;}_0x5d1899[_0x06fb('0x18')](_0x256435);return _0x5d1899[_0x06fb('0x1d')](_0x06fb('0x1e'),_0x5c5261+'-'+_0x594abd+'/'+_0x17e11f)[_0x06fb('0x1a')](_0x3d8bc2);}return null;};}function patchUpdates(_0x4e8aaf){return function(_0x575e81){try{jsonpatch[_0x06fb('0x1f')](_0x575e81,_0x4e8aaf,!![]);}catch(_0x4bcd56){return BPromise['reject'](_0x4bcd56);}return _0x575e81[_0x06fb('0x20')]();};}function saveUpdates(_0x2e735d,_0x2fe15d){return function(_0x10dec4){if(_0x10dec4){return _0x10dec4[_0x06fb('0x21')](_0x2e735d)['then'](function(_0x419e34){return _0x419e34;});}return null;};}function removeEntity(_0x5cf14b,_0xc650db){return function(_0x5bb274){if(_0x5bb274){return _0x5bb274[_0x06fb('0x22')]()[_0x06fb('0x23')](function(){var _0x2a081c=_0x5bb274['get']({'plain':!![]});var _0xa5d2a5=_0x06fb('0x24');return db[_0x06fb('0x25')]['destroy']({'where':{'type':_0xa5d2a5,'resourceId':_0x2a081c['id']}})['then'](function(){return _0x5bb274;});})[_0x06fb('0x23')](function(){_0x5cf14b[_0x06fb('0x18')](0xcc)[_0x06fb('0x19')]();});}};}function handleEntityNotFound(_0x5a4044,_0x657c39){return function(_0x865bb4){if(!_0x865bb4){_0x5a4044[_0x06fb('0x26')](0x194);}return _0x865bb4;};}function handleError(_0x28aa80,_0x4e8935){_0x4e8935=_0x4e8935||0x1f4;return function(_0x3e71c7){logger['error'](_0x3e71c7[_0x06fb('0x27')]);if(_0x3e71c7[_0x06fb('0x28')]){delete _0x3e71c7[_0x06fb('0x28')];}_0x28aa80['status'](_0x4e8935)[_0x06fb('0x29')](_0x3e71c7);};}exports[_0x06fb('0x2a')]=function(_0x54a4dd,_0x268de6){var _0x26be53={},_0x3dca0a={},_0x26ac66={'count':0x0,'rows':[]};var _0x193d69=_[_0x06fb('0x2b')](db['Schedule'][_0x06fb('0x2c')],function(_0x252b52){return{'name':_0x252b52[_0x06fb('0x2d')],'type':_0x252b52[_0x06fb('0x2e')][_0x06fb('0x2f')]};});_0x3dca0a[_0x06fb('0x30')]=_['map'](_0x193d69,_0x06fb('0x28'));_0x3dca0a[_0x06fb('0x31')]=_['keys'](_0x54a4dd[_0x06fb('0x31')]);_0x3dca0a['filters']=_[_0x06fb('0x32')](_0x3dca0a['model'],_0x3dca0a[_0x06fb('0x31')]);_0x26be53[_0x06fb('0x33')]=_[_0x06fb('0x32')](_0x3dca0a[_0x06fb('0x30')],qs[_0x06fb('0x34')](_0x54a4dd[_0x06fb('0x31')][_0x06fb('0x34')]));_0x26be53[_0x06fb('0x33')]=_0x26be53[_0x06fb('0x33')][_0x06fb('0x35')]?_0x26be53[_0x06fb('0x33')]:_0x3dca0a[_0x06fb('0x30')];if(!_0x54a4dd[_0x06fb('0x31')]['hasOwnProperty']('nolimit')){_0x26be53['limit']=qs['limit'](_0x54a4dd[_0x06fb('0x31')][_0x06fb('0x1c')]);_0x26be53[_0x06fb('0x1b')]=qs['offset'](_0x54a4dd[_0x06fb('0x31')][_0x06fb('0x1b')]);}_0x26be53[_0x06fb('0x36')]=qs['sort'](_0x54a4dd[_0x06fb('0x31')][_0x06fb('0x37')]);_0x26be53['where']=qs[_0x06fb('0x38')](_[_0x06fb('0x39')](_0x54a4dd['query'],_0x3dca0a[_0x06fb('0x38')]),_0x193d69);if(_0x54a4dd['query']['filter']){_0x26be53[_0x06fb('0x3a')]=_['merge'](_0x26be53[_0x06fb('0x3a')],{'$or':_[_0x06fb('0x2b')](_0x193d69,function(_0x455f8d){if(_0x455f8d[_0x06fb('0x2e')]!==_0x06fb('0x3b')){var _0x1e18d7={};_0x1e18d7[_0x455f8d[_0x06fb('0x28')]]={'$like':'%'+_0x54a4dd[_0x06fb('0x31')][_0x06fb('0x3c')]+'%'};return _0x1e18d7;}})});}_0x26be53=_[_0x06fb('0x3d')]({},_0x26be53,_0x54a4dd[_0x06fb('0x3e')]);var _0x4fce5a={'where':_0x26be53[_0x06fb('0x3a')]};return db[_0x06fb('0x3f')][_0x06fb('0x40')](_0x4fce5a)[_0x06fb('0x23')](function(_0x473ee8){_0x26ac66[_0x06fb('0x40')]=_0x473ee8;if(_0x54a4dd[_0x06fb('0x31')][_0x06fb('0x41')]){_0x26be53[_0x06fb('0x42')]=[{'all':!![]}];}return db['Schedule'][_0x06fb('0x43')](_0x26be53);})[_0x06fb('0x23')](function(_0x4e0da0){_0x26ac66[_0x06fb('0x44')]=_0x4e0da0;return _0x26ac66;})['then'](respondWithFilteredResult(_0x268de6,_0x26be53))[_0x06fb('0x45')](handleError(_0x268de6,null));};exports[_0x06fb('0x46')]=function(_0x2eb072,_0x518be1){var _0x13be54={'raw':![],'where':{'id':_0x2eb072[_0x06fb('0x47')]['id']}},_0x4b4033={};_0x4b4033[_0x06fb('0x30')]=_[_0x06fb('0x48')](db[_0x06fb('0x3f')]['rawAttributes']);_0x4b4033[_0x06fb('0x31')]=_[_0x06fb('0x48')](_0x2eb072['query']);_0x4b4033[_0x06fb('0x38')]=_['intersection'](_0x4b4033[_0x06fb('0x30')],_0x4b4033[_0x06fb('0x31')]);_0x13be54[_0x06fb('0x33')]=_[_0x06fb('0x32')](_0x4b4033[_0x06fb('0x30')],qs[_0x06fb('0x34')](_0x2eb072['query'][_0x06fb('0x34')]));_0x13be54[_0x06fb('0x33')]=_0x13be54['attributes'][_0x06fb('0x35')]?_0x13be54[_0x06fb('0x33')]:_0x4b4033['model'];if(_0x2eb072[_0x06fb('0x31')][_0x06fb('0x41')]){_0x13be54[_0x06fb('0x42')]=[{'all':!![]}];}_0x13be54=_['merge']({},_0x13be54,_0x2eb072[_0x06fb('0x3e')]);return db[_0x06fb('0x3f')][_0x06fb('0x49')](_0x13be54)[_0x06fb('0x23')](handleEntityNotFound(_0x518be1,null))[_0x06fb('0x23')](respondWithResult(_0x518be1,null))[_0x06fb('0x45')](handleError(_0x518be1,null));};exports[_0x06fb('0x4a')]=function(_0x7b6dfa,_0xe0f935){return db[_0x06fb('0x3f')][_0x06fb('0x4a')](_0x7b6dfa['body'],{})['then'](function(_0x1e31e5){var _0x82718=_0x7b6dfa[_0x06fb('0x4b')][_0x06fb('0x4c')]({'plain':!![]});if(!_0x82718)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x82718[_0x06fb('0x4d')]==='user'){var _0x4e2bd9=_0x1e31e5[_0x06fb('0x4c')]({'plain':!![]});var _0x2c72f2=_0x06fb('0x24');return db[_0x06fb('0x4e')][_0x06fb('0x49')]({'where':{'name':_0x2c72f2,'userProfileId':_0x82718[_0x06fb('0x4f')]},'raw':!![]})['then'](function(_0x152f9c){if(_0x152f9c&&_0x152f9c[_0x06fb('0x50')]===0x0){return db['UserProfileResource'][_0x06fb('0x4a')]({'name':_0x4e2bd9['name'],'resourceId':_0x4e2bd9['id'],'type':_0x152f9c['name'],'sectionId':_0x152f9c['id']},{})[_0x06fb('0x23')](function(){return _0x1e31e5;});}else{return _0x1e31e5;}})[_0x06fb('0x45')](function(_0x53cc21){logger[_0x06fb('0x51')](_0x06fb('0x52'),_0x53cc21);throw _0x53cc21;});}return _0x1e31e5;})['then'](respondWithResult(_0xe0f935,0xc9))[_0x06fb('0x45')](handleError(_0xe0f935,null));};exports[_0x06fb('0x21')]=function(_0xf47864,_0x3b276f){if(_0xf47864[_0x06fb('0x53')]['id']){delete _0xf47864[_0x06fb('0x53')]['id'];}return db[_0x06fb('0x3f')][_0x06fb('0x49')]({'where':{'id':_0xf47864[_0x06fb('0x47')]['id']}})['then'](handleEntityNotFound(_0x3b276f,null))[_0x06fb('0x23')](saveUpdates(_0xf47864['body'],null))['then'](respondWithResult(_0x3b276f,null))['catch'](handleError(_0x3b276f,null));};exports[_0x06fb('0x22')]=function(_0x42e2d2,_0x566e81){return db['Schedule']['find']({'where':{'id':_0x42e2d2[_0x06fb('0x47')]['id']}})['then'](handleEntityNotFound(_0x566e81,null))[_0x06fb('0x23')](removeEntity(_0x566e81,null))[_0x06fb('0x45')](handleError(_0x566e81,null));};exports[_0x06fb('0x54')]=function(_0x5dbc46,_0x48f8a4,_0x536f33){var _0x59f2d6=require(_0x06fb('0x55'));return db['Schedule'][_0x06fb('0x49')]({'where':{'id':_0x5dbc46['params']['id']},'raw':!![]})[_0x06fb('0x23')](handleEntityNotFound(_0x48f8a4,null))['then'](function(){_0x59f2d6[_0x06fb('0x54')](_0x5dbc46[_0x06fb('0x47')]['id']);})[_0x06fb('0x23')](respondWithStatusCode(_0x48f8a4,null))['catch'](handleError(_0x48f8a4,null));};