From c0d95ac8b6d19a18e9b2f426eb162c45a4e51c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EA=B0=80=EC=98=81?= Date: Fri, 12 Nov 2021 13:42:52 +0900 Subject: [PATCH] =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EB=AA=A8=EB=8B=AC=20?= =?UTF-8?q?=EB=B0=8F=20=EA=B3=84=ED=9A=8D=EC=A0=95=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/components/Modal/DeleteModal.js | 20 +++++++++++ .../src/components/StudyPlan/StudyPlanCard.js | 34 +++++++++++-------- .../src/components/StudyPlan/StudyPlanList.js | 2 +- server/controllers/subject.controller.js | 5 +-- server/db/index.js | 5 --- 5 files changed, 43 insertions(+), 23 deletions(-) create mode 100644 client/src/components/Modal/DeleteModal.js diff --git a/client/src/components/Modal/DeleteModal.js b/client/src/components/Modal/DeleteModal.js new file mode 100644 index 0000000..b877f14 --- /dev/null +++ b/client/src/components/Modal/DeleteModal.js @@ -0,0 +1,20 @@ +const DeleteModal = ({ handleClick, renListID }) => { + return ( + + ) +} + +export default DeleteModal; diff --git a/client/src/components/StudyPlan/StudyPlanCard.js b/client/src/components/StudyPlan/StudyPlanCard.js index bede003..3adc521 100644 --- a/client/src/components/StudyPlan/StudyPlanCard.js +++ b/client/src/components/StudyPlan/StudyPlanCard.js @@ -1,26 +1,30 @@ import { Link } from "react-router-dom"; import PlanLineList from "./PlanLineList"; +import DeleteModal from "../Modal/DeleteModal"; import style from "./studyplan.module.scss"; -const StudyPlanCard = ({ renList, handleClick, handleEdit }) => { +const StudyPlanCard = ({ renList, handleEdit, delSubject }) => { return ( - -
-
-
{renList.name}
-
- - handleClick(e, renList.id)}> - + <> + +
+
+
{renList.name}
+
+ + e.preventDefault()}> + +
+
+

{renList.prof && renList.room ? renList.prof + ' - ' + renList.room : (renList.prof || renList.room)}

+
+
-

{renList.prof && renList.room ? renList.prof + ' - ' + renList.room : (renList.prof || renList.room)}

-
- -
-
- + + + ) } diff --git a/client/src/components/StudyPlan/StudyPlanList.js b/client/src/components/StudyPlan/StudyPlanList.js index 3d524f5..4b3de44 100644 --- a/client/src/components/StudyPlan/StudyPlanList.js +++ b/client/src/components/StudyPlan/StudyPlanList.js @@ -58,7 +58,7 @@ const StudyPlanList = () => { return (
- {renList.length !== 0 ? renList.map((info, idx) => ) : null} + {renList.length !== 0 ? renList.map((info, idx) => ) : null}
diff --git a/server/controllers/subject.controller.js b/server/controllers/subject.controller.js index a0dc680..4b1aebb 100644 --- a/server/controllers/subject.controller.js +++ b/server/controllers/subject.controller.js @@ -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 }, order:[[sequelize.literal('checked, deadline'), 'ASC']] }) + 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 || "과목 삭제 에러 발생") diff --git a/server/db/index.js b/server/db/index.js index 276bf85..52de169 100644 --- a/server/db/index.js +++ b/server/db/index.js @@ -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 { -- GitLab