transpost chagnes
This commit is contained in:
@@ -42,13 +42,12 @@ export const PickupDetailDto = z.object({
|
||||
locationLat: z.number().nullable().optional(),
|
||||
locationLong: z.number().nullable().optional(),
|
||||
locationAddress: z.string().nullable().optional(),
|
||||
transportBasePrice: z.number().int().optional().default(0),
|
||||
transportTotalPrice: z.number().int().optional().default(0),
|
||||
transportTotalPrice: z.number().int().min(1),
|
||||
});
|
||||
|
||||
|
||||
export const PickupTransportDto = z.object({
|
||||
transportModeXid: z.number().int(),
|
||||
isTransportModeChargeable: z.boolean().optional().default(false),
|
||||
pickupDetails: z.array(PickupDetailDto).optional().default([]),
|
||||
});
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ const bucket = config.aws.bucketName;
|
||||
|
||||
@Injectable()
|
||||
export class HostService {
|
||||
constructor(private prisma: PrismaClient) { }
|
||||
constructor(private prisma: PrismaClient) {}
|
||||
|
||||
async createHost(data: CreateHostDto) {
|
||||
return this.prisma.user.create({ data });
|
||||
@@ -762,7 +762,7 @@ export class HostService {
|
||||
if (
|
||||
existingHostCompany &&
|
||||
existingHostCompany.hostStatusInternal ===
|
||||
HOST_STATUS_INTERNAL.HOST_TO_UPDATE &&
|
||||
HOST_STATUS_INTERNAL.HOST_TO_UPDATE &&
|
||||
!isDraft
|
||||
) {
|
||||
hostStatusInternal = HOST_STATUS_INTERNAL.HOST_SUBMITTED;
|
||||
@@ -775,7 +775,7 @@ export class HostService {
|
||||
else if (
|
||||
existingHostCompany &&
|
||||
existingHostCompany.hostStatusInternal ===
|
||||
HOST_STATUS_INTERNAL.HOST_TO_UPDATE &&
|
||||
HOST_STATUS_INTERNAL.HOST_TO_UPDATE &&
|
||||
isDraft
|
||||
) {
|
||||
// keep original
|
||||
@@ -886,19 +886,19 @@ export class HostService {
|
||||
// Safely handle city connection - only connect if valid ID exists
|
||||
cities:
|
||||
parentCompanyData?.cityXid &&
|
||||
!isNaN(Number(parentCompanyData.cityXid))
|
||||
!isNaN(Number(parentCompanyData.cityXid))
|
||||
? { connect: { id: Number(parentCompanyData.cityXid) } }
|
||||
: undefined,
|
||||
|
||||
states:
|
||||
parentCompanyData?.stateXid &&
|
||||
!isNaN(Number(parentCompanyData.stateXid))
|
||||
!isNaN(Number(parentCompanyData.stateXid))
|
||||
? { connect: { id: Number(parentCompanyData.stateXid) } }
|
||||
: undefined,
|
||||
|
||||
countries:
|
||||
parentCompanyData?.countryXid &&
|
||||
!isNaN(Number(parentCompanyData.countryXid))
|
||||
!isNaN(Number(parentCompanyData.countryXid))
|
||||
? { connect: { id: Number(parentCompanyData.countryXid) } }
|
||||
: undefined,
|
||||
pinCode: parentCompanyData.pinCode || null,
|
||||
@@ -1048,19 +1048,19 @@ export class HostService {
|
||||
address2: parentCompanyData.address2 || null,
|
||||
cities:
|
||||
parentCompanyData?.cityXid &&
|
||||
!isNaN(Number(parentCompanyData.cityXid))
|
||||
!isNaN(Number(parentCompanyData.cityXid))
|
||||
? { connect: { id: Number(parentCompanyData.cityXid) } }
|
||||
: undefined,
|
||||
|
||||
states:
|
||||
parentCompanyData?.stateXid &&
|
||||
!isNaN(Number(parentCompanyData.stateXid))
|
||||
!isNaN(Number(parentCompanyData.stateXid))
|
||||
? { connect: { id: Number(parentCompanyData.stateXid) } }
|
||||
: undefined,
|
||||
|
||||
countries:
|
||||
parentCompanyData?.countryXid &&
|
||||
!isNaN(Number(parentCompanyData.countryXid))
|
||||
!isNaN(Number(parentCompanyData.countryXid))
|
||||
? { connect: { id: Number(parentCompanyData.countryXid) } }
|
||||
: undefined,
|
||||
pinCode: parentCompanyData.pinCode || null,
|
||||
@@ -1106,19 +1106,19 @@ export class HostService {
|
||||
address2: parentCompanyData.address2 || null,
|
||||
cities:
|
||||
parentCompanyData?.cityXid &&
|
||||
!isNaN(Number(parentCompanyData.cityXid))
|
||||
!isNaN(Number(parentCompanyData.cityXid))
|
||||
? { connect: { id: Number(parentCompanyData.cityXid) } }
|
||||
: undefined,
|
||||
|
||||
states:
|
||||
parentCompanyData?.stateXid &&
|
||||
!isNaN(Number(parentCompanyData.stateXid))
|
||||
!isNaN(Number(parentCompanyData.stateXid))
|
||||
? { connect: { id: Number(parentCompanyData.stateXid) } }
|
||||
: undefined,
|
||||
|
||||
countries:
|
||||
parentCompanyData?.countryXid &&
|
||||
!isNaN(Number(parentCompanyData.countryXid))
|
||||
!isNaN(Number(parentCompanyData.countryXid))
|
||||
? { connect: { id: Number(parentCompanyData.countryXid) } }
|
||||
: undefined,
|
||||
pinCode: parentCompanyData.pinCode || null,
|
||||
@@ -1192,10 +1192,8 @@ export class HostService {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
console.log('Last ke else block me aaya hai');
|
||||
const previousParent = existingHostCompany.hostParent;
|
||||
let prevParentId = null;
|
||||
@@ -1749,7 +1747,7 @@ export class HostService {
|
||||
select: {
|
||||
id: true,
|
||||
interestName: true,
|
||||
}
|
||||
},
|
||||
},
|
||||
energyLevel: {
|
||||
select: {
|
||||
@@ -1757,9 +1755,9 @@ export class HostService {
|
||||
energyLevelName: true,
|
||||
energyIcon: true,
|
||||
energyColor: true,
|
||||
displayOrder: true
|
||||
}
|
||||
}
|
||||
displayOrder: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ActivitiesMedia: {
|
||||
@@ -1800,9 +1798,9 @@ export class HostService {
|
||||
isPackage: true,
|
||||
sessionValidity: true,
|
||||
sessionValidityFrequency: true,
|
||||
sellPrice: true
|
||||
}
|
||||
}
|
||||
sellPrice: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ActivityPickUpDetails: {
|
||||
@@ -1821,17 +1819,17 @@ export class HostService {
|
||||
},
|
||||
activityPickUpTransports: {
|
||||
where: {
|
||||
isActive: true
|
||||
isActive: true,
|
||||
},
|
||||
select: {
|
||||
transportModeXid: true,
|
||||
transportMode: {
|
||||
select: {
|
||||
transportModeName: true,
|
||||
transportModeIcon: true
|
||||
}
|
||||
}
|
||||
}
|
||||
transportModeIcon: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
foodAvailable: true,
|
||||
foodIsChargeable: true,
|
||||
@@ -2426,9 +2424,9 @@ export class HostService {
|
||||
const rootTaxes =
|
||||
taxIds.length > 0
|
||||
? await this.prisma.taxes.findMany({
|
||||
where: { id: { in: taxIds }, isActive: true },
|
||||
select: { id: true, taxPer: true },
|
||||
})
|
||||
where: { id: { in: taxIds }, isActive: true },
|
||||
select: { id: true, taxPer: true },
|
||||
})
|
||||
: [];
|
||||
|
||||
if (taxIds.length !== rootTaxes.length) {
|
||||
@@ -2869,70 +2867,51 @@ export class HostService {
|
||||
/* --------------------------------
|
||||
* 1️⃣1️⃣ CLEAN & CREATE PICKUP/DROP TRANSPORTS WITH DETAILS & TAXES
|
||||
* -------------------------------- */
|
||||
const oldTransportIds = (
|
||||
await tx.activityPickUpTransport.findMany({
|
||||
where: { activityXid },
|
||||
/* --------------------------------
|
||||
* 1️⃣1️⃣ CLEAN OLD PICKUP/DROP DATA
|
||||
* -------------------------------- */
|
||||
const oldPickupDetailIds = (
|
||||
await tx.activityPickUpDetails.findMany({
|
||||
where: { activitiesXid: activityXid },
|
||||
select: { id: true },
|
||||
})
|
||||
).map((t) => t.id);
|
||||
).map((p) => p.id);
|
||||
|
||||
if (oldTransportIds.length) {
|
||||
// Get all pickup details for these transports
|
||||
const oldPickupDetailIds = (
|
||||
await tx.activityPickUpDetails.findMany({
|
||||
where: { activityPickUpTransportXid: { in: oldTransportIds } },
|
||||
select: { id: true },
|
||||
})
|
||||
).map((p) => p.id);
|
||||
if (oldPickupDetailIds.length) {
|
||||
await tx.activityPickUpTransportTaxes.deleteMany({
|
||||
where: {
|
||||
activityPickUpDetailsXid: { in: oldPickupDetailIds },
|
||||
},
|
||||
});
|
||||
|
||||
if (oldPickupDetailIds.length) {
|
||||
// Delete taxes first
|
||||
await tx.activityPickUpTransportTaxes.deleteMany({
|
||||
where: { activityPickUpDetailsXid: { in: oldPickupDetailIds } },
|
||||
});
|
||||
// Delete pickup details
|
||||
await tx.activityPickUpDetails.deleteMany({
|
||||
where: { id: { in: oldPickupDetailIds } },
|
||||
});
|
||||
}
|
||||
|
||||
// Delete transports
|
||||
await tx.activityPickUpTransport.deleteMany({
|
||||
where: { id: { in: oldTransportIds } },
|
||||
where: {
|
||||
activityPickUpDetailsId: { in: oldPickupDetailIds },
|
||||
},
|
||||
});
|
||||
|
||||
await tx.activityPickUpDetails.deleteMany({
|
||||
where: { id: { in: oldPickupDetailIds } },
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
Array.isArray(payload.pickupTransports) &&
|
||||
payload.pickupTransports.length
|
||||
) {
|
||||
if (Array.isArray(payload.pickupTransports)) {
|
||||
for (const transport of payload.pickupTransports) {
|
||||
// Create transport mode
|
||||
const transportRow = await tx.activityPickUpTransport.create({
|
||||
data: {
|
||||
activityXid,
|
||||
transportModeXid: transport.transportModeXid,
|
||||
isTransportModeChargeable: toBool(
|
||||
transport.isTransportModeChargeable,
|
||||
),
|
||||
},
|
||||
});
|
||||
// transport.transportModeXid is here ✅
|
||||
|
||||
// Create pickup details for this transport
|
||||
if (
|
||||
Array.isArray(transport.pickupDetails) &&
|
||||
transport.pickupDetails.length
|
||||
) {
|
||||
if (Array.isArray(transport.pickupDetails)) {
|
||||
for (const detail of transport.pickupDetails) {
|
||||
const totalPrice = toNumber(detail.transportTotalPrice) ?? 0;
|
||||
|
||||
const { basePrice, taxDetails } = computeBasePriceAndTaxes(
|
||||
totalPrice,
|
||||
rootTaxes,
|
||||
);
|
||||
|
||||
/* 1️⃣ CREATE PICKUP DETAILS (PRICE OWNER) */
|
||||
const pickupDetail = await tx.activityPickUpDetails.create({
|
||||
data: {
|
||||
activityPickUpTransportXid: transportRow.id,
|
||||
activitiesXid: activityXid,
|
||||
isPickUp: toBool(detail.isPickUp),
|
||||
locationLat: toNumber(detail.locationLat),
|
||||
locationLong: toNumber(detail.locationLong),
|
||||
@@ -2942,6 +2921,16 @@ export class HostService {
|
||||
},
|
||||
});
|
||||
|
||||
/* 2️⃣ CREATE TRANSPORT MODE */
|
||||
await tx.activityPickUpTransport.create({
|
||||
data: {
|
||||
activityXid: activityXid, // required by your schema
|
||||
transportModeXid: transport.transportModeXid,
|
||||
activityPickUpDetailsId: pickupDetail.id,
|
||||
},
|
||||
});
|
||||
|
||||
/* 3️⃣ CREATE TAXES */
|
||||
if (taxDetails.length) {
|
||||
await tx.activityPickUpTransportTaxes.createMany({
|
||||
data: taxDetails.map((t) => ({
|
||||
|
||||
Reference in New Issue
Block a user