Built motion from commit ab870f9e.|2.5.44
[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 _0xf494=['DATE','isPlainObject','$gte','format','YYYY-MM-DD','utc','name','uniqueid','isArray','sort','map','indexOf','priority','col','unsigned','DESC','cast','length','isObject','isString','unset','omit','isNumeric','^[+]?[0-9]*$','isEmail','replace','match','push','join','getOptions','query','$id','intersection','model','attributes','hasOwnProperty','nolimit','limit','offset','where','pick','filter','object','columns','value','type','lower','options','lodash','sequelize','moment','parse','keys','includes','fields','split','filters','forOwn'];(function(_0x44a4c4,_0x440b0c){var _0x47adb8=function(_0xd43d22){while(--_0xd43d22){_0x44a4c4['push'](_0x44a4c4['shift']());}};_0x47adb8(++_0x440b0c);}(_0xf494,0x1c6));var _0x4f49=function(_0x1a2d5e,_0x4c16fe){_0x1a2d5e=_0x1a2d5e-0x0;var _0x19a8bd=_0xf494[_0x1a2d5e];return _0x19a8bd;};'use strict';var _=require(_0x4f49('0x0'));var sequelize=require(_0x4f49('0x1'));var moment=require(_0x4f49('0x2'));var LIMIT_VALUE=0xfa;function hasSequelizeOperator(_0x52d22c){var _0x3aeeb8=['ne'];try{var _0x1d54cc=JSON[_0x4f49('0x3')](_0x52d22c);var _0x25677c=Object[_0x4f49('0x4')](_0x1d54cc)[0x0];return _0x3aeeb8[_0x4f49('0x5')](_0x25677c);}catch(_0x3267c1){return![];}}function getOperatorValue(_0x790e8b){var _0xc5e778=JSON[_0x4f49('0x3')](_0x790e8b);var _0x42b0e8=Object['keys'](_0xc5e778)[0x0];var _0x58e9a0=_0xc5e778[_0x42b0e8];return{['$'+_0x42b0e8]:_0x58e9a0};}exports[_0x4f49('0x6')]=function(_0x327bd5){var _0x31a725=null;if(_0x327bd5){_0x31a725=_0x327bd5[_0x4f49('0x7')](',');}return _0x31a725;};exports[_0x4f49('0x8')]=function(_0x174d0d,_0x151d8c){var _0x410884={};if(!_['isEmpty'](_0x174d0d)){_[_0x4f49('0x9')](_0x174d0d,function(_0x411759,_0x5bcfe5){try{if(_0x151d8c){var _0x15e7a1=_['find'](_0x151d8c,{'name':_0x5bcfe5})||{};if(hasSequelizeOperator(_0x411759)){_0x410884[_0x5bcfe5]=getOperatorValue(_0x411759);}else if(_0x15e7a1['type']===_0x4f49('0xa')&&_[_0x4f49('0xb')](_0x411759)){var _0x4bf89f=JSON[_0x4f49('0x3')](_0x411759);var _0x111a8b={'$gte':moment(moment(_0x4bf89f[_0x4f49('0xc')])[_0x4f49('0xd')](_0x4f49('0xe')))[_0x4f49('0xf')]()[_0x4f49('0xd')](),'$lte':moment(moment(_0x4bf89f['$lte'])[_0x4f49('0xd')](_0x4f49('0xe')))[_0x4f49('0xf')]()['subtract'](0x1,'s')['format']()};_0x410884[_0x5bcfe5]=_0x111a8b;}else if(_0x15e7a1[_0x4f49('0x10')]===_0x4f49('0x11')){_0x410884[_0x5bcfe5]=_0x411759;}else{_0x410884[_0x5bcfe5]=_[_0x4f49('0x12')](_0x411759)?_0x411759:JSON['parse'](_0x411759);}}else{_0x410884[_0x5bcfe5]=_[_0x4f49('0x12')](_0x411759)?_0x411759:JSON[_0x4f49('0x3')](_0x411759);}}catch(_0x4e85df){_0x410884[_0x5bcfe5]=_0x411759['split'](',');}});}return _0x410884;};exports['limit']=function(_0x560592){_0x560592=parseInt(_0x560592,0xa);if(!_0x560592||_0x560592<0x0){_0x560592=LIMIT_VALUE;}return _0x560592;};exports['offset']=function(_0xb2081a){_0xb2081a=parseInt(_0xb2081a,0xa);if(!_0xb2081a||_0xb2081a<0x0){_0xb2081a=0x0;}return _0xb2081a;};exports[_0x4f49('0x13')]=function(_0x1c2d70){var _0x407042,_0x5793ac=null;if(_0x1c2d70){_0x407042=_0x1c2d70[_0x4f49('0x7')](',');_0x5793ac=_[_0x4f49('0x14')](_0x407042,function(_0x197a49){if(_0x197a49[_0x4f49('0x15')]('-')===0x0){return[_0x197a49===_0x4f49('0x16')?sequelize['cast'](sequelize[_0x4f49('0x17')](_0x4f49('0x16')),_0x4f49('0x18')):_0x197a49['substr'](0x1),_0x4f49('0x19')];}else{return[_0x197a49===_0x4f49('0x16')?sequelize[_0x4f49('0x1a')](sequelize[_0x4f49('0x17')](_0x4f49('0x16')),_0x4f49('0x18')):_0x197a49,'ASC'];}});}return _0x5793ac;};exports['omit']=function(_0x3a947b,_0x429de7){if(_['isEmpty'](_0x3a947b)){return _0x3a947b;}if(_[_0x4f49('0x12')](_0x3a947b)){for(var _0x2c1519=0x0;_0x2c1519<_0x3a947b[_0x4f49('0x1b')];_0x2c1519+=0x1){_0x3a947b[_0x2c1519]=this['omit'](_0x3a947b[_0x2c1519],_0x429de7);}return _0x3a947b;}if(!_[_0x4f49('0x1c')](_0x3a947b)){return _0x3a947b;}if(_[_0x4f49('0x1d')](_0x429de7)){_0x429de7=[_0x429de7];}if(!_[_0x4f49('0x12')](_0x429de7)){return _0x3a947b;}for(var _0x148153=0x0;_0x148153<_0x429de7[_0x4f49('0x1b')];_0x148153+=0x1){_[_0x4f49('0x1e')](_0x3a947b,_0x429de7[_0x148153]);}for(var _0x4915af in _0x3a947b){if(_0x3a947b['hasOwnProperty'](_0x4915af)){_0x3a947b[_0x4915af]=this[_0x4f49('0x1f')](_0x3a947b[_0x4915af],_0x429de7);}}return _0x3a947b;};exports[_0x4f49('0x20')]=function(_0x605c91){return _0x605c91['match'](RegExp(_0x4f49('0x21')))?!![]:![];};exports[_0x4f49('0x22')]=function(_0x43d8e3){return _0x43d8e3['match'](/^\S+@\S+$/)?!![]:![];};exports['getFullTextValue']=function(_0x3e207f){var _0x27d004=[];_0x3e207f[_0x4f49('0x7')](/[ ,]+/)['forEach'](function(_0x1eaac6){_0x1eaac6=_0x1eaac6[_0x4f49('0x23')](/([^:]")"+/g,'$1');_0x1eaac6='+'+_0x1eaac6+'*';var _0x173657=/[ `!@#$%^&*()_\-?~]/;if(_0x1eaac6[_0x4f49('0x24')](_0x173657))_0x1eaac6='\x22'+_0x1eaac6+'\x22';_0x27d004[_0x4f49('0x25')](_0x1eaac6);});return _0x27d004[_0x4f49('0x26')]('\x20');};exports[_0x4f49('0x27')]=function(_0x45ae19,_0x1f38d3,_0x310ee2){var _0x2291d4={},_0xf65ac6={};if(_0x1f38d3[_0x4f49('0x28')][_0x4f49('0x29')]){_0x1f38d3[_0x4f49('0x28')]['id']=_0x1f38d3[_0x4f49('0x28')][_0x4f49('0x29')];delete _0x1f38d3[_0x4f49('0x28')][_0x4f49('0x29')];}_0x2291d4['model']=_[_0x4f49('0x14')](_0x45ae19,_0x4f49('0x10'));_0x2291d4[_0x4f49('0x28')]=_[_0x4f49('0x4')](_0x1f38d3[_0x4f49('0x28')]);_0x2291d4[_0x4f49('0x8')]=_[_0x4f49('0x2a')](_0x2291d4[_0x4f49('0x2b')],_0x2291d4[_0x4f49('0x28')]);_0xf65ac6[_0x4f49('0x2c')]=_[_0x4f49('0x2a')](_0x2291d4[_0x4f49('0x2b')],this[_0x4f49('0x6')](_0x1f38d3['query'][_0x4f49('0x6')]));_0xf65ac6[_0x4f49('0x2c')]=_0xf65ac6[_0x4f49('0x2c')][_0x4f49('0x1b')]?_0xf65ac6[_0x4f49('0x2c')]:_0x2291d4[_0x4f49('0x2b')];if(!_0x1f38d3[_0x4f49('0x28')][_0x4f49('0x2d')](_0x4f49('0x2e'))){_0xf65ac6[_0x4f49('0x2f')]=this[_0x4f49('0x2f')](_0x1f38d3[_0x4f49('0x28')][_0x4f49('0x2f')]);_0xf65ac6[_0x4f49('0x30')]=this['offset'](_0x1f38d3[_0x4f49('0x28')][_0x4f49('0x30')]);}_0xf65ac6['order']=this[_0x4f49('0x13')](_0x1f38d3[_0x4f49('0x28')]['sort']);_0xf65ac6[_0x4f49('0x31')]=this[_0x4f49('0x8')](_[_0x4f49('0x32')](_0x1f38d3[_0x4f49('0x28')],_0x2291d4[_0x4f49('0x8')]),_0x45ae19);if(_0x1f38d3[_0x4f49('0x28')][_0x4f49('0x33')]){var _0x5d464e=_0x45ae19;var _0x5e1461=_0x1f38d3['query'][_0x4f49('0x33')];if(typeof _0x5e1461===_0x4f49('0x34')){_0x5d464e=_[_0x4f49('0x33')](_0x45ae19,function(_0x373f90){return _[_0x4f49('0x5')](_0x5e1461[_0x4f49('0x35')],_0x373f90[_0x4f49('0x10')]);});_0x5e1461=_0x5e1461[_0x4f49('0x36')];}_0xf65ac6[_0x4f49('0x31')]=_['merge'](_0xf65ac6['where'],{'$or':_[_0x4f49('0x14')](_0x5d464e,function(_0x432b5d){if(_0x432b5d[_0x4f49('0x37')]!=='VIRTUAL'){if(_0x310ee2){return sequelize[_0x4f49('0x31')](sequelize['fn']('lower',sequelize['col'](_0x432b5d[_0x4f49('0x10')])),{'$like':sequelize['fn'](_0x4f49('0x38'),'%'+_0x1f38d3[_0x4f49('0x28')]['filter']+'%')});}else{var _0x287781={};_0x287781[_0x432b5d[_0x4f49('0x10')]]={'$like':'%'+_0x1f38d3['query'][_0x4f49('0x33')]+'%'};return _0x287781;}}})});}_0xf65ac6=_['merge']({},_0xf65ac6,_0x1f38d3[_0x4f49('0x39')]);return _0xf65ac6;};