159 lines
6.1 KiB
TypeScript
159 lines
6.1 KiB
TypeScript
import { getPayload } from 'payload';
|
||
import configPromise from '../payload.config';
|
||
|
||
const fixPages = async () => {
|
||
const payload = await getPayload({ config: configPromise });
|
||
payload.logger.info('Running missing pages alignment script...');
|
||
|
||
const teamMembers = [
|
||
{ name: 'Danny Joseph', position: 'Geschäftsführung', email: 'd.joseph@e-tib.com', phone: '015207230518', branch: 'e-tib' },
|
||
{ name: 'Dirk Schmidt', position: 'Projektleitung', email: 'd.schmidt@e-tib.com', phone: '015165069040', branch: 'e-tib' },
|
||
{ name: 'Oliver Fiedler', position: 'Bauleitung', email: 'o.fiedler@e-tib.com', phone: '015152264087', branch: 'e-tib' },
|
||
{ name: 'Martin Polan', position: 'Polier', email: 'm.polan@e-tib.com', phone: '01713868167', branch: 'e-tib' },
|
||
{ name: 'Kerstin Joseph', position: 'Sekretariat / Buchhaltung', email: 'k.joseph@e-tib.com', phone: '03561 6851692', branch: 'verw' },
|
||
{ name: 'Kathrin Lemanski', position: 'Sachbearbeitung', email: 'k.lemanski@e-tib.com', phone: '03561 6857733', branch: 'verw' },
|
||
{ name: 'Sven Kirbs', position: 'Bauleitung', email: 's.kirbs@e-tib.com', phone: '', branch: 'e-tib' },
|
||
{ name: 'Maik Weichert', position: 'Bauleitung', email: 'm.weichert@e-tib.com', phone: '', branch: 'e-tib' },
|
||
];
|
||
|
||
try {
|
||
// Seed Team Members
|
||
for (const member of teamMembers) {
|
||
const existing = await payload.find({
|
||
collection: 'team',
|
||
where: { name: { equals: member.name } },
|
||
limit: 1,
|
||
});
|
||
|
||
if (existing.totalDocs === 0) {
|
||
payload.logger.info(`Creating team member: ${member.name}`);
|
||
await payload.create({
|
||
collection: 'team',
|
||
data: {
|
||
name: member.name,
|
||
position: member.position,
|
||
email: member.email,
|
||
phone: member.phone,
|
||
branch: member.branch as any,
|
||
},
|
||
});
|
||
}
|
||
}
|
||
|
||
// Create Kontakt and Karriere pages
|
||
for (const loc of ['de', 'en']) {
|
||
// Kontakt
|
||
const existingKontakt = await payload.find({
|
||
collection: 'pages',
|
||
where: { slug: { equals: 'kontakt' } },
|
||
locale: loc as any,
|
||
limit: 1,
|
||
});
|
||
|
||
const kontaktData = {
|
||
title: loc === 'de' ? 'Kontakt' : 'Contact',
|
||
slug: 'kontakt',
|
||
_status: 'published',
|
||
content: {
|
||
root: {
|
||
type: 'root',
|
||
format: '',
|
||
indent: 0,
|
||
version: 1,
|
||
children: [
|
||
{
|
||
type: 'block',
|
||
format: '',
|
||
version: 2,
|
||
fields: {
|
||
blockType: 'heroSection',
|
||
title: loc === 'de' ? 'Kontaktieren Sie uns' : 'Contact Us',
|
||
description: loc === 'de' ? 'Ihre Ansprechpartner der E-TIB Gruppe' : 'Your contacts at the E-TIB Group'
|
||
}
|
||
},
|
||
{
|
||
type: 'block',
|
||
format: '',
|
||
version: 2,
|
||
fields: {
|
||
blockType: 'homeMeetTheTeam',
|
||
title: loc === 'de' ? 'Das sind Ihre Ansprechpartner' : 'Meet our team',
|
||
subtitle: loc === 'de' ? 'Unser Team aus Experten freut sich auf Ihr Projekt.' : 'Our team of experts is looking forward to your project.',
|
||
description: loc === 'de' ? 'Hier finden Sie alle Zertifikate und Ansprechpartner an einem Ort.' : 'Here you can find all certificates and contacts in one place.',
|
||
ctaLabel: loc === 'de' ? 'Zum Kontaktformular' : 'To Contact Form',
|
||
networkLabel: loc === 'de' ? 'Das E-TIB Netzwerk' : 'The E-TIB Network'
|
||
}
|
||
}
|
||
]
|
||
}
|
||
}
|
||
};
|
||
|
||
if (existingKontakt.totalDocs === 0) {
|
||
payload.logger.info(`Creating Kontakt page [${loc}]...`);
|
||
await payload.create({ collection: 'pages', locale: loc as any, data: kontaktData });
|
||
} else {
|
||
await payload.update({ collection: 'pages', id: existingKontakt.docs[0].id, locale: loc as any, data: kontaktData });
|
||
}
|
||
|
||
// Karriere
|
||
const existingKarriere = await payload.find({
|
||
collection: 'pages',
|
||
where: { slug: { equals: 'karriere' } },
|
||
locale: loc as any,
|
||
limit: 1,
|
||
});
|
||
|
||
const karriereData = {
|
||
title: loc === 'de' ? 'Karriere & Messen' : 'Career & Exhibitions',
|
||
slug: 'karriere',
|
||
_status: 'published',
|
||
content: {
|
||
root: {
|
||
type: 'root',
|
||
format: '',
|
||
indent: 0,
|
||
version: 1,
|
||
children: [
|
||
{
|
||
type: 'block',
|
||
format: '',
|
||
version: 2,
|
||
fields: {
|
||
blockType: 'heroSection',
|
||
title: loc === 'de' ? 'Karriere bei E-TIB' : 'Career at E-TIB',
|
||
description: loc === 'de' ? 'Wir wachsen – und werfen gemeinsam mit Dir die Energie-Wende an.' : 'We are growing - and fueling the energy transition together.'
|
||
}
|
||
},
|
||
{
|
||
type: 'paragraph',
|
||
children: [{ type: 'text', text: loc === 'de' ? 'Trefft uns auf diesen kommenden Messen:\n- Intersolar München\n- Windenergietage Linstow\n- Kabelwerkstatt Wiesbaden' : 'Meet us at these upcoming exhibitions:\n- Intersolar Munich\n- Wind Energy Days Linstow\n- Cable Workshop Wiesbaden', version: 1 }]
|
||
}
|
||
]
|
||
}
|
||
}
|
||
};
|
||
|
||
if (existingKarriere.totalDocs === 0) {
|
||
payload.logger.info(`Creating Karriere page [${loc}]...`);
|
||
await payload.create({ collection: 'pages', locale: loc as any, data: karriereData });
|
||
} else {
|
||
await payload.update({ collection: 'pages', id: existingKarriere.docs[0].id, locale: loc as any, data: karriereData });
|
||
}
|
||
}
|
||
|
||
payload.logger.info('✅ Missing pages created successfully!');
|
||
process.exit(0);
|
||
} catch (err: any) {
|
||
payload.logger.error('❌ Missing pages script failed!');
|
||
if (err.data) {
|
||
payload.logger.error(JSON.stringify(err.data, null, 2));
|
||
} else {
|
||
payload.logger.error(err.stack || err.message || err);
|
||
}
|
||
process.exit(1);
|
||
}
|
||
};
|
||
|
||
fixPages();
|