mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Add relationship for pinned posts and user
- The CreateUser mutation now returns the user who pinned a post and so we can see the user who pinned the post
This commit is contained in:
parent
774581f2e0
commit
ab06e8a91f
@ -75,20 +75,29 @@ export default {
|
|||||||
},
|
},
|
||||||
Mutation: {
|
Mutation: {
|
||||||
CreatePost: async (_parent, params, context, _resolveInfo) => {
|
CreatePost: async (_parent, params, context, _resolveInfo) => {
|
||||||
const { categoryIds } = params
|
const { categoryIds, pinned } = params
|
||||||
|
delete params.pinned
|
||||||
delete params.categoryIds
|
delete params.categoryIds
|
||||||
params = await fileUpload(params, { file: 'imageUpload', url: 'image' })
|
params = await fileUpload(params, { file: 'imageUpload', url: 'image' })
|
||||||
params.id = params.id || uuid()
|
params.id = params.id || uuid()
|
||||||
let post
|
let post
|
||||||
|
|
||||||
const createPostCypher = `CREATE (post:Post {params})
|
let createPostCypher = `CREATE (post:Post {params})
|
||||||
SET post.createdAt = toString(datetime())
|
SET post.createdAt = toString(datetime())
|
||||||
SET post.updatedAt = toString(datetime())
|
SET post.updatedAt = toString(datetime())
|
||||||
WITH post
|
WITH post
|
||||||
MATCH (author:User {id: $userId})
|
MATCH (author:User {id: $userId})
|
||||||
MERGE (post)<-[:WROTE]-(author)
|
MERGE (post)<-[:WROTE]-(author)
|
||||||
WITH post
|
WITH post, author`
|
||||||
UNWIND $categoryIds AS categoryId
|
|
||||||
|
if (pinned) {
|
||||||
|
createPostCypher += `
|
||||||
|
MERGE (post)<-[:PINNED]-(author)
|
||||||
|
WITH post
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
createPostCypher += `UNWIND $categoryIds AS categoryId
|
||||||
MATCH (category:Category {id: categoryId})
|
MATCH (category:Category {id: categoryId})
|
||||||
MERGE (post)-[:CATEGORIZED]->(category)
|
MERGE (post)-[:CATEGORIZED]->(category)
|
||||||
RETURN post`
|
RETURN post`
|
||||||
@ -98,7 +107,9 @@ export default {
|
|||||||
const session = context.driver.session()
|
const session = context.driver.session()
|
||||||
try {
|
try {
|
||||||
const transactionRes = await session.run(createPostCypher, createPostVariables)
|
const transactionRes = await session.run(createPostCypher, createPostVariables)
|
||||||
const posts = transactionRes.records.map(record => record.get('post').properties)
|
const posts = transactionRes.records.map(record => {
|
||||||
|
return record.get('post').properties
|
||||||
|
})
|
||||||
post = posts[0]
|
post = posts[0]
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.code === 'Neo.ClientError.Schema.ConstraintValidationFailed')
|
if (e.code === 'Neo.ClientError.Schema.ConstraintValidationFailed')
|
||||||
@ -225,6 +236,7 @@ export default {
|
|||||||
hasOne: {
|
hasOne: {
|
||||||
author: '<-[:WROTE]-(related:User)',
|
author: '<-[:WROTE]-(related:User)',
|
||||||
disabledBy: '<-[:DISABLED]-(related:User)',
|
disabledBy: '<-[:DISABLED]-(related:User)',
|
||||||
|
pinnedBy: '<-[:PINNED]-(related:User)',
|
||||||
},
|
},
|
||||||
count: {
|
count: {
|
||||||
commentsCount:
|
commentsCount:
|
||||||
|
|||||||
@ -39,7 +39,11 @@ const createPostMutation = gql`
|
|||||||
slug
|
slug
|
||||||
disabled
|
disabled
|
||||||
deleted
|
deleted
|
||||||
pinned
|
pinnedBy {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
role
|
||||||
|
}
|
||||||
language
|
language
|
||||||
author {
|
author {
|
||||||
name
|
name
|
||||||
@ -422,9 +426,14 @@ describe('CreatePost', () => {
|
|||||||
author: {
|
author: {
|
||||||
name: 'Admin',
|
name: 'Admin',
|
||||||
},
|
},
|
||||||
pinned: true,
|
pinnedBy: {
|
||||||
|
id: 'current-user',
|
||||||
|
name: 'Admin',
|
||||||
|
role: 'admin',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
errors: undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
await expect(mutate({ mutation: createPostMutation, variables })).resolves.toMatchObject(
|
await expect(mutate({ mutation: createPostMutation, variables })).resolves.toMatchObject(
|
||||||
|
|||||||
@ -16,7 +16,7 @@ type Post {
|
|||||||
createdAt: String
|
createdAt: String
|
||||||
updatedAt: String
|
updatedAt: String
|
||||||
language: String
|
language: String
|
||||||
pinned: Boolean
|
pinnedBy: User @relation(name:"PINNED", direction: "IN")
|
||||||
relatedContributions: [Post]!
|
relatedContributions: [Post]!
|
||||||
@cypher(
|
@cypher(
|
||||||
statement: """
|
statement: """
|
||||||
@ -41,7 +41,7 @@ type Post {
|
|||||||
@cypher(
|
@cypher(
|
||||||
statement: "MATCH (this)<-[:SHOUTED]-(r:User) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(DISTINCT r)"
|
statement: "MATCH (this)<-[:SHOUTED]-(r:User) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(DISTINCT r)"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Has the currently logged in user shouted that post?
|
# Has the currently logged in user shouted that post?
|
||||||
shoutedByCurrentUser: Boolean!
|
shoutedByCurrentUser: Boolean!
|
||||||
@cypher(
|
@cypher(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user