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 -4
View File
@@ -129,8 +129,9 @@ let TourController = class TourController {
}
});
}
async addLocation(tourId, body) {
async addLocation(tourId, body, req) {
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 } });
@@ -149,6 +150,58 @@ let TourController = class TourController {
}
});
}
async updateTourStartPoint(tourId, body, req) {
const { latitude, longitude, name } = body;
console.log(`[USER ACTION] User ${req.user.id} set START point for Tour ${tourId}: "${name}" at [${latitude}, ${longitude}]`);
await this.prisma.location.deleteMany({
where: {
leg: { tourId: tourId },
plannedStart: new Date(0)
}
});
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');
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),
}
});
}
async updateTourEndPoint(tourId, body, req) {
const { latitude, longitude, name } = body;
console.log(`[USER ACTION] User ${req.user.id} set END point for Tour ${tourId}: "${name}" at [${latitude}, ${longitude}]`);
await this.prisma.location.deleteMany({
where: {
leg: { tourId: tourId },
plannedEnd: new Date(0)
}
});
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),
}
});
}
async addLeg(tourId, body) {
const tour = await this.prisma.tour.findUnique({
where: { id: tourId },
@@ -186,9 +239,9 @@ let TourController = class TourController {
include: {
photos: { take: 1 },
legs: {
take: 1,
orderBy: { sequence: 'asc' },
include: {
locations: { take: 1 }
locations: { orderBy: { plannedStart: 'asc' } }
}
}
}
@@ -228,10 +281,31 @@ __decorate([
Post(':tourId/locations'),
__param(0, Param('tourId', ParseUUIDPipe)),
__param(1, Body()),
__param(2, Req()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object]),
__metadata("design:paramtypes", [String, Object, Object]),
__metadata("design:returntype", Promise)
], TourController.prototype, "addLocation", null);
__decorate([
UseGuards(JwtAuthGuard),
Post(':tourId/start-point'),
__param(0, Param('tourId', ParseUUIDPipe)),
__param(1, Body()),
__param(2, Req()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object, Object]),
__metadata("design:returntype", Promise)
], TourController.prototype, "updateTourStartPoint", null);
__decorate([
UseGuards(JwtAuthGuard),
Post(':tourId/end-point'),
__param(0, Param('tourId', ParseUUIDPipe)),
__param(1, Body()),
__param(2, Req()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object, Object]),
__metadata("design:returntype", Promise)
], TourController.prototype, "updateTourEndPoint", null);
__decorate([
UseGuards(JwtAuthGuard),
Post(':tourId/legs'),