-
Notifications
You must be signed in to change notification settings - Fork 0
AUTH-9 - Implemented UserProject server actions #5
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| "use server"; | ||
| import { prisma } from "@/lib/prisma"; | ||
|
|
||
| async function createUserProject(userId: string, projectId: string) { | ||
| const existing = await prisma.userProject.findUnique({ where: { userId_projectId: { userId, projectId, deletedAt: null } }}); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if (existing) { | ||
| throw new Error("User project already exists"); | ||
| } | ||
| return await prisma.userProject.upsert({ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once the type error above is fixed, this |
||
| where: { userId_projectId: { userId, projectId } }, | ||
| update: {deletedAt: null}, | ||
| create: { userId, projectId } }); | ||
| } | ||
|
|
||
| async function getUserProject(userId: string, projectId: string) { | ||
| return await prisma.userProject.findUnique({ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also move inline, anything this short can be inline |
||
| where: { userId_projectId: { userId, projectId, deletedAt: null } } } | ||
| ); | ||
| } | ||
|
|
||
|
|
||
| async function getUserProjects({userId, projectId}: { userId?: string, projectId?: string }) { | ||
| return await prisma.userProject.findMany({ | ||
| where: { userId, projectId, deletedAt: null }, | ||
| }); | ||
| } | ||
|
|
||
| async function removeUserFromProject(userId: string, projectId: string) { | ||
| return await prisma.userProject.update({ | ||
| where: { userId_projectId: { userId, projectId, deletedAt: null } }, | ||
| data: { deletedAt: new Date() } | ||
| }); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed none of the four functions in this file are actually
exported yet, so as merged this is dead code and not reachable — which reads like this might genuinely be the "data layer first, action layer later" pattern. If that's the plan, just want to flag it explicitly: wheneverexportgets added here (which the PR title implies is coming), it'll need a caller-identity + authority check attached at the same time, sinceUserProjectis the authorization-scoping table for the whole system — an unauthenticated grant/revoke here is more consequential than on the other open PRs. Also worth scopinggetUserProjects(line 22) to the caller once it's exposed — an empty{}filter currently returns every membership across all projects.