mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
create post in group
This commit is contained in:
parent
90e1696f86
commit
f331813572
@ -77,10 +77,11 @@ export default {
|
|||||||
},
|
},
|
||||||
Mutation: {
|
Mutation: {
|
||||||
CreatePost: async (_parent, params, context, _resolveInfo) => {
|
CreatePost: async (_parent, params, context, _resolveInfo) => {
|
||||||
const { categoryIds } = params
|
const { categoryIds, groupId } = params
|
||||||
const { image: imageInput } = params
|
const { image: imageInput } = params
|
||||||
delete params.categoryIds
|
delete params.categoryIds
|
||||||
delete params.image
|
delete params.image
|
||||||
|
delete params.groupId
|
||||||
params.id = params.id || uuid()
|
params.id = params.id || uuid()
|
||||||
const session = context.driver.session()
|
const session = context.driver.session()
|
||||||
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
|
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
|
||||||
@ -91,6 +92,10 @@ export default {
|
|||||||
MATCH (category:Category {id: categoryId})
|
MATCH (category:Category {id: categoryId})
|
||||||
MERGE (post)-[:CATEGORIZED]->(category)`
|
MERGE (post)-[:CATEGORIZED]->(category)`
|
||||||
: ''
|
: ''
|
||||||
|
const groupCypher = groupId
|
||||||
|
? `WITH post MATCH (group:Group { id: $groupId })
|
||||||
|
MERGE (post)-[:IN]-(group)`
|
||||||
|
: ''
|
||||||
const createPostTransactionResponse = await transaction.run(
|
const createPostTransactionResponse = await transaction.run(
|
||||||
`
|
`
|
||||||
CREATE (post:Post)
|
CREATE (post:Post)
|
||||||
@ -103,9 +108,10 @@ export default {
|
|||||||
MATCH (author:User {id: $userId})
|
MATCH (author:User {id: $userId})
|
||||||
MERGE (post)<-[:WROTE]-(author)
|
MERGE (post)<-[:WROTE]-(author)
|
||||||
${categoriesCypher}
|
${categoriesCypher}
|
||||||
|
${groupCypher}
|
||||||
RETURN post {.*}
|
RETURN post {.*}
|
||||||
`,
|
`,
|
||||||
{ userId: context.user.id, params, categoryIds },
|
{ userId: context.user.id, params, categoryIds, groupId },
|
||||||
)
|
)
|
||||||
const [post] = createPostTransactionResponse.records.map((record) => record.get('post'))
|
const [post] = createPostTransactionResponse.records.map((record) => record.get('post'))
|
||||||
if (imageInput) {
|
if (imageInput) {
|
||||||
@ -367,6 +373,7 @@ export default {
|
|||||||
author: '<-[:WROTE]-(related:User)',
|
author: '<-[:WROTE]-(related:User)',
|
||||||
pinnedBy: '<-[:PINNED]-(related:User)',
|
pinnedBy: '<-[:PINNED]-(related:User)',
|
||||||
image: '-[:HERO_IMAGE]->(related:Image)',
|
image: '-[:HERO_IMAGE]->(related:Image)',
|
||||||
|
group: '-[:IN]->(related:Group)',
|
||||||
},
|
},
|
||||||
count: {
|
count: {
|
||||||
commentsCount:
|
commentsCount:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user