133 lines
3.8 KiB
TypeScript
133 lines
3.8 KiB
TypeScript
import { Controller, Get, Post, Param, Body, Res } from '@nestjs/common';
|
|
import {
|
|
ApiCreatedResponse,
|
|
ApiOperation,
|
|
ApiTags,
|
|
ApiBody,
|
|
ApiProperty,
|
|
} from '@nestjs/swagger';
|
|
import { Board as BoardModel } from '@prisma/client';
|
|
import { BoardService } from './board.service';
|
|
import dayjs from 'dayjs';
|
|
|
|
import { Cron, CronExpression } from '@nestjs/schedule';
|
|
@Controller({
|
|
path: 'board',
|
|
version: '1',
|
|
})
|
|
@ApiTags('CS용 API')
|
|
export class BoardController {
|
|
constructor(private readonly boardService: BoardService) {}
|
|
|
|
@Get('/makeExcel')
|
|
@ApiOperation({ summary: '엑셀파일 생성', description: '엑셀파일 생성' })
|
|
@ApiCreatedResponse({
|
|
description: 'The user has been successfully created.',
|
|
})
|
|
async getExcel(@Res() res, @Param('date') date: string): Promise<any> {
|
|
var mydate = date
|
|
? dayjs(dayjs(date).format('YYYY-MM-DD'))
|
|
: dayjs(dayjs().format('YYYY-MM-DD'));
|
|
res.sendFile(__dirname + `snapshot_${mydate.format('YYYY-MM-DD')}.csv`);
|
|
}
|
|
|
|
@Cron('0 0 0 * * *')
|
|
@Post('/makeExcel')
|
|
@ApiOperation({ summary: '엑셀파일 생성', description: '엑셀파일 생성' })
|
|
@ApiCreatedResponse({
|
|
description: 'The user has been successfully created.',
|
|
})
|
|
async makeExcel(@Body() body: any): Promise<any> {
|
|
const { date } = body;
|
|
var mydate = date
|
|
? dayjs(dayjs(date).format('YYYY-MM-DD'))
|
|
: dayjs(dayjs().format('YYYY-MM-DD'));
|
|
return await this.boardService.generateSnapshotExcel(mydate);
|
|
}
|
|
|
|
@Get('/toc')
|
|
@ApiOperation({
|
|
summary: '이용약관 조회',
|
|
description: '이용약관 Board 데이터 회수',
|
|
})
|
|
getToc(): Promise<BoardModel> {
|
|
return this.boardService.getToc();
|
|
}
|
|
|
|
@Get('/terms')
|
|
@ApiOperation({
|
|
summary: '전자금융거래약관 조회',
|
|
description: '전자금융거래약관 Board 데이터 회수',
|
|
})
|
|
getTerm(): Promise<BoardModel> {
|
|
return this.boardService.getTerm();
|
|
}
|
|
|
|
@Get('/privacy')
|
|
@ApiOperation({
|
|
summary: '개인정보처리방침 조회',
|
|
description: '개인정보처리방침 Board 데이터 회수',
|
|
})
|
|
getPrivacy(): Promise<BoardModel> {
|
|
return this.boardService.getPrivacy();
|
|
}
|
|
|
|
@Get('/announce')
|
|
@ApiOperation({
|
|
summary: '공지사항 리스트 조회',
|
|
description: '공지사항 Board 데이터 회수',
|
|
})
|
|
getAccounces(): Promise<BoardModel[]> {
|
|
return this.boardService.getNotices();
|
|
}
|
|
|
|
@Get('/announce/:id')
|
|
@ApiOperation({
|
|
summary: '공지사항 조회',
|
|
description: '공지사항 Board 데이터 회수',
|
|
})
|
|
getAccounce(@Param('id') id: number): Promise<BoardModel> {
|
|
return this.boardService.getNotice(id);
|
|
}
|
|
|
|
@Get('/faq')
|
|
@ApiOperation({
|
|
summary: 'FAQ 리스트 조회',
|
|
description: 'FAQ Board 데이터 회수',
|
|
})
|
|
getFaqs(): Promise<BoardModel[]> {
|
|
return this.boardService.getFaqs();
|
|
}
|
|
|
|
@Get('/faq/:id')
|
|
@ApiOperation({ summary: 'FAQ 조회', description: '' })
|
|
getFaq(@Param('id') id: number): Promise<BoardModel> {
|
|
return this.boardService.getFaq(id);
|
|
}
|
|
|
|
@Get('/banner')
|
|
@ApiOperation({ summary: '배너 리스트 가져오기', description: '' })
|
|
getBanners(): Promise<BoardModel[]> {
|
|
return this.boardService.getBanners();
|
|
}
|
|
|
|
@Get('/banner/id')
|
|
@ApiOperation({ summary: '배너 가져오기', description: '' })
|
|
getBanner(@Param('id') id: number): Promise<BoardModel> {
|
|
return this.boardService.getBanner(id);
|
|
}
|
|
|
|
@Get('/:key')
|
|
@ApiOperation({
|
|
summary: '시스템 정보 가져오기',
|
|
description: 'key에대한 시스템 정보를 가져온다',
|
|
})
|
|
async getSystemInfo(@Param('key') key: string): Promise<{ value: string }> {
|
|
const systemInfo = await this.boardService.getByTitle(key);
|
|
if (!systemInfo) {
|
|
throw new Error(`System info with key ${key} not found`);
|
|
}
|
|
return { value: systemInfo.body };
|
|
}
|
|
}
|