2022-02-28 13:51:11 +00:00
|
|
|
import AppError from "../../errors/AppError";
|
|
|
|
import SchedulingNotify from "../../models/SchedulingNotify";
|
|
|
|
|
|
|
|
|
2023-04-20 18:48:42 +00:00
|
|
|
interface SchedulingData {
|
|
|
|
name?: string
|
|
|
|
}
|
2022-02-28 13:51:11 +00:00
|
|
|
|
|
|
|
interface Request {
|
2023-04-20 18:48:42 +00:00
|
|
|
schedulingData: SchedulingData
|
|
|
|
schedulingDataId: string
|
2022-02-28 13:51:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const UpdateSchedulingNotify = async ({
|
2023-04-20 18:48:42 +00:00
|
|
|
schedulingData,
|
|
|
|
schedulingDataId
|
2022-02-28 13:51:11 +00:00
|
|
|
|
|
|
|
}: Request): Promise<SchedulingNotify> => {
|
|
|
|
|
2023-04-20 18:48:42 +00:00
|
|
|
try {
|
|
|
|
|
|
|
|
const { name } = schedulingData;
|
|
|
|
|
|
|
|
const updateScheduling = await SchedulingNotify.findOne({
|
|
|
|
where: { id: schedulingDataId },
|
|
|
|
attributes: ["id", "name"]
|
|
|
|
});
|
2022-02-28 13:51:11 +00:00
|
|
|
|
2023-04-20 18:48:42 +00:00
|
|
|
if (!updateScheduling) {
|
2022-02-28 13:51:11 +00:00
|
|
|
//console.log('NOT FOUND SCHEDULING NOTIFY')
|
2023-04-20 18:48:42 +00:00
|
|
|
throw new AppError("ERR_NO_SCHEDULING_NOTIFY_FOUND", 404);
|
|
|
|
}
|
|
|
|
await updateScheduling.update({ name });
|
|
|
|
|
|
|
|
await updateScheduling.reload({
|
|
|
|
attributes: ["id", "name"]
|
|
|
|
});
|
2022-02-28 13:51:11 +00:00
|
|
|
|
2023-04-20 18:48:42 +00:00
|
|
|
return updateScheduling;
|
|
|
|
|
|
|
|
} 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
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
export default UpdateSchedulingNotify;
|