4263787d0d81081b43e64f8d3c9d28222936921d
[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 _0xf4f6=['user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','../../config/schedule','run','rimraf','fast-json-patch','request-promise','moment','util','path','sox','fs-extra','lodash','squel','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','api','../../config/environment','../../config/license/util','sendStatus','status','end','json','undefined','limit','count','set','Content-Range','apply','reject','update','then','destroy','get','Scheduler','UserProfileResource','error','stack','name','send','map','rawAttributes','fieldName','type','key','keys','query','intersection','model','attributes','fields','hasOwnProperty','nolimit','offset','order','sort','where','filters','pick','filter','merge','VIRTUAL','options','Schedule','include','findAll','catch','length','find','create','body'];(function(_0x23e81d,_0x1e6cf0){var _0x2d255d=function(_0x2f08dc){while(--_0x2f08dc){_0x23e81d['push'](_0x23e81d['shift']());}};_0x2d255d(++_0x1e6cf0);}(_0xf4f6,0x193));var _0x6f4f=function(_0xfae23b,_0x2be4ba){_0xfae23b=_0xfae23b-0x0;var _0x200640=_0xf4f6[_0xfae23b];return _0x200640;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x6f4f('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x6f4f('0x1'));var rp=require(_0x6f4f('0x2'));var moment=require(_0x6f4f('0x3'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x6f4f('0x4'));var path=require(_0x6f4f('0x5'));var sox=require(_0x6f4f('0x6'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x6f4f('0x7'));var _=require(_0x6f4f('0x8'));var squel=require(_0x6f4f('0x9'));var crypto=require('crypto');var jsforce=require(_0x6f4f('0xa'));var deskjs=require(_0x6f4f('0xb'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x6f4f('0xc'));var Redis=require(_0x6f4f('0xd'));var authService=require(_0x6f4f('0xe'));var qs=require('../../components/parsers/qs');var as=require(_0x6f4f('0xf'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x6f4f('0x10'));var utils=require('../../config/utils');var config=require(_0x6f4f('0x11'));var licenseUtil=require(_0x6f4f('0x12'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x23146c,_0x3305f6){_0x3305f6=_0x3305f6||0xcc;return function(_0x491b40){if(_0x491b40){return _0x23146c[_0x6f4f('0x13')](_0x3305f6);}return _0x23146c[_0x6f4f('0x14')](_0x3305f6)[_0x6f4f('0x15')]();};}function respondWithResult(_0x266600,_0x147c96){_0x147c96=_0x147c96||0xc8;return function(_0x1d97c4){if(_0x1d97c4){return _0x266600[_0x6f4f('0x14')](_0x147c96)[_0x6f4f('0x16')](_0x1d97c4);}};}function respondWithFilteredResult(_0x517435,_0x3eed2f){return function(_0x103faf){if(_0x103faf){var _0xfc00c0=typeof _0x3eed2f['offset']===_0x6f4f('0x17')&&typeof _0x3eed2f[_0x6f4f('0x18')]===_0x6f4f('0x17');var _0x56a57f=_0x103faf[_0x6f4f('0x19')];var _0x18e1dd=_0xfc00c0?0x0:_0x3eed2f['offset'];var _0x192926=_0xfc00c0?_0x103faf['count']:_0x3eed2f['offset']+_0x3eed2f[_0x6f4f('0x18')];var _0xfd4ab9;if(_0x192926>=_0x56a57f){_0x192926=_0x56a57f;_0xfd4ab9=0xc8;}else{_0xfd4ab9=0xce;}_0x517435['status'](_0xfd4ab9);return _0x517435[_0x6f4f('0x1a')](_0x6f4f('0x1b'),_0x18e1dd+'-'+_0x192926+'/'+_0x56a57f)[_0x6f4f('0x16')](_0x103faf);}return null;};}function patchUpdates(_0x3f6488){return function(_0x171634){try{jsonpatch[_0x6f4f('0x1c')](_0x171634,_0x3f6488,!![]);}catch(_0x1e4df1){return BPromise[_0x6f4f('0x1d')](_0x1e4df1);}return _0x171634['save']();};}function saveUpdates(_0x5f2958,_0x472589){return function(_0x234124){if(_0x234124){return _0x234124[_0x6f4f('0x1e')](_0x5f2958)[_0x6f4f('0x1f')](function(_0x12701e){return _0x12701e;});}return null;};}function removeEntity(_0x4fdcb0,_0x33a606){return function(_0x1cf61e){if(_0x1cf61e){return _0x1cf61e[_0x6f4f('0x20')]()[_0x6f4f('0x1f')](function(){var _0x37269b=_0x1cf61e[_0x6f4f('0x21')]({'plain':!![]});var _0x130fa4=_0x6f4f('0x22');return db[_0x6f4f('0x23')][_0x6f4f('0x20')]({'where':{'type':_0x130fa4,'resourceId':_0x37269b['id']}})[_0x6f4f('0x1f')](function(){return _0x1cf61e;});})[_0x6f4f('0x1f')](function(){_0x4fdcb0[_0x6f4f('0x14')](0xcc)[_0x6f4f('0x15')]();});}};}function handleEntityNotFound(_0x330683,_0x47ae77){return function(_0x5e4cb0){if(!_0x5e4cb0){_0x330683['sendStatus'](0x194);}return _0x5e4cb0;};}function handleError(_0x38cfd2,_0x13006e){_0x13006e=_0x13006e||0x1f4;return function(_0x2afc65){logger[_0x6f4f('0x24')](_0x2afc65[_0x6f4f('0x25')]);if(_0x2afc65[_0x6f4f('0x26')]){delete _0x2afc65[_0x6f4f('0x26')];}_0x38cfd2[_0x6f4f('0x14')](_0x13006e)[_0x6f4f('0x27')](_0x2afc65);};}exports['index']=function(_0x2871a7,_0x1698b8){var _0x52e64c={},_0x2d8047={},_0x1638a1={'count':0x0,'rows':[]};var _0x23c824=_[_0x6f4f('0x28')](db['Schedule'][_0x6f4f('0x29')],function(_0x2ca7ad){return{'name':_0x2ca7ad[_0x6f4f('0x2a')],'type':_0x2ca7ad[_0x6f4f('0x2b')][_0x6f4f('0x2c')]};});_0x2d8047['model']=_[_0x6f4f('0x28')](_0x23c824,_0x6f4f('0x26'));_0x2d8047['query']=_[_0x6f4f('0x2d')](_0x2871a7[_0x6f4f('0x2e')]);_0x2d8047['filters']=_[_0x6f4f('0x2f')](_0x2d8047[_0x6f4f('0x30')],_0x2d8047[_0x6f4f('0x2e')]);_0x52e64c[_0x6f4f('0x31')]=_[_0x6f4f('0x2f')](_0x2d8047[_0x6f4f('0x30')],qs[_0x6f4f('0x32')](_0x2871a7[_0x6f4f('0x2e')][_0x6f4f('0x32')]));_0x52e64c[_0x6f4f('0x31')]=_0x52e64c[_0x6f4f('0x31')]['length']?_0x52e64c[_0x6f4f('0x31')]:_0x2d8047[_0x6f4f('0x30')];if(!_0x2871a7['query'][_0x6f4f('0x33')](_0x6f4f('0x34'))){_0x52e64c[_0x6f4f('0x18')]=qs['limit'](_0x2871a7[_0x6f4f('0x2e')][_0x6f4f('0x18')]);_0x52e64c[_0x6f4f('0x35')]=qs[_0x6f4f('0x35')](_0x2871a7[_0x6f4f('0x2e')]['offset']);}_0x52e64c[_0x6f4f('0x36')]=qs['sort'](_0x2871a7['query'][_0x6f4f('0x37')]);_0x52e64c[_0x6f4f('0x38')]=qs[_0x6f4f('0x39')](_[_0x6f4f('0x3a')](_0x2871a7[_0x6f4f('0x2e')],_0x2d8047[_0x6f4f('0x39')]),_0x23c824);if(_0x2871a7['query'][_0x6f4f('0x3b')]){_0x52e64c['where']=_[_0x6f4f('0x3c')](_0x52e64c[_0x6f4f('0x38')],{'$or':_[_0x6f4f('0x28')](_0x23c824,function(_0x28c842){if(_0x28c842['type']!==_0x6f4f('0x3d')){var _0x2c73d1={};_0x2c73d1[_0x28c842[_0x6f4f('0x26')]]={'$like':'%'+_0x2871a7[_0x6f4f('0x2e')]['filter']+'%'};return _0x2c73d1;}})});}_0x52e64c=_[_0x6f4f('0x3c')]({},_0x52e64c,_0x2871a7[_0x6f4f('0x3e')]);var _0x476cb7={'where':_0x52e64c['where']};return db[_0x6f4f('0x3f')]['count'](_0x476cb7)['then'](function(_0x474113){_0x1638a1[_0x6f4f('0x19')]=_0x474113;if(_0x2871a7[_0x6f4f('0x2e')]['includeAll']){_0x52e64c[_0x6f4f('0x40')]=[{'all':!![]}];}return db['Schedule'][_0x6f4f('0x41')](_0x52e64c);})[_0x6f4f('0x1f')](function(_0x33c661){_0x1638a1['rows']=_0x33c661;return _0x1638a1;})[_0x6f4f('0x1f')](respondWithFilteredResult(_0x1698b8,_0x52e64c))[_0x6f4f('0x42')](handleError(_0x1698b8,null));};exports['show']=function(_0x5d1219,_0x3ca8cf){var _0x1526d7={'raw':![],'where':{'id':_0x5d1219['params']['id']}},_0x3d3cf4={};_0x3d3cf4[_0x6f4f('0x30')]=_['keys'](db[_0x6f4f('0x3f')][_0x6f4f('0x29')]);_0x3d3cf4[_0x6f4f('0x2e')]=_[_0x6f4f('0x2d')](_0x5d1219['query']);_0x3d3cf4[_0x6f4f('0x39')]=_[_0x6f4f('0x2f')](_0x3d3cf4[_0x6f4f('0x30')],_0x3d3cf4[_0x6f4f('0x2e')]);_0x1526d7[_0x6f4f('0x31')]=_['intersection'](_0x3d3cf4[_0x6f4f('0x30')],qs['fields'](_0x5d1219['query'][_0x6f4f('0x32')]));_0x1526d7['attributes']=_0x1526d7[_0x6f4f('0x31')][_0x6f4f('0x43')]?_0x1526d7[_0x6f4f('0x31')]:_0x3d3cf4[_0x6f4f('0x30')];if(_0x5d1219[_0x6f4f('0x2e')]['includeAll']){_0x1526d7[_0x6f4f('0x40')]=[{'all':!![]}];}_0x1526d7=_['merge']({},_0x1526d7,_0x5d1219['options']);return db[_0x6f4f('0x3f')][_0x6f4f('0x44')](_0x1526d7)[_0x6f4f('0x1f')](handleEntityNotFound(_0x3ca8cf,null))[_0x6f4f('0x1f')](respondWithResult(_0x3ca8cf,null))[_0x6f4f('0x42')](handleError(_0x3ca8cf,null));};exports[_0x6f4f('0x45')]=function(_0x269384,_0x316320){return db[_0x6f4f('0x3f')]['create'](_0x269384[_0x6f4f('0x46')],{})['then'](function(_0x5854a0){var _0x45f726=_0x269384[_0x6f4f('0x47')][_0x6f4f('0x21')]({'plain':!![]});if(!_0x45f726)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x45f726['role']===_0x6f4f('0x47')){var _0x4da4e8=_0x5854a0[_0x6f4f('0x21')]({'plain':!![]});var _0x1e32b5=_0x6f4f('0x22');return db[_0x6f4f('0x48')][_0x6f4f('0x44')]({'where':{'name':_0x1e32b5,'userProfileId':_0x45f726[_0x6f4f('0x49')]},'raw':!![]})['then'](function(_0x3e904d){if(_0x3e904d&&_0x3e904d[_0x6f4f('0x4a')]===0x0){return db['UserProfileResource'][_0x6f4f('0x45')]({'name':_0x4da4e8[_0x6f4f('0x26')],'resourceId':_0x4da4e8['id'],'type':_0x3e904d[_0x6f4f('0x26')],'sectionId':_0x3e904d['id']},{})[_0x6f4f('0x1f')](function(){return _0x5854a0;});}else{return _0x5854a0;}})[_0x6f4f('0x42')](function(_0x38e8c9){logger['error'](_0x6f4f('0x4b'),_0x38e8c9);throw _0x38e8c9;});}return _0x5854a0;})[_0x6f4f('0x1f')](respondWithResult(_0x316320,0xc9))['catch'](handleError(_0x316320,null));};exports[_0x6f4f('0x1e')]=function(_0x53d49f,_0x3b2c69){if(_0x53d49f['body']['id']){delete _0x53d49f['body']['id'];}return db[_0x6f4f('0x3f')][_0x6f4f('0x44')]({'where':{'id':_0x53d49f[_0x6f4f('0x4c')]['id']}})[_0x6f4f('0x1f')](handleEntityNotFound(_0x3b2c69,null))[_0x6f4f('0x1f')](saveUpdates(_0x53d49f['body'],null))[_0x6f4f('0x1f')](respondWithResult(_0x3b2c69,null))[_0x6f4f('0x42')](handleError(_0x3b2c69,null));};exports['destroy']=function(_0x3f5f5b,_0x1e6bcc){return db[_0x6f4f('0x3f')]['find']({'where':{'id':_0x3f5f5b['params']['id']}})[_0x6f4f('0x1f')](handleEntityNotFound(_0x1e6bcc,null))[_0x6f4f('0x1f')](removeEntity(_0x1e6bcc,null))[_0x6f4f('0x42')](handleError(_0x1e6bcc,null));};exports['run']=function(_0x4aecf1,_0x57cecb,_0x58be63){var _0x564627=require(_0x6f4f('0x4d'));return db[_0x6f4f('0x3f')][_0x6f4f('0x44')]({'where':{'id':_0x4aecf1[_0x6f4f('0x4c')]['id']},'raw':!![]})[_0x6f4f('0x1f')](handleEntityNotFound(_0x57cecb,null))[_0x6f4f('0x1f')](function(){_0x564627[_0x6f4f('0x4e')](_0x4aecf1[_0x6f4f('0x4c')]['id']);})['then'](respondWithStatusCode(_0x57cecb,null))[_0x6f4f('0x42')](handleError(_0x57cecb,null));};