fix: cleanup seed and fetch latest restaurant
This commit is contained in:
15
app/page.tsx
15
app/page.tsx
@@ -5,7 +5,8 @@ export const dynamic = 'force-dynamic';
|
|||||||
|
|
||||||
export default async function Page() {
|
export default async function Page() {
|
||||||
try {
|
try {
|
||||||
const restaurant = await prisma.restaurant.findFirst({
|
const restaurant = await (prisma as any).restaurant.findFirst({
|
||||||
|
orderBy: { createdAt: 'desc' },
|
||||||
include: {
|
include: {
|
||||||
categories: {
|
categories: {
|
||||||
include: {
|
include: {
|
||||||
@@ -48,6 +49,18 @@ export default async function Page() {
|
|||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (data.categories.length === 0) {
|
||||||
|
return (
|
||||||
|
<div style={{ background: '#000', color: '#fff', height: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center', textAlign: 'center', padding: '20px' }}>
|
||||||
|
<div>
|
||||||
|
<h1 style={{ color: 'var(--gold)' }}>LUNA</h1>
|
||||||
|
<p>Restoran bulundu ancak henüz hiç kategori eklenmemiş.</p>
|
||||||
|
<p style={{ fontSize: '0.8rem', color: '#666' }}>Lütfen admin panelinden kategori ve ürün ekleyin.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return <MenuView data={data} />;
|
return <MenuView data={data} />;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error("Database error:", error);
|
console.error("Database error:", error);
|
||||||
|
|||||||
@@ -15,8 +15,11 @@ async function main() {
|
|||||||
const menuPath = path.join(__dirname, '../menu/menu.json');
|
const menuPath = path.join(__dirname, '../menu/menu.json');
|
||||||
const menuData = JSON.parse(fs.readFileSync(menuPath, 'utf-8'));
|
const menuData = JSON.parse(fs.readFileSync(menuPath, 'utf-8'));
|
||||||
|
|
||||||
// 1. Create Restaurant
|
console.log('Cleaning up existing data...');
|
||||||
const restaurant = await prisma.restaurant.create({
|
await (prisma as any).item.deleteMany();
|
||||||
|
await (prisma as any).category.deleteMany();
|
||||||
|
await (prisma as any).restaurant.deleteMany();
|
||||||
|
const restaurant = await (prisma as any).restaurant.create({
|
||||||
data: {
|
data: {
|
||||||
name: menuData.restaurant_name,
|
name: menuData.restaurant_name,
|
||||||
footerNote: menuData.footer_note,
|
footerNote: menuData.footer_note,
|
||||||
@@ -40,7 +43,7 @@ async function main() {
|
|||||||
console.log(`Created admin user: ${adminUsername}`);
|
console.log(`Created admin user: ${adminUsername}`);
|
||||||
}
|
}
|
||||||
for (const cat of menuData.categories) {
|
for (const cat of menuData.categories) {
|
||||||
const category = await prisma.category.create({
|
const category = await (prisma as any).category.create({
|
||||||
data: {
|
data: {
|
||||||
title: cat.title,
|
title: cat.title,
|
||||||
externalId: cat.id,
|
externalId: cat.id,
|
||||||
@@ -51,7 +54,7 @@ async function main() {
|
|||||||
console.log(`Created category: ${category.title}`);
|
console.log(`Created category: ${category.title}`);
|
||||||
|
|
||||||
for (const item of cat.items) {
|
for (const item of cat.items) {
|
||||||
await prisma.item.create({
|
await (prisma as any).item.create({
|
||||||
data: {
|
data: {
|
||||||
name: item.name,
|
name: item.name,
|
||||||
ingredients: item.ingredients || null,
|
ingredients: item.ingredients || null,
|
||||||
|
|||||||
Reference in New Issue
Block a user