feat(web): complete portfolio public filter and sort integration
This commit is contained in:
@@ -9,15 +9,18 @@ import {
|
||||
updateGroupingInputSchema,
|
||||
updateMediaAssetInputSchema,
|
||||
} from "@cms/content"
|
||||
import type { Prisma } from "@prisma/client"
|
||||
|
||||
import { db } from "./client"
|
||||
|
||||
type PublicArtworkGroupType = "gallery" | "album" | "category" | "tag"
|
||||
type PublicArtworkSort = "latest" | "title_asc" | "title_desc"
|
||||
|
||||
type ListPublishedArtworksInput = {
|
||||
groupType?: PublicArtworkGroupType
|
||||
groupSlug?: string
|
||||
limit?: number
|
||||
sort?: PublicArtworkSort
|
||||
}
|
||||
|
||||
export async function listMediaAssets(limit = 24) {
|
||||
@@ -431,6 +434,12 @@ export async function listPublishedArtworks(input: ListPublishedArtworksInput =
|
||||
const where: Record<string, unknown> = {
|
||||
isPublished: true,
|
||||
}
|
||||
const orderBy: Prisma.ArtworkOrderByWithRelationInput[] =
|
||||
input.sort === "title_asc"
|
||||
? [{ title: "asc" }, { updatedAt: "desc" }]
|
||||
: input.sort === "title_desc"
|
||||
? [{ title: "desc" }, { updatedAt: "desc" }]
|
||||
: [{ updatedAt: "desc" }]
|
||||
|
||||
if (input.groupType && input.groupSlug) {
|
||||
if (input.groupType === "gallery") {
|
||||
@@ -474,7 +483,7 @@ export async function listPublishedArtworks(input: ListPublishedArtworksInput =
|
||||
|
||||
return db.artwork.findMany({
|
||||
where,
|
||||
orderBy: [{ updatedAt: "desc" }],
|
||||
orderBy,
|
||||
take,
|
||||
include: {
|
||||
renditions: {
|
||||
|
||||
Reference in New Issue
Block a user