Codificão e adaptação basica para salvar agendamento no backend completado

pull/1/head
adriano 2022-02-28 15:17:36 -03:00
parent d0918ac2a3
commit d8a00b6bce
6 changed files with 143 additions and 93 deletions

View File

@ -1,38 +0,0 @@
import { Request, Response } from "express";
// import { getIO } from "../libs/socket";
import CreateSchedulingNotifyService from "../services/SchedulingNotifyServices/CreateSchedulingNotifyService";
interface SchedulingNotifyData {
schedulingId: number | string;
ticketId: number | string;
cpf_cnpj: string;
schedulingDate: string;
reminder: string;
message: string;
status: string;
}
export const store = async (req: Request, res: Response): Promise<Response> => {
const { schedulingId, ticketId, cpf_cnpj, schedulingDate, reminder, message, status}: SchedulingNotifyData = req.body;
const schedulingNotify = await CreateSchedulingNotifyService({
schedulingId,
ticketId,
cpf_cnpj,
schedulingDate,
reminder,
message,
status
}
)
// const io = getIO();
// io.to(ticket.status).emit("ticket", {
// action: "update",
// ticket
// });
return res.status(200).json(schedulingNotify);
};

View File

@ -9,6 +9,7 @@ import UpdateTicketService from "../services/TicketServices/UpdateTicketService"
import SendWhatsAppMessage from "../services/WbotServices/SendWhatsAppMessage";
import ShowWhatsAppService from "../services/WhatsappService/ShowWhatsAppService";
import CreateSchedulingNotifyService from "../services/SchedulingNotifyServices/CreateSchedulingNotifyService";
@ -93,21 +94,29 @@ export const show = async (req: Request, res: Response): Promise<Response> => {
return res.status(200).json({contact, schedules});
};
export const update = async ( req: Request, res: Response ): Promise<Response> => {
const { ticketId } = req.params;
const ticketData: TicketData = req.body;
let ticket2 = {}
// const { contactId, status, queueId, userId, schedulingNotify} = req.body
if(req.body['status'] === "closed"){
const {status, userId, schedulingNotifyData} = req.body;
const { ticket } = await UpdateTicketService({
ticketData,
ticketData:{'status': status, 'userId': userId},
ticketId
});
if (ticket.status === "closed") {
///////////////////////////////
const whatsapp = await ShowWhatsAppService(ticket.whatsappId);
const { farewellMessage } = whatsapp;
@ -115,11 +124,72 @@ export const update = async ( req: Request, res: Response): Promise<Response> =>
if (farewellMessage) {
await SendWhatsAppMessage({ body: farewellMessage, ticket });
}
///////////////////////////////
// agendamento
const scheduleData = JSON.parse(schedulingNotifyData)
const schedulingNotifyCreate = await CreateSchedulingNotifyService(
{
ticketId: scheduleData.ticketId,
scheduleId: scheduleData.scheduleId,
cpf_cnpj: scheduleData.cpf_cnpj,
schedulingDate: scheduleData.schedulingDate,
reminder: scheduleData.reminder,
message: scheduleData.message,
status: '',
}
)
ticket2 = ticket
}
else{
const ticketData: TicketData = req.body;
const { ticket } = await UpdateTicketService({
ticketData,
ticketId
});
ticket2 = ticket
}
return res.status(200).json(ticket);
return res.status(200).json(ticket2);
};
// export const update = async (
// req: Request,
// res: Response
// ): Promise<Response> => {
// const { ticketId } = req.params;
// const ticketData: TicketData = req.body;
// const { ticket } = await UpdateTicketService({
// ticketData,
// ticketId
// });
// if (ticket.status === "closed") {
// const whatsapp = await ShowWhatsAppService(ticket.whatsappId);
// const { farewellMessage } = whatsapp;
// if (farewellMessage) {
// await SendWhatsAppMessage({ body: farewellMessage, ticket });
// }
// }
// return res.status(200).json(ticket);
// };
export const remove = async (
req: Request,
res: Response

View File

@ -9,7 +9,7 @@ module.exports = {
primaryKey: true,
allowNull: false
},
schedulingId: {
scheduleId: {
type: DataTypes.INTEGER,
references: { model: "Schedules", key: "id" },
onUpdate: "CASCADE",

View File

@ -1,9 +1,10 @@
import AppError from "../../errors/AppError";
import SchedulingNotify from "../../models/SchedulingNotify";
interface Request {
schedulingId: number | string,
ticketId: number | string,
ticketId: string,
scheduleId: string,
cpf_cnpj: string,
schedulingDate: string,
reminder: string,
@ -11,29 +12,30 @@ interface Request {
status: string
}
const CreateSchedulingNotifyService = async ({
schedulingId,
const CreateSchedulingNotifyService = async (
{
ticketId,
scheduleId,
cpf_cnpj,
schedulingDate,
reminder,
message,
status
}: Request): Promise<SchedulingNotify> => {
const schedulingNotify = await SchedulingNotify.create(
{
schedulingId,
ticketId,
scheduleId,
cpf_cnpj,
schedulingDate,
reminder,
message,
status
}
)
})
return schedulingNotify
}

View File

@ -58,7 +58,7 @@ Item.propTypes = {
const Modal = (props) => {
const [open, setOpen] = useState(true);
const [scroll, /*setScroll*/] = useState('body');
const [schedulingId, setScheduling] = useState(null)
const [scheduleId, setScheduling] = useState(null)
const [startDate, setDatePicker] = useState(new Date())
const [timerPicker, setTimerPicker] = useState(new Date())
const [textArea1, setTextArea1] = useState()
@ -85,7 +85,7 @@ const Modal = (props) => {
setChatEnd({
'schedulingId': schedulingId,
'scheduleId': scheduleId,
'cpf_cnpj': textFieldCpfCnpj,
'schedulingDate': `${startDate} ${timerPicker.getHours()}:${timerPicker.getMinutes()}:${timerPicker.getSeconds()}`,
'reminder': textArea1,

View File

@ -49,9 +49,11 @@ const TicketActionButtons = ({ ticket, schedule }) => {
if(data){
data = {...data, 'ticketId': ticket.id}
console.log('ChatEnd: ',(data));
// handleUpdateTicketStatus(e, "closed", user?.id)
handleUpdateTicketStatus(null, "closed", user?.id, data)
}
@ -59,39 +61,53 @@ const TicketActionButtons = ({ ticket, schedule }) => {
}
const handleModal = (e, status, userId) => {
const handleModal = (status, userId) => {
render(<Modal
modal_header={'Finalização de Atendimento'}
func={chatEndVal}
schedules={schedule}
status={status}
userId={userId}
ticketId={ticket.id}/>)
/>)
};
const handleUpdateTicketStatus = async (e, status, userId) => {
const handleUpdateTicketStatus = async (e, status, userId, schedulingData={}) => {
// Thuanny
// render(<Modal
// modal_header={'Finalização de Atendimento'}
// func={chatEndVal} schedules={schedule}
// e={e}
// status={status}
// userId={userId}/>)
// let schedulingData = {
// 'ticketId': ticket.id,
// 'scheduleId': '2',
// 'cpf_cnpj': '3337733377',
// 'schedulingDate': '2022-02-25 22:30:42',
// 'reminder': 'Retorno',
// 'message': 'Ola sr estamos entrando em contato para confirma seu horário hoje às 17:00?',
// 'status': ''
// }
setLoading(true);
try {
if(status==='closed'){
await api.put(`/tickets/${ticket.id}`, {
status: status,
userId: userId || null,
schedulingNotifyData: JSON.stringify(schedulingData)
});
}
else{
await api.put(`/tickets/${ticket.id}`, {
status: status,
userId: userId || null
});
}
setLoading(false);
if (status === "open") {
history.push(`/tickets/${ticket.id}`);
@ -138,7 +154,7 @@ const TicketActionButtons = ({ ticket, schedule }) => {
color="primary"
onClick={e => {
handleModal(e, "closed", user?.id)
handleModal( "closed", user?.id)
// handleUpdateTicketStatus(e, "closed", user?.id)
}}