@@ -3,7 +3,6 @@ import { authOptions } from "app/lib/auth";
33import { getServerSession } from "next-auth" ;
44//? https://github.com/code100x/cms/blob/main/src/app/api/admin/content/route.ts
55import { NextRequest , NextResponse } from "next/server" ;
6- import { AiOutlineConsoleSql } from "react-icons/ai" ;
76
87const prisma = new PrismaClient ( ) ;
98
@@ -66,54 +65,38 @@ export const POST = async (req: NextRequest) => {
6665 const tweet = await prisma . tweet . create ( {
6766 data : { content, userID : userId } ,
6867 } ) ;
68+ // router.push("")
6969 console . log ( "This is the response" , tweet ) ;
70+
7071 return NextResponse . json ( tweet , { status : 201 } ) ;
7172 } catch ( error ) {
7273 console . log ( "Getting error in Creating" , error ) ;
7374 }
7475} ;
75- interface RouteContext {
76- params : {
77- id : string ;
78- } ;
79- }
80- // export const DELETE = async (
81- // req: NextRequest,
82- // params: { param: { id: string } }
83- // ) => {
84- // console.log(params.param.id);
85-
86- // try {
87- // console.log("Hitting the Delete");
88- // const tweetId = Number(params.param.id);
89- // const deleteTweet = await prisma.tweet.delete({
90- // where: {
91- // id: tweetId,
92- // },
93- // });
94- // console.log("Deleting the Tweet", deleteTweet);
95- // return NextResponse.json({ mess: "Done with Delete", status: 200 });
96- // } catch (error) {
97- // console.log("Getting this error while deleting", error);
98- // return NextResponse.json(
99- // { error: "Failed to delete tweet" },
100- // { status: 500 }
101- // );
102- // }
103- // };
10476
10577export async function DELETE ( req : NextRequest ) {
10678 try {
107- console . log ( "Hitting the delete" ) ;
79+ const session = await getServerSession ( authOptions ) ;
80+ if ( ! session ?. user ?. id ) {
81+ return NextResponse . json (
82+ { error : "Unauthorized - User not authenticated" } ,
83+ { status : 401 }
84+ ) ;
85+ }
86+ const userDel = session ?. user ?. id ;
10887 const id = req . nextUrl . searchParams . get ( "id" ) ;
10988 if ( ! id ) {
11089 return NextResponse . json (
11190 { message : "Todi ID is required" } ,
11291 { status : 400 }
11392 ) ;
11493 }
115- const deleteTweet = await prisma . tweet . delete ( {
116- where : { id : Number ( id ) } ,
94+ const tweetId = Number ( id ) ;
95+ const deleteTweet = await prisma . tweet . update ( {
96+ where : { id : tweetId , userID : userDel } ,
97+ data : {
98+ IsDelete : true ,
99+ } ,
117100 } ) ;
118101 if ( ! deleteTweet ) {
119102 return NextResponse . json ( { message : "Tweet not found" } , { status : 404 } ) ;
0 commit comments