Commit 6a504a36 authored by Kim, Subin's avatar Kim, Subin
Browse files

Schedule client 및 server 완성

parent 411e53a3
...@@ -9,13 +9,13 @@ const AdminScheduleItem = ({ schedule, handleClick }) => { ...@@ -9,13 +9,13 @@ const AdminScheduleItem = ({ schedule, handleClick }) => {
<div className="col-11"> <div className="col-11">
<div className="d-flex"> <div className="d-flex">
<h3 className="col-10 rows-cols-2">{schedule.title}</h3> <h3 className="col-10 rows-cols-2">{schedule.title}</h3>
<div className="d-flex col-2 fs-5"> <div className={`d-flex col-2 fs-5 ${styles.cursor}`}>
<Link to={`/admin/edit/${schedule.id}`}><i className="bi bi-pencil-square text-dark me-2" data-bs-dismiss="modal"></i></Link> <Link to={`/admin/edit/${schedule.id}`}><i className="bi bi-pencil-square text-dark me-2" data-bs-dismiss="modal"></i></Link>
<i className="bi bi-trash" onClick={() => handleClick(schedule.id)}></i> <i className="bi bi-trash" onClick={() => handleClick(schedule.id)}></i>
</div> </div>
</div> </div>
<p className="text-start text-secondary mb-2"> <p className="text-start text-secondary mb-2">
{(schedule.start === schedule.end) ? schedule.start : schedule.start + "~" + schedule.end} {(schedule.start === schedule.end) ? schedule.start : schedule.start + " ~ " + schedule.end}
</p> </p>
<div className={`text-start ${styles.textBox}`}>{schedule.memo}</div> <div className={`text-start ${styles.textBox}`}>{schedule.memo}</div>
</div> </div>
......
...@@ -28,12 +28,12 @@ const AdminMonthly = () => { ...@@ -28,12 +28,12 @@ const AdminMonthly = () => {
} }
}) })
// useEffect(() => { useEffect(() => {
// getAll() getAll()
// return () => { return () => {
// getAll() getAll()
// } }
// }, []) }, [dateShow.show])
useEffect(() => { useEffect(() => {
if (calenIconRef && calenIconRef.current) { if (calenIconRef && calenIconRef.current) {
...@@ -60,6 +60,7 @@ const AdminMonthly = () => { ...@@ -60,6 +60,7 @@ const AdminMonthly = () => {
}, [changeDate]) }, [changeDate])
useEffect(() => { useEffect(() => {
calendar.removeAllEvents()
calendar.addEventSource(scheduleList) calendar.addEventSource(scheduleList)
}, [scheduleList]) }, [scheduleList])
...@@ -75,7 +76,6 @@ const AdminMonthly = () => { ...@@ -75,7 +76,6 @@ const AdminMonthly = () => {
return ( return (
<> <>
{console.log("list==", scheduleList)}
<div ref={calenIconRef} className="position-absolute" style={{ top: "7px", left: "7px" }}> <div ref={calenIconRef} className="position-absolute" style={{ top: "7px", left: "7px" }}>
<CalendarBtn date={moment(initialDate).format('DD')} /> <CalendarBtn date={moment(initialDate).format('DD')} />
</div> </div>
...@@ -128,7 +128,6 @@ const AdminMonthly = () => { ...@@ -128,7 +128,6 @@ const AdminMonthly = () => {
}} }}
timeZone="local" timeZone="local"
events={scheduleList, { color: 'crimson' }} events={scheduleList, { color: 'crimson' }}
eventLimit="3"
themeSystem='bootstrap' themeSystem='bootstrap'
height='78vh' height='78vh'
/> />
......
...@@ -14,7 +14,6 @@ import '@fortawesome/fontawesome-free/css/all.css'; ...@@ -14,7 +14,6 @@ import '@fortawesome/fontawesome-free/css/all.css';
const Monthly = () => { const Monthly = () => {
const { user } = useAuth() const { user } = useAuth()
console.log("msds==",user)
const [initialDate, setInitialDate] = useState(moment().format('YYYY-MM-DD')) const [initialDate, setInitialDate] = useState(moment().format('YYYY-MM-DD'))
const [changeDate, setChangeDate] = useState(moment().format('YYYY-MM-DD')) const [changeDate, setChangeDate] = useState(moment().format('YYYY-MM-DD'))
const [show, setShow] = useState(false) const [show, setShow] = useState(false)
...@@ -56,15 +55,15 @@ const Monthly = () => { ...@@ -56,15 +55,15 @@ const Monthly = () => {
}, [changeDate]) }, [changeDate])
useEffect(() => { useEffect(() => {
calendar.removeAllEvents()
calendar.addEventSource(scheduleList) calendar.addEventSource(scheduleList)
}, [scheduleList]) }, [scheduleList])
async function getAll() { async function getAll() {
try { try {
setError("") setError("")
console.log("home user",user) const { KU, individual } = await scheduleApi.getbyMonth(changeDate, user.id)
const resList = await scheduleApi.getbyMonth(changeDate, user.id) setScheduleList([...KU, ...individual])
setScheduleList(resList)
} catch (error) { } catch (error) {
catchErrors(error, setError) catchErrors(error, setError)
} }
...@@ -72,7 +71,6 @@ const Monthly = () => { ...@@ -72,7 +71,6 @@ const Monthly = () => {
return ( return (
<> <>
{console.log("user scheduleList==",scheduleList)}
<div ref={calenIconRef} className="position-absolute" style={{ top: "9px", right: "8px" }}> <div ref={calenIconRef} className="position-absolute" style={{ top: "9px", right: "8px" }}>
<CalendarBtn date={moment(initialDate).format('DD')} /> <CalendarBtn date={moment(initialDate).format('DD')} />
</div> </div>
......
...@@ -49,7 +49,9 @@ const ScheduleForm = () => { ...@@ -49,7 +49,9 @@ const ScheduleForm = () => {
async function getOne(id) { async function getOne(id) {
try { try {
setError("") setError("")
const resSchedule = await scheduleApi.getOne(id, user.id) let resSchedule = null
if (user.role === "admin") resSchedule = await scheduleApi.getOne(id)
else resSchedule = await scheduleApi.getOne(id, user.id)
setSchedule({ ...schedule, ...resSchedule }) setSchedule({ ...schedule, ...resSchedule })
} catch (error) { } catch (error) {
catchErrors(error, setError) catchErrors(error, setError)
...@@ -72,11 +74,13 @@ const ScheduleForm = () => { ...@@ -72,11 +74,13 @@ const ScheduleForm = () => {
try { try {
setError("") setError("")
if (scheduleId) { if (scheduleId) {
await scheduleApi.edit(scheduleId, schedule, user.id) if (user.role === "admin") await scheduleApi.edit(scheduleId, schedule)
else await scheduleApi.edit(scheduleId, schedule, user.id)
alert('해당 일정이 성공적으로 수정되었습니다.') alert('해당 일정이 성공적으로 수정되었습니다.')
} }
else { else {
await scheduleApi.submit(schedule, user.id) if (user.role === "admin") await scheduleApi.submit(schedule)
else await scheduleApi.submit(schedule, user.id)
alert('해당 일정이 성공적으로 등록되었습니다.') alert('해당 일정이 성공적으로 등록되었습니다.')
} }
setSuccess(true) setSuccess(true)
...@@ -101,7 +105,7 @@ const ScheduleForm = () => { ...@@ -101,7 +105,7 @@ const ScheduleForm = () => {
<input className={`form-control shadow-none ${styles.dateInput}`} type="date" name="startDate" value={schedule.startDate} aria-label="startDate" onChange={handleChange} /> <input className={`form-control shadow-none ${styles.dateInput}`} type="date" name="startDate" value={schedule.startDate} aria-label="startDate" onChange={handleChange} />
</div> </div>
<div className={"col-5 " + ((user.role === "admin" || schedule.allDay === "on") ? "d-none" : "d-block")}> <div className={"col-5 " + ((user.role === "admin" || schedule.allDay === "on") ? "d-none" : "d-block")}>
<input className={`form-control shadow-none ${styles.dateInput}`} type="time" name="startTime" aria-label="startTime" onChange={handleChange} /> <input className={`form-control shadow-none ${styles.dateInput}`} type="time" name="startTime" value={schedule.startTime} aria-label="startTime" onChange={handleChange} />
</div> </div>
</div> </div>
<div className={"d-flex " + (user.role === "admin" ? "mb-5" : "mb-3")}> <div className={"d-flex " + (user.role === "admin" ? "mb-5" : "mb-3")}>
...@@ -116,11 +120,11 @@ const ScheduleForm = () => { ...@@ -116,11 +120,11 @@ const ScheduleForm = () => {
<div className={"d-flex justify-content-end form-check mb-4 " + (user.role === "admin" ? "d-none" : "d-block")}> <div className={"d-flex justify-content-end form-check mb-4 " + (user.role === "admin" ? "d-none" : "d-block")}>
<input className={`form-check-input shadow-none ${styles.checkBox}`} type="checkbox" id="allDay" name="allDay" onChange={handleChange} checked={schedule.allDay === "on" ? true : false} /> <input className={`form-check-input shadow-none ${styles.checkBox}`} type="checkbox" id="allDay" name="allDay" onChange={handleChange} checked={schedule.allDay === "on" ? true : false} />
<label className="form-check-label ms-2" htmlFor="allDay">하루 종일</label> <label className="form-check-label ms-2" htmlFor="allDay">하루 종일</label>
</div>52 </div>
<div className={"d-flex justify-content-between align-items-center mb-4 " + (user.role === "admin" ? "d-none" : "d-block")}> <div className={"d-flex justify-content-between align-items-center mb-4 " + (user.role === "admin" ? "d-none" : "d-block")}>
<i className="col bi bi-geo-alt fs-3"></i> <i className="col bi bi-geo-alt fs-3"></i>
<div className="col-10"> <div className="col-10">
<input className={`form-control shadow-none rounded-0 px-1 ${styles.textInput}`} type="text" name="location" placeholder="장소" aria-label="location" onChange={handleChange} /> <input className={`form-control shadow-none rounded-0 px-1 ${styles.textInput}`} type="text" name="location" value={schedule.location} placeholder="장소" aria-label="location" onChange={handleChange} />
</div> </div>
</div> </div>
<div className="d-flex justify-content-between mb-5"> <div className="d-flex justify-content-between mb-5">
......
...@@ -8,7 +8,7 @@ const KUSchedule = ({ schedule }) => { ...@@ -8,7 +8,7 @@ const KUSchedule = ({ schedule }) => {
</div> </div>
<div className="card-body text-center pb-2"> <div className="card-body text-center pb-2">
{schedule.title.length > 12 ? <marquee className={`card-title fs-5 ${styles.flowText}`} loop="infinite">{schedule.title}</marquee> : <h5 className="card-title">{schedule.title}</h5>} {schedule.title.length > 12 ? <marquee className={`card-title fs-5 ${styles.flowText}`} loop="infinite">{schedule.title}</marquee> : <h5 className="card-title">{schedule.title}</h5>}
<p className="card-text text-secondary mb-1">{(schedule.start === schedule.end) ? schedule.start : schedule.start + "~" + schedule.end}</p> <p className="card-text text-secondary mb-1">{(schedule.start === schedule.end) ? schedule.start : schedule.start + " ~ " + schedule.end}</p>
<p className="text-start mb-0">{schedule.memo}</p> <p className="text-start mb-0">{schedule.memo}</p>
</div> </div>
</div> </div>
......
...@@ -11,16 +11,6 @@ const ScheduleCarousel = () => { ...@@ -11,16 +11,6 @@ const ScheduleCarousel = () => {
useEffect(() => { useEffect(() => {
getSchedule(date) getSchedule(date)
return () => {
getSchedule(date)
}
}, [])
useEffect(() => {
getSchedule(date)
return () => {
getSchedule(date)
}
}, [date]) }, [date])
async function getSchedule(date) { async function getSchedule(date) {
...@@ -38,7 +28,7 @@ const ScheduleCarousel = () => { ...@@ -38,7 +28,7 @@ const ScheduleCarousel = () => {
<div className="carousel-inner"> <div className="carousel-inner">
{scheduleList.length !== 0 ? {scheduleList.length !== 0 ?
scheduleList.map((schedule, idx) => scheduleList.map((schedule, idx) =>
<div className={"carousel-item" + (idx === 0 ? " active" : "")}> <div key={idx} className={"carousel-item" + (idx === 0 ? " active" : "")}>
<KU key={idx} schedule={schedule} /> <KU key={idx} schedule={schedule} />
</div>) : null} </div>) : null}
</div> </div>
......
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import styles from "./schedule.module.scss"; import styles from "./schedule.module.scss";
const ScheduleItem = ({ schedule, handleClick }) => { const ScheduleItem = ({ index, curDate, schedule, handleClick }) => {
return ( return (
<div className="accordion-item border-bottom-0"> <div className="accordion-item border-bottom-0">
<button className={`d-flex flex-column align-items-start accordion-button collapsed bg-white shadow-none px-0 ${styles.activeBtn}`} type="button" data-bs-toggle="collapse" data-bs-target={schedule.id} aria-expanded="false" aria-controls={schedule.id}> <button className={`d-flex flex-column align-items-start accordion-button collapsed bg-white shadow-none px-0 ${styles.activeBtn}`} type="button" data-bs-toggle="collapse" data-bs-target={"#collapse" + index} aria-expanded="false" aria-controls={"collapse" + index}>
<h5 className={`accordion-header ${styles.title}`} id={"heading" + schedule.id}>{schedule.title}</h5> <h5 className={`accordion-header ${styles.title}`} id={"heading" + index}>{schedule.title}</h5>
<p className={`text-secondary mb-0 ${styles.time}`}>sadsadsdsadsadsaf</p> <p className={`text-secondary mb-0 ${styles.time}`}>
<p className={`mb-0 ${styles.period}`}>2021.01.151 ~ 2021.09.35</p> {(schedule.allDay) ? "하루 종일" : (curDate === schedule.startDate ? schedule.startTime + " ~" : (curDate === schedule.endDate ? "~ " + schedule.endTime : "하루 종일"))}
</p>
<p className={`mb-0 ${styles.period}`}>
{schedule.allDay ? schedule.startDate + " ~ " + schedule.endDate : schedule.startDate + " " + schedule.startTime + " ~ " + schedule.endDate + " " + schedule.endTime}
</p>
</button> </button>
<div id={schedule.id} className="accordion-collapse collapse" aria-labelledby={"heading" + schedule.id} data-bs-parent="#scheduleList"> <div id={"collapse" + index} className="accordion-collapse collapse" aria-labelledby={"heading" + index} data-bs-parent="#scheduleList">
<div className={`accordion-body px-0 pt-2 pb-0 mb-3 ${styles.textBox}`}> <div className={`accordion-body px-0 pt-2 pb-0 mb-3 ${styles.textBox}`}>
{schedule.location ? <div className="d-flex align-items-start"> {schedule.location ? <div className="d-flex align-items-start">
<i className="col bi bi-geo-alt fs-5"></i> <i className="col bi bi-geo-alt fs-5"></i>
...@@ -19,7 +22,7 @@ const ScheduleItem = ({ schedule, handleClick }) => { ...@@ -19,7 +22,7 @@ const ScheduleItem = ({ schedule, handleClick }) => {
{schedule.memo} {schedule.memo}
<div className="d-flex justify-content-end mt-3"> <div className="d-flex justify-content-end mt-3">
<Link className="btn btn-light btn-sm border-dark" to={`/schedule/edit/${schedule.id}`}>수정</Link> <Link className="btn btn-light btn-sm border-dark" to={`/schedule/edit/${schedule.id}`}>수정</Link>
<button type="button" className="btn btn-crimson btn-sm ms-2" onClick={handleClick}>삭제</button> <button type="button" className="btn btn-crimson btn-sm ms-2" onClick={() => handleClick(schedule.id)}>삭제</button>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -4,6 +4,7 @@ import Item from "./ScheduleItem"; ...@@ -4,6 +4,7 @@ import Item from "./ScheduleItem";
import scheduleApi from "../../apis/schedule.api"; import scheduleApi from "../../apis/schedule.api";
import { useAuth } from "../../utils/context"; import { useAuth } from "../../utils/context";
import catchErrors from "../../utils/catchErrors"; import catchErrors from "../../utils/catchErrors";
import moment from 'moment';
import styles from "./schedule.module.scss"; import styles from "./schedule.module.scss";
const ScheduleList = () => { const ScheduleList = () => {
...@@ -14,16 +15,6 @@ const ScheduleList = () => { ...@@ -14,16 +15,6 @@ const ScheduleList = () => {
useEffect(() => { useEffect(() => {
getAll(date) getAll(date)
return () => {
getAll(date)
}
}, [])
useEffect(() => {
getAll(date)
return () => {
getAll(date)
}
}, [date]) }, [date])
async function getAll(date) { async function getAll(date) {
...@@ -51,8 +42,8 @@ const ScheduleList = () => { ...@@ -51,8 +42,8 @@ const ScheduleList = () => {
<div className={styles.list}> <div className={styles.list}>
<div className="accordion accordion-flush" id="scheduleList"> <div className="accordion accordion-flush" id="scheduleList">
{scheduleList.length !== 0 ? {scheduleList.length !== 0 ?
scheduleList.map((schedule, idx) => <Item key={idx} schedule={schedule} handleClick={delSchedule} />) scheduleList.map((schedule, idx) => <Item key={idx} index={idx} curDate={moment(date).format("YY.MM.DD")} schedule={schedule} handleClick={delSchedule} />)
: <div className="text-center text-secondary">오늘 등록된 일정이 없습니다.</div>} : <div className="text-center text-secondary mt-2">오늘 등록된 일정이 없습니다.</div>}
</div> </div>
</div> </div>
) )
......
...@@ -71,4 +71,8 @@ ...@@ -71,4 +71,8 @@
.flowText { .flowText {
font-family: "Plex-Bold"; font-family: "Plex-Bold";
}
.cursor {
cursor: pointer;
} }
\ No newline at end of file
...@@ -23,11 +23,11 @@ const AuthProvider = ({ children }) => { ...@@ -23,11 +23,11 @@ const AuthProvider = ({ children }) => {
console.log("context getUser") console.log("context getUser")
const resUser = await authApi.getUser(); const resUser = await authApi.getUser();
setUser({ ...user, ...resUser }) setUser({ ...user, ...resUser })
if (pathname === "/admin" && user.role !== "admin") { if (resUser.role === "admin") history.push("/admin")
else if (pathname === "/admin" && resUser.role !== "admin") {
await logout() await logout()
return <ErrorPage /> return <ErrorPage />
} else if (user.role === "admin") history.push("/admin") } else history.push("/home")
else history.push("/home")
} catch (error) { } catch (error) {
catchErrorAuth(error, setError); catchErrorAuth(error, setError);
} }
...@@ -43,6 +43,7 @@ const AuthProvider = ({ children }) => { ...@@ -43,6 +43,7 @@ const AuthProvider = ({ children }) => {
const user = await authApi.login(data); const user = await authApi.login(data);
localStorage.setItem("login", true) localStorage.setItem("login", true)
setUser(user) setUser(user)
if (user.role === "admin") history.push("/admin")
return true; return true;
} catch (error) { } catch (error) {
catchErrors(error, setError); catchErrors(error, setError);
......
...@@ -4,6 +4,7 @@ const config = { ...@@ -4,6 +4,7 @@ const config = {
password: process.env.PG_PASSWORD || 'kuku0725', password: process.env.PG_PASSWORD || 'kuku0725',
database: process.env.PG_DATABASE || 'todayKUDB', database: process.env.PG_DATABASE || 'todayKUDB',
dialect: 'postgres', dialect: 'postgres',
timezone: '+09:00',
pool: { pool: {
max: 10, max: 10,
min: 0, min: 0,
......
...@@ -24,12 +24,12 @@ const findbyId = async (req, res, next) => { ...@@ -24,12 +24,12 @@ const findbyId = async (req, res, next) => {
findSchedule = await Schedule.findOne({ where: { [Op.and]: [{ id: id }, { userId: userId }] } }) findSchedule = await Schedule.findOne({ where: { [Op.and]: [{ id: id }, { userId: userId }] } })
if (!findSchedule) throw new Error("해당 일정을 찾지 못했습니다.") if (!findSchedule) throw new Error("해당 일정을 찾지 못했습니다.")
else { else {
const { id, title, start, end, location, memo } = findSchedule const { id, title, start, end, allDay, location, memo } = findSchedule
startDate = dateToString(start, "full") startDate = dateToString(start, "full")
endDate = dateToString(end, "full") endDate = dateToString(end, "full")
const startTime = dateToString(start, "time") const startTime = dateToString(start, "time")
const endTime = dateToString(end, "time") const endTime = dateToString(end, "time")
req.schedule = { id, title, startDate, endDate, startTime, endTime, location, memo } req.schedule = { id, title, startDate, endDate, startTime, endTime, allDay: allDay ? "on" : "off", location, memo }
} }
} }
next() next()
...@@ -43,11 +43,20 @@ const findbyDate = async (req, res, next) => { ...@@ -43,11 +43,20 @@ const findbyDate = async (req, res, next) => {
try { try {
if (req.date || req.month) { if (req.date || req.month) {
let date = "" let date = ""
let startDate = null
let endDate = null
let findList = null let findList = null
let findKUList = null
let findIndividualList = null
if (req.date) { if (req.date) {
// 날짜 기준
date = new Date(req.date) date = new Date(req.date)
startDate = new Date(req.date)
startDate.setHours(24, 0, 0, 0)
endDate = new Date(req.date)
endDate.setHours(0, 0, 0, 0)
if (req.userId === "ku") { if (req.userId === "ku") {
findList = await KU.findAll({ findKUList = await KU.findAll({
where: { where: {
[Op.and]: [ [Op.and]: [
{ {
...@@ -62,32 +71,43 @@ const findbyDate = async (req, res, next) => { ...@@ -62,32 +71,43 @@ const findbyDate = async (req, res, next) => {
] ]
}, order: [['updatedAt', 'DESC']] }, order: [['updatedAt', 'DESC']]
}) })
findList.forEach(schedule => { findKUList.forEach(schedule => {
schedule.dataValues.start = dateToString(schedule.start, "twoYear") schedule.dataValues.start = dateToString(schedule.dataValues.start, "twoYear")
schedule.dataValues.end = dateToString(schedule.end, "twoYear") schedule.dataValues.end = dateToString(schedule.dataValues.end, "twoYear")
}) })
findList = findKUList
} else { } else {
findList = await Schedule.findAll({ findIndividualList = await Schedule.findAll({
where: { where: {
[Op.and]: [ [Op.and]: [
{ {
start: { start: {
[Op.lte]: date [Op.lte]: startDate
} }
}, { }, {
end: { end: {
[Op.gte]: date [Op.gte]: endDate
} }
} }
] ]
}, order: [['updatedAt', 'DESC']] }, order: [['updatedAt', 'DESC']]
}) })
findIndividualList.forEach(schedule => {
schedule.dataValues.startDate = dateToString(schedule.dataValues.start, "twoYear")
schedule.dataValues.endDate = dateToString(schedule.dataValues.end, "twoYear")
if (!schedule.dataValues.allDay) {
schedule.dataValues.startTime = dateToString(schedule.dataValues.start, "time")
schedule.dataValues.endTime = dateToString(schedule.dataValues.end, "time")
}
})
findList = findIndividualList
} }
} else { } else {
// 달 기준
date = new Date(req.month) date = new Date(req.month)
const year = dateToString(date, "year") const year = dateToString(date, "year")
const month = dateToString(date, "month") const month = dateToString(date, "month")
const findKUList = await KU.findAll({ findKUList = await KU.findAll({
where: { where: {
[Op.or]: [ [Op.or]: [
{ {
...@@ -105,22 +125,17 @@ const findbyDate = async (req, res, next) => { ...@@ -105,22 +125,17 @@ const findbyDate = async (req, res, next) => {
}, attributes: ['id', 'title', 'start', 'end'] }, attributes: ['id', 'title', 'start', 'end']
, order: [['start']] , order: [['start']]
}) })
findKUList.forEach(schedule => {
schedule.dataValues.end.setDate(schedule.dataValues.end.getDate() + 1)
schedule.dataValues.end = dateToString(schedule.dataValues.end, "full")
schedule.dataValues.start = dateToString(schedule.dataValues.start, "full")
schedule.dataValues.allDay = true
schedule.dataValues.className = 'text'
})
if (req.userId === "ku") { if (req.userId === "ku") {
// console.log("list==",findList)
findKUList.forEach(schedule => {
// const find = findList.find(el => {
// if (el.dataValues.start <= schedule.dataValues.start) {
// if (el.dataValues.end >= schedule.dataValues.start) return el
// } else if (el.dataValues.start <= schedule.dataValues.end) return el
// })
// console.log("find==",find.dataValues)
if (dateToString(schedule.start, "full") !== dateToString(schedule.end, "full")) schedule.dataValues.end = schedule.dataValues.end.setDate(schedule.dataValues.end.getDate() + 1)
schedule.dataValues.allDay = true
schedule.dataValues.className = 'text'
})
findList = findKUList findList = findKUList
} else { } else {
const findIndividualList = await Schedule.findAll({ findIndividualList = await Schedule.findAll({
where: { where: {
[Op.or]: [ [Op.or]: [
{ {
...@@ -139,6 +154,13 @@ const findbyDate = async (req, res, next) => { ...@@ -139,6 +154,13 @@ const findbyDate = async (req, res, next) => {
, order: [['start']] , order: [['start']]
}) })
console.log("개인 일정 찾기", findIndividualList) console.log("개인 일정 찾기", findIndividualList)
findIndividualList.forEach(schedule => {
schedule.dataValues.end.setDate(schedule.dataValues.end.getDate() + 1)
schedule.dataValues.end = dateToString(schedule.dataValues.end, "full")
schedule.dataValues.start = dateToString(schedule.dataValues.start, "full")
schedule.dataValues.allDay = true
schedule.dataValues.className = 'text'
})
findList = { KU: findKUList, individual: findIndividualList } findList = { KU: findKUList, individual: findIndividualList }
} }
} }
...@@ -155,6 +177,7 @@ const create = async (req, res) => { ...@@ -155,6 +177,7 @@ const create = async (req, res) => {
let newSchedule = null let newSchedule = null
let start = null let start = null
let end = null let end = null
let allDay_v = false
const userId = req.userId const userId = req.userId
if (userId === "ku") { if (userId === "ku") {
const { title, startDate, endDate, memo } = req.body const { title, startDate, endDate, memo } = req.body
...@@ -166,11 +189,12 @@ const create = async (req, res) => { ...@@ -166,11 +189,12 @@ const create = async (req, res) => {
if (allDay === "on") { if (allDay === "on") {
start = new Date(startDate) start = new Date(startDate)
end = new Date(endDate) end = new Date(endDate)
allDay_v = true
} else { } else {
start = new Date(startDate + " " + startTime) start = new Date(startDate + " " + startTime)
end = new Date(endDate + " " + endTime) end = new Date(endDate + " " + endTime)
} }
newSchedule = await Schedule.create({ title: title, start: start, end: end, location: location, memo: memo, userId: userId }) newSchedule = await Schedule.create({ title: title, start: start, end: end, allDay: allDay_v, location: location, memo: memo, userId: userId })
} }
return res.json(newSchedule) return res.json(newSchedule)
} catch (error) { } catch (error) {
...@@ -183,6 +207,7 @@ const edit = async (req, res) => { ...@@ -183,6 +207,7 @@ const edit = async (req, res) => {
let updated = null let updated = null
let start = null let start = null
let end = null let end = null
let allDay_v = false
const userId = req.userId const userId = req.userId
const { scheduleId } = req.query const { scheduleId } = req.query
if (userId === "ku") { if (userId === "ku") {
...@@ -195,11 +220,12 @@ const edit = async (req, res) => { ...@@ -195,11 +220,12 @@ const edit = async (req, res) => {
if (allDay === "on") { if (allDay === "on") {
start = new Date(startDate) start = new Date(startDate)
end = new Date(endDate) end = new Date(endDate)
allDay_v = true
} else { } else {
start = new Date(startDate + " " + startTime) start = new Date(startDate + " " + startTime)
end = new Date(endDate + " " + endTime) end = new Date(endDate + " " + endTime)
} }
updated = await Schedule.update({ title: title, start: start, end: end, location: location, memo: memo }, updated = await Schedule.update({ title: title, start: start, end: end, allDay: allDay_v, location: location, memo: memo },
{ where: { [Op.and]: [{ id: scheduleId }, { userId: userId }] } }) { where: { [Op.and]: [{ id: scheduleId }, { userId: userId }] } })
} }
if (!updated) throw new Error("해당 일정의 일부 정보를 수정하는데 실패하였습니다.") if (!updated) throw new Error("해당 일정의 일부 정보를 수정하는데 실패하였습니다.")
...@@ -214,6 +240,7 @@ const remove = async (req, res) => { ...@@ -214,6 +240,7 @@ const remove = async (req, res) => {
let deleted = null let deleted = null
const userId = req.userId const userId = req.userId
const { scheduleId } = req.query const { scheduleId } = req.query
console.log("scheduleId==",scheduleId)
if (userId === "ku") deleted = await KU.destroy({ where: { id: scheduleId } }) if (userId === "ku") deleted = await KU.destroy({ where: { id: scheduleId } })
else deleted = await Schedule.destroy({ where: { [Op.and]: [{ id: scheduleId }, { userId: userId }] } }) else deleted = await Schedule.destroy({ where: { [Op.and]: [{ id: scheduleId }, { userId: userId }] } })
if (!deleted) throw new Error("해당 일정을 삭제하는데 실패하였습니다.") if (!deleted) throw new Error("해당 일정을 삭제하는데 실패하였습니다.")
...@@ -267,9 +294,7 @@ function dateToString(dateObj, method) { ...@@ -267,9 +294,7 @@ function dateToString(dateObj, method) {
case "full": case "full":
return [year, (month > 9 ? "" : "0") + month, (date > 9 ? "" : "0") + date].join("-") return [year, (month > 9 ? "" : "0") + month, (date > 9 ? "" : "0") + date].join("-")
case "twoYear": case "twoYear":
return [year_disit, (month > 9 ? "" : "0") + month, (date > 9 ? "" : "0") + date].join("-") return [year_disit, (month > 9 ? "" : "0") + month, (date > 9 ? "" : "0") + date].join(".")
// case "dateTime":
// return [year, (month > 9 ? "" : "0") + month, (date > 9 ? "" : "0") + date, ].join("-")
case "time": case "time":
return [(hour > 9 ? "" : "0") + hour, (minute > 9 ? "" : "0") + minute].join(":") return [(hour > 9 ? "" : "0") + hour, (minute > 9 ? "" : "0") + minute].join(":")
case "year": case "year":
......
...@@ -14,6 +14,7 @@ const sequelize = new Sequelize( ...@@ -14,6 +14,7 @@ const sequelize = new Sequelize(
{ {
host: dbConfig.host, host: dbConfig.host,
dialect: dbConfig.dialect, dialect: dbConfig.dialect,
timezone: dbConfig.timezone,
pool: { pool: {
max: dbConfig.pool?.max, max: dbConfig.pool?.max,
min: dbConfig.pool?.min, min: dbConfig.pool?.min,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment