Skip to content

Commit

Permalink
Merge pull request #116 from EyeSeeTea/feature/user-lookup
Browse files Browse the repository at this point in the history
Implement endpoint /api/userLookup
  • Loading branch information
adrianq authored Jan 3, 2022
2 parents fec2bbf + cf84ff9 commit 26e0722
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/api/UserLookup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { D2ApiGeneric } from "./d2Api";
import { Id } from "./base";
import { CancelableResponse } from "../repositories/CancelableResponse";

export class UserLookup {
constructor(public api: D2ApiGeneric) {}

get(id: Id): CancelableResponse<UserInfo> {
return this.api.get<UserInfo>(`/userLookup/${id}`);
}

query(searchText: string): CancelableResponse<UserLookupQueryResponse> {
return this.api.get<UserLookupQueryResponse>(`/userLookup`, { query: searchText });
}
}

export interface UserLookupQueryResponse {
users: UserInfo[];
}

export interface UserInfo {
id: Id;
username: string;
firstName: string;
surname: string;
displayName: string;
}
6 changes: 6 additions & 0 deletions src/api/d2Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { SqlViews } from "./SqlViews";
import { System } from "./system";
import { TrackedEntityInstances } from "./trackedEntityInstances";
import { D2ApiOptions, D2ApiRequest, IndexedModels } from "./types";
import { UserLookup } from "./UserLookup";

export class D2ApiGeneric {
public baseUrl: string;
Expand Down Expand Up @@ -196,6 +197,11 @@ export abstract class D2ApiVersioned<
get sqlViews() {
return new SqlViews(this);
}

@cache()
get userLookup() {
return new UserLookup(this);
}
}

export { D2ApiOptions };

0 comments on commit 26e0722

Please sign in to comment.