projeto-hit/backend/src/services/SchedulingNotifyServices/CreateSchedulingNotifyServi...

90 lines
2.0 KiB
TypeScript

import AppError from "../../errors/AppError";
import SchedulingNotify from "../../models/SchedulingNotify";
interface Request {
schedulingNotifyId?: string,
ticketId: string,
statusChatEndId: string,
schedulingDate: string,
schedulingTime: string,
message: string
}
const CreateSchedulingNotifyService = async ({
schedulingNotifyId = '',
ticketId,
statusChatEndId,
schedulingDate,
schedulingTime,
message
}: Request): Promise<SchedulingNotify> => {
let schedulingNotify = null;
if(schedulingNotifyId){
console.log('000000000000000000000000000 ATUALIZOU!')
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
})
}
return schedulingNotify
}
// const CreateSchedulingNotifyService = async ({ ticketId, statusChatEndId, schedulingDate, schedulingTime, message }: Request): Promise<SchedulingNotify> => {
// const schedulingNotify = await SchedulingNotify.create(
// {
// ticketId,
// statusChatEndId,
// schedulingDate,
// schedulingTime,
// message
// })
// return schedulingNotify
// }
export default CreateSchedulingNotifyService