|
| 1 | +import mongoose from 'mongoose'; |
| 2 | +import dotenv from 'dotenv'; |
| 3 | +import User from '../../models/User.js'; |
| 4 | +import Club from '../../models/Club.js'; |
| 5 | + |
| 6 | +dotenv.config(); |
| 7 | + |
| 8 | +const clubData = { |
| 9 | + name: 'Saint Barthélémy Volley-Ball', |
| 10 | + subtitle: 'Passion, Performance, Partage', |
| 11 | + homeDescription: |
| 12 | + 'Bienvenue sur le site officiel du Saint Barthélémy Volley-Ball, le club où la passion du volley rencontre l'esprit d'équipe et la convivialité.', |
| 13 | + clubDescription: |
| 14 | + 'Le club propose des entraînements pour tous les niveaux, des jeunes aux seniors, dans un esprit de partage et de progression.', |
| 15 | + ownerDescription: |
| 16 | + 'Notre équipe dirigeante est composée de bénévoles passionnés, engagés pour le développement du volley-ball à Saint-Barthélémy.', |
| 17 | + logo: '/assets/images/default_logo.png', |
| 18 | + photo: '/assets/images/default_club_photo.png', |
| 19 | + email: 'contact@saintbarthvolley.fr', |
| 20 | + phone: '(+33) 02 41 XX XX XX', |
| 21 | + address: 'Saint-Barthélemy, Caraïbes', |
| 22 | + social_links: { |
| 23 | + facebook: '', |
| 24 | + instagram: '', |
| 25 | + youtube: '', |
| 26 | + sporteasy: '', |
| 27 | + clubMerch: '', |
| 28 | + clubRegistration: '', |
| 29 | + website: '', |
| 30 | + other: '', |
| 31 | + }, |
| 32 | + legal_info: { |
| 33 | + associationName: 'Saint Barth Volley-Ball', |
| 34 | + legalForm: 'Association loi 1901', |
| 35 | + siret: '', |
| 36 | + rna: '', |
| 37 | + headOffice: 'Saint-Barthélemy', |
| 38 | + publicationDate: null, |
| 39 | + responsible: '', |
| 40 | + hostingProvider: '', |
| 41 | + updatedAt: null, |
| 42 | + }, |
| 43 | +}; |
| 44 | + |
| 45 | +const seedAdmin = async () => { |
| 46 | + const existing = await User.findOne({ role: 'admin' }); |
| 47 | + if (existing) { |
| 48 | + console.log('⚠️ Admin déjà existant :', existing.email); |
| 49 | + return; |
| 50 | + } |
| 51 | + |
| 52 | + const admin = new User({ |
| 53 | + email: process.env.ADMIN_EMAIL, |
| 54 | + firstName: 'Admin', |
| 55 | + lastName: 'Root', |
| 56 | + role: 'admin', |
| 57 | + isActive: true, |
| 58 | + isVerified: true, |
| 59 | + }); |
| 60 | + |
| 61 | + await admin.setPassword(process.env.ADMIN_PASSWORD); |
| 62 | + await admin.save(); |
| 63 | + |
| 64 | + console.log('✅ Admin créé'); |
| 65 | + console.log(' Email :', admin.email); |
| 66 | + console.log(' Password :', process.env.ADMIN_PASSWORD); |
| 67 | +}; |
| 68 | + |
| 69 | +const seedClub = async () => { |
| 70 | + const existing = await Club.findOne({}); |
| 71 | + if (existing) { |
| 72 | + console.log('⚠️ Club déjà existant, ignoré.'); |
| 73 | + return; |
| 74 | + } |
| 75 | + |
| 76 | + const club = new Club(clubData); |
| 77 | + await club.save(); |
| 78 | + console.log('✅ Club seedé'); |
| 79 | +}; |
| 80 | + |
| 81 | +const run = async () => { |
| 82 | + try { |
| 83 | + await mongoose.connect(process.env.MONGO_URI); |
| 84 | + console.log('🔗 Connecté à MongoDB\n'); |
| 85 | + |
| 86 | + await seedAdmin(); |
| 87 | + await seedClub(); |
| 88 | + |
| 89 | + console.log('\n🎉 Seed terminé.'); |
| 90 | + } catch (err) { |
| 91 | + console.error('❌ Erreur seed :', err); |
| 92 | + process.exit(1); |
| 93 | + } finally { |
| 94 | + await mongoose.disconnect(); |
| 95 | + } |
| 96 | +}; |
| 97 | + |
| 98 | +run(); |
0 commit comments