Added trigger for player.rank update

This commit is contained in:
Alec LaLonde
2021-02-11 16:02:20 -07:00
parent 4d59ac3f1b
commit 4f020fe0c3
7 changed files with 49 additions and 2 deletions

View File

@@ -3,9 +3,11 @@ import { ParamsDictionary } from 'express-serve-static-core';
import { fetchBoxVerifiedAccounts } from './fetchBoxVerifiedAccounts';
import { TriggerPayload } from './types';
import { updateDiscordRole } from './updateDiscordRole';
const TRIGGERS = {
fetchBoxVerifiedAccounts,
updateDiscordRole
};
export const triggerHandler = async (

View File

@@ -0,0 +1,24 @@
import { UpdateRole } from '@metafam/discord-bot';
import { AccountType_Enum, Player } from '../../lib/autogen/hasura-sdk';
import { TriggerPayload } from './types';
export const updateDiscordRole = async (
payload: TriggerPayload<Player>,
) => {
const {old: oldPlayer, new: newPlayer} = payload.event.data;
const discordPlayerAccount = newPlayer?.Accounts.find(a => a.type === AccountType_Enum.Discord);
if (discordPlayerAccount?.identifier == null) return;
const newRank = newPlayer?.rank;
if (newRank == null) return;
const discordPayload: UpdateRole = {
previousRole: oldPlayer?.rank?.toString(),
newRole: newRank
}
// todo call API in discord-bot repo
};