06a805ee1597dab9e7b5baba29dcfa273b5052a6
[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 _0x953f=['priority','cast','col','unsigned','substr','DESC','ASC','omit','length','isObject','unset','isNumeric','^[+]?[0-9]*$','isEmail','match','getFullTextValue','\x22{EXPR}\x22','{EXPR}','replace','forEach','push','join','getOptions','$id','query','filters','intersection','attributes','nolimit','order','sort','where','pick','filter','object','name','value','type','VIRTUAL','lower','merge','options','include','includeAll','escapeLIKESpecialChars','lodash','sequelize','moment','../../mysqldb','parse','keys','includes','model','alias','raw','fields','isEmpty','find','DATE','isPlainObject','$gte','YYYY-MM-DD','utc','format','uniqueid','isArray','limit','offset','split','map','indexOf'];(function(_0x65c50e,_0x1aa926){var _0x4573e7=function(_0x5bc049){while(--_0x5bc049){_0x65c50e['push'](_0x65c50e['shift']());}};_0x4573e7(++_0x1aa926);}(_0x953f,0x190));var _0xf953=function(_0x1694f5,_0x49b7c3){_0x1694f5=_0x1694f5-0x0;var _0x5b4321=_0x953f[_0x1694f5];return _0x5b4321;};'use strict';var _=require(_0xf953('0x0'));var sequelize=require(_0xf953('0x1'));var moment=require(_0xf953('0x2'));var db=require(_0xf953('0x3'))['db'];var LIMIT_VALUE=0xfa;function hasSequelizeOperator(_0x2ef4a1){var _0x1618ac=['ne'];try{var _0x68d8f0=JSON[_0xf953('0x4')](_0x2ef4a1);var _0x537270=Object[_0xf953('0x5')](_0x68d8f0)[0x0];return _0x1618ac[_0xf953('0x6')](_0x537270);}catch(_0x16d732){return![];}}function getOperatorValue(_0x1eeff1){var _0x4bbadc=JSON[_0xf953('0x4')](_0x1eeff1);var _0x4f5ed7=Object[_0xf953('0x5')](_0x4bbadc)[0x0];var _0x32e7a3=_0x4bbadc[_0x4f5ed7];return{['$'+_0x4f5ed7]:_0x32e7a3};}function parseIncludeModel(_0x4d728){var _0x3ddcfb=JSON[_0xf953('0x4')](_0x4d728);return{'model':db[_0x3ddcfb[_0xf953('0x7')]],'as':_0x3ddcfb[_0xf953('0x8')],'attributes':_0x3ddcfb['fields'],'raw':_0x3ddcfb[_0xf953('0x9')]};}exports[_0xf953('0xa')]=function(_0x5429eb){var _0x43caff=null;if(_0x5429eb){_0x43caff=_0x5429eb['split'](',');}return _0x43caff;};exports['filters']=function(_0x3513b9,_0x43f6c9){var _0xedce10={};if(!_[_0xf953('0xb')](_0x3513b9)){_['forOwn'](_0x3513b9,function(_0x521661,_0x10912a){try{if(_0x43f6c9){var _0x308b89=_[_0xf953('0xc')](_0x43f6c9,{'name':_0x10912a})||{};if(hasSequelizeOperator(_0x521661)){_0xedce10[_0x10912a]=getOperatorValue(_0x521661);}else if(_0x308b89['type']===_0xf953('0xd')&&_[_0xf953('0xe')](_0x521661)){var _0x4ab802=JSON[_0xf953('0x4')](_0x521661);var _0x42a9f3={'$gte':moment(moment(_0x4ab802[_0xf953('0xf')])['format'](_0xf953('0x10')))[_0xf953('0x11')]()[_0xf953('0x12')](),'$lte':moment(moment(_0x4ab802['$lte'])[_0xf953('0x12')](_0xf953('0x10')))[_0xf953('0x11')]()['subtract'](0x1,'s')['format']()};_0xedce10[_0x10912a]=_0x42a9f3;}else if(_0x308b89['name']===_0xf953('0x13')){_0xedce10[_0x10912a]=_0x521661;}else{_0xedce10[_0x10912a]=_['isArray'](_0x521661)?_0x521661:JSON[_0xf953('0x4')](_0x521661);}}else{_0xedce10[_0x10912a]=_[_0xf953('0x14')](_0x521661)?_0x521661:JSON[_0xf953('0x4')](_0x521661);}}catch(_0x310dcb){_0xedce10[_0x10912a]=_0x521661['split'](',');}});}return _0xedce10;};exports[_0xf953('0x15')]=function(_0x4fd5c4){_0x4fd5c4=parseInt(_0x4fd5c4,0xa);if(!_0x4fd5c4||_0x4fd5c4<0x0){_0x4fd5c4=LIMIT_VALUE;}return _0x4fd5c4;};exports[_0xf953('0x16')]=function(_0x49b43b){_0x49b43b=parseInt(_0x49b43b,0xa);if(!_0x49b43b||_0x49b43b<0x0){_0x49b43b=0x0;}return _0x49b43b;};exports['sort']=function(_0x529eaf){var _0x13c090,_0x6ea1a6=null;if(_0x529eaf){_0x13c090=_0x529eaf[_0xf953('0x17')](',');_0x6ea1a6=_[_0xf953('0x18')](_0x13c090,function(_0x36dd49){if(_0x36dd49[_0xf953('0x19')]('-')===0x0){return[_0x36dd49===_0xf953('0x1a')?sequelize[_0xf953('0x1b')](sequelize[_0xf953('0x1c')]('priority'),_0xf953('0x1d')):_0x36dd49[_0xf953('0x1e')](0x1),_0xf953('0x1f')];}else{return[_0x36dd49===_0xf953('0x1a')?sequelize[_0xf953('0x1b')](sequelize[_0xf953('0x1c')](_0xf953('0x1a')),'unsigned'):_0x36dd49,_0xf953('0x20')];}});}return _0x6ea1a6;};exports[_0xf953('0x21')]=function(_0x4df216,_0x4d7d36){if(_[_0xf953('0xb')](_0x4df216)){return _0x4df216;}if(_[_0xf953('0x14')](_0x4df216)){for(var _0x51c226=0x0;_0x51c226<_0x4df216[_0xf953('0x22')];_0x51c226+=0x1){_0x4df216[_0x51c226]=this[_0xf953('0x21')](_0x4df216[_0x51c226],_0x4d7d36);}return _0x4df216;}if(!_[_0xf953('0x23')](_0x4df216)){return _0x4df216;}if(_['isString'](_0x4d7d36)){_0x4d7d36=[_0x4d7d36];}if(!_[_0xf953('0x14')](_0x4d7d36)){return _0x4df216;}for(var _0x2171f6=0x0;_0x2171f6<_0x4d7d36[_0xf953('0x22')];_0x2171f6+=0x1){_[_0xf953('0x24')](_0x4df216,_0x4d7d36[_0x2171f6]);}for(var _0x194a49 in _0x4df216){if(_0x4df216['hasOwnProperty'](_0x194a49)){_0x4df216[_0x194a49]=this[_0xf953('0x21')](_0x4df216[_0x194a49],_0x4d7d36);}}return _0x4df216;};exports[_0xf953('0x25')]=function(_0xd7cfff){return _0xd7cfff['match'](RegExp(_0xf953('0x26')))?!![]:![];};exports[_0xf953('0x27')]=function(_0x23f473){return _0x23f473[_0xf953('0x28')](/^\S+@\S+$/)?!![]:![];};exports[_0xf953('0x29')]=function(_0x282896,_0x1b2c11){var _0x594545=[];var _0x16d489=/([^:]")"+/g;var _0x248366=/[*<>~@-]/g;var _0x3d8dd0=/[ `!@#$%^&*()_\-?~<>]/;var _0x1cc329=/[ ,]+/;var _0x58ef60=_0x1b2c11?_0xf953('0x2a'):_0xf953('0x2b');if(_0x1b2c11){_0x282896=_0x282896[_0xf953('0x2c')](_0x248366,'\x20')['trim']();}_0x282896['split'](_0x1cc329)[_0xf953('0x2d')](function(_0x6a7cf0){_0x6a7cf0=_0x6a7cf0['replace'](_0x16d489,'$1');_0x6a7cf0='+'+_0x6a7cf0+'*';var _0x2be3fc=_0x6a7cf0[_0xf953('0x28')](_0x3d8dd0);if(_0x2be3fc){_0x6a7cf0='\x22'+_0x6a7cf0+'\x22';}_0x594545[_0xf953('0x2e')](_0x6a7cf0);});_0x58ef60=_0x58ef60[_0xf953('0x2c')]('{EXPR}',_0x594545[_0xf953('0x2f')]('\x20'));return _0x58ef60;};exports[_0xf953('0x30')]=function(_0x55aa91,_0x20e21a,_0x6367a7){var _0x17470f={},_0x4f295f={};if(_0x20e21a['query'][_0xf953('0x31')]){_0x20e21a['query']['id']=_0x20e21a['query'][_0xf953('0x31')];delete _0x20e21a[_0xf953('0x32')][_0xf953('0x31')];}_0x17470f[_0xf953('0x7')]=_[_0xf953('0x18')](_0x55aa91,'name');_0x17470f[_0xf953('0x32')]=_[_0xf953('0x5')](_0x20e21a[_0xf953('0x32')]);_0x17470f[_0xf953('0x33')]=_[_0xf953('0x34')](_0x17470f[_0xf953('0x7')],_0x17470f[_0xf953('0x32')]);_0x4f295f[_0xf953('0x35')]=_[_0xf953('0x34')](_0x17470f[_0xf953('0x7')],this[_0xf953('0xa')](_0x20e21a['query'][_0xf953('0xa')]));_0x4f295f[_0xf953('0x35')]=_0x4f295f['attributes'][_0xf953('0x22')]?_0x4f295f[_0xf953('0x35')]:_0x17470f[_0xf953('0x7')];if(!_0x20e21a['query']['hasOwnProperty'](_0xf953('0x36'))){_0x4f295f['limit']=this[_0xf953('0x15')](_0x20e21a[_0xf953('0x32')][_0xf953('0x15')]);_0x4f295f[_0xf953('0x16')]=this[_0xf953('0x16')](_0x20e21a[_0xf953('0x32')][_0xf953('0x16')]);}_0x4f295f[_0xf953('0x37')]=this[_0xf953('0x38')](_0x20e21a[_0xf953('0x32')][_0xf953('0x38')]);_0x4f295f[_0xf953('0x39')]=this[_0xf953('0x33')](_[_0xf953('0x3a')](_0x20e21a[_0xf953('0x32')],_0x17470f['filters']),_0x55aa91);if(_0x20e21a[_0xf953('0x32')][_0xf953('0x3b')]){var _0x23c405=_0x55aa91;var _0x5814f0=_0x20e21a['query'][_0xf953('0x3b')];if(typeof _0x5814f0===_0xf953('0x3c')){_0x23c405=_[_0xf953('0x3b')](_0x55aa91,function(_0x5a1a25){return _[_0xf953('0x6')](_0x5814f0['columns'],_0x5a1a25[_0xf953('0x3d')]);});_0x5814f0=_0x5814f0[_0xf953('0x3e')];}_0x4f295f[_0xf953('0x39')]=_['merge'](_0x4f295f[_0xf953('0x39')],{'$or':_[_0xf953('0x18')](_0x23c405,function(_0x32cc4d){if(_0x32cc4d[_0xf953('0x3f')]!==_0xf953('0x40')){if(_0x6367a7){return sequelize[_0xf953('0x39')](sequelize['fn']('lower',sequelize['col'](_0x32cc4d['name'])),{'$like':sequelize['fn'](_0xf953('0x41'),'%'+_0x20e21a['query']['filter']+'%')});}else{var _0x3ab2b2={};_0x3ab2b2[_0x32cc4d['name']]={'$like':'%'+_0x20e21a[_0xf953('0x32')]['filter']+'%'};return _0x3ab2b2;}}})});}_0x4f295f=_[_0xf953('0x42')]({},_0x4f295f,_0x20e21a[_0xf953('0x43')]);return _0x4f295f;};exports[_0xf953('0x44')]=function(_0x4caa06){var _0x3f6fe2=[];if(_0x4caa06[_0xf953('0x45')]){_0x3f6fe2[_0xf953('0x2e')]({'all':!![]});}else if(_0x4caa06['include']){if(Array[_0xf953('0x14')](_0x4caa06['include'])){_0x3f6fe2=Object[_0xf953('0x5')](_0x4caa06[_0xf953('0x44')])[_0xf953('0x18')](function(_0x530a11){return parseIncludeModel(_0x4caa06[_0xf953('0x44')][_0x530a11]);});}else{var _0x11b416=parseIncludeModel(_0x4caa06[_0xf953('0x44')]);_0x3f6fe2[_0xf953('0x2e')](_0x11b416);}}return _0x3f6fe2;};exports[_0xf953('0x46')]=function(_0x35bc3f){return _0x35bc3f[_0xf953('0x2c')](/[%_^-]/g,function(_0x3a0053){return'\x5c'+_0x3a0053;});};