Bổ sung tính năng cập nhật tiền của địa điểm bị lỗi trùng cổng

This commit is contained in:
2026-06-14 12:24:53 +07:00
parent 58087a4b37
commit 65a9b39966
11 changed files with 115 additions and 47 deletions
+18 -10
View File
@@ -8,6 +8,7 @@ import { AdminGuard } from './admin.guard.js';
import { JwtModule, JwtService } from '@nestjs/jwt';
import { JwtAuthGuard } from './jwt-auth.guard.js';
import { JwtStrategy } from './jwt.strategy.js';
import { TourRoleGuard } from './rbac.middleware.js';
@Controller()
class AppController {
@@ -108,7 +109,7 @@ class TourController {
});
}
@UseGuards(JwtAuthGuard)
@UseGuards(JwtAuthGuard, TourRoleGuard)
@Post(':tourId/locations')
async addLocation(@Param('tourId', ParseUUIDPipe) tourId: string, @Body() body: any, @Req() req: any) {
const legId = body.legId;
@@ -149,7 +150,7 @@ class TourController {
});
}
@UseGuards(JwtAuthGuard)
@UseGuards(JwtAuthGuard, TourRoleGuard)
@Post(':tourId/start-point')
async updateTourStartPoint(@Param('tourId', ParseUUIDPipe) tourId: string, @Body() body: any, @Req() req: any) {
const { latitude, longitude, name } = body;
@@ -186,7 +187,7 @@ class TourController {
});
}
@UseGuards(JwtAuthGuard)
@UseGuards(JwtAuthGuard, TourRoleGuard)
@Post(':tourId/end-point')
async updateTourEndPoint(@Param('tourId', ParseUUIDPipe) tourId: string, @Body() body: any, @Req() req: any) {
const { latitude, longitude, name } = body;
@@ -221,7 +222,7 @@ class TourController {
});
}
@UseGuards(JwtAuthGuard)
@UseGuards(JwtAuthGuard, TourRoleGuard)
@Post(':tourId/legs/batch')
async initializeLegs(@Param('tourId', ParseUUIDPipe) tourId: string, @Body() body: { count: number }) {
const { count } = body;
@@ -266,7 +267,7 @@ class TourController {
return allLegs;
}
@UseGuards(JwtAuthGuard)
@UseGuards(JwtAuthGuard, TourRoleGuard)
@Post(':tourId/legs')
async addLeg(@Param('tourId', ParseUUIDPipe) tourId: string, @Body() body: any) {
const tour = await this.prisma.tour.findUnique({
@@ -284,7 +285,7 @@ class TourController {
});
}
@UseGuards(JwtAuthGuard)
@UseGuards(JwtAuthGuard, TourRoleGuard)
@Patch(':id')
async updateTour(@Param('id', ParseUUIDPipe) id: string, @Body() body: any) {
// Lưu ý: Trong thực tế nên kiểm tra xem user có phải là OWNER không
@@ -298,7 +299,7 @@ class TourController {
});
}
@UseGuards(JwtAuthGuard)
@UseGuards(JwtAuthGuard, TourRoleGuard)
@Delete(':id')
async deleteTour(@Param('id', ParseUUIDPipe) id: string) {
// Xóa tour sẽ xóa cascade các Leg, Location, Expense nhờ config onDelete: Cascade trong schema
@@ -308,10 +309,16 @@ class TourController {
return { success: true };
}
@UseGuards(JwtAuthGuard)
@Get('explore')
async getPublicTours() {
// Lấy các tour có ít nhất 1 ảnh và thông tin vị trí từ chặng đầu tiên
async getPublicTours(@Req() req: any) {
// Lc Tour: Chỉ lấy những tour mà người dùng hiện tại là thành viên (Participant)
return this.prisma.tour.findMany({
where: {
participants: {
some: { userId: req.user.id }
}
},
take: 20,
include: {
photos: { take: 1 },
@@ -325,6 +332,7 @@ class TourController {
});
}
@UseGuards(JwtAuthGuard, TourRoleGuard)
@Get(':id')
async getTourDetails(@Param('id', ParseUUIDPipe) id: string) {
const tour = await this.prisma.tour.findUnique({
@@ -618,7 +626,7 @@ class UserController {
}),
],
controllers: [AppController, AuthController, TourController, UserController, RoutingController, LegController, LocationController],
providers: [PrismaService, JwtStrategy],
providers: [PrismaService, JwtStrategy, TourRoleGuard],
exports: [PrismaService]
})
class AppModule {}