40 lines
876 B
TypeScript
40 lines
876 B
TypeScript
|
import AppError from "../../errors/AppError";
|
||
|
import SchedulingNotify from "../../models/SchedulingNotify";
|
||
|
|
||
|
|
||
|
interface SchedulingData {
|
||
|
name?: string
|
||
|
}
|
||
|
|
||
|
interface Request {
|
||
|
schedulingData: SchedulingData
|
||
|
schedulingDataId: string
|
||
|
}
|
||
|
|
||
|
const UpdateSchedulingNotify = async ({
|
||
|
schedulingData,
|
||
|
schedulingDataId
|
||
|
|
||
|
}: Request): Promise<SchedulingNotify> => {
|
||
|
const { name } = schedulingData;
|
||
|
|
||
|
const updateScheduling = await SchedulingNotify.findOne({
|
||
|
where: { id: schedulingDataId },
|
||
|
attributes: ["id", "name"]
|
||
|
});
|
||
|
|
||
|
if (!updateScheduling) {
|
||
|
//console.log('NOT FOUND SCHEDULING NOTIFY')
|
||
|
throw new AppError("ERR_NO_SCHEDULING_NOTIFY_FOUND", 404);
|
||
|
}
|
||
|
await updateScheduling.update({ name });
|
||
|
|
||
|
await updateScheduling.reload({
|
||
|
attributes: ["id", "name"]
|
||
|
});
|
||
|
|
||
|
return updateScheduling;
|
||
|
};
|
||
|
|
||
|
export default UpdateSchedulingNotify;
|