Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
833 B
2
Indexable
Never
    const totalAmountReservations = (
      await this.prisma.reservation.findMany({
        where: {
          status: ReservationStatus.CONFIRMED
        },
        include: {
          roomReserved: {
            select: {
              room: {
                select: {
                  id: true,
                  roomType: {
                    select: {
                      price: true
                    }
                  }
                }
              }
            }
          }
        }
      })
    ).reduce(
      (acc, item) =>
        acc +
        item.roomReserved[0].room.roomType.price *
          item.roomReserved.length *
          Math.floor(
            (item.checkOut.getTime() - item.checkIn.getTime()) /
              (1000 * 3600 * 24)
          ),
      0
    );