chore: remove MVP positioning and align plan defaults

This commit is contained in:
sirily
2026-03-10 14:58:01 +03:00
parent ba029d8f3f
commit bec00d2c9b
11 changed files with 73 additions and 26 deletions

View File

@@ -4,7 +4,7 @@ Database package for `nproxy`.
## Implemented in this iteration
- Prisma package scaffold
- Initial Prisma schema for MVP persisted state
- Current Prisma schema for persisted state
- Shared schema path export for runtime tooling
## Current scope

View File

@@ -73,7 +73,7 @@ export function createPrismaAuthStore(database: PrismaClient = defaultPrisma) {
return database.$transaction(async (transaction) => {
const defaultPlan = await transaction.subscriptionPlan.findFirst({
where: {
code: "mvp_monthly",
code: "monthly",
isActive: true,
},
});

View File

@@ -10,8 +10,8 @@ export interface SubscriptionPlanSeedInput {
}
export const defaultSubscriptionPlanSeed: SubscriptionPlanSeedInput = {
code: "mvp_monthly",
displayName: "MVP Monthly",
code: "monthly",
displayName: "Monthly",
monthlyRequestLimit: 100,
monthlyPriceUsd: 9.99,
billingCurrency: "USDT",
@@ -21,6 +21,8 @@ export async function ensureSubscriptionPlan(
input: SubscriptionPlanSeedInput,
database: PrismaClient = defaultPrisma,
): Promise<void> {
await reconcileDefaultSubscriptionPlan(input, database);
await database.subscriptionPlan.upsert({
where: {
code: input.code,
@@ -48,3 +50,47 @@ export async function ensureDefaultSubscriptionPlan(
): Promise<void> {
await ensureSubscriptionPlan(defaultSubscriptionPlanSeed, database);
}
async function reconcileDefaultSubscriptionPlan(
input: SubscriptionPlanSeedInput,
database: PrismaClient,
): Promise<void> {
const existing = await database.subscriptionPlan.findUnique({
where: {
code: input.code,
},
select: {
id: true,
},
});
if (existing) {
return;
}
const candidate = await database.subscriptionPlan.findFirst({
where: {
monthlyRequestLimit: input.monthlyRequestLimit,
monthlyPriceUsd: new Prisma.Decimal(input.monthlyPriceUsd),
billingCurrency: input.billingCurrency,
},
orderBy: {
createdAt: "asc",
},
});
if (!candidate) {
return;
}
await database.subscriptionPlan.update({
where: {
id: candidate.id,
},
data: {
code: input.code,
displayName: input.displayName,
isActive: true,
},
});
}