-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
461 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
async function main() { | ||
// Lösche existierende Pläne | ||
await prisma.plan.deleteMany(); | ||
|
||
// Erstelle Standard-Pläne | ||
const plans = [ | ||
{ | ||
name: 'Free', | ||
price: 0, | ||
description: 'Perfekt zum Testen und für kleine Projekte', | ||
features: [ | ||
'1 Umfrage', | ||
'50 Antworten pro Monat', | ||
'Basis-Auswertungen', | ||
'Community Support', | ||
'Kostenlos starten', | ||
], | ||
}, | ||
{ | ||
name: 'Professional', | ||
price: 29.99, | ||
description: 'Ideal für wachsende Unternehmen', | ||
features: [ | ||
'Unbegrenzte Umfragen', | ||
'1000 Antworten pro Monat', | ||
'Erweiterte Auswertungen', | ||
'Prioritäts-Support', | ||
'Eigenes Branding', | ||
], | ||
}, | ||
{ | ||
name: 'Enterprise', | ||
price: 99.99, | ||
description: 'Für große Organisationen', | ||
features: [ | ||
'Unbegrenzte Umfragen', | ||
'Unbegrenzte Antworten', | ||
'Premium Auswertungen', | ||
'24/7 Support', | ||
'Eigenes Branding', | ||
'API Zugang', | ||
'SLA Garantie', | ||
], | ||
}, | ||
]; | ||
|
||
for (const plan of plans) { | ||
await prisma.plan.create({ | ||
data: plan, | ||
}); | ||
} | ||
|
||
console.log('Seed erfolgreich ausgeführt'); | ||
} | ||
|
||
main() | ||
.catch((e) => { | ||
console.error(e); | ||
process.exit(1); | ||
}) | ||
.finally(async () => { | ||
await prisma.$disconnect(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"sourceMap": true, | ||
"outDir": "dist", | ||
"strict": true, | ||
"lib": ["esnext"], | ||
"esModuleInterop": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { NextResponse } from 'next/server'; | ||
import { getServerSession } from 'next-auth'; | ||
import { prisma } from '@/lib/prisma'; | ||
import { authOptions } from '@/lib/auth'; | ||
|
||
export async function POST(req: Request) { | ||
try { | ||
const session = await getServerSession(authOptions); | ||
if (!session?.user?.email) { | ||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); | ||
} | ||
|
||
const { planId, paymentDetails } = await req.json(); | ||
|
||
// Validiere die Zahlung (hier später PayPal Webhook Integration) | ||
if (!paymentDetails?.id) { | ||
return NextResponse.json({ error: 'Invalid payment details' }, { status: 400 }); | ||
} | ||
|
||
// Hole den Plan aus der Datenbank | ||
const plan = await prisma.plan.findUnique({ | ||
where: { id: planId }, | ||
}); | ||
|
||
if (!plan) { | ||
return NextResponse.json({ error: 'Plan not found' }, { status: 404 }); | ||
} | ||
|
||
// Plan aktivieren | ||
const updatedUser = await prisma.user.update({ | ||
where: { email: session.user.email }, | ||
data: { | ||
planId: planId, | ||
planActiveUntil: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000), // 30 Tage | ||
}, | ||
include: { | ||
plan: true, | ||
}, | ||
}); | ||
|
||
return NextResponse.json({ | ||
success: true, | ||
user: updatedUser, | ||
}); | ||
} catch (error) { | ||
console.error('Error activating plan:', error); | ||
return NextResponse.json({ error: 'Failed to activate plan' }, { status: 500 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { NextResponse } from 'next/server'; | ||
import { getServerSession } from 'next-auth'; | ||
import { prisma } from '@/lib/prisma'; | ||
import { authOptions } from '@/lib/auth'; | ||
|
||
export async function POST(req: Request) { | ||
try { | ||
const session = await getServerSession(authOptions); | ||
if (!session?.user?.email) { | ||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); | ||
} | ||
|
||
const { planId } = await req.json(); | ||
|
||
// Hole den Plan aus der Datenbank | ||
const plan = await prisma.plan.findUnique({ | ||
where: { id: planId }, | ||
}); | ||
|
||
if (!plan) { | ||
return NextResponse.json({ error: 'Plan not found' }, { status: 404 }); | ||
} | ||
|
||
// Subscription aktualisieren | ||
const updatedUser = await prisma.user.update({ | ||
where: { email: session.user.email }, | ||
data: { | ||
planId: plan.id, | ||
planActiveUntil: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000), // 30 days from now | ||
}, | ||
include: { | ||
plan: true, | ||
}, | ||
}); | ||
|
||
return NextResponse.json({ | ||
success: true, | ||
user: updatedUser, | ||
}); | ||
} catch (error) { | ||
console.error('Error updating subscription:', error); | ||
return NextResponse.json({ error: 'Failed to update subscription' }, { status: 500 }); | ||
} | ||
} | ||
|
||
export async function GET(req: Request) { | ||
try { | ||
const session = await getServerSession(authOptions); | ||
if (!session?.user?.email) { | ||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); | ||
} | ||
|
||
// Hole den Benutzer mit seinem aktuellen Plan | ||
const user = await prisma.user.findUnique({ | ||
where: { email: session.user.email }, | ||
include: { | ||
plan: true, | ||
}, | ||
}); | ||
|
||
if (!user) { | ||
return NextResponse.json({ error: 'User not found' }, { status: 404 }); | ||
} | ||
|
||
// Hole alle verfügbaren Pläne | ||
const plans = await prisma.plan.findMany(); | ||
|
||
return NextResponse.json({ | ||
success: true, | ||
currentPlan: user.plan, | ||
allPlans: plans, | ||
planActiveUntil: user.planActiveUntil, | ||
}); | ||
} catch (error) { | ||
console.error('Error fetching subscription:', error); | ||
return NextResponse.json({ error: 'Failed to fetch subscription' }, { status: 500 }); | ||
} | ||
} |
Oops, something went wrong.