94 lines
2.6 KiB
TypeScript
94 lines
2.6 KiB
TypeScript
import {
|
|
BadRequestException,
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Query,
|
|
Response,
|
|
UploadedFile,
|
|
UseGuards,
|
|
UseInterceptors,
|
|
} from '@nestjs/common';
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
import { FileInterceptor } from '@nestjs/platform-express';
|
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
|
import { UploadFileService } from './upload-file.service';
|
|
import { IdInstitucionDto } from '../dto/id-institucion.dto';
|
|
|
|
@Controller('upload-file')
|
|
@ApiTags('upload-file')
|
|
export class UploadFileController {
|
|
constructor(private uploadFileService: UploadFileService) {}
|
|
|
|
@Post('carga-masiva-equipos')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@UseInterceptors(FileInterceptor('csv'))
|
|
@ApiBearerAuth('jwt')
|
|
cargaMasivaEquipos(
|
|
@UploadedFile() file: Express.Multer.File,
|
|
@Query() query: IdInstitucionDto,
|
|
) {
|
|
const path = file ? `${file.destination}/${file.filename}` : null;
|
|
|
|
if (!file) throw new BadRequestException('No se mandó ningún archivo.');
|
|
return this.uploadFileService.createEquipos(
|
|
path,
|
|
parseInt(query.id_institucion),
|
|
);
|
|
}
|
|
|
|
@Post('carga-masiva-usuarios')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@UseInterceptors(FileInterceptor('csv'))
|
|
@ApiBearerAuth('jwt')
|
|
cargaMasivaUsuarios(
|
|
@UploadedFile() file: Express.Multer.File,
|
|
@Query() query: IdInstitucionDto,
|
|
) {
|
|
const path = file ? `${file.destination}/${file.filename}` : null;
|
|
|
|
if (!file) throw new BadRequestException('No se mandó ningún archivo.');
|
|
return this.uploadFileService.createUsuarios(
|
|
path,
|
|
parseInt(query.id_institucion),
|
|
);
|
|
}
|
|
|
|
@Get('download-logo')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@ApiBearerAuth('jwt')
|
|
downloadLogo(@Response() res, @Query() query: IdInstitucionDto) {
|
|
return this.uploadFileService
|
|
.downloadLogo(parseInt(query.id_institucion))
|
|
.then((logo) => res.download(logo));
|
|
}
|
|
|
|
@Get('download-plantilla-equipos')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@ApiBearerAuth('jwt')
|
|
downloadPlantillaEquipos(@Response() res) {
|
|
return res.download('./upload/plantilla_equipos.csv');
|
|
}
|
|
|
|
@Get('download-plantilla-usuarios')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@ApiBearerAuth('jwt')
|
|
downloadPlantillaUsuarios(@Response() res) {
|
|
return res.download('./upload/plantilla_alumnos.csv');
|
|
}
|
|
|
|
@Post('upload-logo')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@ApiBearerAuth('jwt')
|
|
@UseInterceptors(FileInterceptor('logo'))
|
|
uploadLogo(
|
|
@UploadedFile() file: Express.Multer.File,
|
|
@Query() query: IdInstitucionDto,
|
|
) {
|
|
return this.uploadFileService.uploadLogo(
|
|
file,
|
|
parseInt(query.id_institucion),
|
|
);
|
|
}
|
|
}
|