3a50dbe3d4f3b9d51d997a2a8196ce2b712a1648
[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 _0xe3bc=['user','clause','tags','checkListsRestrictions','then','ids','tag','countFilteredContacts','count','fields','rows','catch','describe','CmContact','keys','startsWith','CmCustomField','findOne','slice','all','cf_','fieldType','type','lodash','./sql-utils','../../mysqldb','findAll','skipContactsQuery','resolve','search','parseAdvancedSearchFilter','parseQueryParameters','where','default','filter'];(function(_0x54ed8e,_0x3106ab){var _0x12443e=function(_0x43832e){while(--_0x43832e){_0x54ed8e['push'](_0x54ed8e['shift']());}};_0x12443e(++_0x3106ab);}(_0xe3bc,0x1de));var _0xce3b=function(_0x41c74e,_0x1917d7){_0x41c74e=_0x41c74e-0x0;var _0x4f5f6a=_0xe3bc[_0x41c74e];return _0x4f5f6a;};'use strict';var _=require(_0xce3b('0x0'));var sqlUtils=require(_0xce3b('0x1'));var db=require(_0xce3b('0x2'))['db'];exports[_0xce3b('0x3')]=function(_0x5e06bf,_0x59fdd3,_0x4b9468,_0x4f6fbd){var _0x174210={'count':0x0,'rows':[]};var _0x6d98d9=sqlUtils[_0xce3b('0x4')](_0x59fdd3,_0x5e06bf);if(_0x6d98d9){return Promise['resolve'](_0x174210);}var _0x4e1fe8=sqlUtils['getContactsSubquery']();var _0x53c18d={};var _0x55d3b6=![];var _0x286a87=![];return Promise[_0xce3b('0x5')]()['then'](function(){if(_0x5e06bf[_0xce3b('0x6')]){return sqlUtils[_0xce3b('0x7')](_0x5e06bf['search'],_0x4f6fbd);}else{return sqlUtils[_0xce3b('0x8')](_0x5e06bf,_0x4f6fbd);}})['then'](function(_0x59c760){_0x4e1fe8[_0xce3b('0x9')](_0x59c760[_0xce3b('0xa')]);_0x4e1fe8[_0xce3b('0x9')](_0x59c760['fields']);_0x4e1fe8[_0xce3b('0x9')](_0x59c760[_0xce3b('0xb')]);_0x4e1fe8[_0xce3b('0x9')](_0x59c760[_0xce3b('0xc')][_0xce3b('0xd')]);_0x53c18d=_0x59c760[_0xce3b('0xe')];_0x286a87=_0x59c760[_0xce3b('0xc')]['skip'];return sqlUtils[_0xce3b('0xf')](_0x59fdd3,_0x5e06bf,_0x286a87);})[_0xce3b('0x10')](function(_0xb4b727){_0x4e1fe8[_0xce3b('0x9')](_0xb4b727);var _0x51d502=_0x5e06bf[_0xce3b('0x6')]?_0x53c18d[_0xce3b('0x11')]:_0x5e06bf[_0xce3b('0x12')];_0x55d3b6=_0x51d502?!![]:![];return sqlUtils[_0xce3b('0x13')](_0x4e1fe8,_0x51d502);})['then'](function(_0x260b5b){_0x174210[_0xce3b('0x14')]=_0x260b5b;if(_0x174210[_0xce3b('0x14')]===0x0){return;}if(_0x5e06bf['User']){_0x286a87=!![];}return sqlUtils['buildContactsQuery'](_0x4e1fe8,_0x5e06bf[_0xce3b('0x15')],_0x4b9468,_0x55d3b6,_0x53c18d['clause'],_0x286a87);})['then'](function(_0x2c2457){if(!_0x2c2457){return[];}return sqlUtils['getFilteredContacts'](_0x2c2457,_0x5e06bf,_0x4b9468);})[_0xce3b('0x10')](function(_0x2d9c83){_0x174210[_0xce3b('0x16')]=_0x2d9c83;return _0x174210;})[_0xce3b('0x17')](function(_0x389b4e){throw _0x389b4e;});};exports[_0xce3b('0x18')]=function(){var _0x55d0d1={};var _0xfd4ad0=[];return db[_0xce3b('0x19')][_0xce3b('0x18')]()[_0xce3b('0x10')](function(_0x30bf9b){_0x55d0d1=_0x30bf9b;var _0x464cf7=Object[_0xce3b('0x1a')](_0x55d0d1)[_0xce3b('0xb')](function(_0x1231f8){return _[_0xce3b('0x1b')](_0x1231f8,'cf_')?_0x1231f8:undefined;});var _0x3c1ce1=_0x464cf7['map'](function(_0xec9369){return db[_0xce3b('0x1c')][_0xce3b('0x1d')]({'where':{'id':_0xec9369[_0xce3b('0x1e')](0x3)},'raw':!![]});});return Promise[_0xce3b('0x1f')](_0x3c1ce1);})[_0xce3b('0x10')](function(_0x5f23c5){for(var _0x1ee300=0x0;_0x1ee300<_0x5f23c5['length'];_0x1ee300++){if(_0x5f23c5[_0x1ee300]){var _0xd000bf=_0xce3b('0x20')+_0x5f23c5[_0x1ee300]['id'];_0x55d0d1[_0xd000bf][_0xce3b('0x21')]=_0x5f23c5[_0x1ee300][_0xce3b('0x22')];}}_0xfd4ad0=_['map'](Object[_0xce3b('0x1a')](_0x55d0d1),function(_0x44cce){return{'name':_0x44cce,'type':_0x55d0d1[_0x44cce][_0xce3b('0x22')]};});return _0xfd4ad0;})[_0xce3b('0x17')](function(_0x555c93){throw _0x555c93;});};