Skip to content

Commit

Permalink
Fix TBD teams in getEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
gigobyte committed Mar 2, 2021
1 parent 77ea0b3 commit 9e8dc50
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/endpoints/getEvent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FullEvent } from '../models/FullEvent'
import { EventTeam, FullEvent } from '../models/FullEvent'
import { HLTVConfig } from '../config'
import {
fetchPage,
Expand All @@ -9,6 +9,8 @@ import {
import { popSlashSource } from '../utils/parsing'
import { checkForRateLimiting } from '../utils/checkForRateLimiting'

const notNull = <T>(x: T | null): x is T => x !== null

export const getEvent = (config: HLTVConfig) => async ({
id
}: {
Expand All @@ -34,16 +36,25 @@ export const getEvent = (config: HLTVConfig) => async ({
code: popSlashSource($('img.flag'))!.split('.')[0]
}

const teams = toArray($('.team-box')).map((teamEl) => ({
name: teamEl.find('.logo').attr('title')!,
id:
Number(teamEl.find('.team-name a').attr('href')!.split('/')[2]) ||
undefined,
reasonForParticipation: teamEl.find('.sub-text').text().trim() || undefined,
rankDuringEvent:
Number(teamEl.find('.event-world-rank').text().replace('#', '')) ||
undefined
}))
const teams: EventTeam[] = toArray($('.team-box'))
.map((teamEl) => {
if (!teamEl.find('.team-name a').length) {
return null
}

return {
name: teamEl.find('.logo').attr('title')!,
id:
Number(teamEl.find('.team-name a').attr('href')!.split('/')[2]) ||
undefined,
reasonForParticipation:
teamEl.find('.sub-text').text().trim() || undefined,
rankDuringEvent:
Number(teamEl.find('.event-world-rank').text().replace('#', '')) ||
undefined
}
})
.filter(notNull)

const relatedEvents = toArray($('.related-event')).map((eventEl) => ({
name: eventEl.find('.event-name').text(),
Expand Down

0 comments on commit 9e8dc50

Please sign in to comment.