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',
|
'Notfication',
|
||||||
'Post',
|
'Post',
|
||||||
'Comment',
|
'Comment',
|
||||||
'Report',
|
'REPORTED',
|
||||||
'Statistics',
|
'Statistics',
|
||||||
'LoggedInUser',
|
'LoggedInUser',
|
||||||
'Location',
|
'Location',
|
||||||
|
|||||||
@ -8,10 +8,10 @@ export default {
|
|||||||
{ driver, _req, user },
|
{ driver, _req, user },
|
||||||
_resolveInfo,
|
_resolveInfo,
|
||||||
) => {
|
) => {
|
||||||
const reportId = uuid()
|
// Wolle const reportId = uuid()
|
||||||
const session = driver.session()
|
const session = driver.session()
|
||||||
const reportProperties = {
|
const reportProperties = {
|
||||||
id: reportId,
|
// Wolle id: reportId,
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
reasonCategory,
|
reasonCategory,
|
||||||
reasonDescription,
|
reasonDescription,
|
||||||
@ -19,7 +19,7 @@ export default {
|
|||||||
|
|
||||||
const reportQueryRes = await session.run(
|
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
|
RETURN labels(resource)[0] as label
|
||||||
`,
|
`,
|
||||||
{
|
{
|
||||||
@ -39,22 +39,22 @@ export default {
|
|||||||
|
|
||||||
const res = await session.run(
|
const res = await session.run(
|
||||||
`
|
`
|
||||||
MATCH (submitter:User {id: $userId})
|
MATCH (submitter:User {id: $submitterId})
|
||||||
MATCH (resource {id: $resourceId})
|
MATCH (resource {id: $resourceId})
|
||||||
WHERE resource:User OR resource:Comment OR resource:Post
|
WHERE resource:User OR resource:Comment OR resource:Post
|
||||||
CREATE (report:Report {reportProperties})
|
CREATE (resource)<-[report:REPORTED {createdAt: $createdAt, reasonCategory: $reasonCategory, reasonDescription: $reasonDescription}]-(submitter)
|
||||||
MERGE (resource)<-[:REPORTED]-(report)
|
|
||||||
MERGE (report)<-[:REPORTED]-(submitter)
|
|
||||||
RETURN report, submitter, resource, labels(resource)[0] as type
|
RETURN report, submitter, resource, labels(resource)[0] as type
|
||||||
`,
|
`,
|
||||||
{
|
{
|
||||||
resourceId,
|
resourceId,
|
||||||
userId: user.id,
|
submitterId: user.id,
|
||||||
reportProperties,
|
createdAt: reportProperties.createdAt,
|
||||||
|
reasonCategory: reportProperties.reasonCategory,
|
||||||
|
reasonDescription: reportProperties.reasonDescription,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
const [dbResponse] = res.records.map(r => {
|
const [dbResponse] = res.records.map(r => {
|
||||||
return {
|
return {
|
||||||
@ -65,6 +65,7 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (!dbResponse) return null
|
if (!dbResponse) return null
|
||||||
|
|
||||||
const { report, submitter, resource, type } = dbResponse
|
const { report, submitter, resource, type } = dbResponse
|
||||||
|
|
||||||
const response = {
|
const response = {
|
||||||
|
|||||||
@ -16,7 +16,7 @@ describe('report', () => {
|
|||||||
const categoryIds = ['cat9']
|
const categoryIds = ['cat9']
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
returnedObject = '{ id }'
|
returnedObject = '{ createdAt }'
|
||||||
variables = {
|
variables = {
|
||||||
resourceId: 'whatever',
|
resourceId: 'whatever',
|
||||||
reasonCategory: 'reason-category-dummy',
|
reasonCategory: 'reason-category-dummy',
|
||||||
|
|||||||
@ -24,7 +24,6 @@ type Mutation {
|
|||||||
changePassword(oldPassword: String!, newPassword: String!): String!
|
changePassword(oldPassword: String!, newPassword: String!): String!
|
||||||
requestPasswordReset(email: String!): Boolean!
|
requestPasswordReset(email: String!): Boolean!
|
||||||
resetPassword(email: String!, nonce: String!, newPassword: String!): Boolean!
|
resetPassword(email: String!, nonce: String!, newPassword: String!): Boolean!
|
||||||
report(resourceId: ID!, reasonCategory: String!, reasonDescription: String!): Report
|
|
||||||
disable(id: ID!): ID
|
disable(id: ID!): ID
|
||||||
enable(id: ID!): ID
|
enable(id: ID!): ID
|
||||||
# Shout the given Type and ID
|
# Shout the given Type and ID
|
||||||
@ -35,18 +34,28 @@ type Mutation {
|
|||||||
unfollowUser(id: ID!): User
|
unfollowUser(id: ID!): User
|
||||||
}
|
}
|
||||||
|
|
||||||
type Report {
|
# Wolle
|
||||||
id: ID!
|
# type Report {
|
||||||
createdAt: String!
|
# not necessary
|
||||||
reasonCategory: String!
|
# id: ID!
|
||||||
reasonDescription: String!
|
# done
|
||||||
submitter: User @relation(name: "REPORTED", direction: "IN")
|
# createdAt: String!
|
||||||
type: String!
|
# done
|
||||||
@cypher(statement: "MATCH (resource)<-[:REPORTED]-(this) RETURN labels(resource)[0]")
|
# reasonCategory: String!
|
||||||
comment: Comment @relation(name: "REPORTED", direction: "OUT")
|
# done
|
||||||
post: Post @relation(name: "REPORTED", direction: "OUT")
|
# reasonDescription: String!
|
||||||
user: User @relation(name: "REPORTED", direction: "OUT")
|
# 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 {
|
enum Deletable {
|
||||||
Post
|
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
|
reasonCategory: $reasonCategory
|
||||||
reasonDescription: $reasonDescription
|
reasonDescription: $reasonDescription
|
||||||
) {
|
) {
|
||||||
id
|
type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|||||||
@ -129,7 +129,7 @@ Given('somebody reported the following posts:', table => {
|
|||||||
.authenticateAs(submitter)
|
.authenticateAs(submitter)
|
||||||
.mutate(`mutation($resourceId: ID!, $reasonCategory: String!, $reasonDescription: String!) {
|
.mutate(`mutation($resourceId: ID!, $reasonCategory: String!, $reasonDescription: String!) {
|
||||||
report(resourceId: $resourceId, reasonCategory: $reasonCategory, reasonDescription: $reasonDescription) {
|
report(resourceId: $resourceId, reasonCategory: $reasonCategory, reasonDescription: $reasonDescription) {
|
||||||
id
|
type
|
||||||
}
|
}
|
||||||
}`, {
|
}`, {
|
||||||
resourceId,
|
resourceId,
|
||||||
|
|||||||
@ -1,14 +1,15 @@
|
|||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
|
|
||||||
export const reportListQuery = () => {
|
export const reportListQuery = () => {
|
||||||
|
// no limit vor the moment like before: "Report(first: 20, orderBy: createdAt_desc)"
|
||||||
return gql`
|
return gql`
|
||||||
query {
|
query {
|
||||||
Report(first: 20, orderBy: createdAt_desc) {
|
Report(orderBy: createdAt_desc) {
|
||||||
id
|
|
||||||
createdAt
|
createdAt
|
||||||
reasonCategory
|
reasonCategory
|
||||||
reasonDescription
|
reasonDescription
|
||||||
type
|
type
|
||||||
|
resourceId
|
||||||
submitter {
|
submitter {
|
||||||
id
|
id
|
||||||
slug
|
slug
|
||||||
@ -89,7 +90,7 @@ export const reportMutation = () => {
|
|||||||
reasonCategory: $reasonCategory
|
reasonCategory: $reasonCategory
|
||||||
reasonDescription: $reasonDescription
|
reasonDescription: $reasonDescription
|
||||||
) {
|
) {
|
||||||
id
|
type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user