diff --git a/src/db/AreaSchema.ts b/src/db/AreaSchema.ts index e6582248..d4800a0e 100644 --- a/src/db/AreaSchema.ts +++ b/src/db/AreaSchema.ts @@ -62,7 +62,8 @@ const MetadataSchema = new Schema({ }, { _id: false }) const ContentSchema = new Schema({ - description: { type: Schema.Types.String } + description: { type: Schema.Types.String }, + areaLocation: { type: Schema.Types.String } }, { _id: false }) export const CountByGroup = new Schema({ diff --git a/src/db/AreaTypes.ts b/src/db/AreaTypes.ts index 7dad6116..b0837fa7 100644 --- a/src/db/AreaTypes.ts +++ b/src/db/AreaTypes.ts @@ -162,14 +162,15 @@ export interface IAreaMetadata { } export interface IAreaContent { - /** longform to mediumform description of this area. - * Remembering that areas can be the size of countries, or as precise as a single cliff/boulder, + /** longform to mediumform description and location of this area. + * Remembering that area descriptions can be the size of countries, or as precise as a single cliff/boulder, * there is not a single definition of valid content for this field. * * We expect users to make a call about whatever kind of context may be appropriate for this * entity, and may be pretty short to extremely detailed. */ description?: string + areaLocation?: string } /** Fields that may be directly modified by users. @@ -179,6 +180,7 @@ export interface IAreaContent { export interface AreaEditableFieldsType { areaName?: string description?: string + areaLocation?: string isDestination?: boolean isLeaf?: boolean isBoulder?: boolean diff --git a/src/db/import/usa/AreaTransformer.ts b/src/db/import/usa/AreaTransformer.ts index 7687c686..4b3815d5 100644 --- a/src/db/import/usa/AreaTransformer.ts +++ b/src/db/import/usa/AreaTransformer.ts @@ -110,7 +110,8 @@ export const makeDBArea = (node: AreaNode): AreaType => { density: 0, totalClimbs: 0, content: { - description: isLeaf ? (Array.isArray(node.jsonLine.description) ? node.jsonLine.description.join('\n\n') : '') : '' + description: isLeaf ? (Array.isArray(node.jsonLine.description) ? node.jsonLine.description.join('\n\n') : '') : '', + areaLocation: isLeaf ? (Array.isArray(node.jsonLine.areaLocation) ? node.jsonLine.areaLocation.join('\n\n') : '') : '' } } } diff --git a/src/graphql/schema/Area.gql b/src/graphql/schema/Area.gql index 20fbc88e..6a80c933 100644 --- a/src/graphql/schema/Area.gql +++ b/src/graphql/schema/Area.gql @@ -158,6 +158,7 @@ type CountByGradeBand { type AreaContent { description: String + areaLocation: String } input Point { diff --git a/src/graphql/schema/AreaEdit.gql b/src/graphql/schema/AreaEdit.gql index 53808577..d3bdb63a 100644 --- a/src/graphql/schema/AreaEdit.gql +++ b/src/graphql/schema/AreaEdit.gql @@ -173,6 +173,7 @@ input AreEditableFieldsInput { lat: Float lng: Float description: String + areaLocation: String experimentalAuthor: ExperimentalAuthorType leftRightIndex: Int } diff --git a/src/model/MutableAreaDataSource.ts b/src/model/MutableAreaDataSource.ts index 4eba2c64..0ba2dec2 100644 --- a/src/model/MutableAreaDataSource.ts +++ b/src/model/MutableAreaDataSource.ts @@ -401,6 +401,7 @@ export default class MutableAreaDataSource extends AreaDataSource { const { areaName, description, + areaLocation, shortCode, isDestination, isLeaf, @@ -465,6 +466,10 @@ export default class MutableAreaDataSource extends AreaDataSource { const sanitized = sanitizeStrict(description) area.set({ 'content.description': sanitized }) } + if (areaLocation != null) { + const sanitized = sanitizeStrict(areaLocation) + area.set({ 'content.areaLocation': sanitized }) + } const latLngHasChanged = lat != null && lng != null if (latLngHasChanged) { // we should already validate lat,lng before in GQL layer @@ -697,7 +702,8 @@ export const newAreaHelper = (areaName: string, parentAncestors: string, parentP density: 0, totalClimbs: 0, content: { - description: '' + description: '', + areaLocation: '' } } } diff --git a/src/model/__tests__/updateAreas.ts b/src/model/__tests__/updateAreas.ts index 4d5a894b..b17df811 100644 --- a/src/model/__tests__/updateAreas.ts +++ b/src/model/__tests__/updateAreas.ts @@ -126,12 +126,13 @@ describe('Areas', () => { if (a1 == null) { fail() } - // for testing area desccription is sanitized + // for testing area description and location is sanitized const iframeStr = '' const doc1: AreaEditableFieldsType = { areaName: '1', shortCode: 'ONE', description: `This is a cool area with some malicious code.${iframeStr}`, + areaLocation: `This is a cool area location with some malicious code.${iframeStr}`, isDestination: true } let a1Updated = await areas.updateArea(testUser, a1?.metadata.area_id, doc1) @@ -140,6 +141,8 @@ describe('Areas', () => { expect(a1Updated?.shortCode).toEqual(doc1.shortCode) // make sure area description is sanitized expect(a1Updated?.content.description).toEqual(doc1.description?.replace(iframeStr, '')) + // make sure area location is sanitized + expect(a1Updated?.content.areaLocation).toEqual(doc1.areaLocation?.replace(iframeStr, '')) expect(a1Updated?.metadata.isDestination).toEqual(doc1.isDestination) const doc2: AreaEditableFieldsType = {