Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/search/users.js
Show All 21 Lines | for (const row of result) { | ||||
userInfos.push({ | userInfos.push({ | ||||
id: row.id.toString(), | id: row.id.toString(), | ||||
username: row.username, | username: row.username, | ||||
}); | }); | ||||
} | } | ||||
return userInfos; | return userInfos; | ||||
} | } | ||||
export { searchForUsers }; | async function searchForUser( | ||||
usernameQuery: string, | |||||
): Promise<?GlobalAccountUserInfo> { | |||||
const query = SQL` | |||||
SELECT id, username | |||||
FROM users | |||||
WHERE LOWER(username) = LOWER(${usernameQuery}) | |||||
`; | |||||
const [result] = await dbQuery(query); | |||||
if (result.length === 0) { | |||||
return null; | |||||
} | |||||
const { id, username } = result[0]; | |||||
return { id, username }; | |||||
} | |||||
export { searchForUsers, searchForUser }; |