Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ [email protected]
FIREBASE_PROJECT_ID=*
FIREBASE_PRIVATE_KEY=*
FIREBASE_CLIENT_EMAIL=*
PUBLIC_FIXED_PRICE=300

PUBLIC_FIXED_PRICE=500
PUBLIC_FIXED_REDUCED_PRICE=300
SECRET_KEY=*
2 changes: 2 additions & 0 deletions src/lib/i18n/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ const translations: Translations = {
kidsZeroToTwo: '0 - 2 Jahre',
kidsThreeToFour: '3 - 4 Jahre',
kidsFiveToSix: '5 - 6 Jahre',
kidsSevenToFourteen: '7 - 14 Jahre',
foldableWheelchair: 'Faltbarer Rollstuhl',
withFoldableWheelchair: 'Mit faltbarem Rollstuhl',
passengerNumber: 'Anzahl Personen',
Expand All @@ -259,6 +260,7 @@ const translations: Translations = {
},
totalPrice: 'Gesamtpreis',
cashOnly: 'Nur Barzahlung im Taxi',
ptTicketNeeded: 'Zusätzlich ist ein entsprechendes ÖPNV-Ticket erforderlich.',
cancel: 'Stornieren',
loginToBook: 'Einloggen zum Buchen',
connection: 'Verbindung',
Expand Down
2 changes: 2 additions & 0 deletions src/lib/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ const translations: Translations = {
kidsZeroToTwo: '0 - 2 years',
kidsThreeToFour: '3 - 4 years',
kidsFiveToSix: '5 - 6 years',
kidsSevenToFourteen: '7 - 14 years',
foldableWheelchair: 'Foldable wheelchair',
withFoldableWheelchair: 'With foldable wheelchair',
passengerNumber: 'Number of people',
Expand All @@ -252,6 +253,7 @@ const translations: Translations = {
},
totalPrice: 'Total price',
cashOnly: 'Cash payment only',
ptTicketNeeded: 'In addition, a valid public transport ticket is required.',
cancel: 'Cancel',
loginToBook: 'Login to book',
connection: 'Connection',
Expand Down
2 changes: 2 additions & 0 deletions src/lib/i18n/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,10 @@ export type Translations = {
kidsZeroToTwo: string;
kidsThreeToFour: string;
kidsFiveToSix: string;
kidsSevenToFourteen: string;
totalPrice: string;
cashOnly: string;
ptTicketNeeded: string;
foldableWheelchair: string;
withFoldableWheelchair: string;
passengerNumber: string;
Expand Down
4 changes: 4 additions & 0 deletions src/lib/server/booking/bookingApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export async function bookingApi(
kidsZeroToTwo: number,
kidsThreeToFour: number,
kidsFiveToSix: number,
kidsSevenToFourteen: number,
skipPromiseCheck?: boolean
): Promise<{
message?: string;
Expand All @@ -88,6 +89,7 @@ export async function bookingApi(
JSON.stringify(kidsZeroToTwo, null, 2),
JSON.stringify(kidsThreeToFour, null, 2),
JSON.stringify(kidsFiveToSix, null, 2),
JSON.stringify(kidsSevenToFourteen, null, 2),
JSON.stringify(skipPromiseCheck, null, 2)
);
if (p.connection1 == null && p.connection2 == null) {
Expand Down Expand Up @@ -200,6 +202,7 @@ export async function bookingApi(
kidsZeroToTwo,
kidsThreeToFour,
kidsFiveToSix,
kidsSevenToFourteen,
trx
)) ?? null;
}
Expand All @@ -213,6 +216,7 @@ export async function bookingApi(
kidsZeroToTwo,
kidsThreeToFour,
kidsFiveToSix,
kidsSevenToFourteen,
trx
)) ?? null;
}
Expand Down
11 changes: 7 additions & 4 deletions src/lib/server/booking/insertRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type Database } from '$lib/server/db';
import { sql, Transaction } from 'kysely';
import { sendNotifications } from '$lib/server/firebase/notifications';
import { TourChange } from '$lib/server/firebase/firebase';
import { env } from '$env/dynamic/public';
import { legOdmPrice } from '$lib/util/odmPrice';

export async function insertRequest(
r: BookRideResponse,
Expand All @@ -14,6 +14,7 @@ export async function insertRequest(
kidsZeroToTwo: number,
kidsThreeToFour: number,
kidsFiveToSix: number,
kidsSevenToFourteen: number,
trx: Transaction<Database>
): Promise<number> {
r.mergeTourList = r.mergeTourList.filter((id) => id != r.best.tour);
Expand All @@ -24,9 +25,11 @@ export async function insertRequest(
sql`,`
)}]::INTEGER[]`
: sql`ARRAY[]::INTEGER[]`;
const ticketPrice =
(capacities.passengers - kidsZeroToTwo - kidsThreeToFour - kidsFiveToSix) *
parseInt(env.PUBLIC_FIXED_PRICE);
const ticketPrice = legOdmPrice(
capacities.passengers,
kidsZeroToTwo + kidsThreeToFour + kidsFiveToSix,
kidsSevenToFourteen
);
const requestId = (
await sql<{ request: number }>`
SELECT create_and_merge_tours(
Expand Down
4 changes: 2 additions & 2 deletions src/lib/server/booking/tests/concatenations/append.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Concatenation tests', () => {
capacities
};

await bookingApi(bookingBody, mockUserId, true, 0, 0, 0, true);
await bookingApi(bookingBody, mockUserId, true, 0, 0, 0, 0, true);
const tours = await getTours();
expect(tours.length).toBe(1);
expect(tours[0].requests.length).toBe(1);
Expand Down Expand Up @@ -76,7 +76,7 @@ describe('Concatenation tests', () => {
connection2: null,
capacities
};
await bookingApi(bookingBodyAppend, mockUserId, true, 0, 0, 0, true);
await bookingApi(bookingBodyAppend, mockUserId, true, 0, 0, 0, 0, true);
const tours2 = await getTours();
expect(tours2.length).toBe(1);
expect(tours2[0].requests.length).toBe(2);
Expand Down
6 changes: 3 additions & 3 deletions src/lib/server/booking/tests/concatenations/connect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('Concatenation tests', () => {
capacities
};

await bookingApi(bookingBody, mockUserId, true, 0, 0, 0, false);
await bookingApi(bookingBody, mockUserId, true, 0, 0, 0, 0, false);
const tours = await getTours();
expect(tours.length).toBe(1);
expect(tours[0].requests.length).toBe(1);
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('Concatenation tests', () => {
connection2: null,
capacities
};
await bookingApi(bookingBody2, mockUserId, true, 0, 0, 0, false);
await bookingApi(bookingBody2, mockUserId, true, 0, 0, 0, 0, false);
const tours2 = await getTours();
expect(tours2.length).toBe(2);
expect(tours2[0].requests.length).toBe(1);
Expand Down Expand Up @@ -132,7 +132,7 @@ describe('Concatenation tests', () => {
connection2: null,
capacities
};
await bookingApi(bookingBodyConnect, mockUserId, true, 0, 0, 0, false);
await bookingApi(bookingBodyConnect, mockUserId, true, 0, 0, 0, 0, false);
const tours3 = await getTours();
expect(tours3.length).toBe(1);
expect(tours3[0].requests.length).toBe(3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('Concatenation tests', () => {
capacities
};

await bookingApi(bookingBody, mockUserId, true, 0, 0, 0, true);
await bookingApi(bookingBody, mockUserId, true, 0, 0, 0, 0, true);
const tours = await getTours();
expect(tours.length).toBe(1);
expect(tours[0].requests.length).toBe(1);
Expand Down Expand Up @@ -78,7 +78,7 @@ describe('Concatenation tests', () => {
connection2: null,
capacities
};
await bookingApi(bookingBodyAppend, mockUserId, true, 0, 0, 0, true);
await bookingApi(bookingBodyAppend, mockUserId, true, 0, 0, 0, 0, true);
const tours2 = await getTours();
expect(tours2.length).toBe(1);
expect(tours2[0].requests.length).toBe(2);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/server/booking/tests/concatenations/prepend1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Concatenation tests', () => {
capacities
};

await bookingApi(bookingBody, mockUserId, true, 0, 0, 0, true);
await bookingApi(bookingBody, mockUserId, true, 0, 0, 0, 0, true);
const tours = await getTours();
expect(tours.length).toBe(1);
expect(tours[0].requests.length).toBe(1);
Expand Down Expand Up @@ -76,7 +76,7 @@ describe('Concatenation tests', () => {
connection2: null,
capacities
};
await bookingApi(bookingBodyAppend, mockUserId, true, 0, 0, 0, true);
await bookingApi(bookingBodyAppend, mockUserId, true, 0, 0, 0, 0, true);
const tours2 = await getTours();
expect(tours2.length).toBe(1);
expect(tours2[0].requests.length).toBe(2);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/server/booking/tests/concatenations/prepend2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Concatenation tests', () => {
capacities
};

await bookingApi(bookingBody, mockUserId, true, 0, 0, 0, true);
await bookingApi(bookingBody, mockUserId, true, 0, 0, 0, 0, true);
const tours = await getTours();
expect(tours.length).toBe(1);
expect(tours[0].requests.length).toBe(1);
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('Concatenation tests', () => {
connection2: null,
capacities
};
await bookingApi(bookingBodyAppend, mockUserId, true, 0, 0, 0, true);
await bookingApi(bookingBodyAppend, mockUserId, true, 0, 0, 0, 0, true);
const tours2 = await getTours();
expect(tours2.length).toBe(1);
expect(tours2[0].requests.length).toBe(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('Concatenation tests', () => {
capacities
};

await bookingApi(bookingBody, mockUserId, true, 0, 0, 0, true);
await bookingApi(bookingBody, mockUserId, true, 0, 0, 0, 0, true);
const tours = await getTours();
expect(tours.length).toBe(1);
expect(tours[0].requests.length).toBe(1);
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('Concatenation tests', () => {
connection2: null,
capacities
};
await bookingApi(bookingBodyAppend, mockUserId, true, 0, 0, 0, true);
await bookingApi(bookingBodyAppend, mockUserId, true, 0, 0, 0, 0, true);
const tours2 = await getTours();
expect(tours2.length).toBe(1);
expect(tours2[0].requests.length).toBe(2);
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('Concatenation tests', () => {
connection2: null,
capacities
};
await bookingApi(bookingBodyAppend2, mockUserId, true, 0, 0, 0, true);
await bookingApi(bookingBodyAppend2, mockUserId, true, 0, 0, 0, 0, true);
const tours3 = await getTours();
expect(tours3.length).toBe(1);
expect(tours3[0].requests.length).toBe(3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('Concatenation tests', () => {
connection2: null,
capacities
};
await bookingApi(bookingBody, mockUserId, true, 0, 0, 0, true);
await bookingApi(bookingBody, mockUserId, true, 0, 0, 0, 0, true);
const tours = await getTours();
expect(tours.length).toBe(1);
expect(tours[0].requests.length).toBe(1);
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('Concatenation tests', () => {
connection2: null,
capacities
};
await bookingApi(bookingBodyAppend, mockUserId, true, 0, 0, 0, true);
await bookingApi(bookingBodyAppend, mockUserId, true, 0, 0, 0, 0, true);
const tours2 = await getTours();
expect(tours2.length).toBe(1);
expect(tours2[0].requests.length).toBe(2);
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('Concatenation tests', () => {
connection2: null,
capacities
};
await bookingApi(bookingBodyAppend2, mockUserId, true, 0, 0, 0, true);
await bookingApi(bookingBodyAppend2, mockUserId, true, 0, 0, 0, 0, true);
const tours3 = await getTours();
expect(tours3.length).toBe(1);
expect(tours3[0].requests.length).toBe(3);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/server/booking/tests/generatedTests/gen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('Concatenation tests', () => {
connection2: null,
capacities: { passengers: 1, luggage: 0, wheelchairs: 0, bikes: 0 }
};
await bookingApi(bookingBody, mockUserId, true, 0, 0, 0, true);
await bookingApi(bookingBody, mockUserId, true, 0, 0, 0, 0, true);
const tours = await getTours();
for (const condition of test.conditions.filter((c) => c.evalAfterStep === requestIdx)) {
try {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/server/booking/tests/singleRequest/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ describe('Whitelist and Booking API Tests', () => {
capacities
};

const bookingResponse = await bookingApi(bookingBody, mockUserId, false, 0, 0, 0);
const bookingResponse = await bookingApi(bookingBody, mockUserId, false, 0, 0, 0, 0);
const tours = await getTours();
expect(tours.length).toBe(1);
expect(tours[0].requests.length).toBe(1);
Expand Down Expand Up @@ -358,7 +358,7 @@ describe('Whitelist and Booking API Tests', () => {
capacities
};

await bookingApi(bookingBody, mockUserId, false, 0, 0, 0);
await bookingApi(bookingBody, mockUserId, false, 0, 0, 0, 0);
const tours = await getTours();
expect(tours.length).toBe(1);
}, 30000);
Expand Down Expand Up @@ -405,7 +405,7 @@ describe('Whitelist and Booking API Tests', () => {
connection2: null,
capacities
};
const response = await bookingApi(bookingBody, mockUserId, false, 0, 0, 0);
const response = await bookingApi(bookingBody, mockUserId, false, 0, 0, 0, 0);
const tours = await getTours();
expect(response.status === 403);
expect(tours.length).toBe(0);
Expand Down
2 changes: 2 additions & 0 deletions src/lib/ui/BookingSummary.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<span class="font-bold">{getEuroString(price)}</span>
</li>

<li>{t.booking.ptTicketNeeded}</li>

<li>{t.booking.bookingFor(passengers)}</li>

{#if wheelchair}
Expand Down
20 changes: 18 additions & 2 deletions src/lib/util/odmPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,26 @@ import { env } from '$env/dynamic/public';

import type { Itinerary, Leg } from '$lib/openapi';

export const odmPrice = (it: Itinerary, passengers: number, kids: number) =>
export const legOdmPrice = (
totalPassengers: number,
freePassengers: number,
reducedPassengers: number
) =>
Math.abs(
(totalPassengers - freePassengers - reducedPassengers) * parseInt(env.PUBLIC_FIXED_PRICE) +
reducedPassengers * parseInt(env.PUBLIC_FIXED_REDUCED_PRICE)
);

export const odmPrice = (
it: Itinerary,
totalPassengers: number,
freePassengers: number,
reducedPassengers: number
) =>
it.legs.reduce(
(acc: number, l: Leg) =>
acc + (l.mode === 'ODM' ? (passengers - kids) * parseInt(env.PUBLIC_FIXED_PRICE) : 0),
acc +
(l.mode === 'ODM' ? legOdmPrice(totalPassengers, freePassengers, reducedPassengers) : 0),
0
);

Expand Down
Loading