feat(portfolio): add grouping visibility and ordering controls
This commit is contained in:
@@ -75,6 +75,21 @@ export const createGroupingInputSchema = z.object({
|
||||
isVisible: z.boolean().default(true),
|
||||
})
|
||||
|
||||
export const updateGroupingInputSchema = z.object({
|
||||
groupType: z.enum(["gallery", "album", "category", "tag"]),
|
||||
groupId: z.string().uuid(),
|
||||
name: z.string().min(1).max(180),
|
||||
slug: z.string().min(1).max(180),
|
||||
description: z.string().max(5000).nullable().optional(),
|
||||
sortOrder: z.number().int().min(0),
|
||||
isVisible: z.boolean(),
|
||||
})
|
||||
|
||||
export const deleteGroupingInputSchema = z.object({
|
||||
groupType: z.enum(["gallery", "album", "category", "tag"]),
|
||||
groupId: z.string().uuid(),
|
||||
})
|
||||
|
||||
export const linkArtworkGroupingInputSchema = z.object({
|
||||
artworkId: z.string().uuid(),
|
||||
groupType: z.enum(["gallery", "album", "category", "tag"]),
|
||||
@@ -96,5 +111,7 @@ export type CreateMediaAssetInput = z.infer<typeof createMediaAssetInputSchema>
|
||||
export type UpdateMediaAssetInput = z.infer<typeof updateMediaAssetInputSchema>
|
||||
export type CreateArtworkInput = z.infer<typeof createArtworkInputSchema>
|
||||
export type CreateGroupingInput = z.infer<typeof createGroupingInputSchema>
|
||||
export type UpdateGroupingInput = z.infer<typeof updateGroupingInputSchema>
|
||||
export type DeleteGroupingInput = z.infer<typeof deleteGroupingInputSchema>
|
||||
export type LinkArtworkGroupingInput = z.infer<typeof linkArtworkGroupingInputSchema>
|
||||
export type AttachArtworkRenditionInput = z.infer<typeof attachArtworkRenditionInputSchema>
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
ALTER TABLE "Tag"
|
||||
ADD COLUMN "description" TEXT,
|
||||
ADD COLUMN "sortOrder" INTEGER NOT NULL DEFAULT 0,
|
||||
ADD COLUMN "isVisible" BOOLEAN NOT NULL DEFAULT true;
|
||||
@@ -222,6 +222,9 @@ model Tag {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
slug String @unique
|
||||
description String?
|
||||
sortOrder Int @default(0)
|
||||
isVisible Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
artworkLinks ArtworkTag[]
|
||||
|
||||
@@ -24,6 +24,7 @@ export {
|
||||
createGallery,
|
||||
createMediaAsset,
|
||||
createTag,
|
||||
deleteGrouping,
|
||||
deleteMediaAsset,
|
||||
getMediaAssetById,
|
||||
getMediaFoundationSummary,
|
||||
@@ -34,6 +35,7 @@ export {
|
||||
listMediaFoundationGroups,
|
||||
listPublishedArtworks,
|
||||
listPublishedPortfolioGroups,
|
||||
updateGrouping,
|
||||
updateMediaAsset,
|
||||
} from "./media-foundation"
|
||||
export type { PublicNavigationItem } from "./pages-navigation"
|
||||
|
||||
@@ -3,7 +3,9 @@ import {
|
||||
createArtworkInputSchema,
|
||||
createGroupingInputSchema,
|
||||
createMediaAssetInputSchema,
|
||||
deleteGroupingInputSchema,
|
||||
linkArtworkGroupingInputSchema,
|
||||
updateGroupingInputSchema,
|
||||
updateMediaAssetInputSchema,
|
||||
} from "@cms/content"
|
||||
|
||||
@@ -96,7 +98,7 @@ export async function listMediaFoundationGroups() {
|
||||
orderBy: [{ sortOrder: "asc" }, { name: "asc" }],
|
||||
}),
|
||||
db.tag.findMany({
|
||||
orderBy: { name: "asc" },
|
||||
orderBy: [{ sortOrder: "asc" }, { name: "asc" }],
|
||||
}),
|
||||
])
|
||||
|
||||
@@ -171,18 +173,76 @@ export async function createCategory(input: unknown) {
|
||||
}
|
||||
|
||||
export async function createTag(input: unknown) {
|
||||
const payload = createGroupingInputSchema
|
||||
.pick({
|
||||
name: true,
|
||||
slug: true,
|
||||
})
|
||||
.parse(input)
|
||||
const payload = createGroupingInputSchema.parse(input)
|
||||
|
||||
return db.tag.create({
|
||||
data: payload,
|
||||
})
|
||||
}
|
||||
|
||||
export async function updateGrouping(input: unknown) {
|
||||
const payload = updateGroupingInputSchema.parse(input)
|
||||
const data = {
|
||||
name: payload.name,
|
||||
slug: payload.slug,
|
||||
description: payload.description ?? null,
|
||||
sortOrder: payload.sortOrder,
|
||||
isVisible: payload.isVisible,
|
||||
}
|
||||
|
||||
if (payload.groupType === "gallery") {
|
||||
return db.gallery.update({
|
||||
where: { id: payload.groupId },
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
||||
if (payload.groupType === "album") {
|
||||
return db.album.update({
|
||||
where: { id: payload.groupId },
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
||||
if (payload.groupType === "category") {
|
||||
return db.category.update({
|
||||
where: { id: payload.groupId },
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
||||
return db.tag.update({
|
||||
where: { id: payload.groupId },
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
||||
export async function deleteGrouping(input: unknown) {
|
||||
const payload = deleteGroupingInputSchema.parse(input)
|
||||
|
||||
if (payload.groupType === "gallery") {
|
||||
return db.gallery.delete({
|
||||
where: { id: payload.groupId },
|
||||
})
|
||||
}
|
||||
|
||||
if (payload.groupType === "album") {
|
||||
return db.album.delete({
|
||||
where: { id: payload.groupId },
|
||||
})
|
||||
}
|
||||
|
||||
if (payload.groupType === "category") {
|
||||
return db.category.delete({
|
||||
where: { id: payload.groupId },
|
||||
})
|
||||
}
|
||||
|
||||
return db.tag.delete({
|
||||
where: { id: payload.groupId },
|
||||
})
|
||||
}
|
||||
|
||||
export async function linkArtworkToGrouping(input: unknown) {
|
||||
const payload = linkArtworkGroupingInputSchema.parse(input)
|
||||
|
||||
@@ -325,7 +385,10 @@ export async function listPublishedPortfolioGroups() {
|
||||
},
|
||||
}),
|
||||
db.tag.findMany({
|
||||
orderBy: [{ name: "asc" }],
|
||||
where: {
|
||||
isVisible: true,
|
||||
},
|
||||
orderBy: [{ sortOrder: "asc" }, { name: "asc" }],
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
@@ -381,6 +444,7 @@ export async function listPublishedArtworks(input: ListPublishedArtworksInput =
|
||||
some: {
|
||||
tag: {
|
||||
slug: input.groupSlug,
|
||||
isVisible: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user