Skip to content
This repository was archived by the owner on Dec 28, 2023. It is now read-only.
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
2 changes: 1 addition & 1 deletion src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<body data-sveltekit-preload-data="hover" data-sveltekit-preload-code="eager">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>
22 changes: 13 additions & 9 deletions src/lib/components/svelte/navbar/BottomNavBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,43 @@

const handleRouteChange = (route: string) => {
currentRoute.set(route);
goto(route);
// goto(route);
};
</script>

<div class="rounded-3xl bg-[#F5222D] fixed bottom-4 w-full max-w-[90%]">
<div class="py-5 flex flex-row gap-4 items-center justify-between px-10 text-white">
<button
<a
href="/home"
on:click={() => {
handleRouteChange('/home');
}}
>
<Home size={28} class={`${$isHomeRoute ? 'text-white' : 'opacity-50'}`} />
</button>
<button
</a>
<a
href="/reservation/survey"
on:click={() => {
handleRouteChange('/reservation/survey');
}}
>
<CalendarClock size={28} class={`${$isReservationRoute ? 'text-white' : 'opacity-40'}`} />
</button>
<button
</a>
<a
href="/history"
on:click={() => {
handleRouteChange('/history');
}}
>
<FileClock size={28} class={`${$isHistoryRoute ? 'text-white' : 'opacity-50'}`} />
</button>
<button
</a>
<a
href="/reward"
on:click={() => {
handleRouteChange('/reward');
}}
>
<Gift size={28} class={`${$isRewardRoute ? 'text-white' : 'opacity-50'}`} />
</button>
</a>
</div>
</div>
11 changes: 11 additions & 0 deletions src/lib/server/routes/donationHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ export const donationHistoryRouter = createRouter({
Reservation: true
}
});

await prisma.donators.update({
where: {
id: reservation.donator_id
},
data: {
reward_point: {
increment: data.rewarded_points
}
}
});
return donationHistory;
}),
getAllDonationHistoryByDonatorId: publicProcedure
Expand Down
12 changes: 12 additions & 0 deletions src/lib/server/routes/donationHistoryRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ export const donationHistoryRouter = createRouter({
Reservation: true
}
});

await prisma.donators.update({
where: {
id: reservation.donator_id
},
data: {
reward_point: {
increment: data.rewarded_points
}
}
});

return donationHistory;
}),
getAllDonationHistoryByDonatorId: publicProcedure
Expand Down
2 changes: 1 addition & 1 deletion src/lib/server/routes/rewardRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const rewardRouter = createRouter({
name: newData.name,
description: newData.description,
required_points: newData.required_points,
amount_left: newData.required_points,
amount_left: newData.amount_left,
image_src: newData.image_src
}
});
Expand Down
5 changes: 5 additions & 0 deletions src/lib/server/routes/specialEventRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export const specialEventRouter = createRouter({
return sp_event;
}),

getEvents: publicProcedure.query(async () => {
const sp_events = await prisma.special_Events.findMany();
return sp_events;
}),

isEvent: publicProcedure.query(async ({ ctx }) => {
const sessionToken = ctx.sessionToken;
const session = await prisma.session.findUnique({
Expand Down
13 changes: 8 additions & 5 deletions src/routes/(donator)/history/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ export const load = (async ({ fetch }) => {
throw redirect(307, '/login');
}

const reservationLog = await trpc.reservationSlot.getLog.query();
const donationHistoryData = await trpc.donationHistory.getDonationHistories.query();
const pendingFeedback = await trpc.postFeedback.checkPendingFeedback.query({
id: userContext.user.id
});
// promise all
const [reservationLog, donationHistoryData, pendingFeedback] = await Promise.all([
trpc.reservationSlot.getLog.query(),
trpc.donationHistory.getDonationHistories.query(),
trpc.postFeedback.checkPendingFeedback.query({
id: userContext.user.id
})
]);

console.log(pendingFeedback);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ export const load = (async ({ params, fetch }) => {

const trpc = trpcOnServer(fetch);

const donationHistory = await trpc.donationHistory.getDonationHistory.query({
id: donationHistoryId
});
// promise all
const [donationHistory, questions] = await Promise.all([
trpc.donationHistory.getDonationHistory.query({
id: donationHistoryId
}),
trpc.postFeedback.getPostFeedbackQuestions.query()
]);

if (!donationHistory) {
throw redirect(307, '/history');
Expand All @@ -21,7 +25,6 @@ export const load = (async ({ params, fetch }) => {
}

const place = donationHistory?.Reservation.Reservation_Slot.Place;
const questions = await trpc.postFeedback.getPostFeedbackQuestions.query();

return {
donationHistoryId: params.donationId,
Expand Down
18 changes: 12 additions & 6 deletions src/routes/(donator)/home/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import type { PageServerLoad } from './$types';

export const load: PageServerLoad = async ({ fetch }) => {
const trpc = trpcOnServer(fetch);
const user = await trpc.auth.getUser.query();

const [user, announcements, sp_events] = await Promise.all([
trpc.auth.getUser.query(),
trpc.announcement.getAnnouncements.query(),
trpc.specialEvent.getEvents.query()
]);

if (user?.type !== 'DONATOR') {
throw redirect(307, '/login');
Expand All @@ -13,14 +18,15 @@ export const load: PageServerLoad = async ({ fetch }) => {
if (user.user?.id === undefined) {
throw redirect(307, '/login');
}

// fetch announcemnet
const announcements = await trpc.announcement.getAnnouncements.query();

// fetch for post feedback status
const pendingFeedback = await trpc.postFeedback.checkPendingFeedback.query({
id: user.user.id
});

return { announcements, user: user.user, pendingFeedback: pendingFeedback ?? undefined };
return {
announcements,
user: user.user,
pendingFeedback: pendingFeedback ?? undefined,
sp_events
};
};
2 changes: 1 addition & 1 deletion src/routes/(donator)/home/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{/if}

<section class="px-8 py-8">
<SpecialEvent />
<SpecialEvent sp_events={data.sp_events} />
</section>
<section class="px-8">
<Searchbar />
Expand Down
43 changes: 15 additions & 28 deletions src/routes/(donator)/home/SpecialEventHero.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,11 @@
import specialEventMockImage from '$lib/images/home/special_event_banner.png';

interface Poster {
img: string;
href: string;
img_src: string | null;
}

const mock_data: Poster[] = [
{
img: '/images/mock_carousel.png',
href: 'www.google.com'
},
{
img: '/images/mock_carousel.png',
href: 'www.google.com'
},
{
img: '/images/mock_carousel.png',
href: 'www.google.com'
}
];

$: selectID = $page.url.hash;
export let sp_events: Poster[] = [];
</script>

<div class="flex flex-row items-center gap-2">
Expand All @@ -34,21 +19,23 @@
<br class="my-10" />
<div>
<div class="carousel w-full gap-x-6">
{#each mock_data as poster, key}
<div id={`slide${key}`} class="carousel-item relative w-full rounded-xl overflow-hidden">
<!-- svelte-ignore a11y-missing-content -->
<a class="absolute inset-0 inline-block" href={poster.href} />
<img
src={specialEventMockImage}
class="w-full h-64"
alt={`${specialEventMockImage} poster image`}
/>
</div>
{#each sp_events as poster, key}
{#if poster.img_src}
<div id={`slide${key}`} class="carousel-item relative w-full rounded-xl overflow-hidden">
<!-- svelte-ignore a11y-missing-content -->
<!-- <a class="absolute inset-0 inline-block" href={poster.href} /> -->
<img
src={specialEventMockImage}
class="w-full h-64"
alt={`${specialEventMockImage} poster image`}
/>
</div>
{/if}
{/each}
</div>
</div>
<div class="flex justify-around w-full gap-2 items-center px-24 mt-6">
{#each mock_data as _, key}
{#each sp_events as _, key}
<a
href={`#slide${key}`}
class={`${selectID === `#slide${key}` ? 'bg-gray-800' : 'bg-gray-200'} w-2 h-2 rounded-full`}
Expand Down
32 changes: 16 additions & 16 deletions src/routes/(donator)/reservation/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import type { PageServerLoad } from './$types';
import type { HospitalWithReviews } from './utils';

export const load = (async () => {
// fetch hospital
const hospital = await prisma.places.findMany({
where: {
deleted_at: null
}
});

const reviews = await prisma.place_Review_History.groupBy({
by: ['place_id'],
_sum: {
rating: true
},
_count: {
id: true
}
});
const [hospital, reviews] = await Promise.all([
prisma.places.findMany({
where: {
deleted_at: null
}
}),
prisma.place_Review_History.groupBy({
by: ['place_id'],
_sum: {
rating: true
},
_count: {
id: true
}
})
]);

const hospitalWithReviews: HospitalWithReviews[] = hospital.map((hospital) => {
const review = reviews.find((review) => review.place_id === hospital.id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { mock_hospitalData } from '../utils';
import { get24HoursTimeString } from '../date/utils';
import { trpcOnServer } from '$lib/trpc';
import reservationController from '$lib/server/database/controllers/reservationController';
Expand All @@ -21,14 +20,11 @@ export const load = (async ({ url, params, fetch }) => {

const selectedDate = new Date(+date);

// check for valid available dates
const hospital = await trpcServer.places.findById.query({ placeId: placeId });
if (!hospital) {
throw redirect(307, `/reservation`);
}

// get available dates
const availableDates = await reservationController.getAvailbleTimeSlots(placeId, selectedDate);
// promise all
const [hospital, availableDates] = await Promise.all([
trpcServer.places.findById.query({ placeId: placeId }),
reservationController.getAvailbleTimeSlots(placeId, selectedDate)
]);

const filteredByDate = availableDates.find((d) => {
// check date only
Expand Down
Loading