Built motion from commit (unavailable).|2.5.13
[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 _0x402b=['rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','sox','to-csv','ejs','lodash','squel','crypto','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','../../components/extensions/rewrite','sendStatus','status','end','json','count','offset','Content-Range','apply','reject','save','update','then','destroy','UserProfileResource','name','send','map','Interval','fieldName','type','key','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','limit','order','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','keys','rawAttributes','find','create','user','role','get','Intervals','autoAssociation','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','addInterval','getIntervals','sort','addIntervals','findOne','sequelize','transaction','IntervalId','bulkCreate','html-pdf','eml-format'];(function(_0x39cd60,_0x37a480){var _0x344b50=function(_0x2cd2ca){while(--_0x2cd2ca){_0x39cd60['push'](_0x39cd60['shift']());}};_0x344b50(++_0x37a480);}(_0x402b,0x112));var _0xb402=function(_0x44b77c,_0x1f9646){_0x44b77c=_0x44b77c-0x0;var _0x28604a=_0x402b[_0x44b77c];return _0x28604a;};'use strict';var pdf=require(_0xb402('0x0'));var emlformat=require(_0xb402('0x1'));var rimraf=require(_0xb402('0x2'));var zipdir=require(_0xb402('0x3'));var jsonpatch=require(_0xb402('0x4'));var rp=require(_0xb402('0x5'));var moment=require(_0xb402('0x6'));var BPromise=require(_0xb402('0x7'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0xb402('0x8'));var csv=require(_0xb402('0x9'));var ejs=require(_0xb402('0xa'));var fs=require('fs');var _=require(_0xb402('0xb'));var squel=require(_0xb402('0xc'));var crypto=require(_0xb402('0xd'));var jsforce=require(_0xb402('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xb402('0x9'));var querystring=require('querystring');var Papa=require(_0xb402('0xf'));var Redis=require(_0xb402('0x10'));var authService=require(_0xb402('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0xb402('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xb402('0x13'))(_0xb402('0x14'));var utils=require(_0xb402('0x15'));var config=require(_0xb402('0x16'));var licenseUtil=require(_0xb402('0x17'));var db=require(_0xb402('0x18'))['db'];var extensions=require(_0xb402('0x19'));function respondWithStatusCode(_0x16e8c3,_0x28b9dd){_0x28b9dd=_0x28b9dd||0xcc;return function(_0x58c8fb){if(_0x58c8fb){return _0x16e8c3[_0xb402('0x1a')](_0x28b9dd);}return _0x16e8c3[_0xb402('0x1b')](_0x28b9dd)[_0xb402('0x1c')]();};}function respondWithResult(_0x4b5a0a,_0x3a9abd){_0x3a9abd=_0x3a9abd||0xc8;return function(_0x436c94){if(_0x436c94){return _0x4b5a0a[_0xb402('0x1b')](_0x3a9abd)[_0xb402('0x1d')](_0x436c94);}};}function respondWithFilteredResult(_0xd5a16,_0x3994a5){return function(_0x38263c){if(_0x38263c){var _0x577504=_0x38263c[_0xb402('0x1e')],_0x373626=_0x3994a5[_0xb402('0x1f')],_0x5a368e=_0x3994a5[_0xb402('0x1f')]+_0x3994a5['limit'],_0x4d5df4;if(_0x5a368e>=_0x577504){_0x5a368e=_0x577504;_0x4d5df4=0xc8;}else{_0x4d5df4=0xce;}_0xd5a16[_0xb402('0x1b')](_0x4d5df4);return _0xd5a16['set'](_0xb402('0x20'),_0x373626+'-'+_0x5a368e+'/'+_0x577504)['json'](_0x38263c);}return null;};}function patchUpdates(_0x1460a7){return function(_0x296b36){try{jsonpatch[_0xb402('0x21')](_0x296b36,_0x1460a7,!![]);}catch(_0x38f7cd){return BPromise[_0xb402('0x22')](_0x38f7cd);}return _0x296b36[_0xb402('0x23')]();};}function saveUpdates(_0x560b5f,_0x4f64d0){return function(_0x4100a9){if(_0x4100a9){return _0x4100a9[_0xb402('0x24')](_0x560b5f)[_0xb402('0x25')](function(_0x23c865){return _0x23c865;});}return null;};}function removeEntity(_0x3ad909,_0x449af9){return function(_0x3f559a){if(_0x3f559a){return _0x3f559a[_0xb402('0x26')]()[_0xb402('0x25')](function(){var _0x55f28d=_0x3f559a['get']({'plain':!![]});var _0x9f9090='Intervals';return db[_0xb402('0x27')][_0xb402('0x26')]({'where':{'type':_0x9f9090,'resourceId':_0x55f28d['id']}})[_0xb402('0x25')](function(){return _0x3f559a;});})[_0xb402('0x25')](function(){_0x3ad909[_0xb402('0x1b')](0xcc)[_0xb402('0x1c')]();});}};}function handleEntityNotFound(_0x42d41b,_0x3fc90c){return function(_0x4b1356){if(!_0x4b1356){_0x42d41b[_0xb402('0x1a')](0x194);}return _0x4b1356;};}function handleError(_0x5aeb80,_0x1db244){_0x1db244=_0x1db244||0x1f4;return function(_0x53b6d3){logger['error'](_0x53b6d3['stack']);if(_0x53b6d3[_0xb402('0x28')]){delete _0x53b6d3[_0xb402('0x28')];}_0x5aeb80['status'](_0x1db244)[_0xb402('0x29')](_0x53b6d3);};}exports['index']=function(_0x19d93a,_0xc67087){var _0x30c9c7={},_0xfea409={},_0x3a6518={'count':0x0,'rows':[]};var _0x459845=_[_0xb402('0x2a')](db[_0xb402('0x2b')]['rawAttributes'],function(_0x24dfbc){return{'name':_0x24dfbc[_0xb402('0x2c')],'type':_0x24dfbc[_0xb402('0x2d')][_0xb402('0x2e')]};});_0xfea409[_0xb402('0x2f')]=_[_0xb402('0x2a')](_0x459845,_0xb402('0x28'));_0xfea409['query']=_['keys'](_0x19d93a[_0xb402('0x30')]);_0xfea409[_0xb402('0x31')]=_['intersection'](_0xfea409[_0xb402('0x2f')],_0xfea409['query']);_0x30c9c7['attributes']=_[_0xb402('0x32')](_0xfea409[_0xb402('0x2f')],qs[_0xb402('0x33')](_0x19d93a[_0xb402('0x30')][_0xb402('0x33')]));_0x30c9c7['attributes']=_0x30c9c7[_0xb402('0x34')][_0xb402('0x35')]?_0x30c9c7['attributes']:_0xfea409[_0xb402('0x2f')];if(!_0x19d93a[_0xb402('0x30')][_0xb402('0x36')](_0xb402('0x37'))){_0x30c9c7[_0xb402('0x38')]=qs['limit'](_0x19d93a[_0xb402('0x30')][_0xb402('0x38')]);_0x30c9c7[_0xb402('0x1f')]=qs[_0xb402('0x1f')](_0x19d93a[_0xb402('0x30')][_0xb402('0x1f')]);}_0x30c9c7[_0xb402('0x39')]=qs['sort'](_0x19d93a[_0xb402('0x30')]['sort']);_0x30c9c7[_0xb402('0x3a')]=qs[_0xb402('0x31')](_[_0xb402('0x3b')](_0x19d93a[_0xb402('0x30')],_0xfea409['filters']),_0x459845);if(_0x19d93a['query'][_0xb402('0x3c')]){_0x30c9c7[_0xb402('0x3a')]=_[_0xb402('0x3d')](_0x30c9c7[_0xb402('0x3a')],{'$or':_['map'](_0x459845,function(_0x3959dd){if(_0x3959dd[_0xb402('0x2d')]!==_0xb402('0x3e')){var _0xef3e7b={};_0xef3e7b[_0x3959dd[_0xb402('0x28')]]={'$like':'%'+_0x19d93a[_0xb402('0x30')][_0xb402('0x3c')]+'%'};return _0xef3e7b;}})});}_0x30c9c7=_['merge']({},_0x30c9c7,_0x19d93a[_0xb402('0x3f')]);var _0x2405d7={'where':_0x30c9c7[_0xb402('0x3a')]};return db[_0xb402('0x2b')][_0xb402('0x1e')](_0x2405d7)[_0xb402('0x25')](function(_0xd12c76){_0x3a6518[_0xb402('0x1e')]=_0xd12c76;if(_0x19d93a[_0xb402('0x30')][_0xb402('0x40')]){_0x30c9c7[_0xb402('0x41')]=[{'all':!![]}];}return db[_0xb402('0x2b')][_0xb402('0x42')](_0x30c9c7);})[_0xb402('0x25')](function(_0x5da0f5){_0x3a6518[_0xb402('0x43')]=_0x5da0f5;return _0x3a6518;})[_0xb402('0x25')](respondWithFilteredResult(_0xc67087,_0x30c9c7))[_0xb402('0x44')](handleError(_0xc67087,null));};exports[_0xb402('0x45')]=function(_0x4e20bc,_0x5694d2){var _0xe0138a={'raw':!![],'where':{'id':_0x4e20bc[_0xb402('0x46')]['id']}},_0x298154={};_0x298154[_0xb402('0x2f')]=_[_0xb402('0x47')](db[_0xb402('0x2b')][_0xb402('0x48')]);_0x298154[_0xb402('0x30')]=_[_0xb402('0x47')](_0x4e20bc[_0xb402('0x30')]);_0x298154[_0xb402('0x31')]=_[_0xb402('0x32')](_0x298154[_0xb402('0x2f')],_0x298154[_0xb402('0x30')]);_0xe0138a['attributes']=_[_0xb402('0x32')](_0x298154[_0xb402('0x2f')],qs[_0xb402('0x33')](_0x4e20bc[_0xb402('0x30')][_0xb402('0x33')]));_0xe0138a[_0xb402('0x34')]=_0xe0138a[_0xb402('0x34')][_0xb402('0x35')]?_0xe0138a[_0xb402('0x34')]:_0x298154[_0xb402('0x2f')];if(_0x4e20bc['query'][_0xb402('0x40')]){_0xe0138a['include']=[{'all':!![]}];}_0xe0138a=_[_0xb402('0x3d')]({},_0xe0138a,_0x4e20bc[_0xb402('0x3f')]);return db[_0xb402('0x2b')][_0xb402('0x49')](_0xe0138a)['then'](handleEntityNotFound(_0x5694d2,null))['then'](respondWithResult(_0x5694d2,null))['catch'](handleError(_0x5694d2,null));};exports['create']=function(_0x5903fe,_0x5af43a){return db['Interval'][_0xb402('0x4a')](_0x5903fe['body'],{})[_0xb402('0x25')](function(_0x3ff21d){var _0x3dc2c0=_0x5903fe[_0xb402('0x4b')]['get']({'plain':!![]});if(!_0x3dc2c0)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x3dc2c0[_0xb402('0x4c')]===_0xb402('0x4b')){var _0x21ebaf=_0x3ff21d[_0xb402('0x4d')]({'plain':!![]});var _0x612a20=_0xb402('0x4e');return db['UserProfileSection']['find']({'where':{'name':_0x612a20,'userProfileId':_0x3dc2c0['userProfileId']},'raw':!![]})['then'](function(_0x2f7463){if(_0x2f7463&&_0x2f7463[_0xb402('0x4f')]===0x0){return db[_0xb402('0x27')]['create']({'name':_0x21ebaf[_0xb402('0x28')],'resourceId':_0x21ebaf['id'],'type':_0x2f7463[_0xb402('0x28')],'sectionId':_0x2f7463['id']},{})[_0xb402('0x25')](function(){return _0x3ff21d;});}else{return _0x3ff21d;}})['catch'](function(_0xcba6d7){logger[_0xb402('0x50')](_0xb402('0x51'),_0xcba6d7);throw _0xcba6d7;});}return _0x3ff21d;})[_0xb402('0x25')](respondWithResult(_0x5af43a,0xc9))[_0xb402('0x44')](handleError(_0x5af43a,null));};exports[_0xb402('0x24')]=function(_0x4d818c,_0x4db62d){if(_0x4d818c[_0xb402('0x52')]['id']){delete _0x4d818c[_0xb402('0x52')]['id'];}return db[_0xb402('0x2b')]['find']({'where':{'id':_0x4d818c[_0xb402('0x46')]['id']}})[_0xb402('0x25')](handleEntityNotFound(_0x4db62d,null))[_0xb402('0x25')](saveUpdates(_0x4d818c[_0xb402('0x52')],null))[_0xb402('0x25')](respondWithResult(_0x4db62d,null))[_0xb402('0x44')](handleError(_0x4db62d,null));};exports[_0xb402('0x26')]=function(_0x3bcfe8,_0x15b2ce){return db[_0xb402('0x2b')]['find']({'where':{'id':_0x3bcfe8[_0xb402('0x46')]['id']}})[_0xb402('0x25')](handleEntityNotFound(_0x15b2ce,null))[_0xb402('0x25')](removeEntity(_0x15b2ce,null))[_0xb402('0x44')](handleError(_0x15b2ce,null));};exports[_0xb402('0x53')]=function(_0x371ff9,_0xd84ce3,_0x4c9b3c){if(_0x371ff9[_0xb402('0x52')]['id']){delete _0x371ff9['body']['id'];}return db[_0xb402('0x2b')]['find']({'where':{'id':_0x371ff9[_0xb402('0x46')]['id']}})[_0xb402('0x25')](handleEntityNotFound(_0xd84ce3,null))[_0xb402('0x25')](function(_0x3e2ef6){if(_0x3e2ef6){_0x371ff9[_0xb402('0x52')]['IntervalId']=_0x3e2ef6['id'];return db['Interval'][_0xb402('0x4a')](_0x371ff9['body']);}})[_0xb402('0x25')](respondWithResult(_0xd84ce3,null))[_0xb402('0x44')](handleError(_0xd84ce3,null));};exports[_0xb402('0x54')]=function(_0xfee5e,_0x520108,_0xf10756){var _0xa3d72={};var _0x278455={};var _0x3bae35;var _0x5d5091;return db['Interval']['findOne']({'where':{'id':_0xfee5e[_0xb402('0x46')]['id']}})[_0xb402('0x25')](handleEntityNotFound(_0x520108,null))[_0xb402('0x25')](function(_0x1c9b1a){if(_0x1c9b1a){_0x3bae35=_0x1c9b1a;_0x278455['model']=_[_0xb402('0x47')](db[_0xb402('0x2b')][_0xb402('0x48')]);_0x278455[_0xb402('0x30')]=_[_0xb402('0x47')](_0xfee5e['query']);_0x278455[_0xb402('0x31')]=_[_0xb402('0x32')](_0x278455[_0xb402('0x2f')],_0x278455[_0xb402('0x30')]);_0xa3d72['attributes']=_[_0xb402('0x32')](_0x278455[_0xb402('0x2f')],qs[_0xb402('0x33')](_0xfee5e[_0xb402('0x30')][_0xb402('0x33')]));_0xa3d72[_0xb402('0x34')]=_0xa3d72[_0xb402('0x34')][_0xb402('0x35')]?_0xa3d72[_0xb402('0x34')]:_0x278455[_0xb402('0x2f')];_0xa3d72['order']=qs['sort'](_0xfee5e[_0xb402('0x30')][_0xb402('0x55')]);_0xa3d72[_0xb402('0x3a')]=qs['filters'](_['pick'](_0xfee5e[_0xb402('0x30')],_0x278455['filters']));if(_0xfee5e[_0xb402('0x30')][_0xb402('0x3c')]){_0xa3d72[_0xb402('0x3a')]=_['merge'](_0xa3d72['where'],{'$or':_[_0xb402('0x2a')](_0xa3d72[_0xb402('0x34')],function(_0x407349){var _0x2912b8={};_0x2912b8[_0x407349]={'$like':'%'+_0xfee5e[_0xb402('0x30')]['filter']+'%'};return _0x2912b8;})});}_0xa3d72=_[_0xb402('0x3d')]({},_0xa3d72,_0xfee5e[_0xb402('0x3f')]);return _0x3bae35[_0xb402('0x54')](_0xa3d72);}})[_0xb402('0x25')](function(_0x54d56b){if(_0x54d56b){_0x5d5091=_0x54d56b[_0xb402('0x35')];if(!_0xfee5e[_0xb402('0x30')]['hasOwnProperty'](_0xb402('0x37'))){_0xa3d72[_0xb402('0x38')]=qs[_0xb402('0x38')](_0xfee5e['query'][_0xb402('0x38')]);_0xa3d72['offset']=qs['offset'](_0xfee5e[_0xb402('0x30')]['offset']);}return _0x3bae35[_0xb402('0x54')](_0xa3d72);}})[_0xb402('0x25')](function(_0x392f03){if(_0x392f03){return _0x392f03?{'count':_0x5d5091,'rows':_0x392f03}:null;}})[_0xb402('0x25')](respondWithResult(_0x520108,null))['catch'](handleError(_0x520108,null));};exports[_0xb402('0x56')]=function(_0x437dd1,_0x467a32,_0x1b68fe){return db['Interval'][_0xb402('0x57')]({'where':{'id':_0x437dd1[_0xb402('0x46')]['id']}})[_0xb402('0x25')](handleEntityNotFound(_0x467a32,null))[_0xb402('0x25')](function(_0x546bc2){if(_0x546bc2){return db[_0xb402('0x58')][_0xb402('0x59')](function(_0x4eb5b7){return db[_0xb402('0x2b')][_0xb402('0x26')]({'where':{'IntervalId':_0x437dd1[_0xb402('0x46')]['id']},'transaction':_0x4eb5b7})['then'](function(_0x5719a1){var _0x3a1ba1=_[_0xb402('0x2a')](_0x437dd1['body'],function(_0x2bd91b){delete _0x2bd91b['id'];_0x2bd91b[_0xb402('0x5a')]=_0x437dd1[_0xb402('0x46')]['id'];return _0x2bd91b;});return db[_0xb402('0x2b')][_0xb402('0x5b')](_0x3a1ba1,{'transaction':_0x4eb5b7});});})[_0xb402('0x25')](function(){return db['Interval'][_0xb402('0x42')]({'where':{'IntervalId':_0x437dd1[_0xb402('0x46')]['id']}});});}})['then'](respondWithResult(_0x467a32,null))[_0xb402('0x44')](handleError(_0x467a32,null));};