forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
userSearchResult.ts
54 lines (43 loc) · 1.56 KB
/
userSearchResult.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* eslint-disable prefer-object-spread */
import { CorpUser, SearchResult, SearchResults } from '../../../types.generated';
import { userEntity, UserEntityArg } from '../entity/userEntity';
import { generateData } from './dataGenerator';
// login with one of these usernames
const usernames = ['kafka', 'looker', 'datahub'];
type SearchResultArg = UserEntityArg;
const searchResult = (option?: SearchResultArg) => (): SearchResult => {
return {
entity: userEntity(option),
matchedFields: [],
__typename: 'SearchResult',
};
};
const generateSearchResults = (): SearchResult[] => {
const loginUsers = usernames.map((username) => {
return searchResult({ username })();
});
return [...loginUsers, ...generateData<SearchResult>({ generator: searchResult(), count: 25 })];
};
const searchResults = generateSearchResults();
export const userSearchResult: SearchResults = {
start: 0,
count: 0,
total: 0,
searchResults,
facets: [],
__typename: 'SearchResults',
};
export const findUserByUsername = (username: string): CorpUser => {
const result = searchResults.find((r) => {
return (r.entity as CorpUser).username === username;
});
return Object.assign({}, result?.entity as CorpUser);
};
export const getUsers = (): CorpUser[] => {
return searchResults.map((r) => Object.assign({}, r.entity as CorpUser));
};
export const findUserByURN = (urn: string | null): CorpUser => {
return searchResults.find((r) => {
return (r.entity as CorpUser).urn === urn;
})?.entity as CorpUser;
};