Tạo UI cho người dùng tạo Tour

This commit is contained in:
2026-06-13 20:46:31 +07:00
parent c51ddc34c7
commit 25fcd5d926
28 changed files with 767 additions and 76 deletions
+47 -1
View File
@@ -1,6 +1,6 @@
import 'reflect-metadata';
import { NestFactory } from '@nestjs/core';
import { Module, Controller, Get, Post, Body, Param, Patch, Delete, ParseUUIDPipe, NotFoundException, BadRequestException, UnauthorizedException, UseGuards } from '@nestjs/common';
import { Module, Controller, Get, Post, Body, Param, Patch, Delete, ParseUUIDPipe, NotFoundException, BadRequestException, UnauthorizedException, UseGuards, Req } from '@nestjs/common';
import { PrismaService } from './prisma.service.js';
import 'dotenv/config';
import * as bcrypt from 'bcrypt';
@@ -82,6 +82,52 @@ class AuthController {
class TourController {
constructor(private prisma: PrismaService) {}
@UseGuards(JwtAuthGuard)
@Post()
async createTour(@Body() body: any, @Req() req: any) {
const { title, startDate, endDate } = body;
return this.prisma.tour.create({
data: {
title,
startDate: startDate ? new Date(startDate) : null,
endDate: endDate ? new Date(endDate) : null,
createdById: req.user.id,
participants: {
create: {
userId: req.user.id,
role: 'OWNER'
}
},
legs: {
create: {
sequence: 1,
note: 'Chặng khởi đầu'
}
}
}
});
}
@UseGuards(JwtAuthGuard)
@Post(':tourId/locations')
async addLocation(@Param('tourId', ParseUUIDPipe) tourId: string, @Body() body: any) {
const leg = await this.prisma.leg.findFirst({ where: { tourId } });
if (!leg) throw new NotFoundException('Không tìm thấy chặng nào trong tour');
return this.prisma.location.create({
data: {
name: body.name,
address: body.address,
latitude: body.latitude,
longitude: body.longitude,
type: body.type,
legId: leg.id,
plannedStart: body.plannedStart ? new Date(body.plannedStart) : null,
plannedEnd: body.plannedEnd ? new Date(body.plannedEnd) : null,
}
});
}
@Get('explore')
async getPublicTours() {
// Lấy các tour có ít nhất 1 ảnh và thông tin vị trí từ chặng đầu tiên