2022-02-28 13:51:11 +00:00
|
|
|
import AppError from "../../errors/AppError";
|
|
|
|
import SchedulingNotify from "../../models/SchedulingNotify";
|
|
|
|
|
2022-02-28 18:17:36 +00:00
|
|
|
|
2022-02-28 13:51:11 +00:00
|
|
|
interface Request {
|
2022-03-28 19:28:35 +00:00
|
|
|
schedulingNotifyId?: string,
|
2022-02-28 18:17:36 +00:00
|
|
|
ticketId: string,
|
2022-03-23 02:59:01 +00:00
|
|
|
statusChatEndId: string,
|
2022-03-06 19:37:09 +00:00
|
|
|
schedulingDate: string,
|
2022-03-12 05:13:15 +00:00
|
|
|
schedulingTime: string,
|
2022-03-06 19:37:09 +00:00
|
|
|
message: string
|
2022-03-24 22:16:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const CreateSchedulingNotifyService = async ({
|
|
|
|
schedulingNotifyId = '',
|
|
|
|
ticketId,
|
|
|
|
statusChatEndId,
|
|
|
|
schedulingDate,
|
|
|
|
schedulingTime,
|
|
|
|
message
|
|
|
|
}: Request): Promise<SchedulingNotify> => {
|
|
|
|
|
|
|
|
let schedulingNotify = null;
|
|
|
|
|
|
|
|
if(schedulingNotifyId){
|
|
|
|
|
|
|
|
console.log('000000000000000000000000000 ATUALIZOU!')
|
2022-02-28 18:17:36 +00:00
|
|
|
|
2022-03-24 22:16:31 +00:00
|
|
|
schedulingNotify = await SchedulingNotify.findOne({ where: { id: schedulingNotifyId } });
|
|
|
|
|
|
|
|
if(schedulingNotify){
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
await schedulingNotify.update({ statusChatEndId, schedulingDate, schedulingTime, message});
|
|
|
|
|
|
|
|
}catch(err){
|
|
|
|
|
|
|
|
throw new AppError("ERR_NO_SCHEDULING_NOTIFY_FOUND", 404);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//await scheduleNotify.reload({attributes: ["id", "name"]});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!schedulingNotify){
|
|
|
|
|
|
|
|
console.log('111111111111111111111111111 criou!')
|
|
|
|
|
|
|
|
schedulingNotify = await SchedulingNotify.create(
|
|
|
|
{
|
|
|
|
ticketId,
|
|
|
|
statusChatEndId,
|
|
|
|
schedulingDate,
|
|
|
|
schedulingTime,
|
|
|
|
message
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
2022-03-29 21:32:48 +00:00
|
|
|
|
2022-02-28 13:51:11 +00:00
|
|
|
|
|
|
|
return schedulingNotify
|
|
|
|
}
|
|
|
|
|
2022-03-24 22:16:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const CreateSchedulingNotifyService = async ({ ticketId, statusChatEndId, schedulingDate, schedulingTime, message }: Request): Promise<SchedulingNotify> => {
|
|
|
|
|
|
|
|
// const schedulingNotify = await SchedulingNotify.create(
|
|
|
|
// {
|
|
|
|
// ticketId,
|
|
|
|
// statusChatEndId,
|
|
|
|
// schedulingDate,
|
|
|
|
// schedulingTime,
|
|
|
|
// message
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// return schedulingNotify
|
|
|
|
// }
|
|
|
|
|
2022-02-28 13:51:11 +00:00
|
|
|
export default CreateSchedulingNotifyService
|