Skip to content

Commit

Permalink
Add FA & length field to updateClimbs mutation (#243)
Browse files Browse the repository at this point in the history
* feat: support FA & length update
* test: unit test length & fa updates
* docs: update climbs mutation

---------

Co-authored-by: viet nguyen <vietnguyen@noreply>
  • Loading branch information
vnugent and viet nguyen authored Mar 12, 2023
1 parent bd83c94 commit 81243e0
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/db/ClimbTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export interface IClimbProps {
/** First ascent, if known. Who was the first person to climb this route? */
fa?: string
yds?: string

/** Total length in metersif known. We will support individual pitch lenth in the future. */
length?: number
/**
* Grades appear within as an I18n-safe format.
* We achieve this via a larger data encapsulation, and perform interpretation and comparison
Expand Down Expand Up @@ -149,11 +152,11 @@ export interface ClimbChangeInputType {
description?: string
location?: string
protection?: string
fa?: string
length?: number
}

// export type ClimbDBChangeType = ClimbChangeInputType

type UpdatableClimbFieldsType = Pick<ClimbType, 'fa'|'name'|'type' | 'gradeContext' |'grades' | 'content'>
type UpdatableClimbFieldsType = Pick<ClimbType, 'fa' | 'name' | 'type' | 'gradeContext' | 'grades' | 'content' | 'length'>
/**
* Minimum required fields when adding a new climb or boulder problem
*/
Expand Down
2 changes: 2 additions & 0 deletions src/graphql/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ const resolvers = {

yds: (node: ClimbGQLQueryType) => node.yds ?? null,

length: (node: ClimbGQLQueryType) => node.length ?? -1,

grades: (node: ClimbGQLQueryType) => node.grades ?? null,

metadata: (node: ClimbGQLQueryType) => ({
Expand Down
4 changes: 4 additions & 0 deletions src/graphql/schema/Climb.gql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ type Climb {
name: String!
"First ascent, if known. Who was the first person to climb this route?"
fa: String

"Total length in meters if known (-1 otherwise)"
length: Int!

"The grade(s) assigned to this climb. See GradeType documentation"
grades: GradeType

Expand Down
21 changes: 19 additions & 2 deletions src/graphql/schema/ClimbEdit.gql
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
type Mutation {
"""
Create or update one or more climbs.
"""
updateClimbs(input: UpdateClimbsInput): [ID]
}

type Mutation {
"""
Delete one or more climbs
"""
deleteClimbs(input: DeleteManyClimbsInput): Int
}

Expand All @@ -11,12 +15,21 @@ input DeleteManyClimbsInput {
idList: [ID]
}

"""
Create/update climbs input parameter.
"""
input UpdateClimbsInput {
"Parent area ID"
parentId: ID!
"Array of change records"
changes: [SingleClimbChangeInput]
}

"""
Climb change record. If the climb ID is omitted or does not exist in the database, a new climb will be created.
"""
input SingleClimbChangeInput {
"Climb UUID"
id: ID
name: String
disciplines: DisciplineType
Expand All @@ -25,6 +38,10 @@ input SingleClimbChangeInput {
description: String
location: String
protection: String
"Legacy FA data"
fa: String
"Length in meters"
length: Int
}

input DisciplineType {
Expand Down
4 changes: 3 additions & 1 deletion src/model/MutableClimbDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default class MutableClimbDataSource extends ClimbDataSource {
? createGradeObject(grade, typeSafeDisciplines, cragGradeScales)
: null

const { description, location, protection, name } = userInput[i]
const { description, location, protection, name, fa, length } = userInput[i]

// Make sure we don't update content = {}
// See https://www.mongodb.com/community/forums/t/mongoservererror-invalid-set-caused-by-an-empty-object-is-not-a-valid-value/148344/2
Expand All @@ -131,6 +131,8 @@ export default class MutableClimbDataSource extends ClimbDataSource {
...newGradeObj != null && { grades: newGradeObj },
...typeSafeDisciplines != null && { type: typeSafeDisciplines },
gradeContext: parent.gradeContext,
...fa != null && { fa },
...length != null && length > 0 && { length },
content: Object.keys(content).length === 0 ? undefined : content,
metadata: {
areaRef: parent.metadata.area_id,
Expand Down
32 changes: 32 additions & 0 deletions src/model/__tests__/MutableClimbDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,36 @@ describe('Climb CRUD', () => {
expect(actual1?.createdBy?.toUUID().toString()).toEqual(testUser.toUUID().toString())
expect(actual1?.updatedBy?.toUUID().toString()).toEqual(otherUser.toUUID().toString())
})

it('can update climb length & fa', async () => {
const newDestination = await areas.addArea(testUser, 'Sport area Z100', null, 'fr')

if (newDestination == null) fail('Expect new area to be created')

const newIDs = await climbs.addOrUpdateClimbs(
testUser,
newDestination.metadata.area_id,
newClimbsToAdd
)

const change: ClimbChangeInputType = {
id: newIDs[0],
fa: 'First name Last name, 2023',
length: 20
}

await climbs.addOrUpdateClimbs(testUser,
newDestination.metadata.area_id,
[change])

const actual = await climbs.findOneClimbByMUUID(muid.from(newIDs[0]))

expect(actual?.fa).not.toBeNull()
expect(actual?.length).not.toBeNull()

expect(actual).toMatchObject({
fa: change.fa,
length: change.length
})
})
})

0 comments on commit 81243e0

Please sign in to comment.