882a3a7489f9a7246cf1e478d1d1737f2376d03a
[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 _0x832f=['^[+]?[0-9]*$','isEmail','getFullTextValue','split','forEach','push','query','$id','model','intersection','attributes','length','nolimit','order','where','filters','pick','merge','col','filter','lodash','moment','keys','includes','parse','fields','isEmpty','find','type','DATE','isPlainObject','$gte','format','YYYY-MM-DD','utc','subtract','name','uniqueid','isArray','limit','offset','sort','map','indexOf','priority','cast','unsigned','ASC','omit','isObject','isString','hasOwnProperty','isNumeric','match'];(function(_0x2a6501,_0x9c5a0e){var _0x34d3ae=function(_0x204c8b){while(--_0x204c8b){_0x2a6501['push'](_0x2a6501['shift']());}};_0x34d3ae(++_0x9c5a0e);}(_0x832f,0xb6));var _0xf832=function(_0x4327fe,_0x4f8040){_0x4327fe=_0x4327fe-0x0;var _0x138651=_0x832f[_0x4327fe];return _0x138651;};'use strict';var _=require(_0xf832('0x0'));var sequelize=require('sequelize');var moment=require(_0xf832('0x1'));var LIMIT_VALUE=0xfa;function hasSequelizeOperator(_0x41330f){var _0xc433b7=['ne'];try{var _0x1c8595=JSON['parse'](_0x41330f);var _0x2766d5=Object[_0xf832('0x2')](_0x1c8595)[0x0];return _0xc433b7[_0xf832('0x3')](_0x2766d5);}catch(_0x413029){return![];}}function getOperatorValue(_0x4266f8){var _0x151794=JSON[_0xf832('0x4')](_0x4266f8);var _0x3b7153=Object[_0xf832('0x2')](_0x151794)[0x0];var _0xe001bd=_0x151794[_0x3b7153];return{['$'+_0x3b7153]:_0xe001bd};}exports[_0xf832('0x5')]=function(_0x1aab83){var _0x2ee5dd=null;if(_0x1aab83){_0x2ee5dd=_0x1aab83['split'](',');}return _0x2ee5dd;};exports['filters']=function(_0x112fdb,_0x1b2248){var _0x90eab2={};if(!_[_0xf832('0x6')](_0x112fdb)){_['forOwn'](_0x112fdb,function(_0x40c5d3,_0x195a84){try{if(_0x1b2248){var _0x5ef394=_[_0xf832('0x7')](_0x1b2248,{'name':_0x195a84})||{};if(hasSequelizeOperator(_0x40c5d3)){_0x90eab2[_0x195a84]=getOperatorValue(_0x40c5d3);}else if(_0x5ef394[_0xf832('0x8')]===_0xf832('0x9')&&_[_0xf832('0xa')](_0x40c5d3)){var _0x5b391a=JSON[_0xf832('0x4')](_0x40c5d3);var _0x4255c5={'$gte':moment(moment(_0x5b391a[_0xf832('0xb')])[_0xf832('0xc')](_0xf832('0xd')))[_0xf832('0xe')]()['format'](),'$lte':moment(moment(_0x5b391a['$lte'])[_0xf832('0xc')]('YYYY-MM-DD'))[_0xf832('0xe')]()[_0xf832('0xf')](0x1,'s')[_0xf832('0xc')]()};_0x90eab2[_0x195a84]=_0x4255c5;}else if(_0x5ef394[_0xf832('0x10')]===_0xf832('0x11')){_0x90eab2[_0x195a84]=_0x40c5d3;}else{_0x90eab2[_0x195a84]=_[_0xf832('0x12')](_0x40c5d3)?_0x40c5d3:JSON[_0xf832('0x4')](_0x40c5d3);}}else{_0x90eab2[_0x195a84]=_['isArray'](_0x40c5d3)?_0x40c5d3:JSON[_0xf832('0x4')](_0x40c5d3);}}catch(_0x507148){_0x90eab2[_0x195a84]=_0x40c5d3['split'](',');}});}return _0x90eab2;};exports[_0xf832('0x13')]=function(_0x4c2a73){_0x4c2a73=parseInt(_0x4c2a73,0xa);if(!_0x4c2a73||_0x4c2a73<0x0){_0x4c2a73=LIMIT_VALUE;}return _0x4c2a73;};exports[_0xf832('0x14')]=function(_0x4ee01e){_0x4ee01e=parseInt(_0x4ee01e,0xa);if(!_0x4ee01e||_0x4ee01e<0x0){_0x4ee01e=0x0;}return _0x4ee01e;};exports[_0xf832('0x15')]=function(_0x4f3d5d){var _0x34d2d3,_0x8a08c7=null;if(_0x4f3d5d){_0x34d2d3=_0x4f3d5d['split'](',');_0x8a08c7=_[_0xf832('0x16')](_0x34d2d3,function(_0x47be7a){if(_0x47be7a[_0xf832('0x17')]('-')===0x0){return[_0x47be7a===_0xf832('0x18')?sequelize[_0xf832('0x19')](sequelize['col'](_0xf832('0x18')),_0xf832('0x1a')):_0x47be7a['substr'](0x1),'DESC'];}else{return[_0x47be7a===_0xf832('0x18')?sequelize['cast'](sequelize['col']('priority'),'unsigned'):_0x47be7a,_0xf832('0x1b')];}});}return _0x8a08c7;};exports[_0xf832('0x1c')]=function(_0x2047d1,_0x1b03b1){if(_[_0xf832('0x6')](_0x2047d1)){return _0x2047d1;}if(_[_0xf832('0x12')](_0x2047d1)){for(var _0x4f91de=0x0;_0x4f91de<_0x2047d1['length'];_0x4f91de+=0x1){_0x2047d1[_0x4f91de]=this['omit'](_0x2047d1[_0x4f91de],_0x1b03b1);}return _0x2047d1;}if(!_[_0xf832('0x1d')](_0x2047d1)){return _0x2047d1;}if(_[_0xf832('0x1e')](_0x1b03b1)){_0x1b03b1=[_0x1b03b1];}if(!_[_0xf832('0x12')](_0x1b03b1)){return _0x2047d1;}for(var _0x52af07=0x0;_0x52af07<_0x1b03b1['length'];_0x52af07+=0x1){_['unset'](_0x2047d1,_0x1b03b1[_0x52af07]);}for(var _0x41c307 in _0x2047d1){if(_0x2047d1[_0xf832('0x1f')](_0x41c307)){_0x2047d1[_0x41c307]=this[_0xf832('0x1c')](_0x2047d1[_0x41c307],_0x1b03b1);}}return _0x2047d1;};exports[_0xf832('0x20')]=function(_0x198bfa){return _0x198bfa[_0xf832('0x21')](RegExp(_0xf832('0x22')))?!![]:![];};exports[_0xf832('0x23')]=function(_0x348eec){return _0x348eec[_0xf832('0x21')](/^\S+@\S+$/)?!![]:![];};exports[_0xf832('0x24')]=function(_0x54f3b6){var _0x3b7dbf=[];_0x54f3b6[_0xf832('0x25')](/[ ,]+/)[_0xf832('0x26')](function(_0x476bbc){_0x476bbc=_0x476bbc['replace'](/([^:]")"+/g,'$1');_0x476bbc='+'+_0x476bbc+'*';if(_0x476bbc[_0xf832('0x3')]('@'))_0x476bbc='\x22'+_0x476bbc+'\x22';_0x3b7dbf[_0xf832('0x27')](_0x476bbc);});return _0x3b7dbf['join']('\x20');};exports['getOptions']=function(_0x787012,_0x430e5e,_0x40e370){var _0x3e649e={},_0x4c8d33={};if(_0x430e5e[_0xf832('0x28')][_0xf832('0x29')]){_0x430e5e[_0xf832('0x28')]['id']=_0x430e5e['query']['$id'];delete _0x430e5e['query'][_0xf832('0x29')];}_0x3e649e[_0xf832('0x2a')]=_[_0xf832('0x16')](_0x787012,_0xf832('0x10'));_0x3e649e[_0xf832('0x28')]=_[_0xf832('0x2')](_0x430e5e[_0xf832('0x28')]);_0x3e649e['filters']=_['intersection'](_0x3e649e[_0xf832('0x2a')],_0x3e649e[_0xf832('0x28')]);_0x4c8d33['attributes']=_[_0xf832('0x2b')](_0x3e649e[_0xf832('0x2a')],this[_0xf832('0x5')](_0x430e5e['query']['fields']));_0x4c8d33[_0xf832('0x2c')]=_0x4c8d33[_0xf832('0x2c')][_0xf832('0x2d')]?_0x4c8d33[_0xf832('0x2c')]:_0x3e649e[_0xf832('0x2a')];if(!_0x430e5e[_0xf832('0x28')][_0xf832('0x1f')](_0xf832('0x2e'))){_0x4c8d33['limit']=this[_0xf832('0x13')](_0x430e5e[_0xf832('0x28')][_0xf832('0x13')]);_0x4c8d33['offset']=this[_0xf832('0x14')](_0x430e5e[_0xf832('0x28')][_0xf832('0x14')]);}_0x4c8d33[_0xf832('0x2f')]=this[_0xf832('0x15')](_0x430e5e['query'][_0xf832('0x15')]);_0x4c8d33[_0xf832('0x30')]=this[_0xf832('0x31')](_[_0xf832('0x32')](_0x430e5e[_0xf832('0x28')],_0x3e649e['filters']),_0x787012);if(_0x430e5e[_0xf832('0x28')]['filter']){_0x4c8d33['where']=_[_0xf832('0x33')](_0x4c8d33[_0xf832('0x30')],{'$or':_[_0xf832('0x16')](_0x787012,function(_0x4fa2a4){if(_0x4fa2a4[_0xf832('0x8')]!=='VIRTUAL'){if(_0x40e370){return sequelize['where'](sequelize['fn']('lower',sequelize[_0xf832('0x34')](_0x4fa2a4[_0xf832('0x10')])),{'$like':sequelize['fn']('lower','%'+_0x430e5e['query'][_0xf832('0x35')]+'%')});}else{var _0x82fc1c={};_0x82fc1c[_0x4fa2a4['name']]={'$like':'%'+_0x430e5e[_0xf832('0x28')][_0xf832('0x35')]+'%'};return _0x82fc1c;}}})});}_0x4c8d33=_['merge']({},_0x4c8d33,_0x430e5e['options']);return _0x4c8d33;};