Skip to content

Commit

Permalink
Merge pull request #286 from cofacts/fix-url-resolver
Browse files Browse the repository at this point in the history
Fix ArticleType's attachmentUrl and CreateOrUpdateArticleReplyFeedback's articleReplyUserId
  • Loading branch information
MrOrz authored Jun 30, 2022
2 parents 6540c6c + b2c3854 commit f5e6992
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/graphql/models/Article.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ const Article = new GraphQLObjectType({
type: GraphQLString,
description: 'Attachment of this article',
async resolve({ attachmentHash }) {
if (!attachmentHash) return null;

const info = await mediaManager.getInfo(attachmentHash);
return info.url;
},
Expand Down
23 changes: 14 additions & 9 deletions src/graphql/mutations/CreateOrUpdateArticleReplyFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,22 @@ export default {
// Fill in reply & article reply author ID
//

const { userId: replyUserId } = await loaders.docLoader.load({
index: 'replies',
id: replyId,
});
const [
{ userId: replyUserId },
article,
] = await loaders.docLoader.loadMany([
{
index: 'replies',
id: replyId,
},
{
index: 'articles',
id: articleId,
},
]);

const article = await loaders.docLoader.load({
index: 'articles',
id: articleId,
});
const { userId: articleReplyUserId } = article.articleReplies.find(
ar => (ar.replyId = replyId)
ar => ar.replyId === replyId
);

await client.update({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ function generateEntry(data) {
export default {
'/articles/doc/article1': {
articleReplies: [
{
replyId: 'reply2',
userId: 'another articleReply user ID',
positiveFeedbackCount: 0,
negativeFeedbackCount: 0,
},
{
replyId: 'reply1',
userId: 'articleReply user ID',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ describe('CreateOrUpdateArticleReplyFeedback', () => {
});
expect(article._source.articleReplies).toMatchInlineSnapshot(`
Array [
Object {
"negativeFeedbackCount": 0,
"positiveFeedbackCount": 0,
"replyId": "reply2",
"userId": "another articleReply user ID",
},
Object {
"negativeFeedbackCount": 0,
"positiveFeedbackCount": 12,
Expand Down Expand Up @@ -247,6 +253,12 @@ describe('CreateOrUpdateArticleReplyFeedback', () => {
});
expect(article._source.articleReplies).toMatchInlineSnapshot(`
Array [
Object {
"negativeFeedbackCount": 0,
"positiveFeedbackCount": 0,
"replyId": "reply2",
"userId": "another articleReply user ID",
},
Object {
"negativeFeedbackCount": 0,
"positiveFeedbackCount": 11,
Expand Down
2 changes: 2 additions & 0 deletions src/graphql/queries/__tests__/GetReplyAndGetArticle.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ describe('GetReplyAndGetArticle', () => {
}
}
requestedForReply
attachmentHash
attachmentUrl
}
}
`({}, { user: { id: 'fakeUser', appId: 'LINE' } })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ Object {
"updatedAt": "2015-01-02T12:10:30Z",
},
],
"attachmentHash": null,
"attachmentUrl": null,
"references": Array [
Object {
"type": "LINE",
Expand Down

0 comments on commit f5e6992

Please sign in to comment.