b211301719c72a8448f64debbb7978097125c815
[motion2.git] / server / components / parsers / advancedSearch.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 _0x1ddb=['value','includes','$gt','$lte','operator','days','YYYY-MM-DD','castTo','text','CAST(','field','\x20AS\x20','$ne','\x20OR\x20','\x20IS\x20NULL)','IN\x20?','$notIn','=\x20?','<>\x20?','$substring','LIKE\x20?','<\x20?','<=\x20?','$gte','>=\x20?','BETWEEN\x20?\x20AND\x20?','$in','start','$startsWith','pop','utcOffset','format','hours','add','minutes','seconds','lodash','moment','parseSearch','sqlOperator','startsWith','[$or]','and','replace','[$and]','split','slice','forEach','shift','match','filter','indexOf','map','conditions','push','DATE','$eq','$between'];(function(_0x44946b,_0xf874ec){var _0x249bc4=function(_0x40a23e){while(--_0x40a23e){_0x44946b['push'](_0x44946b['shift']());}};_0x249bc4(++_0xf874ec);}(_0x1ddb,0x1ba));var _0xb1dd=function(_0x1ed354,_0x4bb5be){_0x1ed354=_0x1ed354-0x0;var _0x532757=_0x1ddb[_0x1ed354];return _0x532757;};'use strict';var _=require(_0xb1dd('0x0'));var moment=require(_0xb1dd('0x1'));exports[_0xb1dd('0x2')]=function(_0x15fe20){var _0x390b03={'conditions':[]};_0x390b03[_0xb1dd('0x3')]=_[_0xb1dd('0x4')](_0x15fe20,_0xb1dd('0x5'))?'or':_0xb1dd('0x6');var _0x3f2bb8=_0x15fe20[_0xb1dd('0x7')](_0xb1dd('0x8'),'')[_0xb1dd('0x7')](_0xb1dd('0x5'),'')[_0xb1dd('0x9')]('||');for(var _0x2feaee=0x0;_0x2feaee<_0x3f2bb8['length'];_0x2feaee++){var _0x13084a=_0x3f2bb8[_0x2feaee][_0xb1dd('0x9')](':=');var _0xf7fefc=_0x13084a[0x0];var _0x681a7b=_0x13084a[_0xb1dd('0xa')](0x1);_0x681a7b[_0xb1dd('0xb')](function(_0x457e2d){var _0x27492f=_0x457e2d[_0xb1dd('0x9')]('[')[_0xb1dd('0xc')]();var _0x2438f3=_0x457e2d[_0xb1dd('0xd')](/\[(.*?)\]/g);_0x2438f3[_0xb1dd('0xb')](function(_0x3da7d9){var _0x3f5ab4=_0x3da7d9[_0xb1dd('0x9')]('[')[_0xb1dd('0xe')](function(_0x901550){return _0x901550[_0xb1dd('0xf')](']')>-0x1;})[_0xb1dd('0x10')](function(_0x108495){return _0x108495[_0xb1dd('0x9')](']')[0x0];})[0x0];_0x390b03[_0xb1dd('0x11')][_0xb1dd('0x12')]({'field':_0xf7fefc,'operator':_0x27492f,'value':_0x3f5ab4});});});}return _0x390b03;};exports['buildExpression']=function(_0x44d5be,_0x13d562,_0x33bde2){var _0x3d1b2f={};if(_0x13d562===_0xb1dd('0x13')){if(_0x33bde2['operator']===_0xb1dd('0x14')){_0x33bde2['operator']=_0xb1dd('0x15');_0x33bde2[_0xb1dd('0x16')]+=','+_0x33bde2['value'];}else if(_[_0xb1dd('0x17')]([_0xb1dd('0x18'),_0xb1dd('0x19')],_0x33bde2[_0xb1dd('0x1a')])){_0x33bde2[_0xb1dd('0x16')]=moment(_0x33bde2[_0xb1dd('0x16')])['add'](0x1,_0xb1dd('0x1b'))['format'](_0xb1dd('0x1c'));}}if(_0x33bde2[_0xb1dd('0x1d')]){_0x13d562=_0x33bde2[_0xb1dd('0x1d')];_0x3d1b2f[_0xb1dd('0x1e')]=_0xb1dd('0x1f')+_0x44d5be+'.'+_0x33bde2[_0xb1dd('0x20')]+_0xb1dd('0x21')+_0x33bde2[_0xb1dd('0x1d')]+')\x20'+parseOperator(_0x33bde2[_0xb1dd('0x1a')]);}else{_0x3d1b2f[_0xb1dd('0x1e')]=_0x44d5be+'.'+_0x33bde2['field']+'\x20'+parseOperator(_0x33bde2[_0xb1dd('0x1a')]);}if(_[_0xb1dd('0x17')]([_0xb1dd('0x22'),'$notIn'],_0x33bde2[_0xb1dd('0x1a')]))_0x3d1b2f['text']='('+_0x3d1b2f[_0xb1dd('0x1e')]+_0xb1dd('0x23')+_0x44d5be+'.'+_0x33bde2[_0xb1dd('0x20')]+_0xb1dd('0x24');_0x3d1b2f['value']=parseValue(_0x13d562,_0x33bde2[_0xb1dd('0x1a')],_0x33bde2[_0xb1dd('0x16')]);return _0x3d1b2f;};function parseOperator(_0x3107c4){var _0x3e2c04;switch(_0x3107c4){case'$in':_0x3e2c04=_0xb1dd('0x25');break;case _0xb1dd('0x26'):_0x3e2c04='NOT\x20IN\x20?';break;case'$eq':_0x3e2c04=_0xb1dd('0x27');break;case'$ne':_0x3e2c04=_0xb1dd('0x28');break;case _0xb1dd('0x29'):case'$startsWith':case'$endsWith':_0x3e2c04=_0xb1dd('0x2a');break;case'$lt':_0x3e2c04=_0xb1dd('0x2b');break;case'$gt':_0x3e2c04='>\x20?';break;case _0xb1dd('0x19'):_0x3e2c04=_0xb1dd('0x2c');break;case _0xb1dd('0x2d'):_0x3e2c04=_0xb1dd('0x2e');break;case'$between':_0x3e2c04=_0xb1dd('0x2f');break;}return _0x3e2c04;}function parseValue(_0x755b12,_0x514faa,_0x556e67){var _0x23060c={'start':undefined,'end':undefined};switch(_0x514faa){case _0xb1dd('0x30'):case'$notIn':_0x23060c[_0xb1dd('0x31')]=_0x556e67[_0xb1dd('0x9')](',');break;case'$substring':_0x23060c['start']='%'+_0x556e67+'%';break;case _0xb1dd('0x32'):_0x23060c[_0xb1dd('0x31')]=_0x556e67+'%';break;case'$endsWith':_0x23060c[_0xb1dd('0x31')]='%'+_0x556e67;break;case'$between':var _0xd6d8cc=_0x556e67[_0xb1dd('0x9')](',');var _0x556e67=_0xd6d8cc[_0xb1dd('0xc')]();var _0x7821e2=_0xd6d8cc[_0xb1dd('0x33')]();if(_0x755b12===_0xb1dd('0x13')){_0x556e67=moment(_0x556e67)[_0xb1dd('0x34')](0x0,!![])[_0xb1dd('0x35')]();_0x7821e2=moment(_0x7821e2)['utcOffset'](0x0,!![])['add'](0x17,_0xb1dd('0x36'))[_0xb1dd('0x37')](0x3b,_0xb1dd('0x38'))[_0xb1dd('0x37')](0x3b,_0xb1dd('0x39'))[_0xb1dd('0x35')]();}_0x23060c={'start':_0x556e67,'end':_0x7821e2};break;default:_0x23060c[_0xb1dd('0x31')]=_0x556e67;break;}return _0x23060c;}