diff --git a/app/actions/getFavoriteListings.ts b/app/actions/getFavoriteListings.ts index b0e2eaa..8a0c50c 100644 --- a/app/actions/getFavoriteListings.ts +++ b/app/actions/getFavoriteListings.ts @@ -1,6 +1,72 @@ +// 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, +// createdAt: favorite.createdAt.toISOString() +// })) + +// return safeFavorites +// } catch (error: any) { +// throw new Error(error) +// } +// } + + +//2nd one + +// import prisma from '@/app/libs/prismadb' +// import getCurrentUser from './getCurrentUser' +// import { Listing } from '@prisma/client' // Assuming your Prisma model is named Listing + +// export default async function getFavoriteListings() { +// try { +// const currentUser = await getCurrentUser() + +// if (!currentUser) { +// return [] +// } + +// const favorites: Listing[] = await prisma.listing.findMany({ +// where: { +// id: { +// in: [...(currentUser.favoriteIds || [])] +// } +// } +// }) + +// const safeFavorites = favorites.map((favorite: Listing) => ({ +// ...favorite, +// createdAt: favorite.createdAt.toISOString() +// })) + +// return safeFavorites +// } catch (error: any) { +// throw new Error(error) +// } +// } + +// app/actions/getFavoriteListings.ts import prisma from '@/app/libs/prismadb' import getCurrentUser from './getCurrentUser' -import { Listing } from '@prisma/client' // Assuming your Prisma model is named Listing +import { Prisma } from '@prisma/client' export default async function getFavoriteListings() { try { @@ -10,7 +76,7 @@ export default async function getFavoriteListings() { return [] } - const favorites: Listing[] = await prisma.listing.findMany({ + const favorites: Prisma.ListingGetPayload<{}>[] = await prisma.listing.findMany({ where: { id: { in: [...(currentUser.favoriteIds || [])] @@ -18,7 +84,7 @@ export default async function getFavoriteListings() { } }) - const safeFavorites = favorites.map((favorite: Listing) => ({ + const safeFavorites = favorites.map((favorite) => ({ ...favorite, createdAt: favorite.createdAt.toISOString() })) @@ -28,3 +94,4 @@ export default async function getFavoriteListings() { throw new Error(error) } } +