feat: добавляет файл инициализации данных, DTO для категорий списка желаний и компонент формы для создания событий.

This commit is contained in:
2025-12-06 11:20:38 +03:00
parent 043b2fd681
commit b823c1b58d
3 changed files with 128 additions and 11 deletions

120
backend/seed.ts Normal file
View File

@@ -0,0 +1,120 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './src/app.module';
import { WishlistCategoriesService } from './src/wishlist/categories.service';
import { WishlistService } from './src/wishlist/wishlist.service';
async function seed() {
const app = await NestFactory.createApplicationContext(AppModule);
const categoriesService = app.get(WishlistCategoriesService);
const wishlistService = app.get(WishlistService);
console.log('🌱 Seeding wishlist categories...');
// Создать категории
const category1 = await categoriesService.create({
name: 'БЮДЖЕТНО',
slug: 'tier-1',
minPrice: 0,
maxPrice: 150000, // 1500 руб
color: '#00ff41',
icon: '🟢',
order: 1,
});
const category2 = await categoriesService.create({
name: 'СРЕДНИЙ',
slug: 'tier-2',
minPrice: 150001,
maxPrice: 500000, // 5000 руб
color: '#00cc33',
icon: '🟡',
order: 2,
});
const category3 = await categoriesService.create({
name: 'ТОП',
slug: 'tier-3',
minPrice: 500001,
maxPrice: null, // без ограничения
color: '#009922',
icon: '🔴',
order: 3,
});
console.log(`✅ Created 3 categories`);
console.log('🌱 Seeding wishlist items...');
// Создать примерные товары
await wishlistService.create({
title: 'Зерновой Кофе (Эфиопия)',
description: 'Люблю светлую обжарку. Желательно Эфиопия или Кения. Нужен именно в зернах.',
price: 85000, // 850 руб
currency: 'RUB',
link: 'https://ozon.ru',
imageUrls: ['https://images.unsplash.com/photo-1497935586351-b67a49e012bf?w=500'],
categoryId: category1.id,
});
await wishlistService.create({
title: 'Молескин в точку',
description: 'Черный, классический. Обязательно в точку, а не в линейку.',
price: 120000, // 1200 руб
currency: 'RUB',
link: 'https://wildberries.ru',
imageUrls: ['https://images.unsplash.com/photo-1531346878377-a513bc957374?w=500'],
categoryId: category1.id,
});
await wishlistService.create({
title: 'Винил: Daft Punk',
description: 'Альбом "Random Access Memories". Мечтаю послушать его на проигрывателе.',
price: 350000, // 3500 руб
currency: 'RUB',
link: 'https://market.yandex.ru',
imageUrls: ['https://images.unsplash.com/photo-1603048588665-791ca8aea617?w=500'],
categoryId: category2.id,
});
await wishlistService.create({
title: 'D&D Стартовый набор',
description: '5-я редакция. Хочу попробовать поиграть с друзьями.',
price: 290000, // 2900 руб
currency: 'RUB',
link: 'https://hobbygames.ru',
imageUrls: ['https://images.unsplash.com/photo-1632501641765-e568d90e09b2?w=500'],
categoryId: category2.id,
});
await wishlistService.create({
title: 'LEGO Speed Champions',
description: 'Любая машинка из этой серии, желательно Porsche или Ferrari.',
price: 250000, // 2500 руб
currency: 'RUB',
link: 'https://detmir.ru',
imageUrls: ['https://images.unsplash.com/photo-1585366119957-e9730b6d0f60?w=500'],
categoryId: category2.id,
});
await wishlistService.create({
title: 'Keychron K2',
description: 'Механическая клавиатура. Свичи Red или Brown. Нужна подсветка.',
price: 900000, // 9000 руб
currency: 'RUB',
link: 'https://geekboards.ru',
imageUrls: ['https://images.unsplash.com/photo-1595225476474-87563907a212?w=500'],
categoryId: category3.id,
});
console.log(`✅ Created 6 wishlist items`);
console.log('✨ Seeding completed!');
await app.close();
process.exit(0);
}
seed().catch((error) => {
console.error('❌ Seeding failed:', error);
process.exit(1);
});

View File

@@ -4,7 +4,7 @@ export const CreateWishlistCategorySchema = z.object({
name: z.string().min(1).max(100),
slug: z.string().regex(/^[a-z0-9-]+$/),
minPrice: z.number().int().min(0).default(0),
maxPrice: z.number().int().positive().optional(),
maxPrice: z.number().int().positive().optional().nullable(),
color: z.string().regex(/^#[0-9A-Fa-f]{6}$/).optional(),
icon: z.string().optional(),
order: z.number().int().default(0),