unknown il y a 2 ans
Parent
commit
bf75964b48

BIN
audios/626a71920508b6301021da2e/1651243184audio.mp3


+ 29 - 14
controllers/messages.js

@@ -30,7 +30,7 @@ const removeMessage = async (req, res, next) => {
 		const DIR_VIDEOS = process.env.DIR_VIDEOS;
 		const DIR_FILES = process.env.DIR_FILES;
 		const userMessage = await MessageModel.remove(id, userId);
-		const companionMessage = await MessageModel.removeByFields(
+		await MessageModel.removeByFields(
 			userId,
 			userMessage.idTime,
 			userMessage.companionId
@@ -51,19 +51,34 @@ const removeMessage = async (req, res, next) => {
 					break;
 			}
 		}
-		if (userMessage && companionMessage) {
-			return res.json({
-				status: 'success',
-				code: 200,
-				data: {},
-			});
-		} else {
-			return res.status(404).json({
-				status: 'error',
-				code: 404,
-				data: 'Not Found',
-			});
-		}
+		const isChat = await ChatModel.getByField(userMessage.companionId, userId);
+		const isCompanionChat = await ChatModel.getByField(
+			userId,
+			userMessage.companionId
+		);
+		const { total } = await MessageModel.getList(
+			{ owner: userId, companionId: userMessage.companionId },
+			{}
+		);
+		const { total: Total } = await MessageModel.getList(
+			{ owner: userMessage.companionId, companionId: userId },
+			{}
+		);
+		await ChatModel.update(isChat._id, userId, {
+			total: total,
+			seen: total - isChat.seen > 0 ? isChat.seen : total,
+			watched: false,
+		});
+		await ChatModel.update(isCompanionChat._id, userMessage.companionId, {
+			total: Total,
+			seen: Total - isCompanionChat.seen > 0 ? isCompanionChat.seen : Total,
+			watched: true,
+		});
+		return res.json({
+			status: 'success',
+			code: 200,
+			data: {},
+		});
 	} catch (e) {
 		next(e);
 	}

BIN
images/626a45efcd8b494250448c59/1651142863we.jpg


BIN
images/626a71260508b6301021da29/1651146180we.jpg


images/626a714b0508b6301021da2a/1651144010id.jpg → images/626a71260508b6301021da29/1651239454id.jpg


images/626a71260508b6301021da29/1651145643download(1).png → images/626a71260508b6301021da29/1651241502download(2).png


BIN
images/626a714b0508b6301021da2a/1651241118monkey.png


BIN
videos/626a71920508b6301021da2e/1651243188video.mp4