Refactor for i18n, CMS integration, and project slugs; enhance admin & analytics
Co-authored-by: dennis <dennis@konkol.net>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { generateUniqueSlug } from './slug';
|
||||
|
||||
const globalForPrisma = globalThis as unknown as {
|
||||
prisma: PrismaClient | undefined;
|
||||
@@ -68,9 +69,26 @@ export const projectService = {
|
||||
|
||||
// Create new project
|
||||
async createProject(data: Record<string, unknown>) {
|
||||
const providedSlug = typeof data.slug === 'string' ? data.slug : undefined;
|
||||
const providedTitle = typeof data.title === 'string' ? data.title : undefined;
|
||||
|
||||
const slug =
|
||||
providedSlug?.trim() ||
|
||||
(await generateUniqueSlug({
|
||||
base: providedTitle || 'project',
|
||||
isTaken: async (candidate) => {
|
||||
const existing = await prisma.project.findUnique({
|
||||
where: { slug: candidate },
|
||||
select: { id: true },
|
||||
});
|
||||
return !!existing;
|
||||
},
|
||||
}));
|
||||
|
||||
return prisma.project.create({
|
||||
data: {
|
||||
...data,
|
||||
slug,
|
||||
performance: data.performance || { lighthouse: 0, bundleSize: '0KB', loadTime: '0s' },
|
||||
analytics: data.analytics || { views: 0, likes: 0, shares: 0 }
|
||||
} as any // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
|
||||
Reference in New Issue
Block a user