|
@@ -32,32 +32,37 @@ const getListById = async (companionId, userId) => {
|
|
};
|
|
};
|
|
|
|
|
|
const getById = async (id, userId) => {
|
|
const getById = async (id, userId) => {
|
|
- const foundContact = await Message.findById({
|
|
|
|
|
|
+ const foundMessage = await Message.findById({
|
|
_id: id,
|
|
_id: id,
|
|
owner: userId,
|
|
owner: userId,
|
|
});
|
|
});
|
|
- return foundContact;
|
|
|
|
|
|
+ return foundMessage;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+const getLastMessagesList = async (userId) => {
|
|
|
|
+ const messages = await Message.find({ owner: userId });
|
|
|
|
+ return messages;
|
|
};
|
|
};
|
|
|
|
|
|
const getByField = async (number, userId) => {
|
|
const getByField = async (number, userId) => {
|
|
- const contact = await Message.findOne({
|
|
|
|
|
|
+ const message = await Message.findOne({
|
|
number,
|
|
number,
|
|
owner: userId,
|
|
owner: userId,
|
|
});
|
|
});
|
|
- return contact;
|
|
|
|
|
|
+ return message;
|
|
};
|
|
};
|
|
|
|
|
|
const add = async (obj) => {
|
|
const add = async (obj) => {
|
|
- const contact = await Message.create(obj);
|
|
|
|
- return contact;
|
|
|
|
|
|
+ const message = await Message.create(obj);
|
|
|
|
+ return message;
|
|
};
|
|
};
|
|
|
|
|
|
const remove = async (id, userId) => {
|
|
const remove = async (id, userId) => {
|
|
- const removedContact = await Message.findByIdAndRemove({
|
|
|
|
|
|
+ const removedMessage = await Message.findByIdAndRemove({
|
|
_id: id,
|
|
_id: id,
|
|
owner: userId,
|
|
owner: userId,
|
|
});
|
|
});
|
|
- return removedContact;
|
|
|
|
|
|
+ return removedMessage;
|
|
};
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
module.exports = {
|
|
@@ -65,6 +70,7 @@ module.exports = {
|
|
getListById,
|
|
getListById,
|
|
getByField,
|
|
getByField,
|
|
getById,
|
|
getById,
|
|
|
|
+ getLastMessagesList,
|
|
add,
|
|
add,
|
|
remove,
|
|
remove,
|
|
};
|
|
};
|