Built motion from commit c738b9ac.|2.6.25
[motion2.git] / server / api / interval / interval.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 _0x6f73=['update','then','destroy','Intervals','UserProfileResource','error','stack','name','send','index','Interval','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','merge','map','VIRTUAL','options','includeAll','include','catch','show','params','find','body','get','role','user','UserProfileSection','userProfileId','autoAssociation','create','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','addInterval','IntervalId','getIntervals','findOne','pick','addIntervals','sequelize','transaction','bulkCreate','findAll','eml-format','zip-dir','fast-json-patch','moment','bluebird','mustache','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','../../components/extensions/rewrite','sendStatus','status','end','json','offset','limit','undefined','count','set','Content-Range','apply','reject'];(function(_0x1c4290,_0x3b65de){var _0x47bebc=function(_0xa736c4){while(--_0xa736c4){_0x1c4290['push'](_0x1c4290['shift']());}};_0x47bebc(++_0x3b65de);}(_0x6f73,0x97));var _0x36f7=function(_0x3b1f96,_0x5adc68){_0x3b1f96=_0x3b1f96-0x0;var _0x1e4ada=_0x6f73[_0x3b1f96];return _0x1e4ada;};'use strict';var emlformat=require(_0x36f7('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x36f7('0x1'));var jsonpatch=require(_0x36f7('0x2'));var rp=require('request-promise');var moment=require(_0x36f7('0x3'));var BPromise=require(_0x36f7('0x4'));var Mustache=require(_0x36f7('0x5'));var util=require('util');var path=require('path');var sox=require(_0x36f7('0x6'));var csv=require(_0x36f7('0x7'));var ejs=require(_0x36f7('0x8'));var fs=require('fs');var fs_extra=require(_0x36f7('0x9'));var _=require(_0x36f7('0xa'));var squel=require(_0x36f7('0xb'));var crypto=require(_0x36f7('0xc'));var jsforce=require(_0x36f7('0xd'));var deskjs=require(_0x36f7('0xe'));var toCsv=require('to-csv');var querystring=require(_0x36f7('0xf'));var Papa=require(_0x36f7('0x10'));var Redis=require(_0x36f7('0x11'));var authService=require(_0x36f7('0x12'));var qs=require(_0x36f7('0x13'));var as=require(_0x36f7('0x14'));var hardwareService=require(_0x36f7('0x15'));var logger=require(_0x36f7('0x16'))('api');var utils=require(_0x36f7('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0x36f7('0x18'));var db=require(_0x36f7('0x19'))['db'];var extensions=require(_0x36f7('0x1a'));function respondWithStatusCode(_0x19b2dc,_0x48c7b2){_0x48c7b2=_0x48c7b2||0xcc;return function(_0x262b70){if(_0x262b70){return _0x19b2dc[_0x36f7('0x1b')](_0x48c7b2);}return _0x19b2dc[_0x36f7('0x1c')](_0x48c7b2)[_0x36f7('0x1d')]();};}function respondWithResult(_0xc5d66d,_0x3a4856){_0x3a4856=_0x3a4856||0xc8;return function(_0x25e46e){if(_0x25e46e){return _0xc5d66d[_0x36f7('0x1c')](_0x3a4856)[_0x36f7('0x1e')](_0x25e46e);}};}function respondWithFilteredResult(_0x4729a3,_0x58e8ff){return function(_0x171843){if(_0x171843){var _0x145390=typeof _0x58e8ff[_0x36f7('0x1f')]==='undefined'&&typeof _0x58e8ff[_0x36f7('0x20')]===_0x36f7('0x21');var _0x3f5469=_0x171843[_0x36f7('0x22')];var _0x4a095d=_0x145390?0x0:_0x58e8ff[_0x36f7('0x1f')];var _0x49adde=_0x145390?_0x171843[_0x36f7('0x22')]:_0x58e8ff['offset']+_0x58e8ff['limit'];var _0x36293f;if(_0x49adde>=_0x3f5469){_0x49adde=_0x3f5469;_0x36293f=0xc8;}else{_0x36293f=0xce;}_0x4729a3['status'](_0x36293f);return _0x4729a3[_0x36f7('0x23')](_0x36f7('0x24'),_0x4a095d+'-'+_0x49adde+'/'+_0x3f5469)[_0x36f7('0x1e')](_0x171843);}return null;};}function patchUpdates(_0x50dbd4){return function(_0x44392e){try{jsonpatch[_0x36f7('0x25')](_0x44392e,_0x50dbd4,!![]);}catch(_0x327263){return BPromise[_0x36f7('0x26')](_0x327263);}return _0x44392e['save']();};}function saveUpdates(_0x9240d8,_0x47c401){return function(_0x208c86){if(_0x208c86){return _0x208c86[_0x36f7('0x27')](_0x9240d8)[_0x36f7('0x28')](function(_0x406e6c){return _0x406e6c;});}return null;};}function removeEntity(_0x4eed6d,_0x1d30f6){return function(_0x179f8e){if(_0x179f8e){return _0x179f8e[_0x36f7('0x29')]()[_0x36f7('0x28')](function(){var _0x5fa631=_0x179f8e['get']({'plain':!![]});var _0x55795e=_0x36f7('0x2a');return db[_0x36f7('0x2b')][_0x36f7('0x29')]({'where':{'type':_0x55795e,'resourceId':_0x5fa631['id']}})[_0x36f7('0x28')](function(){return _0x179f8e;});})[_0x36f7('0x28')](function(){_0x4eed6d[_0x36f7('0x1c')](0xcc)[_0x36f7('0x1d')]();});}};}function handleEntityNotFound(_0x3e9d66,_0x58f793){return function(_0x159d2b){if(!_0x159d2b){_0x3e9d66[_0x36f7('0x1b')](0x194);}return _0x159d2b;};}function handleError(_0xb830ce,_0x19b53d){_0x19b53d=_0x19b53d||0x1f4;return function(_0x3710be){logger[_0x36f7('0x2c')](_0x3710be[_0x36f7('0x2d')]);if(_0x3710be['name']){delete _0x3710be[_0x36f7('0x2e')];}_0xb830ce[_0x36f7('0x1c')](_0x19b53d)[_0x36f7('0x2f')](_0x3710be);};}exports[_0x36f7('0x30')]=function(_0x5d6429,_0x4420b7){var _0x36f69c={},_0x520a42={},_0xe56b5f={'count':0x0,'rows':[]};var _0x263d71=_['map'](db[_0x36f7('0x31')][_0x36f7('0x32')],function(_0x1d867f){return{'name':_0x1d867f[_0x36f7('0x33')],'type':_0x1d867f[_0x36f7('0x34')]['key']};});_0x520a42[_0x36f7('0x35')]=_['map'](_0x263d71,_0x36f7('0x2e'));_0x520a42[_0x36f7('0x36')]=_[_0x36f7('0x37')](_0x5d6429[_0x36f7('0x36')]);_0x520a42[_0x36f7('0x38')]=_[_0x36f7('0x39')](_0x520a42[_0x36f7('0x35')],_0x520a42[_0x36f7('0x36')]);_0x36f69c[_0x36f7('0x3a')]=_[_0x36f7('0x39')](_0x520a42[_0x36f7('0x35')],qs['fields'](_0x5d6429[_0x36f7('0x36')][_0x36f7('0x3b')]));_0x36f69c[_0x36f7('0x3a')]=_0x36f69c[_0x36f7('0x3a')][_0x36f7('0x3c')]?_0x36f69c[_0x36f7('0x3a')]:_0x520a42[_0x36f7('0x35')];if(!_0x5d6429['query'][_0x36f7('0x3d')](_0x36f7('0x3e'))){_0x36f69c[_0x36f7('0x20')]=qs['limit'](_0x5d6429[_0x36f7('0x36')][_0x36f7('0x20')]);_0x36f69c[_0x36f7('0x1f')]=qs['offset'](_0x5d6429[_0x36f7('0x36')][_0x36f7('0x1f')]);}_0x36f69c[_0x36f7('0x3f')]=qs[_0x36f7('0x40')](_0x5d6429[_0x36f7('0x36')][_0x36f7('0x40')]);_0x36f69c[_0x36f7('0x41')]=qs[_0x36f7('0x38')](_['pick'](_0x5d6429['query'],_0x520a42[_0x36f7('0x38')]),_0x263d71);if(_0x5d6429[_0x36f7('0x36')]['filter']){_0x36f69c[_0x36f7('0x41')]=_[_0x36f7('0x42')](_0x36f69c[_0x36f7('0x41')],{'$or':_[_0x36f7('0x43')](_0x263d71,function(_0x29d8b0){if(_0x29d8b0['type']!==_0x36f7('0x44')){var _0x3b941a={};_0x3b941a[_0x29d8b0[_0x36f7('0x2e')]]={'$like':'%'+_0x5d6429[_0x36f7('0x36')]['filter']+'%'};return _0x3b941a;}})});}_0x36f69c=_[_0x36f7('0x42')]({},_0x36f69c,_0x5d6429[_0x36f7('0x45')]);var _0xc5e5b2={'where':_0x36f69c[_0x36f7('0x41')]};return db[_0x36f7('0x31')][_0x36f7('0x22')](_0xc5e5b2)[_0x36f7('0x28')](function(_0x19fb03){_0xe56b5f[_0x36f7('0x22')]=_0x19fb03;if(_0x5d6429[_0x36f7('0x36')][_0x36f7('0x46')]){_0x36f69c[_0x36f7('0x47')]=[{'all':!![]}];}return db[_0x36f7('0x31')]['findAll'](_0x36f69c);})[_0x36f7('0x28')](function(_0x2f0fa5){_0xe56b5f['rows']=_0x2f0fa5;return _0xe56b5f;})[_0x36f7('0x28')](respondWithFilteredResult(_0x4420b7,_0x36f69c))[_0x36f7('0x48')](handleError(_0x4420b7,null));};exports[_0x36f7('0x49')]=function(_0x3ce78c,_0xb9afca){var _0x156aa9={'raw':!![],'where':{'id':_0x3ce78c[_0x36f7('0x4a')]['id']}},_0x330229={};_0x330229['model']=_['keys'](db['Interval']['rawAttributes']);_0x330229[_0x36f7('0x36')]=_[_0x36f7('0x37')](_0x3ce78c['query']);_0x330229[_0x36f7('0x38')]=_['intersection'](_0x330229['model'],_0x330229[_0x36f7('0x36')]);_0x156aa9[_0x36f7('0x3a')]=_[_0x36f7('0x39')](_0x330229[_0x36f7('0x35')],qs[_0x36f7('0x3b')](_0x3ce78c[_0x36f7('0x36')]['fields']));_0x156aa9[_0x36f7('0x3a')]=_0x156aa9[_0x36f7('0x3a')]['length']?_0x156aa9[_0x36f7('0x3a')]:_0x330229[_0x36f7('0x35')];if(_0x3ce78c[_0x36f7('0x36')][_0x36f7('0x46')]){_0x156aa9[_0x36f7('0x47')]=[{'all':!![]}];}_0x156aa9=_[_0x36f7('0x42')]({},_0x156aa9,_0x3ce78c[_0x36f7('0x45')]);return db[_0x36f7('0x31')][_0x36f7('0x4b')](_0x156aa9)[_0x36f7('0x28')](handleEntityNotFound(_0xb9afca,null))['then'](respondWithResult(_0xb9afca,null))[_0x36f7('0x48')](handleError(_0xb9afca,null));};exports['create']=function(_0x6d120c,_0x2a751e){return db[_0x36f7('0x31')]['create'](_0x6d120c[_0x36f7('0x4c')],{})[_0x36f7('0x28')](function(_0x2c503b){var _0x52a9eb=_0x6d120c['user'][_0x36f7('0x4d')]({'plain':!![]});if(!_0x52a9eb)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x52a9eb[_0x36f7('0x4e')]===_0x36f7('0x4f')){var _0x50ac04=_0x2c503b['get']({'plain':!![]});var _0x199489=_0x36f7('0x2a');return db[_0x36f7('0x50')][_0x36f7('0x4b')]({'where':{'name':_0x199489,'userProfileId':_0x52a9eb[_0x36f7('0x51')]},'raw':!![]})[_0x36f7('0x28')](function(_0x24af7b){if(_0x24af7b&&_0x24af7b[_0x36f7('0x52')]===0x0){return db[_0x36f7('0x2b')][_0x36f7('0x53')]({'name':_0x50ac04[_0x36f7('0x2e')],'resourceId':_0x50ac04['id'],'type':_0x24af7b['name'],'sectionId':_0x24af7b['id']},{})['then'](function(){return _0x2c503b;});}else{return _0x2c503b;}})['catch'](function(_0x3ace5c){logger[_0x36f7('0x2c')](_0x36f7('0x54'),_0x3ace5c);throw _0x3ace5c;});}return _0x2c503b;})[_0x36f7('0x28')](respondWithResult(_0x2a751e,0xc9))[_0x36f7('0x48')](handleError(_0x2a751e,null));};exports['update']=function(_0x42fa0c,_0x1f5105){if(_0x42fa0c[_0x36f7('0x4c')]['id']){delete _0x42fa0c[_0x36f7('0x4c')]['id'];}return db['Interval'][_0x36f7('0x4b')]({'where':{'id':_0x42fa0c[_0x36f7('0x4a')]['id']}})[_0x36f7('0x28')](handleEntityNotFound(_0x1f5105,null))[_0x36f7('0x28')](saveUpdates(_0x42fa0c[_0x36f7('0x4c')],null))[_0x36f7('0x28')](respondWithResult(_0x1f5105,null))[_0x36f7('0x48')](handleError(_0x1f5105,null));};exports['destroy']=function(_0x519c70,_0x4409c9){return db[_0x36f7('0x31')][_0x36f7('0x4b')]({'where':{'id':_0x519c70['params']['id']}})[_0x36f7('0x28')](handleEntityNotFound(_0x4409c9,null))['then'](removeEntity(_0x4409c9,null))[_0x36f7('0x48')](handleError(_0x4409c9,null));};exports[_0x36f7('0x55')]=function(_0x595b1b,_0x5bd8a1,_0x23bfb7){if(_0x595b1b['body']['id']){delete _0x595b1b[_0x36f7('0x4c')]['id'];}return db[_0x36f7('0x31')][_0x36f7('0x4b')]({'where':{'id':_0x595b1b[_0x36f7('0x4a')]['id']}})[_0x36f7('0x28')](handleEntityNotFound(_0x5bd8a1,null))['then'](function(_0x44eb96){if(_0x44eb96){_0x595b1b['body'][_0x36f7('0x56')]=_0x44eb96['id'];return db[_0x36f7('0x31')]['create'](_0x595b1b['body']);}})[_0x36f7('0x28')](respondWithResult(_0x5bd8a1,null))[_0x36f7('0x48')](handleError(_0x5bd8a1,null));};exports[_0x36f7('0x57')]=function(_0x41c0dd,_0x40bd07,_0x4ff5fc){var _0x56867e={};var _0x18fb26={};var _0x318596;var _0x2c2e4f;return db[_0x36f7('0x31')][_0x36f7('0x58')]({'where':{'id':_0x41c0dd['params']['id']}})[_0x36f7('0x28')](handleEntityNotFound(_0x40bd07,null))[_0x36f7('0x28')](function(_0x1d97d0){if(_0x1d97d0){_0x318596=_0x1d97d0;_0x18fb26[_0x36f7('0x35')]=_[_0x36f7('0x37')](db['Interval'][_0x36f7('0x32')]);_0x18fb26[_0x36f7('0x36')]=_[_0x36f7('0x37')](_0x41c0dd[_0x36f7('0x36')]);_0x18fb26[_0x36f7('0x38')]=_[_0x36f7('0x39')](_0x18fb26[_0x36f7('0x35')],_0x18fb26['query']);_0x56867e[_0x36f7('0x3a')]=_[_0x36f7('0x39')](_0x18fb26[_0x36f7('0x35')],qs['fields'](_0x41c0dd[_0x36f7('0x36')][_0x36f7('0x3b')]));_0x56867e[_0x36f7('0x3a')]=_0x56867e[_0x36f7('0x3a')][_0x36f7('0x3c')]?_0x56867e[_0x36f7('0x3a')]:_0x18fb26[_0x36f7('0x35')];_0x56867e[_0x36f7('0x3f')]=qs['sort'](_0x41c0dd[_0x36f7('0x36')][_0x36f7('0x40')]);_0x56867e[_0x36f7('0x41')]=qs[_0x36f7('0x38')](_[_0x36f7('0x59')](_0x41c0dd[_0x36f7('0x36')],_0x18fb26['filters']));if(_0x41c0dd['query']['filter']){_0x56867e[_0x36f7('0x41')]=_[_0x36f7('0x42')](_0x56867e[_0x36f7('0x41')],{'$or':_[_0x36f7('0x43')](_0x56867e[_0x36f7('0x3a')],function(_0x114b66){var _0x579606={};_0x579606[_0x114b66]={'$like':'%'+_0x41c0dd[_0x36f7('0x36')]['filter']+'%'};return _0x579606;})});}_0x56867e=_[_0x36f7('0x42')]({},_0x56867e,_0x41c0dd[_0x36f7('0x45')]);return _0x318596[_0x36f7('0x57')](_0x56867e);}})[_0x36f7('0x28')](function(_0x2f7711){if(_0x2f7711){_0x2c2e4f=_0x2f7711['length'];if(!_0x41c0dd['query'][_0x36f7('0x3d')](_0x36f7('0x3e'))){_0x56867e[_0x36f7('0x20')]=qs[_0x36f7('0x20')](_0x41c0dd[_0x36f7('0x36')][_0x36f7('0x20')]);_0x56867e[_0x36f7('0x1f')]=qs[_0x36f7('0x1f')](_0x41c0dd['query'][_0x36f7('0x1f')]);}return _0x318596[_0x36f7('0x57')](_0x56867e);}})[_0x36f7('0x28')](function(_0x227ee4){if(_0x227ee4){return _0x227ee4?{'count':_0x2c2e4f,'rows':_0x227ee4}:null;}})[_0x36f7('0x28')](respondWithResult(_0x40bd07,null))[_0x36f7('0x48')](handleError(_0x40bd07,null));};exports[_0x36f7('0x5a')]=function(_0xe3de17,_0x53790,_0x3af621){return db['Interval']['findOne']({'where':{'id':_0xe3de17['params']['id']}})[_0x36f7('0x28')](handleEntityNotFound(_0x53790,null))[_0x36f7('0x28')](function(_0x1ae54a){if(_0x1ae54a){return db[_0x36f7('0x5b')][_0x36f7('0x5c')](function(_0x2f7c00){return db[_0x36f7('0x31')][_0x36f7('0x29')]({'where':{'IntervalId':_0xe3de17[_0x36f7('0x4a')]['id']},'transaction':_0x2f7c00})[_0x36f7('0x28')](function(_0x39df25){var _0x31327e=_[_0x36f7('0x43')](_0xe3de17['body'],function(_0x49cc87){delete _0x49cc87['id'];_0x49cc87[_0x36f7('0x56')]=_0xe3de17['params']['id'];return _0x49cc87;});return db[_0x36f7('0x31')][_0x36f7('0x5d')](_0x31327e,{'transaction':_0x2f7c00});});})[_0x36f7('0x28')](function(){return db['Interval'][_0x36f7('0x5e')]({'where':{'IntervalId':_0xe3de17[_0x36f7('0x4a')]['id']}});});}})[_0x36f7('0x28')](respondWithResult(_0x53790,null))[_0x36f7('0x48')](handleError(_0x53790,null));};