From 93b5e14e60f770ff5dd4e281e7080492a222d0d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EB=8C=80=ED=9D=AC?= <joedaehui@ajou.ac.kr> Date: Thu, 14 Nov 2024 22:57:41 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B3=A0=EC=A0=95/=EC=9C=A0=EB=8F=99?= =?UTF-8?q?=20=EC=8A=A4=EC=BC=80=EC=A4=84=20=EC=83=9D=EC=84=B1=20(#5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/scheduleService.js | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 services/scheduleService.js diff --git a/services/scheduleService.js b/services/scheduleService.js new file mode 100644 index 0000000..4d971fc --- /dev/null +++ b/services/scheduleService.js @@ -0,0 +1,39 @@ +const { Op } = require('sequelize'); +const Schedule = require('../models/Schedule'); + +class schedulService { + + /** + * 유동 스케줄 만료일 구하기 + */ + getNextMonday() { + const date = new Date(); + const day = date.getDay(); + const daysUntilNextMonday = (8 - day) % 7; + date.setDate(date.getDate() + daysUntilNextMonday); + date.setHours(0, 0, 0, 0); + return date; + } + + /** + * 사용자 스케줄 생성 + */ + async createSchedule({ userId, title, start_time, end_time, is_fixed }) { + try { + const scehduleData = { + user_id: userId, + title, + start_time, + end_time, + is_fixed, + expiry_date: is_fixed ? null : this.getNextMonday() + }; + + const schedule = await Schedule.create(scehduleData); + return schedule; + } catch (error) { + throw new Error(`Failed to create schedule: ${error.message}`); + } + } + +} \ No newline at end of file -- GitLab