Browse Source

finished search by date and request

unknown 3 years ago
parent
commit
e94e24efd0
2 changed files with 11 additions and 1 deletions
  1. 6 1
      controllers/chats.js
  2. 5 0
      model/schemas/chat.js

+ 6 - 1
controllers/chats.js

@@ -25,13 +25,14 @@ const startChat = async (req, res, next) => {
 		const companion = await UserModel.findById(id);
 		const isUser = await ChatModel.getByField(id, userId);
 		const isCompanion = await ChatModel.getByField(userId, id);
-		const { name, lastName, avatarUrl, color, online } = companion;
+		const { name, lastName, avatarUrl, color, online, number } = companion;
 		const {
 			name: Name,
 			lastName: LastName,
 			avatarUrl: AvatarUrl,
 			color: Color,
 			online: Online,
+			number: Number,
 		} = user;
 		if (companion && (isUser || isCompanion)) {
 			await ChatModel.update(isUser._id, {
@@ -40,6 +41,7 @@ const startChat = async (req, res, next) => {
 				avatarUrl,
 				color,
 				online,
+				number,
 			});
 			await ChatModel.update(isCompanion._id, {
 				name: Name,
@@ -47,6 +49,7 @@ const startChat = async (req, res, next) => {
 				avatarUrl: AvatarUrl,
 				color: Color,
 				online: Online,
+				number: Number,
 			});
 			const updatedChat = await ChatModel.getByField(id, userId);
 			return res.status(200).json({
@@ -63,6 +66,7 @@ const startChat = async (req, res, next) => {
 				avatarUrl,
 				color,
 				online,
+				number,
 				companionId: id,
 				owner: userId,
 			});
@@ -72,6 +76,7 @@ const startChat = async (req, res, next) => {
 				avatarUrl: AvatarUrl,
 				color: Color,
 				online: Online,
+				number: Number,
 				companionId: userId,
 				owner: id,
 			});

+ 5 - 0
model/schemas/chat.js

@@ -29,6 +29,11 @@ const chatSchema = new Schema(
 			type: String,
 			default: null,
 		},
+		number: {
+			type: String,
+			min: 8,
+			max: 14,
+		},
 		owner: {
 			type: SchemaTypes.ObjectId,
 			ref: 'user',