diff --git a/backend/src/schema/index.js b/backend/src/schema/index.js index 4d1b9574e..e3c835447 100644 --- a/backend/src/schema/index.js +++ b/backend/src/schema/index.js @@ -35,7 +35,7 @@ export default applyScalars( 'Notfication', 'Post', 'Comment', - 'Report', + 'REPORTED', 'Statistics', 'LoggedInUser', 'Location', diff --git a/backend/src/schema/resolvers/reports.js b/backend/src/schema/resolvers/reports.js index 4b86e57f4..2cf1187e0 100644 --- a/backend/src/schema/resolvers/reports.js +++ b/backend/src/schema/resolvers/reports.js @@ -8,10 +8,10 @@ export default { { driver, _req, user }, _resolveInfo, ) => { - const reportId = uuid() + // Wolle const reportId = uuid() const session = driver.session() const reportProperties = { - id: reportId, + // Wolle id: reportId, createdAt: new Date().toISOString(), reasonCategory, reasonDescription, @@ -19,7 +19,7 @@ export default { const reportQueryRes = await session.run( ` - MATCH (u:User {id:$submitterId})-[:REPORTED]->(report)-[:REPORTED]->(resource {id: $resourceId}) + MATCH (:User {id:$submitterId})-[:REPORTED]->(resource {id:$resourceId}) RETURN labels(resource)[0] as label `, { @@ -39,22 +39,22 @@ export default { const res = await session.run( ` - MATCH (submitter:User {id: $userId}) + MATCH (submitter:User {id: $submitterId}) MATCH (resource {id: $resourceId}) WHERE resource:User OR resource:Comment OR resource:Post - CREATE (report:Report {reportProperties}) - MERGE (resource)<-[:REPORTED]-(report) - MERGE (report)<-[:REPORTED]-(submitter) + CREATE (resource)<-[report:REPORTED {createdAt: $createdAt, reasonCategory: $reasonCategory, reasonDescription: $reasonDescription}]-(submitter) RETURN report, submitter, resource, labels(resource)[0] as type `, { resourceId, - userId: user.id, - reportProperties, + submitterId: user.id, + createdAt: reportProperties.createdAt, + reasonCategory: reportProperties.reasonCategory, + reasonDescription: reportProperties.reasonDescription, }, ) - session.close() + session.close() const [dbResponse] = res.records.map(r => { return { @@ -65,6 +65,7 @@ export default { } }) if (!dbResponse) return null + const { report, submitter, resource, type } = dbResponse const response = { diff --git a/backend/src/schema/resolvers/reports.spec.js b/backend/src/schema/resolvers/reports.spec.js index 4b0aa7ba4..cf89dab7a 100644 --- a/backend/src/schema/resolvers/reports.spec.js +++ b/backend/src/schema/resolvers/reports.spec.js @@ -16,7 +16,7 @@ describe('report', () => { const categoryIds = ['cat9'] beforeEach(async () => { - returnedObject = '{ id }' + returnedObject = '{ createdAt }' variables = { resourceId: 'whatever', reasonCategory: 'reason-category-dummy', diff --git a/backend/src/schema/types/schema.gql b/backend/src/schema/types/schema.gql index cdf0d7f87..e4986ad73 100644 --- a/backend/src/schema/types/schema.gql +++ b/backend/src/schema/types/schema.gql @@ -24,7 +24,6 @@ type Mutation { changePassword(oldPassword: String!, newPassword: String!): String! requestPasswordReset(email: String!): Boolean! resetPassword(email: String!, nonce: String!, newPassword: String!): Boolean! - report(resourceId: ID!, reasonCategory: String!, reasonDescription: String!): Report disable(id: ID!): ID enable(id: ID!): ID # Shout the given Type and ID @@ -35,18 +34,28 @@ type Mutation { unfollowUser(id: ID!): User } -type Report { - id: ID! - createdAt: String! - reasonCategory: String! - reasonDescription: String! - submitter: User @relation(name: "REPORTED", direction: "IN") - type: String! - @cypher(statement: "MATCH (resource)<-[:REPORTED]-(this) RETURN labels(resource)[0]") - comment: Comment @relation(name: "REPORTED", direction: "OUT") - post: Post @relation(name: "REPORTED", direction: "OUT") - user: User @relation(name: "REPORTED", direction: "OUT") -} +# Wolle +# type Report { + # not necessary + # id: ID! + # done + # createdAt: String! + # done + # reasonCategory: String! + # done + # reasonDescription: String! + # done + # submitter: User @relation(name: "REPORTED", direction: "IN") + # done + # type: String! + # @cypher(statement: "MATCH (resource)<-[:REPORTED]-(this) RETURN labels(resource)[0]") + # seems unused + # comment: Comment @relation(name: "REPORTED", direction: "OUT") + # seems unused + # post: Post @relation(name: "REPORTED", direction: "OUT") + # seems unused + # user: User @relation(name: "REPORTED", direction: "OUT") +# } enum Deletable { Post diff --git a/backend/src/schema/types/type/REPORTED.gql b/backend/src/schema/types/type/REPORTED.gql new file mode 100644 index 000000000..881184bb5 --- /dev/null +++ b/backend/src/schema/types/type/REPORTED.gql @@ -0,0 +1,30 @@ +type REPORTED { + createdAt: String + reasonCategory: String + reasonDescription: String + submitter: User + @cypher(statement: "MATCH (resource)<-[:REPORTED]-(user:User) RETURN user") + resource: ReportReource + @cypher(statement: "MATCH (resource)<-[:REPORTED]-(user:User) RETURN resource") + resourceId: ID + @cypher(statement: "MATCH (resource)<-[:REPORTED]-(user:User) RETURN resource {.id}") + type: String + @cypher(statement: "MATCH (resource)<-[:REPORTED]-(user:User) RETURN labels(resource)[0]") + user: User + post: Post + comment: Comment +} + +union ReportReource = User | Post | Comment + +enum ReportOrdering { + createdAt_desc +} + +type Query { + Report(orderBy: ReportOrdering): [REPORTED] +} + +type Mutation { + report(resourceId: ID!, reasonCategory: String!, reasonDescription: String!): REPORTED +} diff --git a/backend/src/seed/seed-db.js b/backend/src/seed/seed-db.js index 89180ac2e..aae955752 100644 --- a/backend/src/seed/seed-db.js +++ b/backend/src/seed/seed-db.js @@ -657,7 +657,7 @@ import { gql } from '../jest/helpers' reasonCategory: $reasonCategory reasonDescription: $reasonDescription ) { - id + type } } ` diff --git a/cypress/integration/common/report.js b/cypress/integration/common/report.js index 907c3d5eb..ab9a90e36 100644 --- a/cypress/integration/common/report.js +++ b/cypress/integration/common/report.js @@ -129,7 +129,7 @@ Given('somebody reported the following posts:', table => { .authenticateAs(submitter) .mutate(`mutation($resourceId: ID!, $reasonCategory: String!, $reasonDescription: String!) { report(resourceId: $resourceId, reasonCategory: $reasonCategory, reasonDescription: $reasonDescription) { - id + type } }`, { resourceId, diff --git a/webapp/graphql/Moderation.js b/webapp/graphql/Moderation.js index d86205042..981b8146e 100644 --- a/webapp/graphql/Moderation.js +++ b/webapp/graphql/Moderation.js @@ -1,14 +1,15 @@ import gql from 'graphql-tag' export const reportListQuery = () => { + // no limit vor the moment like before: "Report(first: 20, orderBy: createdAt_desc)" return gql` query { - Report(first: 20, orderBy: createdAt_desc) { - id + Report(orderBy: createdAt_desc) { createdAt reasonCategory reasonDescription type + resourceId submitter { id slug @@ -89,7 +90,7 @@ export const reportMutation = () => { reasonCategory: $reasonCategory reasonDescription: $reasonDescription ) { - id + type } } `