This commit is contained in:
Kiss Dávid
2026-03-29 11:18:31 +02:00
parent 1ebb2e53a9
commit d55e085741
16 changed files with 4130 additions and 0 deletions
@@ -0,0 +1,113 @@
import { BaseSchema } from '@adonisjs/lucid/schema'
export default class extends BaseSchema {
async up() {
this.schema.createTable('users', (table) => {
table.increments('id')
table.string('full_name').notNullable()
table.string('email').notNullable().unique()
table.string('role').notNullable().defaultTo('user')
table.string('password').notNullable()
table.timestamp('created_at', { useTz: true }).notNullable()
table.timestamp('updated_at', { useTz: true }).notNullable()
})
this.schema.createTable('auth_access_tokens', (table) => {
table.increments('id')
table
.integer('tokenable_id')
.unsigned()
.notNullable()
.references('id')
.inTable('users')
.onDelete('CASCADE')
table.string('type').notNullable()
table.string('name').nullable()
table.string('hash').notNullable()
table.text('abilities').notNullable()
table.timestamp('created_at')
table.timestamp('updated_at')
table.timestamp('last_used_at').nullable()
table.timestamp('expires_at').nullable()
})
this.schema.createTable('categories', (table) => {
table.increments('id')
table.string('name').notNullable().unique()
table.string('name_hu')
table.string('name_en')
table.string('slug').notNullable().unique()
table.timestamp('created_at', { useTz: true }).notNullable()
table.timestamp('updated_at', { useTz: true }).notNullable()
})
this.schema.createTable('restaurant_menus', (table) => {
table.increments('id')
table.string('name').notNullable()
table.string('name_hu')
table.string('name_en')
table.timestamp('created_at', { useTz: true }).notNullable()
table.timestamp('updated_at', { useTz: true }).notNullable()
})
this.schema.createTable('restaurant_menu_items', (table) => {
table.increments('id')
table.string('name').notNullable()
table.string('name_hu')
table.string('name_en')
table.decimal('price_small', 10, 2).notNullable()
table.decimal('price_large', 10, 2).notNullable()
table.text('description')
table.text('description_hu')
table.text('description_en')
table
.integer('category_id')
.unsigned()
.references('id')
.inTable('categories')
.onDelete('SET NULL')
table.timestamp('created_at', { useTz: true }).notNullable()
table.timestamp('updated_at', { useTz: true }).notNullable()
})
this.schema.createTable('menu_item_menus', (table) => {
table.increments('id')
table
.integer('restaurant_menu_item_id')
.unsigned()
.notNullable()
.references('id')
.inTable('restaurant_menu_items')
.onDelete('CASCADE')
table
.integer('restaurant_menu_id')
.unsigned()
.notNullable()
.references('id')
.inTable('restaurant_menus')
.onDelete('CASCADE')
table.unique(['restaurant_menu_item_id', 'restaurant_menu_id'])
})
this.schema.createTable('rate_limits', (table) => {
table.string('key', 255).notNullable().primary()
table.integer('points', 9).notNullable().defaultTo(0)
table.bigint('expire').unsigned()
})
}
async down() {
this.schema.dropTable('menu_item_menus')
this.schema.dropTable('restaurant_menu_items')
this.schema.dropTable('restaurant_menus')
this.schema.dropTable('categories')
this.schema.dropTable('auth_access_tokens')
this.schema.dropTable('users')
this.schema.dropTable('rate_limits')
}
}
+94
View File
@@ -0,0 +1,94 @@
import { BaseSeeder } from '@adonisjs/lucid/seeders'
import RestaurantMenuItem from '#models/restaurant_menu_item'
import Category from '#models/category'
import fs from 'node:fs'
import path from 'node:path'
import app from '@adonisjs/core/services/app'
export default class extends BaseSeeder {
async run() {
const filePath = path.join(app.makePath(), 'menu.json')
const content = fs.readFileSync(filePath, 'utf-8')
const menuItems = JSON.parse(content)
// Create categories
const categoriesData = [
{ name: 'Levesek', nameHu: 'Levesek', nameEn: 'Soups', slug: 'levesek' },
{ name: 'Főzelékek', nameHu: 'Főzelékek', nameEn: 'Vegetable Stews', slug: 'fozelekek' },
{ name: 'Készételek', nameHu: 'Készételek', nameEn: 'Ready Meals', slug: 'keszetelek' },
{
name: 'Frissensültek',
nameHu: 'Frissensültek',
nameEn: 'Fresh Roasts',
slug: 'frissensultek',
},
{ name: 'Tészták', nameHu: 'Tészták', nameEn: 'Pasta', slug: 'tesztak' },
{ name: 'Desszertek', nameHu: 'Desszertek', nameEn: 'Desserts', slug: 'desszertek' },
{ name: 'Egyéb', nameHu: 'Egyéb', nameEn: 'Other', slug: 'egyeb' },
{ name: 'Köretek', nameHu: 'Köretek', nameEn: 'Sides', slug: 'koretek' },
{ name: 'Savanyúság', nameHu: 'Savanyúság', nameEn: 'Pickles', slug: 'savanyusag' },
]
const categories: Record<string, Category> = {}
for (const catData of categoriesData) {
categories[catData.slug] = await Category.updateOrCreate({ slug: catData.slug }, catData)
}
const getCategoryId = (name: string): number => {
const lowerName = name.toLowerCase()
if (lowerName.includes('leves')) return categories['levesek'].id
if (lowerName.includes('főzelék') || lowerName.includes('káposzta'))
return categories['fozelekek'].id
if (
lowerName.includes('fánk') ||
(lowerName.includes('szelet') &&
(lowerName.includes('üdítős') || lowerName.includes('gesztenyés'))) ||
lowerName.includes('gombóc') ||
lowerName.includes('linzer') ||
lowerName.includes('nudli') ||
lowerName.includes('lúdláb') ||
lowerName.includes('tekercs')
)
return categories['desszertek'].id
if (
lowerName.includes('tészta') ||
lowerName.includes('spagetti') ||
lowerName.includes('nudli') ||
lowerName.includes('csusza')
)
return categories['tesztak'].id
if (
lowerName.includes('rántott') ||
lowerName.includes('sült') ||
lowerName.includes('grill')
)
return categories['frissensultek'].id
if (
lowerName.includes('pörkölt') ||
lowerName.includes('tokány') ||
lowerName.includes('aprópecsenye') ||
lowerName.includes('rakott')
)
return categories['keszetelek'].id
return categories['egyeb'].id
}
for (const item of menuItems) {
const { name, nameHu, nameEn, priceLarge, priceSmall } = item
if (name) {
await RestaurantMenuItem.updateOrCreate(
{ name },
{
name,
nameHu,
nameEn,
priceLarge,
priceSmall,
categoryId: getCategoryId(nameHu),
}
)
}
}
}
}
+13
View File
@@ -0,0 +1,13 @@
import { BaseSeeder } from '@adonisjs/lucid/seeders'
import User from '#models/user'
export default class extends BaseSeeder {
async run() {
await User.create({
email: 'kiss.david@test.hu',
password: 'Palacsinta1.',
fullName: 'Kiss Dávid',
role: 'admin',
})
}
}