Notice
                              
                          
                        
                          
                          
                            Recent Posts
                            
                        
                          
                          
                            Recent Comments
                            
                        
                          
                          
                            Link
                            
                        
                    | 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 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 | 
                            Tags
                            
                        
                          
                          - frontend
- CLONE
- JavaScript
- express
- CSS
- form
- TypeScript
- node.js
- clonecoding
- MongoDB
- 리액트
- 자바스크립트
- graphQL
- javscript
- DART
- backend
- ES6
- heroku
- GRID
- Component
- Session
- Mongoose
- NextJs
- nodejs
- pug
- API
- Flutter
- react
- HTML
- ECMAScript
                            Archives
                            
                        
                          
                          - Today
- Total
Enjoy Programming
[Backend] Nestjs - Graphql APi 본문
최근 회사에서 인력이 부족해서 백엔드 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 등록하고 하는거는 굳이 남기진 않겠다.. 기록용이니까..
'JavaScript > Node.JS' 카테고리의 다른 글
| [javascript] value의 grade 지정하기 (0) | 2023.05.01 | 
|---|---|
| [error] Error: spawn apollo ENOENT 코드젠 실행 스크립트 에러 (0) | 2022.07.15 | 
| Iron session (0) | 2022.05.15 | 
| socket.io 간단한 채팅 테스트 (0) | 2021.08.09 | 
| Socket IO (0) | 2021.08.08 | 
 
                  