Skip to content

Commit

Permalink
Merge branch 'develop' into 339-bug-scroll-bar-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
vazquezea96 authored Jul 11, 2024
2 parents 05d8dd0 + 1df7007 commit 93bece9
Show file tree
Hide file tree
Showing 31 changed files with 554 additions and 178 deletions.
2 changes: 1 addition & 1 deletion api/apiFunctions.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// Licensed under the MIT License.

export enum Collection {
ENTRIES = 'entries',
USERS = '6626c4fa8f793ae275ee',
LEAGUE = '6626a937b6302f6a4d28',
GAME_RESULTS = '66313025000612a5380e',
GAME_WEEK = '6622c701cb5a58fcdf06',
CURRENT_WEEK = 'current_week',
NFL_TEAMS = '662152bfabacfbda3bb3',
NFL_SCHEDULE_2024 = 'nfl_schedule_2024',
}

/**
Expand Down
18 changes: 8 additions & 10 deletions api/apiFunctions.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Gridiron Survivor.
// Licensed under the MIT License.

import { IEntry } from '@/app/league/[leagueId]/entry/Entries.interface';

export interface IAccountData {
email: string;
password: string;
Expand All @@ -12,8 +14,10 @@ export interface IUser {
}
export interface IUserPick {
[userId: string]: {
team: string;
correct: boolean;
[entryId: IEntry['$id']]: {
teamName: string;
correct: boolean;
};
};
}
export interface IDeleteUser {
Expand All @@ -22,19 +26,13 @@ export interface IDeleteUser {
export interface IWeeklyPicks {
leagueId: string;
gameWeekId: string;
userResults: IUserPicksData | null;
userResults: IUserPicksData;
}
export interface INFLTeam {
teamId: string;
teamName: string;
teamLogo: string;
}
export interface IUserPicksData {
[key: string]: {
team: string;
correct: boolean;
};
}
export interface IUserPicksData extends IUserPick {}
export interface ILeague {
leagueId: string;
leagueName: string;
Expand Down
71 changes: 70 additions & 1 deletion api/apiFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import {
} from './apiFunctions.interface';
import { Collection, Document } from './apiFunctions.enum';
import { Query } from 'appwrite';
import {
IEntry,
IEntryProps,
} from '@/app/league/[leagueId]/entry/Entries.interface';

/**
* Register a new account
Expand Down Expand Up @@ -88,6 +92,38 @@ export async function getCurrentUser(userId: IUser['id']): Promise<IUser> {
}
}

/**
* Get all the leagues the user is a part of
* @param userId - The user Id
* @param leagueId - The league Id
* @returns {IEntry[] | Error} - The list of entries or an error
*/
export async function getCurrentUserEntries(
userId: IUser['id'],
leagueId: ILeague['leagueId'],
): Promise<IEntry[]> {
try {
const response = await databases.listDocuments(
appwriteConfig.databaseId,
Collection.ENTRIES,
[Query.equal('user', userId), Query.equal('league', leagueId)],
);

const entries = response.documents.map((entry) => ({
$id: entry.$id,
name: entry.name,
user: entry.user,
league: entry.league,
selectedTeams: entry.selectedTeams,
}));

return entries;
} catch (error) {
console.error(error);
throw new Error('Error getting user entries');
}
}

/**
* Get all NFL teams
* @returns {INFLTeam | Error} - The list of NFL teams
Expand All @@ -97,12 +133,12 @@ export const getNFLTeams = async (): Promise<INFLTeam[]> => {
const response = await databases.listDocuments(
appwriteConfig.databaseId,
Collection.NFL_TEAMS,
[Query.limit(32)],
);

const nflTeams = response.documents.map((team) => ({
teamId: team.$id,
teamName: team.teamName,
teamLogo: team.teamLogo,
}));

return nflTeams;
Expand Down Expand Up @@ -230,3 +266,36 @@ export async function createWeeklyPicks({
throw new Error('Error creating weekly picks');
}
}

/**
* Create a new entry
* @param props - The entry data
* @param props.name - The name of the entry
* @param props.user - The user ID
* @param props.league - The league ID
* @param props.selectedTeams - The selected teams
* @returns {Models.Document | Error} - The entry object or an error
*/
export async function createEntry({
name,
user,
league,
selectedTeams = [],
}: IEntryProps): Promise<Models.Document & IEntry> {
try {
return await databases.createDocument(
appwriteConfig.databaseId,
Collection.ENTRIES,
ID.unique(),
{
name,
user,
league,
selectedTeams,
},
);
} catch (error) {
console.error(error);
throw new Error('Error creating entry');
}
}
3 changes: 3 additions & 0 deletions api/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Gridiron Survivor.
// Licensed under the MIT License.

import { Client, Account, Databases, ID } from 'appwrite';

const URL = process.env.NEXT_PUBLIC_APPWRITE_API_URL as string;
Expand Down
3 changes: 3 additions & 0 deletions api/serverConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Gridiron Survivor.
// Licensed under the MIT License.

import * as sdk from 'node-appwrite';

const URL = process.env.NEXT_PUBLIC_APPWRITE_API_URL as string;
Expand Down
33 changes: 0 additions & 33 deletions app/League-Entries/page.tsx

This file was deleted.

19 changes: 19 additions & 0 deletions app/league/[leagueId]/entry/Entries.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Gridiron Survivor.
// Licensed under the MIT License.

import { ILeague, INFLTeam, IUser } from '@/api/apiFunctions.interface';

export interface IEntry {
$id: string;
name: string;
user: IUser;
league: ILeague;
selectedTeams: INFLTeam[];
}

export interface IEntryProps {
name: string;
user: IUser['id'];
league: ILeague['leagueId'];
selectedTeams?: INFLTeam[];
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Gridiron Survivor.
// Licensed under the MIT License.

import { INFLTeam } from '@/api/apiFunctions.interface';
import { INFLTeam, ILeague } from '@/api/apiFunctions.interface';

export interface IWeekParams {
params: {
Expand All @@ -13,7 +13,7 @@ export interface IWeekParams {

export interface IWeekProps {
entry: string;
league: string;
league: ILeague['leagueId'];
NFLTeams: INFLTeam[];
week: string;
}
Loading

0 comments on commit 93bece9

Please sign in to comment.