feat: update my hacking_status, filter by hacking status, allow optional fields in inputArgs

This commit is contained in:
MTG2000
2022-09-09 12:14:56 +03:00
parent 64d8263ae6
commit 329ecf3b60
9 changed files with 228 additions and 24 deletions

View File

@@ -64,6 +64,10 @@ export interface NexusGenInputs {
tags: string[]; // [String!]!
title: string; // String!
}
UpdateTournamentRegistrationInput: { // input type
email?: string | null; // String
hacking_status?: NexusGenEnums['TournamentMakerHackingStatusEnum'] | null; // TournamentMakerHackingStatusEnum
}
UserKeyInputType: { // input type
key: string; // String!
name: string; // String!
@@ -194,6 +198,7 @@ export interface NexusGenObjects {
}
ParticipationInfo: { // root type
createdAt: NexusGenScalars['Date']; // Date!
email: string; // String!
hacking_status: NexusGenEnums['TournamentMakerHackingStatusEnum']; // TournamentMakerHackingStatusEnum!
}
PostComment: { // root type
@@ -445,6 +450,7 @@ export interface NexusGenFieldTypes {
registerInTournament: NexusGenRootTypes['User'] | null; // User
updateProfileDetails: NexusGenRootTypes['MyProfile'] | null; // MyProfile
updateProfileRoles: NexusGenRootTypes['MyProfile'] | null; // MyProfile
updateTournamentRegistration: NexusGenRootTypes['ParticipationInfo'] | null; // ParticipationInfo
updateUserPreferences: NexusGenRootTypes['MyProfile']; // MyProfile!
vote: NexusGenRootTypes['Vote']; // Vote!
}
@@ -475,6 +481,7 @@ export interface NexusGenFieldTypes {
}
ParticipationInfo: { // field return type
createdAt: NexusGenScalars['Date']; // Date!
email: string; // String!
hacking_status: NexusGenEnums['TournamentMakerHackingStatusEnum']; // TournamentMakerHackingStatusEnum!
}
PostComment: { // field return type
@@ -798,6 +805,7 @@ export interface NexusGenFieldTypeNames {
registerInTournament: 'User'
updateProfileDetails: 'MyProfile'
updateProfileRoles: 'MyProfile'
updateTournamentRegistration: 'ParticipationInfo'
updateUserPreferences: 'MyProfile'
vote: 'Vote'
}
@@ -828,6 +836,7 @@ export interface NexusGenFieldTypeNames {
}
ParticipationInfo: { // field return type name
createdAt: 'Date'
email: 'String'
hacking_status: 'TournamentMakerHackingStatusEnum'
}
PostComment: { // field return type name
@@ -1076,6 +1085,10 @@ export interface NexusGenArgTypes {
updateProfileRoles: { // args
data?: NexusGenInputs['ProfileRolesInput'] | null; // ProfileRolesInput
}
updateTournamentRegistration: { // args
data?: NexusGenInputs['UpdateTournamentRegistrationInput'] | null; // UpdateTournamentRegistrationInput
tournament_id: number; // Int!
}
updateUserPreferences: { // args
userKeys?: NexusGenInputs['UserKeyInputType'][] | null; // [UserKeyInputType!]
}
@@ -1112,6 +1125,7 @@ export interface NexusGenArgTypes {
project_id: number; // Int!
}
getMakersInTournament: { // args
openToConnect?: boolean | null; // Boolean
roleId?: number | null; // Int
search?: string | null; // String
skip?: number | null; // Int

View File

@@ -152,6 +152,7 @@ type Mutation {
registerInTournament(data: RegisterInTournamentInput, tournament_id: Int!): User
updateProfileDetails(data: ProfileDetailsInput): MyProfile
updateProfileRoles(data: ProfileRolesInput): MyProfile
updateTournamentRegistration(data: UpdateTournamentRegistrationInput, tournament_id: Int!): ParticipationInfo
updateUserPreferences(userKeys: [UserKeyInputType!]): MyProfile!
vote(amount_in_sat: Int!, item_id: Int!, item_type: VOTE_ITEM_TYPE!): Vote!
}
@@ -190,6 +191,7 @@ enum POST_TYPE {
type ParticipationInfo {
createdAt: Date!
email: String!
hacking_status: TournamentMakerHackingStatusEnum!
}
@@ -261,7 +263,7 @@ type Query {
getDonationsStats: DonationsStats!
getFeed(skip: Int = 0, sortBy: String, tag: Int = 0, take: Int = 10): [Post!]!
getLnurlDetailsForProject(project_id: Int!): LnurlDetails!
getMakersInTournament(roleId: Int, search: String, skip: Int = 0, take: Int = 10, tournamentId: Int!): TournamentMakersResponse!
getMakersInTournament(openToConnect: Boolean, roleId: Int, search: String, skip: Int = 0, take: Int = 10, tournamentId: Int!): TournamentMakersResponse!
getMyDrafts(type: POST_TYPE!): [Post!]!
getPostById(id: Int!, type: POST_TYPE!): Post!
getProject(id: Int!): Project!
@@ -420,6 +422,11 @@ type TournamentProjectsResponse {
projects: [Project!]!
}
input UpdateTournamentRegistrationInput {
email: String
hacking_status: TournamentMakerHackingStatusEnum
}
type User implements BaseUser {
avatar: String!
bio: String

View File

@@ -6,10 +6,11 @@ const {
nonNull,
enumType,
inputObjectType,
booleanArg,
} = require('nexus');
const { getUserByPubKey } = require('../../../auth/utils/helperFuncs');
const { prisma } = require('../../../prisma');
const { paginationArgs } = require('./helpers');
const { paginationArgs, removeNulls } = require('./helpers');
@@ -196,6 +197,7 @@ const ParticipationInfo = objectType({
name: "ParticipationInfo",
definition(t) {
t.nonNull.date('createdAt')
t.nonNull.string('email')
t.nonNull.field('hacking_status', { type: TournamentMakerHackingStatusEnum });
}
@@ -237,6 +239,7 @@ const getMakersInTournament = extendType({
...paginationArgs({ take: 10 }),
search: stringArg(),
roleId: intArg(),
openToConnect: booleanArg()
},
async resolve(_, args, ctx) {
@@ -271,12 +274,33 @@ const getMakersInTournament = extendType({
}
})
if (args.openToConnect) filters.push({
OR: [
{
github: {
not: null
}
},
{
twitter: {
not: null
}
},
{
linkedin: {
not: null
}
},
]
})
if (user?.id) filters.push({
id: {
not: user.id
}
})
const makers = (await prisma.tournamentParticipant.findMany({
where: {
tournament_id: args.tournamentId,
@@ -284,6 +308,9 @@ const getMakersInTournament = extendType({
user: {
AND: filters
}
}),
...(args.openToConnect && {
hacking_status: TournamentMakerHackingStatusEnum.value.members.OpenToConnect
})
},
orderBy: {
@@ -433,6 +460,50 @@ const registerInTournament = extendType({
},
})
const UpdateTournamentRegistrationInput = inputObjectType({
name: 'UpdateTournamentRegistrationInput',
definition(t) {
t.string('email')
t.field('hacking_status', { type: TournamentMakerHackingStatusEnum })
}
})
const updateTournamentRegistration = extendType({
type: 'Mutation',
definition(t) {
t.field('updateTournamentRegistration', {
type: ParticipationInfo,
args: {
data: UpdateTournamentRegistrationInput,
tournament_id: nonNull(intArg())
},
async resolve(_root, { tournament_id, data: { 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:
// ....
// ....
return prisma.tournamentParticipant.update({
where: {
tournament_id_user_id: { tournament_id, user_id: user.id }
},
data: removeNulls({
email,
hacking_status
}),
});
}
})
},
})
module.exports = {
// Types
Tournament,
@@ -448,5 +519,5 @@ module.exports = {
// Mutations
registerInTournament,
updateTournamentRegistration,
}