brenapp / robotevents

RobotEvents v2 API Module
https://npm.im/robotevents
15 stars 5 forks source link

match.teamOutcome(team.number) returing undefined... #21

Closed Adam-Salem-Codes closed 1 month ago

Adam-Salem-Codes commented 4 months ago

Hello, I'm using Next.js (typescript), and I was trying to write an API for my frontend to access the team data and match outcomes. For some reason, using the example code (record.ts) doesn't work. I've isolated the problem to the function match.teamOutcome(team.number)

I've also tested this with an express.js server and it gave me the same results.

import { NextResponse } from "next/server";
import * as robotevents from "robotevents";

robotevents.authentication.setBearer(
  ...
);

export async function GET(request: Request) {
  const program = "V5RC";

  const number = request.url.slice(request.url.lastIndexOf("/") + 1);

  const team = await robotevents.teams.get(number, program);

  if (!team) {
    console.log(`Could not find ${team} in ${program}`);
    return;
  }

  const events = await team.events({
    season: [robotevents.seasons.get(program, "2023-2024")!],
  });

  const ids = events.array().map(e => e.id);

  const matches = await team.matches({ event: ids });

  const outcomes = matches.group(match => match.teamOutcome(team.number));

  const matchesByEvent = matches.group(match => match.event.name)

  console.log(outcomes.win?.length) // returns undefined... 

  return NextResponse.json({ team: team, events: events, matches: matches });
}

export async function POST() {}
brenapp commented 3 months ago

Hey @Adam-Salem-Codes!

Not sure which method is returning MatchData instead of Match, I will investigate that later this week. For now, you can use the Match constructor like below. The library should be doing this automatically.

const match = new Match(matchData);
brenapp commented 1 month ago

Fixed in v6.0.0 - this is a significant breaking update.