9b099585026108cf1992ab294aeb505ad5f18dc6
[motion2.git] / server / components / parsers / qs.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 _0x2502=['merge','map','lower','options','include','push','lodash','moment','../../mysqldb','parse','keys','includes','model','alias','fields','split','filters','isEmpty','type','DATE','$gte','format','YYYY-MM-DD','utc','$lte','subtract','name','uniqueid','isArray','limit','offset','indexOf','priority','cast','col','unsigned','substr','omit','length','isObject','isString','unset','hasOwnProperty','isNumeric','match','isEmail','getFullTextValue','{EXPR}','replace','trim','join','$id','query','intersection','attributes','nolimit','sort','where','pick','filter','object','columns','value'];(function(_0x1a5ad1,_0x357407){var _0x7b8b22=function(_0x312e53){while(--_0x312e53){_0x1a5ad1['push'](_0x1a5ad1['shift']());}};_0x7b8b22(++_0x357407);}(_0x2502,0x1bf));var _0x2250=function(_0x33cd9d,_0x2a0516){_0x33cd9d=_0x33cd9d-0x0;var _0x270fc1=_0x2502[_0x33cd9d];return _0x270fc1;};'use strict';var _=require(_0x2250('0x0'));var sequelize=require('sequelize');var moment=require(_0x2250('0x1'));var db=require(_0x2250('0x2'))['db'];var LIMIT_VALUE=0xfa;function hasSequelizeOperator(_0x353103){var _0xda7e03=['ne'];try{var _0x51db49=JSON[_0x2250('0x3')](_0x353103);var _0xf82f85=Object[_0x2250('0x4')](_0x51db49)[0x0];return _0xda7e03[_0x2250('0x5')](_0xf82f85);}catch(_0x419f8d){return![];}}function getOperatorValue(_0x359585){var _0x3e89bb=JSON[_0x2250('0x3')](_0x359585);var _0x59f691=Object['keys'](_0x3e89bb)[0x0];var _0x1d43f2=_0x3e89bb[_0x59f691];return{['$'+_0x59f691]:_0x1d43f2};}function parseIncludeModel(_0x933f65){var _0x27f932=JSON[_0x2250('0x3')](_0x933f65);return{'model':db[_0x27f932[_0x2250('0x6')]],'as':_0x27f932[_0x2250('0x7')],'attributes':_0x27f932[_0x2250('0x8')],'raw':_0x27f932['raw']};}exports['fields']=function(_0x39cd95){var _0x3b97f0=null;if(_0x39cd95){_0x3b97f0=_0x39cd95[_0x2250('0x9')](',');}return _0x3b97f0;};exports[_0x2250('0xa')]=function(_0x5a709f,_0x2d6081){var _0x54d0b4={};if(!_[_0x2250('0xb')](_0x5a709f)){_['forOwn'](_0x5a709f,function(_0x74672,_0x27f2ce){try{if(_0x2d6081){var _0x1f3d2e=_['find'](_0x2d6081,{'name':_0x27f2ce})||{};if(hasSequelizeOperator(_0x74672)){_0x54d0b4[_0x27f2ce]=getOperatorValue(_0x74672);}else if(_0x1f3d2e[_0x2250('0xc')]===_0x2250('0xd')&&_['isPlainObject'](_0x74672)){var _0x29403c=JSON['parse'](_0x74672);var _0x2afa2c={'$gte':moment(moment(_0x29403c[_0x2250('0xe')])[_0x2250('0xf')](_0x2250('0x10')))[_0x2250('0x11')]()[_0x2250('0xf')](),'$lte':moment(moment(_0x29403c[_0x2250('0x12')])['format'](_0x2250('0x10')))[_0x2250('0x11')]()[_0x2250('0x13')](0x1,'s')[_0x2250('0xf')]()};_0x54d0b4[_0x27f2ce]=_0x2afa2c;}else if(_0x1f3d2e[_0x2250('0x14')]===_0x2250('0x15')){_0x54d0b4[_0x27f2ce]=_0x74672;}else{_0x54d0b4[_0x27f2ce]=_[_0x2250('0x16')](_0x74672)?_0x74672:JSON[_0x2250('0x3')](_0x74672);}}else{_0x54d0b4[_0x27f2ce]=_[_0x2250('0x16')](_0x74672)?_0x74672:JSON[_0x2250('0x3')](_0x74672);}}catch(_0x11dcf2){_0x54d0b4[_0x27f2ce]=_0x74672['split'](',');}});}return _0x54d0b4;};exports[_0x2250('0x17')]=function(_0x4a3a06){_0x4a3a06=parseInt(_0x4a3a06,0xa);if(!_0x4a3a06||_0x4a3a06<0x0){_0x4a3a06=LIMIT_VALUE;}return _0x4a3a06;};exports[_0x2250('0x18')]=function(_0x19795a){_0x19795a=parseInt(_0x19795a,0xa);if(!_0x19795a||_0x19795a<0x0){_0x19795a=0x0;}return _0x19795a;};exports['sort']=function(_0x2e045e){var _0xdad9d7,_0x4b788d=null;if(_0x2e045e){_0xdad9d7=_0x2e045e[_0x2250('0x9')](',');_0x4b788d=_['map'](_0xdad9d7,function(_0x26eeda){if(_0x26eeda[_0x2250('0x19')]('-')===0x0){return[_0x26eeda===_0x2250('0x1a')?sequelize[_0x2250('0x1b')](sequelize[_0x2250('0x1c')](_0x2250('0x1a')),_0x2250('0x1d')):_0x26eeda[_0x2250('0x1e')](0x1),'DESC'];}else{return[_0x26eeda===_0x2250('0x1a')?sequelize[_0x2250('0x1b')](sequelize['col'](_0x2250('0x1a')),_0x2250('0x1d')):_0x26eeda,'ASC'];}});}return _0x4b788d;};exports[_0x2250('0x1f')]=function(_0x4c29ff,_0x184bbe){if(_[_0x2250('0xb')](_0x4c29ff)){return _0x4c29ff;}if(_['isArray'](_0x4c29ff)){for(var _0x3b2e62=0x0;_0x3b2e62<_0x4c29ff[_0x2250('0x20')];_0x3b2e62+=0x1){_0x4c29ff[_0x3b2e62]=this[_0x2250('0x1f')](_0x4c29ff[_0x3b2e62],_0x184bbe);}return _0x4c29ff;}if(!_[_0x2250('0x21')](_0x4c29ff)){return _0x4c29ff;}if(_[_0x2250('0x22')](_0x184bbe)){_0x184bbe=[_0x184bbe];}if(!_[_0x2250('0x16')](_0x184bbe)){return _0x4c29ff;}for(var _0x162aff=0x0;_0x162aff<_0x184bbe[_0x2250('0x20')];_0x162aff+=0x1){_[_0x2250('0x23')](_0x4c29ff,_0x184bbe[_0x162aff]);}for(var _0x53b5c2 in _0x4c29ff){if(_0x4c29ff[_0x2250('0x24')](_0x53b5c2)){_0x4c29ff[_0x53b5c2]=this[_0x2250('0x1f')](_0x4c29ff[_0x53b5c2],_0x184bbe);}}return _0x4c29ff;};exports[_0x2250('0x25')]=function(_0xd4156c){return _0xd4156c[_0x2250('0x26')](RegExp('^[+]?[0-9]*$'))?!![]:![];};exports[_0x2250('0x27')]=function(_0x3d205e){return _0x3d205e[_0x2250('0x26')](/^\S+@\S+$/)?!![]:![];};exports[_0x2250('0x28')]=function(_0x2a1068,_0xe80120){var _0x1a7d93=[];var _0x1d1fe1=/([^:]")"+/g;var _0x1de611=/[*<>~@-]/g;var _0x28813e=/[ `!@#$%^&*()_\-?~<>]/;var _0x584289=/[ ,]+/;var _0x588553=_0xe80120?'\x22{EXPR}\x22':_0x2250('0x29');if(_0xe80120){_0x2a1068=_0x2a1068[_0x2250('0x2a')](_0x1de611,'\x20')[_0x2250('0x2b')]();}_0x2a1068['split'](_0x584289)['forEach'](function(_0x3164ce){_0x3164ce=_0x3164ce[_0x2250('0x2a')](_0x1d1fe1,'$1');_0x3164ce='+'+_0x3164ce+'*';var _0x5a4a64=_0x3164ce['match'](_0x28813e);if(_0x5a4a64){_0x3164ce='\x22'+_0x3164ce+'\x22';}_0x1a7d93['push'](_0x3164ce);});_0x588553=_0x588553[_0x2250('0x2a')](_0x2250('0x29'),_0x1a7d93[_0x2250('0x2c')]('\x20'));return _0x588553;};exports['getOptions']=function(_0x218751,_0x54aae7,_0x39cf1a){var _0x425133={},_0x46024e={};if(_0x54aae7['query'][_0x2250('0x2d')]){_0x54aae7['query']['id']=_0x54aae7[_0x2250('0x2e')][_0x2250('0x2d')];delete _0x54aae7['query'][_0x2250('0x2d')];}_0x425133['model']=_['map'](_0x218751,'name');_0x425133[_0x2250('0x2e')]=_[_0x2250('0x4')](_0x54aae7[_0x2250('0x2e')]);_0x425133[_0x2250('0xa')]=_[_0x2250('0x2f')](_0x425133[_0x2250('0x6')],_0x425133[_0x2250('0x2e')]);_0x46024e['attributes']=_[_0x2250('0x2f')](_0x425133[_0x2250('0x6')],this[_0x2250('0x8')](_0x54aae7[_0x2250('0x2e')][_0x2250('0x8')]));_0x46024e[_0x2250('0x30')]=_0x46024e[_0x2250('0x30')][_0x2250('0x20')]?_0x46024e[_0x2250('0x30')]:_0x425133[_0x2250('0x6')];if(!_0x54aae7[_0x2250('0x2e')][_0x2250('0x24')](_0x2250('0x31'))){_0x46024e[_0x2250('0x17')]=this[_0x2250('0x17')](_0x54aae7[_0x2250('0x2e')][_0x2250('0x17')]);_0x46024e[_0x2250('0x18')]=this[_0x2250('0x18')](_0x54aae7[_0x2250('0x2e')][_0x2250('0x18')]);}_0x46024e['order']=this['sort'](_0x54aae7[_0x2250('0x2e')][_0x2250('0x32')]);_0x46024e[_0x2250('0x33')]=this['filters'](_[_0x2250('0x34')](_0x54aae7[_0x2250('0x2e')],_0x425133[_0x2250('0xa')]),_0x218751);if(_0x54aae7['query'][_0x2250('0x35')]){var _0x5b5ecd=_0x218751;var _0x52d204=_0x54aae7[_0x2250('0x2e')][_0x2250('0x35')];if(typeof _0x52d204===_0x2250('0x36')){_0x5b5ecd=_[_0x2250('0x35')](_0x218751,function(_0x2bd242){return _[_0x2250('0x5')](_0x52d204[_0x2250('0x37')],_0x2bd242[_0x2250('0x14')]);});_0x52d204=_0x52d204[_0x2250('0x38')];}_0x46024e[_0x2250('0x33')]=_[_0x2250('0x39')](_0x46024e[_0x2250('0x33')],{'$or':_[_0x2250('0x3a')](_0x5b5ecd,function(_0x34595d){if(_0x34595d['type']!=='VIRTUAL'){if(_0x39cf1a){return sequelize[_0x2250('0x33')](sequelize['fn'](_0x2250('0x3b'),sequelize['col'](_0x34595d[_0x2250('0x14')])),{'$like':sequelize['fn'](_0x2250('0x3b'),'%'+_0x54aae7[_0x2250('0x2e')][_0x2250('0x35')]+'%')});}else{var _0x3aa0e6={};_0x3aa0e6[_0x34595d[_0x2250('0x14')]]={'$like':'%'+_0x54aae7[_0x2250('0x2e')]['filter']+'%'};return _0x3aa0e6;}}})});}_0x46024e=_[_0x2250('0x39')]({},_0x46024e,_0x54aae7[_0x2250('0x3c')]);return _0x46024e;};exports['include']=function(_0x5d188e){var _0x4131c2=[];if(_0x5d188e['includeAll']){_0x4131c2['push']({'all':!![]});}else if(_0x5d188e['include']){if(Array['isArray'](_0x5d188e[_0x2250('0x3d')])){_0x4131c2=Object[_0x2250('0x4')](_0x5d188e[_0x2250('0x3d')])['map'](function(_0x3cea00){return parseIncludeModel(_0x5d188e[_0x2250('0x3d')][_0x3cea00]);});}else{var _0x209e74=parseIncludeModel(_0x5d188e['include']);_0x4131c2[_0x2250('0x3e')](_0x209e74);}}return _0x4131c2;};exports['escapeLIKESpecialChars']=function(_0x41de40){return _0x41de40[_0x2250('0x2a')](/[%_^-]/g,function(_0x39d8c4){return'\x5c'+_0x39d8c4;});};