Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/fetchers/user-fetchers.js
Show First 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | ): Promise<OldCurrentUserInfo | CurrentUserInfo> { | ||||
const currentUserInfo = await fetchLoggedInUserInfo(viewer); | const currentUserInfo = await fetchLoggedInUserInfo(viewer); | ||||
return currentUserInfo; | return currentUserInfo; | ||||
} | } | ||||
async function fetchLoggedInUserInfo( | async function fetchLoggedInUserInfo( | ||||
viewer: Viewer, | viewer: Viewer, | ||||
): Promise<OldLoggedInUserInfo | LoggedInUserInfo> { | ): Promise<OldLoggedInUserInfo | LoggedInUserInfo> { | ||||
const userQuery = SQL` | const userQuery = SQL` | ||||
SELECT id, username | SELECT id, username, avatar | ||||
FROM users | FROM users | ||||
WHERE id = ${viewer.userID} | WHERE id = ${viewer.userID} | ||||
`; | `; | ||||
const settingsQuery = SQL` | const settingsQuery = SQL` | ||||
SELECT name, data | SELECT name, data | ||||
FROM settings | FROM settings | ||||
WHERE user = ${viewer.userID} | WHERE user = ${viewer.userID} | ||||
Show All 11 Lines | const stillExpectsEmailFields = !hasMinCodeVersion( | ||||
87, | 87, | ||||
); | ); | ||||
if (!userRow) { | if (!userRow) { | ||||
throw new ServerError('unknown_error'); | throw new ServerError('unknown_error'); | ||||
} | } | ||||
const id = userRow.id.toString(); | const id = userRow.id.toString(); | ||||
const { username } = userRow; | const { username, avatar } = userRow; | ||||
if (stillExpectsEmailFields) { | if (stillExpectsEmailFields) { | ||||
return { | return { | ||||
id, | id, | ||||
username, | username, | ||||
email: 'removed from DB', | email: 'removed from DB', | ||||
emailVerified: true, | emailVerified: true, | ||||
}; | }; | ||||
} | } | ||||
let loggedInUserInfo: LoggedInUserInfo = { | |||||
id, | |||||
username, | |||||
}; | |||||
const shouldIncludeAvatar = hasMinCodeVersion(viewer.platformDetails, 1000); | |||||
if (shouldIncludeAvatar && avatar) { | |||||
loggedInUserInfo = { ...loggedInUserInfo, avatar }; | |||||
} | |||||
const featureGateSettings = !hasMinCodeVersion(viewer.platformDetails, 1000); | const featureGateSettings = !hasMinCodeVersion(viewer.platformDetails, 1000); | ||||
if (featureGateSettings) { | if (featureGateSettings) { | ||||
return { id, username }; | return loggedInUserInfo; | ||||
} | } | ||||
const settings = settingsResult.reduce((prev, curr) => { | const settings = settingsResult.reduce((prev, curr) => { | ||||
prev[curr.name] = curr.data; | prev[curr.name] = curr.data; | ||||
return prev; | return prev; | ||||
}, {}); | }, {}); | ||||
loggedInUserInfo = { ...loggedInUserInfo, settings }; | |||||
return { id, username, settings }; | return loggedInUserInfo; | ||||
} | } | ||||
async function fetchAllUserIDs(): Promise<string[]> { | async function fetchAllUserIDs(): Promise<string[]> { | ||||
const query = SQL`SELECT id FROM users`; | const query = SQL`SELECT id FROM users`; | ||||
const [result] = await dbQuery(query); | const [result] = await dbQuery(query); | ||||
return result.map(row => row.id.toString()); | return result.map(row => row.id.toString()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines |