Skip to content
Snippets Groups Projects
Commit 93b5e14e authored by 조대희's avatar 조대희
Browse files

feat: 고정/유동 스케줄 생성 (#5)

parent d4c5e131
No related branches found
No related tags found
2 merge requests!31Develop,!6[#5] Schedule 서비스 로직 개발
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment