Skip to content

Commit

Permalink
fix: removed ts ingore from route.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Sama-004 committed Sep 18, 2024
1 parent a6e1eb1 commit 9f3e460
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 105 deletions.
Binary file modified bun.lockb
Binary file not shown.
4 changes: 4 additions & 0 deletions db/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ const prisma = globalThis.prismaGlobal ?? prismaClientSingleton();

export default prisma;

export type PrismaTransactionalClient = Parameters<
Parameters<PrismaClient['$transaction']>[0]
>[0];

if (process.env.NODE_ENV !== 'production') globalThis.prismaGlobal = prisma;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"build": "next build",
"vercel-build": "npx prisma generate && next build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"type-check":"tsc --noEmit --watch"
},
"dependencies": {
"@next-auth/prisma-adapter": "^1.0.7",
Expand Down
1 change: 0 additions & 1 deletion src/app/api/room/[roomId]/leave/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-nocheck
import { getServerSession } from 'next-auth';
import { authOptions } from '../../../../../../lib/auth';
import prisma from '../../../../../../db/db';
Expand Down
12 changes: 0 additions & 12 deletions src/app/api/room/[roomId]/notifications/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-nocheck
import prisma from '../../../../../../db/db';
import { NextResponse } from 'next/server';

Expand All @@ -12,17 +11,6 @@ export async function GET(
const room = await prisma.room.findUnique({
where: { id: roomId },
include: { notifications: { orderBy: { createdAt: 'desc' } } },
// include: {
// notifications: {
// select: {
// id: true,
// message: true,
// createdAt: true,
// color: true,
// },
// orderBy: { createdAt: "desc" },
// },
// },
});

if (!room) {
Expand Down
1 change: 0 additions & 1 deletion src/app/api/room/[roomId]/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-nocheck
import { NextResponse } from 'next/server';
import { authOptions } from '../../../../../lib/auth';
import { getServerSession } from 'next-auth';
Expand Down
67 changes: 34 additions & 33 deletions src/app/api/room/create/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @ts-nocheck
import { NextResponse } from 'next/server';
import prisma from '../../../../../db/db';
import prisma, { PrismaTransactionalClient } from '../../../../../db/db';
import { getServerSession } from 'next-auth';
import { authOptions } from '../../../../../lib/auth';
import { GenerateRoomCode } from '../../../../../lib/roomCode';
Expand All @@ -21,42 +20,44 @@ export async function POST(req: Request, res: Response) {

const roomCode: string = await GenerateRoomCode();

const newRoom = await prisma.$transaction(async (prisma) => {
const newRoom = await prisma.room.create({
data: {
name: roomName,
code: roomCode,
creator: {
connect: { id: session.user.id },
},
participants: {
create: {
user: {
connect: { id: session.user.id },
const newRoom = await prisma.$transaction(
async (prisma: PrismaTransactionalClient) => {
const newRoom = await prisma.room.create({
data: {
name: roomName,
code: roomCode,
creator: {
connect: { id: session.user.id },
},
participants: {
create: {
user: {
connect: { id: session.user.id },
},
},
},
},
},
include: {
creator: true,
participants: {
include: {
user: true,
include: {
creator: true,
participants: {
include: {
user: true,
},
},
},
},
});
await prisma.notification.create({
data: {
roomId: newRoom.id,
message: `${
session.user.leetCodeUsername || 'A new user'
} created the room ${roomName}`,
color: 'blue',
},
});
return newRoom;
});
});
await prisma.notification.create({
data: {
roomId: newRoom.id,
message: `${
session.user.leetCodeUsername || 'A new user'
} created the room ${roomName}`,
color: 'blue',
},
});
return newRoom;
},
);

return NextResponse.json(newRoom, { status: 200 });
} catch (err) {
Expand Down
55 changes: 28 additions & 27 deletions src/app/api/room/invite/[invitecode]/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// @ts-nocheck
import { getServerSession } from 'next-auth';
import { authOptions } from '../../../../../../lib/auth';
import { NextResponse } from 'next/server';
import prisma from '../../../../../../db/db';
import prisma, { PrismaTransactionalClient } from '../../../../../../db/db';

export async function GET(
req: Request,
Expand Down Expand Up @@ -49,37 +48,39 @@ export async function GET(
);
}

const updatedRoom = await prisma.$transaction(async (prisma) => {
const updatedRoom = await prisma.room.update({
where: { id: room.id },
data: {
participants: {
create: {
userId: session.user.id,
const updatedRoom = await prisma.$transaction(
async (prisma: PrismaTransactionalClient) => {
const updatedRoom = await prisma.room.update({
where: { id: room.id },
data: {
participants: {
create: {
userId: session.user.id,
},
},
},
},
include: {
participants: {
include: {
user: true,
include: {
participants: {
include: {
user: true,
},
},
},
},
});
});

await prisma.notification.create({
data: {
roomId: room.id,
message: `${
session.user.leetCodeUsername || 'A new user'
} joined the room`,
color: 'join',
},
});
await prisma.notification.create({
data: {
roomId: room.id,
message: `${
session.user.leetCodeUsername || 'A new user'
} joined the room`,
color: 'join',
},
});

return updatedRoom;
});
return updatedRoom;
},
);

return NextResponse.json(
{ message: 'Room joined successfully', roomId: room.id, success: true },
Expand Down
55 changes: 28 additions & 27 deletions src/app/api/room/join/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// @ts-nocheck
import { NextResponse } from 'next/server';
import { authOptions } from '../../../../../lib/auth';
import { getServerSession } from 'next-auth';
import prisma from '../../../../../db/db';
import prisma, { PrismaTransactionalClient } from '../../../../../db/db';

export async function POST(req: Request, res: Response) {
const session = await getServerSession(authOptions);
Expand Down Expand Up @@ -38,36 +37,38 @@ export async function POST(req: Request, res: Response) {
);
}

const updatedRoom = await prisma.$transaction(async (prisma) => {
const updatedRoom = await prisma.room.update({
where: { id: room.id },
data: {
participants: {
create: {
userId: session.user.id,
const updatedRoom = await prisma.$transaction(
async (prisma: PrismaTransactionalClient) => {
const updatedRoom = await prisma.room.update({
where: { id: room.id },
data: {
participants: {
create: {
userId: session.user.id,
},
},
},
},
include: {
participants: {
include: {
user: true,
include: {
participants: {
include: {
user: true,
},
},
},
},
});
});

await prisma.notification.create({
data: {
roomId: room.id,
color: 'join',
message: `${
session.user.leetCodeUsername || 'A new user'
} joined the room`,
},
});
return updatedRoom;
});
await prisma.notification.create({
data: {
roomId: room.id,
color: 'join',
message: `${
session.user.leetCodeUsername || 'A new user'
} joined the room`,
},
});
return updatedRoom;
},
);

return NextResponse.json(updatedRoom, { status: 200 });
} catch (err) {
Expand Down
1 change: 0 additions & 1 deletion src/app/api/room/joined/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-nocheck
import { getServerSession } from 'next-auth';
import { authOptions } from '../../../../../lib/auth';
import { NextResponse } from 'next/server';
Expand Down
1 change: 0 additions & 1 deletion src/app/api/verify/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-nocheck
import axios from 'axios';
import prisma from '../../../../db/db';
import { NextResponse } from 'next/server';
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
Expand Down

0 comments on commit 9f3e460

Please sign in to comment.