diff --git a/src/db/ClimbTypes.ts b/src/db/ClimbTypes.ts index 0647232e..7882aa43 100644 --- a/src/db/ClimbTypes.ts +++ b/src/db/ClimbTypes.ts @@ -27,7 +27,7 @@ export type ClimbGQLQueryType = ClimbType & { * Clinbs have a number of fields that may be expected to appear within their documents. */ export type ClimbType = IClimbProps & { - pitches?: IPitch + pitches?: IPitch[] metadata: IClimbMetadata content?: IClimbContent } @@ -35,7 +35,7 @@ export type ClimbType = IClimbProps & { /* Models a single pitch of a multi-pitch route */ export interface IPitch { _id: MUUID - parent_id: MUUID + parent_id: string number: number grades?: Partial> type?: DisciplineType @@ -175,6 +175,8 @@ export interface IPitchInput { description?: string; } + + export interface ClimbChangeInputType { id?: string name?: string @@ -194,6 +196,9 @@ export interface ClimbChangeInputType { } } +// Includes all properties of IPitchInput except for id and parent_id +export type UpdatablePitchInput = Omit; + type UpdatableClimbFieldsType = { fa: ClimbType['fa'], name: ClimbType['name'], @@ -203,7 +208,7 @@ type UpdatableClimbFieldsType = { content: ClimbType['content'], length: ClimbType['length'], boltsCount: ClimbType['boltsCount'], - pitches: IPitchInput[], + pitches: UpdatablePitchInput[], } /** * Minimum required fields when adding a new climb or boulder problem diff --git a/src/model/MutableClimbDataSource.ts b/src/model/MutableClimbDataSource.ts index 02c897ef..1190e3ed 100644 --- a/src/model/MutableClimbDataSource.ts +++ b/src/model/MutableClimbDataSource.ts @@ -136,14 +136,14 @@ export default class MutableClimbDataSource extends ClimbDataSource { const pitches = userInput[i].pitches const newPitchesWithIDs = pitches != null - ? pitches.map(pitch => ({ + ? pitches.map((pitch): IPitch => ({ ...pitch, _id: muid.from(pitch.id ?? muid.v4()), - parent_id: muid.from(pitch.parent_id ?? newClimbIds[i]) + parent_id: muid.from(pitch.parent_id ?? newClimbIds[i]).toString(), + number: pitch.number ?? 0 // revert to 0 if number cannot be retrieved })) - : null; + : null; - const { description, location, protection, name, fa, length, boltsCount } = userInput[i] // Make sure we don't update content = {} diff --git a/src/model/__tests__/MutableClimbDataSource.ts b/src/model/__tests__/MutableClimbDataSource.ts index a723aa0e..73615e82 100644 --- a/src/model/__tests__/MutableClimbDataSource.ts +++ b/src/model/__tests__/MutableClimbDataSource.ts @@ -567,10 +567,10 @@ describe('Climb CRUD', () => { } // Store original pitch IDs and parent IDs - const originalPitch1ID = original.pitches[0]._id.toUUID().toString(); - const originalPitch1ParentID = original.pitches[0].parent_id.toUUID().toString(); - const originalPitch2ID = original.pitches[1]._id.toUUID().toString(); - const originalPitch2ParentID = original.pitches[1].parent_id.toUUID().toString(); + const originalPitch1ID = original.pitches[0]._id.toUUID().toString() + const originalPitch1ParentID = original.pitches[0].parent_id + const originalPitch2ID = original.pitches[1]._id.toUUID().toString() + const originalPitch2ParentID = original.pitches[1].parent_id const updatedPitch1 = { _id: originalPitch1ID, @@ -608,19 +608,19 @@ describe('Climb CRUD', () => { // Check if 'actual' is not null before accessing its properties if (actual) { -/* // Validate that the climb is updated correctly + // Validate that the climb is updated correctly expect(actual).toMatchObject({ name: actual.name, // Assuming the name did not change type: actual.type, // Assuming the type did not change pitches: changes[0].pitches // The pitches should now match the updated pitches - }); */ + }); // Check that the pitches.id and pitches.parent_id are identical to the original values if (actual.pitches) { expect(actual.pitches[0]._id.toUUID().toString()).toEqual(originalPitch1ID); - expect(actual.pitches[0].parent_id.toUUID().toString()).toEqual(originalPitch1ParentID); + expect(actual.pitches[0].parent_id).toEqual(originalPitch1ParentID); expect(actual.pitches[1]._id.toUUID().toString()).toEqual(originalPitch2ID); - expect(actual.pitches[1].parent_id.toUUID().toString()).toEqual(originalPitch2ParentID); + expect(actual.pitches[1].parent_id).toEqual(originalPitch2ParentID); } // Check that the createdBy and updatedBy fields are not undefined before accessing their properties