fix: block bookings for contracted rooms
This commit is contained in:
@@ -82,6 +82,54 @@ export async function findBookingRoomConflict({
|
||||
return conflict ?? null;
|
||||
}
|
||||
|
||||
export async function findBookingContractRoomConflict({
|
||||
organizationId,
|
||||
roomId,
|
||||
startsAt,
|
||||
endsAt,
|
||||
status
|
||||
}: {
|
||||
organizationId: string;
|
||||
roomId: string;
|
||||
startsAt: string;
|
||||
endsAt: string;
|
||||
status: string;
|
||||
}): Promise<ContractRoomConflict | null> {
|
||||
if (status === 'cancelled') return null;
|
||||
|
||||
const startDate = startsAt.slice(0, 10);
|
||||
const endDate = endsAt.slice(0, 10);
|
||||
|
||||
const [conflict] = await db
|
||||
.select({
|
||||
contractId: contracts.id,
|
||||
roomId: contractRooms.roomId,
|
||||
roomName: rooms.name,
|
||||
startDate: contracts.startDate,
|
||||
endDate: contracts.endDate
|
||||
})
|
||||
.from(contractRooms)
|
||||
.innerJoin(contracts, eq(contractRooms.contractId, contracts.id))
|
||||
.innerJoin(rooms, eq(contractRooms.roomId, rooms.id))
|
||||
.where(
|
||||
and(
|
||||
eq(contracts.organizationId, organizationId),
|
||||
eq(contracts.status, 'active'),
|
||||
isNull(contracts.archivedAt),
|
||||
eq(contractRooms.roomId, roomId),
|
||||
eq(rooms.organizationId, organizationId),
|
||||
inArray(rooms.type, rentableContractRoomTypes),
|
||||
isNull(rooms.archivedAt),
|
||||
lte(contracts.startDate, endDate),
|
||||
gte(contracts.endDate, startDate)
|
||||
)
|
||||
)
|
||||
.orderBy(asc(contracts.startDate), asc(rooms.name))
|
||||
.limit(1);
|
||||
|
||||
return conflict ?? null;
|
||||
}
|
||||
|
||||
export async function findActiveContractRoomConflict({
|
||||
organizationId,
|
||||
roomIds,
|
||||
|
||||
Reference in New Issue
Block a user