Skip to content

Commit

Permalink
feat(api): restrict wallet creation based on entitlement
Browse files Browse the repository at this point in the history
  • Loading branch information
duongdev committed Sep 22, 2024
1 parent 3342e94 commit c001d2d
Showing 1 changed file with 7 additions and 2 deletions.
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

0 comments on commit c001d2d

Please sign in to comment.