Built motion from commit d5e4af8c.|2.6.23
[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 _0xd478=['user','skip','tag','countFilteredContacts','count','User','buildContactsQuery','fields','getFilteredContacts','rows','describe','CmContact','cf_','map','CmCustomField','slice','all','length','type','catch','lodash','./sql-utils','../../mysqldb','findAll','skipContactsQuery','resolve','getContactsSubquery','then','search','parseQueryParameters','where','default','filter','tags'];(function(_0x89bb8e,_0x2a429f){var _0x11df0d=function(_0x44dc52){while(--_0x44dc52){_0x89bb8e['push'](_0x89bb8e['shift']());}};_0x11df0d(++_0x2a429f);}(_0xd478,0x9c));var _0x8d47=function(_0x1eac9b,_0x24bf2f){_0x1eac9b=_0x1eac9b-0x0;var _0x33dfd6=_0xd478[_0x1eac9b];return _0x33dfd6;};'use strict';var _=require(_0x8d47('0x0'));var sqlUtils=require(_0x8d47('0x1'));var db=require(_0x8d47('0x2'))['db'];exports[_0x8d47('0x3')]=function(_0x414dde,_0x4f15ca,_0x2b7f87,_0xb41367){var _0x71ae3d={'count':0x0,'rows':[]};var _0x5cbb10=sqlUtils[_0x8d47('0x4')](_0x4f15ca,_0x414dde);if(_0x5cbb10){return Promise[_0x8d47('0x5')](_0x71ae3d);}var _0x3b37d4=sqlUtils[_0x8d47('0x6')]();var _0x511bae={};var _0x3cfe2f=![];var _0x5a6b3d=![];return Promise[_0x8d47('0x5')]()[_0x8d47('0x7')](function(){if(_0x414dde[_0x8d47('0x8')]){return sqlUtils['parseAdvancedSearchFilter'](_0x414dde[_0x8d47('0x8')],_0xb41367);}else{return sqlUtils[_0x8d47('0x9')](_0x414dde,_0xb41367);}})[_0x8d47('0x7')](function(_0x2db3a7){_0x3b37d4[_0x8d47('0xa')](_0x2db3a7[_0x8d47('0xb')]);_0x3b37d4[_0x8d47('0xa')](_0x2db3a7['fields']);_0x3b37d4[_0x8d47('0xa')](_0x2db3a7[_0x8d47('0xc')]);_0x3b37d4[_0x8d47('0xa')](_0x2db3a7['user']['clause']);_0x511bae=_0x2db3a7[_0x8d47('0xd')];_0x5a6b3d=_0x2db3a7[_0x8d47('0xe')][_0x8d47('0xf')];return sqlUtils['checkListsRestrictions'](_0x4f15ca,_0x414dde,_0x5a6b3d);})[_0x8d47('0x7')](function(_0x500975){_0x3b37d4['where'](_0x500975);var _0x901ea5=_0x414dde[_0x8d47('0x8')]?_0x511bae['ids']:_0x414dde[_0x8d47('0x10')];_0x3cfe2f=_0x901ea5?!![]:![];return sqlUtils[_0x8d47('0x11')](_0x3b37d4,_0x901ea5);})[_0x8d47('0x7')](function(_0x365fd9){_0x71ae3d[_0x8d47('0x12')]=_0x365fd9;if(_0x71ae3d[_0x8d47('0x12')]===0x0){return;}if(_0x414dde[_0x8d47('0x13')]){_0x5a6b3d=!![];}return sqlUtils[_0x8d47('0x14')](_0x3b37d4,_0x414dde[_0x8d47('0x15')],_0x2b7f87,_0x3cfe2f,_0x511bae['clause'],_0x5a6b3d);})[_0x8d47('0x7')](function(_0x5ab229){if(!_0x5ab229){return[];}return sqlUtils[_0x8d47('0x16')](_0x5ab229,_0x414dde,_0x2b7f87);})[_0x8d47('0x7')](function(_0x5cecfc){_0x71ae3d[_0x8d47('0x17')]=_0x5cecfc;return _0x71ae3d;})['catch'](function(_0x275922){throw _0x275922;});};exports[_0x8d47('0x18')]=function(){var _0x387eb4={};var _0x4eb74a=[];return db[_0x8d47('0x19')][_0x8d47('0x18')]()[_0x8d47('0x7')](function(_0x30f4ef){_0x387eb4=_0x30f4ef;var _0x58df71=Object['keys'](_0x387eb4)[_0x8d47('0xc')](function(_0x2b14f9){return _['startsWith'](_0x2b14f9,_0x8d47('0x1a'))?_0x2b14f9:undefined;});var _0x1e5907=_0x58df71[_0x8d47('0x1b')](function(_0x366c07){return db[_0x8d47('0x1c')]['findOne']({'where':{'id':_0x366c07[_0x8d47('0x1d')](0x3)},'raw':!![]});});return Promise[_0x8d47('0x1e')](_0x1e5907);})[_0x8d47('0x7')](function(_0x10554d){for(var _0x3ed8e9=0x0;_0x3ed8e9<_0x10554d[_0x8d47('0x1f')];_0x3ed8e9++){if(_0x10554d[_0x3ed8e9]){var _0x386220='cf_'+_0x10554d[_0x3ed8e9]['id'];_0x387eb4[_0x386220]['fieldType']=_0x10554d[_0x3ed8e9][_0x8d47('0x20')];}}_0x4eb74a=_[_0x8d47('0x1b')](Object['keys'](_0x387eb4),function(_0x295765){return{'name':_0x295765,'type':_0x387eb4[_0x295765][_0x8d47('0x20')]};});return _0x4eb74a;})[_0x8d47('0x21')](function(_0xa391e6){throw _0xa391e6;});};