mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
First step of implementing direct report relation
This commit is contained in:
parent
7990879fc8
commit
a07010f50c
@ -35,7 +35,7 @@ export default applyScalars(
|
||||
'Notfication',
|
||||
'Post',
|
||||
'Comment',
|
||||
'Report',
|
||||
'REPORTED',
|
||||
'Statistics',
|
||||
'LoggedInUser',
|
||||
'Location',
|
||||
|
||||
@ -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,18 +39,18 @@ 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,
|
||||
},
|
||||
)
|
||||
|
||||
@ -65,6 +65,7 @@ export default {
|
||||
}
|
||||
})
|
||||
if (!dbResponse) return null
|
||||
|
||||
const { report, submitter, resource, type } = dbResponse
|
||||
|
||||
const response = {
|
||||
|
||||
@ -16,7 +16,7 @@ describe('report', () => {
|
||||
const categoryIds = ['cat9']
|
||||
|
||||
beforeEach(async () => {
|
||||
returnedObject = '{ id }'
|
||||
returnedObject = '{ createdAt }'
|
||||
variables = {
|
||||
resourceId: 'whatever',
|
||||
reasonCategory: 'reason-category-dummy',
|
||||
|
||||
@ -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
|
||||
|
||||
30
backend/src/schema/types/type/REPORTED.gql
Normal file
30
backend/src/schema/types/type/REPORTED.gql
Normal file
@ -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
|
||||
}
|
||||
@ -657,7 +657,7 @@ import { gql } from '../jest/helpers'
|
||||
reasonCategory: $reasonCategory
|
||||
reasonDescription: $reasonDescription
|
||||
) {
|
||||
id
|
||||
type
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user