Cho phép xóa tour và xóa chặng trong Tour Dashboard

This commit is contained in:
2026-06-13 21:48:53 +07:00
parent 578b03d808
commit 5e3f10631f
18 changed files with 580 additions and 42 deletions
+108 -3
View File
@@ -130,9 +130,12 @@ let TourController = class TourController {
});
}
async addLocation(tourId, body) {
const leg = await this.prisma.leg.findFirst({ where: { tourId } });
const legId = body.legId;
const leg = legId
? await this.prisma.leg.findUnique({ where: { id: legId } })
: await this.prisma.leg.findFirst({ where: { tourId } });
if (!leg)
throw new NotFoundException('Không tìm thấy chặng nào trong tour');
throw new NotFoundException('Không tìm thấy chặng phù hợp để thêm địa điểm');
return this.prisma.location.create({
data: {
name: body.name,
@@ -146,6 +149,37 @@ let TourController = class TourController {
}
});
}
async addLeg(tourId, body) {
const tour = await this.prisma.tour.findUnique({
where: { id: tourId },
include: { legs: true }
});
if (!tour)
throw new NotFoundException('Không tìm thấy tour');
return this.prisma.leg.create({
data: {
tourId,
sequence: tour.legs.length + 1,
note: body.note || `Chặng ${tour.legs.length + 1}`
}
});
}
async updateTour(id, body) {
return this.prisma.tour.update({
where: { id },
data: {
title: body.title,
startDate: body.startDate ? new Date(body.startDate) : undefined,
endDate: body.endDate ? new Date(body.endDate) : undefined,
},
});
}
async deleteTour(id) {
await this.prisma.tour.delete({
where: { id },
});
return { success: true };
}
async getPublicTours() {
return this.prisma.tour.findMany({
take: 20,
@@ -198,6 +232,32 @@ __decorate([
__metadata("design:paramtypes", [String, Object]),
__metadata("design:returntype", Promise)
], TourController.prototype, "addLocation", null);
__decorate([
UseGuards(JwtAuthGuard),
Post(':tourId/legs'),
__param(0, Param('tourId', ParseUUIDPipe)),
__param(1, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object]),
__metadata("design:returntype", Promise)
], TourController.prototype, "addLeg", null);
__decorate([
UseGuards(JwtAuthGuard),
Patch(':id'),
__param(0, Param('id', ParseUUIDPipe)),
__param(1, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object]),
__metadata("design:returntype", Promise)
], TourController.prototype, "updateTour", null);
__decorate([
UseGuards(JwtAuthGuard),
Delete(':id'),
__param(0, Param('id', ParseUUIDPipe)),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], TourController.prototype, "deleteTour", null);
__decorate([
Get('explore'),
__metadata("design:type", Function),
@@ -215,6 +275,51 @@ TourController = __decorate([
Controller('v1/tours'),
__metadata("design:paramtypes", [PrismaService])
], TourController);
let LegController = class LegController {
constructor(prisma) {
this.prisma = prisma;
}
async updateLeg(id, body) {
return this.prisma.leg.update({
where: { id },
data: {
note: body.note,
sequence: body.sequence
}
});
}
async deleteLeg(id) {
const leg = await this.prisma.leg.findUnique({
where: { id },
include: { _count: { select: { locations: true } } }
});
if (leg?._count.locations && leg._count.locations > 0) {
throw new BadRequestException('Không thể xóa chặng đang có địa điểm. Hãy xóa địa điểm trước.');
}
await this.prisma.leg.delete({ where: { id } });
return { success: true };
}
};
__decorate([
Patch(':id'),
__param(0, Param('id', ParseUUIDPipe)),
__param(1, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object]),
__metadata("design:returntype", Promise)
], LegController.prototype, "updateLeg", null);
__decorate([
Delete(':id'),
__param(0, Param('id', ParseUUIDPipe)),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], LegController.prototype, "deleteLeg", null);
LegController = __decorate([
Controller('v1/legs'),
UseGuards(JwtAuthGuard),
__metadata("design:paramtypes", [PrismaService])
], LegController);
function calculateDistance(lat1, lon1, lat2, lon2) {
const p = 0.017453292519943295;
const c = Math.cos;
@@ -363,7 +468,7 @@ AppModule = __decorate([
signOptions: { expiresIn: '1d' },
}),
],
controllers: [AppController, AuthController, TourController, UserController, RoutingController],
controllers: [AppController, AuthController, TourController, UserController, RoutingController, LegController],
providers: [PrismaService, JwtStrategy],
exports: [PrismaService]
})