Built motion from commit 00bf23f6.|2.6.16
[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 _0xd09e=['isObject','isString','unset','hasOwnProperty','isNumeric','match','getFullTextValue','\x22{EXPR}\x22','{EXPR}','forEach','replace','getOptions','query','$id','intersection','model','attributes','length','nolimit','order','sort','where','pick','filter','object','value','merge','type','VIRTUAL','lower','options','lodash','sequelize','keys','includes','parse','fields','filters','isEmpty','forOwn','find','DATE','isPlainObject','$gte','format','YYYY-MM-DD','utc','$lte','subtract','isArray','split','limit','offset','map','indexOf','priority','cast','substr','DESC','col','unsigned','ASC','omit'];(function(_0x161f59,_0x42e9ff){var _0x3ffa0e=function(_0x3aef14){while(--_0x3aef14){_0x161f59['push'](_0x161f59['shift']());}};_0x3ffa0e(++_0x42e9ff);}(_0xd09e,0xdc));var _0xed09=function(_0x1833a5,_0x166312){_0x1833a5=_0x1833a5-0x0;var _0x1385b5=_0xd09e[_0x1833a5];return _0x1385b5;};'use strict';var _=require(_0xed09('0x0'));var sequelize=require(_0xed09('0x1'));var moment=require('moment');var LIMIT_VALUE=0xfa;function hasSequelizeOperator(_0x1f0210){var _0x4c331b=['ne'];try{var _0x181ca4=JSON['parse'](_0x1f0210);var _0x51612b=Object[_0xed09('0x2')](_0x181ca4)[0x0];return _0x4c331b[_0xed09('0x3')](_0x51612b);}catch(_0x2226e5){return![];}}function getOperatorValue(_0x1e0b1e){var _0x27ba52=JSON[_0xed09('0x4')](_0x1e0b1e);var _0x3252ed=Object[_0xed09('0x2')](_0x27ba52)[0x0];var _0x1168fd=_0x27ba52[_0x3252ed];return{['$'+_0x3252ed]:_0x1168fd};}exports[_0xed09('0x5')]=function(_0x3bf636){var _0x10e243=null;if(_0x3bf636){_0x10e243=_0x3bf636['split'](',');}return _0x10e243;};exports[_0xed09('0x6')]=function(_0x47d757,_0x167c80){var _0x47ce53={};if(!_[_0xed09('0x7')](_0x47d757)){_[_0xed09('0x8')](_0x47d757,function(_0x300aa1,_0x5f466b){try{if(_0x167c80){var _0x57f78e=_[_0xed09('0x9')](_0x167c80,{'name':_0x5f466b})||{};if(hasSequelizeOperator(_0x300aa1)){_0x47ce53[_0x5f466b]=getOperatorValue(_0x300aa1);}else if(_0x57f78e['type']===_0xed09('0xa')&&_[_0xed09('0xb')](_0x300aa1)){var _0x92dbf1=JSON[_0xed09('0x4')](_0x300aa1);var _0x4bdd61={'$gte':moment(moment(_0x92dbf1[_0xed09('0xc')])[_0xed09('0xd')](_0xed09('0xe')))[_0xed09('0xf')]()['format'](),'$lte':moment(moment(_0x92dbf1[_0xed09('0x10')])[_0xed09('0xd')]('YYYY-MM-DD'))[_0xed09('0xf')]()[_0xed09('0x11')](0x1,'s')[_0xed09('0xd')]()};_0x47ce53[_0x5f466b]=_0x4bdd61;}else if(_0x57f78e['name']==='uniqueid'){_0x47ce53[_0x5f466b]=_0x300aa1;}else{_0x47ce53[_0x5f466b]=_[_0xed09('0x12')](_0x300aa1)?_0x300aa1:JSON[_0xed09('0x4')](_0x300aa1);}}else{_0x47ce53[_0x5f466b]=_[_0xed09('0x12')](_0x300aa1)?_0x300aa1:JSON[_0xed09('0x4')](_0x300aa1);}}catch(_0x15ab3e){_0x47ce53[_0x5f466b]=_0x300aa1[_0xed09('0x13')](',');}});}return _0x47ce53;};exports[_0xed09('0x14')]=function(_0x1feec7){_0x1feec7=parseInt(_0x1feec7,0xa);if(!_0x1feec7||_0x1feec7<0x0){_0x1feec7=LIMIT_VALUE;}return _0x1feec7;};exports[_0xed09('0x15')]=function(_0x19a566){_0x19a566=parseInt(_0x19a566,0xa);if(!_0x19a566||_0x19a566<0x0){_0x19a566=0x0;}return _0x19a566;};exports['sort']=function(_0x4afd63){var _0x3899b5,_0x637368=null;if(_0x4afd63){_0x3899b5=_0x4afd63[_0xed09('0x13')](',');_0x637368=_[_0xed09('0x16')](_0x3899b5,function(_0xad5b5){if(_0xad5b5[_0xed09('0x17')]('-')===0x0){return[_0xad5b5===_0xed09('0x18')?sequelize[_0xed09('0x19')](sequelize['col']('priority'),'unsigned'):_0xad5b5[_0xed09('0x1a')](0x1),_0xed09('0x1b')];}else{return[_0xad5b5===_0xed09('0x18')?sequelize[_0xed09('0x19')](sequelize[_0xed09('0x1c')](_0xed09('0x18')),_0xed09('0x1d')):_0xad5b5,_0xed09('0x1e')];}});}return _0x637368;};exports[_0xed09('0x1f')]=function(_0x3fcb42,_0x514e9e){if(_[_0xed09('0x7')](_0x3fcb42)){return _0x3fcb42;}if(_[_0xed09('0x12')](_0x3fcb42)){for(var _0x28f647=0x0;_0x28f647<_0x3fcb42['length'];_0x28f647+=0x1){_0x3fcb42[_0x28f647]=this[_0xed09('0x1f')](_0x3fcb42[_0x28f647],_0x514e9e);}return _0x3fcb42;}if(!_[_0xed09('0x20')](_0x3fcb42)){return _0x3fcb42;}if(_[_0xed09('0x21')](_0x514e9e)){_0x514e9e=[_0x514e9e];}if(!_['isArray'](_0x514e9e)){return _0x3fcb42;}for(var _0x1626aa=0x0;_0x1626aa<_0x514e9e['length'];_0x1626aa+=0x1){_[_0xed09('0x22')](_0x3fcb42,_0x514e9e[_0x1626aa]);}for(var _0x1329df in _0x3fcb42){if(_0x3fcb42[_0xed09('0x23')](_0x1329df)){_0x3fcb42[_0x1329df]=this[_0xed09('0x1f')](_0x3fcb42[_0x1329df],_0x514e9e);}}return _0x3fcb42;};exports[_0xed09('0x24')]=function(_0xe02db7){return _0xe02db7[_0xed09('0x25')](RegExp('^[+]?[0-9]*$'))?!![]:![];};exports['isEmail']=function(_0x585ec7){return _0x585ec7['match'](/^\S+@\S+$/)?!![]:![];};exports[_0xed09('0x26')]=function(_0xaea332,_0x1c05d0){var _0x42e4fd=[];var _0x3648bc=/[ `!@#$%^&*()_\-?~]/;var _0x1923de=_0x1c05d0?_0xed09('0x27'):_0xed09('0x28');_0xaea332[_0xed09('0x13')](/[ ,]+/)[_0xed09('0x29')](function(_0x4a6d45){_0x4a6d45=_0x4a6d45[_0xed09('0x2a')](/([^:]")"+/g,'$1');_0x4a6d45='+'+_0x4a6d45+'*';var _0x348331=_0x4a6d45[_0xed09('0x25')](_0x3648bc);if(_0x348331){_0x4a6d45='\x22'+_0x4a6d45+'\x22';}_0x42e4fd['push'](_0x4a6d45);});_0x1923de=_0x1923de[_0xed09('0x2a')](_0xed09('0x28'),_0x42e4fd['join']('\x20'));return _0x1923de;};exports[_0xed09('0x2b')]=function(_0x55008d,_0x3f5221,_0x2fcc92){var _0x49021a={},_0x45a7be={};if(_0x3f5221[_0xed09('0x2c')][_0xed09('0x2d')]){_0x3f5221[_0xed09('0x2c')]['id']=_0x3f5221['query'][_0xed09('0x2d')];delete _0x3f5221[_0xed09('0x2c')][_0xed09('0x2d')];}_0x49021a['model']=_[_0xed09('0x16')](_0x55008d,'name');_0x49021a['query']=_[_0xed09('0x2')](_0x3f5221['query']);_0x49021a['filters']=_[_0xed09('0x2e')](_0x49021a[_0xed09('0x2f')],_0x49021a['query']);_0x45a7be[_0xed09('0x30')]=_[_0xed09('0x2e')](_0x49021a[_0xed09('0x2f')],this[_0xed09('0x5')](_0x3f5221[_0xed09('0x2c')][_0xed09('0x5')]));_0x45a7be[_0xed09('0x30')]=_0x45a7be['attributes'][_0xed09('0x31')]?_0x45a7be[_0xed09('0x30')]:_0x49021a[_0xed09('0x2f')];if(!_0x3f5221[_0xed09('0x2c')][_0xed09('0x23')](_0xed09('0x32'))){_0x45a7be[_0xed09('0x14')]=this['limit'](_0x3f5221[_0xed09('0x2c')][_0xed09('0x14')]);_0x45a7be['offset']=this['offset'](_0x3f5221['query'][_0xed09('0x15')]);}_0x45a7be[_0xed09('0x33')]=this['sort'](_0x3f5221[_0xed09('0x2c')][_0xed09('0x34')]);_0x45a7be[_0xed09('0x35')]=this['filters'](_[_0xed09('0x36')](_0x3f5221[_0xed09('0x2c')],_0x49021a[_0xed09('0x6')]),_0x55008d);if(_0x3f5221[_0xed09('0x2c')]['filter']){var _0x54d335=_0x55008d;var _0xbe1831=_0x3f5221['query'][_0xed09('0x37')];if(typeof _0xbe1831===_0xed09('0x38')){_0x54d335=_[_0xed09('0x37')](_0x55008d,function(_0x241f76){return _[_0xed09('0x3')](_0xbe1831['columns'],_0x241f76['name']);});_0xbe1831=_0xbe1831[_0xed09('0x39')];}_0x45a7be[_0xed09('0x35')]=_[_0xed09('0x3a')](_0x45a7be[_0xed09('0x35')],{'$or':_[_0xed09('0x16')](_0x54d335,function(_0x75113){if(_0x75113[_0xed09('0x3b')]!==_0xed09('0x3c')){if(_0x2fcc92){return sequelize['where'](sequelize['fn'](_0xed09('0x3d'),sequelize[_0xed09('0x1c')](_0x75113['name'])),{'$like':sequelize['fn'](_0xed09('0x3d'),'%'+_0x3f5221['query']['filter']+'%')});}else{var _0x5778aa={};_0x5778aa[_0x75113['name']]={'$like':'%'+_0x3f5221['query'][_0xed09('0x37')]+'%'};return _0x5778aa;}}})});}_0x45a7be=_['merge']({},_0x45a7be,_0x3f5221[_0xed09('0x3e')]);return _0x45a7be;};