fix: sửa tính năng hiển thị quãng đường tại điểm đến kế tiếp
This commit is contained in:
Vendored
+117
-16
@@ -189,6 +189,9 @@ let TourRoleGuard = class TourRoleGuard {
|
||||
if (!rolesToCheck.some(r => role === r)) {
|
||||
throw new common_1.ForbiddenException('Bạn không có quyền thực hiện hành động này trong tour này.');
|
||||
}
|
||||
if (tourId) {
|
||||
request.tourId = tourId;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -405,6 +408,11 @@ let TourController = class TourController {
|
||||
}
|
||||
});
|
||||
}
|
||||
await Promise.all([
|
||||
this.cacheManager.del(tourId),
|
||||
this.cacheManager.del(`/api/v1/tours/${tourId}`),
|
||||
this.cacheManager.del(`/api/v1/tours/${tourId}/public`),
|
||||
]);
|
||||
return loc;
|
||||
});
|
||||
}
|
||||
@@ -432,6 +440,13 @@ let TourController = class TourController {
|
||||
legId: firstLeg.id,
|
||||
plannedStart: new Date(0),
|
||||
}
|
||||
}).then(async (loc) => {
|
||||
await Promise.all([
|
||||
this.cacheManager.del(tourId),
|
||||
this.cacheManager.del(`/api/v1/tours/${tourId}`),
|
||||
this.cacheManager.del(`/api/v1/tours/${tourId}/public`),
|
||||
]);
|
||||
return loc;
|
||||
});
|
||||
}
|
||||
async updateTourEndPoint(tourId, body, req) {
|
||||
@@ -458,6 +473,13 @@ let TourController = class TourController {
|
||||
legId: lastLeg.id,
|
||||
plannedEnd: new Date(0),
|
||||
}
|
||||
}).then(async (loc) => {
|
||||
await Promise.all([
|
||||
this.cacheManager.del(tourId),
|
||||
this.cacheManager.del(`/api/v1/tours/${tourId}`),
|
||||
this.cacheManager.del(`/api/v1/tours/${tourId}/public`),
|
||||
]);
|
||||
return loc;
|
||||
});
|
||||
}
|
||||
async initializeLegs(tourId, body) {
|
||||
@@ -491,6 +513,11 @@ let TourController = class TourController {
|
||||
data: { legId: lastLeg.id }
|
||||
});
|
||||
}
|
||||
await Promise.all([
|
||||
this.cacheManager.del(tourId),
|
||||
this.cacheManager.del(`/api/v1/tours/${tourId}`),
|
||||
this.cacheManager.del(`/api/v1/tours/${tourId}/public`),
|
||||
]);
|
||||
return allLegs;
|
||||
}
|
||||
async addLeg(tourId, body) {
|
||||
@@ -506,6 +533,13 @@ let TourController = class TourController {
|
||||
sequence: tour.legs.length + 1,
|
||||
note: body.note || `Chặng ${tour.legs.length + 1}`
|
||||
}
|
||||
}).then(async (leg) => {
|
||||
await Promise.all([
|
||||
this.cacheManager.del(tourId),
|
||||
this.cacheManager.del(`/api/v1/tours/${tourId}`),
|
||||
this.cacheManager.del(`/api/v1/tours/${tourId}/public`),
|
||||
]);
|
||||
return leg;
|
||||
});
|
||||
}
|
||||
async updateTour(id, body) {
|
||||
@@ -521,6 +555,13 @@ let TourController = class TourController {
|
||||
childCount: body.childCount !== undefined ? Number(body.childCount) : undefined,
|
||||
childDiscount: body.childDiscount !== undefined ? Number(body.childDiscount) : undefined,
|
||||
},
|
||||
}).then(async (tour) => {
|
||||
await Promise.all([
|
||||
this.cacheManager.del(id),
|
||||
this.cacheManager.del(`/api/v1/tours/${id}`),
|
||||
this.cacheManager.del(`/api/v1/tours/${id}/public`),
|
||||
]);
|
||||
return tour;
|
||||
});
|
||||
}
|
||||
async deleteTour(id) {
|
||||
@@ -1013,10 +1054,11 @@ TourController = __decorate([
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService, Object])
|
||||
], TourController);
|
||||
let LocationController = class LocationController {
|
||||
constructor(prisma) {
|
||||
constructor(prisma, cacheManager) {
|
||||
this.prisma = prisma;
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
async updateLocation(id, body) {
|
||||
async updateLocation(id, body, req) {
|
||||
const { expenseAmount, expenseCategory, ...data } = body;
|
||||
const location = await this.prisma.location.update({
|
||||
where: { id },
|
||||
@@ -1054,38 +1096,63 @@ let LocationController = class LocationController {
|
||||
});
|
||||
}
|
||||
}
|
||||
if (req.tourId) {
|
||||
await Promise.all([
|
||||
this.cacheManager.del(req.tourId),
|
||||
this.cacheManager.del(`/api/v1/tours/${req.tourId}`),
|
||||
this.cacheManager.del(`/api/v1/tours/${req.tourId}/public`),
|
||||
]);
|
||||
}
|
||||
return location;
|
||||
}
|
||||
async deleteLocation(id) {
|
||||
await this.prisma.location.delete({ where: { id } });
|
||||
async deleteLocation(id, req) {
|
||||
try {
|
||||
await this.prisma.location.delete({ where: { id } });
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
await this.cacheManager.del(`res-to-tour:${id}`);
|
||||
if (req.tourId) {
|
||||
await Promise.all([
|
||||
this.cacheManager.del(req.tourId),
|
||||
this.cacheManager.del(`/api/v1/tours/${req.tourId}`),
|
||||
this.cacheManager.del(`/api/v1/tours/${req.tourId}/public`),
|
||||
]);
|
||||
}
|
||||
return { success: true };
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Patch)(':id'),
|
||||
(0, common_1.UseGuards)(TourRoleGuard),
|
||||
__param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__param(2, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String, Object]),
|
||||
__metadata("design:paramtypes", [String, Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], LocationController.prototype, "updateLocation", null);
|
||||
__decorate([
|
||||
(0, common_1.Delete)(':id'),
|
||||
(0, common_1.UseGuards)(TourRoleGuard),
|
||||
__param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String]),
|
||||
__metadata("design:paramtypes", [String, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], LocationController.prototype, "deleteLocation", null);
|
||||
LocationController = __decorate([
|
||||
(0, common_1.Controller)('locations'),
|
||||
(0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard),
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
||||
__param(1, (0, common_1.Inject)(cache_manager_1.CACHE_MANAGER)),
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService, Object])
|
||||
], LocationController);
|
||||
let LegController = class LegController {
|
||||
constructor(prisma) {
|
||||
constructor(prisma, cacheManager) {
|
||||
this.prisma = prisma;
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
async updateLeg(id, body) {
|
||||
async updateLeg(id, body, req) {
|
||||
return this.prisma.leg.update({
|
||||
where: { id },
|
||||
data: {
|
||||
@@ -1095,6 +1162,13 @@ let LegController = class LegController {
|
||||
endDate: body.endDate ? new Date(body.endDate) : undefined,
|
||||
description: body.description,
|
||||
}
|
||||
}).then(async (leg) => {
|
||||
await Promise.all([
|
||||
this.cacheManager.del(req.tourId),
|
||||
this.cacheManager.del(`/api/v1/tours/${req.tourId}`),
|
||||
this.cacheManager.del(`/api/v1/tours/${req.tourId}/public`),
|
||||
]);
|
||||
return leg;
|
||||
});
|
||||
}
|
||||
async deleteLeg(id) {
|
||||
@@ -1105,20 +1179,35 @@ let LegController = class LegController {
|
||||
if (leg?._count.locations && leg._count.locations > 0) {
|
||||
throw new common_1.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 } });
|
||||
try {
|
||||
const deletedLeg = await this.prisma.leg.delete({ where: { id } });
|
||||
await this.cacheManager.del(`res-to-tour:${id}`);
|
||||
if (deletedLeg.tourId) {
|
||||
await Promise.all([
|
||||
this.cacheManager.del(deletedLeg.tourId),
|
||||
this.cacheManager.del(`/api/v1/tours/${deletedLeg.tourId}`),
|
||||
this.cacheManager.del(`/api/v1/tours/${deletedLeg.tourId}/public`),
|
||||
]);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
return { success: true };
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Patch)(':id'),
|
||||
(0, common_1.UseGuards)(TourRoleGuard),
|
||||
__param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__param(2, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String, Object]),
|
||||
__metadata("design:paramtypes", [String, Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], LegController.prototype, "updateLeg", null);
|
||||
__decorate([
|
||||
(0, common_1.Delete)(':id'),
|
||||
(0, common_1.UseGuards)(TourRoleGuard),
|
||||
__param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String]),
|
||||
@@ -1128,7 +1217,8 @@ LegController = __decorate([
|
||||
(0, common_1.Controller)('legs'),
|
||||
(0, exports.Roles)(client_1.ParticipantRole.OWNER, client_1.ParticipantRole.MANAGER),
|
||||
(0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, TourRoleGuard),
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
||||
__param(1, (0, common_1.Inject)(cache_manager_1.CACHE_MANAGER)),
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService, Object])
|
||||
], LegController);
|
||||
function calculateDistance(lat1, lon1, lat2, lon2) {
|
||||
const p = 0.017453292519943295;
|
||||
@@ -1139,10 +1229,11 @@ function calculateDistance(lat1, lon1, lat2, lon2) {
|
||||
return 12742 * Math.asin(Math.sqrt(a));
|
||||
}
|
||||
let RoutingController = class RoutingController {
|
||||
constructor(prisma) {
|
||||
constructor(prisma, cacheManager) {
|
||||
this.prisma = prisma;
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
async optimize(legId) {
|
||||
async optimize(legId, req) {
|
||||
const currentLeg = await this.prisma.leg.findUnique({
|
||||
where: { id: legId },
|
||||
});
|
||||
@@ -1214,6 +1305,13 @@ let RoutingController = class RoutingController {
|
||||
where: { legId },
|
||||
orderBy: { plannedStart: 'asc' }
|
||||
});
|
||||
if (req.tourId) {
|
||||
await Promise.all([
|
||||
this.cacheManager.del(req.tourId),
|
||||
this.cacheManager.del(`/api/v1/tours/${req.tourId}`),
|
||||
this.cacheManager.del(`/api/v1/tours/${req.tourId}/public`),
|
||||
]);
|
||||
}
|
||||
return {
|
||||
locations: updatedLocations,
|
||||
totalDistance: parseFloat(totalDistance.toFixed(2))
|
||||
@@ -1222,16 +1320,19 @@ let RoutingController = class RoutingController {
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Post)('optimize/:legId'),
|
||||
(0, common_1.UseGuards)(TourRoleGuard),
|
||||
__param(0, (0, common_1.Param)('legId', common_1.ParseUUIDPipe)),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String]),
|
||||
__metadata("design:paramtypes", [String, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], RoutingController.prototype, "optimize", null);
|
||||
RoutingController = __decorate([
|
||||
(0, common_1.Controller)('routing'),
|
||||
(0, exports.Roles)(client_1.ParticipantRole.OWNER, client_1.ParticipantRole.MANAGER),
|
||||
(0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, TourRoleGuard),
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
||||
__param(1, (0, common_1.Inject)(cache_manager_1.CACHE_MANAGER)),
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService, Object])
|
||||
], RoutingController);
|
||||
let PhotoController = class PhotoController {
|
||||
constructor(prisma) {
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user