@@ -6,6 +6,7 @@ import { NextRequest, NextResponse } from "next/server";
66
77const prisma = new PrismaClient ( ) ;
88
9+ //? GET Tweet
910export async function GET ( ) {
1011 const session = await getServerSession ( authOptions ) ;
1112 if ( ! session ) {
@@ -31,13 +32,10 @@ export async function GET() {
3132 return NextResponse . json ( { userId : session . user . id } ) ;
3233}
3334
35+ //? POST Tweet
3436export const POST = async ( req : NextRequest ) => {
3537 try {
3638 const session = await getServerSession ( authOptions ) ;
37- // console.log("Reaching in Post");
38- // console.log(session, "This is the user");
39- // console.log(session?.user.id, "This is the userID");
40- // console.log(session?.user, "This is the userID");
4139
4240 if ( ! session ?. user ?. id ) {
4341 return NextResponse . json (
@@ -74,10 +72,11 @@ export const POST = async (req: NextRequest) => {
7472 }
7573} ;
7674
75+ //? DELETE Tweet
7776export async function DELETE ( req : NextRequest ) {
78- try {
77+ try {
7978 const session = await getServerSession ( authOptions ) ;
80-
79+
8180 if ( ! session ?. user ?. id ) {
8281 return NextResponse . json (
8382 { error : "Unauthorized - User not authenticated" } ,
@@ -96,23 +95,20 @@ export async function DELETE(req: NextRequest) {
9695 where : { id : Number ( id ) } ,
9796 } ) ;
9897 if ( ! tweet ) {
99- return NextResponse . json (
100- { message : "Tweet not found" } ,
101- { status : 404 }
102- ) ;
98+ return NextResponse . json ( { message : "Tweet not found" } , { status : 404 } ) ;
10399 }
104100 if ( tweet . userID !== Number ( userDel ) ) {
105- return NextResponse . json ( { message :"Unauthorized" } )
101+ return NextResponse . json ( { message : "Unauthorized" } ) ;
106102 }
107103 const tweetId = Number ( id ) ;
108104 const deleteTweet = await prisma . tweet . update ( {
109- where : { id : tweetId } ,
105+ where : { id : tweetId } ,
110106 data : {
111107 IsDelete : true ,
112108 } ,
113109 } ) ;
114110 console . log ( "This is the response" , deleteTweet ) ;
115-
111+
116112 return NextResponse . json ( { message : "Done with delete" } , { status : 200 } ) ;
117113 } catch ( error ) {
118114 console . log ( "Getting error in Delete" , error ) ;
0 commit comments