This repository was archived by the owner on Feb 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate-publication-article.ts
63 lines (59 loc) · 1.63 KB
/
update-publication-article.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { APIError, query } from "./base";
import { Article } from "./types";
type InputArticle = Omit<Article, "url">;
/**
* Update an article in a publication.
*
* @param publicationId The publication's id.
* @param article The article with updated content.
*/
const updatePublicationArticle = async (
publicationId: string,
article: InputArticle
): Promise<Article> =>
query(
`mutation updateStory($postId: String!, $input: UpdateStoryInput!) {
updateStory(postId: $postId, input: $input) {
success,
message,
post {
_id,
title,
slug,
isRepublished,
publication {
domain
}
},
}
}`,
{
postId: article.id,
input: {
title: article.title,
slug: article.slug,
tags: [], // Hashnode API doesn't support tags yet.
contentMarkdown: article.contentMarkdown,
isPartOfPublication: {
publicationId: publicationId,
},
isRepublished: article.canonicalURL
? {
originalArticleURL: article.canonicalURL,
}
: null,
},
}
).then(({ data: { updateStory } }) => {
if (!updateStory.success) throw new APIError([updateStory.message]);
const { post } = updateStory;
return {
id: post._id,
title: post.title,
slug: post.slug,
url: `https://${post.publication.domain}/${post.slug}`,
canonicalURL: post.isRepublished ? article.canonicalURL : undefined,
contentMarkdown: article.contentMarkdown,
};
});
export default updatePublicationArticle;