Commit 443851bc authored by Yoon, Daeki's avatar Yoon, Daeki 😅
Browse files

Merge remote-tracking branch 'origin/master' into master-up-merge-master

parents 155b7e3c b3127999
.list {
height: 70vh;
height: 75vh;
overflow-y: auto;
}
.inCard {
overflow: scroll;
}
.checkBox {
border-color: black;
......
......@@ -13,7 +13,8 @@ const TodoList = () => {
const { date } = useParams()
const [todoList, setTodoList] = useState([])
const [selectTodo, setSelectTodo] = useState(null)
const [error, setError] = useState("");
const [clicked, setClicked] = useState(false)
const [error, setError] = useState("")
useEffect(() => {
getAll()
......@@ -29,12 +30,26 @@ const TodoList = () => {
}
}
async function checkFn(e, todoId) {
try {
setError("")
const check_v = e.target.value === "true" ? true : false
await todoApi.edit({ id: todoId, done: check_v }, user.id)
alert("해당 변경사항이 정상적으로 저장되었습니다.")
window.location.reload()
// getAll()
// getTodoList()
} catch (error) {
catchErrors(error, setError)
}
}
async function delayTodo() {
try {
setError("")
const nextDate = moment(date).add(1, 'day').format("YYYY-MM-DD")
await todoApi.edit({ id: selectTodo.id, todoDate: nextDate }, user.id)
getAll()
window.location.reload()
} catch (error) {
catchErrors(error, setError)
}
......@@ -45,28 +60,32 @@ const TodoList = () => {
setError("")
await todoApi.remove(todoId, user.id)
alert("해당 할일이 성공적으로 삭제되었습니다.")
getAll()
window.location.reload()
} catch (error) {
catchErrors(error, setError)
}
}
return (
<div className={"mt-3 " + (todoList.length ? "d-flex" : "d-block")}>
<div className={`mt-3 ${styles.list}`}>
<div className={todoList.length ? "d-flex flex-column" : "d-block"}>
{todoList.length !== 0 ?
todoList.map((todo, idx) => <>
todoList.map((todo, idx) => <div key={idx} className="d-flex mb-1">
<div className="d-flex align-items-center" style={{ width: "75%" }}>
<input className={`form-check-input rounded-0 shadow-none mt-0 ${styles.checkBox}`} type="checkbox" checked={todo.done} />
<label className="form-check-label fs-5 ms-3 pe-2 text-nowrap" style={{ overflow: "hidden", textOverflow: "ellipsis" }}>{todo.todoTitle}</label>
<div className="col d-flex align-items-center">
<input className={`form-check-input rounded-0 shadow-none mt-0 ${styles.checkBox}`} type="checkbox" id={"todoCheck" + idx} value={todo.done} checked={todo.done} onClick={(e) => checkFn(e, todo.id)} />
</div>
<label className="col-11 form-check-label fs-5 pe-1 text-nowrap" style={{ overflow: "hidden", textOverflow: "ellipsis" }}>{todo.todoTitle}</label>
</div>
<div className="d-flex justify-content-between" style={{ cursor: "pointer", width: "25%" }}>
<i className="bi bi-arrow-right fs-5" data-bs-toggle="modal" data-bs-target="#postmodal" onClick={() => setSelectTodo(todo)}></i>
<i className="bi bi-pencil-square fs-5" data-bs-toggle="modal" data-bs-target="#todomodal" onClick={() => setSelectTodo(todo)}></i>
<i className="bi bi-pencil-square fs-5" data-bs-toggle="modal" data-bs-target="#todomodal" onClick={() => { setSelectTodo(todo); setClicked(true) }}></i>
<i className="bi bi-trash fs-5" onClick={() => delTodo(todo.id)}></i>
</div>
</>) : <p className="text-center">등록된 할일이 없습니다.</p>}
</div>) : <p className="text-center">등록된 할일이 없습니다.</p>}
<TodoPostModal handleClick={delayTodo} />
<TodoModal curDate={date} selectTodo={selectTodo} />
<TodoModal curDate={date} selectTodo={selectTodo} clicked={clicked} setClicked={setClicked} />
</div>
</div>
)
}
......
......@@ -33,7 +33,7 @@ const StudyPlanPage = () => {
<Menu />
<BackBtn />
<h2 className="text-center">{planList.name}</h2>
<AddplanList planList={planList} />
<AddplanList planList={planList} getPlanList={getPlanList} />
<Footer pathname={`studyplan/submit/${subjectId}`} />
</>
)
......
......@@ -149,10 +149,6 @@ button {
display: none;
}
& .fc-dayGridDay-view {
display: none;
}
& .text {
font-family: "Plex-Text";
......
......@@ -20,7 +20,6 @@ const AuthProvider = ({ children }) => {
const { pathname } = useLocation()
const getUser = async () => {
try {
console.log("context getUser")
const resUser = await authApi.getUser();
setUser({ ...user, ...resUser })
if (resUser.role === "admin") history.push("/admin")
......
......@@ -55,6 +55,18 @@ const edit = async (req, res) => {
}
}
const putCk = async (req, res) => {
try {
console.log('server/planCtrl/putCk req.body', req.body)
const planId = req.planId
const result = await Plan.update({ checked: !req.body.planCk }, { where: { id: planId } })
if (!result) throw new Error("체크 상태 수정에 실패하였습니다.")
else return res.send("success")
} catch (error) {
return res.status(500).send(error.message || "체크 상태 저장 중 에러 발생")
}
}
const remove = async (req, res) => {
try {
const planId = req.planId
......@@ -80,6 +92,7 @@ export default {
getOne,
create,
edit,
putCk,
remove,
getParams
}
\ No newline at end of file
......@@ -153,7 +153,6 @@ const findbyDate = async (req, res, next) => {
}, attributes: ['id', 'title', 'start', 'end']
, order: [['start']]
})
console.log("개인 일정 찾기", findIndividualList)
findIndividualList.forEach(schedule => {
schedule.dataValues.end.setDate(schedule.dataValues.end.getDate() + 1)
schedule.dataValues.end = dateToString(schedule.dataValues.end, "full")
......
......@@ -11,7 +11,7 @@ const findAll = async (req, res) => {
if (subjectId) findList = await Subject.findAll({ where: { [Op.and]: [{ id: subjectId }, { userId: userId }] }, order: [['updatedAt', 'DESC']] })
else findList = await Subject.findAll({ where: { userId: userId }, order: [['updatedAt', 'DESC']] })
const subjectAndPlan = await Promise.all(findList.map(async (subjectInfo) => {
const resPlan = await Plan.findAll({ where: { subjectId: subjectInfo.id } })
const resPlan = await Plan.findAll({ where: { subjectId: subjectInfo.id }, order: [[sequelize.literal('checked, deadline'), 'ASC']] })
subjectInfo.dataValues.planList = resPlan
return subjectInfo
}))
......@@ -63,8 +63,9 @@ const remove = async (req, res) => {
try {
const { subjectId } = req.query
const userId = req.userId
const deleted2 = await Plan.destroy({ where: { subjectId: subjectId } })
const deleted = await Subject.destroy({ where: { [Op.and]: [{ id: subjectId }, { userId: userId }] } })
if (!deleted) throw new Error("해당 과목을 삭제하는데 실패하였습니다.")
if (!(deleted && deleted2)) throw new Error("해당 과목을 삭제하는데 실패하였습니다.")
else return res.send(200)
} catch (error) {
return res.status(500).send(error.message || "과목 삭제 에러 발생")
......
......@@ -3,33 +3,15 @@ import sequelize from 'sequelize';
const { Op } = sequelize
const findbyId = async (req, res, next) => {
try {
const userId = req.userId
const { todoId } = req.query
if (todoId) {
console.log(" findbyId todoId가 있을 때 실행", todoId)
const findTodo = await Todo.findOne({ where: { [Op.and]: [{ id: todoId }, { userId: userId }] }, attributes: ['id', ['title', 'todoTitle'], ['date', 'todoDate'], 'done'] })
if (!findTodo) throw new Error("해당 todo를 찾지 못했습니다.")
req.todoOne = findTodo
}
next()
} catch (error) {
return res.status(500).send(error.message || "todo 가져오는 중 에러 발생")
}
}
const findbyDate = async (req, res, next) => {
const findbyDate = async (req, res) => {
try {
// Todo 페이지
const userId = req.userId
const { date } = req.query
if (date) {
console.log(" findbydate 날짜가 있을 때 실행", date, userId)
const findList = await Todo.findAll({ where: { [Op.and]: [{ date: { [Op.eq]: date } }, { userId: userId }] }, attributes: ['id', ['title', 'todoTitle'], ['date', 'todoDate'], 'done'] })
console.log("find==", findList)
req.todoList = findList
}
next()
const nonCheck = await Todo.findAll({ where: { [Op.and]: [{ done: false }, { date: { [Op.eq]: date } }, { userId: userId }] }, attributes: ['id', ['title', 'todoTitle'], ['date', 'todoDate'], 'done'], order: [['updatedAt', "DESC"]] })
const check = await Todo.findAll({ where: { [Op.and]: [{ done: true }, { date: { [Op.eq]: date } }, { userId: userId }] }, attributes: ['id', ['title', 'todoTitle'], ['date', 'todoDate'], 'done'], order: [['updatedAt', "DESC"]] })
check.forEach(el => nonCheck.push(el.dataValues))
return res.json(nonCheck)
} catch (error) {
return res.status(500).send(error.message || "todo 가져오는 중 에러 발생")
}
......@@ -37,22 +19,51 @@ const findbyDate = async (req, res, next) => {
const findforPercent = async (req, res) => {
try {
let doneTodo = null
let nonCheck = null
let check = null
const userId = req.userId
const { start, end } = req.query
if (end) {
const { count, rows } = await Todo.findAndCountAll({ where: { [Op.and]: [{ date: { [Op.eq]: start } }, { userId: userId }] } })
// weekly percent
nonCheck = await Todo.findAll({
where: { [Op.and]: [{ userId: userId }, { done: false }, { date: { [Op.between]: [start, end] } }] },
order: [['date']]
})
check = await Todo.findAll({
where: { [Op.and]: [{ userId: userId }, { done: true }, { date: { [Op.between]: [start, end] } }] },
order: [['date']]
})
const nonCheckCountList = countInList(nonCheck)
let checkCountList = countInList(check)
let percentList = nonCheckCountList.map(nonCheckEl => {
const findIdx = checkCountList.findIndex(el => el.date === nonCheckEl.date)
if (findIdx === -1) nonCheckEl['rate'] = 0
else {
nonCheckEl['rate'] = Math.round((checkCountList[findIdx].count / (nonCheckEl.count + checkCountList[findIdx].count)) * 100)
checkCountList.splice(findIdx, 1)
}
return nonCheckEl
})
if (checkCountList.length !== 0) {
checkCountList.forEach(el => el['rate'] = 100)
const sendList = percentList.concat(checkCountList).sort((pre, next) => {
if (pre.date < next.date) return -1
else if (pre.date > next.date) return 1
else return 0
})
return res.json(sendList)
} else return res.json(percentList)
} else {
// Menu
let percent = 0
console.log("findforPercent end 없음")
const nonCheck = await Todo.findAndCountAll({ where: { [Op.and]: [{ date: { [Op.eq]: start } }, { userId: userId }, { done: false }] } })
const check = await Todo.findAndCountAll({ where: { [Op.and]: [{ date: { [Op.eq]: start } }, { userId: userId }, { done: true }] } })
nonCheck = await Todo.findAndCountAll({ where: { [Op.and]: [{ date: { [Op.eq]: start } }, { userId: userId }, { done: false }] }, order: [['updatedAt', "DESC"]] })
check = await Todo.findAndCountAll({ where: { [Op.and]: [{ date: { [Op.eq]: start } }, { userId: userId }, { done: true }] }, order: [['updatedAt', "DESC"]] })
let total = nonCheck.count + check.count
check.rows.forEach(el => nonCheck.rows.push(el.dataValues))
console.log("non",nonCheck)
if (total === 0) percent = 0
else percent = Math.round((check.count / total)*100)
return res.json({ percent: percent, list: nonCheck.rows })
if (total !== 0) percent = Math.round((check.count / total) * 100)
if (nonCheck.count < 3) check.rows.forEach(el => nonCheck.rows.push(el.dataValues))
return res.json({ percent: percent, list: nonCheck.rows.slice(0, 3) })
}
} catch (error) {
return res.status(500).send(error.message || "todo 가져오는 중 에러 발생")
......@@ -75,9 +86,10 @@ const edit = async (req, res) => {
let updated = null
const userId = req.userId
const { todoId } = req.query
const { todoTitle, todoDate } = req.body
const { todoTitle, todoDate, done } = req.body
if (todoTitle) updated = await Todo.update({ title: todoTitle, date: todoDate }, { where: { [Op.and]: [{ id: todoId }, { userId: userId }] } })
else updated = await Todo.update({ date: todoDate }, { where: { [Op.and]: [{ id: todoId }, { userId: userId }] } })
else if (todoDate) updated = await Todo.update({ date: todoDate }, { where: { [Op.and]: [{ id: todoId }, { userId: userId }] } })
else updated = await Todo.update({ done: !done }, { where: { [Op.and]: [{ id: todoId }, { userId: userId }] } })
if (!updated) throw new Error("해당 todo의 일부 정보를 수정하는데 실패하였습니다.")
else return res.send(200)
} catch (error) {
......@@ -107,22 +119,22 @@ const getParams = async (req, res, next) => {
}
}
const send = async (req, res) => {
try {
const result = req.todoOne || req.todoList
return res.json(result)
} catch (error) {
return res.status(500).send(error.message || "todo 가져오는 중 에러 발생")
}
function countInList(list) {
const countList = list.reduce((acc, cur) => {
const findIdx = acc.findIndex(el => el.date === cur.dataValues.date)
if (findIdx === -1) acc.push({ date: cur.dataValues.date, count: 1 })
else acc[findIdx].count += 1
return acc
}, [])
return countList
}
export default {
findbyId,
findbyDate,
findforPercent,
create,
edit,
remove,
getParams,
send
getParams
}
\ No newline at end of file
......@@ -17,7 +17,6 @@ const getUser = async (req, res) => {
}
const signup = async (req, res) => {
console.log('server/signup req.body', req.body)
const { userId, password, userName, userStudNum } = req.body;
try {
const findId = await User.findOne({ where: { userID: userId } });
......@@ -39,7 +38,6 @@ const signup = async (req, res) => {
}
const login = async (req, res) => {
console.log('server/login req.body', req.body)
const { userId, password } = req.body;
try {
const user = await User.scope("withPassword").findOne({ where: { userID: userId } });
......
......@@ -34,11 +34,6 @@ const Plan = PlanModel(sequelize)
Schedule.belongsTo(User)
Subject.belongsTo(User)
Todo.belongsTo(User)
Subject.hasOne(Plan, {
onDelete: "CASCADE"
})
Plan.belongsTo(Subject)
export {
......
......@@ -7,6 +7,10 @@ router
.route("/")
.post(planCtrl.create)
router
.route("/check/:planId")
.put(planCtrl.putCk)
router
.route("/:planId")
.get(planCtrl.getOne)
......
......@@ -9,7 +9,7 @@ router
router
.route("/:userId")
.get(todoCtrl.findbyId, todoCtrl.findbyDate, todoCtrl.send)
.get(todoCtrl.findbyDate)
.post(todoCtrl.create)
.put(todoCtrl.edit)
.delete(todoCtrl.remove)
......
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