Skip to content

Commit

Permalink
fix: use Lead Style from MP tick import instead of Style (#1259)
Browse files Browse the repository at this point in the history
* convert 'Fell/Hung' to 'Attempt' since thats what OB uses
* add .tool-versions to gitignore for anyone using asdf
* somewhat complicated logic for other edge cases
* references md document in openbeta-graphql for ease
  of understanding the logic
  • Loading branch information
glassbead0 authored Feb 5, 2025
1 parent f26c453 commit aa7c9cb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,8 @@ content
*.pem
.vscode/launch.json

# for anyone using asdf
.tool-versions

.lighthouseci
.idea/
37 changes: 32 additions & 5 deletions src/app/api/user/bulkImportTicks/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export interface Tick {
notes: string
climbId: string
userId: string | undefined
style: string | null
attemptType: string | null
style: string | undefined
attemptType: string | undefined
dateClimbed: Date
grade: string
source: string
Expand Down Expand Up @@ -61,7 +61,7 @@ interface MPTick {
async function getMPTicks (profileUrl: string): Promise<MPTick[]> {
const mpClient: AxiosInstance = axios.create({
baseURL: 'https://www.mountainproject.com/user',
timeout: 60000
timeout: 180000
})
const res = await mpClient.get(`${profileUrl}/tick-export`)
if (res.status === 200) {
Expand All @@ -78,6 +78,33 @@ async function getMPTicks (profileUrl: string): Promise<MPTick[]> {
return []
}

// See [Tick Logic](https://github.com/OpenBeta/openbeta-graphql/blob/develop/documentation/tick_logic.md) for info on all the logic in this file.
function trueBoulderTick (style: string, leadStyle: string, routeType: string): boolean {
return routeType.includes('Boulder') && ((leadStyle ?? '') === '') && ['Flash', 'Send', 'Attempt'].includes(style)
}

function convertMPattemptType (style: string, leadStyle: string, routeType: string): string | undefined {
if (trueBoulderTick(style, leadStyle, routeType)) {
return style === '' ? undefined : style
} else {
switch (leadStyle) {
case '':
return undefined
case 'Fell/Hung':
return 'Attempt'
default:
return leadStyle
}
}
}

function convertMPTickStyle (style: string, leadStyle: string, routeType: string): string | undefined {
if (trueBoulderTick(style, leadStyle, routeType)) {
return 'Boulder'
} else {
return style === '' ? undefined : style
}
}
const postHandler = async (req: NextRequest): Promise<any> => {
const uuid = req.headers.get(PREDEFINED_HEADERS.user_uuid)
const auth0Userid = req.headers.get(PREDEFINED_HEADERS.auth0_id)
Expand All @@ -99,8 +126,8 @@ const postHandler = async (req: NextRequest): Promise<any> => {
notes: tick.Notes,
climbId: tick.mp_id,
userId: uuid,
style: tick.Style === '' ? null : tick.Style,
attemptType: tick['Lead Style'] === '' ? null : tick['Lead Style'],
style: convertMPTickStyle(tick.Style, tick['Lead Style'], tick['Route Type']),
attemptType: convertMPattemptType(tick.Style, tick['Lead Style'], tick['Route Type']),
dateClimbed: new Date(Date.parse(`${tick.Date}T00:00:00`)), // Date.parse without timezone specified converts date to user's present timezone.
grade: tick.Rating,
source: 'MP'
Expand Down

0 comments on commit aa7c9cb

Please sign in to comment.