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); await DeleteWhatsAppService(whatsappId);
removeDir(path.join(process.cwd(),'WWebJS', `session-bd_${whatsappId}`)) removeDir(path.join(process.cwd(),'.wwebjs_auth', `session-bd_${whatsappId}`))
removeWbot(+whatsappId); removeWbot(+whatsappId);

View File

@ -1,16 +1,77 @@
import AppError from "../errors/AppError"; import AppError from "../errors/AppError";
import Whatsapp from "../models/Whatsapp"; import Whatsapp from "../models/Whatsapp";
const GetDefaultWhatsApp = async (): Promise<Whatsapp> => { import WhatsappQueue from "../models/WhatsappQueue"
const defaultWhatsapp = await Whatsapp.findOne({ import UserQueue from "../models/UserQueue"
const GetDefaultWhatsApp = async (userId?: string | number ): Promise<Whatsapp> => {
// test del
let defaultWhatsapp = await Whatsapp.findOne({
where: { isDefault: true } 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) { if (!defaultWhatsapp) {
throw new AppError("ERR_NO_DEF_WAPP_FOUND"); throw new AppError("ERR_NO_DEF_WAPP_FOUND");
} }
return defaultWhatsapp; 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; export default GetDefaultWhatsApp;

View File

@ -1,8 +1,16 @@
import ShowQueueService from "./ShowQueueService"; import ShowQueueService from "./ShowQueueService";
import UserQueue from "../../models/UserQueue";
const DeleteQueueService = async (queueId: number | string): Promise<void> => { const DeleteQueueService = async (queueId: number | string): Promise<void> => {
const queue = await ShowQueueService(queueId); 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(); await queue.destroy();
}; };

View File

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

View File

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

View File

@ -1,15 +1,25 @@
import Whatsapp from "../../models/Whatsapp"; import Whatsapp from "../../models/Whatsapp";
import AppError from "../../errors/AppError"; import AppError from "../../errors/AppError";
import WhatsappQueue from "../../models/WhatsappQueue";
const DeleteWhatsAppService = async (id: string): Promise<void> => { const DeleteWhatsAppService = async (id: string): Promise<void> => {
const whatsapp = await Whatsapp.findOne({ const whatsapp = await Whatsapp.findOne({
where: { id } where: { id }
}); });
if (!whatsapp) { if (!whatsapp) {
throw new AppError("ERR_NO_WAPP_FOUND", 404); 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(); await whatsapp.destroy();
}; };

View File

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

View File

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