Sửa hiển thị điểm đầu và điểm cuối của chặng

This commit is contained in:
2026-06-14 09:28:33 +07:00
parent ed437cdb0f
commit 14bf43487e
17 changed files with 189 additions and 12 deletions
+42
View File
@@ -202,6 +202,39 @@ let TourController = class TourController {
}
});
}
async initializeLegs(tourId, body) {
const { count } = body;
if (count <= 0 || count > 20)
throw new BadRequestException('Số lượng chặng không hợp lệ (1-20)');
const existingLegs = await this.prisma.leg.findMany({
where: { tourId },
orderBy: { sequence: 'asc' }
});
const needed = count - existingLegs.length;
if (needed > 0) {
const createData = Array.from({ length: needed }).map((_, i) => ({
tourId,
sequence: existingLegs.length + i + 1,
note: `Chặng ${existingLegs.length + i + 1}`
}));
await this.prisma.leg.createMany({ data: createData });
}
const allLegs = await this.prisma.leg.findMany({
where: { tourId },
orderBy: { sequence: 'asc' }
});
const lastLeg = allLegs[allLegs.length - 1];
const endPoint = await this.prisma.location.findFirst({
where: { leg: { tourId }, plannedEnd: new Date(0) }
});
if (endPoint && lastLeg && endPoint.legId !== lastLeg.id) {
await this.prisma.location.update({
where: { id: endPoint.id },
data: { legId: lastLeg.id }
});
}
return allLegs;
}
async addLeg(tourId, body) {
const tour = await this.prisma.tour.findUnique({
where: { id: tourId },
@@ -306,6 +339,15 @@ __decorate([
__metadata("design:paramtypes", [String, Object, Object]),
__metadata("design:returntype", Promise)
], TourController.prototype, "updateTourEndPoint", null);
__decorate([
UseGuards(JwtAuthGuard),
Post(':tourId/legs/batch'),
__param(0, Param('tourId', ParseUUIDPipe)),
__param(1, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object]),
__metadata("design:returntype", Promise)
], TourController.prototype, "initializeLegs", null);
__decorate([
UseGuards(JwtAuthGuard),
Post(':tourId/legs'),