mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
27 lines
720 B
TypeScript
27 lines
720 B
TypeScript
import { PremiumModel } from "~/shared/schema/PremiumSchema";
|
|
|
|
export default defineEventHandler(async event => {
|
|
const ctx = await getRequestContext(event, 'flag:allowAnonRegistered');
|
|
|
|
|
|
//TODO: SELFHOST
|
|
|
|
const { user_id } = ctx;
|
|
|
|
const { plan_tag } = getQuery(event);
|
|
|
|
const tRpc = useTRPC();
|
|
|
|
const premiumData = await PremiumModel.findOne({ user_id })
|
|
if (!premiumData) throw createError({ status: 400, message: 'Cannot get premium data. Please contact support.' });
|
|
|
|
|
|
const preview = await tRpc.payments.subscription.createPreviewUpgrade.query({
|
|
user_id,
|
|
customer_id: premiumData.customer_id,
|
|
plan_tag: plan_tag as string
|
|
});
|
|
|
|
return preview;
|
|
|
|
}); |