mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
provide information of the observing status of the post after creating a comment (#8310)
This commit is contained in:
parent
538f409086
commit
316c12bd35
@ -100,6 +100,14 @@ export default {
|
|||||||
author: '<-[:WROTE]-(related:User)',
|
author: '<-[:WROTE]-(related:User)',
|
||||||
post: '-[:COMMENTS]->(related:Post)',
|
post: '-[:COMMENTS]->(related:Post)',
|
||||||
},
|
},
|
||||||
|
count: {
|
||||||
|
postObservingUsersCount:
|
||||||
|
'-[:COMMENTS]->(:Post)<-[obs:OBSERVES]-(related:User) WHERE obs.active = true AND NOT related.deleted AND NOT related.disabled',
|
||||||
|
},
|
||||||
|
boolean: {
|
||||||
|
isPostObservedByMe:
|
||||||
|
'MATCH (this)-[:COMMENTS]->(:Post)<-[obs:OBSERVES]-(related:User {id: $cypherParams.currentUserId}) WHERE obs.active = true RETURN COUNT(related) >= 1',
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,8 @@ const createCommentMutation = gql`
|
|||||||
mutation ($id: ID, $postId: ID!, $content: String!) {
|
mutation ($id: ID, $postId: ID!, $content: String!) {
|
||||||
CreateComment(id: $id, postId: $postId, content: $content) {
|
CreateComment(id: $id, postId: $postId, content: $content) {
|
||||||
id
|
id
|
||||||
|
isPostObservedByMe
|
||||||
|
postObservingUsersCount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
@ -122,11 +124,20 @@ describe('observing posts', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('has another user observing the post AFTER commenting it', async () => {
|
it('has another user observing the post AFTER commenting it', async () => {
|
||||||
await mutate({
|
await expect(
|
||||||
mutation: createCommentMutation,
|
mutate({
|
||||||
variables: {
|
mutation: createCommentMutation,
|
||||||
postId: 'p2',
|
variables: {
|
||||||
content: 'After commenting the post, I should observe the post automatically',
|
postId: 'p2',
|
||||||
|
content: 'After commenting the post, I should observe the post automatically',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).resolves.toMatchObject({
|
||||||
|
data: {
|
||||||
|
CreateComment: {
|
||||||
|
isPostObservedByMe: true,
|
||||||
|
postObservingUsersCount: 2,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -187,12 +198,21 @@ describe('observing posts', () => {
|
|||||||
|
|
||||||
describe('comment the post again', () => {
|
describe('comment the post again', () => {
|
||||||
it('does NOT alter the observation state', async () => {
|
it('does NOT alter the observation state', async () => {
|
||||||
await mutate({
|
await expect(
|
||||||
mutation: createCommentMutation,
|
mutate({
|
||||||
variables: {
|
mutation: createCommentMutation,
|
||||||
postId: 'p2',
|
variables: {
|
||||||
content:
|
postId: 'p2',
|
||||||
'After commenting the post I do not observe again, I should NOT observe the post',
|
content:
|
||||||
|
'After commenting the post I do not observe again, I should NOT observe the post',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).resolves.toMatchObject({
|
||||||
|
data: {
|
||||||
|
CreateComment: {
|
||||||
|
isPostObservedByMe: false,
|
||||||
|
postObservingUsersCount: 1,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -47,6 +47,12 @@ type Comment {
|
|||||||
updatedAt: String
|
updatedAt: String
|
||||||
deleted: Boolean
|
deleted: Boolean
|
||||||
disabled: Boolean
|
disabled: Boolean
|
||||||
|
isPostObservedByMe: Boolean!
|
||||||
|
@cypher(
|
||||||
|
statement: "MATCH (this)-[:COMMENTS]->(:Post)<-[obs:OBSERVES]-(u:User {id: $cypherParams.currentUserId}) WHERE obs.active = true RETURN COUNT(u) >= 1"
|
||||||
|
)
|
||||||
|
postObservingUsersCount: Int!
|
||||||
|
@cypher(statement: "MATCH (this)-[:COMMENTS]->(:Post)<-[obs:OBSERVES]-(u:User) WHERE obs.active = true AND NOT u.disabled = true AND NOT u.deleted = true RETURN COUNT(DISTINCT u)")
|
||||||
}
|
}
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
|
|||||||
@ -135,5 +135,7 @@ export const commentFragment = gql`
|
|||||||
deleted
|
deleted
|
||||||
content
|
content
|
||||||
contentExcerpt
|
contentExcerpt
|
||||||
|
isPostObservedByMe
|
||||||
|
postObservingUsersCount
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user