mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 19:59:20 +00:00
all routes changed to typescript
This commit is contained in:
@@ -109,7 +109,8 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||
}
|
||||
|
||||
const ticket: Ticket = await defaultWhatsapp.$create("ticket", req.body);
|
||||
const contact = await ticket.$get("contact");
|
||||
|
||||
await ticket.$get("contact");
|
||||
|
||||
const wapp = await ticket.$get("whatsapp");
|
||||
|
||||
@@ -122,7 +123,7 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||
// ticket: serializaedTicket
|
||||
// });
|
||||
|
||||
return res.status(200).json({ ticket, contact, wapp, tickets });
|
||||
return res.status(200).json({ ticket });
|
||||
};
|
||||
|
||||
// export const update = (req: Request, res: Response): Promise<Response> => {
|
||||
|
||||
136
backend/src/controllers/WhatsAppController.ts
Normal file
136
backend/src/controllers/WhatsAppController.ts
Normal file
@@ -0,0 +1,136 @@
|
||||
import { Request, Response } from "express";
|
||||
import CreateWhatsAppService from "../services/WhatsappService/CreateWhatsAppService";
|
||||
// import Yup from "yup";
|
||||
// import Whatsapp from "../models/Whatsapp";
|
||||
// import { getIO } from "../libs/socket";
|
||||
// import { getWbot, initWbot, removeWbot } from "../libs/wbot";
|
||||
// import wbotMessageListener from "../services/wbotMessageListener";
|
||||
// import wbotMonitor from "../services/wbotMonitor";
|
||||
|
||||
import ListWhatsAppsService from "../services/WhatsappService/ListWhatsAppsService";
|
||||
|
||||
export const index = async (req: Request, res: Response): Promise<Response> => {
|
||||
const whatsapps = await ListWhatsAppsService();
|
||||
|
||||
return res.status(200).json(whatsapps);
|
||||
};
|
||||
|
||||
interface WhatsappData {
|
||||
name: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||
// const io = getIO();
|
||||
|
||||
console.log("aqui");
|
||||
|
||||
const { name, status }: WhatsappData = req.body;
|
||||
|
||||
const whatsapp = await CreateWhatsAppService({ name, status });
|
||||
|
||||
// if (!whatsapp) {
|
||||
// return res.status(400).json({ error: "Cannot create whatsapp session." });
|
||||
// }
|
||||
|
||||
// initWbot(whatsapp)
|
||||
// .then(() => {
|
||||
// wbotMessageListener(whatsapp);
|
||||
// wbotMonitor(whatsapp);
|
||||
// })
|
||||
// .catch(err => console.log(err));
|
||||
|
||||
// io.emit("whatsapp", {
|
||||
// action: "update",
|
||||
// whatsapp: whatsapp
|
||||
// });
|
||||
|
||||
return res.status(200).json(whatsapp);
|
||||
};
|
||||
|
||||
// export const show = async (req: Request, res: Response): Promise<Response> => {
|
||||
// const { whatsappId } = req.params;
|
||||
// const whatsapp = await Whatsapp.findByPk(whatsappId);
|
||||
|
||||
// if (!whatsapp) {
|
||||
// return res.status(200).json({ message: "Session not found" });
|
||||
// }
|
||||
|
||||
// return res.status(200).json(whatsapp);
|
||||
// };
|
||||
|
||||
// export const update = async (
|
||||
// req: Request,
|
||||
// res: Response
|
||||
// ): Promise<Response> => {
|
||||
// const { whatsappId } = req.params;
|
||||
|
||||
// const schema = Yup.object().shape({
|
||||
// name: Yup.string().required().min(2),
|
||||
// default: Yup.boolean()
|
||||
// .required()
|
||||
// .test(
|
||||
// "Check-default",
|
||||
// "Only one default whatsapp is permited",
|
||||
// async value => {
|
||||
// if (value === true) {
|
||||
// const whatsappFound = await Whatsapp.findOne({
|
||||
// where: { default: true }
|
||||
// });
|
||||
// if (whatsappFound) {
|
||||
// return !(whatsappFound.id !== +whatsappId);
|
||||
// } else {
|
||||
// return true;
|
||||
// }
|
||||
// } else return true;
|
||||
// }
|
||||
// )
|
||||
// });
|
||||
|
||||
// try {
|
||||
// await schema.validate(req.body);
|
||||
// } catch (err) {
|
||||
// return res.status(400).json({ error: err.message });
|
||||
// }
|
||||
|
||||
// const io = getIO();
|
||||
|
||||
// const whatsapp = await Whatsapp.findByPk(whatsappId);
|
||||
|
||||
// if (!whatsapp) {
|
||||
// return res.status(404).json({ message: "Whatsapp not found" });
|
||||
// }
|
||||
|
||||
// await whatsapp.update(req.body);
|
||||
|
||||
// io.emit("whatsapp", {
|
||||
// action: "update",
|
||||
// whatsapp: whatsapp
|
||||
// });
|
||||
|
||||
// return res.status(200).json({ message: "Whatsapp updated" });
|
||||
// };
|
||||
|
||||
// export const remove = async (
|
||||
// req: Request,
|
||||
// res: Response
|
||||
// ): Promise<Response> => {
|
||||
// const io = getIO();
|
||||
// const { whatsappId } = req.params;
|
||||
|
||||
// const whatsapp = await Whatsapp.findByPk(whatsappId);
|
||||
|
||||
// if (!whatsapp) {
|
||||
// return res.status(404).json({ message: "Whatsapp not found" });
|
||||
// }
|
||||
|
||||
// await whatsapp.destroy();
|
||||
// removeWbot(whatsapp.id);
|
||||
|
||||
// io.emit("whatsapp", {
|
||||
// action: "delete",
|
||||
// whatsappId: whatsapp.id
|
||||
// });
|
||||
|
||||
// return res.status(200).json({ message: "Whatsapp deleted." });
|
||||
// };
|
||||
Reference in New Issue
Block a user