Skip to content

Instantly share code, notes, and snippets.

@jsjoeio
Created July 28, 2021 14:51
Show Gist options
  • Save jsjoeio/f29f5f86900d309325645f68e1cf41bd to your computer and use it in GitHub Desktop.
Save jsjoeio/f29f5f86900d309325645f68e1cf41bd to your computer and use it in GitHub Desktop.
Example interacting with Supabase on server
type UserInGroup = Pick<DipUser, "timezone" | "telegramUsername" | "groupIds">
/**
* Gets the users from the DB using their groupId
*/
export async function getUsersInGroup(
telegramGroupId: number
): Promise<UserInGroup[] | undefined> {
const groupId = UPCOMING_GROUPS.find(
(group) => group.telegramGroupId === telegramGroupId
)?.id
if (!groupId) {
logger.error(
`Error getting users in group ${groupId}. Could not find group id in upcoming groups.`
)
return []
}
const { data, error } = await supabaseServer
.from(USERS_TABLE_NAME)
.select("timezone,telegramUsername,groupIds")
.eq("groupIds", groupId)
// TODO @jsjoeio eventually, i need to make the column an array of strings
if (data) {
return data
}
if (error) {
console.log(error)
logger.error(`Error getting users in group ${groupId}`, error)
return []
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment