Add business images upload and cascade delete improvements.
This commit is contained in:
@@ -7,8 +7,13 @@ import {
|
||||
Patch,
|
||||
Post,
|
||||
Query,
|
||||
UploadedFiles,
|
||||
UseGuards,
|
||||
UseInterceptors,
|
||||
} from '@nestjs/common';
|
||||
import { FilesInterceptor } from '@nestjs/platform-express';
|
||||
import { memoryStorage } from 'multer';
|
||||
import { BusinessImageEntity } from '../../entities/business-image.entity';
|
||||
import { BusinessEntity } from '../../entities/business.entity';
|
||||
import { UserRole } from '../../entities/user.entity';
|
||||
import { AuthUser } from '../auth/auth.types';
|
||||
@@ -16,6 +21,7 @@ import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
||||
import { Roles } from '../auth/decorators/roles.decorator';
|
||||
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
||||
import { RolesGuard } from '../auth/guards/roles.guard';
|
||||
import { BusinessImagesService } from './business-images.service';
|
||||
import { BusinessesService } from './businesses.service';
|
||||
import { AssignBusinessOwnerDto } from './dto/assign-business-owner.dto';
|
||||
import { CreateBusinessDto } from './dto/create-business.dto';
|
||||
@@ -23,7 +29,10 @@ import { UpdateBusinessDto } from './dto/update-business.dto';
|
||||
|
||||
@Controller('businesses')
|
||||
export class BusinessesController {
|
||||
constructor(private readonly service: BusinessesService) {}
|
||||
constructor(
|
||||
private readonly service: BusinessesService,
|
||||
private readonly images: BusinessImagesService,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
findAll(
|
||||
@@ -51,6 +60,33 @@ export class BusinessesController {
|
||||
return this.service.create(payload);
|
||||
}
|
||||
|
||||
@Post(':id/images')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(UserRole.ADMIN)
|
||||
@UseInterceptors(
|
||||
FilesInterceptor('files', 10, {
|
||||
storage: memoryStorage(),
|
||||
limits: { fileSize: 5 * 1024 * 1024 },
|
||||
}),
|
||||
)
|
||||
uploadImages(
|
||||
@Param('id') id: string,
|
||||
@UploadedFiles() files: Express.Multer.File[],
|
||||
): Promise<BusinessImageEntity[]> {
|
||||
return this.images.upload(id, files);
|
||||
}
|
||||
|
||||
@Delete(':id/images/:imageId')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(UserRole.ADMIN)
|
||||
async removeImage(
|
||||
@Param('id') id: string,
|
||||
@Param('imageId') imageId: string,
|
||||
): Promise<{ success: true }> {
|
||||
await this.images.remove(id, imageId);
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
@Post(':id/assign-owner')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(UserRole.ADMIN)
|
||||
|
||||
Reference in New Issue
Block a user