diff --git a/backend/src/graphql/posts.js b/backend/src/graphql/posts.js index 7d57b8510..f1b62a286 100644 --- a/backend/src/graphql/posts.js +++ b/backend/src/graphql/posts.js @@ -38,10 +38,8 @@ export const createPostMutation = () => { id } eventStart - eventEnd eventLocationName eventVenue - eventIsOnline eventLocation { lng lat diff --git a/backend/src/schema/resolvers/helpers/events.js b/backend/src/schema/resolvers/helpers/events.js index 6f3eda3d4..b2f204f1d 100644 --- a/backend/src/schema/resolvers/helpers/events.js +++ b/backend/src/schema/resolvers/helpers/events.js @@ -5,16 +5,11 @@ export const validateEventParams = (params) => { const { eventInput } = params validateEventDate(eventInput.eventStart) params.eventStart = eventInput.eventStart - if (eventInput.eventEnd) { - validateEventEnd(eventInput.eventStart, eventInput.eventEnd) - params.eventEnd = eventInput.eventEnd - } if (eventInput.eventLocation && !eventInput.eventVenue) { throw new UserInputError('Event venue must be present if event location is given!') } params.eventVenue = eventInput.eventVenue params.eventLocation = eventInput.eventLocation - params.eventIsOnline = !!eventInput.eventIsOnline } delete params.eventInput let locationName @@ -38,12 +33,3 @@ const validateEventDate = (dateString) => { throw new UserInputError('Event start date must be in the future!') } } - -const validateEventEnd = (start, end) => { - const endDate = new Date(end) - if (endDate.toString() === 'Invalid Date') - throw new UserInputError('Event end date must be a valid date!') - const startDate = new Date(start) - if (endDate < startDate) - throw new UserInputError('Event end date must be a after event start date!') -} diff --git a/backend/src/schema/resolvers/notifications.js b/backend/src/schema/resolvers/notifications.js index 117b9b530..c3b882146 100644 --- a/backend/src/schema/resolvers/notifications.js +++ b/backend/src/schema/resolvers/notifications.js @@ -51,7 +51,7 @@ export default { OPTIONAL MATCH (resource)<-[membership:MEMBER_OF]-(relatedUser) WITH user, notification, resource, membership, relatedUser, [(resource)<-[:WROTE]-(author:User) | author {.*}] AS authors, - [(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post {.*, author: properties(author)} ] AS posts + [(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post {.*, author: properties(author), postType: filter(l IN labels(post) WHERE NOT l = "Post")} ] AS posts WITH resource, user, notification, authors, posts, relatedUser, membership, resource {.*, __typename: labels(resource)[0], @@ -90,7 +90,7 @@ export default { SET notification.read = TRUE WITH user, notification, resource, [(resource)<-[:WROTE]-(author:User) | author {.*}] AS authors, - [(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post{.*, author: properties(author)} ] AS posts + [(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post{.*, author: properties(author), postType: filter(l IN labels(post) WHERE NOT l = "Post")} ] AS posts OPTIONAL MATCH (resource)<-[membership:MEMBER_OF]-(user) WITH resource, user, notification, authors, posts, membership, resource {.*, __typename: labels(resource)[0], author: authors[0], post: posts[0], myRole: membership.role } AS finalResource @@ -120,7 +120,7 @@ export default { SET notification.read = TRUE WITH user, notification, resource, [(resource)<-[:WROTE]-(author:User) | author {.*}] AS authors, - [(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post{.*, author: properties(author)} ] AS posts + [(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post{.*, author: properties(author), postType: filter(l IN labels(post) WHERE NOT l = "Post")} ] AS posts OPTIONAL MATCH (resource)<-[membership:MEMBER_OF]-(user) WITH resource, user, notification, authors, posts, membership, resource {.*, __typename: labels(resource)[0], author: authors[0], post: posts[0], myRole: membership.role} AS finalResource diff --git a/backend/src/schema/resolvers/posts.js b/backend/src/schema/resolvers/posts.js index ac8267281..42a755e8f 100644 --- a/backend/src/schema/resolvers/posts.js +++ b/backend/src/schema/resolvers/posts.js @@ -416,8 +416,6 @@ export default { 'eventLocation', 'eventLocationName', 'eventStart', - 'eventEnd', - 'eventIsOnline', ], hasMany: { tags: '-[:TAGGED]->(related:Tag)', diff --git a/backend/src/schema/resolvers/posts.spec.js b/backend/src/schema/resolvers/posts.spec.js index d3936d034..b3dd28f38 100644 --- a/backend/src/schema/resolvers/posts.spec.js +++ b/backend/src/schema/resolvers/posts.spec.js @@ -398,113 +398,6 @@ describe('CreatePost', () => { }) }) - describe('with valid start date and invalid end date', () => { - it('throws an error', async () => { - const now = new Date() - await expect( - mutate({ - mutation: createPostMutation(), - variables: { - ...variables, - postType: 'Event', - eventInput: { - eventStart: new Date(now.getFullYear(), now.getMonth() + 1).toISOString(), - eventEnd: 'not-valid', - }, - }, - }), - ).resolves.toMatchObject({ - errors: [ - { - message: 'Event end date must be a valid date!', - }, - ], - }) - }) - }) - - describe('with valid start date and end date before start date', () => { - it('throws an error', async () => { - const now = new Date() - await expect( - mutate({ - mutation: createPostMutation(), - variables: { - ...variables, - postType: 'Event', - eventInput: { - eventStart: new Date(now.getFullYear(), now.getMonth() + 2).toISOString(), - eventEnd: new Date(now.getFullYear(), now.getMonth() + 1).toISOString(), - }, - }, - }), - ).resolves.toMatchObject({ - errors: [ - { - message: 'Event end date must be a after event start date!', - }, - ], - }) - }) - }) - - describe('with valid start date and valid end date', () => { - it('creates the event', async () => { - const now = new Date() - await expect( - mutate({ - mutation: createPostMutation(), - variables: { - ...variables, - postType: 'Event', - eventInput: { - eventStart: new Date(now.getFullYear(), now.getMonth() + 1).toISOString(), - eventEnd: new Date(now.getFullYear(), now.getMonth() + 2).toISOString(), - }, - }, - }), - ).resolves.toMatchObject({ - data: { - CreatePost: { - postType: ['Event'], - eventStart: new Date(now.getFullYear(), now.getMonth() + 1).toISOString(), - eventEnd: new Date(now.getFullYear(), now.getMonth() + 2).toISOString(), - eventIsOnline: false, - }, - }, - errors: undefined, - }) - }) - }) - - describe('with valid start date and event is online', () => { - it('creates the event', async () => { - const now = new Date() - await expect( - mutate({ - mutation: createPostMutation(), - variables: { - ...variables, - postType: 'Event', - eventInput: { - eventStart: new Date(now.getFullYear(), now.getMonth() + 1).toISOString(), - eventIsOnline: true, - }, - }, - }), - ).resolves.toMatchObject({ - data: { - CreatePost: { - postType: ['Event'], - eventStart: new Date(now.getFullYear(), now.getMonth() + 1).toISOString(), - eventIsOnline: true, - }, - }, - errors: undefined, - }) - }) - }) - describe('event location is given but event venue is missing', () => { it('throws an error', async () => { const now = new Date() @@ -549,7 +442,6 @@ describe('CreatePost', () => { CreatePost: { postType: ['Event'], eventStart: new Date(now.getFullYear(), now.getMonth() + 1).toISOString(), - eventIsOnline: false, }, }, errors: undefined, diff --git a/backend/src/schema/resolvers/users/location.js b/backend/src/schema/resolvers/users/location.js index 9d8a11f89..54d73560b 100644 --- a/backend/src/schema/resolvers/users/location.js +++ b/backend/src/schema/resolvers/users/location.js @@ -22,7 +22,7 @@ const locales = ['en', 'de', 'fr', 'nl', 'it', 'es', 'pt', 'pl', 'ru'] const createLocation = async (session, mapboxData) => { const data = { - id: mapboxData.id, + id: mapboxData.id + (mapboxData.address ? `-${mapboxData.address}` : ''), nameEN: mapboxData.text_en, nameDE: mapboxData.text_de, nameFR: mapboxData.text_fr, @@ -33,6 +33,7 @@ const createLocation = async (session, mapboxData) => { namePL: mapboxData.text_pl, nameRU: mapboxData.text_ru, type: mapboxData.id.split('.')[0].toLowerCase(), + address: mapboxData.address, lng: mapboxData.center && mapboxData.center.length ? mapboxData.center[0] : null, lat: mapboxData.center && mapboxData.center.length ? mapboxData.center[1] : null, } @@ -54,6 +55,10 @@ const createLocation = async (session, mapboxData) => { if (data.lat && data.lng) { mutation += ', l.lat = $lat, l.lng = $lng' } + if (data.address) { + mutation += ', l.address = $address' + } + mutation += ' RETURN l.id' await session.writeTransaction((transaction) => { @@ -72,7 +77,7 @@ export const createOrUpdateLocations = async (nodeLabel, nodeId, locationName, s locationName, )}.json?access_token=${ CONFIG.MAPBOX_TOKEN - }&types=region,place,country&language=${locales.join(',')}`, + }&types=region,place,country,address&language=${locales.join(',')}`, ) debug(res) @@ -103,6 +108,10 @@ export const createOrUpdateLocations = async (nodeLabel, nodeId, locationName, s let parent = data + if (parent.address) { + parent.id += `-${parent.address}` + } + if (data.context) { await asyncForEach(data.context, async (ctx) => { await createLocation(session, ctx) diff --git a/backend/src/schema/types/type/Post.gql b/backend/src/schema/types/type/Post.gql index 22d7c1d5c..c35ee7054 100644 --- a/backend/src/schema/types/type/Post.gql +++ b/backend/src/schema/types/type/Post.gql @@ -179,8 +179,6 @@ type Post { eventLocation: Location @cypher(statement: "MATCH (this)-[:IS_IN]->(l:Location) RETURN l") eventVenue: String eventStart: String - eventEnd: String - eventIsOnline: Boolean } input _PostInput { @@ -191,8 +189,6 @@ input _EventInput { eventStart: String! eventLocation: String eventVenue: String - eventEnd: String - eventIsOnline: Boolean } type Mutation {