fix: tags không có trong csdl gây nên lỗi crash backend

This commit is contained in:
2026-06-16 11:15:39 +07:00
parent bc49e081c6
commit 8cca4a83ca
9 changed files with 189 additions and 10 deletions
+3 -1
View File
@@ -211,12 +211,13 @@ let TourController = class TourController {
this.prisma = prisma;
}
async createTour(body, req) {
const { title, startDate, endDate, adultCount, childCount, childDiscount } = body;
const { title, startDate, endDate, adultCount, childCount, childDiscount, tags } = body;
return this.prisma.tour.create({
data: {
title,
startDate: startDate ? new Date(startDate) : null,
endDate: endDate ? new Date(endDate) : null,
tags: tags || [],
adultCount: adultCount || 1,
childCount: childCount || 0,
childDiscount: childDiscount || 0,
@@ -384,6 +385,7 @@ let TourController = class TourController {
title: body.title,
description: body.description,
startDate: body.startDate ? new Date(body.startDate) : undefined,
tags: body.tags,
endDate: body.endDate ? new Date(body.endDate) : undefined,
adultCount: body.adultCount !== undefined ? Number(body.adultCount) : undefined,
childCount: body.childCount !== undefined ? Number(body.childCount) : undefined,
+1 -1
View File
File diff suppressed because one or more lines are too long
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Tour" ADD COLUMN "tags" TEXT[];
+1
View File
@@ -90,6 +90,7 @@ model Tour {
childCount Int @default(0)
childDiscount Int @default(30)
tags String[]
createdById String
creator User @relation("TourCreator", fields: [createdById], references: [id])
+3 -1
View File
@@ -150,12 +150,13 @@ class TourController {
@UseGuards(JwtAuthGuard)
@Post()
async createTour(@Body() body: any, @Req() req: any) {
const { title, startDate, endDate, adultCount, childCount, childDiscount } = body;
const { title, startDate, endDate, adultCount, childCount, childDiscount, tags } = body;
return this.prisma.tour.create({
data: {
title,
startDate: startDate ? new Date(startDate) : null,
endDate: endDate ? new Date(endDate) : null,
tags: tags || [],
adultCount: adultCount || 1,
childCount: childCount || 0,
childDiscount: childDiscount || 0,
@@ -368,6 +369,7 @@ class TourController {
title: body.title,
description: body.description,
startDate: body.startDate ? new Date(body.startDate) : undefined,
tags: body.tags,
endDate: body.endDate ? new Date(body.endDate) : undefined,
adultCount: body.adultCount !== undefined ? Number(body.adultCount) : undefined,
childCount: body.childCount !== undefined ? Number(body.childCount) : undefined,