Files
spotlightcam/backend/scripts/create-event.js

71 lines
2.1 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env node
const { PrismaClient } = require('@prisma/client');
const crypto = require('crypto');
const prisma = new PrismaClient();
/**
* Create a new event with a random slug
* Usage: node scripts/create-event.js <name> <location> <startDate> <endDate>
* Example: node scripts/create-event.js "Santa Swing" "Kraków, Poland" "2025-12-12" "2025-12-15"
*/
async function createEvent() {
try {
// Parse command-line arguments
const args = process.argv.slice(2);
if (args.length < 4) {
console.error('❌ Usage: node scripts/create-event.js <name> <location> <startDate> <endDate>');
console.error(' Example: node scripts/create-event.js "Santa Swing" "Kraków, Poland" "2025-12-12" "2025-12-15"');
process.exit(1);
}
const [name, location, startDate, endDate] = args;
// Validate dates
const start = new Date(startDate);
const end = new Date(endDate);
if (isNaN(start.getTime()) || isNaN(end.getTime())) {
console.error('❌ Invalid date format. Use YYYY-MM-DD format.');
process.exit(1);
}
if (end < start) {
console.error('❌ End date must be after start date.');
process.exit(1);
}
// Generate random slug (8 characters alphanumeric)
const slug = crypto.randomBytes(4).toString('hex');
// Create event
const event = await prisma.event.create({
data: {
name,
slug,
location,
startDate: start,
endDate: end,
},
});
console.log('✅ Event created successfully:');
console.log(` ID: ${event.id}`);
console.log(` Name: ${event.name}`);
console.log(` Slug: ${event.slug}`);
console.log(` Location: ${event.location}`);
console.log(` Dates: ${event.startDate.toISOString().split('T')[0]}${event.endDate.toISOString().split('T')[0]}`);
console.log(`\n URL: ${process.env.FRONTEND_URL || 'http://localhost'}/events/${event.slug}`);
} catch (error) {
console.error('❌ Error creating event:', error.message);
process.exit(1);
} finally {
await prisma.$disconnect();
}
}
createEvent();