feat: add prisma support, admin panel and auth

This commit is contained in:
AyrisAI
2026-05-15 19:11:17 +03:00
parent 31c3deb2da
commit 09a105cd1e
29 changed files with 3606 additions and 441 deletions

76
prisma/seed.ts Normal file
View File

@@ -0,0 +1,76 @@
import { PrismaClient } from '@prisma/client';
import { PrismaPg } from '@prisma/adapter-pg';
import { Pool } from 'pg';
import fs from 'fs';
import path from 'path';
import 'dotenv/config';
import bcrypt from 'bcryptjs';
const connectionString = process.env.DATABASE_URL;
const pool = new Pool({ connectionString });
const adapter = new PrismaPg(pool);
const prisma = new PrismaClient({ adapter });
async function main() {
const menuPath = path.join(__dirname, '../menu/menu.json');
const menuData = JSON.parse(fs.readFileSync(menuPath, 'utf-8'));
// 1. Create Restaurant
const restaurant = await prisma.restaurant.create({
data: {
name: menuData.restaurant_name,
footerNote: menuData.footer_note,
},
});
console.log(`Created restaurant: ${restaurant.name}`);
// 1.5 Create Admin User
const adminUsername = 'admin';
const hashedPassword = await bcrypt.hash('admin', 10);
const existingUser = await prisma.user.findUnique({ where: { username: adminUsername } });
if (!existingUser) {
await prisma.user.create({
data: {
username: adminUsername,
password: hashedPassword,
},
});
console.log(`Created admin user: ${adminUsername}`);
}
for (const cat of menuData.categories) {
const category = await prisma.category.create({
data: {
title: cat.title,
externalId: cat.id,
restaurantId: restaurant.id,
},
});
console.log(`Created category: ${category.title}`);
for (const item of cat.items) {
await prisma.item.create({
data: {
name: item.name,
ingredients: item.ingredients || null,
tasteProfile: item.taste_profile || null,
grapeVariety: item.grape_variety || null,
price: item.price, // Prisma handles JSON fields automatically
categoryId: category.id,
},
});
}
console.log(` Added ${cat.items.length} items to ${cat.title}`);
}
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});