Skip to content

Commit

Permalink
Fix Bug 2
Browse files Browse the repository at this point in the history
  • Loading branch information
honux77 committed Sep 2, 2022
1 parent 6d6f501 commit 710d76a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
7 changes: 4 additions & 3 deletions db.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ const mydb = {
const [rows, fields] = await pool.query("select * from lotto");
rows.forEach((row) => {
console.log(
`No. ${row.id} ${row.message} [${row.nums.nums}] ${row.created}`
`No. ${row.id} ${row.name} ${row.message} [${row.nums.nums}] ${row.created}`
);
});
},
add: async function (message) {
add: async function (name, message) {
const l = { nums: lotto() };
await pool.execute("insert into lotto(message, nums) values (?, ?)", [
await pool.execute("insert into lotto(name, message, nums) values (?, ?, ?)", [
name,
message,
l,
]);
Expand Down
25 changes: 19 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
const { mydb } = require("./db.js");

const prompt =
"\nType some message:(dd : delete, q! : quit, 1 ~ 99 : auto generate) ";
"\n오늘의 응원 메시지를 입력해 주세요:(dd : 전부 삭제, q! : 종료, 1 ~ 200 : 숫자만큼 자동 생성) ";
const eline = "------------------------------------------------------";

const command = require("readline").createInterface({
input: process.stdin,
output: process.stdout,
});

console.log(prompt);
console.log("이름을 입력해 주세요.");

let name = "Mr. Lotto";
let begin = true;

command.on("line", async (line) => {
if (begin) {
name = line;
begin = false;
console.log(`${name} 님, ${prompt}`);
return;
}

let count = 1;
if (!isNaN(parseInt(line))) {
count = parseInt(line);
line = "Auto Generate Lotto";
line = "자동 생성된 로또 ";
}

if (line === "dd") {
console.log("이전 기록을 지웁니다.");
await mydb.clear();
line = "This is first message!";
line = "모두 대박 나세요!";
} else if (
line === "q!" ||
line === "exit" ||
line === "bye" ||
line.length == 0
) {
console.log("오늘도 좋은 하루 되세요!");
console.log("오늘도 좋은 하루 되세요 ≤^오^≥");
process.exit(0);
}

for (let i = 0; i < count; i++) {
await mydb.add(line);
if (i == 0)
await mydb.add(name, line);
else
await mydb.add(name, line + (i + 1));
}
await mydb.read();
console.log(eline);
Expand Down
1 change: 1 addition & 0 deletions init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ drop table if exists lotto;

create table lotto(
id int primary key auto_increment,
name varchar(64),
message varchar(255),
nums json,
created timestamp default current_timestamp
Expand Down
5 changes: 0 additions & 5 deletions lotto.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@ function shuffle() {

function lotto() {
shuffle();
console.log(a)
const l = a.slice(0, 6);
l.sort((a, b) => a - b);
return l;
}

for (let i = 0; i < 50; i++) {
console.log(lotto())
}

module.exports.lotto = lotto;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Simple Lotto using mysql",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"repository": {
Expand Down

0 comments on commit 710d76a

Please sign in to comment.