Sửa lỗi hiển thị điểm đầu và điểm cuối của lộ trình trên bản đồ

This commit is contained in:
2026-06-14 09:06:51 +07:00
parent c7db2c3ed8
commit ed437cdb0f
16 changed files with 783 additions and 163 deletions
+78 -3
View File
@@ -110,8 +110,11 @@ class TourController {
@UseGuards(JwtAuthGuard)
@Post(':tourId/locations')
async addLocation(@Param('tourId', ParseUUIDPipe) tourId: string, @Body() body: any) {
async addLocation(@Param('tourId', ParseUUIDPipe) tourId: string, @Body() body: any, @Req() req: any) {
const legId = body.legId;
console.log(`[USER ACTION] User ${req.user.id} added a NEW VISIT point to Tour ${tourId}: "${body.name}"`);
const leg = legId
? await this.prisma.leg.findUnique({ where: { id: legId } })
: await this.prisma.leg.findFirst({ where: { tourId } });
@@ -132,6 +135,78 @@ class TourController {
});
}
@UseGuards(JwtAuthGuard)
@Post(':tourId/start-point')
async updateTourStartPoint(@Param('tourId', ParseUUIDPipe) tourId: string, @Body() body: any, @Req() req: any) {
const { latitude, longitude, name } = body;
console.log(`[USER ACTION] User ${req.user.id} set START point for Tour ${tourId}: "${name}" at [${latitude}, ${longitude}]`);
// 1. Xóa tất cả các điểm bắt đầu cũ của Tour này (được đánh dấu bằng plannedStart = 0)
// để đảm bảo tính duy nhất và sạch sẽ của dữ liệu.
await this.prisma.location.deleteMany({
where: {
leg: { tourId: tourId },
plannedStart: new Date(0)
}
});
// Tìm chặng đầu tiên của tour để ghim điểm xuất phát
const firstLeg = await this.prisma.leg.findFirst({
where: { tourId },
orderBy: { sequence: 'asc' }
});
if (!firstLeg) throw new NotFoundException('Không tìm thấy chặng đầu tiên cho Tour này');
// 2. Tạo mới điểm xuất phát tại Chặng 1
return this.prisma.location.create({
data: {
name: name || 'Điểm xuất phát',
latitude,
longitude,
type: 'MOVE',
legId: firstLeg.id,
plannedStart: new Date(0),
}
});
}
@UseGuards(JwtAuthGuard)
@Post(':tourId/end-point')
async updateTourEndPoint(@Param('tourId', ParseUUIDPipe) tourId: string, @Body() body: any, @Req() req: any) {
const { latitude, longitude, name } = body;
console.log(`[USER ACTION] User ${req.user.id} set END point for Tour ${tourId}: "${name}" at [${latitude}, ${longitude}]`);
// Xóa điểm kết thúc cũ (được đánh dấu bằng plannedEnd = 0) để tránh trùng lặp ghim trên bản đồ
await this.prisma.location.deleteMany({
where: {
leg: { tourId: tourId },
plannedEnd: new Date(0)
}
});
// Tìm chặng cuối cùng của tour để ghim điểm kết thúc
const lastLeg = await this.prisma.leg.findFirst({
where: { tourId },
orderBy: { sequence: 'desc' }
});
if (!lastLeg) throw new NotFoundException('Không tìm thấy chặng cuối cùng cho Tour này');
return this.prisma.location.create({
data: {
name: name || 'Điểm kết thúc',
latitude,
longitude,
type: 'MOVE',
legId: lastLeg.id,
plannedEnd: new Date(0), // Đánh dấu đây là điểm kết thúc đặc biệt
}
});
}
@UseGuards(JwtAuthGuard)
@Post(':tourId/legs')
async addLeg(@Param('tourId', ParseUUIDPipe) tourId: string, @Body() body: any) {
@@ -182,9 +257,9 @@ class TourController {
include: {
photos: { take: 1 },
legs: {
take: 1,
orderBy: { sequence: 'asc' },
include: {
locations: { take: 1 }
locations: { orderBy: { plannedStart: 'asc' } }
}
}
}