Showing
7 changed files
with
75 additions
and
84 deletions
... | @@ -19,6 +19,19 @@ | ... | @@ -19,6 +19,19 @@ |
19 | "kuler": "^2.0.0" | 19 | "kuler": "^2.0.0" |
20 | } | 20 | } |
21 | }, | 21 | }, |
22 | + "@types/mysql": { | ||
23 | + "version": "2.15.21", | ||
24 | + "resolved": "https://registry.npmjs.org/@types/mysql/-/mysql-2.15.21.tgz", | ||
25 | + "integrity": "sha512-NPotx5CVful7yB+qZbWtXL2fA4e7aEHkihHLjklc6ID8aq7bhguHgeIoC1EmSNTAuCgI6ZXrjt2ZSaXnYX0EUg==", | ||
26 | + "requires": { | ||
27 | + "@types/node": "*" | ||
28 | + } | ||
29 | + }, | ||
30 | + "@types/node": { | ||
31 | + "version": "17.0.41", | ||
32 | + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.41.tgz", | ||
33 | + "integrity": "sha512-xA6drNNeqb5YyV5fO3OAEsnXLfO7uF0whiOfPTz5AeDo8KeZFmODKnvwPymMNO8qE/an8pVY/O50tig2SQCrGw==" | ||
34 | + }, | ||
22 | "accepts": { | 35 | "accepts": { |
23 | "version": "1.3.8", | 36 | "version": "1.3.8", |
24 | "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", | 37 | "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", |
... | @@ -334,9 +347,9 @@ | ... | @@ -334,9 +347,9 @@ |
334 | "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==" | 347 | "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==" |
335 | }, | 348 | }, |
336 | "denque": { | 349 | "denque": { |
337 | - "version": "2.0.1", | 350 | + "version": "1.5.1", |
338 | - "resolved": "https://registry.npmjs.org/denque/-/denque-2.0.1.tgz", | 351 | + "resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz", |
339 | - "integrity": "sha512-tfiWc6BQLXNLpNiR5iGd0Ocu3P3VpxfzFiqubLgMfhfOw9WyvgJBd46CClNn9k3qfbjvT//0cf7AlYRX/OslMQ==" | 352 | + "integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw==" |
340 | }, | 353 | }, |
341 | "depd": { | 354 | "depd": { |
342 | "version": "2.0.0", | 355 | "version": "2.0.0", |
... | @@ -928,13 +941,14 @@ | ... | @@ -928,13 +941,14 @@ |
928 | } | 941 | } |
929 | }, | 942 | }, |
930 | "mysql2": { | 943 | "mysql2": { |
931 | - "version": "2.3.3", | 944 | + "version": "2.2.0", |
932 | - "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-2.3.3.tgz", | 945 | + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-2.2.0.tgz", |
933 | - "integrity": "sha512-wxJUev6LgMSgACDkb/InIFxDprRa6T95+VEoR+xPvtngtccNH2dGjEB/fVZ8yg1gWv1510c9CvXuJHi5zUm0ZA==", | 946 | + "integrity": "sha512-3DvnvXihGiFrq6oaMjGN+gR/oreZA5cA1bI7/yBAvReo2W2I6cHd8vfX/9mk9FQEebubxqB/4VAlIJTlnYUEEg==", |
934 | "requires": { | 947 | "requires": { |
935 | - "denque": "^2.0.1", | 948 | + "@types/mysql": "^2.15.7", |
949 | + "denque": "^1.4.1", | ||
936 | "generate-function": "^2.3.1", | 950 | "generate-function": "^2.3.1", |
937 | - "iconv-lite": "^0.6.3", | 951 | + "iconv-lite": "^0.6.2", |
938 | "long": "^4.0.0", | 952 | "long": "^4.0.0", |
939 | "lru-cache": "^6.0.0", | 953 | "lru-cache": "^6.0.0", |
940 | "named-placeholders": "^1.1.2", | 954 | "named-placeholders": "^1.1.2", | ... | ... |
... | @@ -17,7 +17,7 @@ | ... | @@ -17,7 +17,7 @@ |
17 | "jsonwebtoken": "^8.5.1", | 17 | "jsonwebtoken": "^8.5.1", |
18 | "method-override": "^3.0.0", | 18 | "method-override": "^3.0.0", |
19 | "mysql": "^2.18.1", | 19 | "mysql": "^2.18.1", |
20 | - "mysql2": "^2.0.0", | 20 | + "mysql2": "^2.2.0", |
21 | "regex-email": "^1.0.2", | 21 | "regex-email": "^1.0.2", |
22 | "request": "^2.88.2", | 22 | "request": "^2.88.2", |
23 | "winston": "^3.2.1", | 23 | "winston": "^3.2.1", | ... | ... |
... | @@ -14,7 +14,6 @@ class User { | ... | @@ -14,7 +14,6 @@ class User { |
14 | const client = this.body; | 14 | const client = this.body; |
15 | 15 | ||
16 | try { | 16 | try { |
17 | - const connection = await pool.getConnection(async (conn) => conn); | ||
18 | try { | 17 | try { |
19 | const {id, password} = await UserStorage.getUserInfo(connection, client.id); | 18 | const {id, password} = await UserStorage.getUserInfo(connection, client.id); |
20 | // console.log(id, password); | 19 | // console.log(id, password); |
... | @@ -39,19 +38,19 @@ class User { | ... | @@ -39,19 +38,19 @@ class User { |
39 | 38 | ||
40 | async register() { | 39 | async register() { |
41 | const client = this.body; | 40 | const client = this.body; |
42 | - | ||
43 | try { | 41 | try { |
44 | const connection = await pool.getConnection(async (conn) => conn); | 42 | const connection = await pool.getConnection(async (conn) => conn); |
43 | + // console.log(client); | ||
45 | try { | 44 | try { |
46 | const response = await UserStorage.save(connection, client); | 45 | const response = await UserStorage.save(connection, client); |
47 | - // console.log(response); | 46 | + // console.log("테스트2 : ", response); |
48 | return response; | 47 | return response; |
49 | - } catch (err) { | 48 | + } catch (err) { |
50 | - | 49 | + console.log(err); |
51 | - return {success: false, msg : err}; | 50 | + return {success: false, msg : err}; |
52 | - } finally { | 51 | + } finally { |
53 | - connection.release(); | 52 | + connection.release(); |
54 | - } | 53 | + } |
55 | } catch (err) { | 54 | } catch (err) { |
56 | logger.error(`usersaving DB Connection error\n: ${JSON.stringify(err)}`); | 55 | logger.error(`usersaving DB Connection error\n: ${JSON.stringify(err)}`); |
57 | return false; | 56 | return false; | ... | ... |
1 | 'use strict'; | 1 | 'use strict'; |
2 | + | ||
3 | +const { pool } = require("../config/db"); | ||
4 | + | ||
2 | //for DB CRUD | 5 | //for DB CRUD |
3 | -const pool = require("../config/db"); | 6 | + |
4 | 7 | ||
5 | class UserStorage { | 8 | class UserStorage { |
6 | constructor(body) { | 9 | constructor(body) { |
7 | this.body = body; | 10 | this.body = body; |
11 | + // this.connection = await pool.getConnection(async (conn) => conn); | ||
8 | } | 12 | } |
13 | + | ||
9 | // static getUsers(isAll, ...fields) {} | 14 | // static getUsers(isAll, ...fields) {} |
10 | static async getUserInfo(connection, id) { | 15 | static async getUserInfo(connection, id) { |
11 | return new Promise((resolve, reject) => { | 16 | return new Promise((resolve, reject) => { |
... | @@ -14,23 +19,28 @@ class UserStorage { | ... | @@ -14,23 +19,28 @@ class UserStorage { |
14 | if (err) reject(`${err}`); | 19 | if (err) reject(`${err}`); |
15 | // console.log(data[0]); | 20 | // console.log(data[0]); |
16 | resolve(data[0]); | 21 | resolve(data[0]); |
22 | + pool.releaseConnection(conn); | ||
17 | }); | 23 | }); |
18 | }); | 24 | }); |
19 | } | 25 | } |
20 | 26 | ||
21 | - static async save(connection, userInfo) { | 27 | + static async save (connection, userInfo) { |
22 | - return new Promise((resolve, reject) => { | 28 | + const query = "INSERT INTO users(id, name, password) VALUES(?, ?, ?);"; |
23 | - const query = "INSERT INTO users(id, name, password) VALUES(?, ?, ?);"; | 29 | + try { |
24 | - connection.query( | 30 | + const [rows] = await connection.query({ |
25 | - query, | 31 | + sql: query, |
26 | - [userInfo.id, userInfo.name, userInfo.password], | 32 | + timeout: 30000, |
27 | - (err, data) => { | 33 | + values: [userInfo.id, userInfo.name, userInfo.password] |
28 | - if (err) reject(`${err}`); | 34 | + }); |
29 | - // console.log(data[0]); | 35 | + // console.log(fields); |
30 | - resolve({ success: true}); | 36 | + if (rows.affectedRows) { |
31 | - } | 37 | + return {success: true}; |
32 | - ); | 38 | + } else { |
33 | - }); | 39 | + return {success: false}; |
40 | + } | ||
41 | + } catch (error) { | ||
42 | + console.log(error); | ||
43 | + } | ||
34 | } | 44 | } |
35 | 45 | ||
36 | } | 46 | } | ... | ... |
... | @@ -8,7 +8,7 @@ const id = document.querySelector("#id"), | ... | @@ -8,7 +8,7 @@ const id = document.querySelector("#id"), |
8 | 8 | ||
9 | registerBtn.addEventListener("click", register); | 9 | registerBtn.addEventListener("click", register); |
10 | 10 | ||
11 | -function register() { | 11 | +async function register() { |
12 | if(!id.value) { | 12 | if(!id.value) { |
13 | return alert("아이디를 입력해주세요.") | 13 | return alert("아이디를 입력해주세요.") |
14 | } | 14 | } |
... | @@ -27,28 +27,23 @@ function register() { | ... | @@ -27,28 +27,23 @@ function register() { |
27 | } | 27 | } |
28 | 28 | ||
29 | const req = { | 29 | const req = { |
30 | - id : id.value, | 30 | + id: id.value, |
31 | - name : name.value, | 31 | + name: name.value, |
32 | - password : password.value, | 32 | + password: password.value, |
33 | }; | 33 | }; |
34 | 34 | ||
35 | - fetch("/register", { | 35 | + console.log("id : ", req.id); |
36 | - method: "POST", | 36 | + try { |
37 | - headers: { | 37 | + const response = await fetch("/register", { |
38 | - "Content-Type": "application/json" | 38 | + method: "POST", |
39 | - }, | 39 | + headers: { |
40 | - body: JSON.stringify(req), | 40 | + "Content-Type": "application/json" |
41 | - }) | 41 | + }, |
42 | - .then((res) => res.json()) | 42 | + body: JSON.stringify(req), |
43 | - .then((res) => { | ||
44 | - if (res.success) { | ||
45 | - //성공하면 이동 | ||
46 | - location.href = "/login"; | ||
47 | - } else { | ||
48 | - alert(res.msg); | ||
49 | - } | ||
50 | - }) | ||
51 | - .catch((err) => { | ||
52 | - console.error("회원가입 중 에러 발생"); | ||
53 | }); | 43 | }); |
44 | + console.log("테스트 : ", response); | ||
45 | + } catch(e) { | ||
46 | + console.log(e); | ||
47 | + } | ||
48 | + | ||
54 | } | 49 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -31,6 +31,8 @@ const process = { | ... | @@ -31,6 +31,8 @@ const process = { |
31 | register: async (req, res) => { | 31 | register: async (req, res) => { |
32 | const user = new User(req.body); | 32 | const user = new User(req.body); |
33 | const response = await user.register(); | 33 | const response = await user.register(); |
34 | + // console.log(res.json(response)); | ||
35 | + // console.log(res.json(response).statusCode); => 이거도 잘 찍혔음. | ||
34 | return res.json(response); | 36 | return res.json(response); |
35 | }, | 37 | }, |
36 | 38 | ||
... | @@ -39,23 +41,6 @@ const process = { | ... | @@ -39,23 +41,6 @@ const process = { |
39 | // const response = await restaurant.restaurants(); | 41 | // const response = await restaurant.restaurants(); |
40 | // return res.json(response); | 42 | // return res.json(response); |
41 | // }, | 43 | // }, |
42 | - // const id = req.body.id, | ||
43 | - // password = req.body.password; | ||
44 | - // const users = UserStorage.getUsers("id", "password"); | ||
45 | - // // console.log(UserStorage.getUsers("id", "password","name")); | ||
46 | - // const response = {}; | ||
47 | - | ||
48 | - // if (users.id.includes(id)) { | ||
49 | - // const idx = users.id.indexOf(id); | ||
50 | - // if (users.password[idx] === password) { | ||
51 | - // response.success = true; | ||
52 | - // return res.json(response); | ||
53 | - // } | ||
54 | - // } | ||
55 | - | ||
56 | - // response.success = false; | ||
57 | - // response.msg = "로그인에 실패하였습니다." | ||
58 | - // return res.json(response); | ||
59 | }; | 44 | }; |
60 | 45 | ||
61 | module.exports = { | 46 | module.exports = { | ... | ... |
1 | module.exports = function (app) { | 1 | module.exports = function (app) { |
2 | //controller갖고있는 모듈 생성 | 2 | //controller갖고있는 모듈 생성 |
3 | const index = require("../../models/Restaurant"); | 3 | const index = require("../../models/Restaurant"); |
4 | + // const user = require("../../models/User"); | ||
4 | const jwtMiddleware = require("../../config/jwtMiddleware"); | 5 | const jwtMiddleware = require("../../config/jwtMiddleware"); |
5 | 6 | ||
6 | // 식당 목록 조회 | 7 | // 식당 목록 조회 |
7 | app.get("/restaurants", index.readRestaurants); | 8 | app.get("/restaurants", index.readRestaurants); |
8 | - // const express = require("express"); | ||
9 | - // const router = express.Router(); | ||
10 | - // const ctrl = require("./home.ctrl"); | ||
11 | - | ||
12 | - // router.get("/", ctrl.output.hello); | ||
13 | - // router.get("/login", ctrl.output.login); | ||
14 | - // router.get("/register", ctrl.output.register); | ||
15 | - | ||
16 | - | ||
17 | - // router.post("/login", ctrl.process.login); | ||
18 | - // router.post("/register", ctrl.process.register); | ||
19 | - | ||
20 | - // module.exports = router; | ||
21 | }; | 9 | }; |
22 | 10 | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment