Add images property to CreateRestaurantDto and Restaurant entity; update UploaderController with AdminAuthGuard and API tags for enhanced security and documentation.
This commit is contained in:
@@ -85,6 +85,16 @@ export class CreateRestaurantDto {
|
|||||||
@IsArray()
|
@IsArray()
|
||||||
tagNames?: string[];
|
tagNames?: string[];
|
||||||
|
|
||||||
|
@ApiPropertyOptional({
|
||||||
|
example: ['https://example.com/image1.jpg', 'https://example.com/image2.jpg'],
|
||||||
|
description: 'لیست آدرس تصاویر رستوران',
|
||||||
|
type: [String],
|
||||||
|
})
|
||||||
|
@IsOptional()
|
||||||
|
@IsArray()
|
||||||
|
@IsUrl({}, { each: true })
|
||||||
|
images?: string[];
|
||||||
|
|
||||||
@ApiPropertyOptional({ example: true, description: 'آیا رستوران اکنون باز است؟' })
|
@ApiPropertyOptional({ example: true, description: 'آیا رستوران اکنون باز است؟' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
|
|||||||
@@ -63,6 +63,10 @@ export class Restaurant extends BaseEntity {
|
|||||||
@Property({ nullable: true, type: 'json' })
|
@Property({ nullable: true, type: 'json' })
|
||||||
tagNames?: string[];
|
tagNames?: string[];
|
||||||
|
|
||||||
|
// --- تصاویر ---
|
||||||
|
@Property({ nullable: true, type: 'json' })
|
||||||
|
images?: string[];
|
||||||
|
|
||||||
// --- مالیات یا VAT ---
|
// --- مالیات یا VAT ---
|
||||||
@Property({ type: 'decimal', default: 0 })
|
@Property({ type: 'decimal', default: 0 })
|
||||||
vat?: number = 0;
|
vat?: number = 0;
|
||||||
|
|||||||
@@ -1,22 +1,23 @@
|
|||||||
import { type File, FileInterceptor, FilesInterceptor } from '@nest-lab/fastify-multer';
|
import { type File, FileInterceptor, FilesInterceptor } from '@nest-lab/fastify-multer';
|
||||||
import { Controller, Post, UploadedFile, UploadedFiles, UseGuards, UseInterceptors } from '@nestjs/common';
|
import { Controller, Post, UploadedFile, UploadedFiles, UseGuards, UseInterceptors } from '@nestjs/common';
|
||||||
import { ApiBody, ApiConsumes, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
import { ApiBody, ApiConsumes, ApiOperation, ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
import { UploadMultipleFileDto, UploadSingleFileDto } from './DTO/upload-file.dto';
|
import { UploadMultipleFileDto, UploadSingleFileDto } from './DTO/upload-file.dto';
|
||||||
import { UploaderService } from './providers/uploader.service';
|
import { UploaderService } from './providers/uploader.service';
|
||||||
// import { AuthGuard } from 'src/modules/auth/guards/auth.guard';
|
import { AdminAuthGuard } from '../auth/guards/adminAuth.guard';
|
||||||
|
|
||||||
|
@UseGuards(AdminAuthGuard)
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@ApiTags('uploader')
|
||||||
@Controller('uploader')
|
@Controller('uploader')
|
||||||
export class UploaderController {
|
export class UploaderController {
|
||||||
constructor(private readonly uploaderService: UploaderService) {}
|
constructor(private readonly uploaderService: UploaderService) {}
|
||||||
|
|
||||||
@ApiOperation({ summary: 'Upload a file (admin)' })
|
@ApiOperation({ summary: 'Upload a file (admin)' })
|
||||||
@ApiConsumes('multipart/form-data')
|
@ApiConsumes('multipart/form-data')
|
||||||
// @ApiBearerAuth()
|
|
||||||
@UseInterceptors(FileInterceptor('file'))
|
@UseInterceptors(FileInterceptor('file'))
|
||||||
@ApiBody({ type: UploadSingleFileDto })
|
@ApiBody({ type: UploadSingleFileDto })
|
||||||
@Post('single-file')
|
@Post('single-file')
|
||||||
// @UseGuards(AuthGuard)
|
|
||||||
uploadFile(@UploadedFile() file: File) {
|
uploadFile(@UploadedFile() file: File) {
|
||||||
return this.uploaderService.uploadFile(file);
|
return this.uploaderService.uploadFile(file);
|
||||||
}
|
}
|
||||||
@@ -24,10 +25,8 @@ export class UploaderController {
|
|||||||
@ApiOperation({ summary: 'Uploads multiple files' })
|
@ApiOperation({ summary: 'Uploads multiple files' })
|
||||||
@ApiConsumes('multipart/form-data')
|
@ApiConsumes('multipart/form-data')
|
||||||
@UseInterceptors(FilesInterceptor('files'))
|
@UseInterceptors(FilesInterceptor('files'))
|
||||||
// @ApiBearerAuth()
|
|
||||||
@ApiBody({ type: UploadMultipleFileDto })
|
@ApiBody({ type: UploadMultipleFileDto })
|
||||||
@Post('multi-file')
|
@Post('multi-file')
|
||||||
// @UseGuards(AuthGuard)
|
|
||||||
uploadFiles(@UploadedFiles() files: File[]) {
|
uploadFiles(@UploadedFiles() files: File[]) {
|
||||||
return this.uploaderService.uploadMultiple(files);
|
return this.uploaderService.uploadMultiple(files);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user