remove hotel schedule
This commit is contained in:
@@ -11,7 +11,6 @@ import type {
|
||||
} from "@/common/types";
|
||||
import { FlightClass } from "@/database/entities/flight-class.entity";
|
||||
import { FlightSchedule } from "@/database/entities/flight-schedule.entity";
|
||||
import { HotelSchedule } from "@/database/entities/hotel-schedule.entity";
|
||||
import { Hotel } from "@/database/entities/hotel.entity";
|
||||
import { PackageDetail } from "@/database/entities/package-detail.entity";
|
||||
import { PackageItineraryDay } from "@/database/entities/package-itinerary-day.entity";
|
||||
@@ -382,7 +381,7 @@ export class PackageController extends Controller {
|
||||
const makkahHotel = await orm.em.findOne(
|
||||
Hotel,
|
||||
{
|
||||
id: body.makkah_hotel.hotel_id,
|
||||
id: body.makkah_hotel_id,
|
||||
},
|
||||
{
|
||||
populate: ["*"],
|
||||
@@ -393,26 +392,18 @@ export class PackageController extends Controller {
|
||||
data: null,
|
||||
errors: [
|
||||
{
|
||||
path: "makkah_hotel.hotel_id",
|
||||
path: "makkah_hotel_id",
|
||||
location: "body",
|
||||
message: "Hotel not found.",
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
const makkahHotelSchedule = orm.em.create(HotelSchedule, {
|
||||
id: ulid(),
|
||||
hotel: makkahHotel,
|
||||
checkIn: `${body.makkah_hotel.check_in.getHours()}:${body.makkah_hotel.check_in.getMinutes()}:00`,
|
||||
checkOut: `${body.makkah_hotel.check_out.getHours()}:${body.makkah_hotel.check_out.getMinutes()}:00`,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
|
||||
const madinahHotel = await orm.em.findOne(
|
||||
Hotel,
|
||||
{
|
||||
id: body.madinah_hotel.hotel_id,
|
||||
id: body.madinah_hotel_id,
|
||||
},
|
||||
{
|
||||
populate: ["*"],
|
||||
@@ -423,21 +414,13 @@ export class PackageController extends Controller {
|
||||
data: null,
|
||||
errors: [
|
||||
{
|
||||
path: "madinah_hotel.hotel_id",
|
||||
path: "madinah_hotel_id",
|
||||
location: "body",
|
||||
message: "Hotel not found.",
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
const madinahHotelSchedule = orm.em.create(HotelSchedule, {
|
||||
id: ulid(),
|
||||
hotel: madinahHotel,
|
||||
checkIn: `${body.madinah_hotel.check_in.getHours()}:${body.madinah_hotel.check_in.getMinutes()}:00`,
|
||||
checkOut: `${body.madinah_hotel.check_out.getHours()}:${body.madinah_hotel.check_out.getMinutes()}:00`,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
|
||||
const transportationClass = await orm.em.findOne(
|
||||
TransportationClass,
|
||||
@@ -604,8 +587,8 @@ export class PackageController extends Controller {
|
||||
tourFlight: tourFlightSchedule,
|
||||
outboundFlight: outboundFlightSchedule,
|
||||
inboundFlight: inboundFlightSchedule,
|
||||
makkahHotel: makkahHotelSchedule,
|
||||
madinahHotel: madinahHotelSchedule,
|
||||
makkahHotel: makkahHotel,
|
||||
madinahHotel: madinahHotel,
|
||||
transportation: transportationClass,
|
||||
quadPrice: body.quad_price,
|
||||
triplePrice: body.triple_price,
|
||||
@@ -616,22 +599,22 @@ export class PackageController extends Controller {
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
|
||||
for (const [index, tourHotel] of (body.tour_hotels ?? []).entries()) {
|
||||
const tourHotelEntity = await orm.em.findOne(
|
||||
for (const [index, tourHotelId] of (body.tour_hotel_ids ?? []).entries()) {
|
||||
const tourHotel = await orm.em.findOne(
|
||||
Hotel,
|
||||
{
|
||||
id: tourHotel.hotel_id,
|
||||
id: tourHotelId,
|
||||
},
|
||||
{
|
||||
populate: ["*"],
|
||||
},
|
||||
);
|
||||
if (!tourHotelEntity) {
|
||||
if (!tourHotel) {
|
||||
return res.status(404).json({
|
||||
data: null,
|
||||
errors: [
|
||||
{
|
||||
path: `tour_hotels.${index}.hotel_id`,
|
||||
path: `tour_hotel_ids.${index}`,
|
||||
location: "body",
|
||||
message: "Hotel not found.",
|
||||
},
|
||||
@@ -639,16 +622,7 @@ export class PackageController extends Controller {
|
||||
});
|
||||
}
|
||||
|
||||
const tourHotelSchedule = orm.em.create(HotelSchedule, {
|
||||
id: ulid(),
|
||||
hotel: tourHotelEntity,
|
||||
checkIn: `${tourHotel.check_in.getHours()}:${tourHotel.check_in.getMinutes()}:00`,
|
||||
checkOut: `${tourHotel.check_out.getHours()}:${tourHotel.check_out.getMinutes()}:00`,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
|
||||
packageDetail.tourHotels.add(tourHotelSchedule);
|
||||
packageDetail.tourHotels.add(tourHotel);
|
||||
}
|
||||
|
||||
await orm.em.flush();
|
||||
@@ -964,11 +938,10 @@ export class PackageController extends Controller {
|
||||
});
|
||||
}
|
||||
|
||||
orm.em.remove(packageDetail.makkahHotel);
|
||||
const makkahHotel = await orm.em.findOne(
|
||||
Hotel,
|
||||
{
|
||||
id: body.makkah_hotel.hotel_id,
|
||||
id: body.makkah_hotel_id,
|
||||
},
|
||||
{
|
||||
populate: ["*"],
|
||||
@@ -979,27 +952,18 @@ export class PackageController extends Controller {
|
||||
data: null,
|
||||
errors: [
|
||||
{
|
||||
path: "makkah_hotel.hotel_id",
|
||||
path: "makkah_hotel_id",
|
||||
location: "body",
|
||||
message: "Hotel not found.",
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
const makkahHotelSchedule = orm.em.create(HotelSchedule, {
|
||||
id: ulid(),
|
||||
hotel: makkahHotel,
|
||||
checkIn: `${body.makkah_hotel.check_in.getHours()}:${body.makkah_hotel.check_in.getMinutes()}:00`,
|
||||
checkOut: `${body.makkah_hotel.check_out.getHours()}:${body.makkah_hotel.check_out.getMinutes()}:00`,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
|
||||
orm.em.remove(packageDetail.madinahHotel);
|
||||
const madinahHotel = await orm.em.findOne(
|
||||
Hotel,
|
||||
{
|
||||
id: body.madinah_hotel.hotel_id,
|
||||
id: body.madinah_hotel_id,
|
||||
},
|
||||
{
|
||||
populate: ["*"],
|
||||
@@ -1010,21 +974,13 @@ export class PackageController extends Controller {
|
||||
data: null,
|
||||
errors: [
|
||||
{
|
||||
path: "madinah_hotel.hotel_id",
|
||||
path: "madinah_hotel_id",
|
||||
location: "body",
|
||||
message: "Hotel not found.",
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
const madinahHotelSchedule = orm.em.create(HotelSchedule, {
|
||||
id: ulid(),
|
||||
hotel: madinahHotel,
|
||||
checkIn: `${body.madinah_hotel.check_in.getHours()}:${body.madinah_hotel.check_in.getMinutes()}:00`,
|
||||
checkOut: `${body.madinah_hotel.check_out.getHours()}:${body.madinah_hotel.check_out.getMinutes()}:00`,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
|
||||
const transportationClass = await orm.em.findOne(
|
||||
TransportationClass,
|
||||
@@ -1214,8 +1170,8 @@ export class PackageController extends Controller {
|
||||
tourFlight: tourFlightSchedule,
|
||||
outboundFlight: outboundFlightSchedule,
|
||||
inboundFlight: inboundFlightSchedule,
|
||||
makkahHotel: makkahHotelSchedule,
|
||||
madinahHotel: madinahHotelSchedule,
|
||||
makkahHotel: makkahHotel,
|
||||
madinahHotel: madinahHotel,
|
||||
transportation: transportationClass,
|
||||
quadPrice: body.quad_price,
|
||||
triplePrice: body.triple_price,
|
||||
@@ -1225,25 +1181,23 @@ export class PackageController extends Controller {
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
|
||||
for (const tourHotel of packageDetail.tourHotels) {
|
||||
orm.em.remove(tourHotel);
|
||||
}
|
||||
for (const [index, tourHotel] of (body.tour_hotels ?? []).entries()) {
|
||||
const tourHotelEntity = await orm.em.findOne(
|
||||
packageDetail.tourHotels.set([]);
|
||||
for (const [index, tourHotelId] of (body.tour_hotel_ids ?? []).entries()) {
|
||||
const tourHotel = await orm.em.findOne(
|
||||
Hotel,
|
||||
{
|
||||
id: tourHotel.hotel_id,
|
||||
id: tourHotelId,
|
||||
},
|
||||
{
|
||||
populate: ["*"],
|
||||
},
|
||||
);
|
||||
if (!tourHotelEntity) {
|
||||
if (!tourHotel) {
|
||||
return res.status(404).json({
|
||||
data: null,
|
||||
errors: [
|
||||
{
|
||||
path: `tour_hotels.${index}.hotel_id`,
|
||||
path: `tour_hotel_ids.${index}`,
|
||||
location: "body",
|
||||
message: "Hotel not found.",
|
||||
},
|
||||
@@ -1251,16 +1205,7 @@ export class PackageController extends Controller {
|
||||
});
|
||||
}
|
||||
|
||||
const tourHotelSchedule = orm.em.create(HotelSchedule, {
|
||||
id: ulid(),
|
||||
hotel: tourHotelEntity,
|
||||
checkIn: `${tourHotel.check_in.getHours()}:${tourHotel.check_in.getMinutes()}:00`,
|
||||
checkOut: `${tourHotel.check_out.getHours()}:${tourHotel.check_out.getMinutes()}:00`,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
|
||||
packageDetail.tourHotels.add(tourHotelSchedule);
|
||||
packageDetail.tourHotels.add(tourHotel);
|
||||
}
|
||||
|
||||
await orm.em.flush();
|
||||
|
||||
Reference in New Issue
Block a user