Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/responders/search-responders.js
// @flow | // @flow | ||||
import t, { type TInterface } from 'tcomb'; | import t, { type TInterface } from 'tcomb'; | ||||
import type { | import type { | ||||
UserSearchRequest, | UserSearchRequest, | ||||
UserSearchResult, | UserSearchResult, | ||||
ExactUserSearchRequest, | |||||
ExactUserSearchResult, | |||||
} from 'lib/types/search-types.js'; | } from 'lib/types/search-types.js'; | ||||
import { globalAccountUserInfoValidator } from 'lib/types/user-types.js'; | import { globalAccountUserInfoValidator } from 'lib/types/user-types.js'; | ||||
import { tShape } from 'lib/utils/validation-utils.js'; | import { tShape } from 'lib/utils/validation-utils.js'; | ||||
import { searchForUsers } from '../search/users.js'; | import { searchForUsers, searchForUser } from '../search/users.js'; | ||||
import type { Viewer } from '../session/viewer.js'; | import type { Viewer } from '../session/viewer.js'; | ||||
import { validateInput, validateOutput } from '../utils/validation-utils.js'; | import { validateInput, validateOutput } from '../utils/validation-utils.js'; | ||||
const userSearchRequestInputValidator = tShape<UserSearchRequest>({ | const userSearchRequestInputValidator = tShape<UserSearchRequest>({ | ||||
prefix: t.maybe(t.String), | prefix: t.maybe(t.String), | ||||
}); | }); | ||||
export const userSearchResultValidator: TInterface<UserSearchResult> = | export const userSearchResultValidator: TInterface<UserSearchResult> = | ||||
Show All 14 Lines | ): Promise<UserSearchResult> { | ||||
const result = { userInfos: searchResults }; | const result = { userInfos: searchResults }; | ||||
return validateOutput( | return validateOutput( | ||||
viewer.platformDetails, | viewer.platformDetails, | ||||
userSearchResultValidator, | userSearchResultValidator, | ||||
result, | result, | ||||
); | ); | ||||
} | } | ||||
export { userSearchResponder }; | const exactUserSearchRequestInputValidator = tShape<ExactUserSearchRequest>({ | ||||
username: t.String, | |||||
}); | |||||
const exactUserSearchResultValidator = tShape<ExactUserSearchResult>({ | |||||
userInfo: t.maybe(globalAccountUserInfoValidator), | |||||
}); | |||||
async function exactUserSearchResponder( | |||||
viewer: Viewer, | |||||
input: mixed, | |||||
): Promise<ExactUserSearchResult> { | |||||
const request = await validateInput( | |||||
viewer, | |||||
exactUserSearchRequestInputValidator, | |||||
input, | |||||
); | |||||
const searchResult = await searchForUser(request.username); | |||||
const result = { userInfo: searchResult }; | |||||
return validateOutput( | |||||
viewer.platformDetails, | |||||
exactUserSearchResultValidator, | |||||
result, | |||||
); | |||||
} | |||||
export { userSearchResponder, exactUserSearchResponder }; |