feat: citizenship applications

This commit is contained in:
Ivan Rezchikov
2026-06-23 19:03:10 +03:00
parent 58ec75c948
commit c60ab9e8f9
44 changed files with 1254 additions and 130 deletions
+11 -7
View File
@@ -1,18 +1,19 @@
import { getCurrentUser } from "../user";
import { Block, PageMeta, PageStatus, PageType } from "./types";
import type { Block, Page, PageMeta, PageStatus, PageType } from "./types";
import { prisma } from "../prisma";
export async function getPages(type: PageType, status: PageStatus, limit?: number) {
// return await prisma.page.findMany({ where: { type, status }, take: limit, orderBy: { publishedAt: "desc" }, });
return []
return await prisma.page.findMany({ where: { type, status }, take: limit, orderBy: { publishedAt: "desc" }, }) as Page[];
}
export async function getPageById(id: string) {
return await prisma.page.findUnique({ where: { id: id } });
}
export async function getPageBySlug(slug: string) {
return await prisma.page.findUnique({ where: { slug } });
export async function getPageBySlug(slug: string, type?: PageType) {
return await prisma.page.findFirst({
where: { slug, ...(type ? { type } : {}) },
}) as Page | null;
}
export async function createPage(slug: string, title: string, type: PageType, status: PageStatus, blocks: Block[], meta?: PageMeta) {
@@ -68,6 +69,9 @@ export async function updatePage(
const user = await getCurrentUser();
if (!user?.isAdmin) throw new Error("Access denied");
const currentPage = await prisma.page.findUnique({ where: { id }, select: { status: true } });
const isNewlyPublished = status === "PUBLISHED" && currentPage?.status !== "PUBLISHED";
const page = await prisma.page.update({
where: { id },
data: {
@@ -75,7 +79,7 @@ export async function updatePage(
type,
status,
meta: meta ?? {},
publishedAt: status === "PUBLISHED" ? new Date() : undefined,
publishedAt: isNewlyPublished ? new Date() : undefined,
updatedAt: new Date(),
updatedBy: user.id
},
@@ -115,5 +119,5 @@ export async function getBlocksByPageId(pageId: string) {
return prisma.block.findMany({
where: { pageId },
orderBy: { position: "asc" },
});
}) as Promise<Block[]>;
}