mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 11:49:19 +00:00
Finished contact CRUD and frontend with websockets
This commit is contained in:
@@ -61,14 +61,18 @@ exports.store = async (req, res) => {
|
||||
exports.show = async (req, res) => {
|
||||
const { contactId } = req.params;
|
||||
|
||||
const { id, name, number, extraInfo } = await Contact.findByPk(contactId, {
|
||||
include: [{ model: ContactCustomField, as: "extraInfo" }],
|
||||
});
|
||||
const { id, name, number, email, extraInfo } = await Contact.findByPk(
|
||||
contactId,
|
||||
{
|
||||
include: [{ model: ContactCustomField, as: "extraInfo" }],
|
||||
}
|
||||
);
|
||||
|
||||
res.status(200).json({
|
||||
id,
|
||||
name,
|
||||
number,
|
||||
email,
|
||||
extraInfo,
|
||||
});
|
||||
};
|
||||
@@ -93,3 +97,23 @@ exports.update = async (req, res) => {
|
||||
|
||||
res.status(200).json(contact);
|
||||
};
|
||||
|
||||
exports.delete = async (req, res) => {
|
||||
const io = getIO();
|
||||
const { contactId } = req.params;
|
||||
|
||||
const contact = await Contact.findByPk(contactId);
|
||||
|
||||
if (!contact) {
|
||||
return res.status(400).json({ error: "No contact found with this ID" });
|
||||
}
|
||||
|
||||
await contact.destroy();
|
||||
|
||||
io.emit("contact", {
|
||||
action: "delete",
|
||||
contactId: contactId,
|
||||
});
|
||||
|
||||
res.status(200).json({ message: "Contact deleted" });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user