mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 19:59:20 +00:00
Finished Contact Drawer styles and func
This commit is contained in:
@@ -48,8 +48,9 @@ exports.index = async (req, res, next) => {
|
||||
include: [
|
||||
{
|
||||
model: Contact,
|
||||
as: "contact",
|
||||
include: "extraInfo",
|
||||
attributes: ["name", "number", "profilePicUrl"],
|
||||
attributes: ["id", "name", "number", "profilePicUrl"],
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -81,7 +82,6 @@ exports.index = async (req, res, next) => {
|
||||
return res.json({
|
||||
messages: serializedMessages.reverse(),
|
||||
ticket: ticket,
|
||||
contact: ticket.Contact,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -98,6 +98,7 @@ exports.store = async (req, res, next) => {
|
||||
include: [
|
||||
{
|
||||
model: Contact,
|
||||
as: "contact",
|
||||
attributes: ["number"],
|
||||
},
|
||||
],
|
||||
@@ -113,12 +114,12 @@ exports.store = async (req, res, next) => {
|
||||
}
|
||||
|
||||
sentMessage = await wbot.sendMessage(
|
||||
`${ticket.Contact.number}@c.us`,
|
||||
`${ticket.contact.number}@c.us`,
|
||||
newMedia
|
||||
);
|
||||
} else {
|
||||
sentMessage = await wbot.sendMessage(
|
||||
`${ticket.Contact.number}@c.us`,
|
||||
`${ticket.contact.number}@c.us`,
|
||||
message.body
|
||||
);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ exports.index = async (req, res) => {
|
||||
include: [
|
||||
{
|
||||
model: Contact,
|
||||
as: "contact",
|
||||
attributes: ["name", "number", "profilePicUrl"],
|
||||
},
|
||||
],
|
||||
@@ -60,6 +61,7 @@ exports.update = async (req, res) => {
|
||||
include: [
|
||||
{
|
||||
model: Contact,
|
||||
as: "contact",
|
||||
attributes: ["name", "number", "profilePicUrl"],
|
||||
},
|
||||
],
|
||||
|
||||
@@ -18,7 +18,7 @@ class Contact extends Sequelize.Model {
|
||||
}
|
||||
|
||||
static associate(models) {
|
||||
this.hasMany(models.Ticket, { foreignKey: "contactId" });
|
||||
this.hasMany(models.Ticket, { foreignKey: "contactId", as: "contact" });
|
||||
this.hasMany(models.ContactCustomField, {
|
||||
foreignKey: "contactId",
|
||||
as: "extraInfo",
|
||||
|
||||
@@ -5,6 +5,7 @@ class Ticket extends Sequelize.Model {
|
||||
super.init(
|
||||
{
|
||||
status: { type: Sequelize.STRING, defaultValue: "pending" },
|
||||
userId: { type: Sequelize.INTEGER, defaultValue: null },
|
||||
lastMessage: { type: Sequelize.STRING },
|
||||
},
|
||||
{
|
||||
@@ -16,7 +17,7 @@ class Ticket extends Sequelize.Model {
|
||||
}
|
||||
|
||||
static associate(models) {
|
||||
this.belongsTo(models.Contact, { foreignKey: "contactId" });
|
||||
this.belongsTo(models.Contact, { foreignKey: "contactId", as: "contact" });
|
||||
this.belongsTo(models.User, { foreignKey: "userId" });
|
||||
this.hasMany(models.Message, { foreignKey: "ticketId" });
|
||||
}
|
||||
|
||||
@@ -28,22 +28,16 @@ const verifyContact = async (msgContact, profilePicUrl) => {
|
||||
};
|
||||
|
||||
const verifyTicket = async contact => {
|
||||
let ticket = await Ticket.findOne({
|
||||
const [ticket, created] = await Ticket.findOrCreate({
|
||||
where: {
|
||||
status: {
|
||||
[Op.or]: ["open", "pending"],
|
||||
},
|
||||
contactId: contact.id,
|
||||
},
|
||||
defaults: { contactId: contact.id, status: "pending" },
|
||||
});
|
||||
|
||||
if (!ticket) {
|
||||
ticket = await Ticket.create({
|
||||
contactId: contact.id,
|
||||
status: "pending",
|
||||
});
|
||||
}
|
||||
|
||||
return ticket;
|
||||
};
|
||||
|
||||
@@ -127,6 +121,7 @@ const wbotMessageListener = () => {
|
||||
...ticket.dataValues,
|
||||
unreadMessages: 1,
|
||||
lastMessage: newMessage.body,
|
||||
contact: contact,
|
||||
};
|
||||
|
||||
io.to(ticket.id).to("notification").emit("appMessage", {
|
||||
|
||||
Reference in New Issue
Block a user