Skip to content

Commit

Permalink
Refactor getFavoriteListings to use Prisma model and add type annotat…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
GithmiHashara committed Sep 13, 2024
1 parent 4a959a3 commit 3b734d8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/actions/getFavoriteListings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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 {
Expand All @@ -10,15 +10,15 @@ export default async function getFavoriteListings() {
return []
}

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

const safeFavorites = favorites.map((favorite) => ({
const safeFavorites = favorites.map((favorite: Listing) => ({
...favorite,
createdAt: favorite.createdAt.toISOString()
}))
Expand Down

0 comments on commit 3b734d8

Please sign in to comment.