Create UpdateComment resolver, update UpdateUser

- UpdateUser should update updatedAt at point of insertion in the
database as well
This commit is contained in:
mattwr18 2019-09-13 20:11:29 +02:00
parent ca6ae3bd1b
commit 60c473bb94
3 changed files with 18 additions and 5 deletions

View File

@ -78,7 +78,7 @@ const invitationLimitReached = rule({
const isAuthor = rule({
cache: 'no_cache',
})(async (parent, args, { user, driver }) => {
})(async (_parent, args, { user, driver }) => {
if (!user) return false
const session = driver.session()
const { id: resourceId } = args

View File

@ -30,11 +30,24 @@ export default {
})
session.close()
const [response] = transactionRes.records.map(record => record.get('comment').properties)
const [comment] = transactionRes.records.map(record => record.get('comment').properties)
return response
return comment
},
DeleteComment: async (object, args, context, resolveInfo) => {
UpdateComment: async (_parent, params, context, _resolveInfo) => {
const session = context.driver.session()
const updateCommentCypher = `
MATCH (comment:Comment {id: $params.id})
SET comment += $params
SET comment.updatedAt = toString(datetime())
RETURN comment
`
const transactionRes = await session.run(updateCommentCypher, { params })
session.close()
const [comment] = transactionRes.records.map(record => record.get('comment').properties)
return comment
},
DeleteComment: async (_parent, args, context, _resolveInfo) => {
const session = context.driver.session()
const transactionRes = await session.run(
`

View File

@ -100,7 +100,7 @@ export default {
try {
const user = await instance.find('User', args.id)
if (!user) return null
await user.update(args)
await user.update({ ...args, updatedAt: new Date().toISOString() })
return user.toJson()
} catch (e) {
throw new UserInputError(e.message)