Skip to content

Commit

Permalink
Added rental website
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditijainnn committed Aug 1, 2024
1 parent c134b92 commit 5167309
Show file tree
Hide file tree
Showing 84 changed files with 3,727 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Typescript-Projects/Advanced/Rental-Website/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["next/core-web-vitals"]
}
64 changes: 64 additions & 0 deletions Typescript-Projects/Advanced/Rental-Website/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<h1 align='center'><b>💥 Rental Website 💥</b></h1>

<!-- -------------------------------------------------------------------------------------------------------------- -->

<h3 align='center'>Tech Stack Used 🎮</h3>

<div align='center'>
<img alt="TypeScript" src="https://img.shields.io/badge/typescipt-darkblue?style=for-the-badge&logo=typescript&logoColor=white">
</div>


![Line](https://github.com/Avdhesh-Varshney/WebMasterLog/assets/114330097/4b78510f-a941-45f8-a9d5-80ed0705e847)

<!-- -------------------------------------------------------------------------------------------------------------- -->

## :zap: Description 📃

<div align='center'>
<p>A property rental website where you can list your property or rent other properties with ease. </p>
</div>

<!-- -------------------------------------------------------------------------------------------------------------- -->

## :zap: How to run it? 🕹️

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

<!-- -------------------------------------------------------------------------------------------------------------- -->

## :zap: Screenshots 📸
<!-- add the screenshot of the project (Mandatory) -->

<img src='./Countdown-Timer.webp'>


![Line](https://github.com/Avdhesh-Varshney/WebMasterLog/assets/114330097/4b78510f-a941-45f8-a9d5-80ed0705e847)

<!-- -------------------------------------------------------------------------------------------------------------- -->

<h4 align='center'>Developed By <b><i>Vishal Malyan</i></b></h4>
<p align='center'>
<a href='https://github.com/Aditijainnn'>
<img src='https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white' />
</a>
</p>

<h4 align='center'>Happy Coding 🧑‍💻</h4>

<h3 align="center">Show some &nbsp;❤️&nbsp; by &nbsp;🌟&nbsp; this repository!</h3>

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { getServerSession } from "next-auth/next";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import prisma from "@/app/libs/prismadb";

export async function getSession() {
return await getServerSession(authOptions);
}

export default async function getCurrentUser() {
try {
const session = await getSession();

if (!session?.user?.email) {
return null;
}

const currentUser = await prisma.user.findUnique({
where: {
email: session.user.email as string,
},
});

if (!currentUser) {
return null;
}

return {
...currentUser,
createdAt: currentUser.createdAt.toISOString(),
updatedAt: currentUser.updatedAt.toISOString(),
emailVerified: currentUser.emailVerified?.toISOString() || null,
};
} catch (error: any) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import prisma from "@/app/libs/prismadb";

import getCurrentUser from "./getCurrentUser";

export default async function getFavoriteListings() {
try {
const currentUser = await getCurrentUser();

if (!currentUser) {
return [];
}

const favorites = await prisma.listing.findMany({
where: {
id: {
in: [...(currentUser.favoriteIds || [])],
},
},
});

const safeFavorites = favorites.map((favorite) => ({
...favorite,
createAt: favorite.createAt.toISOString(),
}));

return safeFavorites;
} catch (error: any) {
throw new Error(error);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import prisma from "@/app/libs/prismadb";

interface IParams {
listingId?: string;
}

export default async function getListingById(params: IParams) {
try {
const { listingId } = params;
const listing = await prisma?.listing.findUnique({
where: {
id: listingId,
},
include: {
user: true,
},
});

if (!listing) {
return null;
}

return {
...listing,
createAt: listing.createAt.toString(),
user: {
...listing.user,
createdAt: listing.user.createdAt.toString(),
updatedAt: listing.user.updatedAt.toString(),
emailVerified: listing.user.emailVerified?.toString() || null,
},
};
} catch (error: any) {
throw new Error(error);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import prisma from "@/app/libs/prismadb";

export interface IListingsParams {
userId?: string;
guestCount?: number;
roomCount?: number;
bathroomCount?: number;
startDate?: string;
endDate?: string;
locationValue?: string;
category?: string;
}

export default async function getListings(params: IListingsParams) {
try {
const {
userId,
guestCount,
roomCount,
bathroomCount,
startDate,
endDate,
locationValue,
category,
} = params;
let query: any = {};

if (userId) {
query.userId = userId;
}

if (category) {
query.category = category;
}

if (locationValue) {
query.locationValue = locationValue;
}

if (roomCount) {
query.roomCount = {
gte: +roomCount,
};
}

if (bathroomCount) {
query.bathroomCount = {
gte: +bathroomCount,
};
}

if (guestCount) {
query.guestCount = {
gte: +guestCount,
};
}

if (startDate && endDate) {
query.NOT = {
reservations: {
some: {
OR: [
{
endDate: { gte: startDate },
startDate: { lte: startDate },
},
{
startDate: { lte: endDate },
endDate: { gte: endDate },
},
],
},
},
};
}

const listings = await prisma.listing.findMany({
where: query,
orderBy: {
createAt: "desc",
},
});

const safeListings = listings.map((listing) => ({
...listing,
createAt: listing.createAt.toISOString(),
}));

return safeListings;
} catch (error: any) {
throw new Error(error);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import prisma from "@/app/libs/prismadb";

interface IParams {
listingId?: string;
userId?: string;
authorId?: string;
}

export default async function getReservations(params: IParams) {
try {
const { listingId, userId, authorId } = params;

const query: any = {};

if (listingId) {
query.listingId = listingId;
}

if (userId) {
query.userId = userId;
}

if (authorId) {
query.listing = { userId: authorId };
}

const reservations = await prisma.reservation.findMany({
where: query,
include: {
listing: true,
},
orderBy: {
createdAt: "desc",
},
});

const safeReservations = reservations.map((reservation) => ({
...reservation,
createdAt: reservation.createdAt.toISOString(),
startDate: reservation.startDate.toISOString(),
endDate: reservation.endDate.toISOString(),

listing: {
...reservation.listing,
createAt: reservation.listing.createAt.toISOString(),
},
}));

return safeReservations;
} catch (error: any) {
throw new Error(error);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { NextResponse } from "next/server";

import getCurrentUser from "@/app/actions/getCurrentUser";
import prisma from "@/app/libs/prismadb";

interface IParams {
listingId?: string;
}

export async function POST(request: Request, { params }: { params: IParams }) {
const currentUser = await getCurrentUser();

if (!currentUser) {
return NextResponse.error();
}

const { listingId } = params;

if (!listingId || typeof listingId !== "string") {
throw new Error("Invalid ID");
}

let favoriteIds = [...(currentUser.favoriteIds || [])];

favoriteIds.push(listingId);

const user = await prisma.user.update({
where: {
id: currentUser.id,
},
data: {
favoriteIds,
},
});

return NextResponse.json(user);
}

export async function DELETE(request: Request, { params }: { params: IParams }) {
const currentUser = await getCurrentUser();

if (!currentUser) {
return NextResponse.error();
}

const { listingId } = params;

if (!listingId || typeof listingId !== "string") {
throw new Error("Invalid ID");
}

let favoriteIds = [...(currentUser.favoriteIds || [])];

favoriteIds = favoriteIds.filter((id) => id != listingId);

const user = await prisma.user.update({
where: {
id: currentUser.id,
},
data: {
favoriteIds,
},
});

return NextResponse.json(user);
}
Loading

0 comments on commit 5167309

Please sign in to comment.