Loading backend/src/place/place.controller.ts +28 −4 Original line number Diff line number Diff line import { Controller, Get, Post, Body, Param, UseInterceptors, UploadedFile, Query } from '@nestjs/common'; import { Controller, Get, Post, Body, Param, UseInterceptors, UploadedFile, Query, UnauthorizedException, Req, } from '@nestjs/common'; import { PlaceService } from './place.service'; import { CreatePlaceDateTradDto } from './dto/create-place-date.dto'; import { ApiBearerAuth, ApiBody, ApiConsumes, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger'; Loading @@ -7,6 +18,7 @@ import { ADMIN_ROLES } from 'src/shared/enum/admin-role.enum'; import { fileInterceptor } from 'src/shared/interceptors/file-save.interceptor'; import { FileValidationPipe } from 'src/shared/pipe/file-validation.pipe'; import { LANGUAGES } from 'src/shared/enum/languages.enum'; import { CustomAdminRequest } from 'src/auth/admin/interface/customAdminReq'; @Controller('place') @ApiTags('Place') Loading @@ -19,9 +31,21 @@ export class PlaceController { @ApiBearerAuth('jwt') @Post() @UseInterceptors(fileInterceptor('image', 'static/places/', ['.jpg', '.jpeg', '.png'])) async create(@UploadedFile(new FileValidationPipe()) file, @Body() createPlaceDto: CreatePlaceDateTradDto) { async create( @UploadedFile(new FileValidationPipe()) file, @Body() createPlaceDto: CreatePlaceDateTradDto, @Req() req: CustomAdminRequest, ) { try { console.log({ idTown: req.admin.idTown, createPlaceDto }); if (req.admin.idTown.townId != createPlaceDto.idTown) { throw new UnauthorizedException('This is not your assigned town'); } createPlaceDto.image = file; return await this.placeService.create(createPlaceDto); } catch (e) { throw e; } } @ApiQuery({ name: 'lang', type: String }) Loading Loading
backend/src/place/place.controller.ts +28 −4 Original line number Diff line number Diff line import { Controller, Get, Post, Body, Param, UseInterceptors, UploadedFile, Query } from '@nestjs/common'; import { Controller, Get, Post, Body, Param, UseInterceptors, UploadedFile, Query, UnauthorizedException, Req, } from '@nestjs/common'; import { PlaceService } from './place.service'; import { CreatePlaceDateTradDto } from './dto/create-place-date.dto'; import { ApiBearerAuth, ApiBody, ApiConsumes, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger'; Loading @@ -7,6 +18,7 @@ import { ADMIN_ROLES } from 'src/shared/enum/admin-role.enum'; import { fileInterceptor } from 'src/shared/interceptors/file-save.interceptor'; import { FileValidationPipe } from 'src/shared/pipe/file-validation.pipe'; import { LANGUAGES } from 'src/shared/enum/languages.enum'; import { CustomAdminRequest } from 'src/auth/admin/interface/customAdminReq'; @Controller('place') @ApiTags('Place') Loading @@ -19,9 +31,21 @@ export class PlaceController { @ApiBearerAuth('jwt') @Post() @UseInterceptors(fileInterceptor('image', 'static/places/', ['.jpg', '.jpeg', '.png'])) async create(@UploadedFile(new FileValidationPipe()) file, @Body() createPlaceDto: CreatePlaceDateTradDto) { async create( @UploadedFile(new FileValidationPipe()) file, @Body() createPlaceDto: CreatePlaceDateTradDto, @Req() req: CustomAdminRequest, ) { try { console.log({ idTown: req.admin.idTown, createPlaceDto }); if (req.admin.idTown.townId != createPlaceDto.idTown) { throw new UnauthorizedException('This is not your assigned town'); } createPlaceDto.image = file; return await this.placeService.create(createPlaceDto); } catch (e) { throw e; } } @ApiQuery({ name: 'lang', type: String }) Loading