Skip to content

Commit

Permalink
feat(api): restrict transaction 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 edd723f commit bc6edd4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion apps/api/v1/services/transaction.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getPlanConfig } from '@6pm/utilities'
import type { CreateTransaction, UpdateTransaction } from '@6pm/validation'
import type {
Budget,
Expand All @@ -14,6 +15,7 @@ import {
isUserBudgetOwner,
} from './budget.service'
import { getExchangeRate } from './exchange-rates.service'
import { getUserPlan } from './user.service'

const VND = 'VND'

Expand Down Expand Up @@ -43,7 +45,13 @@ export async function canUserCreateTransaction({
return false
}

return true
const userPlan = getUserPlan(user)
const maxTransactions = getPlanConfig(userPlan, 'maxTransactions')
const transactionCount = await prisma.transaction.count({
where: { createdByUserId: user.id },
})

return maxTransactions !== null && transactionCount < maxTransactions
}

export async function canUserReadTransaction({
Expand Down

0 comments on commit bc6edd4

Please sign in to comment.