Merge pull request #1926 from Human-Connection/1924-moderators-reports-list-sort-desc

🍰 Add Cypher statement for ordering
This commit is contained in:
Wolfgang Huß 2019-10-17 14:28:47 +02:00 committed by GitHub
commit 4a2f8edb9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 44 deletions

View File

@ -1,8 +1,9 @@
export default {
Mutation: {
report: async (_parent, params, { driver, user }, _resolveInfo) => {
report: async (_parent, params, context, _resolveInfo) => {
let createdRelationshipWithNestedAttributes
const { resourceId, reasonCategory, reasonDescription } = params
const { driver, user } = context
const session = driver.session()
const writeTxResultPromise = session.writeTransaction(async txc => {
const reportRelationshipTransactionResponse = await txc.run(
@ -58,54 +59,68 @@ export default {
},
},
Query: {
reports: async (_parent, _params, { driver }, _resolveInfo) => {
reports: async (_parent, params, context, _resolveInfo) => {
const { driver } = context
const session = driver.session()
const res = await session.run(
`
let response
let orderByClause
switch (params.orderBy) {
case 'createdAt_asc':
orderByClause = 'ORDER BY report.createdAt ASC'
break
case 'createdAt_desc':
orderByClause = 'ORDER BY report.createdAt DESC'
break
default:
orderByClause = ''
}
try {
const cypher = `
MATCH (submitter:User)-[report:REPORTED]->(resource)
WHERE resource:User OR resource:Comment OR resource:Post
RETURN report, submitter, resource, labels(resource)[0] as type
`,
{},
)
session.close()
${orderByClause}
`
const result = await session.run(cypher, {})
const dbResponse = result.records.map(r => {
return {
report: r.get('report'),
submitter: r.get('submitter'),
resource: r.get('resource'),
type: r.get('type'),
}
})
if (!dbResponse) return null
const dbResponse = res.records.map(r => {
return {
report: r.get('report'),
submitter: r.get('submitter'),
resource: r.get('resource'),
type: r.get('type'),
}
})
if (!dbResponse) return null
response = []
dbResponse.forEach(ele => {
const { report, submitter, resource, type } = ele
const response = []
dbResponse.forEach(ele => {
const { report, submitter, resource, type } = ele
const responseEle = {
...report.properties,
post: null,
comment: null,
user: null,
submitter: submitter.properties,
type,
}
const responseEle = {
...report.properties,
post: null,
comment: null,
user: null,
submitter: submitter.properties,
type,
}
switch (type) {
case 'Post':
responseEle.post = resource.properties
break
case 'Comment':
responseEle.comment = resource.properties
break
case 'User':
responseEle.user = resource.properties
break
}
response.push(responseEle)
})
switch (type) {
case 'Post':
responseEle.post = resource.properties
break
case 'Comment':
responseEle.comment = resource.properties
break
case 'User':
responseEle.user = resource.properties
break
}
response.push(responseEle)
})
} finally {
session.close()
}
return response
},

View File

@ -30,6 +30,7 @@ enum ReasonCategory {
# union ReportResource = User | Post | Comment
enum ReportOrdering {
createdAt_asc
createdAt_desc
}

View File

@ -21,6 +21,6 @@ DETACH DELETE report
CREATE (submitter)-[reported:REPORTED]->(resource)
SET reported.createdAt = toString(datetime())
SET reported.reasonCategory = 'other'
SET reported.reasonDescription = '!!! Created automatically to ensure database consistency! createdAt is when the database manipulation happened.'
SET reported.reasonDescription = '!!! Created automatically to ensure database consistency! Creation date is when the database manipulation happened.'
RETURN reported;
" | cypher-shell

@ -1 +1 @@
Subproject commit d46fc1570c6bcea328ae4cc3a4892745edea7319
Subproject commit 808b3c5a9523505cb80b20b50348d29ba9932845