Alteração na opção de whatsapp default para que essa opção seja escolhida pelo usuário adicionando à alguma fila e conexão de whastapp existente ou seja escolhida a conexão que esta com status CONNECTED

pull/1/head
adriano 2022-04-17 18:02:15 -03:00
parent 85cf4863d6
commit 7baed2a7da
8 changed files with 172 additions and 37 deletions

View File

@ -120,7 +120,7 @@ export const remove = async (
await DeleteWhatsAppService(whatsappId);
removeDir(path.join(process.cwd(),'WWebJS', `session-bd_${whatsappId}`))
removeDir(path.join(process.cwd(),'.wwebjs_auth', `session-bd_${whatsappId}`))
removeWbot(+whatsappId);

View File

@ -1,16 +1,77 @@
import AppError from "../errors/AppError";
import Whatsapp from "../models/Whatsapp";
const GetDefaultWhatsApp = async (): Promise<Whatsapp> => {
const defaultWhatsapp = await Whatsapp.findOne({
import WhatsappQueue from "../models/WhatsappQueue"
import UserQueue from "../models/UserQueue"
const GetDefaultWhatsApp = async (userId?: string | number ): Promise<Whatsapp> => {
// test del
let defaultWhatsapp = await Whatsapp.findOne({
where: { isDefault: true }
});
if (!defaultWhatsapp) {
try{
if(userId){
const queue = await UserQueue.findOne(
{
where: { userId: userId },
raw:true,
attributes: ['queueId']
});
console.log('+++++++++++++++ queueId: ',queue?.queueId, ' | userId: ', userId)
const whatsapp = await WhatsappQueue.findOne(
{
where: { queueId: `${queue?.queueId }`},
raw:true,
attributes: ['whatsappId']
});
console.log('+++++++++++++++ whatsappId1: ',whatsapp?.whatsappId)
defaultWhatsapp = await Whatsapp.findOne({
where: { id: `${whatsapp?.whatsappId}` }
});
}
else{
defaultWhatsapp = await Whatsapp.findOne({
where: { status: 'CONNECTED' }
});
}
}catch(err){
console.log('There was an error on select a whatsapp id by user queue: ', err)
}
}
if (!defaultWhatsapp) {
throw new AppError("ERR_NO_DEF_WAPP_FOUND");
}
return defaultWhatsapp;
//
// const defaultWhatsapp = await Whatsapp.findOne({
// where: { isDefault: true }
// });
// if (!defaultWhatsapp) {
// throw new AppError("ERR_NO_DEF_WAPP_FOUND");
// }
// return defaultWhatsapp;
};
export default GetDefaultWhatsApp;

View File

@ -1,8 +1,16 @@
import ShowQueueService from "./ShowQueueService";
import UserQueue from "../../models/UserQueue";
const DeleteQueueService = async (queueId: number | string): Promise<void> => {
const queue = await ShowQueueService(queueId);
try {
await UserQueue.destroy({ where: {queueId: queueId } });
} catch (error) {
console.log('Error on delete UserQueue by queueId: ',queueId)
}
await queue.destroy();
};

View File

@ -15,7 +15,7 @@ const CreateTicketService = async ({
status,
userId
}: Request): Promise<Ticket> => {
const defaultWhatsapp = await GetDefaultWhatsApp();
const defaultWhatsapp = await GetDefaultWhatsApp(userId);
await CheckContactOpenTickets(contactId);

View File

@ -14,6 +14,7 @@ import moment from 'moment';
import { startOfDay, endOfDay, parseISO, getDate} from "date-fns";
import { string } from "yup/lib/locale";
import Whatsapp from "../../models/Whatsapp";
//Report by user, startDate, endDate
const ShowTicketReport = async (id: string | number, startDate: string, endDate: string): Promise<Ticket[]> => {
@ -75,7 +76,10 @@ const ShowTicketReport = async (id: string | number, startDate: string, endDate:
model: Queue,
attributes: ['name']
},
{
model: Whatsapp,
attributes: ['name']
},
],
});

View File

@ -1,6 +1,8 @@
import Whatsapp from "../../models/Whatsapp";
import AppError from "../../errors/AppError";
import WhatsappQueue from "../../models/WhatsappQueue";
const DeleteWhatsAppService = async (id: string): Promise<void> => {
const whatsapp = await Whatsapp.findOne({
where: { id }
@ -10,6 +12,14 @@ const DeleteWhatsAppService = async (id: string): Promise<void> => {
throw new AppError("ERR_NO_WAPP_FOUND", 404);
}
//test del
try {
await WhatsappQueue.destroy({ where: {whatsappId: id } });
} catch (error) {
console.log('Error on delete WhatsappQueue by whatsapp id: ',id)
}
//
await whatsapp.destroy();
};

View File

@ -106,8 +106,10 @@ Item.propTypes = {
let columnsData = [
{ title: 'Whatsapp', field: 'whatsapp.name' },
{ title: 'Atendente', field: 'user.name' },
{ title: 'Contato', field: 'contact.number' },
{ title: 'Nome', field: 'contact.name' },
{ title: 'Assunto', field: 'queue.name' },
{ title: 'Status', field: 'status' },
{ title: 'Criado', field: 'createdAt' },
@ -219,6 +221,8 @@ const Report = () => {
//setLoading(false);
console.log('dataQuery: ', dataQuery.data)
} catch (err) {
console.log(err);
}

View File

@ -16,6 +16,8 @@ import toastError from "../../errors/toastError";
import { AuthContext } from "../../context/Auth/AuthContext";
import { Can } from "../../components/Can";
import Button from "@material-ui/core/Button";
const useStyles = makeStyles(theme => ({
root: {
display: "flex",
@ -95,6 +97,13 @@ const Settings = () => {
return value;
};
// const handleEdit = () => {
// console.log('Editar....')
// }
return (
@ -102,37 +111,76 @@ const Settings = () => {
role={user.profile}
perform="settings-view:show"
yes={() => (
<div className={classes.root}>
<Container className={classes.container} maxWidth="sm">
<Typography variant="body2" gutterBottom>
{i18n.t("settings.title")}
</Typography>
<Paper className={classes.paper}>
<Typography variant="body1">
{i18n.t("settings.settings.userCreation.name")}
</Typography>
<Select
margin="dense"
variant="outlined"
native
id="userCreation-setting"
name="userCreation"
value={
settings && settings.length > 0 && getSettingValue("userCreation")
}
className={classes.settingOption}
onChange={handleChangeSetting}
>
<option value="enabled">
{i18n.t("settings.settings.userCreation.options.enabled")}
</option>
<option value="disabled">
{i18n.t("settings.settings.userCreation.options.disabled")}
</option>
</Select>
</Paper>
</Container>
</div>
<div>
<div className={classes.root}>
<Container className={classes.container} maxWidth="sm">
<Typography variant="body2" gutterBottom>
{i18n.t("settings.title")}
</Typography>
<Paper className={classes.paper}>
<Typography variant="body1">
{i18n.t("settings.settings.userCreation.name")}
</Typography>
<Select
margin="dense"
variant="outlined"
native
id="userCreation-setting"
name="userCreation"
value={
settings && settings.length > 0 && getSettingValue("userCreation")
}
className={classes.settingOption}
onChange={handleChangeSetting}
>
<option value="enabled">
{i18n.t("settings.settings.userCreation.options.enabled")}
</option>
<option value="disabled">
{i18n.t("settings.settings.userCreation.options.disabled")}
</option>
</Select>
</Paper>
</Container>
</div>
{/* <div className={classes.root}>
<Container className={classes.container} maxWidth="sm">
<Typography variant="body2" gutterBottom>
Application name
</Typography>
<Paper className={classes.paper}>
<Typography variant="body1">
Estudio Face
</Typography>
<Button
margin="dense"
variant="outlined"
id="applicationName-setting"
name="applicationName"
color="primary"
onClick={(e) => handleEdit()}
className={classes.settingOption}
>
{"EDIT"}
</Button>
</Paper>
</Container>
</div> */}
</div>
)}
/>