39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import axios from "axios";
|
|
import { Article } from "../domain/articleEntity";
|
|
import { create } from "../domain/articleModel";
|
|
import { FetchArticleByIdDTO } from "./dto/fetch_article_by_id_dto";
|
|
import Failure from "core/failure";
|
|
import { integratorApiClient } from "core/httpClient";
|
|
|
|
const articleEndpoint = "/papers/"
|
|
|
|
async function getArticle(id: string): Promise<Article> {
|
|
try {
|
|
// await new Promise((res, _) => {
|
|
// setTimeout(() => res(null), 2000);
|
|
// });
|
|
const response = await integratorApiClient.get<FetchArticleByIdDTO>(
|
|
// `https://run.mocky.io/v3/62cd4581-d864-4d46-b1d6-02b45b5d1994/${id}`
|
|
// `https://jsonplaceholder.typicode.com/posts/${id}`
|
|
articleEndpoint + id
|
|
);
|
|
const dto = response.data;
|
|
return create({
|
|
id: dto.id,
|
|
topic: [dto.topic],
|
|
title: dto.title,
|
|
authors: dto.authors,
|
|
tags: dto.tags,
|
|
summary: dto.summary,
|
|
content: dto.content,
|
|
});
|
|
} catch (reason) {
|
|
if (axios.isAxiosError(reason)) {
|
|
throw Failure.fromReason(reason, "failures.services.load");
|
|
}
|
|
throw reason;
|
|
}
|
|
}
|
|
|
|
export { getArticle };
|