File

src/app/data-dgql/queries/users.service.ts

Index

Methods

Constructor

constructor(qSearchUsers: SearchUsersGQL, qCurrentUser: CurrentUserGQL)
Parameters :
Name Type Optional
qSearchUsers SearchUsersGQL No
qCurrentUser CurrentUserGQL No

Methods

currentUser
currentUser()
searchUsers
searchUsers(filter: literal type)
Parameters :
Name Type Optional
filter literal type No
Returns : Promise<any[]>
import {Injectable} from '@angular/core';
import {CurrentUserGQL, CurrentUserQuery, SearchUsersGQL} from 'src/generated/graphql-dgql';
import {promisifyApolloFetch} from '@app/data-dgql/queries/util';

@Injectable({
  providedIn: 'root'
})
export class UsersService {
  constructor(private qSearchUsers: SearchUsersGQL, private qCurrentUser: CurrentUserGQL) {}

  searchUsers(filter: {username: string}): Promise<any[]> {
    let query = '';
    // The searchUser query is special in that it does not use a filter object.
    // However, this is not compatible with the rest of our API, which uses UserFilter
    // (e.g. issue assignees).
    // Hence, this function uses the username search field, even though this is technically
    // incorrect (searchUsers will also search by display name).
    if (filter) {
      query = filter.username;
    }

    if (!query) {
      // searchUser does not work without a search string
      return Promise.resolve([]);
    }

    return promisifyApolloFetch(this.qSearchUsers.fetch({query})).then((data) => data.searchUser);
  }

  currentUser(): Promise<CurrentUserQuery> {
    return promisifyApolloFetch(this.qCurrentUser.fetch());
  }
}

results matching ""

    No results matching ""