add hotel schedule (again)
This commit is contained in:
@@ -465,7 +465,7 @@ export class PackageController extends Controller {
|
||||
const makkahHotel = await orm.em.findOne(
|
||||
Hotel,
|
||||
{
|
||||
id: body.makkah_hotel_id,
|
||||
id: body.makkah_hotel.hotel_id,
|
||||
},
|
||||
{
|
||||
populate: ["*"],
|
||||
@@ -487,7 +487,7 @@ export class PackageController extends Controller {
|
||||
const madinahHotel = await orm.em.findOne(
|
||||
Hotel,
|
||||
{
|
||||
id: body.madinah_hotel_id,
|
||||
id: body.madinah_hotel.hotel_id,
|
||||
},
|
||||
{
|
||||
populate: ["*"],
|
||||
@@ -671,8 +671,22 @@ export class PackageController extends Controller {
|
||||
tourFlight: tourFlightSchedule,
|
||||
outboundFlight: outboundFlightSchedule,
|
||||
inboundFlight: inboundFlightSchedule,
|
||||
makkahHotel: makkahHotel,
|
||||
madinahHotel: madinahHotel,
|
||||
makkahHotel: {
|
||||
id: ulid(),
|
||||
hotel: makkahHotel,
|
||||
checkIn: body.makkah_hotel.check_in,
|
||||
checkOut: body.makkah_hotel.check_out,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
madinahHotel: {
|
||||
id: ulid(),
|
||||
hotel: madinahHotel,
|
||||
checkIn: body.madinah_hotel.check_in,
|
||||
checkOut: body.madinah_hotel.check_out,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
transportation: transportationClass,
|
||||
quadPrice: body.quad_price,
|
||||
quadDiscount: body.quad_discount,
|
||||
@@ -687,22 +701,22 @@ export class PackageController extends Controller {
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
|
||||
for (const [index, tourHotelId] of (body.tour_hotel_ids ?? []).entries()) {
|
||||
const tourHotel = await orm.em.findOne(
|
||||
for (const [index, tourHotel] of (body.tour_hotels ?? []).entries()) {
|
||||
const tourHotelEntity = await orm.em.findOne(
|
||||
Hotel,
|
||||
{
|
||||
id: tourHotelId,
|
||||
id: tourHotel.hotel_id,
|
||||
},
|
||||
{
|
||||
populate: ["*"],
|
||||
},
|
||||
);
|
||||
if (!tourHotel) {
|
||||
if (!tourHotelEntity) {
|
||||
return res.status(404).json({
|
||||
data: null,
|
||||
errors: [
|
||||
{
|
||||
path: `tour_hotel_ids.${index}`,
|
||||
path: `tour_hotels.${index}.hotel_id`,
|
||||
location: "body",
|
||||
message: "Hotel not found.",
|
||||
},
|
||||
@@ -710,7 +724,14 @@ export class PackageController extends Controller {
|
||||
});
|
||||
}
|
||||
|
||||
packageDetail.tourHotels.add(tourHotel);
|
||||
packageDetail.tourHotels.add({
|
||||
id: ulid(),
|
||||
hotel: tourHotelEntity,
|
||||
checkIn: tourHotel.check_in,
|
||||
checkOut: tourHotel.check_out,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
}
|
||||
|
||||
await orm.em.flush();
|
||||
@@ -1029,7 +1050,7 @@ export class PackageController extends Controller {
|
||||
const makkahHotel = await orm.em.findOne(
|
||||
Hotel,
|
||||
{
|
||||
id: body.makkah_hotel_id,
|
||||
id: body.makkah_hotel.hotel_id,
|
||||
},
|
||||
{
|
||||
populate: ["*"],
|
||||
@@ -1051,7 +1072,7 @@ export class PackageController extends Controller {
|
||||
const madinahHotel = await orm.em.findOne(
|
||||
Hotel,
|
||||
{
|
||||
id: body.madinah_hotel_id,
|
||||
id: body.madinah_hotel.hotel_id,
|
||||
},
|
||||
{
|
||||
populate: ["*"],
|
||||
@@ -1258,8 +1279,18 @@ export class PackageController extends Controller {
|
||||
tourFlight: tourFlightSchedule,
|
||||
outboundFlight: outboundFlightSchedule,
|
||||
inboundFlight: inboundFlightSchedule,
|
||||
makkahHotel: makkahHotel,
|
||||
madinahHotel: madinahHotel,
|
||||
makkahHotel: {
|
||||
hotel: makkahHotel,
|
||||
checkIn: body.makkah_hotel.check_in,
|
||||
checkOut: body.makkah_hotel.check_out,
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
madinahHotel: {
|
||||
hotel: madinahHotel,
|
||||
checkIn: body.madinah_hotel.check_in,
|
||||
checkOut: body.madinah_hotel.check_out,
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
transportation: transportationClass,
|
||||
quadPrice: body.quad_price,
|
||||
quadDiscount: body.quad_discount,
|
||||
@@ -1274,22 +1305,22 @@ export class PackageController extends Controller {
|
||||
});
|
||||
|
||||
packageDetail.tourHotels.set([]);
|
||||
for (const [index, tourHotelId] of (body.tour_hotel_ids ?? []).entries()) {
|
||||
const tourHotel = await orm.em.findOne(
|
||||
for (const [index, tourHotel] of (body.tour_hotels ?? []).entries()) {
|
||||
const tourHotelEntity = await orm.em.findOne(
|
||||
Hotel,
|
||||
{
|
||||
id: tourHotelId,
|
||||
id: tourHotel.hotel_id,
|
||||
},
|
||||
{
|
||||
populate: ["*"],
|
||||
},
|
||||
);
|
||||
if (!tourHotel) {
|
||||
if (!tourHotelEntity) {
|
||||
return res.status(404).json({
|
||||
data: null,
|
||||
errors: [
|
||||
{
|
||||
path: `tour_hotel_ids.${index}`,
|
||||
path: `tour_hotels.${index}.hotel_id`,
|
||||
location: "body",
|
||||
message: "Hotel not found.",
|
||||
},
|
||||
@@ -1297,7 +1328,14 @@ export class PackageController extends Controller {
|
||||
});
|
||||
}
|
||||
|
||||
packageDetail.tourHotels.add(tourHotel);
|
||||
packageDetail.tourHotels.add({
|
||||
id: ulid(),
|
||||
hotel: tourHotelEntity,
|
||||
checkIn: tourHotel.check_in,
|
||||
checkOut: tourHotel.check_out,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
}
|
||||
|
||||
await orm.em.flush();
|
||||
|
||||
Reference in New Issue
Block a user