2022-02-28 13:51:11 +00:00
|
|
|
import AppError from "../../errors/AppError";
|
2022-12-18 14:45:41 +00:00
|
|
|
import { createSchedulingNotifyCache } from "../../helpers/SchedulingNotifyCache";
|
2022-02-28 13:51:11 +00:00
|
|
|
import SchedulingNotify from "../../models/SchedulingNotify";
|
|
|
|
|
2023-04-20 18:48:42 +00:00
|
|
|
|
2022-02-28 13:51:11 +00:00
|
|
|
interface Request {
|
2023-04-20 18:48:42 +00:00
|
|
|
schedulingNotifyId?: string,
|
2022-02-28 18:17:36 +00:00
|
|
|
ticketId: string,
|
2023-04-20 18:48:42 +00:00
|
|
|
statusChatEndId: string,
|
|
|
|
schedulingDate: string,
|
2022-03-12 05:13:15 +00:00
|
|
|
schedulingTime: string,
|
2023-04-20 18:48:42 +00:00
|
|
|
message: string
|
2022-03-24 22:16:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-20 18:48:42 +00:00
|
|
|
const CreateSchedulingNotifyService = async ({
|
2022-03-24 22:16:31 +00:00
|
|
|
schedulingNotifyId = '',
|
2023-04-20 18:48:42 +00:00
|
|
|
ticketId,
|
|
|
|
statusChatEndId,
|
|
|
|
schedulingDate,
|
|
|
|
schedulingTime,
|
|
|
|
message
|
|
|
|
}: Request): Promise<SchedulingNotify> => {
|
|
|
|
|
|
|
|
try {
|
2022-03-24 22:16:31 +00:00
|
|
|
|
2023-04-20 18:48:42 +00:00
|
|
|
let schedulingNotify = null;
|
|
|
|
|
|
|
|
if (schedulingNotifyId) {
|
2022-03-24 22:16:31 +00:00
|
|
|
|
|
|
|
schedulingNotify = await SchedulingNotify.findOne({ where: { id: schedulingNotifyId } });
|
|
|
|
|
2023-04-20 18:48:42 +00:00
|
|
|
if (schedulingNotify) {
|
|
|
|
|
|
|
|
try {
|
2022-03-24 22:16:31 +00:00
|
|
|
|
2023-04-20 18:48:42 +00:00
|
|
|
await schedulingNotify.update({ statusChatEndId, schedulingDate, schedulingTime, message });
|
2022-03-24 22:16:31 +00:00
|
|
|
|
2023-04-20 18:48:42 +00:00
|
|
|
} catch (err) {
|
2022-03-24 22:16:31 +00:00
|
|
|
|
|
|
|
throw new AppError("ERR_NO_SCHEDULING_NOTIFY_FOUND", 404);
|
2023-04-20 18:48:42 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-24 22:16:31 +00:00
|
|
|
//await scheduleNotify.reload({attributes: ["id", "name"]});
|
2023-04-20 18:48:42 +00:00
|
|
|
}
|
2022-03-24 22:16:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-04-20 18:48:42 +00:00
|
|
|
if (!schedulingNotify) {
|
|
|
|
|
2022-03-24 22:16:31 +00:00
|
|
|
schedulingNotify = await SchedulingNotify.create(
|
|
|
|
{
|
|
|
|
ticketId,
|
2023-04-20 18:48:42 +00:00
|
|
|
statusChatEndId,
|
|
|
|
schedulingDate,
|
2022-03-24 22:16:31 +00:00
|
|
|
schedulingTime,
|
2023-04-20 18:48:42 +00:00
|
|
|
message
|
|
|
|
|
|
|
|
})
|
2022-03-24 22:16:31 +00:00
|
|
|
}
|
2023-04-20 18:48:42 +00:00
|
|
|
|
|
|
|
await createSchedulingNotifyCache(JSON.parse(JSON.stringify(schedulingNotify)))
|
2022-12-18 14:45:41 +00:00
|
|
|
|
2022-02-28 13:51:11 +00:00
|
|
|
|
|
|
|
return schedulingNotify
|
2023-04-20 18:48:42 +00:00
|
|
|
|
|
|
|
} catch (error: any) {
|
|
|
|
console.error('===> Error on CreateSchedulingNotifyService.ts file: \n', error)
|
|
|
|
throw new AppError(error.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-28 13:51:11 +00:00
|
|
|
|
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
|
2023-04-20 18:48:42 +00:00
|
|
|
|
2022-03-24 22:16:31 +00:00
|
|
|
// })
|
|
|
|
|
|
|
|
// return schedulingNotify
|
|
|
|
// }
|
|
|
|
|
2023-04-20 18:48:42 +00:00
|
|
|
export default CreateSchedulingNotifyService
|