From 658af73fcbdee58b735d35735810296104948806 Mon Sep 17 00:00:00 2001 From: MTG2000 Date: Thu, 8 Sep 2022 09:52:50 +0300 Subject: [PATCH] feat: add base registration api --- api/functions/graphql/types/tournament.js | 59 ++++++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/api/functions/graphql/types/tournament.js b/api/functions/graphql/types/tournament.js index f1b3a49..cfb8d8c 100644 --- a/api/functions/graphql/types/tournament.js +++ b/api/functions/graphql/types/tournament.js @@ -5,7 +5,9 @@ const { extendType, nonNull, enumType, + inputObjectType, } = require('nexus'); +const { getUserByPubKey } = require('../../../auth/utils/helperFuncs'); const { prisma } = require('../../../prisma'); const { paginationArgs } = require('./helpers'); @@ -49,6 +51,15 @@ const TournamentEventTypeEnum = enumType({ }, }); +const TournamentMakerHackingStatusEnum = enumType({ + name: 'TournamentMakerHackingStatusEnum', + members: { + Solo: 0, + OpenToConnect: 1, + }, +}); + + const TournamentEvent = objectType({ name: 'TournamentEvent', @@ -319,14 +330,58 @@ const getProjectsInTournament = extendType({ } }) + + +const RegisterInTournamentInput = inputObjectType({ + name: 'RegisterInTournamentInput', + definition(t) { + t.nonNull.string('email') + t.nonNull.field('hacking_status', { type: TournamentMakerHackingStatusEnum }) + } +}) + + +const registerInTournament = extendType({ + type: 'Mutation', + definition(t) { + t.field('registerInTournament', { + type: 'boolean', + args: { data: RegisterInTournamentInput }, + async resolve(_root, { email, hacking_status }, ctx) { + const user = await getUserByPubKey(ctx.userPubKey); + + // Do some validation + if (!user) + throw new Error("You have to login"); + + + // Email verification here: + // .... + // .... + + prisma.tournamentParticipant.create({ + data:{ + + } + }) + + } + }) + }, +}) + module.exports = { // Types Tournament, + // Enums + TournamentEventTypeEnum, + // Queries getTournamentById, getMakersInTournament, getProjectsInTournament, - // Enums - TournamentEventTypeEnum, + // Mutations + registerInTournament, + } \ No newline at end of file