Created
July 28, 2021 14:51
-
-
Save jsjoeio/f29f5f86900d309325645f68e1cf41bd to your computer and use it in GitHub Desktop.
Example interacting with Supabase on server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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