Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get event results #165

Merged
merged 4 commits into from May 3, 2019
Merged

Get event results #165

merged 4 commits into from May 3, 2019

Conversation

Chuli2k
Copy link
Contributor

@Chuli2k Chuli2k commented Apr 29, 2019

Simirally to filtering by teamId, I added a parameter for events. I also changed how the Event data is filled and how the date-time is found, because the results page of events has a bit different layout

I also reset the pages parameter to 1 if the eventId parameter is passed. That's because all the results for events are show on one page. For example: event=3047 has 220 results...
Maybe they have a limit of 500 or something, but I didn't find any events that have that many results :)

This PR is related to issue #124.

I did a new branch from master, so the teamId parameter is not included... But it should not be difficult to merge both.

@Chuli2k
Copy link
Contributor Author

Chuli2k commented Apr 29, 2019

I can also add a eventId parameter to the getMatches endpoint and it should filter by event. But you mentioned, that it should remain just for the main page matches. So it's your choice :)
If I add this then #124 should be covered...

@@ -6,19 +6,35 @@ import { popSlashSource } from '../utils/parsing'
import { HLTVConfig } from '../config'
import { fetchPage, toArray, getMatchFormatAndMap } from '../utils/mappers'

export const getResults = (config: HLTVConfig) => async ({ pages = 1 } = {}): Promise<
export const getResults = (config: HLTVConfig) => async ({ pages = 1, eventId = 0 } = {}): Promise<
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the default to 0 needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's not... I'll remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean I should set it to undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cheated and looked at how emha did it for teamId in his PR and made the same changes :)
I'm still new to typescript and didn't know how to remove the default value...

@@ -48,11 +64,21 @@ export const getResults = (config: HLTVConfig) => async ({ pages = 1 } = {}): Pr
}

const event: Event = {
name: matchEl.find('.event-logo').attr('alt'),
id: Number(popSlashSource(matchEl.find('.event-logo'))!.split('.')[0])
name: eventId ? eventName : matchEl.find('.event-logo').attr('alt'),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just put the implementation of eventName here? Instead of:

let eventName: string

if(eventId) {
  eventName = $('.eventname').text()
}

name: eventId ? eventName : matchEl.find('.event-logo').attr('alt')

just

name: eventId ? $('.eventname').text() : matchEl.find('.event-logo').attr('alt')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want it inside the for loop. This way if you filter by eventid it is resolved only once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so I was on my phone and missed, that I had it insode the for loop. I wanted to set it outside, but for the events it will only get one page, so setting it outside the loop is irrelevant :P
I did it as you suggested.

@gigobyte
Copy link
Owner

gigobyte commented May 3, 2019

I've left some comments, but otherwise looks good!

@gigobyte gigobyte merged commit c8cacaf into gigobyte:master May 3, 2019
@Chuli2k Chuli2k deleted the GetEventResults branch May 3, 2019 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants