Skip to content

Commit

Permalink
refactor: #4
Browse files Browse the repository at this point in the history
  • Loading branch information
raunakgurud09 committed Jan 31, 2024
1 parent 731a21d commit cd32dba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/controller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const publishBlog = async (
return {
data: {
status_code: 200,
message: `Title:${article.data.title} is been worked on ⚒️`,
message: `Title:${article.data.title} is been worked on ⚒️, Change to publish:true to publish`,
},
error: null,
};
Expand Down Expand Up @@ -60,26 +60,30 @@ export const publishBlog = async (
};

try {
const { data } = await axios({
const {
data: { data, error },
} = await axios({
url: HASHNODE_ENDPOINT,
method: "post",
data: PublishPost(payload),
headers: headers,
});

return {
data: { data },
error: null,
data: data,
error: error,
};
} catch (error) {
console.log(error);
return {
data: null,
error: {
status_code: 500,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
message: JSON.stringify(error?.errors?.message),
status_code: error?.errors[0].extensions?.code,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
message: JSON.stringify(error?.errors[0]?.message),
},
};
}
Expand Down
11 changes: 8 additions & 3 deletions src/libs/publication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ export const publishToHashnode = async ({
const article = await parseFile(file);

// TODO: validation
const publish_response = await publishBlog(hashnode_key, article, host);
const { data, error } = await publishBlog(hashnode_key, article, host);

console.log("publish data", publish_response);
if (error) {
console.log(error);
process.exit(1);
}

console.log("res", data);

// return result of publish blog
return publish_response;
return data;
};

0 comments on commit cd32dba

Please sign in to comment.