diff --git a/backend/src/db/seed.js b/backend/src/db/seed.js index a8f8b9c68..9eb67abbf 100644 --- a/backend/src/db/seed.js +++ b/backend/src/db/seed.js @@ -596,7 +596,79 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl'] }), ]) - // Create Posts + // Create Events (by peter lustig) + authenticatedUser = await peterLustig.toJson() + const now = new Date() + + await Promise.all([ + mutate({ + mutation: createPostMutation(), + variables: { + id: 'e0', + title: 'Illegaler Kindergeburtstag', + content: 'Elli hat nächste Woche Geburtstag. Wir feiern das!', + categoryIds: ['cat4'], + postType: 'Event', + eventInput: { + eventStart: new Date( + now.getFullYear(), + now.getMonth(), + now.getDate() + 7, + ).toISOString(), + eventVenue: 'Ellis Kinderzimmer', + eventLocationName: 'Deutschland', + }, + }, + }), + mutate({ + mutation: createPostMutation(), + variables: { + id: 'e1', + title: 'Wir Schützen den Stuttgarter Schlossgarten', + content: 'Kein Baum wird gefällt werden!', + categoryIds: ['cat5'], + postType: 'Event', + eventInput: { + eventStart: new Date( + now.getFullYear(), + now.getMonth(), + now.getDate() + 1, + ).toISOString(), + eventVenue: 'Schlossgarten', + eventLocationName: 'Stuttgart', + }, + }, + }), + mutate({ + mutation: createPostMutation(), + variables: { + id: 'e2', + title: 'IT 4 Change Treffen', + content: 'Wir sitzen eine Woche zusammen rum und glotzen uns blöde an.', + categoryIds: ['cat5'], + postType: 'Event', + eventInput: { + eventStart: new Date( + now.getFullYear(), + now.getMonth(), + now.getDate() + 1, + ).toISOString(), + eventEnd: new Date(now.getFullYear(), now.getMonth(), now.getDate() + 4).toISOString(), + eventVenue: 'Ferienlager', + eventLocationName: 'Bahra, Sachsen', + }, + }, + }), + ]) + + let passedEvent = await neode.find('Post', 'e1') + await passedEvent.update({ eventStart: new Date(2010, 8, 30, 10).toISOString() }) + passedEvent = await neode.find('Post', 'e2') + await passedEvent.update({ + eventStart: new Date(now.getFullYear(), now.getMonth(), now.getDate() - 3).toISOString(), + }) + + // Create Posts (Articles) const [p0, p1, p3, p4, p5, p6, p9, p10, p11, p13, p14, p15] = await Promise.all([ Factory.build( diff --git a/backend/src/middleware/notifications/notificationsMiddleware.js b/backend/src/middleware/notifications/notificationsMiddleware.js index 1c97e9591..abb8abdc1 100644 --- a/backend/src/middleware/notifications/notificationsMiddleware.js +++ b/backend/src/middleware/notifications/notificationsMiddleware.js @@ -238,7 +238,7 @@ const notifyUsersOfMention = async (label, id, idsOfUsers, reason, context) => { [(resource)<-[:WROTE]-(author:User) | author {.*}] AS authors, [(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post{.*, author: properties(author)} ] AS posts WITH resource, user, notification, authors, posts, - resource {.*, __typename: labels(resource)[0], author: authors[0], post: posts[0]} AS finalResource + resource {.*, __typename: filter(l IN labels(resource) WHERE l IN ['Post', 'Comment', 'Group'])[0], author: authors[0], post: posts[0]} AS finalResource SET notification.read = FALSE SET notification.createdAt = COALESCE(notification.createdAt, toString(datetime())) SET notification.updatedAt = toString(datetime()) diff --git a/backend/src/middleware/validation/validationMiddleware.js b/backend/src/middleware/validation/validationMiddleware.js index 20933a777..9a56536e7 100644 --- a/backend/src/middleware/validation/validationMiddleware.js +++ b/backend/src/middleware/validation/validationMiddleware.js @@ -64,7 +64,7 @@ const validateReview = async (resolve, root, args, context, info) => { WHERE resource:User OR resource:Post OR resource:Comment OPTIONAL MATCH (:User)-[filed:FILED]->(:Report {closed: false})-[:BELONGS_TO]->(resource) OPTIONAL MATCH (resource)<-[:WROTE]-(author:User) - RETURN labels(resource)[0] AS label, author, filed + RETURN filter(l IN labels(resource) WHERE l IN ['Post', 'Comment', 'User'])[0] AS label, author, filed `, { resourceId, diff --git a/backend/src/models/Post.js b/backend/src/models/Post.js index 235e7d68d..e206ea1f5 100644 --- a/backend/src/models/Post.js +++ b/backend/src/models/Post.js @@ -57,4 +57,5 @@ export default { }, }, pinned: { type: 'boolean', default: null, valid: [null, true] }, + postType: { type: 'string', default: 'Article', valid: ['Article', 'Event'] }, } diff --git a/backend/src/schema/resolvers/moderation.js b/backend/src/schema/resolvers/moderation.js index c261d187e..b0472070f 100644 --- a/backend/src/schema/resolvers/moderation.js +++ b/backend/src/schema/resolvers/moderation.js @@ -18,7 +18,7 @@ export default { SET report.updatedAt = $dateTime, report.disable = review.disable, report.closed = $params.closed SET resource.disabled = report.disable - WITH review, report, resource {.*, __typename: labels(resource)[0]} AS finalResource + WITH review, report, resource {.*, __typename: filter(l IN labels(resource) WHERE l IN ['Post', 'Comment', 'User'])[0]} AS finalResource RETURN review {.*, report: properties(report), resource: properties(finalResource)} ` const reviewWriteTxResultPromise = session.writeTransaction(async (txc) => { diff --git a/backend/src/schema/resolvers/notifications.js b/backend/src/schema/resolvers/notifications.js index c3b882146..83c4da11b 100644 --- a/backend/src/schema/resolvers/notifications.js +++ b/backend/src/schema/resolvers/notifications.js @@ -54,7 +54,7 @@ export default { [(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], + __typename: filter(l IN labels(resource) WHERE l IN ['Post', 'Comment', 'Group'])[0], author: authors[0], post: posts[0], myRole: membership.role } AS finalResource @@ -93,7 +93,7 @@ export default { [(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 + resource {.*, __typename: filter(l IN labels(resource) WHERE l IN ['Post', 'Comment', 'Group'])[0], author: authors[0], post: posts[0], myRole: membership.role } AS finalResource RETURN notification {.*, from: finalResource, to: properties(user)} `, { resourceId: args.id, id: currentUser.id }, @@ -123,7 +123,7 @@ export default { [(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 + resource {.*, __typename: filter(l IN labels(resource) WHERE l IN ['Post', 'Comment', 'Group'])[0], author: authors[0], post: posts[0], myRole: membership.role} AS finalResource RETURN notification {.*, from: finalResource, to: properties(user)} `, { id: currentUser.id }, diff --git a/backend/src/schema/resolvers/reports.js b/backend/src/schema/resolvers/reports.js index 431bbaefc..414291acb 100644 --- a/backend/src/schema/resolvers/reports.js +++ b/backend/src/schema/resolvers/reports.js @@ -17,7 +17,7 @@ export default { WITH submitter, resource, report CREATE (report)<-[filed:FILED {createdAt: $createdAt, reasonCategory: $reasonCategory, reasonDescription: $reasonDescription}]-(submitter) - WITH filed, report, resource {.*, __typename: labels(resource)[0]} AS finalResource + WITH filed, report, resource {.*, __typename: filter(l IN labels(resource) WHERE l IN ['Post', 'Comment', 'User'])[0]} AS finalResource RETURN filed {.*, reportId: report.id, resource: properties(finalResource)} AS filedReport `, { @@ -93,7 +93,7 @@ export default { [(moderator:User)-[reviewed:REVIEWED]->(report) | reviewed {.*, moderator: properties(moderator)} ] as reviewed, [(resource)<-[:WROTE]-(author:User) | author {.*} ] as optionalAuthors, [(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post {.*, author: properties(author), postType: filter(l IN labels(post) WHERE NOT l = "Post")} ] as optionalCommentedPosts, - resource {.*, __typename: labels(resource)[0] } as resourceWithType + resource {.*, __typename: filter(l IN labels(resource) WHERE l IN ['Post', 'Comment', 'User'])[0] } as resourceWithType WITH report, optionalAuthors, optionalCommentedPosts, reviewed, filed, resourceWithType {.*, post: optionalCommentedPosts[0], author: optionalAuthors[0] } as finalResource RETURN report {.*, resource: finalResource, filed: filed, reviewed: reviewed } diff --git a/backend/src/schema/resolvers/searches.js b/backend/src/schema/resolvers/searches.js index a67abe90d..ccbbb3b8e 100644 --- a/backend/src/schema/resolvers/searches.js +++ b/backend/src/schema/resolvers/searches.js @@ -38,7 +38,7 @@ const searchPostsSetup = { [(resource)<-[:SHOUTED]-(user:User) | user] AS shouter`, returnClause: `resource { .*, - __typename: labels(resource)[0], + __typename: 'Post', author: properties(author), commentsCount: toString(size(comments)), shoutedCount: toString(size(shouter)), @@ -53,7 +53,7 @@ const searchUsersSetup = { match: 'MATCH (resource:User)', whereClause: simpleWhereClause, withClause: '', - returnClause: 'resource {.*, __typename: labels(resource)[0]}', + returnClause: `resource {.*, __typename: 'User'}`, limit: 'LIMIT $limit', } @@ -62,7 +62,7 @@ const searchHashtagsSetup = { match: 'MATCH (resource:Tag)', whereClause: simpleWhereClause, withClause: '', - returnClause: 'resource {.*, __typename: labels(resource)[0]}', + returnClause: `resource {.*, __typename: 'Tag'}`, limit: 'LIMIT $limit', } @@ -77,7 +77,7 @@ const searchGroupsSetup = { AND (resource.groupType IN ['public', 'closed'] OR membership.role IN ['usual', 'admin', 'owner'])`, withClause: 'WITH resource, membership', - returnClause: 'resource { .*, myRole: membership.role, __typename: labels(resource)[0] }', + returnClause: `resource { .*, myRole: membership.role, __typename: 'Group' }`, limit: 'LIMIT $limit', }