spinner added to download button, only the posts written by the user are exported

This commit is contained in:
Moriz Wahl 2020-10-26 10:43:22 +01:00
parent bbe3681400
commit c4b436f6cb
3 changed files with 41 additions and 78 deletions

View File

@ -5,14 +5,34 @@ export default {
const cypher = `
MATCH (user:User { id: $id })
WITH user
OPTIONAL MATCH (p:Post)
WHERE ((p)<-[:COMMENTS]-(:Comment)<-[:WROTE]-(user)
OR (user)-[:WROTE]->(p))
AND p.deleted = FALSE
AND p.disabled = FALSE
RETURN { user: properties(user), posts: collect(properties(p)) }
AS result
`
OPTIONAL MATCH (posts:Post)
WHERE (user)-[:WROTE]->(posts)
AND posts.deleted = FALSE
AND posts.disabled = FALSE
RETURN { user: properties(user),
posts: collect(
posts {
.*,
author: [
(posts)<-[:WROTE]-(author:User) |
author {
.*
}
][0],
comments: [
(posts)<-[:COMMENTS]-(comment:Comment)
WHERE comment.disabled = FALSE
AND comment.deleted = FALSE |
comment {
.*,
author: [ (comment)<-[:WROTE]-(commentator:User) |
commentator { .name, .slug, .id } ][0]
}
],
categories: [ (posts)-[:CATEGORIZED]->(category:Category) |
category { .name, .id } ]
})
} AS result`
const session = context.driver.session()
const resultPromise = session.readTransaction(async (transaction) => {
const transactionResponse = transaction.run(cypher, {
@ -23,10 +43,21 @@ export default {
try {
const result = await resultPromise
return result.records[0].get('result')
const userData = result.records[0].get('result')
userData.posts.sort(byCreationDate)
if (userData.posts.comments) {
userData.posts.each((post) => post.comments.sort(byCreationDate))
}
return userData
} finally {
session.close()
}
},
},
}
const byCreationDate = (a, b) => {
if (a.createdAt < b.createdAt) return -1
if (a.createdAt > b.createdAt) return 1
return 0
}

View File

@ -113,63 +113,6 @@ describe('resolvers/userData', () => {
},
})
})
describe('the user comments another post', () => {
beforeAll(async () => {
await Factory.build(
'post',
{
id: 'b-post',
title: 'B post',
content: 'B post',
},
{ authorId: 'o-user' },
)
await Factory.build(
'comment',
{
content: 'A comment to post B',
},
{
postId: 'b-post',
authorId: 'a-user',
},
)
})
it('returns the written post and the commented post', async () => {
await expect(query({ query: userDataQuery, variables })).resolves.toMatchObject({
data: {
userData: {
user: {
id: 'a-user',
name: 'John Doe',
slug: 'john-doe',
},
posts: expect.arrayContaining([
{
id: 'a-post',
title: 'A post',
content: 'A post',
comments: [],
},
{
id: 'b-post',
title: 'B post',
content: 'B post',
comments: [
{
content: 'A comment to post B',
author: { slug: 'john-doe' },
},
],
},
]),
},
},
})
})
})
})
})
@ -191,17 +134,6 @@ describe('resolvers/userData', () => {
content: 'A post',
comments: [],
},
{
id: 'b-post',
title: 'B post',
content: 'B post',
comments: [
{
content: 'A comment to post B',
author: { slug: 'john-doe' },
},
],
},
]),
},
},

View File

@ -1,7 +1,7 @@
<template>
<base-card>
<h2 class="title">{{ $t('settings.download.name') }}</h2>
<base-button @click="onClick(jsonData)" icon="download" secondary filled :disabled="loading">
<base-button @click="onClick(jsonData)" icon="download" secondary filled :disabled="loading" :loading="loading">
{{ $t('settings.download.json') }}
</base-button>
<ds-space margin="large" />