Skip to content

Commit

Permalink
add csv upload endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueHorn07 committed Nov 15, 2023
1 parent 02db2a7 commit 732b3b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/popo/setting/setting.controller.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { ApiTags } from '@nestjs/swagger';
import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
import { PopoSettingDto } from './setting.dto';

import { PopoSettingDto, RcStudentsListDto } from './setting.dto';
import { JwtAuthGuard } from '../../auth/guards/jwt-auth.guard';
import { Roles } from 'src/auth/authroization/roles.decorator';
import { UserType } from '../user/user.meta';
import { RolesGuard } from 'src/auth/authroization/roles.guard';
import { FileService } from '../../file/file.service';
import { FileBody } from '../../file/file-body.decorator';

@ApiTags('POPO 세팅')
@Controller('setting')
export class SettingController {
constructor(private readonly fileService: FileService) {}

@Get()
async getSetting() {
return this.fileService.getText('popo-setting.json');
}


@Post()
@Roles(UserType.admin, UserType.association)
Expand All @@ -25,4 +26,16 @@ export class SettingController {
const settingKey = 'popo-setting.json';
return this.fileService.uploadText(settingKey, JSON.stringify(dto));
}

@Post()
@Roles(UserType.admin, UserType.association)
@UseGuards(JwtAuthGuard, RolesGuard)
@FileBody('csv_file')
async uploadRcStudentList(@Body() dto: RcStudentsListDto) {
const csv_url = await this.fileService.uploadFile(
'popo-rc-students-list.csv',
dto.csv_file,
);
return csv_url;
}
}
7 changes: 7 additions & 0 deletions src/popo/setting/setting.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { IsFile, MaxFileSize, MemoryStoredFile } from 'nestjs-form-data';
export class PopoSettingDto {
readonly popo_crm_mail: string; // CRM = 고객 관계 관리
readonly donyeon_bank: string; // ex. 카카오뱅크 12345-6789-10 (홍길동)
readonly dongyeon_service_time: string; // ex. 학기중 평일 12:30 ~ 13:30
readonly dongyeon_contact: string; // ex. (운영관리부) 0xx-xxxx-xxxx
}

export class RcStudentsListDto {
@IsFile()
@MaxFileSize(10 * 1024 * 1024) // 10 Mb
readonly csv_file: MemoryStoredFile;
}

0 comments on commit 732b3b1

Please sign in to comment.