Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"react": "^19.0.0",
"react-dom": "^19.0.0",

"react-howler": "^5.2.0"
"react-howler": "^5.2.0",

"react-router-dom": "^7.5.2"

Expand Down
2 changes: 0 additions & 2 deletions client/src/components/screens/GameMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// src/components/screens/GameMap.tsx

// IMPORT LIBRARIES
import * as React from 'react';

import React, { useState } from 'react';

import { useNavigate } from 'react-router-dom';
Expand Down
59 changes: 54 additions & 5 deletions client/src/graphql/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,59 @@
import { gql } from '@apollo/client';

export const SUBMIT_ANSWER = gql`
mutation SubmitAnswer($questionId: ID!, $selectedOption: String!) {
submitAnswer(questionId: $questionId, selectedOption: $selectedOption) {
isCorrect
feedback
// Mutation to update player stats
export const UPDATE_STATS = gql`
mutation UpdateStats($isCorrect: Boolean!) {
updateStats(isCorrect: $isCorrect) {
correctAnswers
wrongAnswers
}
}
`;

// Mutation to login
export const LOGIN = gql`
mutation Login($email: String!, $password: String!) {
login(email: $email, password: $password) {
token
user {
_id
username
}
}
}
`;

// Mutation to add a new user
export const ADD_USER = gql`
mutation AddUser($input: UserInput!) {
addUser(input: $input) {
token
user {
_id
username
}
}
}
`;

// Mutation to create a new character
export const CREATE_CHARACTER = gql`
mutation CreateCharacter($name: String!, $picture: String!, $voice: String!) {
createCharacter(name: $name, picture: $picture, voice: $voice) {
_id
name
picture
voice
}
}
`;

// Mutation to delete a character
export const DELETE_CHARACTER = gql`
mutation DeleteCharacter($id: ID!) {
deleteCharacter(id: $id) {
_id
name
}
}
`;
19 changes: 15 additions & 4 deletions client/src/graphql/queries.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import { gql } from '@apollo/client';

export const GENERATE_QUESTIONS = gql`
query GenerateQuestion($track: String!, level: $level, minion: $minion) {
questions {
// Query to generate a new coding question
export const GENERATE_QUESTION = gql`
query GenerateQuestion($track: String!, $level: String!, $minion: String!) {
generateQuestion(track: $track, level: $level, minion: $minion) {
question
choices
answer
}
}
`;


// (Optional bonus if someone else pulls user stats for leaderboard)
export const ME = gql`
query Me {
me {
_id
username
correctAnswers
wrongAnswers
}
}
`;
130 changes: 0 additions & 130 deletions client/src/pages/CodezillaArena.tsx

This file was deleted.

11 changes: 11 additions & 0 deletions server/src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ interface IUser extends Document {
username: string;
email: string;
password: string;
correctAnswers: number;
wrongAnswers: number;
isCorrectPassword(password: string): Promise<boolean>;
}

Expand All @@ -29,6 +31,14 @@ const userSchema = new Schema<IUser>(
required: true,
minlength: 5,
},
correctAnswers: {
type: Number,
default: 0,
},
wrongAnswers: {
type: Number,
default: 0,
},
},
{
timestamps: true,
Expand All @@ -53,3 +63,4 @@ userSchema.methods.isCorrectPassword = async function (password: string): Promis
const User = model<IUser>('User', userSchema);

export default User;

28 changes: 14 additions & 14 deletions server/src/schemas/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const resolvers = {
}
throw new AuthenticationError('You need to be logged in!');
},
<<<<<<< HEAD
generateQuestion: async (_parent: any, args: { track: string; level: string; minion: string }) => {
const { track, level, minion } = args;
const prompt = PromptBuilder.getPrompt(track, level);
Expand Down Expand Up @@ -59,19 +58,6 @@ const resolvers = {
answer: fallback.choices[fallback.correctIndex],
};
}
=======
users: async () => {
return await User.find();
},
user: async (_: any, { username }: { username: string }) => {
return await User.findOne({ username });
},
characters: async () => {
return await Character.find();
},
character: async (_: any, { id }: { id: string }) => {
return await Character.findById(id);
>>>>>>> d7567a5c20d729e2d5c004a2d70be9176db8ea33
},
},

Expand Down Expand Up @@ -104,6 +90,20 @@ const resolvers = {
deleteCharacter: async (_: any, { id }: { id: string }) => {
return await Character.findByIdAndDelete(id);
},
updateStats: async (_parent: any, { isCorrect }: { isCorrect: boolean }, context: any) => {
if (!context.user) {
throw new AuthenticationError('You need to be logged in!');
}

const update = isCorrect
? { $inc: { correctAnswers: 1 } }
: { $inc: { wrongAnswers: 1 } };

const user = await User.findByIdAndUpdate(context.user._id, update, { new: true });

return user;
},

},
};

Expand Down
17 changes: 1 addition & 16 deletions server/src/schemas/typeDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ const typeDefs = gql`
password: String!
}

<<<<<<< HEAD
=======
type Character {
_id: ID!
name: String!
picture: String!
voice: String!
}

>>>>>>> d7567a5c20d729e2d5c004a2d70be9176db8ea33
type Auth {
token: ID!
user: User
Expand All @@ -41,20 +31,15 @@ const typeDefs = gql`
users: [User]
user(username: String!): User
me: User
<<<<<<< HEAD
generateQuestion(track: String!, level: String!, minion: String!): Question
=======
updateStats(isCorrect: Boolean!): User
characters: [Character]
character(id: ID!): Character
>>>>>>> d7567a5c20d729e2d5c004a2d70be9176db8ea33
}

type Mutation {
addUser(input: UserInput!): Auth
login(email: String!, password: String!): Auth
createCharacter(name: String!, picture: String!, voice: String!): Character
deleteCharacter(id: ID!): Character
updateStats(isCorrect: Boolean!): User
}
`;

Expand Down
6 changes: 0 additions & 6 deletions server/src/utils/PromptBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<<<<<<< HEAD
import { FallbackQuestion, fallbackQuestion } from "../utils/fallbackQuestions";
=======

import { FallbackQuestion, fallbackQuestion } from "../utils/fallbackQuestions";

>>>>>>> d7567a5c20d729e2d5c004a2d70be9176db8ea33

export class PromptBuilder {
/**
Expand Down
Loading