feat(Saluer on matchNotification ): Saluer bring you to chat with the user

This commit is contained in:
Laurian-Dufrechou
2023-05-19 12:23:57 +02:00
parent 61df566dcf
commit 96da92a34f
3 changed files with 47 additions and 11 deletions
+26 -2
View File
@@ -3,7 +3,7 @@ const { PrismaClient } = require("@prisma/client");
const patch = async (req: any, res: any) => {
const prisma = new PrismaClient();
const { notificationId } = req.body;
const { notificationId, salute } = req.body;
try {
const notification = await prisma.notification.update({
@@ -15,7 +15,31 @@ const patch = async (req: any, res: any) => {
},
});
res.status(200).json(notification);
let chat = null;
if (!salute) {
res.status(200).json({
message: "notification has been consulted",
notification: notification,
});
} else {
chat = await prisma.chat.findFirst({
where: {
AND: [
{ User: { some: { id: notification.MatchedUserID } } },
{ User: { some: { id: notification.UserID } } },
],
},
include: {
User: true,
},
});
res.status(200).json({
message: "notification has been consulted",
notification: notification,
chat: chat,
});
}
} catch (error) {
res.status(400).json({ message: "Something went wrong" });
} finally {