Codificaçao do recurso opcional de finalização de atendimento e inclução do status de encerramento de atendimento

pull/1/head
adriano 2022-05-19 18:29:38 -03:00
parent 70245a9904
commit a3be6063c4
9 changed files with 519 additions and 454 deletions

View File

@ -8,6 +8,7 @@ import ShowTicketService from "../services/TicketServices/ShowTicketService";
import UpdateTicketService from "../services/TicketServices/UpdateTicketService"; import UpdateTicketService from "../services/TicketServices/UpdateTicketService";
import SendWhatsAppMessage from "../services/WbotServices/SendWhatsAppMessage"; import SendWhatsAppMessage from "../services/WbotServices/SendWhatsAppMessage";
import ShowWhatsAppService from "../services/WhatsappService/ShowWhatsAppService"; import ShowWhatsAppService from "../services/WhatsappService/ShowWhatsAppService";
import ShowStatusChatEndService from '../services/StatusChatEndService/ShowStatusChatEndService'
import CreateSchedulingNotifyService from "../services/SchedulingNotifyServices/CreateSchedulingNotifyService"; import CreateSchedulingNotifyService from "../services/SchedulingNotifyServices/CreateSchedulingNotifyService";
import ListSchedulingNotifyContactService from "../services/SchedulingNotifyServices/ListSchedulingNotifyContactService"; import ListSchedulingNotifyContactService from "../services/SchedulingNotifyServices/ListSchedulingNotifyContactService";
@ -154,15 +155,22 @@ export const update = async ( req: Request, res: Response ): Promise<Response> =
const { status, userId, schedulingNotifyData } = req.body; const { status, userId, schedulingNotifyData } = req.body;
// lembrete
const scheduleData = JSON.parse(schedulingNotifyData)
const statusChatEndName = await ShowStatusChatEndService(scheduleData.statusChatEndId)
const { ticket } = await UpdateTicketService({ const { ticket } = await UpdateTicketService({
ticketData:{'status': status, 'userId': userId}, ticketData: { 'status': status, 'userId': userId, 'statusChatEnd': statusChatEndName.name },
ticketId ticketId
}); });
/////////////////////////////// ///////////////////////////////
console.log('------- scheduleData.farewellMessage: ', scheduleData.farewellMessage)
if (scheduleData.farewellMessage) {
const whatsapp = await ShowWhatsAppService(ticket.whatsappId); const whatsapp = await ShowWhatsAppService(ticket.whatsappId);
const { farewellMessage } = whatsapp; const { farewellMessage } = whatsapp;
@ -170,12 +178,11 @@ export const update = async ( req: Request, res: Response ): Promise<Response> =
if (farewellMessage) { if (farewellMessage) {
await SendWhatsAppMessage({ body: farewellMessage, ticket }); await SendWhatsAppMessage({ body: farewellMessage, ticket });
} }
}
/////////////////////////////// ///////////////////////////////
// lembrete
const scheduleData = JSON.parse(schedulingNotifyData)
// lembrete // agendamento // lembrete // agendamento
if (scheduleData.statusChatEndId === '2' || scheduleData.statusChatEndId === '3') { if (scheduleData.statusChatEndId === '2' || scheduleData.statusChatEndId === '3') {

View File

@ -0,0 +1,15 @@
import { QueryInterface, DataTypes } from "sequelize";
module.exports = {
up: (queryInterface: QueryInterface) => {
return queryInterface.addColumn("Tickets", "statusChatEnd", {
type: DataTypes.STRING,
allowNull: true,
defaultValue: ''
});
},
down: (queryInterface: QueryInterface) => {
return queryInterface.removeColumn("Tickets", "statusChatEnd");
}
};

View File

@ -10,7 +10,8 @@ import {
HasMany, HasMany,
HasOne, HasOne,
AutoIncrement, AutoIncrement,
Default Default,
DataType
} from "sequelize-typescript"; } from "sequelize-typescript";
import Contact from "./Contact"; import Contact from "./Contact";
@ -41,6 +42,9 @@ class Ticket extends Model<Ticket> {
@Column @Column
isGroup: boolean; isGroup: boolean;
@Column
statusChatEnd: string;
@CreatedAt @CreatedAt
createdAt: Date; createdAt: Date;

View File

@ -60,7 +60,7 @@ const ShowMessageReport = async (id: string | number, startDate: string, endDate
where: where_clause_user, where: where_clause_user,
required:true, required:true,
attributes: ['id', 'status'], attributes: ['id', 'status', 'statusChatEnd'],
include: [ include: [
{ {

View File

@ -0,0 +1,14 @@
import StatusChatEnd from "../../models/StatusChatEnd";
import AppError from "../../errors/AppError";
const ShowStatusChatEndService = async (id: string | number): Promise<StatusChatEnd> => {
const status = await StatusChatEnd.findByPk(id, { attributes: ['id', 'name'], });
if (!status) {
throw new AppError("ERR_NO_STATUS_FOUND", 404);
}
return status;
};
export default ShowStatusChatEndService;

View File

@ -47,7 +47,7 @@ const ShowTicketReport = async (id: string | number, startDate: string, endDate:
where: where_clause , where: where_clause ,
//attributes: ['id', 'status', 'createdAt', 'updatedAt'], //attributes: ['id', 'status', 'createdAt', 'updatedAt'],
attributes: ['id', 'status', [Sequelize.fn("DATE_FORMAT",Sequelize.col("Ticket.createdAt"),"%d/%m/%Y %H:%i:%s"),"createdAt"], attributes: ['id', 'status', 'statusChatEnd', [Sequelize.fn("DATE_FORMAT",Sequelize.col("Ticket.createdAt"),"%d/%m/%Y %H:%i:%s"),"createdAt"],
[Sequelize.fn("DATE_FORMAT",Sequelize.col("Ticket.updatedAt"),"%d/%m/%Y %H:%i:%s"),"updatedAt"]], [Sequelize.fn("DATE_FORMAT",Sequelize.col("Ticket.updatedAt"),"%d/%m/%Y %H:%i:%s"),"updatedAt"]],
include: [ include: [

View File

@ -10,6 +10,7 @@ interface TicketData {
status?: string; status?: string;
userId?: number; userId?: number;
queueId?: number; queueId?: number;
statusChatEnd?: string
} }
interface Request { interface Request {
@ -27,7 +28,7 @@ const UpdateTicketService = async ({
ticketData, ticketData,
ticketId ticketId
}: Request): Promise<Response> => { }: Request): Promise<Response> => {
const { status, userId, queueId } = ticketData; const { status, userId, queueId, statusChatEnd } = ticketData;
const ticket = await ShowTicketService(ticketId); const ticket = await ShowTicketService(ticketId);
await SetTicketMessagesAsRead(ticket); await SetTicketMessagesAsRead(ticket);
@ -42,7 +43,8 @@ const UpdateTicketService = async ({
await ticket.update({ await ticket.update({
status, status,
queueId, queueId,
userId userId,
statusChatEnd
}); });

View File

@ -17,7 +17,8 @@ import { subHours, addDays, subDays} from "date-fns";
import TextFieldSelectHourBefore from '@mui/material/TextField'; import TextFieldSelectHourBefore from '@mui/material/TextField';
import MenuItem from '@mui/material/MenuItem'; import MenuItem from '@mui/material/MenuItem';
import Checkbox from '@mui/material/Checkbox';
import FormControlLabel from "@mui/material/FormControlLabel";
import api from "../../../services/api"; import api from "../../../services/api";
import toastError from "../../../errors/toastError"; import toastError from "../../../errors/toastError";
@ -108,6 +109,8 @@ const Modal = (props) => {
const [currencyHourBefore, setCurrency] = useState(null); const [currencyHourBefore, setCurrency] = useState(null);
const [currenciesTimeBefore, setCurrenciesTimeBefore] = useState(null); const [currenciesTimeBefore, setCurrenciesTimeBefore] = useState(null);
const [checked, setChecked] = useState(false);
const handleCancel = (event, reason) => { const handleCancel = (event, reason) => {
@ -197,7 +200,7 @@ const timerPickerValue = (data) => {
const handleChatEnd = (event, reason) => { const handleChatEnd = (event, reason) => {
let dataSendServer = {'statusChatEndId': statusChatEndId} let dataSendServer = { 'statusChatEndId': statusChatEndId, 'farewellMessage':checked }
if (reason && reason === "backdropClick") if (reason && reason === "backdropClick")
return; return;
@ -251,8 +254,7 @@ const timerPickerValue = (data) => {
let sendMessageDayBefore = currenciesTimeBefore.filter(i => i.label.indexOf('24 HORAS ANTES DO HORÁRIO DO AGENDAMENTO') >= 0); let sendMessageDayBefore = currenciesTimeBefore.filter(i => i.label.indexOf('24 HORAS ANTES DO HORÁRIO DO AGENDAMENTO') >= 0);
if(sendMessageDayBefore.length > 0 && timeBefore === formatedTimeHour(timerPicker)) if (sendMessageDayBefore.length > 0 && timeBefore === formatedTimeHour(timerPicker)) {
{
console.log('ENVIAR MENSAGEM UM DIA ANTES!') console.log('ENVIAR MENSAGEM UM DIA ANTES!')
console.log('MENSAGEM SERÁ ENVIA NO DIA: ', dateCurrentFormated(new Date(subDays(new Date(startDate + ' ' + formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:00`))), 1)))) console.log('MENSAGEM SERÁ ENVIA NO DIA: ', dateCurrentFormated(new Date(subDays(new Date(startDate + ' ' + formatedTimeHour(new Date(`${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:00`))), 1))))
@ -333,8 +335,10 @@ const timerPickerValue = (data) => {
console.log('******** another day TIMER: ', formatedTimeHour(subHours(timer, hour))) console.log('******** another day TIMER: ', formatedTimeHour(subHours(timer, hour)))
hours.push( hours.push(
{value: formatedTimeHour(subHours(timer,hour)), {
label: `${hour} HORA ANTES DO HORÁRIO DO AGENDAMENTO`}) value: formatedTimeHour(subHours(timer, hour)),
label: `${hour} HORA ANTES DO HORÁRIO DO AGENDAMENTO`
})
hour++; hour++;
} }
@ -402,6 +406,13 @@ const handleChange = (event) => {
}; };
const handleCheckBoxChange = (event) => {
//console.log('event.target.checked: ', event.target.checked)
setChecked(event.target.checked);
};
const handleChangeHourBefore = (event) => { const handleChangeHourBefore = (event) => {
@ -570,6 +581,12 @@ const handleChangeHourBefore = (event) => {
<DialogActions> <DialogActions>
<div>
<FormControlLabel
control={<Checkbox checked={checked} onChange={handleCheckBoxChange} />}
label="Mensagem de encerramento de atendimento"
/>
</div>
<div style={{ marginRight: '50px' }}> <div style={{ marginRight: '50px' }}>
<Button onClick={handleCancel}>Cancelar</Button> <Button onClick={handleCancel}>Cancelar</Button>
</div> </div>

View File

@ -74,7 +74,13 @@ let columns = [
{ {
key: 'ticket.status', key: 'ticket.status',
label: 'Status', label: 'Status',
}] },
{
key: 'ticket.statusChatEnd',
label: 'Status de encerramento',
}
]
// //
@ -290,12 +296,12 @@ let columnsData = [
{ title: 'Contato', field: 'contact.number' }, { title: 'Contato', field: 'contact.number' },
{ title: 'Nome', field: 'contact.name' }, { title: 'Nome', field: 'contact.name' },
{ title: 'Assunto', field: 'queue.name' }, { title: 'Assunto', field: 'queue.name' },
{ title: 'Status', field: 'status' },
{ title: 'Criado', field: 'createdAt' },
{
title: 'Atualizado', field: 'updatedAt',
}]; { title: 'Status', field: 'status' },
{ title: 'Criado', field: 'createdAt' },
//{title: 'Atualizado', field: 'updatedAt'},
{title: 'Status de encerramento', field: 'statusChatEnd'}];
const Report = () => { const Report = () => {