Skip to content

Commit

Permalink
feat: allow 3 projects for free users
Browse files Browse the repository at this point in the history
  • Loading branch information
vincelwt committed Mar 12, 2024
1 parent 377a261 commit 0293ae7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
9 changes: 0 additions & 9 deletions e2e/projects.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import { test, expect } from "@playwright/test"
import { setOrgFree, setOrgPro } from "./db-utils"

test.beforeAll(async () => {
// need to be pro for multiple projects
await setOrgPro()
})

test.afterAll(async () => {
await setOrgFree()
})

test("create new project, rename it and delete it", async ({ page }) => {
await page.goto("/")

Expand Down
8 changes: 5 additions & 3 deletions packages/backend/src/api/v1/projects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ projects.post("/", async (ctx: Context) => {
})
const { name } = bodySchema.parse(ctx.request.body)

const [org] = await sql`select * from org where id = ${orgId}`
const [{ plan }] = await sql`select plan from org where id = ${orgId}`
const [{ count }] =
await sql`select count(*)::int from project where org_id = ${orgId}`

if (org.plan === "free") {
ctx.throw(403, "You can't create more than 1 project under the free plan.")
if (plan === "free" && count >= 3) {
ctx.throw(403, "You can't create more than 3 project under the free plan.")
}

const newProject = {
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/components/Layout/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default function Sidebar() {
]

async function createProject() {
if (org.plan === "free" && projects.length >= 1) {
if (org.plan === "free" && projects.length >= 3) {
return openUpgrade("projects")
}

Expand Down

0 comments on commit 0293ae7

Please sign in to comment.