feat: добавляет файл инициализации данных, DTO для категорий списка желаний и компонент формы для создания событий.
This commit is contained in:
120
backend/seed.ts
Normal file
120
backend/seed.ts
Normal 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);
|
||||
});
|
||||
@@ -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),
|
||||
|
||||
@@ -51,8 +51,7 @@ export function EventForm({ onEventCreated }: EventFormProps) {
|
||||
setEventType('recurring');
|
||||
setFormData({ ...formData, startYear: undefined, endYear: undefined, endMonth: undefined, endDay: undefined });
|
||||
}}
|
||||
className={`px-4 py-2 rounded-lg font-medium transition-colors ${
|
||||
eventType === 'recurring'
|
||||
className={`px-4 py-2 rounded-lg font-medium transition-colors ${eventType === 'recurring'
|
||||
? 'bg-blue-600 text-white'
|
||||
: 'bg-gray-800 text-gray-400 hover:bg-gray-700'
|
||||
}`}
|
||||
@@ -65,8 +64,7 @@ export function EventForm({ onEventCreated }: EventFormProps) {
|
||||
setEventType('anniversary');
|
||||
setFormData({ ...formData, endYear: undefined, endMonth: undefined, endDay: undefined });
|
||||
}}
|
||||
className={`px-4 py-2 rounded-lg font-medium transition-colors ${
|
||||
eventType === 'anniversary'
|
||||
className={`px-4 py-2 rounded-lg font-medium transition-colors ${eventType === 'anniversary'
|
||||
? 'bg-blue-600 text-white'
|
||||
: 'bg-gray-800 text-gray-400 hover:bg-gray-700'
|
||||
}`}
|
||||
@@ -76,8 +74,7 @@ export function EventForm({ onEventCreated }: EventFormProps) {
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setEventType('duration')}
|
||||
className={`px-4 py-2 rounded-lg font-medium transition-colors ${
|
||||
eventType === 'duration'
|
||||
className={`px-4 py-2 rounded-lg font-medium transition-colors ${eventType === 'duration'
|
||||
? 'bg-blue-600 text-white'
|
||||
: 'bg-gray-800 text-gray-400 hover:bg-gray-700'
|
||||
}`}
|
||||
@@ -116,7 +113,7 @@ export function EventForm({ onEventCreated }: EventFormProps) {
|
||||
<label className="block text-sm font-medium mb-2">Год начала</label>
|
||||
<input
|
||||
type="number"
|
||||
required={eventType !== 'recurring'}
|
||||
required
|
||||
value={formData.startYear || ''}
|
||||
onChange={(e) =>
|
||||
setFormData({
|
||||
|
||||
Reference in New Issue
Block a user