-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from stephan-rz/development
Development
- Loading branch information
Showing
18 changed files
with
471 additions
and
69 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import LoadingModal from "@/components/modals/loading-modal" | ||
|
||
const Loading = () => { | ||
return ( | ||
<LoadingModal/> | ||
) | ||
} | ||
|
||
export default Loading |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { currentUser } from "@/lib/auth"; | ||
import { db } from "@/lib/db"; | ||
import { pusherServer } from "@/lib/pusher"; | ||
import { NextResponse } from "next/server"; | ||
|
||
interface IParams { | ||
conversationId?: string; | ||
} | ||
|
||
export async function DELETE( | ||
request: Request, | ||
{ params }: { params: IParams } | ||
) { | ||
const user = await currentUser(); | ||
|
||
if (!user) { | ||
return new NextResponse("Unauthorized", { status: 401 }); | ||
} | ||
|
||
try { | ||
const { conversationId } = params; | ||
|
||
const conversation = await db.conversation.findUnique({ | ||
where: { | ||
id: conversationId | ||
}, | ||
include: { | ||
users: true | ||
} | ||
}); | ||
|
||
if(!conversation) { | ||
return new NextResponse("Invalid ID", { status: 400 }); | ||
} | ||
|
||
await db.conversation.deleteMany({ | ||
where: { | ||
id: conversationId, | ||
userIds: { | ||
hasSome: [user?.id!] | ||
} | ||
} | ||
}); | ||
|
||
conversation.users.forEach((user) => { | ||
if (user.email) { | ||
pusherServer.trigger(user.email, 'conversation:remove', conversation) | ||
} | ||
}) | ||
|
||
return new NextResponse("Conversation deleted", { status: 200 }); | ||
|
||
} catch (error) { | ||
console.log(error, "ERROR_CONVERSATION_DELETE"); | ||
return new NextResponse("Internal server error", { status: 500 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.