mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 20:59:16 +00:00
change 'default' to 'isDefault' whatsapp field on frontend
This commit is contained in:
@@ -12,18 +12,18 @@ import UpdateWhatsAppService from "../services/WhatsappService/UpdateWhatsAppSer
|
|||||||
// import wbotMessageListener from "../services/wbotMessageListener";
|
// import wbotMessageListener from "../services/wbotMessageListener";
|
||||||
// import wbotMonitor from "../services/wbotMonitor";
|
// import wbotMonitor from "../services/wbotMonitor";
|
||||||
|
|
||||||
export const index = async (req: Request, res: Response): Promise<Response> => {
|
|
||||||
const whatsapps = await ListWhatsAppsService();
|
|
||||||
|
|
||||||
return res.status(200).json(whatsapps);
|
|
||||||
};
|
|
||||||
|
|
||||||
interface WhatsappData {
|
interface WhatsappData {
|
||||||
name: string;
|
name: string;
|
||||||
status?: string;
|
status?: string;
|
||||||
isDefault?: boolean;
|
isDefault?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const index = async (req: Request, res: Response): Promise<Response> => {
|
||||||
|
const whatsapps = await ListWhatsAppsService();
|
||||||
|
|
||||||
|
return res.status(200).json(whatsapps);
|
||||||
|
};
|
||||||
|
|
||||||
export const store = async (req: Request, res: Response): Promise<Response> => {
|
export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||||
// const io = getIO();
|
// const io = getIO();
|
||||||
|
|
||||||
@@ -53,7 +53,9 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
|||||||
export const show = async (req: Request, res: Response): Promise<Response> => {
|
export const show = async (req: Request, res: Response): Promise<Response> => {
|
||||||
const { whatsappId } = req.params;
|
const { whatsappId } = req.params;
|
||||||
|
|
||||||
const whatsapp = await FindWhatsAppService({ where: { id: +whatsappId } });
|
console.log(whatsappId);
|
||||||
|
|
||||||
|
const whatsapp = await FindWhatsAppService(whatsappId);
|
||||||
|
|
||||||
return res.status(200).json(whatsapp);
|
return res.status(200).json(whatsapp);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,24 +1,10 @@
|
|||||||
import Whatsapp from "../../models/Whatsapp";
|
import Whatsapp from "../../models/Whatsapp";
|
||||||
import AppError from "../../errors/AppError";
|
import AppError from "../../errors/AppError";
|
||||||
|
|
||||||
interface WhereParams {
|
const FindWhatsAppService = async (
|
||||||
id?: number;
|
id: string | number
|
||||||
name?: string;
|
): Promise<Whatsapp | undefined> => {
|
||||||
isDefault?: boolean;
|
const whatsapp = await Whatsapp.findByPk(id);
|
||||||
}
|
|
||||||
|
|
||||||
interface Request {
|
|
||||||
where?: WhereParams;
|
|
||||||
}
|
|
||||||
|
|
||||||
const FindWhatsAppService = async ({
|
|
||||||
where
|
|
||||||
}: Request): Promise<Whatsapp | undefined> => {
|
|
||||||
const whereCondition = { ...where };
|
|
||||||
|
|
||||||
const whatsapp = await Whatsapp.findOne({
|
|
||||||
where: whereCondition
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!whatsapp) {
|
if (!whatsapp) {
|
||||||
throw new AppError("No whatsapp found with this conditions.", 404);
|
throw new AppError("No whatsapp found with this conditions.", 404);
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
import Whatsapp from "../../models/Whatsapp";
|
import Whatsapp from "../../models/Whatsapp";
|
||||||
|
|
||||||
interface Response {
|
const ListWhatsAppsService = async (): Promise<Whatsapp[]> => {
|
||||||
whatsapps: Whatsapp[];
|
|
||||||
}
|
|
||||||
|
|
||||||
const ListWhatsAppsService = async (): Promise<Response> => {
|
|
||||||
const whatsapps = await Whatsapp.findAll();
|
const whatsapps = await Whatsapp.findAll();
|
||||||
|
|
||||||
return { whatsapps };
|
return whatsapps;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ListWhatsAppsService;
|
export default ListWhatsAppsService;
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ const WhatsAppModal = ({ open, onClose, whatsAppId }) => {
|
|||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const initialState = {
|
const initialState = {
|
||||||
name: "",
|
name: "",
|
||||||
default: false,
|
isDefault: false,
|
||||||
};
|
};
|
||||||
const [whatsApp, setWhatsApp] = useState(initialState);
|
const [whatsApp, setWhatsApp] = useState(initialState);
|
||||||
|
|
||||||
|
|||||||
@@ -111,31 +111,31 @@ const Connections = () => {
|
|||||||
fetchSession();
|
fetchSession();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
// useEffect(() => {
|
||||||
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
// const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
||||||
|
|
||||||
socket.on("whatsapp", data => {
|
// socket.on("whatsapp", data => {
|
||||||
if (data.action === "update") {
|
// if (data.action === "update") {
|
||||||
dispatch({ type: "UPDATE_WHATSAPPS", payload: data.whatsapp });
|
// dispatch({ type: "UPDATE_WHATSAPPS", payload: data.whatsapp });
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
socket.on("whatsapp", data => {
|
// socket.on("whatsapp", data => {
|
||||||
if (data.action === "delete") {
|
// if (data.action === "delete") {
|
||||||
dispatch({ type: "DELETE_WHATSAPPS", payload: data.whatsappId });
|
// dispatch({ type: "DELETE_WHATSAPPS", payload: data.whatsappId });
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
socket.on("whatsappSession", data => {
|
// socket.on("whatsappSession", data => {
|
||||||
if (data.action === "update") {
|
// if (data.action === "update") {
|
||||||
dispatch({ type: "UPDATE_SESSION", payload: data.session });
|
// dispatch({ type: "UPDATE_SESSION", payload: data.session });
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
return () => {
|
// return () => {
|
||||||
socket.disconnect();
|
// socket.disconnect();
|
||||||
};
|
// };
|
||||||
}, []);
|
// }, []);
|
||||||
|
|
||||||
// const handleDisconnectSession = async whatsAppId => {
|
// const handleDisconnectSession = async whatsAppId => {
|
||||||
// try {
|
// try {
|
||||||
@@ -199,13 +199,13 @@ const Connections = () => {
|
|||||||
>
|
>
|
||||||
Are you sure? It cannot be reverted.
|
Are you sure? It cannot be reverted.
|
||||||
</ConfirmationModal>
|
</ConfirmationModal>
|
||||||
<QrcodeModal
|
{/* <QrcodeModal
|
||||||
open={qrModalOpen}
|
open={qrModalOpen}
|
||||||
onClose={handleCloseQrModal}
|
onClose={handleCloseQrModal}
|
||||||
whatsAppId={
|
whatsAppId={
|
||||||
selectedWhatsApp && !whatsAppModalOpen && selectedWhatsApp.id
|
selectedWhatsApp && !whatsAppModalOpen && selectedWhatsApp.id
|
||||||
}
|
}
|
||||||
/>
|
/> */}
|
||||||
<WhatsAppModal
|
<WhatsAppModal
|
||||||
open={whatsAppModalOpen}
|
open={whatsAppModalOpen}
|
||||||
onClose={handleCloseWhatsAppModal}
|
onClose={handleCloseWhatsAppModal}
|
||||||
|
|||||||
Reference in New Issue
Block a user