Skip to content

Commit

Permalink
[#9] fix - jjim api ์ˆ˜์ •
Browse files Browse the repository at this point in the history
jjim id๋กœ ๋ณ€๊ฒฝํ•˜๋„๋ก
  • Loading branch information
nohgijin committed Jan 16, 2021
1 parent 2bdc5d5 commit bc89d4a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion db/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async function getProjectDetail({ projectId }) {
//ํ”„๋กœ์ ํŠธ ์ฐœ ์—ฌ๋ถ€ ์กฐํšŒ
async function getUserJjim({ projectId, userId }) {
const [rows, fields] = await connection.query(
`SELECT * from jjim INNER JOIN project ON project.id=jjim.project_id WHERE jjim.user_id=${userId} and project.id=${projectId}`
`SELECT *,jjim.id as jjim_id from jjim INNER JOIN project ON project.id=jjim.project_id WHERE jjim.user_id=${userId} and project.id=${projectId}`
);
return rows;
}
Expand Down
9 changes: 4 additions & 5 deletions db/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function deleteCart(req) {
//์ฐœ ์กฐํšŒ
async function getJjim(req) {
let [rows, fields] = await connection.query(
`SELECT *,jjim.id as jjim_id FROM project INNER JOIN jjim ON project.id=jjim.project_id WHERE user_id=${req.user.id}`
`SELECT *,jjim.id as jjim_id FROM project_detail INNER JOIN jjim ON project_detail.id=jjim.project_id WHERE user_id=${req.user.id}`
);
return rows;
}
Expand All @@ -95,10 +95,9 @@ async function addJjim({ date, projectId, userId }) {
}

//์ฐœ ์‚ญ์ œ
async function deleteJjim({ projectId, userId }) {
const query = mysql.format(
`DELETE FROM jjim WHERE project_id = ${projectId} AND user_id = ${userId}`
);
async function deleteJjim(req) {
const jjimId = req.body.jjimId;
const query = mysql.format(`DELETE FROM jjim WHERE id = ${jjimId}`);
let [rows, fields] = await connection.query(query);
return rows;
}
Expand Down
4 changes: 2 additions & 2 deletions routes/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ router.get("/:projectId/jjim", async function (req, res, next) {
const projectId = req.params.projectId;
const userId = 3;
const rows = await getUserJjim({ projectId, userId });
if (rows.length != 0) res.json({ success: true });
res.json({ success: false });
if (rows.length != 0) res.json(rows[0]);
else res.json({ success: false });
});

module.exports = router;
9 changes: 2 additions & 7 deletions routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ router.get("/jjim", async function (req, res, next) {

//์ฐœ ์ถ”๊ฐ€
router.post("/jjim", async function (req, res, next) {
const projectId = parseInt(req.body.projectId);
const projectId = req.body.projectId;
const userId = 3;
await addJjim({
date: new Date(),
Expand All @@ -122,12 +122,7 @@ router.post("/jjim", async function (req, res, next) {

//์ฐœ ์‚ญ์ œ
router.delete("/jjim", async function (req, res, next) {
const projectId = parseInt(req.body.projectId);
const userId = 3;
await deleteJjim({
projectId: projectId,
userId: userId,
});
await deleteJjim(req);
res.json({ success: true });
});

Expand Down

0 comments on commit bc89d4a

Please sign in to comment.