Commit b2869ee6 authored by Kim, Subin's avatar Kim, Subin
Browse files

Menu check

parent 55179450
......@@ -19,8 +19,18 @@ const Menu = () => {
try {
setError("")
const result = await todoApi.getTodopercent(user.id, moment().format("YYYY-MM-DD"))
console.log("client resList",result)
setTodoList({...todoList, ...result})
setTodoList({ ...todoList, ...result })
} catch (error) {
catchErrors(error, setError)
}
}
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)
todayTodo()
} catch (error) {
catchErrors(error, setError)
}
......@@ -41,13 +51,11 @@ const Menu = () => {
<div className="d-flex flex-column justify-content-between flex-grow-1 py-4 ps-3 text-dark" >
<div className="user-select-none w-75 ps-3">
<h2 className="mb-4">To-do</h2>
{todoList.list.length!==0 ? todoList.list.map((todo, idx) => {
if (idx <= 2) return <div className="d-flex">
{todoList.list.length !== 0 ? todoList.list.map((todo, idx) => <div className="d-flex">
<p className={`form-check-label border-bottom border-2 text-nowrap fs-5 pb-1 me-3 ${styles.title}`}>{todo.title}</p>
<input className={`form-check-input rounded-0 border-dark shadow-none mt-1 ${styles.checkBox}`} type="checkbox" id="inlineCheckbox1" aria-label="checkbox" checked={todo.done} />
</div>
}) : null}
<Link className="d-flex justify-content-center text-dark text-decoration-none" to={`/todo/${moment().format("YYYY-MM-DD")}`}>
<input className={`form-check-input rounded-0 border-dark shadow-none mt-1 ${styles.checkBox}`} type="checkbox" id={"todoCheck" + idx} value={todo.done} aria-label="checkbox" onClick={(e) => checkFn(e, todo.id)} checked={todo.done} />
</div>) : <div className="text-center border-bottom border-2 pb-1">오늘의 Todo를 등록해 보세요!</div>}
<Link className="d-flex justify-content-center text-dark text-decoration-none mt-2" to={`/todo/${moment().format("YYYY-MM-DD")}`}>
<i className="bi bi-plus-lg me-2"></i>
<p className="mb-0">더보기</p>
</Link>
......
......@@ -37,24 +37,26 @@ const findbyDate = async (req, res, next) => {
const findforPercent = async (req, res) => {
try {
let doneTodo = null
let sendList = null
const userId = req.userId
const { start, end } = req.query
if (end) {
// weekly에서 불러올 todoList
console.log("week 실행하냐")
const findList= await Todo.findAndCountAll({ where: { [Op.and]: [{ userId: userId }, { date: [start, end] }] }, group: ['date'] })
console.log("week findList",findList)
// const findList = await Todo.findAndCountAll({ where: { [Op.and]: [{ userId: userId }, { date: [start, end] }] }, order: [[]] group: ['date'] })
// console.log("week findList", findList)
} 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 }] }, order: [['updatedAt', "DESC"]] })
const 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 (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 가져오는 중 에러 발생")
......@@ -77,9 +79,11 @@ 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
console.log("done==",done, userId, todoId)
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) {
......
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