Built motion from commit (unavailable).|2.3.8
[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 _0x0a74=['util','sox','ejs','lodash','squel','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../config/license/hardware','../../components/parsers/qs','api','../../config/utils','../../config/environment','../../mysqldb','status','end','offset','limit','set','Content-Range','apply','reject','update','then','destroy','get','UserProfileResource','sendStatus','stack','name','send','index','Schedule','rawAttributes','keys','query','filters','intersection','model','attributes','fields','length','nolimit','order','where','pick','filter','merge','map','type','key','VIRTUAL','field','options','count','includeAll','include','rows','catch','params','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','userProfileId','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','run','../../config/schedule','eml-format','rimraf','request-promise','moment','bluebird'];(function(_0x47d10a,_0x2e7ff0){var _0x1561fb=function(_0x3bf450){while(--_0x3bf450){_0x47d10a['push'](_0x47d10a['shift']());}};_0x1561fb(++_0x2e7ff0);}(_0x0a74,0x99));var _0x40a7=function(_0x99e075,_0x211213){_0x99e075=_0x99e075-0x0;var _0x1a81ba=_0x0a74[_0x99e075];return _0x1a81ba;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x40a7('0x0'));var rimraf=require(_0x40a7('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x40a7('0x2'));var moment=require(_0x40a7('0x3'));var BPromise=require(_0x40a7('0x4'));var Mustache=require('mustache');var util=require(_0x40a7('0x5'));var path=require('path');var sox=require(_0x40a7('0x6'));var csv=require('to-csv');var ejs=require(_0x40a7('0x7'));var fs=require('fs');var _=require(_0x40a7('0x8'));var squel=require(_0x40a7('0x9'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x40a7('0xa'));var toCsv=require(_0x40a7('0xb'));var querystring=require(_0x40a7('0xc'));var Papa=require(_0x40a7('0xd'));var authService=require(_0x40a7('0xe'));var hardwareService=require(_0x40a7('0xf'));var Redis=require('ioredis');var qs=require(_0x40a7('0x10'));var logger=require('../../config/logger')(_0x40a7('0x11'));var utils=require(_0x40a7('0x12'));var config=require(_0x40a7('0x13'));var db=require(_0x40a7('0x14'))['db'];function respondWithStatusCode(_0x5a4055,_0x2b5bb4){_0x2b5bb4=_0x2b5bb4||0xcc;return function(_0x2bdff3){if(_0x2bdff3){return _0x5a4055['sendStatus'](_0x2b5bb4);}return _0x5a4055[_0x40a7('0x15')](_0x2b5bb4)[_0x40a7('0x16')]();};}function respondWithResult(_0x1c434a,_0x5f48d7){_0x5f48d7=_0x5f48d7||0xc8;return function(_0x40a85d){if(_0x40a85d){return _0x1c434a[_0x40a7('0x15')](_0x5f48d7)['json'](_0x40a85d);}};}function respondWithFilteredResult(_0x13bc1d,_0x5d2700){return function(_0x5be65f){if(_0x5be65f){var _0x37c496=_0x5be65f['count'],_0x4799e6=_0x5d2700[_0x40a7('0x17')],_0x3a2fe9=_0x5d2700['offset']+_0x5d2700[_0x40a7('0x18')],_0x2dd0ec;if(_0x3a2fe9>=_0x37c496){_0x3a2fe9=_0x37c496;_0x2dd0ec=0xc8;}else{_0x2dd0ec=0xce;}_0x13bc1d['status'](_0x2dd0ec);return _0x13bc1d[_0x40a7('0x19')](_0x40a7('0x1a'),_0x4799e6+'-'+_0x3a2fe9+'/'+_0x37c496)['json'](_0x5be65f);}return null;};}function patchUpdates(_0x576303){return function(_0x1361bd){try{jsonpatch[_0x40a7('0x1b')](_0x1361bd,_0x576303,!![]);}catch(_0x5c548c){return BPromise[_0x40a7('0x1c')](_0x5c548c);}return _0x1361bd['save']();};}function saveUpdates(_0x4cdb2d,_0x79d048){return function(_0x57d716){if(_0x57d716){return _0x57d716[_0x40a7('0x1d')](_0x4cdb2d)[_0x40a7('0x1e')](function(_0x4cf0dd){return _0x4cf0dd;});}return null;};}function removeEntity(_0x4b6d65,_0x24ba0f){return function(_0x4f1dfe){if(_0x4f1dfe){return _0x4f1dfe[_0x40a7('0x1f')]()['then'](function(){var _0x163cdb=_0x4f1dfe[_0x40a7('0x20')]({'plain':!![]});var _0x2c3dd4='Scheduler';return db[_0x40a7('0x21')][_0x40a7('0x1f')]({'where':{'type':_0x2c3dd4,'resourceId':_0x163cdb['id']}})['then'](function(){return _0x4f1dfe;});})[_0x40a7('0x1e')](function(){_0x4b6d65['status'](0xcc)[_0x40a7('0x16')]();});}};}function handleEntityNotFound(_0x2d9dfc,_0x42d20e){return function(_0x2a6fdb){if(!_0x2a6fdb){_0x2d9dfc[_0x40a7('0x22')](0x194);}return _0x2a6fdb;};}function handleError(_0x73643f,_0x1dd451){_0x1dd451=_0x1dd451||0x1f4;return function(_0x4f7219){logger['error'](_0x4f7219[_0x40a7('0x23')]);if(_0x4f7219[_0x40a7('0x24')]){delete _0x4f7219[_0x40a7('0x24')];}_0x73643f[_0x40a7('0x15')](_0x1dd451)[_0x40a7('0x25')](_0x4f7219);};}exports[_0x40a7('0x26')]=function(_0x302a9b,_0x42e427){var _0x3d3657={},_0x511a16={},_0x5875d9={'count':0x0,'rows':[]};var _0x455f86=db[_0x40a7('0x27')][_0x40a7('0x28')];_0x511a16['model']=_[_0x40a7('0x29')](_0x455f86);_0x511a16[_0x40a7('0x2a')]=_['keys'](_0x302a9b[_0x40a7('0x2a')]);_0x511a16[_0x40a7('0x2b')]=_[_0x40a7('0x2c')](_0x511a16[_0x40a7('0x2d')],_0x511a16['query']);_0x3d3657[_0x40a7('0x2e')]=_['intersection'](_0x511a16[_0x40a7('0x2d')],qs[_0x40a7('0x2f')](_0x302a9b[_0x40a7('0x2a')][_0x40a7('0x2f')]));_0x3d3657[_0x40a7('0x2e')]=_0x3d3657[_0x40a7('0x2e')][_0x40a7('0x30')]?_0x3d3657[_0x40a7('0x2e')]:_0x511a16['model'];if(!_0x302a9b[_0x40a7('0x2a')]['hasOwnProperty'](_0x40a7('0x31'))){_0x3d3657[_0x40a7('0x18')]=qs['limit'](_0x302a9b[_0x40a7('0x2a')]['limit']);_0x3d3657[_0x40a7('0x17')]=qs[_0x40a7('0x17')](_0x302a9b[_0x40a7('0x2a')][_0x40a7('0x17')]);}_0x3d3657[_0x40a7('0x32')]=qs['sort'](_0x302a9b[_0x40a7('0x2a')]['sort']);_0x3d3657[_0x40a7('0x33')]=qs[_0x40a7('0x2b')](_[_0x40a7('0x34')](_0x302a9b['query'],_0x511a16[_0x40a7('0x2b')]));if(_0x302a9b['query'][_0x40a7('0x35')]){_0x3d3657[_0x40a7('0x33')]=_[_0x40a7('0x36')](_0x3d3657[_0x40a7('0x33')],{'$or':_[_0x40a7('0x37')](_0x455f86,function(_0x4d099d){if(_0x4d099d[_0x40a7('0x38')][_0x40a7('0x39')]!==_0x40a7('0x3a')){var _0x3bf87b={};_0x3bf87b[_0x4d099d[_0x40a7('0x3b')]]={'$like':'%'+_0x302a9b['query']['filter']+'%'};return _0x3bf87b;}})});}_0x3d3657=_[_0x40a7('0x36')]({},_0x3d3657,_0x302a9b[_0x40a7('0x3c')]);var _0x5b0b24={'where':_0x3d3657[_0x40a7('0x33')]};return db[_0x40a7('0x27')]['count'](_0x5b0b24)['then'](function(_0x18ac38){_0x5875d9[_0x40a7('0x3d')]=_0x18ac38;if(_0x302a9b[_0x40a7('0x2a')][_0x40a7('0x3e')]){_0x3d3657[_0x40a7('0x3f')]=[{'all':!![]}];}return db[_0x40a7('0x27')]['findAll'](_0x3d3657);})[_0x40a7('0x1e')](function(_0x3867ea){_0x5875d9[_0x40a7('0x40')]=_0x3867ea;return _0x5875d9;})[_0x40a7('0x1e')](respondWithFilteredResult(_0x42e427,_0x3d3657))[_0x40a7('0x41')](handleError(_0x42e427,null));};exports['show']=function(_0xbf15c6,_0x388f16){var _0x5b795c={'raw':![],'where':{'id':_0xbf15c6[_0x40a7('0x42')]['id']}},_0x5ee941={};_0x5ee941['model']=_[_0x40a7('0x29')](db['Schedule'][_0x40a7('0x28')]);_0x5ee941[_0x40a7('0x2a')]=_[_0x40a7('0x29')](_0xbf15c6[_0x40a7('0x2a')]);_0x5ee941[_0x40a7('0x2b')]=_[_0x40a7('0x2c')](_0x5ee941[_0x40a7('0x2d')],_0x5ee941[_0x40a7('0x2a')]);_0x5b795c[_0x40a7('0x2e')]=_[_0x40a7('0x2c')](_0x5ee941['model'],qs[_0x40a7('0x2f')](_0xbf15c6[_0x40a7('0x2a')]['fields']));_0x5b795c['attributes']=_0x5b795c['attributes'][_0x40a7('0x30')]?_0x5b795c[_0x40a7('0x2e')]:_0x5ee941[_0x40a7('0x2d')];if(_0xbf15c6[_0x40a7('0x2a')][_0x40a7('0x3e')]){_0x5b795c[_0x40a7('0x3f')]=[{'all':!![]}];}_0x5b795c=_[_0x40a7('0x36')]({},_0x5b795c,_0xbf15c6['options']);return db[_0x40a7('0x27')][_0x40a7('0x43')](_0x5b795c)[_0x40a7('0x1e')](handleEntityNotFound(_0x388f16,null))['then'](respondWithResult(_0x388f16,null))['catch'](handleError(_0x388f16,null));};exports['create']=function(_0x2e6f5f,_0x459bad){return db[_0x40a7('0x27')][_0x40a7('0x44')](_0x2e6f5f[_0x40a7('0x45')],{})[_0x40a7('0x1e')](function(_0x2025a0){var _0x3b638f=_0x2e6f5f['user'][_0x40a7('0x20')]({'plain':!![]});if(!_0x3b638f)throw new Error(_0x40a7('0x46'));if(_0x3b638f[_0x40a7('0x47')]===_0x40a7('0x48')){var _0x59cc2f=_0x2025a0[_0x40a7('0x20')]({'plain':!![]});var _0x463f4d='Scheduler';return db[_0x40a7('0x49')][_0x40a7('0x43')]({'where':{'name':_0x463f4d,'userProfileId':_0x3b638f[_0x40a7('0x4a')]},'raw':!![]})['then'](function(_0x5c7e1c){if(_0x5c7e1c&&_0x5c7e1c['autoAssociation']===0x0){return db[_0x40a7('0x21')][_0x40a7('0x44')]({'name':_0x59cc2f[_0x40a7('0x24')],'resourceId':_0x59cc2f['id'],'type':_0x5c7e1c[_0x40a7('0x24')],'sectionId':_0x5c7e1c['id']},{})[_0x40a7('0x1e')](function(){return _0x2025a0;});}else{return _0x2025a0;}})[_0x40a7('0x41')](function(_0x431550){logger[_0x40a7('0x4b')](_0x40a7('0x4c'),_0x431550);throw _0x431550;});}return _0x2025a0;})[_0x40a7('0x1e')](respondWithResult(_0x459bad,0xc9))[_0x40a7('0x41')](handleError(_0x459bad,null));};exports[_0x40a7('0x1d')]=function(_0x40d695,_0x42207d){if(_0x40d695['body']['id']){delete _0x40d695[_0x40a7('0x45')]['id'];}return db[_0x40a7('0x27')][_0x40a7('0x43')]({'where':{'id':_0x40d695[_0x40a7('0x42')]['id']}})[_0x40a7('0x1e')](handleEntityNotFound(_0x42207d,null))['then'](saveUpdates(_0x40d695[_0x40a7('0x45')],null))[_0x40a7('0x1e')](respondWithResult(_0x42207d,null))['catch'](handleError(_0x42207d,null));};exports[_0x40a7('0x1f')]=function(_0x16d173,_0x2af84a){return db['Schedule'][_0x40a7('0x43')]({'where':{'id':_0x16d173[_0x40a7('0x42')]['id']}})[_0x40a7('0x1e')](handleEntityNotFound(_0x2af84a,null))[_0x40a7('0x1e')](removeEntity(_0x2af84a,null))['catch'](handleError(_0x2af84a,null));};exports[_0x40a7('0x4d')]=function(_0x4f7451,_0x5a3945,_0x5a1200){var _0x5ae8d4=require(_0x40a7('0x4e'));return db[_0x40a7('0x27')][_0x40a7('0x43')]({'where':{'id':_0x4f7451[_0x40a7('0x42')]['id']},'raw':!![]})[_0x40a7('0x1e')](handleEntityNotFound(_0x5a3945,null))[_0x40a7('0x1e')](function(){_0x5ae8d4[_0x40a7('0x4d')](_0x4f7451['params']['id']);})[_0x40a7('0x1e')](respondWithStatusCode(_0x5a3945,null))[_0x40a7('0x41')](handleError(_0x5a3945,null));};