Skip to content

Commit

Permalink
Fix coupling prisma
Browse files Browse the repository at this point in the history
  • Loading branch information
yunusefendi52 committed Mar 31, 2024
1 parent ad92517 commit 8a23745
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 40 deletions.
10 changes: 4 additions & 6 deletions server/api/add-me-to-org.get.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import prisma from '@/server/db'

export default defineEventHandler(async (event) => {
const userId = event.context.auth.userId
const org = await prisma.organizations.findFirstOrThrow()
await prisma.organizationsPeople.create({
export default defineEventHandler(async ({ context }) => {
const userId = context.auth.userId
const org = await context.prisma.organizations.findFirstOrThrow()
await context.prisma.organizationsPeople.create({
data: {
organizationId: org.id,
userId: userId,
Expand Down
12 changes: 0 additions & 12 deletions server/api/apps.ts

This file was deleted.

2 changes: 1 addition & 1 deletion server/api/create-app.post.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import prisma from '@/server/db'
import _ from 'lodash'

export default defineEventHandler(async (event) => {
const userId = event.context.auth.userId
const prisma = event.context.prisma
const request = await readBody(event)
const userOrg = await prisma.organizations.findFirstOrThrow({
include: {
Expand Down
3 changes: 1 addition & 2 deletions server/api/create-org.post.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import prisma from '@/server/db'

export default defineEventHandler(async (event) => {
const userId = event.context.auth.userId
const prisma = event.context.prisma
const { name, displayName } = await readBody(event)
await prisma.$transaction(async (tx) => {
const org = await tx.organizations.create({
Expand Down
3 changes: 1 addition & 2 deletions server/api/create-user.get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import prisma from '@/server/db'

export default defineEventHandler(async (event) => {
const prisma = event.context.prisma
await prisma.user.create({
data: {
name: 'User 1'
Expand Down
3 changes: 1 addition & 2 deletions server/api/list-apps.get.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import prisma from '@/server/db'

export default defineEventHandler(async (event) => {
const userId = event.context.auth.userId
const prisma = event.context.prisma
const { search, orgName } = getQuery<ListAppsRequest>(event)
const userOrgs = await prisma.organizations.findMany({
include: {
Expand Down
3 changes: 1 addition & 2 deletions server/api/list-orgs.get.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import prisma from '@/server/db'

export default defineEventHandler(async (event) => {
const userId = event.context.auth.userId
const prisma = event.context.prisma
const orgs = await prisma.organizations.findMany({
where: {
OrganizationsPeople: {
Expand Down
13 changes: 0 additions & 13 deletions server/db.ts

This file was deleted.

12 changes: 12 additions & 0 deletions server/middleware/00.start.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { PrismaClient } from "@prisma/client";

declare module 'h3' {
interface H3EventContext {
prisma: PrismaClient;
}
}

export default defineEventHandler(async (event) => {
const prisma = new PrismaClient()
event.context.prisma = prisma
})

0 comments on commit 8a23745

Please sign in to comment.