mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 08:34:55 +00:00
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { Body, Controller, Post, UploadedFile, UseInterceptors } from '@nestjs/common';
|
|
import { FileInterceptor } from '@nestjs/platform-express';
|
|
import { ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger';
|
|
import { memoryStorage } from 'multer';
|
|
import { ResponseFactory } from '~/core/utils';
|
|
import { UploadDocumentRequestDto } from '../dtos/request';
|
|
import { DocumentMetaResponseDto } from '../dtos/response';
|
|
import { DocumentType } from '../enums';
|
|
import { DocumentService } from '../services';
|
|
@Controller('document')
|
|
@ApiTags('document')
|
|
export class DocumentController {
|
|
constructor(private readonly documentService: DocumentService) {}
|
|
|
|
@Post()
|
|
@ApiConsumes('multipart/form-data')
|
|
@ApiBody({
|
|
schema: {
|
|
type: 'object',
|
|
properties: {
|
|
document: {
|
|
type: 'string',
|
|
format: 'binary',
|
|
},
|
|
documentType: {
|
|
type: 'string',
|
|
enum: Object.values(DocumentType),
|
|
},
|
|
},
|
|
required: ['document', 'documentType'],
|
|
},
|
|
})
|
|
@UseInterceptors(FileInterceptor('document', { storage: memoryStorage() }))
|
|
async createDocument(
|
|
@UploadedFile() file: Express.Multer.File,
|
|
@Body() uploadedDocumentRequest: UploadDocumentRequestDto,
|
|
) {
|
|
const document = await this.documentService.createDocument(file, uploadedDocumentRequest);
|
|
|
|
return ResponseFactory.data(new DocumentMetaResponseDto(document));
|
|
}
|
|
}
|