mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Return reviews with reports, rename variables
- Instead of just returning the moderator who reviewed, we return the review as well
This commit is contained in:
parent
21be2c08ba
commit
89daa3356c
@ -41,8 +41,11 @@ const reviewMutation = gql`
|
|||||||
createdAt
|
createdAt
|
||||||
updatedAt
|
updatedAt
|
||||||
closed
|
closed
|
||||||
reviewedByModerator {
|
reviewed {
|
||||||
id
|
createdAt
|
||||||
|
moderator {
|
||||||
|
id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,14 +239,19 @@ describe('moderate resources', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns .reviewedByModerator', async () => {
|
it('returns .reviewed', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
mutate({ mutation: reviewMutation, variables: disableVariables }),
|
mutate({ mutation: reviewMutation, variables: disableVariables }),
|
||||||
).resolves.toMatchObject({
|
).resolves.toMatchObject({
|
||||||
data: {
|
data: {
|
||||||
review: {
|
review: {
|
||||||
resource: { __typename: 'Comment', id: 'comment-id' },
|
resource: { __typename: 'Comment', id: 'comment-id' },
|
||||||
report: { id: expect.any(String), reviewedByModerator: { id: 'moderator-id' } },
|
report: {
|
||||||
|
id: expect.any(String),
|
||||||
|
reviewed: expect.arrayContaining([
|
||||||
|
{ createdAt: expect.any(String), moderator: { id: 'moderator-id' } },
|
||||||
|
]),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -309,14 +317,19 @@ describe('moderate resources', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns .reviewedByModerator', async () => {
|
it('returns .reviewed', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
mutate({ mutation: reviewMutation, variables: disableVariables }),
|
mutate({ mutation: reviewMutation, variables: disableVariables }),
|
||||||
).resolves.toMatchObject({
|
).resolves.toMatchObject({
|
||||||
data: {
|
data: {
|
||||||
review: {
|
review: {
|
||||||
resource: { __typename: 'Post', id: 'post-id' },
|
resource: { __typename: 'Post', id: 'post-id' },
|
||||||
report: { id: expect.any(String), reviewedByModerator: { id: 'moderator-id' } },
|
report: {
|
||||||
|
id: expect.any(String),
|
||||||
|
reviewed: expect.arrayContaining([
|
||||||
|
{ createdAt: expect.any(String), moderator: { id: 'moderator-id' } },
|
||||||
|
]),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -376,14 +389,19 @@ describe('moderate resources', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns .reviewedByModerator', async () => {
|
it('returns .reviewed', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
mutate({ mutation: reviewMutation, variables: disableVariables }),
|
mutate({ mutation: reviewMutation, variables: disableVariables }),
|
||||||
).resolves.toMatchObject({
|
).resolves.toMatchObject({
|
||||||
data: {
|
data: {
|
||||||
review: {
|
review: {
|
||||||
resource: { __typename: 'User', id: 'user-id' },
|
resource: { __typename: 'User', id: 'user-id' },
|
||||||
report: { id: expect.any(String), reviewedByModerator: { id: 'moderator-id' } },
|
report: {
|
||||||
|
id: expect.any(String),
|
||||||
|
reviewed: expect.arrayContaining([
|
||||||
|
{ createdAt: expect.any(String), moderator: { id: 'moderator-id' } },
|
||||||
|
]),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -509,14 +527,19 @@ describe('moderate resources', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns .reviewedByModerator', async () => {
|
it('returns .reviewed', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
mutate({ mutation: reviewMutation, variables: enableVariables }),
|
mutate({ mutation: reviewMutation, variables: enableVariables }),
|
||||||
).resolves.toMatchObject({
|
).resolves.toMatchObject({
|
||||||
data: {
|
data: {
|
||||||
review: {
|
review: {
|
||||||
resource: { __typename: 'Comment', id: 'comment-id' },
|
resource: { __typename: 'Comment', id: 'comment-id' },
|
||||||
report: { id: expect.any(String), reviewedByModerator: { id: 'moderator-id' } },
|
report: {
|
||||||
|
id: expect.any(String),
|
||||||
|
reviewed: expect.arrayContaining([
|
||||||
|
{ createdAt: expect.any(String), moderator: { id: 'moderator-id' } },
|
||||||
|
]),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -569,14 +592,19 @@ describe('moderate resources', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns .reviewedByModerator', async () => {
|
it('returns .reviewed', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
mutate({ mutation: reviewMutation, variables: enableVariables }),
|
mutate({ mutation: reviewMutation, variables: enableVariables }),
|
||||||
).resolves.toMatchObject({
|
).resolves.toMatchObject({
|
||||||
data: {
|
data: {
|
||||||
review: {
|
review: {
|
||||||
resource: { __typename: 'Post', id: 'post-id' },
|
resource: { __typename: 'Post', id: 'post-id' },
|
||||||
report: { id: expect.any(String), reviewedByModerator: { id: 'moderator-id' } },
|
report: {
|
||||||
|
id: expect.any(String),
|
||||||
|
reviewed: expect.arrayContaining([
|
||||||
|
{ createdAt: expect.any(String), moderator: { id: 'moderator-id' } },
|
||||||
|
]),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -628,14 +656,19 @@ describe('moderate resources', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns .reviewedByModerator', async () => {
|
it('returns .reviewed', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
mutate({ mutation: reviewMutation, variables: enableVariables }),
|
mutate({ mutation: reviewMutation, variables: enableVariables }),
|
||||||
).resolves.toMatchObject({
|
).resolves.toMatchObject({
|
||||||
data: {
|
data: {
|
||||||
review: {
|
review: {
|
||||||
resource: { __typename: 'User', id: 'user-id' },
|
resource: { __typename: 'User', id: 'user-id' },
|
||||||
report: { id: expect.any(String), reviewedByModerator: { id: 'moderator-id' } },
|
report: {
|
||||||
|
id: expect.any(String),
|
||||||
|
reviewed: expect.arrayContaining([
|
||||||
|
{ createdAt: expect.any(String), moderator: { id: 'moderator-id' } },
|
||||||
|
]),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@ -86,11 +86,11 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Report: {
|
Report: {
|
||||||
reportsFiled: async (parent, _params, context, _resolveInfo) => {
|
filed: async (parent, _params, context, _resolveInfo) => {
|
||||||
if (typeof parent.reportsFiled !== 'undefined') return parent.reportsFiled
|
if (typeof parent.filed !== 'undefined') return parent.filed
|
||||||
const session = context.driver.session()
|
const session = context.driver.session()
|
||||||
const { id } = parent
|
const { id } = parent
|
||||||
let reportsFiled
|
let filed
|
||||||
const readTxPromise = session.readTransaction(async tx => {
|
const readTxPromise = session.readTransaction(async tx => {
|
||||||
const allReportsTransactionResponse = await tx.run(
|
const allReportsTransactionResponse = await tx.run(
|
||||||
`
|
`
|
||||||
@ -107,7 +107,7 @@ export default {
|
|||||||
try {
|
try {
|
||||||
const txResult = await readTxPromise
|
const txResult = await readTxPromise
|
||||||
if (!txResult[0]) return null
|
if (!txResult[0]) return null
|
||||||
reportsFiled = txResult.map(reportedRecord => {
|
filed = txResult.map(reportedRecord => {
|
||||||
const { submitter, filed } = reportedRecord
|
const { submitter, filed } = reportedRecord
|
||||||
const relationshipWithNestedAttributes = {
|
const relationshipWithNestedAttributes = {
|
||||||
...filed,
|
...filed,
|
||||||
@ -118,35 +118,42 @@ export default {
|
|||||||
} finally {
|
} finally {
|
||||||
session.close()
|
session.close()
|
||||||
}
|
}
|
||||||
return reportsFiled
|
return filed
|
||||||
},
|
},
|
||||||
reviewedByModerator: async (parent, _params, context, _resolveInfo) => {
|
reviewed: async (parent, _params, context, _resolveInfo) => {
|
||||||
if (typeof parent.reviewedByModerator !== 'undefined') return parent.reviewedByModerator
|
if (typeof parent.reviewed !== 'undefined') return parent.reviewed
|
||||||
const session = context.driver.session()
|
const session = context.driver.session()
|
||||||
const { id } = parent
|
const { id } = parent
|
||||||
let reviewedByModerator
|
let reviewed
|
||||||
const readTxPromise = session.readTransaction(async tx => {
|
const readTxPromise = session.readTransaction(async tx => {
|
||||||
const allReportsTransactionResponse = await tx.run(
|
const allReportsTransactionResponse = await tx.run(
|
||||||
`
|
`
|
||||||
MATCH (resource)<-[:BELONGS_TO]-(report:Report {id: $id})<-[review:REVIEWED]-(moderator:User)
|
MATCH (resource)<-[:BELONGS_TO]-(report:Report {id: $id})<-[review:REVIEWED]-(moderator:User)
|
||||||
RETURN moderator
|
RETURN moderator, review
|
||||||
ORDER BY report.updatedAt DESC, review.updatedAt DESC
|
ORDER BY report.updatedAt DESC, review.updatedAt DESC
|
||||||
LIMIT 1
|
|
||||||
`,
|
`,
|
||||||
{ id },
|
{ id },
|
||||||
)
|
)
|
||||||
return allReportsTransactionResponse.records.map(
|
return allReportsTransactionResponse.records.map(record => ({
|
||||||
record => record.get('moderator').properties,
|
review: record.get('review').properties,
|
||||||
)
|
moderator: record.get('moderator').properties,
|
||||||
|
}))
|
||||||
})
|
})
|
||||||
try {
|
try {
|
||||||
const txResult = await readTxPromise
|
const txResult = await readTxPromise
|
||||||
if (!txResult[0]) return null
|
if (!txResult[0]) return null
|
||||||
reviewedByModerator = txResult[0]
|
reviewed = txResult.map(reportedRecord => {
|
||||||
|
const { review, moderator } = reportedRecord
|
||||||
|
const relationshipWithNestedAttributes = {
|
||||||
|
...review,
|
||||||
|
moderator,
|
||||||
|
}
|
||||||
|
return relationshipWithNestedAttributes
|
||||||
|
})
|
||||||
} finally {
|
} finally {
|
||||||
session.close()
|
session.close()
|
||||||
}
|
}
|
||||||
return reviewedByModerator
|
return reviewed
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,7 +35,7 @@ describe('file a report on a resource', () => {
|
|||||||
content
|
content
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reportsFiled {
|
filed {
|
||||||
submitter {
|
submitter {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
@ -201,7 +201,7 @@ describe('file a report on a resource', () => {
|
|||||||
).resolves.toMatchObject({
|
).resolves.toMatchObject({
|
||||||
data: {
|
data: {
|
||||||
fileReport: {
|
fileReport: {
|
||||||
reportsFiled: [
|
filed: [
|
||||||
{
|
{
|
||||||
submitter: {
|
submitter: {
|
||||||
id: 'current-user-id',
|
id: 'current-user-id',
|
||||||
@ -243,7 +243,7 @@ describe('file a report on a resource', () => {
|
|||||||
).resolves.toMatchObject({
|
).resolves.toMatchObject({
|
||||||
data: {
|
data: {
|
||||||
fileReport: {
|
fileReport: {
|
||||||
reportsFiled: [
|
filed: [
|
||||||
{
|
{
|
||||||
reasonCategory: 'criminal_behavior_violation_german_law',
|
reasonCategory: 'criminal_behavior_violation_german_law',
|
||||||
},
|
},
|
||||||
@ -288,7 +288,7 @@ describe('file a report on a resource', () => {
|
|||||||
).resolves.toMatchObject({
|
).resolves.toMatchObject({
|
||||||
data: {
|
data: {
|
||||||
fileReport: {
|
fileReport: {
|
||||||
reportsFiled: [
|
filed: [
|
||||||
{
|
{
|
||||||
reasonDescription: 'My reason!',
|
reasonDescription: 'My reason!',
|
||||||
},
|
},
|
||||||
@ -312,7 +312,7 @@ describe('file a report on a resource', () => {
|
|||||||
).resolves.toMatchObject({
|
).resolves.toMatchObject({
|
||||||
data: {
|
data: {
|
||||||
fileReport: {
|
fileReport: {
|
||||||
reportsFiled: [
|
filed: [
|
||||||
{
|
{
|
||||||
reasonDescription: 'My reason !',
|
reasonDescription: 'My reason !',
|
||||||
},
|
},
|
||||||
@ -487,7 +487,7 @@ describe('file a report on a resource', () => {
|
|||||||
id
|
id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reportsFiled {
|
filed {
|
||||||
submitter {
|
submitter {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
@ -614,7 +614,7 @@ describe('file a report on a resource', () => {
|
|||||||
__typename: 'User',
|
__typename: 'User',
|
||||||
id: 'abusive-user-1',
|
id: 'abusive-user-1',
|
||||||
},
|
},
|
||||||
reportsFiled: expect.arrayContaining([
|
filed: expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
submitter: expect.objectContaining({
|
submitter: expect.objectContaining({
|
||||||
id: 'current-user-id',
|
id: 'current-user-id',
|
||||||
@ -635,7 +635,7 @@ describe('file a report on a resource', () => {
|
|||||||
__typename: 'Post',
|
__typename: 'Post',
|
||||||
id: 'abusive-post-1',
|
id: 'abusive-post-1',
|
||||||
},
|
},
|
||||||
reportsFiled: expect.arrayContaining([
|
filed: expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
submitter: expect.objectContaining({
|
submitter: expect.objectContaining({
|
||||||
id: 'current-user-id',
|
id: 'current-user-id',
|
||||||
@ -656,7 +656,7 @@ describe('file a report on a resource', () => {
|
|||||||
__typename: 'Comment',
|
__typename: 'Comment',
|
||||||
id: 'abusive-comment-1',
|
id: 'abusive-comment-1',
|
||||||
},
|
},
|
||||||
reportsFiled: expect.arrayContaining([
|
filed: expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
submitter: expect.objectContaining({
|
submitter: expect.objectContaining({
|
||||||
id: 'current-user-id',
|
id: 'current-user-id',
|
||||||
|
|||||||
@ -6,7 +6,6 @@ type REVIEWED {
|
|||||||
report: Report
|
report: Report
|
||||||
# @cypher(statement: "MATCH (report:Report)<-[this:REVIEWED]-(:User) RETURN report")
|
# @cypher(statement: "MATCH (report:Report)<-[this:REVIEWED]-(:User) RETURN report")
|
||||||
moderator: User
|
moderator: User
|
||||||
type: String
|
|
||||||
resource: ReviewedResource
|
resource: ReviewedResource
|
||||||
}
|
}
|
||||||
union ReviewedResource = User | Post | Comment
|
union ReviewedResource = User | Post | Comment
|
||||||
|
|||||||
@ -5,10 +5,9 @@ type Report {
|
|||||||
rule: ReportRule!
|
rule: ReportRule!
|
||||||
disable: Boolean!
|
disable: Boolean!
|
||||||
closed: Boolean!
|
closed: Boolean!
|
||||||
reportsFiled: [FILED]
|
filed: [FILED]
|
||||||
|
reviewed: [REVIEWED]
|
||||||
resource: ReportedResource
|
resource: ReportedResource
|
||||||
type: String
|
|
||||||
reviewedByModerator: User
|
|
||||||
}
|
}
|
||||||
|
|
||||||
union ReportedResource = User | Post | Comment
|
union ReportedResource = User | Post | Comment
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user