mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Update post resolver to fix embarrasing bugs
- when a user updates a post, we should not override every property in our database with the new params, since we have read-only properties like createdAt that we don't want to go deleting aimlessly.
This commit is contained in:
parent
ce487f1e0f
commit
67d68db231
@ -1,6 +1,6 @@
|
||||
import cheerio from 'cheerio'
|
||||
|
||||
export default function(content) {
|
||||
export default content => {
|
||||
if (!content) return []
|
||||
const $ = cheerio.load(content)
|
||||
const userIds = $('a.mention[data-mention-id]')
|
||||
|
||||
@ -24,13 +24,9 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => {
|
||||
MATCH (user: User)
|
||||
WHERE user.id in $idsOfUsers
|
||||
AND NOT (user)<-[:BLOCKED]-(author)
|
||||
MERGE (post)-[notification:NOTIFIED {reason: $reason}]->(user)
|
||||
CREATE (post)-[notification:NOTIFIED {reason: $reason}]->(user)
|
||||
SET notification.read = FALSE
|
||||
SET notification.updatedAt = toString(datetime())
|
||||
SET (
|
||||
CASE
|
||||
WHEN notification.createdAt IS NULL
|
||||
THEN notification END ).createdAt = toString(datetime())
|
||||
SET notification.createdAt = toString(datetime())
|
||||
`
|
||||
break
|
||||
}
|
||||
@ -41,13 +37,9 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => {
|
||||
WHERE user.id in $idsOfUsers
|
||||
AND NOT (user)<-[:BLOCKED]-(author)
|
||||
AND NOT (user)<-[:BLOCKED]-(postAuthor)
|
||||
MERGE (comment)-[notification:NOTIFIED {reason: $reason}]->(user)
|
||||
CREATE (comment)-[notification:NOTIFIED {reason: $reason}]->(user)
|
||||
SET notification.read = FALSE
|
||||
SET notification.updatedAt = toString(datetime())
|
||||
SET (
|
||||
CASE
|
||||
WHEN notification.createdAt IS NULL
|
||||
THEN notification END ).createdAt = toString(datetime())
|
||||
SET notification.createdAt = toString(datetime())
|
||||
`
|
||||
break
|
||||
}
|
||||
@ -58,19 +50,14 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => {
|
||||
WHERE user.id in $idsOfUsers
|
||||
AND NOT (user)<-[:BLOCKED]-(author)
|
||||
AND NOT (author)<-[:BLOCKED]-(user)
|
||||
MERGE (comment)-[notification:NOTIFIED {reason: $reason}]->(user)
|
||||
CREATE (comment)-[notification:NOTIFIED {reason: $reason}]->(user)
|
||||
SET notification.read = FALSE
|
||||
SET notification.updatedAt = toString(datetime())
|
||||
SET (
|
||||
CASE
|
||||
WHEN notification.createdAt IS NULL
|
||||
THEN notification END ).createdAt = toString(datetime())
|
||||
SET notification.createdAt = toString(datetime())
|
||||
`
|
||||
break
|
||||
}
|
||||
}
|
||||
await session.run(cypher, {
|
||||
label,
|
||||
id,
|
||||
idsOfUsers,
|
||||
reason,
|
||||
@ -92,6 +79,7 @@ const handleContentDataOfPost = async (resolve, root, args, context, resolveInfo
|
||||
|
||||
const handleContentDataOfComment = async (resolve, root, args, context, resolveInfo) => {
|
||||
const idsOfUsers = extractMentionedUsers(args.content)
|
||||
|
||||
const comment = await resolve(root, args, context, resolveInfo)
|
||||
|
||||
if (comment) {
|
||||
|
||||
@ -15,7 +15,7 @@ const transformReturnType = record => {
|
||||
|
||||
export default {
|
||||
Query: {
|
||||
notifications: async (parent, args, context, resolveInfo) => {
|
||||
notifications: async (_parent, args, context, _resolveInfo) => {
|
||||
const { user: currentUser } = context
|
||||
const session = context.driver.session()
|
||||
let notifications
|
||||
|
||||
@ -74,7 +74,7 @@ export default {
|
||||
},
|
||||
},
|
||||
Mutation: {
|
||||
CreatePost: async (object, params, context, resolveInfo) => {
|
||||
CreatePost: async (_parent, params, context, _resolveInfo) => {
|
||||
const { categoryIds } = params
|
||||
delete params.categoryIds
|
||||
params = await fileUpload(params, { file: 'imageUpload', url: 'image' })
|
||||
@ -110,14 +110,14 @@ export default {
|
||||
|
||||
return post
|
||||
},
|
||||
UpdatePost: async (object, params, context, resolveInfo) => {
|
||||
UpdatePost: async (_parent, params, context, _resolveInfo) => {
|
||||
const { categoryIds } = params
|
||||
delete params.categoryIds
|
||||
params = await fileUpload(params, { file: 'imageUpload', url: 'image' })
|
||||
const session = context.driver.session()
|
||||
|
||||
let updatePostCypher = `MATCH (post:Post {id: $params.id})
|
||||
SET post = $params
|
||||
SET post += $params
|
||||
SET post.updatedAt = toString(datetime())
|
||||
`
|
||||
|
||||
@ -143,12 +143,12 @@ export default {
|
||||
|
||||
const transactionRes = await session.run(updatePostCypher, updatePostVariables)
|
||||
const [post] = transactionRes.records.map(record => {
|
||||
return record.get('post')
|
||||
return record.get('post').properties
|
||||
})
|
||||
|
||||
session.close()
|
||||
|
||||
return post.properties
|
||||
return post
|
||||
},
|
||||
|
||||
DeletePost: async (object, args, context, resolveInfo) => {
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
<template>
|
||||
<ds-button v-if="totalNotifications <= 0" class="notifications-menu" disabled icon="bell">
|
||||
{{ totalNotifications }}
|
||||
</ds-button>
|
||||
<ds-button
|
||||
v-if="totalNotifications <= 0"
|
||||
class="notifications-menu"
|
||||
disabled
|
||||
icon="bell"
|
||||
>{{ totalNotifications }}</ds-button>
|
||||
<dropdown v-else class="notifications-menu" :placement="placement">
|
||||
<template slot="default" slot-scope="{ toggleMenu }">
|
||||
<ds-button primary icon="bell" @click.prevent="toggleMenu">
|
||||
{{ totalNotifications }}
|
||||
</ds-button>
|
||||
<ds-button primary icon="bell" @click.prevent="toggleMenu">{{ totalNotifications }}</ds-button>
|
||||
</template>
|
||||
<template slot="popover">
|
||||
<div class="notifications-menu-popover">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user