Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Server/Account/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ manager.serialCheck = function (serial, callback) {
let response = {
error: false,
available: false
}
};
let JSONResponse;
conn.query("select * from account where uid=? and id is null and password is null", serial, function (err, rows) {
if (err) {
Expand All @@ -23,7 +23,7 @@ manager.idCheck = function (id, callback) {
let response = {
error: false,
available: false
}
};
let JSONResponse;
conn.query("select * from account where id=?", id, function (err, rows) {
if (err) {
Expand All @@ -40,7 +40,7 @@ manager.emailCheck = function (email, callback) {
let response = {
error: false,
available: false
}
};
let JSONResponse;
conn.query("select * from account where email=?", email, function (err, rows) {
if (err) {
Expand All @@ -57,7 +57,7 @@ manager.signUp = function (serial, id, password, email, callback) {
let response = {
error: false,
success: false
}
};
let JSONResponse;
conn.query("update account set id=?, password=?, email=? where uid = ?", [id, password, email, serial], function (err, result) {
if (err) {
Expand Down Expand Up @@ -90,7 +90,7 @@ manager.findAll = function (callback) {
let response = {
error: false,
accounts: []
}
};
let JSONResponse;
conn.query("select * from account", function (err, rows) {
if (err) {
Expand All @@ -113,7 +113,7 @@ manager.getUserInfo = function (uid, callback) {
error: false,
user: null,
circle: null
}
};
let JSONResponse;
console.log(uid);
conn.query("select a.name, c.name as circle from account as a inner join circle as c on a.circle_id = c.id where a.uid = ?", uid, function (err, rows) {
Expand Down
5 changes: 3 additions & 2 deletions Server/Account/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ router.route('/account/logout').post(function (req, res) {

});

router.route('/account/getCircleInfo').post(function (req, res) {
router.route('/account/getUserInfo').post(function (req, res) {
if (!req.session.user) {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.writeHead(200, { 'Content-Type': 'application/json' });
res.write(JSON.stringify({
session: false
}));
Expand All @@ -106,4 +106,5 @@ router.route('/account/getCircleInfo').post(function (req, res) {
res.end();
});
});

module.exports = router;
30 changes: 29 additions & 1 deletion Server/Circle/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ manager.found = function (name, uid, intro, callback) {
session: true,
error: false,
success: false
}
};
let JSONResponse;
conn.query("insert into circle values((select count(c.name)+1 from circle as c),?,?,?)", [name, uid, intro], function (err, result) {
if (err) response.error = true;
Expand All @@ -64,4 +64,32 @@ manager.found = function (name, uid, intro, callback) {
});
}

manager.getCircle = function (circle_id, callback) {
let response = {
session: true,
error: false,
leader: null,
name: []
};
let JSONResponse;
let leaderNum;
conn.query("select name,num from account where num = (select leaderNum from circle where id=?)", circle_id, function (err, rows) {
if (err) response.error = true;
else if (rows.length == 1) {
leaderNum = rows[0].num;
response.leader = rows[0].name;
conn.query("select name from account where circle_id=? and num != ? order by name", [circle_id, leaderNum], function (err, rows) {
if (err) response.error = true;
else if (rows.length > 0) {
for (var i = 0; i < rows.length; i++) {
response.name.push(rows[i].name);
}
}
JSONResponse = JSON.stringify(response);
callback(JSONResponse);
});
}
});
}

module.exports = manager;
22 changes: 20 additions & 2 deletions Server/Circle/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ router.route('/circle/canFound').post(function (req, res) {
response.session = true;
if (!req.session.user.circle_id) {
response.able = true;
}
}
}
res.writeHead(200, { 'Content-Type': 'application/json' });
res.writeHead(200, { 'Content-Type': 'application/json' });
res.write(JSON.stringify(response));
res.end();
});
Expand All @@ -45,4 +45,22 @@ router.route('/circle/found').post(function (req, res) {
});
});

router.route('/circle/getCircle').post(function (req, res) {
if (!req.session.user) {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.write(JSON.stringify({
session: false
}));
res.end();
return;
}
let circle_id = req.session.user.circle_id;
console.log(circle_id);
manager.getCircle(circle_id, function (JSONResponse) {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.write(JSONResponse);
res.end();
})
});

module.exports = router;
2 changes: 1 addition & 1 deletion Server/DBConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let mysql = require('mysql');
let conn = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
password: "hy980615",
database: "Arirang"
});

Expand Down