diff --git a/client/src/components/Modal/DeleteModal.js b/client/src/components/Modal/DeleteModal.js new file mode 100644 index 0000000000000000000000000000000000000000..b877f140b8f33f2b01e39445cf1a7dd7cbda27c3 --- /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 bede003988365d375e64b94bb23924ce094d40fc..3adc521a7d7f37c25f330b0425b3c06fda50568e 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 3d524f5e8c9d74faa27167509056c1c3c8d492de..4b3de44a0f8e24df4d651b3755114f1685a06e42 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 a0dc680f5429b30f940954834073b5e316776aa5..4b1aebb994383103869b9789a6d8d1da949edce9 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 276bf852cb195dc86cb7501f5d0b9e241f2d4749..52de16950392337b7afad58c0c06060a534f34c9 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 {