Hong

즐겨찾기 수정

......@@ -34,37 +34,44 @@ router.get('/show', function(req, res, next) {
router.post('/addfolder', function(req, res, next) {
let user_id = req.body.id;
let folder_name = req.body.name;
let checkfolder = 'SELECT * FROM Folder_Favorites JOIN folders ON (Folder_Favorites.folder_id = folders.folder_id AND Folder_Favorites.user_id = ? AND folders.folder_name = ?);';
connection.query(checkfolder, [user_id, folder_name], function(err, rows, fields) {
console.log(req.body);
let getid = 'SELECT folder_id FROM folders WHERE user_id = ? AND folder_name = ?;';
connection.query(getid, [user_id, folder_name], function(err, folder, fields) {
if (err) {
console.log('select error');
console.log('getid error');
res.status(400).send({ error: err });
} else {
if (!rows) {
let getid = 'SELECT folder_id FROM folders WHERE user_id = ? AND folder_name = ?;';
connection.query(getid, [user_id, folder_name], function(err, folder, fields) {
if (folder.length == 0) {
console.log('dont exist error');
res.status(400).send({ error: err });
} else {
let folder_id = folder[0].folder_id;
console.log(folder_id);
let checkfolder = 'SELECT * FROM Folder_Favorites WHERE user_id = ? AND folder_id = ?;';
connection.query(checkfolder, [user_id, folder_id], function(err, rows, fields) {
if (err) {
console.log('getid error');
console.log('select error');
res.status(400).send({ error: err });
} else {
let folder_id = folder[0].folder_id;
let sql = 'INSERT INTO Folder_Favorites (folder_id,user_id) values (?,?);';
connection.query(sql, [folder_id, user_id], function(err, result, fields) {
if (err) {
console.log('insert error');
res.status(400).send({ error: err });
} else {
res.status(200).send({
success: 'success',
error: ''
});
}
})
if (rows.length == 0) {
let sql = 'INSERT INTO Folder_Favorites (folder_id,user_id) values (?,?);';
connection.query(sql, [folder_id, user_id], function(err, result, fields) {
if (err) {
console.log('insert error');
res.status(400).send({ error: err });
} else {
res.status(200).send({
success: 'success',
error: ''
});
}
});
} else {
console.log('already exist error');
res.status(400).send({ error: err });
}
}
})
} else {
res.status(400).send({ error: err });
});
}
}
});
......@@ -73,21 +80,21 @@ router.post('/addfolder', function(req, res, next) {
router.post('/addfile', function(req, res, next) {
let user_id = req.body.id;
let file_name = req.body.name;
let checkfile = 'SELECT * FROM File_Favorites JOIN files ON (File_Favorites.file_id = files.file_id AND File_Favorites.user_id = ? AND files.file_name = ?);';
connection.query(checkfile, [user_id, file_name], function(err, rows, fields) {
let getid = 'SELECT file_id FROM files WHERE user_id = ? AND file_name = ?;';
connection.query(getid, [user_id, file_name], function(err, file, fields) {
if (err) {
console.log('select error');
console.log('getid error');
res.status(400).send({ error: err });
} else {
if (!rows) {
let getid = 'SELECT file_id FROM files WHERE user_id = ? AND file_name = ?;';
connection.query(getid, [user_id, folder_name], function(err, file, fields) {
if (err) {
console.log('getid error');
res.status(400).send({ error: err });
} else {
let file_id = file[0].file_id;
let file_id = file[0].file_id;
let checkfile = 'SELECT * FROM File_Favorites WHERE user_id = ? AND file_id = ?;';
connection.query(checkfile, [user_id, file_id], function(err, rows, fields) {
if (err) {
console.log('select error');
res.status(400).send({ error: err });
} else {
if (rows.length == 0) {
let sql = 'INSERT INTO File_Favorites (file_id,user_id) values (?,?);';
connection.query(sql, [file_id, user_id], function(err, result, fields) {
if (err) {
......@@ -99,12 +106,13 @@ router.post('/addfile', function(req, res, next) {
error: ''
});
}
})
});
} else {
console.log('already exist error');
res.status(400).send({ error: err });
}
})
} else {
res.status(400).send({ error: err });
}
}
});
}
});
});
......@@ -119,7 +127,7 @@ router.post('/delfolder', function(req, res, next) {
console.log('select error');
res.status(400).send({ error: err });
} else {
if (rows) {
if (rows.length != 0) {
let folder_id = rows[0].folder_id;
let sql = 'DELETE Folder_Favorites WHERE folder_id = ? AND user_id = ?;';
connection.query(sql, [folder_id, user_id], function(err, result, fields) {
......@@ -134,13 +142,14 @@ router.post('/delfolder', function(req, res, next) {
}
})
} else {
console.log('dont exist error');
res.status(400).send({ error: err });
}
}
});
});
router.post('/addfile', function(req, res, next) {
router.post('/delfile', function(req, res, next) {
let user_id = req.body.id;
let file_name = req.body.name;
let checkfile = 'SELECT * FROM File_Favorites JOIN files ON (File_Favorites.file_id = files.file_id AND File_Favorites.user_id = ? AND files.file_name = ?);';
......@@ -150,7 +159,7 @@ router.post('/addfile', function(req, res, next) {
console.log('select error');
res.status(400).send({ error: err });
} else {
if (!rows) {
if (rows.length != 0) {
let file_id = rows[0].file_id;
let sql = 'DELETE File_Favorites WHERE file_id = ? AND user_id = ?;';
connection.query(sql, [file_id, user_id], function(err, result, fields) {
......@@ -165,6 +174,7 @@ router.post('/addfile', function(req, res, next) {
}
})
} else {
console.log('dont exist error');
res.status(400).send({ error: err });
}
}
......