94ce4d0b455646d87b7616d81a3bc2582801a167
[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 _0x01cd=['count','offset','set','Content-Range','reject','save','update','destroy','then','get','Scheduler','UserProfileResource','error','stack','name','send','index','map','Schedule','fieldName','type','key','model','keys','query','filters','attributes','intersection','fields','hasOwnProperty','nolimit','order','where','pick','filter','merge','VIRTUAL','include','findAll','rows','catch','params','rawAttributes','length','includeAll','options','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','run','../../config/schedule','eml-format','rimraf','zip-dir','fast-json-patch','bluebird','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','json','undefined','limit'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x01cd,0x1f0));var _0xd01c=function(_0x5bfe0c,_0x16a2e4){_0x5bfe0c=_0x5bfe0c-0x0;var _0x2e3c3b=_0x01cd[_0x5bfe0c];return _0x2e3c3b;};'use strict';var emlformat=require(_0xd01c('0x0'));var rimraf=require(_0xd01c('0x1'));var zipdir=require(_0xd01c('0x2'));var jsonpatch=require(_0xd01c('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xd01c('0x4'));var Mustache=require('mustache');var util=require(_0xd01c('0x5'));var path=require(_0xd01c('0x6'));var sox=require(_0xd01c('0x7'));var csv=require(_0xd01c('0x8'));var ejs=require(_0xd01c('0x9'));var fs=require('fs');var fs_extra=require(_0xd01c('0xa'));var _=require('lodash');var squel=require(_0xd01c('0xb'));var crypto=require(_0xd01c('0xc'));var jsforce=require(_0xd01c('0xd'));var deskjs=require(_0xd01c('0xe'));var toCsv=require(_0xd01c('0x8'));var querystring=require(_0xd01c('0xf'));var Papa=require(_0xd01c('0x10'));var Redis=require(_0xd01c('0x11'));var authService=require(_0xd01c('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0xd01c('0x13'));var hardwareService=require(_0xd01c('0x14'));var logger=require(_0xd01c('0x15'))(_0xd01c('0x16'));var utils=require(_0xd01c('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0xd01c('0x18'));var db=require(_0xd01c('0x19'))['db'];function respondWithStatusCode(_0x3082ee,_0x5d1c88){_0x5d1c88=_0x5d1c88||0xcc;return function(_0x203b87){if(_0x203b87){return _0x3082ee[_0xd01c('0x1a')](_0x5d1c88);}return _0x3082ee[_0xd01c('0x1b')](_0x5d1c88)[_0xd01c('0x1c')]();};}function respondWithResult(_0x40aed8,_0x12e1f8){_0x12e1f8=_0x12e1f8||0xc8;return function(_0xc4db4){if(_0xc4db4){return _0x40aed8[_0xd01c('0x1b')](_0x12e1f8)[_0xd01c('0x1d')](_0xc4db4);}};}function respondWithFilteredResult(_0x386607,_0x5491b0){return function(_0x3db5fc){if(_0x3db5fc){var _0xb8d791=typeof _0x5491b0['offset']===_0xd01c('0x1e')&&typeof _0x5491b0[_0xd01c('0x1f')]==='undefined';var _0x1dd74b=_0x3db5fc[_0xd01c('0x20')];var _0x5956eb=_0xb8d791?0x0:_0x5491b0['offset'];var _0x31d636=_0xb8d791?_0x3db5fc[_0xd01c('0x20')]:_0x5491b0[_0xd01c('0x21')]+_0x5491b0[_0xd01c('0x1f')];var _0x58205b;if(_0x31d636>=_0x1dd74b){_0x31d636=_0x1dd74b;_0x58205b=0xc8;}else{_0x58205b=0xce;}_0x386607['status'](_0x58205b);return _0x386607[_0xd01c('0x22')](_0xd01c('0x23'),_0x5956eb+'-'+_0x31d636+'/'+_0x1dd74b)[_0xd01c('0x1d')](_0x3db5fc);}return null;};}function patchUpdates(_0x4b7d63){return function(_0x3ed36d){try{jsonpatch['apply'](_0x3ed36d,_0x4b7d63,!![]);}catch(_0x8b5f43){return BPromise[_0xd01c('0x24')](_0x8b5f43);}return _0x3ed36d[_0xd01c('0x25')]();};}function saveUpdates(_0x45779b,_0x5771e0){return function(_0x3d7c56){if(_0x3d7c56){return _0x3d7c56[_0xd01c('0x26')](_0x45779b)['then'](function(_0x35c0e0){return _0x35c0e0;});}return null;};}function removeEntity(_0x162e6f,_0x35c319){return function(_0x2d44e7){if(_0x2d44e7){return _0x2d44e7[_0xd01c('0x27')]()[_0xd01c('0x28')](function(){var _0x466865=_0x2d44e7[_0xd01c('0x29')]({'plain':!![]});var _0x2e8416=_0xd01c('0x2a');return db[_0xd01c('0x2b')][_0xd01c('0x27')]({'where':{'type':_0x2e8416,'resourceId':_0x466865['id']}})[_0xd01c('0x28')](function(){return _0x2d44e7;});})[_0xd01c('0x28')](function(){_0x162e6f[_0xd01c('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x5942a,_0x34ed74){return function(_0xb1188e){if(!_0xb1188e){_0x5942a['sendStatus'](0x194);}return _0xb1188e;};}function handleError(_0x5e39b5,_0x5f0f43){_0x5f0f43=_0x5f0f43||0x1f4;return function(_0x493b8d){logger[_0xd01c('0x2c')](_0x493b8d[_0xd01c('0x2d')]);if(_0x493b8d[_0xd01c('0x2e')]){delete _0x493b8d[_0xd01c('0x2e')];}_0x5e39b5[_0xd01c('0x1b')](_0x5f0f43)[_0xd01c('0x2f')](_0x493b8d);};}exports[_0xd01c('0x30')]=function(_0x56f449,_0x2b0e28){var _0x3e1989={},_0x1d55ea={},_0x14a92e={'count':0x0,'rows':[]};var _0x139a26=_[_0xd01c('0x31')](db[_0xd01c('0x32')]['rawAttributes'],function(_0xcd07db){return{'name':_0xcd07db[_0xd01c('0x33')],'type':_0xcd07db[_0xd01c('0x34')][_0xd01c('0x35')]};});_0x1d55ea[_0xd01c('0x36')]=_['map'](_0x139a26,_0xd01c('0x2e'));_0x1d55ea['query']=_[_0xd01c('0x37')](_0x56f449[_0xd01c('0x38')]);_0x1d55ea[_0xd01c('0x39')]=_['intersection'](_0x1d55ea[_0xd01c('0x36')],_0x1d55ea[_0xd01c('0x38')]);_0x3e1989[_0xd01c('0x3a')]=_[_0xd01c('0x3b')](_0x1d55ea[_0xd01c('0x36')],qs[_0xd01c('0x3c')](_0x56f449['query'][_0xd01c('0x3c')]));_0x3e1989['attributes']=_0x3e1989[_0xd01c('0x3a')]['length']?_0x3e1989[_0xd01c('0x3a')]:_0x1d55ea[_0xd01c('0x36')];if(!_0x56f449[_0xd01c('0x38')][_0xd01c('0x3d')](_0xd01c('0x3e'))){_0x3e1989['limit']=qs[_0xd01c('0x1f')](_0x56f449[_0xd01c('0x38')][_0xd01c('0x1f')]);_0x3e1989[_0xd01c('0x21')]=qs[_0xd01c('0x21')](_0x56f449[_0xd01c('0x38')][_0xd01c('0x21')]);}_0x3e1989[_0xd01c('0x3f')]=qs['sort'](_0x56f449[_0xd01c('0x38')]['sort']);_0x3e1989[_0xd01c('0x40')]=qs[_0xd01c('0x39')](_[_0xd01c('0x41')](_0x56f449[_0xd01c('0x38')],_0x1d55ea['filters']),_0x139a26);if(_0x56f449[_0xd01c('0x38')][_0xd01c('0x42')]){_0x3e1989[_0xd01c('0x40')]=_[_0xd01c('0x43')](_0x3e1989[_0xd01c('0x40')],{'$or':_[_0xd01c('0x31')](_0x139a26,function(_0x388183){if(_0x388183[_0xd01c('0x34')]!==_0xd01c('0x44')){var _0x509b69={};_0x509b69[_0x388183[_0xd01c('0x2e')]]={'$like':'%'+_0x56f449[_0xd01c('0x38')]['filter']+'%'};return _0x509b69;}})});}_0x3e1989=_[_0xd01c('0x43')]({},_0x3e1989,_0x56f449['options']);var _0x368dd0={'where':_0x3e1989[_0xd01c('0x40')]};return db[_0xd01c('0x32')][_0xd01c('0x20')](_0x368dd0)[_0xd01c('0x28')](function(_0x4b4c19){_0x14a92e[_0xd01c('0x20')]=_0x4b4c19;if(_0x56f449['query']['includeAll']){_0x3e1989[_0xd01c('0x45')]=[{'all':!![]}];}return db['Schedule'][_0xd01c('0x46')](_0x3e1989);})['then'](function(_0x305250){_0x14a92e[_0xd01c('0x47')]=_0x305250;return _0x14a92e;})[_0xd01c('0x28')](respondWithFilteredResult(_0x2b0e28,_0x3e1989))[_0xd01c('0x48')](handleError(_0x2b0e28,null));};exports['show']=function(_0x51063f,_0x18ade5){var _0xdcf7f5={'raw':![],'where':{'id':_0x51063f[_0xd01c('0x49')]['id']}},_0x2dbf06={};_0x2dbf06[_0xd01c('0x36')]=_['keys'](db['Schedule'][_0xd01c('0x4a')]);_0x2dbf06['query']=_['keys'](_0x51063f[_0xd01c('0x38')]);_0x2dbf06[_0xd01c('0x39')]=_[_0xd01c('0x3b')](_0x2dbf06[_0xd01c('0x36')],_0x2dbf06['query']);_0xdcf7f5[_0xd01c('0x3a')]=_['intersection'](_0x2dbf06['model'],qs['fields'](_0x51063f[_0xd01c('0x38')][_0xd01c('0x3c')]));_0xdcf7f5['attributes']=_0xdcf7f5[_0xd01c('0x3a')][_0xd01c('0x4b')]?_0xdcf7f5[_0xd01c('0x3a')]:_0x2dbf06['model'];if(_0x51063f['query'][_0xd01c('0x4c')]){_0xdcf7f5[_0xd01c('0x45')]=[{'all':!![]}];}_0xdcf7f5=_['merge']({},_0xdcf7f5,_0x51063f[_0xd01c('0x4d')]);return db[_0xd01c('0x32')][_0xd01c('0x4e')](_0xdcf7f5)[_0xd01c('0x28')](handleEntityNotFound(_0x18ade5,null))[_0xd01c('0x28')](respondWithResult(_0x18ade5,null))[_0xd01c('0x48')](handleError(_0x18ade5,null));};exports[_0xd01c('0x4f')]=function(_0x4580c1,_0x1e217c){return db[_0xd01c('0x32')][_0xd01c('0x4f')](_0x4580c1['body'],{})[_0xd01c('0x28')](function(_0x4455e2){var _0x2b8241=_0x4580c1[_0xd01c('0x50')][_0xd01c('0x29')]({'plain':!![]});if(!_0x2b8241)throw new Error(_0xd01c('0x51'));if(_0x2b8241[_0xd01c('0x52')]==='user'){var _0x165b09=_0x4455e2['get']({'plain':!![]});var _0x470fd7=_0xd01c('0x2a');return db[_0xd01c('0x53')][_0xd01c('0x4e')]({'where':{'name':_0x470fd7,'userProfileId':_0x2b8241['userProfileId']},'raw':!![]})[_0xd01c('0x28')](function(_0x42e156){if(_0x42e156&&_0x42e156['autoAssociation']===0x0){return db[_0xd01c('0x2b')][_0xd01c('0x4f')]({'name':_0x165b09[_0xd01c('0x2e')],'resourceId':_0x165b09['id'],'type':_0x42e156[_0xd01c('0x2e')],'sectionId':_0x42e156['id']},{})[_0xd01c('0x28')](function(){return _0x4455e2;});}else{return _0x4455e2;}})[_0xd01c('0x48')](function(_0x5aee2f){logger[_0xd01c('0x2c')](_0xd01c('0x54'),_0x5aee2f);throw _0x5aee2f;});}return _0x4455e2;})[_0xd01c('0x28')](respondWithResult(_0x1e217c,0xc9))['catch'](handleError(_0x1e217c,null));};exports[_0xd01c('0x26')]=function(_0x2bef42,_0x5a493b){if(_0x2bef42[_0xd01c('0x55')]['id']){delete _0x2bef42[_0xd01c('0x55')]['id'];}return db[_0xd01c('0x32')][_0xd01c('0x4e')]({'where':{'id':_0x2bef42[_0xd01c('0x49')]['id']}})[_0xd01c('0x28')](handleEntityNotFound(_0x5a493b,null))[_0xd01c('0x28')](saveUpdates(_0x2bef42['body'],null))[_0xd01c('0x28')](respondWithResult(_0x5a493b,null))[_0xd01c('0x48')](handleError(_0x5a493b,null));};exports[_0xd01c('0x27')]=function(_0x204a49,_0x5044a8){return db['Schedule']['find']({'where':{'id':_0x204a49['params']['id']}})[_0xd01c('0x28')](handleEntityNotFound(_0x5044a8,null))['then'](removeEntity(_0x5044a8,null))[_0xd01c('0x48')](handleError(_0x5044a8,null));};exports[_0xd01c('0x56')]=function(_0x39606a,_0x1a0cd3,_0x3064e5){var _0x109486=require(_0xd01c('0x57'));return db[_0xd01c('0x32')][_0xd01c('0x4e')]({'where':{'id':_0x39606a[_0xd01c('0x49')]['id']},'raw':!![]})[_0xd01c('0x28')](handleEntityNotFound(_0x1a0cd3,null))['then'](function(){_0x109486['run'](_0x39606a[_0xd01c('0x49')]['id']);})[_0xd01c('0x28')](respondWithStatusCode(_0x1a0cd3,null))[_0xd01c('0x48')](handleError(_0x1a0cd3,null));};