From 468f6bfaf78efb090ec0ce733d13863bf820681e Mon Sep 17 00:00:00 2001 From: Viet Nguyen <3805254+vnugent@users.noreply.github.com> Date: Tue, 30 Apr 2024 06:45:16 -0700 Subject: [PATCH] refactor: relax boulder-only crag check (#400) --- .vscode/settings.json | 4 ++- src/model/MutableClimbDataSource.ts | 25 +------------------ src/model/__tests__/MutableClimbDataSource.ts | 11 ++------ 3 files changed, 6 insertions(+), 34 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 541a13c..e5e150b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -15,5 +15,7 @@ "standard.treatErrorsAsWarnings": true, "javascript.format.enable": false, "javascript.format.semicolons": "remove", - "typescript.format.enable": false + "typescript.format.enable": false, + "prettier.enable": false, + "editor.defaultFormatter": "standard.vscode-standard" } \ No newline at end of file diff --git a/src/model/MutableClimbDataSource.ts b/src/model/MutableClimbDataSource.ts index 9ad85a7..4147a53 100644 --- a/src/model/MutableClimbDataSource.ts +++ b/src/model/MutableClimbDataSource.ts @@ -87,29 +87,6 @@ export default class MutableClimbDataSource extends ClimbDataSource { parent.metadata.leaf = true } - // is there at least 1 boulder problem in the input? - const hasBouldering = userInput.some(entry => entry.disciplines?.bouldering ?? false) - - // input has at least 1 boulder problem AND area is not a bouldering area - if (hasBouldering && !(parent.metadata?.isBoulder ?? false)) { - if (parent.climbs.length === 0) { - // if an area is empty, we're allowed to turn to into a bouldering area - parent.metadata.isBoulder = true - } else { - throw new UserInputError('Adding boulder problems to a route-only area is not allowed') - } - } - - // It's ok to have empty disciplines obj in the input in case - // we just want to update other fields. - // However, if disciplines is non-empty, is there 1 non-boulder problem in the input? - const hasARouteClimb = userInput.some(({ disciplines }) => - disciplines != null && Object.keys(disciplines).length > 0 && !(disciplines?.bouldering ?? false)) - - if (hasARouteClimb && (parent.metadata?.isBoulder ?? false)) { - throw new UserInputError('Adding route climbs to a bouldering area is not allowed') - } - const cragGradeScales = gradeContextToGradeScales[parent.gradeContext] if (cragGradeScales == null) { throw new Error(`Area ${parent.area_name} (${parent.metadata.area_id.toUUID().toString()}) has invalid grade context: '${parent.gradeContext}'`) @@ -219,7 +196,7 @@ export default class MutableClimbDataSource extends ClimbDataSource { } })) - const rs = await (await this.climbModel.bulkWrite(bulk, { session })).toJSON() + const rs = (await this.climbModel.bulkWrite(bulk, { session })).toJSON() if (rs.ok === 1) { const idList: MUUID[] = [] diff --git a/src/model/__tests__/MutableClimbDataSource.ts b/src/model/__tests__/MutableClimbDataSource.ts index 9fa8abe..16a5808 100644 --- a/src/model/__tests__/MutableClimbDataSource.ts +++ b/src/model/__tests__/MutableClimbDataSource.ts @@ -200,10 +200,8 @@ describe('Climb CRUD', () => { climbs.addOrUpdateClimbs(testUser, newDestination.metadata.area_id, [newBoulderProblem1]) ).rejects.toThrowError(/You can only add climbs to a crag/) - // Route-only area should not accept new boulder problems - await expect( - climbs.addOrUpdateClimbs(testUser, routesArea.metadata.area_id, [newBoulderProblem1]) - ).rejects.toThrowError(/Adding boulder problems to a route-only area/) + // Route-only area should accept new boulder problems + await climbs.addOrUpdateClimbs(testUser, routesArea.metadata.area_id, [newBoulderProblem1]) }) it('can add new boulder problems', async () => { @@ -227,11 +225,6 @@ describe('Climb CRUD', () => { if (newClimb == null) fail('Expecting new boulder problem to be added, but didn\'t find one') expect(newClimb.name).toBe(newBoulderProblem1.name) - - // Adding a boulder problem into an empty area will set isBoulder flag - const updatedArea = await areas.findOneAreaByUUID(boulderingArea.metadata.area_id) - if (updatedArea == null) fail('Expect area to be non-null') - expect(updatedArea.metadata.isBoulder).toBeTruthy() }) it('can delete new boulder problems', async () => {