Skip to content

Commit e784df3

Browse files
committed
fixed file patht for task 2 and 3
1 parent 8a0fa9f commit e784df3

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"scripts": {
88
"task1": "node ./src/task-1.js",
99
"task2": "node ./src/task-2.js",
10+
"task3": "node ./src/task-3.js",
1011
"test": "echo \"Error: no test specified\" && exit 1"
1112
},
1213
"type": "module",

src/task-2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import c from "chalk";
33
import { appendFile, mkdir } from "node:fs/promises";
44
import readline from "node:readline/promises";
55
const fileName = "people.txt";
6-
const dirPath = new URL("./../database/task-1", import.meta.url).pathname;
6+
const dirPath = new URL("./../database/task-2", import.meta.url).pathname;
77

88
console.log(c.yellow.bold("LOGIN: "));
99
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });

src/task-3.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { generateRandomUserDataString as newEntry } from "./generateRandomUserDataString.js";
2+
import c from "chalk";
3+
import { appendFile, mkdir } from "node:fs/promises";
4+
import readline from "node:readline/promises";
5+
const fileName = "people.txt";
6+
const dirPath = new URL("./../database/task-2", import.meta.url).pathname;
7+
8+
console.log(c.yellow.bold("LOGIN: "));
9+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
10+
let login = await rl.question(c.bgBlue.bold("username:") + " ");
11+
let password = await rl.question(c.bgBlue.bold("password:") + " ");
12+
13+
if (login.trim() !== "admin" || password.trim() !== "1234") {
14+
console.log(c.red("Neteisingi prisijungimo duomenys"));
15+
rl.close();
16+
} else {
17+
await mkdir(dirPath, { recursive: true });
18+
try {
19+
await appendFile(`${dirPath}/${fileName}`, newEntry()); ///kelias ne nuo sito failo, bet nuo project rooto??...
20+
console.log(c.green("Duomenys faile sėkmingai išsaugoti"));
21+
} catch (err) {
22+
console.error(err);
23+
} finally {
24+
rl.close();
25+
}
26+
}

0 commit comments

Comments
 (0)