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 SendWhatsAppMessage from "../services/WbotServices/SendWhatsAppMessage";
import ShowWhatsAppService from "../services/WhatsappService/ShowWhatsAppService"; 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}); return res.status(200).json({contact, schedules});
}; };
export const update = async ( req: Request, res: Response): Promise<Response> => {
export const update = async ( req: Request, res: Response ): Promise<Response> => {
const { ticketId } = req.params; 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:{'status': status, 'userId': userId},
ticketId
});
const { ticket } = await UpdateTicketService({ ///////////////////////////////
ticketData,
ticketId
});
if (ticket.status === "closed") {
const whatsapp = await ShowWhatsAppService(ticket.whatsappId); const whatsapp = await ShowWhatsAppService(ticket.whatsappId);
const { farewellMessage } = whatsapp; const { farewellMessage } = whatsapp;
@ -115,11 +124,72 @@ export const update = async ( req: Request, res: Response): Promise<Response> =>
if (farewellMessage) { if (farewellMessage) {
await SendWhatsAppMessage({ body: farewellMessage, ticket }); 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 ( export const remove = async (
req: Request, req: Request,
res: Response res: Response

View File

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

View File

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

View File

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

View File

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