mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2026-02-06 09:55:50 +00:00
DRY notifications resolver
This commit is contained in:
parent
733c2d5ce1
commit
9b2c707aa3
@ -1,3 +1,18 @@
|
|||||||
|
const resourceTypes = ['Post', 'Comment']
|
||||||
|
|
||||||
|
const transformReturnType = record => {
|
||||||
|
return {
|
||||||
|
...record.get('notification').properties,
|
||||||
|
from: {
|
||||||
|
__typename: record.get('resource').labels.find(l => resourceTypes.includes(l)),
|
||||||
|
...record.get('resource').properties,
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
...record.get('user').properties,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
Query: {
|
Query: {
|
||||||
notifications: async (parent, args, context, resolveInfo) => {
|
notifications: async (parent, args, context, resolveInfo) => {
|
||||||
@ -35,20 +50,7 @@ export default {
|
|||||||
${orderByClause}
|
${orderByClause}
|
||||||
`
|
`
|
||||||
const result = await session.run(cypher, { id: user.id })
|
const result = await session.run(cypher, { id: user.id })
|
||||||
const resourceTypes = ['Post', 'Comment']
|
notifications = await result.records.map(transformReturnType)
|
||||||
notifications = await result.records.map(record => {
|
|
||||||
return {
|
|
||||||
...record.get('notification').properties,
|
|
||||||
from: {
|
|
||||||
__typename: record.get('resource').labels.find(l => resourceTypes.includes(l)),
|
|
||||||
...record.get('resource').properties,
|
|
||||||
},
|
|
||||||
to: {
|
|
||||||
__typename: 'User',
|
|
||||||
...record.get('user').properties,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} finally {
|
} finally {
|
||||||
session.close()
|
session.close()
|
||||||
}
|
}
|
||||||
@ -67,20 +69,7 @@ export default {
|
|||||||
RETURN resource, notification, user
|
RETURN resource, notification, user
|
||||||
`
|
`
|
||||||
const result = await session.run(cypher, { resourceId: args.id, id: user.id })
|
const result = await session.run(cypher, { resourceId: args.id, id: user.id })
|
||||||
const resourceTypes = ['Post', 'Comment']
|
const notifications = await result.records.map(transformReturnType)
|
||||||
const notifications = await result.records.map(record => {
|
|
||||||
return {
|
|
||||||
...record.get('notification').properties,
|
|
||||||
from: {
|
|
||||||
__typename: record.get('resource').labels.find(l => resourceTypes.includes(l)),
|
|
||||||
...record.get('resource').properties,
|
|
||||||
},
|
|
||||||
to: {
|
|
||||||
__typename: 'User',
|
|
||||||
...record.get('user').properties,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
|
||||||
notification = notifications[0]
|
notification = notifications[0]
|
||||||
} finally {
|
} finally {
|
||||||
session.close()
|
session.close()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user