4cf09a8b9dcc7fb3d48e0511e0e1953bbca0b19a
[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 _0x5334=['value','merge','lower','options','lodash','sequelize','moment','parse','keys','includes','fields','split','filters','isEmpty','forOwn','find','DATE','isPlainObject','$gte','format','YYYY-MM-DD','utc','$lte','subtract','name','uniqueid','isArray','sort','map','indexOf','priority','cast','col','unsigned','substr','DESC','omit','length','isObject','isString','hasOwnProperty','isNumeric','match','^[+]?[0-9]*$','isEmail','getFullTextValue','forEach','replace','push','getOptions','query','$id','model','intersection','attributes','nolimit','limit','offset','order','where','pick','filter','object','columns'];(function(_0x2ccc05,_0x345621){var _0x2d0ff8=function(_0x285b5d){while(--_0x285b5d){_0x2ccc05['push'](_0x2ccc05['shift']());}};_0x2d0ff8(++_0x345621);}(_0x5334,0x84));var _0x4533=function(_0x459ce9,_0x512b3d){_0x459ce9=_0x459ce9-0x0;var _0x183b79=_0x5334[_0x459ce9];return _0x183b79;};'use strict';var _=require(_0x4533('0x0'));var sequelize=require(_0x4533('0x1'));var moment=require(_0x4533('0x2'));var LIMIT_VALUE=0xfa;function hasSequelizeOperator(_0x35fb80){var _0x39af56=['ne'];try{var _0x52b768=JSON[_0x4533('0x3')](_0x35fb80);var _0x5176b5=Object[_0x4533('0x4')](_0x52b768)[0x0];return _0x39af56[_0x4533('0x5')](_0x5176b5);}catch(_0x5cbca4){return![];}}function getOperatorValue(_0x4a576a){var _0x51b4ce=JSON[_0x4533('0x3')](_0x4a576a);var _0x4dea06=Object['keys'](_0x51b4ce)[0x0];var _0x487906=_0x51b4ce[_0x4dea06];return{['$'+_0x4dea06]:_0x487906};}exports[_0x4533('0x6')]=function(_0x42f94b){var _0x300877=null;if(_0x42f94b){_0x300877=_0x42f94b[_0x4533('0x7')](',');}return _0x300877;};exports[_0x4533('0x8')]=function(_0x21b22f,_0xd417){var _0x4fdbda={};if(!_[_0x4533('0x9')](_0x21b22f)){_[_0x4533('0xa')](_0x21b22f,function(_0x1b52ee,_0x12131a){try{if(_0xd417){var _0x5465bf=_[_0x4533('0xb')](_0xd417,{'name':_0x12131a})||{};if(hasSequelizeOperator(_0x1b52ee)){_0x4fdbda[_0x12131a]=getOperatorValue(_0x1b52ee);}else if(_0x5465bf['type']===_0x4533('0xc')&&_[_0x4533('0xd')](_0x1b52ee)){var _0x45ba67=JSON[_0x4533('0x3')](_0x1b52ee);var _0x57ff74={'$gte':moment(moment(_0x45ba67[_0x4533('0xe')])[_0x4533('0xf')](_0x4533('0x10')))[_0x4533('0x11')]()['format'](),'$lte':moment(moment(_0x45ba67[_0x4533('0x12')])['format']('YYYY-MM-DD'))[_0x4533('0x11')]()[_0x4533('0x13')](0x1,'s')['format']()};_0x4fdbda[_0x12131a]=_0x57ff74;}else if(_0x5465bf[_0x4533('0x14')]===_0x4533('0x15')){_0x4fdbda[_0x12131a]=_0x1b52ee;}else{_0x4fdbda[_0x12131a]=_[_0x4533('0x16')](_0x1b52ee)?_0x1b52ee:JSON['parse'](_0x1b52ee);}}else{_0x4fdbda[_0x12131a]=_[_0x4533('0x16')](_0x1b52ee)?_0x1b52ee:JSON['parse'](_0x1b52ee);}}catch(_0x3ddb36){_0x4fdbda[_0x12131a]=_0x1b52ee[_0x4533('0x7')](',');}});}return _0x4fdbda;};exports['limit']=function(_0xd10c6a){_0xd10c6a=parseInt(_0xd10c6a,0xa);if(!_0xd10c6a||_0xd10c6a<0x0){_0xd10c6a=LIMIT_VALUE;}return _0xd10c6a;};exports['offset']=function(_0x5c2c9c){_0x5c2c9c=parseInt(_0x5c2c9c,0xa);if(!_0x5c2c9c||_0x5c2c9c<0x0){_0x5c2c9c=0x0;}return _0x5c2c9c;};exports[_0x4533('0x17')]=function(_0x9740a6){var _0x49fb91,_0x53fe43=null;if(_0x9740a6){_0x49fb91=_0x9740a6[_0x4533('0x7')](',');_0x53fe43=_[_0x4533('0x18')](_0x49fb91,function(_0x3467ba){if(_0x3467ba[_0x4533('0x19')]('-')===0x0){return[_0x3467ba===_0x4533('0x1a')?sequelize[_0x4533('0x1b')](sequelize[_0x4533('0x1c')]('priority'),_0x4533('0x1d')):_0x3467ba[_0x4533('0x1e')](0x1),_0x4533('0x1f')];}else{return[_0x3467ba==='priority'?sequelize['cast'](sequelize[_0x4533('0x1c')](_0x4533('0x1a')),'unsigned'):_0x3467ba,'ASC'];}});}return _0x53fe43;};exports[_0x4533('0x20')]=function(_0x1fa8be,_0xfd9409){if(_['isEmpty'](_0x1fa8be)){return _0x1fa8be;}if(_[_0x4533('0x16')](_0x1fa8be)){for(var _0x39b261=0x0;_0x39b261<_0x1fa8be[_0x4533('0x21')];_0x39b261+=0x1){_0x1fa8be[_0x39b261]=this[_0x4533('0x20')](_0x1fa8be[_0x39b261],_0xfd9409);}return _0x1fa8be;}if(!_[_0x4533('0x22')](_0x1fa8be)){return _0x1fa8be;}if(_[_0x4533('0x23')](_0xfd9409)){_0xfd9409=[_0xfd9409];}if(!_[_0x4533('0x16')](_0xfd9409)){return _0x1fa8be;}for(var _0x27b653=0x0;_0x27b653<_0xfd9409[_0x4533('0x21')];_0x27b653+=0x1){_['unset'](_0x1fa8be,_0xfd9409[_0x27b653]);}for(var _0x5c1e24 in _0x1fa8be){if(_0x1fa8be[_0x4533('0x24')](_0x5c1e24)){_0x1fa8be[_0x5c1e24]=this['omit'](_0x1fa8be[_0x5c1e24],_0xfd9409);}}return _0x1fa8be;};exports[_0x4533('0x25')]=function(_0x4e2b80){return _0x4e2b80[_0x4533('0x26')](RegExp(_0x4533('0x27')))?!![]:![];};exports[_0x4533('0x28')]=function(_0x4300c1){return _0x4300c1[_0x4533('0x26')](/^\S+@\S+$/)?!![]:![];};exports[_0x4533('0x29')]=function(_0xe584a2){var _0xa58dd1=[];_0xe584a2[_0x4533('0x7')](/[ ,]+/)[_0x4533('0x2a')](function(_0x728791){_0x728791=_0x728791[_0x4533('0x2b')](/([^:]")"+/g,'$1');_0x728791='+'+_0x728791+'*';var _0x7fc887=/[ `!@#$%^&*()_\-?~]/;if(_0x728791['match'](_0x7fc887))_0x728791='\x22'+_0x728791+'\x22';_0xa58dd1[_0x4533('0x2c')](_0x728791);});return _0xa58dd1['join']('\x20');};exports[_0x4533('0x2d')]=function(_0x3f7720,_0xb7f0b1,_0x3b89f0){var _0x24acf5={},_0x6d58aa={};if(_0xb7f0b1[_0x4533('0x2e')][_0x4533('0x2f')]){_0xb7f0b1[_0x4533('0x2e')]['id']=_0xb7f0b1[_0x4533('0x2e')][_0x4533('0x2f')];delete _0xb7f0b1[_0x4533('0x2e')]['$id'];}_0x24acf5[_0x4533('0x30')]=_[_0x4533('0x18')](_0x3f7720,_0x4533('0x14'));_0x24acf5[_0x4533('0x2e')]=_[_0x4533('0x4')](_0xb7f0b1['query']);_0x24acf5[_0x4533('0x8')]=_[_0x4533('0x31')](_0x24acf5[_0x4533('0x30')],_0x24acf5[_0x4533('0x2e')]);_0x6d58aa[_0x4533('0x32')]=_[_0x4533('0x31')](_0x24acf5['model'],this[_0x4533('0x6')](_0xb7f0b1[_0x4533('0x2e')]['fields']));_0x6d58aa[_0x4533('0x32')]=_0x6d58aa[_0x4533('0x32')][_0x4533('0x21')]?_0x6d58aa[_0x4533('0x32')]:_0x24acf5[_0x4533('0x30')];if(!_0xb7f0b1[_0x4533('0x2e')][_0x4533('0x24')](_0x4533('0x33'))){_0x6d58aa[_0x4533('0x34')]=this[_0x4533('0x34')](_0xb7f0b1['query'][_0x4533('0x34')]);_0x6d58aa[_0x4533('0x35')]=this[_0x4533('0x35')](_0xb7f0b1[_0x4533('0x2e')][_0x4533('0x35')]);}_0x6d58aa[_0x4533('0x36')]=this[_0x4533('0x17')](_0xb7f0b1[_0x4533('0x2e')][_0x4533('0x17')]);_0x6d58aa[_0x4533('0x37')]=this[_0x4533('0x8')](_[_0x4533('0x38')](_0xb7f0b1['query'],_0x24acf5['filters']),_0x3f7720);if(_0xb7f0b1[_0x4533('0x2e')]['filter']){var _0x4260e6=_0x3f7720;var _0x97aa9e=_0xb7f0b1[_0x4533('0x2e')][_0x4533('0x39')];if(typeof _0x97aa9e===_0x4533('0x3a')){_0x4260e6=_[_0x4533('0x39')](_0x3f7720,function(_0x2df795){return _[_0x4533('0x5')](_0x97aa9e[_0x4533('0x3b')],_0x2df795[_0x4533('0x14')]);});_0x97aa9e=_0x97aa9e[_0x4533('0x3c')];}_0x6d58aa[_0x4533('0x37')]=_[_0x4533('0x3d')](_0x6d58aa['where'],{'$or':_[_0x4533('0x18')](_0x4260e6,function(_0x556dd9){if(_0x556dd9['type']!=='VIRTUAL'){if(_0x3b89f0){return sequelize['where'](sequelize['fn'](_0x4533('0x3e'),sequelize[_0x4533('0x1c')](_0x556dd9[_0x4533('0x14')])),{'$like':sequelize['fn'](_0x4533('0x3e'),'%'+_0xb7f0b1['query'][_0x4533('0x39')]+'%')});}else{var _0x369284={};_0x369284[_0x556dd9[_0x4533('0x14')]]={'$like':'%'+_0xb7f0b1[_0x4533('0x2e')][_0x4533('0x39')]+'%'};return _0x369284;}}})});}_0x6d58aa=_[_0x4533('0x3d')]({},_0x6d58aa,_0xb7f0b1[_0x4533('0x3f')]);return _0x6d58aa;};