upload file controller final
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Controller, Get, Query, Request, UseGuards } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { ApiBearerAuth, ApiOperation, ApiQuery } from '@nestjs/swagger';
|
||||
import { ApiBearerAuth, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';
|
||||
import { Serealize } from '../interceptors/serialize.interceptor';
|
||||
import { ModuloMotivoService } from './modulo-motivo.service';
|
||||
import { ValidarUsuarioService } from '../validar-usuario/validar-usuario.service';
|
||||
@@ -10,6 +10,7 @@ import { ModuloOutputDto } from '../modulo/dto/output/modulo.dto';
|
||||
import { ModuloMotivoOutputDto } from './dto/output/modulo-motivo.dto';
|
||||
|
||||
@Controller('modulo-motivo')
|
||||
@ApiTags('modulo-motivo')
|
||||
export class ModuloMotivoController {
|
||||
constructor(
|
||||
private moduloMotivoService: ModuloMotivoService,
|
||||
|
||||
@@ -3,7 +3,6 @@ import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Query,
|
||||
Response,
|
||||
Request,
|
||||
UploadedFile,
|
||||
@@ -12,12 +11,11 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { ApiBearerAuth, ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger';
|
||||
import { Serealize } from '../interceptors/serialize.interceptor';
|
||||
import { Operador } from '../operador/entity/operador.entity';
|
||||
import { UploadFileService } from './upload-file.service';
|
||||
import { ValidarUsuarioService } from '../validar-usuario/validar-usuario.service';
|
||||
import { IdInstitucionDto } from '../dto/input/id-institucion.dto';
|
||||
import { MessageOutputDto } from '../dto/output/message.dto';
|
||||
|
||||
@Controller('upload-file')
|
||||
@@ -33,10 +31,16 @@ export class UploadFileController {
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@UseInterceptors(FileInterceptor('csv'))
|
||||
@ApiBearerAuth('jwt')
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@ApiBody({
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: { csv: { type: 'string', format: 'binary' } },
|
||||
},
|
||||
})
|
||||
cargaMasivaEquipos(
|
||||
@Request() req,
|
||||
@UploadedFile() file: Express.Multer.File,
|
||||
@Query() query: IdInstitucionDto,
|
||||
) {
|
||||
const admin: Operador = req.user.operador;
|
||||
const path = file ? `${file.destination}/${file.filename}` : null;
|
||||
@@ -45,18 +49,25 @@ export class UploadFileController {
|
||||
if (!file) throw new BadRequestException('No se mandó ningún archivo.');
|
||||
return this.uploadFileService.createEquipos(
|
||||
path,
|
||||
parseInt(query.id_institucion),
|
||||
admin.institucion.id_institucion,
|
||||
);
|
||||
}
|
||||
|
||||
@Serealize(MessageOutputDto)
|
||||
@Post('carga-masiva-usuarios')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@UseInterceptors(FileInterceptor('csv'))
|
||||
@ApiBearerAuth('jwt')
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@ApiBody({
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: { csv: { type: 'string', format: 'binary' } },
|
||||
},
|
||||
})
|
||||
cargaMasivaUsuarios(
|
||||
@Request() req,
|
||||
@UploadedFile() file: Express.Multer.File,
|
||||
@Query() query: IdInstitucionDto,
|
||||
) {
|
||||
const admin: Operador = req.user.operador;
|
||||
const path = file ? `${file.destination}/${file.filename}` : null;
|
||||
@@ -65,42 +76,41 @@ export class UploadFileController {
|
||||
if (!file) throw new BadRequestException('No se mandó ningún archivo.');
|
||||
return this.uploadFileService.createUsuarios(
|
||||
path,
|
||||
parseInt(query.id_institucion),
|
||||
admin.institucion.id_institucion,
|
||||
);
|
||||
}
|
||||
|
||||
// @Get('download-logo')
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
// @ApiBearerAuth('jwt')
|
||||
// downloadLogo(
|
||||
// @Request() req,
|
||||
// @Response() res,
|
||||
// @Query() query: IdInstitucionDto,
|
||||
// ) {
|
||||
// const operador: Operador = req.user.operador;
|
||||
@Get('download-logo')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@ApiBearerAuth('jwt')
|
||||
downloadLogo(@Request() req, @Response() res) {
|
||||
const operador: Operador = req.user.operador;
|
||||
|
||||
// this.validarUsuarioService.validarAdminOperador(operador);
|
||||
// return this.uploadFileService
|
||||
// .downloadLogo(parseInt(query.id_institucion))
|
||||
// .then((logo) => res.download(logo));
|
||||
// }
|
||||
this.validarUsuarioService.validarAdminOperador(operador);
|
||||
// return this.uploadFileService
|
||||
// .downloadLogo(parseInt(query.id_institucion))
|
||||
// .then((logo) => res.download(logo));
|
||||
}
|
||||
|
||||
@Serealize(MessageOutputDto)
|
||||
@Post('upload-logo')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@ApiBearerAuth('jwt')
|
||||
@UseInterceptors(FileInterceptor('logo'))
|
||||
uploadLogo(
|
||||
@Request() req,
|
||||
@UploadedFile() file: Express.Multer.File,
|
||||
@Query() query: IdInstitucionDto,
|
||||
) {
|
||||
@ApiBearerAuth('jwt')
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@ApiBody({
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: { csv: { type: 'string', format: 'binary' } },
|
||||
},
|
||||
})
|
||||
uploadLogo(@Request() req, @UploadedFile() file: Express.Multer.File) {
|
||||
const admin: Operador = req.user.operador;
|
||||
|
||||
this.validarUsuarioService.validarAdmin(admin);
|
||||
return this.uploadFileService.uploadLogo(
|
||||
file,
|
||||
parseInt(query.id_institucion),
|
||||
admin.institucion.id_institucion,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user