Browse Source

finished right lists on credentials

unknown 2 years ago
parent
commit
4c8cb56b2b
4 changed files with 28 additions and 1 deletions
  1. 22 0
      controllers/chats.js
  2. 4 0
      model/schemas/chat.js
  3. 1 0
      routes/chats.js
  4. 1 1
      routes/contacts.js

+ 22 - 0
controllers/chats.js

@@ -149,6 +149,25 @@ const muteChat = async (req, res, next) => {
 	}
 };
 
+const sortChat = async (req, res, next) => {
+	try {
+		const id = req.body.id;
+		const userId = req.user.id;
+		const isChat = await ChatModel.getByField(id, userId);
+		if (isChat) {
+			const { _id, sort } = isChat;
+			await ChatModel.update(_id, { sort: !sort });
+			return res.status(200).json({
+				status: 'success',
+				code: 200,
+				data: {},
+			});
+		}
+	} catch (e) {
+		next(e);
+	}
+};
+
 const seenChat = async (req, res, next) => {
 	try {
 		const id = req.body.id;
@@ -202,6 +221,7 @@ const chatById = async (req, res, next) => {
 				avatarUrl,
 				color,
 				mute,
+				sort,
 				seen,
 				total,
 				watched,
@@ -224,6 +244,7 @@ const chatById = async (req, res, next) => {
 					color,
 					online,
 					mute,
+					sort,
 					seen,
 					total,
 					watched,
@@ -247,6 +268,7 @@ module.exports = {
 	listChats,
 	startChat,
 	muteChat,
+	sortChat,
 	seenChat,
 	typingChat,
 	chatById,

+ 4 - 0
model/schemas/chat.js

@@ -38,6 +38,10 @@ const chatSchema = new Schema(
 			type: Number,
 			default: 0,
 		},
+		sort: {
+			type: Boolean,
+			default: false,
+		},
 		total: {
 			type: Number,
 			default: 0,

+ 1 - 0
routes/chats.js

@@ -9,6 +9,7 @@ router
 	.get('/:companionId', guard, controllers.chatById)
 	.post('/', guard, validation.startChat, controllers.startChat)
 	.patch('/mute/', guard, controllers.muteChat)
+	.patch('/sort/', guard, controllers.sortChat)
 	.patch('/seen/', guard, controllers.seenChat)
 	.patch('/typing/', guard, validation.typingChat, controllers.typingChat);
 

+ 1 - 1
routes/contacts.js

@@ -10,6 +10,6 @@ router
 
 router
 	.get('/:number', guard, controllers.getContactById)
-	.delete('/:number', guard, controllers.removeContact);
+	.delete('/:id', guard, controllers.removeContact);
 
 module.exports = router;