feat: prompts admin-only, add isOpen field to Prompt model
This commit is contained in:
@@ -53,6 +53,7 @@ export async function createPrompt(data: {
|
||||
description: string;
|
||||
content: string;
|
||||
tags?: string[];
|
||||
isOpen?: boolean;
|
||||
}) {
|
||||
try {
|
||||
const slug = data.title
|
||||
@@ -71,11 +72,10 @@ export async function createPrompt(data: {
|
||||
description: data.description,
|
||||
content: data.content,
|
||||
tags,
|
||||
isOpen: data.isOpen ?? false,
|
||||
},
|
||||
});
|
||||
|
||||
revalidatePath('/[locale]');
|
||||
revalidatePath('/[locale]/prompts');
|
||||
revalidatePath('/[locale]/admin');
|
||||
return { success: true, prompt: newPrompt };
|
||||
} catch (error: any) {
|
||||
@@ -90,6 +90,7 @@ export async function updatePrompt(id: string, data: {
|
||||
description: string;
|
||||
content: string;
|
||||
tags?: string[];
|
||||
isOpen?: boolean;
|
||||
}) {
|
||||
try {
|
||||
const tags = data.tags && data.tags.length > 0 ? data.tags : [data.category, 'AI', 'Prompt'];
|
||||
@@ -102,12 +103,11 @@ export async function updatePrompt(id: string, data: {
|
||||
description: data.description,
|
||||
content: data.content,
|
||||
tags,
|
||||
isOpen: data.isOpen ?? false,
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
revalidatePath('/[locale]');
|
||||
revalidatePath('/[locale]/prompts');
|
||||
revalidatePath('/[locale]/admin');
|
||||
return { success: true, prompt: updated };
|
||||
} catch (error: any) {
|
||||
@@ -122,12 +122,10 @@ export async function deletePrompt(id: string) {
|
||||
where: { id },
|
||||
});
|
||||
|
||||
revalidatePath('/[locale]');
|
||||
revalidatePath('/[locale]/prompts');
|
||||
revalidatePath('/[locale]/admin');
|
||||
return { success: true };
|
||||
} catch (error: any) {
|
||||
console.error('Error deleting prompt:', error);
|
||||
return { success: false, error: error.message || 'Failed to delete prompt' };
|
||||
return { success: false, error: error.message || 'Failed to delete prompt' };;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user