feat: add class-transformer dependency for better data transformation
refactor(prisma): update User model to include banned status and ban details refactor(prisma): modify Account model to include new authentication fields refactor(prisma): enhance Session model with impersonation tracking refactor(prisma): adjust Verification model to include value field feat(auth): integrate admin plugin and enhance email verification process refactor(category): enforce ownership checks in category service methods refactor(item): update item service to validate category ownership feat(item): add ability to fetch items by category refactor(restaurant): implement ownership checks and admin routes in restaurant controller fix(user): restrict user access to admin routes feat(exception): implement global exception filter for consistent error handling
This commit is contained in:
@@ -6,62 +6,71 @@ import {
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
Request,
|
||||
UseGuards,
|
||||
Session,
|
||||
} from '@nestjs/common';
|
||||
import { RestaurantService } from './restaurant.service';
|
||||
import {
|
||||
AllowAnonymous,
|
||||
AuthGuard,
|
||||
Roles,
|
||||
Session as UserSession,
|
||||
} from '@thallesp/nestjs-better-auth';
|
||||
|
||||
import type { UserSession as SessionType } from '@thallesp/nestjs-better-auth';
|
||||
import { CreateRestaurantDto } from './dto/create-restaurant.dto';
|
||||
import { UpdateRestaurantDto } from './dto/update-restaurant.dto';
|
||||
import { AuthGuard, Session } from '@thallesp/nestjs-better-auth';
|
||||
import type { UserSession } from '@thallesp/nestjs-better-auth';
|
||||
import { RestaurantService } from './restaurant.service';
|
||||
|
||||
@Controller('restaurants')
|
||||
@UseGuards(AuthGuard)
|
||||
export class RestaurantController {
|
||||
constructor(private readonly service: RestaurantService) {}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Post()
|
||||
async create(
|
||||
@Body() dto: CreateRestaurantDto,
|
||||
@Session() session: UserSession,
|
||||
@Session() session: SessionType,
|
||||
) {
|
||||
const ownerId = session.user.id;
|
||||
return await this.service.create(ownerId, dto);
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Get('my')
|
||||
async myRestaurants(@Session() session) {
|
||||
return await this.service.findByOwner(session.user.id);
|
||||
return await this.service.create(session.user.id, dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
async findAll() {
|
||||
return await this.service.findAll();
|
||||
async findOwnerRestaurants(@Session() session: SessionType) {
|
||||
return await this.service.findByOwner(session.user.id);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(@Param('id') id: string) {
|
||||
return await this.service.findOne(id);
|
||||
async findOne(@Param('id') id: string, @Session() session: SessionType) {
|
||||
return await this.service.findMyRestaurant(id, session.user.id);
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Put(':id')
|
||||
async update(
|
||||
@Param('id') id: string,
|
||||
@Body() dto: UpdateRestaurantDto,
|
||||
@Session() session: UserSession,
|
||||
@Session() session: SessionType,
|
||||
) {
|
||||
return await this.service.update(id, dto, session.user.id);
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Delete(':id')
|
||||
async remove(@Param('id') id: string, @Session() session: UserSession) {
|
||||
await this.service.remove(id, session.user.id);
|
||||
async remove(@Param('id') id: string, @Session() session: SessionType) {
|
||||
return await this.service.remove(id, session.user.id);
|
||||
}
|
||||
|
||||
// public menu by slug
|
||||
@Roles(['admin'])
|
||||
@Get('/admin/all')
|
||||
async adminFindAll() {
|
||||
return await this.service.findAll();
|
||||
}
|
||||
|
||||
@Roles(['admin'])
|
||||
@Get('/admin/:id')
|
||||
async adminFindOne(@Param('id') id: string) {
|
||||
return await this.service.findOne(id);
|
||||
}
|
||||
|
||||
@AllowAnonymous()
|
||||
@Get('/public/:slug')
|
||||
async publicBySlug(@Param('slug') slug: string) {
|
||||
return await this.service.findBySlug(slug);
|
||||
|
||||
Reference in New Issue
Block a user