Merge pull request #6391 from Ocelot-Social-Community/seed-posts-as-articles-2

feat(backend): seed events
This commit is contained in:
Moriz Wahl 2023-06-08 16:45:40 +02:00 committed by GitHub
commit f665324b52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 86 additions and 13 deletions

View File

@ -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(

View File

@ -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())

View File

@ -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,

View File

@ -57,4 +57,5 @@ export default {
},
},
pinned: { type: 'boolean', default: null, valid: [null, true] },
postType: { type: 'string', default: 'Article', valid: ['Article', 'Event'] },
}

View File

@ -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) => {

View File

@ -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 },

View File

@ -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 }

View File

@ -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',
}