From edd723fb690f54a0ce99ae06b6fa28608e06d8bc Mon Sep 17 00:00:00 2001 From: Dustin Do Date: Sun, 22 Sep 2024 10:54:59 +0700 Subject: [PATCH] feat(api): restrict category creation based on entitlement --- apps/api/v1/services/category.service.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/api/v1/services/category.service.ts b/apps/api/v1/services/category.service.ts index be346a61..23f25718 100644 --- a/apps/api/v1/services/category.service.ts +++ b/apps/api/v1/services/category.service.ts @@ -1,3 +1,4 @@ +import { getPlanConfig } from '@6pm/utilities' import type { CreateCategory, UpdateCategory } from '@6pm/validation' import { type Category, CategoryType, type User } from '@prisma/client' import prisma from '../../lib/prisma' @@ -5,12 +6,15 @@ import { DEFAULT_EXPENSE_CATEGORIES, DEFAULT_INCOME_CATEGORIES, } from '../constants/category.const' +import { getUserPlan } from './user.service' export async function canUserCreateCategory({ - // biome-ignore lint/correctness/noUnusedVariables: user, }: { user: User }): Promise { - return true + const userPlan = getUserPlan(user) + const canCreateCategories = getPlanConfig(userPlan, 'canCreateCategories') + + return canCreateCategories === true } // biome-ignore lint/correctness/noEmptyPattern: