1
0
mirror of https://github.com/tabler/tabler.git synced 2025-12-26 11:16:12 +04:00
Files
tabler/site/lib/data.ts
tabler.developer@gmail.com 09a8e2d2c5 lemon squeezy integration
2023-12-07 00:56:02 +01:00

50 lines
897 B
TypeScript

import prisma from '@/lib/prisma'
export async function getPlans() {
// Gets all active plans
return await prisma.plan.findMany({
where: {
NOT: [
{ status: 'draft' },
{ status: 'pending' }
]
},
include: {
subscriptions: true
}
})
}
export async function getPlan(variantId: number) {
// Gets single active plan by ID
return await prisma.plan.findFirst({
where: {
variantId: variantId,
NOT: [
{ status: 'draft' },
{ status: 'pending' }
]
},
include: {
subscriptions: true
}
})
}
export async function getSubscription(userId?: string) {
// Gets the most recent subscription
return await prisma.subscription.findFirst({
where: {
userId: userId
},
include: {
plan: true,
user: true
},
orderBy: {
lemonSqueezyId: 'desc'
}
})
}