Skip to content

Commit

Permalink
Add boltsCount field (#323)
Browse files Browse the repository at this point in the history
* add boltsCount field
  • Loading branch information
l4u532 authored Jul 3, 2023
1 parent ecde57c commit 7191b15
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/db/ClimbSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const ClimbSchema = new Schema<ClimbType>({
enum: Object.values(SafetyType),
required: true
},
boltsCount: { type: Schema.Types.Number, required: false },
metadata: MetadataSchema,
content: ContentSchema,
_deleting: { type: Date },
Expand Down
6 changes: 5 additions & 1 deletion src/db/ClimbTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export interface IClimbProps {

/** Total length in metersif known. We will support individual pitch lenth in the future. */
length?: number
/** Total number of bolts (fixed anchors) */
boltsCount?: 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 @@ -112,6 +114,7 @@ export interface DisciplineType {
snow?: boolean
/** https://en.wikipedia.org/wiki/Ice_climbing */
ice?: boolean
/** https://en.wikipedia.org/wiki/Mixed_climbing */
mixed?: boolean
/** https://en.wikipedia.org/wiki/Aid_climbing */
aid?: boolean
Expand Down Expand Up @@ -156,6 +159,7 @@ export interface ClimbChangeInputType {
description?: string
location?: string
protection?: string
boltsCount?: number
fa?: string
length?: number
experimentalAuthor?: {
Expand All @@ -164,7 +168,7 @@ export interface ClimbChangeInputType {
}
}

type UpdatableClimbFieldsType = Pick<ClimbType, 'fa' | 'name' | 'type' | 'gradeContext' | 'grades' | 'content' | 'length'>
type UpdatableClimbFieldsType = Pick<ClimbType, 'fa' | 'name' | 'type' | 'gradeContext' | 'grades' | 'content' | 'length' | 'boltsCount'>
/**
* 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 @@ -151,6 +151,8 @@ const resolvers = {

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

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

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

metadata: (node: ClimbGQLQueryType) => {
Expand Down
3 changes: 3 additions & 0 deletions src/graphql/schema/Climb.gql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ type Climb {
"Total length in meters if known (-1 otherwise)"
length: Int!

"Number of bolts/permanent anchors, if known (-1 otherwise)"
boltsCount: Int!

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

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

const { description, location, protection, name, fa, length } = userInput[i]
const { description, location, protection, name, fa, length, boltsCount } = 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 @@ -151,6 +151,7 @@ export default class MutableClimbDataSource extends ClimbDataSource {
gradeContext: parent.gradeContext,
...fa != null && { fa },
...length != null && length > 0 && { length },
...boltsCount != null && boltsCount > 0 && { boltsCount },
...Object.keys(content).length > 0 && { content },
metadata: {
areaRef: parent.metadata.area_id,
Expand Down
13 changes: 9 additions & 4 deletions src/model/__tests__/MutableClimbDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const newSportClimb1: ClimbChangeInputType = {
},
description: 'A good warm up problem',
location: 'Start from the left arete',
protection: '2 bolts'
protection: '2 bolts',
boltsCount: 2
}

describe('Climb CRUD', () => {
Expand Down Expand Up @@ -300,6 +301,7 @@ describe('Climb CRUD', () => {
const climb1 = await climbs.findOneClimbByMUUID(muid.from(newIDs[0]))
expect(climb1?.grades).toEqual({ ewbank: '17' })
expect(climb1?.type.sport).toBe(true)
expect(newSportClimb1?.boltsCount).toEqual(2)

const climb2 = await climbs.findOneClimbByMUUID(muid.from(newIDs[1]))
expect(climb2?.grades).toEqual({ ewbank: '29/30' })
Expand Down Expand Up @@ -437,7 +439,7 @@ describe('Climb CRUD', () => {
expect(actual1?.updatedBy?.toUUID().toString()).toEqual(otherUser.toUUID().toString())
})

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

if (newDestination == null) fail('Expect new area to be created')
Expand All @@ -451,7 +453,8 @@ describe('Climb CRUD', () => {
const change: ClimbChangeInputType = {
id: newIDs[0],
fa: 'First name Last name, 2023',
length: 20
length: 20,
boltsCount: 5
}

await climbs.addOrUpdateClimbs(testUser,
Expand All @@ -462,10 +465,12 @@ describe('Climb CRUD', () => {

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

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

0 comments on commit 7191b15

Please sign in to comment.