First github Commit

This commit is contained in:
canove
2020-06-18 17:25:43 -03:00
parent 48ee6385d3
commit 8a6324a98b
19 changed files with 391 additions and 210 deletions

View File

@@ -3,12 +3,23 @@ const Message = require("../models/Message");
const Sequelize = require("sequelize");
exports.getContacts = async (req, res) => {
const { searchParam } = req.query;
const lowerSerachParam = searchParam.toLowerCase();
const whereCondition = {
name: Sequelize.where(
Sequelize.fn("LOWER", Sequelize.col("name")),
"LIKE",
"%" + lowerSerachParam + "%"
),
};
//todo >> add contact number to search where condition
try {
const contacts = await Contact.findAll({
include: {
model: Message,
attributes: [],
},
where: whereCondition,
attributes: {
include: [
[
@@ -25,7 +36,7 @@ exports.getContacts = async (req, res) => {
],
],
},
order: [[Message, "createdAt", "DESC"]],
order: [["updatedAt", "DESC"]],
});
return res.json(contacts);