Built motion from commit e0fa946e.|2.6.5
[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 _0xf072=['DESC','unsigned','ASC','omit','isString','length','unset','hasOwnProperty','isNumeric','match','^[+]?[0-9]*$','getFullTextValue','forEach','replace','push','join','getOptions','query','$id','model','intersection','attributes','nolimit','limit','offset','pick','filter','object','includes','columns','where','merge','type','lower','col','options','lodash','sequelize','moment','parse','keys','fields','split','filters','forOwn','DATE','isPlainObject','$gte','YYYY-MM-DD','utc','format','$lte','subtract','name','uniqueid','isArray','sort','map','cast','priority','substr'];(function(_0x4c39f5,_0x109684){var _0x1db24f=function(_0x44879b){while(--_0x44879b){_0x4c39f5['push'](_0x4c39f5['shift']());}};_0x1db24f(++_0x109684);}(_0xf072,0x1cf));var _0x2f07=function(_0x2889b6,_0x558a66){_0x2889b6=_0x2889b6-0x0;var _0x79991d=_0xf072[_0x2889b6];return _0x79991d;};'use strict';var _=require(_0x2f07('0x0'));var sequelize=require(_0x2f07('0x1'));var moment=require(_0x2f07('0x2'));var LIMIT_VALUE=0xfa;function hasSequelizeOperator(_0x4f62b0){var _0x3c1c25=['ne'];try{var _0x5f20e3=JSON[_0x2f07('0x3')](_0x4f62b0);var _0x432696=Object[_0x2f07('0x4')](_0x5f20e3)[0x0];return _0x3c1c25['includes'](_0x432696);}catch(_0x1d5a33){return![];}}function getOperatorValue(_0x14d6e6){var _0x3643bb=JSON[_0x2f07('0x3')](_0x14d6e6);var _0x235418=Object[_0x2f07('0x4')](_0x3643bb)[0x0];var _0x33b99c=_0x3643bb[_0x235418];return{['$'+_0x235418]:_0x33b99c};}exports[_0x2f07('0x5')]=function(_0x4746c2){var _0x2e167=null;if(_0x4746c2){_0x2e167=_0x4746c2[_0x2f07('0x6')](',');}return _0x2e167;};exports[_0x2f07('0x7')]=function(_0x1a3848,_0x18fe13){var _0x14e237={};if(!_['isEmpty'](_0x1a3848)){_[_0x2f07('0x8')](_0x1a3848,function(_0x2f464b,_0x1d0812){try{if(_0x18fe13){var _0x3525be=_['find'](_0x18fe13,{'name':_0x1d0812})||{};if(hasSequelizeOperator(_0x2f464b)){_0x14e237[_0x1d0812]=getOperatorValue(_0x2f464b);}else if(_0x3525be['type']===_0x2f07('0x9')&&_[_0x2f07('0xa')](_0x2f464b)){var _0x58549c=JSON[_0x2f07('0x3')](_0x2f464b);var _0x34dbd4={'$gte':moment(moment(_0x58549c[_0x2f07('0xb')])['format'](_0x2f07('0xc')))[_0x2f07('0xd')]()[_0x2f07('0xe')](),'$lte':moment(moment(_0x58549c[_0x2f07('0xf')])[_0x2f07('0xe')](_0x2f07('0xc')))['utc']()[_0x2f07('0x10')](0x1,'s')['format']()};_0x14e237[_0x1d0812]=_0x34dbd4;}else if(_0x3525be[_0x2f07('0x11')]===_0x2f07('0x12')){_0x14e237[_0x1d0812]=_0x2f464b;}else{_0x14e237[_0x1d0812]=_[_0x2f07('0x13')](_0x2f464b)?_0x2f464b:JSON[_0x2f07('0x3')](_0x2f464b);}}else{_0x14e237[_0x1d0812]=_[_0x2f07('0x13')](_0x2f464b)?_0x2f464b:JSON[_0x2f07('0x3')](_0x2f464b);}}catch(_0x1a6135){_0x14e237[_0x1d0812]=_0x2f464b[_0x2f07('0x6')](',');}});}return _0x14e237;};exports['limit']=function(_0x15c3dd){_0x15c3dd=parseInt(_0x15c3dd,0xa);if(!_0x15c3dd||_0x15c3dd<0x0){_0x15c3dd=LIMIT_VALUE;}return _0x15c3dd;};exports['offset']=function(_0x3cd3c0){_0x3cd3c0=parseInt(_0x3cd3c0,0xa);if(!_0x3cd3c0||_0x3cd3c0<0x0){_0x3cd3c0=0x0;}return _0x3cd3c0;};exports[_0x2f07('0x14')]=function(_0x119b68){var _0xd944d6,_0x2ef47d=null;if(_0x119b68){_0xd944d6=_0x119b68['split'](',');_0x2ef47d=_[_0x2f07('0x15')](_0xd944d6,function(_0x5a0146){if(_0x5a0146['indexOf']('-')===0x0){return[_0x5a0146==='priority'?sequelize[_0x2f07('0x16')](sequelize['col'](_0x2f07('0x17')),'unsigned'):_0x5a0146[_0x2f07('0x18')](0x1),_0x2f07('0x19')];}else{return[_0x5a0146===_0x2f07('0x17')?sequelize[_0x2f07('0x16')](sequelize['col'](_0x2f07('0x17')),_0x2f07('0x1a')):_0x5a0146,_0x2f07('0x1b')];}});}return _0x2ef47d;};exports['omit']=function(_0x111376,_0x113916){if(_['isEmpty'](_0x111376)){return _0x111376;}if(_[_0x2f07('0x13')](_0x111376)){for(var _0x1c9ca1=0x0;_0x1c9ca1<_0x111376['length'];_0x1c9ca1+=0x1){_0x111376[_0x1c9ca1]=this[_0x2f07('0x1c')](_0x111376[_0x1c9ca1],_0x113916);}return _0x111376;}if(!_['isObject'](_0x111376)){return _0x111376;}if(_[_0x2f07('0x1d')](_0x113916)){_0x113916=[_0x113916];}if(!_[_0x2f07('0x13')](_0x113916)){return _0x111376;}for(var _0x27bd72=0x0;_0x27bd72<_0x113916[_0x2f07('0x1e')];_0x27bd72+=0x1){_[_0x2f07('0x1f')](_0x111376,_0x113916[_0x27bd72]);}for(var _0x139ea8 in _0x111376){if(_0x111376[_0x2f07('0x20')](_0x139ea8)){_0x111376[_0x139ea8]=this[_0x2f07('0x1c')](_0x111376[_0x139ea8],_0x113916);}}return _0x111376;};exports[_0x2f07('0x21')]=function(_0x468cd8){return _0x468cd8[_0x2f07('0x22')](RegExp(_0x2f07('0x23')))?!![]:![];};exports['isEmail']=function(_0x1accef){return _0x1accef[_0x2f07('0x22')](/^\S+@\S+$/)?!![]:![];};exports[_0x2f07('0x24')]=function(_0x571839){var _0x36d4b8=[];_0x571839[_0x2f07('0x6')](/[ ,]+/)[_0x2f07('0x25')](function(_0x5ad0de){_0x5ad0de=_0x5ad0de[_0x2f07('0x26')](/([^:]")"+/g,'$1');_0x5ad0de='+'+_0x5ad0de+'*';var _0x368e3d=/[ `!@#$%^&*()_\-?~]/;if(_0x5ad0de[_0x2f07('0x22')](_0x368e3d))_0x5ad0de='\x22'+_0x5ad0de+'\x22';_0x36d4b8[_0x2f07('0x27')](_0x5ad0de);});return _0x36d4b8[_0x2f07('0x28')]('\x20');};exports[_0x2f07('0x29')]=function(_0x3fed73,_0x5c7593,_0x1decd1){var _0x5b0407={},_0x3496eb={};if(_0x5c7593[_0x2f07('0x2a')][_0x2f07('0x2b')]){_0x5c7593[_0x2f07('0x2a')]['id']=_0x5c7593[_0x2f07('0x2a')][_0x2f07('0x2b')];delete _0x5c7593[_0x2f07('0x2a')][_0x2f07('0x2b')];}_0x5b0407[_0x2f07('0x2c')]=_[_0x2f07('0x15')](_0x3fed73,_0x2f07('0x11'));_0x5b0407[_0x2f07('0x2a')]=_[_0x2f07('0x4')](_0x5c7593[_0x2f07('0x2a')]);_0x5b0407[_0x2f07('0x7')]=_[_0x2f07('0x2d')](_0x5b0407['model'],_0x5b0407['query']);_0x3496eb[_0x2f07('0x2e')]=_[_0x2f07('0x2d')](_0x5b0407[_0x2f07('0x2c')],this['fields'](_0x5c7593['query'][_0x2f07('0x5')]));_0x3496eb['attributes']=_0x3496eb[_0x2f07('0x2e')][_0x2f07('0x1e')]?_0x3496eb[_0x2f07('0x2e')]:_0x5b0407[_0x2f07('0x2c')];if(!_0x5c7593[_0x2f07('0x2a')]['hasOwnProperty'](_0x2f07('0x2f'))){_0x3496eb['limit']=this[_0x2f07('0x30')](_0x5c7593['query'][_0x2f07('0x30')]);_0x3496eb['offset']=this['offset'](_0x5c7593[_0x2f07('0x2a')][_0x2f07('0x31')]);}_0x3496eb['order']=this[_0x2f07('0x14')](_0x5c7593[_0x2f07('0x2a')][_0x2f07('0x14')]);_0x3496eb['where']=this[_0x2f07('0x7')](_[_0x2f07('0x32')](_0x5c7593[_0x2f07('0x2a')],_0x5b0407[_0x2f07('0x7')]),_0x3fed73);if(_0x5c7593[_0x2f07('0x2a')][_0x2f07('0x33')]){var _0x1a0ef2=_0x3fed73;var _0x1a9645=_0x5c7593['query'][_0x2f07('0x33')];if(typeof _0x1a9645===_0x2f07('0x34')){_0x1a0ef2=_[_0x2f07('0x33')](_0x3fed73,function(_0x3f1b6b){return _[_0x2f07('0x35')](_0x1a9645[_0x2f07('0x36')],_0x3f1b6b[_0x2f07('0x11')]);});_0x1a9645=_0x1a9645['value'];}_0x3496eb[_0x2f07('0x37')]=_[_0x2f07('0x38')](_0x3496eb[_0x2f07('0x37')],{'$or':_[_0x2f07('0x15')](_0x1a0ef2,function(_0x3db7ad){if(_0x3db7ad[_0x2f07('0x39')]!=='VIRTUAL'){if(_0x1decd1){return sequelize[_0x2f07('0x37')](sequelize['fn'](_0x2f07('0x3a'),sequelize[_0x2f07('0x3b')](_0x3db7ad[_0x2f07('0x11')])),{'$like':sequelize['fn']('lower','%'+_0x5c7593['query'][_0x2f07('0x33')]+'%')});}else{var _0x437e94={};_0x437e94[_0x3db7ad[_0x2f07('0x11')]]={'$like':'%'+_0x5c7593[_0x2f07('0x2a')]['filter']+'%'};return _0x437e94;}}})});}_0x3496eb=_[_0x2f07('0x38')]({},_0x3496eb,_0x5c7593[_0x2f07('0x3c')]);return _0x3496eb;};