JavaScript/Node.JS
[Backend] Nestjs - Graphql APi
LEETAEEON
2023. 4. 18. 22:41
최근 회사에서 인력이 부족해서 백엔드 api까지 만들고 프론트 작업까지 진행중이다.
현재는 복잡한건 안하고 호출해서 가져오도록 api를 만드는게 다이긴 하지만... 아무튼 그렇다..
@async_timer
async getIssueNewsList(
input: GetIssueNewsListInputDto,
): Promise<GetIssueNewsListOutputDto> {
const fName = this.getIssueNewsList.name;
this.larchiveLoggerService.customLog(
{
fName,
vName: 'GetIssueNewsListInputDto',
message: input,
},
fName,
);
try {
const uri = this.dataSwaggerUrl + '/news/aggregated-news-list';
const {
data: { ok, result, error },
}: { data: IssueMonitorNewsListAixosResponse } =
await this.httpService.axiosRef(uri, {
params: {
page: input.pageNumber,
},
method: 'GET',
});
if (!ok || error !== '' || !result) {
this.larchiveLoggerService.customError(
{
fName,
vName: 'error',
message: error || 'Axios error',
},
fName,
);
return {
ok: false,
error: error || 'Aixos Error',
result: [],
};
}
this.larchiveLoggerService.customLog(
{
fName,
vName: 'fetch result',
message: result,
},
fName,
);
const categoryList = Array.from(
new Set(result.slice().map((item) => item.group_info.category)),
);
const childList = categoryList
.map((cate) => {
const exactList = result
.slice()
.filter((item) => item.group_info.category === cate)
.map((res) => {
const newsList = res.unique_news
.filter((item1, index, arr) => {
const _target = JSON.stringify(item1.title);
return (
arr.findIndex(
(item2) => JSON.stringify(item2.title) === _target,
) === index
);
})
.slice()
.map((news) => {
return {
category: cate,
title: news.title,
url: news.url,
keyword: res.group_info.keyword,
date: res.group_info.date,
negative_pasitive: res.negative_or_positive,
};
});
return newsList;
});
return exactList.flat(1);
})
.flat(1);
this.larchiveLoggerService.customLog(
{
fName,
vName: 'response result',
message: childList,
},
fName,
);
return {
ok: true,
result: childList,
};
} catch (err) {
this.larchiveLoggerService.customError(
{
fName,
vName: 'error',
message: err.stack,
},
fName,
);
return {
ok: false,
error: err.stack,
result: [],
};
}
}
기록용으로 오늘만든 api service logic 이다.. 음 일단 회사에서 따로 dataFlight api 를 운영하고 있어서 거기에서 호출 후 여기서 ... 다시 전처리를 많이 해주는 번거로움이 있지만... (... 왜 애초에 저형태로 데이터를 보내주지 ㅠㅠ....)
뭐 dto만들고 resolver 등록하고 하는거는 굳이 남기진 않겠다.. 기록용이니까..