From 10d5a1c458dae960e9ca750c6535252a2f98a772 Mon Sep 17 00:00:00 2001 From: leedh430 <49018783+leedh430@users.noreply.github.com> Date: Wed, 11 Dec 2019 14:40:24 +0900 Subject: [PATCH 1/2] Update database.js --- src/backend/utils/database.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/backend/utils/database.js b/src/backend/utils/database.js index 01f542c..c92fa5a 100644 --- a/src/backend/utils/database.js +++ b/src/backend/utils/database.js @@ -83,12 +83,12 @@ const checkUserAuth = async (userId) => { const user = await query(sql, [userId]); if (user.length == 0) { - return false; + return NULL; } else { if (user[0].school_mail_auth == 1) { - return true; + return user[0].school_name; } else { - return false; + return NULL; } } }; @@ -242,10 +242,11 @@ const getItem = async (itemId) => { // item_detail: string, // caution -> item_image: JSON (use JSON.parse()), // item_date: date } - var sql = 'SELECT * FROM item WHERE itemId = ?'; + var sql = 'SELECT user.nickname, item.* FROM item INNER JOIN user ON item.userId = user.userId WHERE itemId = ?'; try{ const pickitem = await query(sql, [itemId]); return { + nickname: pickitem[0].nickname, userId: pickitem[0].userId, item_category: pickitem[0].category, itemId: pickitem[0].itemId, @@ -435,6 +436,25 @@ const deleteItem = async(itemId) => { } }; +const deleteUser = async(userId) => { + var sql = 'DELETE FROM user WHERE userId = ?'; + var params = [userId]; + try { + const deletion = await query(sql, params); + console.log(deletion); + return { + success: true, + message: "" + }; + }catch(err){ + console.log(err); + return{ + success: false, + message:"fail" + }; + } +}; + module.exports = { uploadImages, checkUserAuth, From fe20454e89bd6f85713285eefc87eb697aa700af Mon Sep 17 00:00:00 2001 From: leedh430 <49018783+leedh430@users.noreply.github.com> Date: Wed, 11 Dec 2019 15:08:11 +0900 Subject: [PATCH 2/2] Update database.js --- src/backend/utils/database.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/backend/utils/database.js b/src/backend/utils/database.js index c92fa5a..5a747ba 100644 --- a/src/backend/utils/database.js +++ b/src/backend/utils/database.js @@ -79,14 +79,23 @@ const generateToken = (seed="") => { }; const checkUserAuth = async (userId) => { - const sql = 'SELECT school_mail_auth FROM user WHERE userId = ?'; + const sql = 'SELECT * FROM user WHERE userId = ?'; const user = await query(sql, [userId]); if (user.length == 0) { return NULL; } else { if (user[0].school_mail_auth == 1) { - return user[0].school_name; + return { + userId: user[0].userId, + nickname: user[0].nickname, + school_name: user[0].school_name, + school_mail: user[0].school_mail, + school_mail_auth: user[0].school_mail_auth, + openprofile: user[0].openprofile, + report_count: user[0].report_count, + reliability_score: user[0].reliability_score + }; } else { return NULL; } @@ -140,19 +149,18 @@ const authPendingAuthentication = async (userId, token) => { }; // Placeholder -const registNewUser = async (userId, nickname, school_name, school_mail, timetable) => { +const registNewUser = async (userId, nickname, school_name, school_mail) => { // userId: string, nickname: string, school_name: string, school_mail: string, timetable: JSON object // Todo: Create new user with scheme { userId: string, // nickname: string, // school_name: string, // school_mail: string, // school_mail_auth: bool (false at init), - // caution -> timetable: stringfied JSON (use JSON.stringfy()), // openprofile: string (Null at init), // report_count: integer (0 at init), // reliability_score: integer (0 at init) } - var sql = 'INSERT INTO user(userId,nickname, school_name, school_mail, school_mail_auth, timetable, openprofile, report_count, reliability_score)VALUES(?,?,?,?,?,?,?,?,?)'; - var params = [userId, nickname, school_name, school_mail, '0', timetable, null, 0, 50]; + var sql = 'INSERT INTO user(userId,nickname, school_name, school_mail, school_mail_auth, openprofile, report_count, reliability_score)VALUES(?,?,?,?,?,?,?,?,?)'; + var params = [userId, nickname, school_name, school_mail, '0', null, 0, 50]; try { const insert = await query(sql, params); @@ -181,7 +189,6 @@ const getUser = async (userId) => { school_name: pickuser[0].school_name, school_mail: pickuser[0].school_mail, school_mail_auth: pickuser[0].school_mail_auth, - timetable: "",//JSON.parse(pickuser[0].timetable), openprofile: pickuser[0].openprofile, report_count: pickuser[0].report_count, reliability_score: pickuser[0].reliability_score @@ -195,7 +202,6 @@ const getUser = async (userId) => { // school_name: string, // school_mail: string, // school_mail_auth: bool, - // caution -> timetable: JSON (use JSON.parse()), // openprofile: string, // report_count: integer, // reliability_score: integer }