@@ -420,41 +420,38 @@ const internalProxyHost = {
420420 * @param {String } [search_query]
421421 * @returns {Promise }
422422 */
423- getAll : ( access , expand , search_query ) => {
424- return access
425- . can ( "proxy_hosts:list" )
426- . then ( ( access_data ) => {
427- const query = proxyHostModel
428- . query ( )
429- . where ( "is_deleted" , 0 )
430- . groupBy ( "id" )
431- . allowGraph ( "[owner,access_list,certificate]" )
432- . orderBy ( castJsonIfNeed ( "domain_names" ) , "ASC" ) ;
423+ getAll : async ( access , expand , searchQuery ) => {
424+ const accessData = await access . can ( "proxy_hosts:list" ) ;
425+
426+ const query = proxyHostModel
427+ . query ( )
428+ . where ( "is_deleted" , 0 )
429+ . groupBy ( "id" )
430+ . allowGraph ( "[owner,access_list,certificate]" )
431+ . orderBy ( castJsonIfNeed ( "domain_names" ) , "ASC" ) ;
432+
433+ if ( accessData . permission_visibility !== "all" ) {
434+ query . andWhere ( "owner_user_id" , access . token . getUserId ( 1 ) ) ;
435+ }
433436
434- if ( access_data . permission_visibility !== "all" ) {
435- query . andWhere ( "owner_user_id" , access . token . getUserId ( 1 ) ) ;
436- }
437+ // Query is used for searching
438+ if ( typeof searchQuery === "string" && searchQuery . length > 0 ) {
439+ query . where ( function ( ) {
440+ this . where ( castJsonIfNeed ( "domain_names" ) , "like" , `%${ searchQuery } %` ) ;
441+ } ) ;
442+ }
437443
438- // Query is used for searching
439- if ( typeof search_query === "string" && search_query . length > 0 ) {
440- query . where ( function ( ) {
441- this . where ( castJsonIfNeed ( "domain_names" ) , "like" , `%${ search_query } %` ) ;
442- } ) ;
443- }
444+ if ( typeof expand !== "undefined" && expand !== null ) {
445+ query . withGraphFetched ( `[${ expand . join ( ", " ) } ]` ) ;
446+ }
444447
445- if ( typeof expand !== "undefined" && expand !== null ) {
446- query . withGraphFetched ( `[${ expand . join ( ", " ) } ]` ) ;
447- }
448+ const rows = await query . then ( utils . omitRows ( omissions ( ) ) ) ;
448449
449- return query . then ( utils . omitRows ( omissions ( ) ) ) ;
450- } )
451- . then ( ( rows ) => {
452- if ( typeof expand !== "undefined" && expand !== null && expand . indexOf ( "certificate" ) !== - 1 ) {
453- return internalHost . cleanAllRowsCertificateMeta ( rows ) ;
454- }
450+ if ( typeof expand !== "undefined" && expand !== null && expand . indexOf ( "certificate" ) !== - 1 ) {
451+ return internalHost . cleanAllRowsCertificateMeta ( rows ) ;
452+ }
455453
456- return rows ;
457- } ) ;
454+ return rows ;
458455 } ,
459456
460457 /**
0 commit comments