mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-04-24 03:00:09 -04:00
For existing guilds, create a metadata table after the discord auth callback
This commit is contained in:
committed by
Scott Stevenson
parent
3a3c225118
commit
b6a89453ee
@@ -128,6 +128,14 @@
|
||||
- name: GuildType
|
||||
using:
|
||||
foreign_key_constraint_on: type
|
||||
- name: metadata
|
||||
using:
|
||||
manual_configuration:
|
||||
remote_table:
|
||||
schema: public
|
||||
name: guild_metadata
|
||||
column_mapping:
|
||||
id: guild_id
|
||||
array_relationships:
|
||||
- name: guild_players
|
||||
using:
|
||||
|
||||
@@ -43,33 +43,33 @@ export const handleOAuthCallback = async (
|
||||
discordId: discordGuild.id,
|
||||
});
|
||||
|
||||
if (getGuildMetadataResponse.guild_metadata.length > 0) {
|
||||
const existingGuild = getGuildMetadataResponse.guild_metadata[0];
|
||||
if (getGuildMetadataResponse.guild.length > 0) {
|
||||
const existingGuild = getGuildMetadataResponse.guild[0];
|
||||
|
||||
// if a guild with the same server ID already exists, see if a discord refresh token is set.
|
||||
if (existingGuild.discord_metadata?.refreshToken != null) {
|
||||
if (existingGuild.metadata?.discord_metadata?.refreshToken != null) {
|
||||
// if so, it's already set up
|
||||
// might want to save the new refresh token if it's different...?
|
||||
|
||||
const getGuildResponse = await client.GetGuild({
|
||||
id: existingGuild.guild_id,
|
||||
});
|
||||
const successResponse: DiscordGuildAuthResponse = {
|
||||
success: true,
|
||||
guildname: getGuildResponse.guild[0].guildname,
|
||||
guildname: existingGuild.guildname,
|
||||
exists: true,
|
||||
};
|
||||
res.json(successResponse);
|
||||
} else {
|
||||
// otherwise, update the existing guild with the provided info from discord
|
||||
await client.UpdateGuildDiscordMetadata({
|
||||
guildId: existingGuild.guild_id,
|
||||
discordMetadata: parseDiscordMetadata(response.oauthResponse),
|
||||
// otherwise, create metadata for the existing guild with the provided info from discord
|
||||
await client.CreateGuildMetadata({
|
||||
object: {
|
||||
guild_id: existingGuild.id,
|
||||
creator_id: sessionVariables['x-hasura-user-id'],
|
||||
discord_id: discordGuild.id,
|
||||
discord_metadata: parseDiscordMetadata(response.oauthResponse),
|
||||
},
|
||||
});
|
||||
|
||||
const successResponse: DiscordGuildAuthResponse = {
|
||||
success: true,
|
||||
guildname: existingGuild.guild_id,
|
||||
guildname: existingGuild.guildname,
|
||||
};
|
||||
res.json(successResponse);
|
||||
}
|
||||
|
||||
@@ -101,11 +101,15 @@ gql`
|
||||
${GuildFragment}
|
||||
|
||||
query GetGuildMetadataByDiscordId($discordId: String!) {
|
||||
guild_metadata(where: { discord_id: { _eq: $discordId } }) {
|
||||
guild_id
|
||||
creator_id
|
||||
guild(where: { discord_id: { _eq: $discordId } }) {
|
||||
id
|
||||
discord_id
|
||||
discord_metadata
|
||||
guildname
|
||||
metadata {
|
||||
guild_id
|
||||
creator_id
|
||||
discord_metadata
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ export const playerRankUpdated = async (payload: TriggerPayload<Player>) => {
|
||||
const getGuildResponse = await client.GetGuildMetadataByDiscordId({
|
||||
discordId: Constants.METAFAM_DISCORD_GUILD_ID,
|
||||
});
|
||||
const rankDiscordRoleIds = getGuildResponse.guild_metadata[0]
|
||||
const rankDiscordRoleIds = getGuildResponse.guild[0].metadata
|
||||
?.discord_metadata?.rankRoleIds as RankRoleIds;
|
||||
|
||||
const discordPlayer = await guild.members.fetch(playerDiscordId);
|
||||
|
||||
@@ -51,7 +51,7 @@ export const playerRoleChanged = async (
|
||||
discordId: Constants.METAFAM_DISCORD_GUILD_ID,
|
||||
});
|
||||
const metadata: GuildDiscordMetadata =
|
||||
getGuildResponse.guild_metadata[0]?.discord_metadata;
|
||||
getGuildResponse.guild[0]?.metadata?.discord_metadata;
|
||||
const roleIds = metadata.playerRoles as RoleIds;
|
||||
|
||||
const discordPlayer = await guild.members.fetch(playerDiscordId);
|
||||
|
||||
5582
schema.graphql
5582
schema.graphql
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user