archetecture security fix
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.findMany = findMany;
|
||||
exports.findById = findById;
|
||||
exports.findByIdSimple = findByIdSimple;
|
||||
exports.findByIdWithRelations = findByIdWithRelations;
|
||||
exports.findByIdForCheckout = findByIdForCheckout;
|
||||
exports.findForLicenseCheck = findForLicenseCheck;
|
||||
exports.findForContract = findForContract;
|
||||
exports.findForBilling = findForBilling;
|
||||
exports.findForClose = findForClose;
|
||||
exports.findForInspection = findForInspection;
|
||||
exports.findConflict = findConflict;
|
||||
exports.create = create;
|
||||
exports.updateById = updateById;
|
||||
exports.findActiveOffer = findActiveOffer;
|
||||
exports.incrementOfferRedemption = incrementOfferRedemption;
|
||||
exports.findVehicle = findVehicle;
|
||||
exports.findCustomer = findCustomer;
|
||||
exports.findCustomerById = findCustomerById;
|
||||
exports.updateVehicleStatus = updateVehicleStatus;
|
||||
exports.findCompanyWithBrand = findCompanyWithBrand;
|
||||
exports.findBrandLocale = findBrandLocale;
|
||||
exports.findInspections = findInspections;
|
||||
exports.findAdditionalDriver = findAdditionalDriver;
|
||||
exports.updateAdditionalDriver = updateAdditionalDriver;
|
||||
const prisma_1 = require("../../lib/prisma");
|
||||
const FULL_INCLUDE = {
|
||||
vehicle: true,
|
||||
customer: true,
|
||||
insurances: true,
|
||||
additionalDrivers: true,
|
||||
rentalPayments: true,
|
||||
damageReports: true,
|
||||
};
|
||||
async function findMany(where, skip, take) {
|
||||
return Promise.all([
|
||||
prisma_1.prisma.reservation.findMany({
|
||||
where,
|
||||
include: { vehicle: true, customer: true },
|
||||
skip,
|
||||
take,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
}),
|
||||
prisma_1.prisma.reservation.count({ where }),
|
||||
]);
|
||||
}
|
||||
async function findById(id, companyId) {
|
||||
return prisma_1.prisma.reservation.findFirstOrThrow({ where: { id, companyId }, include: FULL_INCLUDE });
|
||||
}
|
||||
async function findByIdSimple(id, companyId) {
|
||||
return prisma_1.prisma.reservation.findFirstOrThrow({ where: { id, companyId } });
|
||||
}
|
||||
async function findByIdWithRelations(id, companyId) {
|
||||
return prisma_1.prisma.reservation.findFirstOrThrow({
|
||||
where: { id, companyId },
|
||||
include: { insurances: true, additionalDrivers: true },
|
||||
});
|
||||
}
|
||||
async function findByIdForCheckout(id, companyId) {
|
||||
return prisma_1.prisma.reservation.findFirstOrThrow({
|
||||
where: { id, companyId },
|
||||
include: { vehicle: true },
|
||||
});
|
||||
}
|
||||
async function findForLicenseCheck(id, companyId) {
|
||||
return prisma_1.prisma.reservation.findFirstOrThrow({
|
||||
where: { id, companyId },
|
||||
include: { customer: true, additionalDrivers: true },
|
||||
});
|
||||
}
|
||||
async function findForContract(id, companyId) {
|
||||
return prisma_1.prisma.reservation.findFirstOrThrow({
|
||||
where: { id, companyId },
|
||||
include: {
|
||||
vehicle: true,
|
||||
customer: true,
|
||||
insurances: true,
|
||||
additionalDrivers: true,
|
||||
rentalPayments: { orderBy: { createdAt: 'asc' } },
|
||||
inspections: { include: { damagePoints: true }, orderBy: { inspectedAt: 'asc' } },
|
||||
company: { include: { brand: true, contractSettings: true, accountingSettings: true } },
|
||||
},
|
||||
});
|
||||
}
|
||||
async function findForBilling(id, companyId) {
|
||||
return prisma_1.prisma.reservation.findFirstOrThrow({
|
||||
where: { id, companyId },
|
||||
include: { vehicle: true, insurances: true, additionalDrivers: true },
|
||||
});
|
||||
}
|
||||
async function findForClose(id, companyId) {
|
||||
return prisma_1.prisma.reservation.findFirstOrThrow({ where: { id, companyId }, include: { customer: true } });
|
||||
}
|
||||
async function findForInspection(id, companyId) {
|
||||
return prisma_1.prisma.reservation.findFirstOrThrow({
|
||||
where: { id, companyId },
|
||||
include: { vehicle: true, customer: true },
|
||||
});
|
||||
}
|
||||
async function findConflict(vehicleId, start, end, excludeId) {
|
||||
return prisma_1.prisma.reservation.findFirst({
|
||||
where: {
|
||||
vehicleId,
|
||||
status: { in: ['CONFIRMED', 'ACTIVE'] },
|
||||
startDate: { lt: end },
|
||||
endDate: { gt: start },
|
||||
...(excludeId ? { id: { not: excludeId } } : {}),
|
||||
},
|
||||
});
|
||||
}
|
||||
async function create(data) {
|
||||
return prisma_1.prisma.reservation.create({ data, include: { vehicle: true, customer: true } });
|
||||
}
|
||||
async function updateById(id, data) {
|
||||
return prisma_1.prisma.reservation.update({ where: { id }, data });
|
||||
}
|
||||
async function findActiveOffer(companyId, promoCode) {
|
||||
return prisma_1.prisma.offer.findFirst({
|
||||
where: { companyId, promoCode, isActive: true, validFrom: { lte: new Date() }, validUntil: { gte: new Date() } },
|
||||
});
|
||||
}
|
||||
async function incrementOfferRedemption(offerId) {
|
||||
return prisma_1.prisma.offer.update({ where: { id: offerId }, data: { redemptionCount: { increment: 1 } } });
|
||||
}
|
||||
async function findVehicle(vehicleId, companyId) {
|
||||
return prisma_1.prisma.vehicle.findFirstOrThrow({ where: { id: vehicleId, companyId } });
|
||||
}
|
||||
async function findCustomer(customerId, companyId) {
|
||||
return prisma_1.prisma.customer.findFirstOrThrow({ where: { id: customerId, companyId } });
|
||||
}
|
||||
async function findCustomerById(customerId) {
|
||||
return prisma_1.prisma.customer.findUniqueOrThrow({ where: { id: customerId } });
|
||||
}
|
||||
async function updateVehicleStatus(vehicleId, status, mileage) {
|
||||
return prisma_1.prisma.vehicle.update({
|
||||
where: { id: vehicleId },
|
||||
data: { status: status, ...(mileage !== undefined ? { mileage } : {}) },
|
||||
});
|
||||
}
|
||||
async function findCompanyWithBrand(companyId) {
|
||||
return prisma_1.prisma.company.findUnique({
|
||||
where: { id: companyId },
|
||||
include: { brand: { select: { displayName: true, defaultLocale: true } } },
|
||||
});
|
||||
}
|
||||
async function findBrandLocale(companyId) {
|
||||
return prisma_1.prisma.brandSettings.findUnique({ where: { companyId }, select: { defaultLocale: true } });
|
||||
}
|
||||
async function findInspections(reservationId, companyId) {
|
||||
return prisma_1.prisma.damageInspection.findMany({
|
||||
where: { reservationId, companyId },
|
||||
include: { damagePoints: true },
|
||||
orderBy: { inspectedAt: 'asc' },
|
||||
});
|
||||
}
|
||||
async function findAdditionalDriver(driverId, reservationId, companyId) {
|
||||
return prisma_1.prisma.additionalDriver.findFirstOrThrow({ where: { id: driverId, reservationId, companyId } });
|
||||
}
|
||||
async function updateAdditionalDriver(id, data) {
|
||||
return prisma_1.prisma.additionalDriver.update({ where: { id }, data });
|
||||
}
|
||||
//# sourceMappingURL=reservation.repo.js.map
|
||||
Reference in New Issue
Block a user