f62923d48a146baf9d36c993f66597d901b4b3b7
[motion2.git] / server / components / contacts / index.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 _0xfdf8=['type','./sql-utils','../../mysqldb','findAll','skipContactsQuery','resolve','getContactsSubquery','then','search','parseAdvancedSearchFilter','parseQueryParameters','where','default','fields','filter','clause','tags','user','skip','checkListsRestrictions','ids','tag','countFilteredContacts','count','User','getFilteredContacts','rows','catch','CmContact','describe','keys','cf_','map','CmCustomField','findOne','slice','length','fieldType'];(function(_0x4fe5a7,_0x147749){var _0x4800ef=function(_0x97c8e8){while(--_0x97c8e8){_0x4fe5a7['push'](_0x4fe5a7['shift']());}};_0x4800ef(++_0x147749);}(_0xfdf8,0x17d));var _0x8fdf=function(_0x14add3,_0x13ce8d){_0x14add3=_0x14add3-0x0;var _0x4a174f=_0xfdf8[_0x14add3];return _0x4a174f;};'use strict';var _=require('lodash');var sqlUtils=require(_0x8fdf('0x0'));var db=require(_0x8fdf('0x1'))['db'];exports[_0x8fdf('0x2')]=function(_0x4cafc9,_0x3d9144,_0x316025,_0x308db2){var _0x545b12={'count':0x0,'rows':[]};var _0x3abd1c=sqlUtils[_0x8fdf('0x3')](_0x3d9144,_0x4cafc9);if(_0x3abd1c){return Promise[_0x8fdf('0x4')](_0x545b12);}var _0x5674f6=sqlUtils[_0x8fdf('0x5')]();var _0x20251c={};var _0xab554a=![];var _0x53da3c=![];return Promise[_0x8fdf('0x4')]()[_0x8fdf('0x6')](function(){if(_0x4cafc9[_0x8fdf('0x7')]){return sqlUtils[_0x8fdf('0x8')](_0x4cafc9['search'],_0x308db2);}else{return sqlUtils[_0x8fdf('0x9')](_0x4cafc9,_0x308db2);}})['then'](function(_0x40f9a1){_0x5674f6[_0x8fdf('0xa')](_0x40f9a1[_0x8fdf('0xb')]);_0x5674f6['where'](_0x40f9a1[_0x8fdf('0xc')]);_0x5674f6[_0x8fdf('0xa')](_0x40f9a1[_0x8fdf('0xd')]);_0x5674f6[_0x8fdf('0xa')](_0x40f9a1['user'][_0x8fdf('0xe')]);_0x20251c=_0x40f9a1[_0x8fdf('0xf')];_0x53da3c=_0x40f9a1[_0x8fdf('0x10')][_0x8fdf('0x11')];return sqlUtils[_0x8fdf('0x12')](_0x3d9144,_0x4cafc9,_0x53da3c);})[_0x8fdf('0x6')](function(_0xb384b0){_0x5674f6[_0x8fdf('0xa')](_0xb384b0);var _0x9645dd=_0x4cafc9[_0x8fdf('0x7')]?_0x20251c[_0x8fdf('0x13')]:_0x4cafc9[_0x8fdf('0x14')];_0xab554a=_0x9645dd?!![]:![];return sqlUtils[_0x8fdf('0x15')](_0x5674f6,_0x9645dd);})['then'](function(_0x2d97da){_0x545b12[_0x8fdf('0x16')]=_0x2d97da;if(_0x545b12['count']===0x0){return;}if(_0x4cafc9[_0x8fdf('0x17')]){_0x53da3c=!![];}return sqlUtils['buildContactsQuery'](_0x5674f6,_0x4cafc9['fields'],_0x316025,_0xab554a,_0x20251c[_0x8fdf('0xe')],_0x53da3c);})[_0x8fdf('0x6')](function(_0x41e7a4){if(!_0x41e7a4){return[];}return sqlUtils[_0x8fdf('0x18')](_0x41e7a4,_0x4cafc9,_0x316025);})[_0x8fdf('0x6')](function(_0x17a142){_0x545b12[_0x8fdf('0x19')]=_0x17a142;return _0x545b12;})[_0x8fdf('0x1a')](function(_0x28eb92){throw _0x28eb92;});};exports['describe']=function(){var _0x43a8b7={};var _0x1f90e0=[];return db[_0x8fdf('0x1b')][_0x8fdf('0x1c')]()[_0x8fdf('0x6')](function(_0x4b76bc){_0x43a8b7=_0x4b76bc;var _0x1ccb12=Object[_0x8fdf('0x1d')](_0x43a8b7)[_0x8fdf('0xd')](function(_0x19e86c){return _['startsWith'](_0x19e86c,_0x8fdf('0x1e'))?_0x19e86c:undefined;});var _0xd10385=_0x1ccb12[_0x8fdf('0x1f')](function(_0x2abf13){return db[_0x8fdf('0x20')][_0x8fdf('0x21')]({'where':{'id':_0x2abf13[_0x8fdf('0x22')](0x3)},'raw':!![]});});return Promise['all'](_0xd10385);})['then'](function(_0x1b8b21){for(var _0x2cfa3e=0x0;_0x2cfa3e<_0x1b8b21[_0x8fdf('0x23')];_0x2cfa3e++){if(_0x1b8b21[_0x2cfa3e]){var _0x1b780c=_0x8fdf('0x1e')+_0x1b8b21[_0x2cfa3e]['id'];_0x43a8b7[_0x1b780c][_0x8fdf('0x24')]=_0x1b8b21[_0x2cfa3e][_0x8fdf('0x25')];}}_0x1f90e0=_[_0x8fdf('0x1f')](Object['keys'](_0x43a8b7),function(_0x5311fa){return{'name':_0x5311fa,'type':_0x43a8b7[_0x5311fa][_0x8fdf('0x25')]};});return _0x1f90e0;})['catch'](function(_0x303ccb){throw _0x303ccb;});};