Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): restrict wallet creation based on entitlement #363

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions apps/api/v1/services/wallet.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { getPlanConfig } from '@6pm/utilities'
import type { CreateWallet, UpdateWallet } from '@6pm/validation'
import type { User, UserWalletAccount } from '@prisma/client'
import prisma from '../../lib/prisma'
import { DEFAULT_WALLETS } from '../constants/wallet.const'
import { getUserPlan } from './user.service'

export async function findUserWallet({
user,
Expand Down Expand Up @@ -75,9 +77,12 @@ export async function getWalletBalance({
return balance._sum.amountInVnd || 0
}

// biome-ignore lint/correctness/noUnusedVariables: <explanation>
export async function canUserCreateWallet({ user }: { user: User }) {
return true
const wallets = await findUserWallets({ user })
const userPlan = getUserPlan(user)
const maxWallets = getPlanConfig(userPlan, 'maxWallets')

return maxWallets !== null && wallets.length < maxWallets
}

export async function canUserUpdateWallet({
Expand Down
Loading