Built motion from commit 497d3d92.|2.5.43
[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 _0x24ca=['omit','isEmpty','isObject','isString','hasOwnProperty','isNumeric','match','getFullTextValue','forEach','replace','push','join','query','$id','intersection','model','attributes','length','order','sort','where','filters','filter','object','value','merge','VIRTUAL','lower','lodash','parse','includes','keys','fields','split','find','type','DATE','$gte','format','YYYY-MM-DD','utc','$lte','subtract','name','uniqueid','isArray','limit','offset','map','indexOf','priority','cast','col','unsigned','substr','ASC'];(function(_0x36c0ca,_0x3e10eb){var _0x5df3cc=function(_0x42a1ed){while(--_0x42a1ed){_0x36c0ca['push'](_0x36c0ca['shift']());}};_0x5df3cc(++_0x3e10eb);}(_0x24ca,0x8c));var _0xa24c=function(_0x46800d,_0x588500){_0x46800d=_0x46800d-0x0;var _0x3824cd=_0x24ca[_0x46800d];return _0x3824cd;};'use strict';var _=require(_0xa24c('0x0'));var sequelize=require('sequelize');var moment=require('moment');var LIMIT_VALUE=0xfa;function hasSequelizeOperator(_0x1f4ee1){var _0x4e90b0=['ne'];try{var _0x155c49=JSON[_0xa24c('0x1')](_0x1f4ee1);var _0xe69cdd=Object['keys'](_0x155c49)[0x0];return _0x4e90b0[_0xa24c('0x2')](_0xe69cdd);}catch(_0x89148d){return![];}}function getOperatorValue(_0x4707f9){var _0x5a37ae=JSON['parse'](_0x4707f9);var _0x52147a=Object[_0xa24c('0x3')](_0x5a37ae)[0x0];var _0x3c10d9=_0x5a37ae[_0x52147a];return{['$'+_0x52147a]:_0x3c10d9};}exports[_0xa24c('0x4')]=function(_0x3c3959){var _0x34288c=null;if(_0x3c3959){_0x34288c=_0x3c3959[_0xa24c('0x5')](',');}return _0x34288c;};exports['filters']=function(_0x101ca7,_0x413b3d){var _0x355882={};if(!_['isEmpty'](_0x101ca7)){_['forOwn'](_0x101ca7,function(_0x1331f4,_0x73a132){try{if(_0x413b3d){var _0x2da0c3=_[_0xa24c('0x6')](_0x413b3d,{'name':_0x73a132})||{};if(hasSequelizeOperator(_0x1331f4)){_0x355882[_0x73a132]=getOperatorValue(_0x1331f4);}else if(_0x2da0c3[_0xa24c('0x7')]===_0xa24c('0x8')&&_['isPlainObject'](_0x1331f4)){var _0x5bb631=JSON['parse'](_0x1331f4);var _0x2444b7={'$gte':moment(moment(_0x5bb631[_0xa24c('0x9')])[_0xa24c('0xa')](_0xa24c('0xb')))[_0xa24c('0xc')]()['format'](),'$lte':moment(moment(_0x5bb631[_0xa24c('0xd')])['format']('YYYY-MM-DD'))['utc']()[_0xa24c('0xe')](0x1,'s')[_0xa24c('0xa')]()};_0x355882[_0x73a132]=_0x2444b7;}else if(_0x2da0c3[_0xa24c('0xf')]===_0xa24c('0x10')){_0x355882[_0x73a132]=_0x1331f4;}else{_0x355882[_0x73a132]=_[_0xa24c('0x11')](_0x1331f4)?_0x1331f4:JSON[_0xa24c('0x1')](_0x1331f4);}}else{_0x355882[_0x73a132]=_[_0xa24c('0x11')](_0x1331f4)?_0x1331f4:JSON[_0xa24c('0x1')](_0x1331f4);}}catch(_0x14f0aa){_0x355882[_0x73a132]=_0x1331f4[_0xa24c('0x5')](',');}});}return _0x355882;};exports[_0xa24c('0x12')]=function(_0x1a667b){_0x1a667b=parseInt(_0x1a667b,0xa);if(!_0x1a667b||_0x1a667b<0x0){_0x1a667b=LIMIT_VALUE;}return _0x1a667b;};exports[_0xa24c('0x13')]=function(_0x3e4e81){_0x3e4e81=parseInt(_0x3e4e81,0xa);if(!_0x3e4e81||_0x3e4e81<0x0){_0x3e4e81=0x0;}return _0x3e4e81;};exports['sort']=function(_0x167a76){var _0x48fb65,_0x98802d=null;if(_0x167a76){_0x48fb65=_0x167a76[_0xa24c('0x5')](',');_0x98802d=_[_0xa24c('0x14')](_0x48fb65,function(_0x37e20e){if(_0x37e20e[_0xa24c('0x15')]('-')===0x0){return[_0x37e20e===_0xa24c('0x16')?sequelize[_0xa24c('0x17')](sequelize[_0xa24c('0x18')](_0xa24c('0x16')),_0xa24c('0x19')):_0x37e20e[_0xa24c('0x1a')](0x1),'DESC'];}else{return[_0x37e20e==='priority'?sequelize[_0xa24c('0x17')](sequelize[_0xa24c('0x18')](_0xa24c('0x16')),_0xa24c('0x19')):_0x37e20e,_0xa24c('0x1b')];}});}return _0x98802d;};exports[_0xa24c('0x1c')]=function(_0x16bd20,_0x3106ff){if(_[_0xa24c('0x1d')](_0x16bd20)){return _0x16bd20;}if(_['isArray'](_0x16bd20)){for(var _0x2290e1=0x0;_0x2290e1<_0x16bd20['length'];_0x2290e1+=0x1){_0x16bd20[_0x2290e1]=this[_0xa24c('0x1c')](_0x16bd20[_0x2290e1],_0x3106ff);}return _0x16bd20;}if(!_[_0xa24c('0x1e')](_0x16bd20)){return _0x16bd20;}if(_[_0xa24c('0x1f')](_0x3106ff)){_0x3106ff=[_0x3106ff];}if(!_[_0xa24c('0x11')](_0x3106ff)){return _0x16bd20;}for(var _0x54b8a6=0x0;_0x54b8a6<_0x3106ff['length'];_0x54b8a6+=0x1){_['unset'](_0x16bd20,_0x3106ff[_0x54b8a6]);}for(var _0x4e5d2c in _0x16bd20){if(_0x16bd20[_0xa24c('0x20')](_0x4e5d2c)){_0x16bd20[_0x4e5d2c]=this[_0xa24c('0x1c')](_0x16bd20[_0x4e5d2c],_0x3106ff);}}return _0x16bd20;};exports[_0xa24c('0x21')]=function(_0x1cdee4){return _0x1cdee4[_0xa24c('0x22')](RegExp('^[+]?[0-9]*$'))?!![]:![];};exports['isEmail']=function(_0x33c208){return _0x33c208[_0xa24c('0x22')](/^\S+@\S+$/)?!![]:![];};exports[_0xa24c('0x23')]=function(_0x1d500e){var _0x4566dc=[];_0x1d500e[_0xa24c('0x5')](/[ ,]+/)[_0xa24c('0x24')](function(_0x1e30a9){_0x1e30a9=_0x1e30a9[_0xa24c('0x25')](/([^:]")"+/g,'$1');_0x1e30a9='+'+_0x1e30a9+'*';var _0x17a001=/[ `!@#$%^&*()_\-?~]/;if(_0x1e30a9['match'](_0x17a001))_0x1e30a9='\x22'+_0x1e30a9+'\x22';_0x4566dc[_0xa24c('0x26')](_0x1e30a9);});return _0x4566dc[_0xa24c('0x27')]('\x20');};exports['getOptions']=function(_0x3c9649,_0x3e8b0f,_0x33f0c9){var _0x1de2ef={},_0x26f2fe={};if(_0x3e8b0f[_0xa24c('0x28')][_0xa24c('0x29')]){_0x3e8b0f[_0xa24c('0x28')]['id']=_0x3e8b0f[_0xa24c('0x28')][_0xa24c('0x29')];delete _0x3e8b0f['query']['$id'];}_0x1de2ef['model']=_[_0xa24c('0x14')](_0x3c9649,'name');_0x1de2ef[_0xa24c('0x28')]=_[_0xa24c('0x3')](_0x3e8b0f[_0xa24c('0x28')]);_0x1de2ef['filters']=_[_0xa24c('0x2a')](_0x1de2ef[_0xa24c('0x2b')],_0x1de2ef[_0xa24c('0x28')]);_0x26f2fe['attributes']=_[_0xa24c('0x2a')](_0x1de2ef[_0xa24c('0x2b')],this['fields'](_0x3e8b0f[_0xa24c('0x28')][_0xa24c('0x4')]));_0x26f2fe[_0xa24c('0x2c')]=_0x26f2fe['attributes'][_0xa24c('0x2d')]?_0x26f2fe[_0xa24c('0x2c')]:_0x1de2ef[_0xa24c('0x2b')];if(!_0x3e8b0f[_0xa24c('0x28')][_0xa24c('0x20')]('nolimit')){_0x26f2fe[_0xa24c('0x12')]=this[_0xa24c('0x12')](_0x3e8b0f['query'][_0xa24c('0x12')]);_0x26f2fe[_0xa24c('0x13')]=this[_0xa24c('0x13')](_0x3e8b0f['query']['offset']);}_0x26f2fe[_0xa24c('0x2e')]=this[_0xa24c('0x2f')](_0x3e8b0f[_0xa24c('0x28')][_0xa24c('0x2f')]);_0x26f2fe[_0xa24c('0x30')]=this[_0xa24c('0x31')](_['pick'](_0x3e8b0f[_0xa24c('0x28')],_0x1de2ef[_0xa24c('0x31')]),_0x3c9649);if(_0x3e8b0f[_0xa24c('0x28')][_0xa24c('0x32')]){var _0x5f3cd4=_0x3c9649;var _0x34026c=_0x3e8b0f[_0xa24c('0x28')][_0xa24c('0x32')];if(typeof _0x34026c===_0xa24c('0x33')){_0x5f3cd4=_[_0xa24c('0x32')](_0x3c9649,function(_0x7d16aa){return _[_0xa24c('0x2')](_0x34026c['columns'],_0x7d16aa['name']);});_0x34026c=_0x34026c[_0xa24c('0x34')];}_0x26f2fe['where']=_[_0xa24c('0x35')](_0x26f2fe['where'],{'$or':_[_0xa24c('0x14')](_0x5f3cd4,function(_0x214627){if(_0x214627[_0xa24c('0x7')]!==_0xa24c('0x36')){if(_0x33f0c9){return sequelize[_0xa24c('0x30')](sequelize['fn'](_0xa24c('0x37'),sequelize[_0xa24c('0x18')](_0x214627[_0xa24c('0xf')])),{'$like':sequelize['fn'](_0xa24c('0x37'),'%'+_0x3e8b0f[_0xa24c('0x28')][_0xa24c('0x32')]+'%')});}else{var _0x1f87b7={};_0x1f87b7[_0x214627[_0xa24c('0xf')]]={'$like':'%'+_0x3e8b0f[_0xa24c('0x28')][_0xa24c('0x32')]+'%'};return _0x1f87b7;}}})});}_0x26f2fe=_[_0xa24c('0x35')]({},_0x26f2fe,_0x3e8b0f['options']);return _0x26f2fe;};