import {
  Controller,
  Post,
  UploadedFile,
  UseInterceptors,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { ImportService } from './import.service';
import { diskStorage } from 'multer';
import { extname } from 'path';

@Controller('')
export class ImportController {
  constructor(private readonly importService: ImportService) {}

  // @Post('xlsx')
  // @UseInterceptors(FileInterceptor('file'))
  // async importExcel(@UploadedFile() file: Express.Multer.File) {
  //   return this.importService.processExcel(file);
  // }

  @Post('xlsx')
  @UseInterceptors(
    FileInterceptor('file', {
      storage: diskStorage({
        destination: './uploads',
        filename: (req, file, cb) => {
          const name = Date.now() + extname(file.originalname);
          cb(null, name);
        },
      }),
    }),
  )
  async uploadFile(@UploadedFile() file: Express.Multer.File) {
    // return this.importService.processExcel(file.path);
  }
}
