Skip to content

Commit

Permalink
style fixes & same roommate multiplier
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanko2 committed Aug 4, 2024
1 parent a4c0b34 commit ada4809
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 24 deletions.
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@
"sameBedMultiplier": 2,
"sameRoomMultiplier": 1.5,
"cancelRefund": 0.7,
"currentDay": "2024-08-09"
"sameRoommateMultiplier": 3,
"currentDay": "2024-08-10"
},
"ads": {
"enabled": false,
Expand Down
1 change: 1 addition & 0 deletions config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface Config {
sameRoomMultiplier: number
cancelRefund: number
currentDay: string
sameRoommateMultiplier: number
}
ads: {
enabled: boolean
Expand Down
4 changes: 2 additions & 2 deletions pages/ad/myads.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function myAds(userId: number) {
})

return (
<div>
<section className='mx-2'>
{config().ads.enabled ? null : (
<p className="text-red-500">
Reklamy sú vypnuté, zapni ich v konfiguračnom súbore
Expand Down Expand Up @@ -84,7 +84,7 @@ async function myAds(userId: number) {
<a href="new" className="btn">
Nová reklama
</a>
</div>
</section>
)
}

Expand Down
10 changes: 5 additions & 5 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ async function home(req: SessionRequest) {
return (
<div>
<div className="bg-red-500">
<h1>LTT 2024 Ultimate Web</h1>
<h1>Legálne Transakcie Trojstenu</h1>
</div>
<section>
<h2>Moje itemy</h2>
<section className='mx-2'>
<h2>Moje kúpené veci</h2>
<ul>
{myItems.map((item) => (
<li key={item!.id} className='bg-gray-300 rounded-2xl p-2 m-1 flex items-center'>
Expand All @@ -40,6 +40,6 @@ async function home(req: SessionRequest) {
)
}

export function get(req: SessionRequest) {
return renderPage(home(req), req)
export async function get(req: SessionRequest) {
return renderPage(await home(req), req)
}
32 changes: 20 additions & 12 deletions pages/reservations/[bedId]/confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@ import type { User } from '@prisma/client'

async function confirmPage(user: User, bedid: number) {
try {
const cost = await getReservationCost(user, bedid)
const result = await getReservationCost(user, bedid)
return (
<div>
<h1>Rezervovať posteľ #{bedid}</h1>
<p>Naozaj rezervovať túto posteľ?</p>
<form method="post">
<a href="/reservations" className="btn">
Späť
</a>
<button type="submit" className="btn">
Rezervovať ({cost})
</button>
</form>
<div className='flex flex-col justify-center items-center h-screen'>
<h1 className='mb-3'>Rezervovať posteľ #{bedid}</h1>
<div>
<ul className='my-3'>
{result.sameBed ? (<li className='text-red-500'>Príplatok za repetitívne použitie postele</li>) : null}
{result.sameRoom ? (<li className='text-red-500'>Príplatok za repetitívne použitie izby</li>) : null}
{result.sameSex ? (<li className='text-red-500'>Príplatok za zmiešanú izbu</li>) : null}
{result.sameRoommate ? (<li className='text-red-500'>Príplatok za repetitívnu zostavu izby</li>) : null}
</ul>
<p>Naozaj rezervovať túto posteľ?</p>
<form method="post" className='flex w-full justify-between'>
<a href="/reservations" className="btn">
<span>Späť</span>
</a>
<button type="submit" className="btn">
<span>Rezervovať ({result.cost})</span>
</button>
</form>
</div>
</div>
)
} catch (e) {
Expand Down
40 changes: 38 additions & 2 deletions pages/reservations/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,61 @@ export async function getReservationCost(user: User, bedid: number) {
select: {
user: {
select: {
sex: true
sex: true,
id: true
}
},
bedId: true
}
})

const allRoommates = (await db.reservation.findMany({
where: {
date: {
lt: getToday()
},
bed: {
roomId: bed.roomId
},
NOT: {
userId: user.id
}
},
select: {
userId: true
}
})).map(e => e.userId)

console.log(allRoommates)

let hasDifferentSexInRoom = false
let hasSameRoommate = false
for (const roommate of roommates) {
if (roommate.bedId == bedid) {
throw new Error('Bed is already reserved')
}
if (roommate.user.sex != user.sex) {
hasDifferentSexInRoom = true
}
if (allRoommates.includes(roommate.user.id)) {
hasSameRoommate = true
}
}

if (hasDifferentSexInRoom) {
bedCost *= getConfig().reservations.differentSexMultiplier
}

if (hasSameRoommate) {
bedCost *= getConfig().reservations.sameRoommateMultiplier
}

const pastReservations = await getPastReservationsInRoom(bed.roomId)
let wasInThisRoom = false
let wasInThisBed = false

for (const reservation of pastReservations) {
getToday
if (reservation.user.id != user.id) continue
if (reservation.bed.id == bed.id) {
wasInThisBed = true
Expand All @@ -148,7 +178,13 @@ export async function getReservationCost(user: User, bedid: number) {
bedCost *= getConfig().reservations.sameBedMultiplier
}

return bedCost
return {
cost: bedCost,
sameRoom: wasInThisRoom,
sameBed: wasInThisBed,
sameSex: hasDifferentSexInRoom,
sameRoommate: hasSameRoommate
}
}

async function getPastReservationsInRoom(roomid: number) {
Expand Down
4 changes: 2 additions & 2 deletions pages/reservations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function Reservations() {
return (
<div className="container w-full md:w-2/3 m-auto">
<h1>Rezervácie</h1>
<ul className="flex flex-col border-2 border-blue-500 rounded-md p-2">
<ul className="flex flex-col">
{rooms.map((room) => roomHTML(room, currentReservations))}
</ul>
<p className="opacity-70">
Expand All @@ -38,7 +38,7 @@ function roomHTML(room: any, reservations: any[]) {
(e) => e.user.id === request.session!.user.id
)
return (
<li className="m-2">
<li className="m-2 border-2 border-blue-500 rounded-md p-2">
<h2 className="text-xl">{room.name}</h2>
<p>
Počet postelí: <strong>{room.bed_count}</strong>
Expand Down
78 changes: 78 additions & 0 deletions static/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,9 @@
}
}
@layer utilities {
.collapse {
visibility: collapse;
}
.invisible {
visibility: hidden;
}
Expand Down Expand Up @@ -484,6 +487,9 @@
.left-5 {
left: var(--spacing-5, 1.25rem);
}
.z-1 {
z-index: 1;
}
.z-1\.0 {
z-index: 1.0;
}
Expand All @@ -502,6 +508,10 @@
.m-auto {
margin: auto;
}
.mx-2 {
margin-left: var(--spacing-2, 0.5rem);
margin-right: var(--spacing-2, 0.5rem);
}
.my-3 {
margin-top: var(--spacing-3, 0.75rem);
margin-bottom: var(--spacing-3, 0.75rem);
Expand Down Expand Up @@ -558,9 +568,15 @@
.hidden {
display: none;
}
.inline {
display: inline;
}
.inline-block {
display: inline-block;
}
.list-item {
display: list-item;
}
.table {
display: table;
}
Expand Down Expand Up @@ -591,6 +607,9 @@
.min-h-screen {
min-height: 100vh;
}
.w-1 {
width: var(--spacing-1, 0.25rem);
}
.w-1\/2 {
width: calc(1/2 * 100%);
}
Expand Down Expand Up @@ -624,6 +643,9 @@
.grow {
flex-grow: 1;
}
.border-collapse {
border-collapse: collapse;
}
.transform {
transform: var(--tw-rotate-x) var(--tw-rotate-y) var(--tw-rotate-z) var(--tw-skew-x) var(--tw-skew-y);
}
Expand Down Expand Up @@ -848,6 +870,9 @@
.text-white {
color: var(--color-white, #fff);
}
.underline {
text-decoration-line: underline;
}
.opacity-0 {
opacity: 0%;
}
Expand Down Expand Up @@ -875,6 +900,10 @@
--tw-blur: blur(8px);
filter: var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,);
}
.contrast-1 {
--tw-contrast: contrast(1%);
filter: var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,);
}
.contrast-1\.0 {
--tw-contrast: contrast(1.0%);
filter: var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,);
Expand All @@ -886,6 +915,10 @@
.filter {
filter: var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,);
}
.backdrop-filter {
-webkit-backdrop-filter: var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,);
backdrop-filter: var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,);
}
.transition {
transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, translate, scale, rotate, filter, -webkit-backdrop-filter, backdrop-filter;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
Expand Down Expand Up @@ -1061,6 +1094,15 @@ h1 {
--tw-opacity: ;
--tw-saturate: ;
--tw-sepia: ;
--tw-backdrop-blur: ;
--tw-backdrop-brightness: ;
--tw-backdrop-contrast: ;
--tw-backdrop-grayscale: ;
--tw-backdrop-hue-rotate: ;
--tw-backdrop-invert: ;
--tw-backdrop-opacity: ;
--tw-backdrop-saturate: ;
--tw-backdrop-sepia: ;
}
}
}
Expand Down Expand Up @@ -1218,3 +1260,39 @@ h1 {
syntax: "*";
inherits: false;
}
@property --tw-backdrop-blur {
syntax: "*";
inherits: false;
}
@property --tw-backdrop-brightness {
syntax: "*";
inherits: false;
}
@property --tw-backdrop-contrast {
syntax: "*";
inherits: false;
}
@property --tw-backdrop-grayscale {
syntax: "*";
inherits: false;
}
@property --tw-backdrop-hue-rotate {
syntax: "*";
inherits: false;
}
@property --tw-backdrop-invert {
syntax: "*";
inherits: false;
}
@property --tw-backdrop-opacity {
syntax: "*";
inherits: false;
}
@property --tw-backdrop-saturate {
syntax: "*";
inherits: false;
}
@property --tw-backdrop-sepia {
syntax: "*";
inherits: false;
}

0 comments on commit ada4809

Please sign in to comment.