Skip to content

Commit 5c6da65

Browse files
committed
fix: path db
1 parent 33dae80 commit 5c6da65

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

database.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
[
22
{
33
"id": 1,
4-
"vehicles": ["Motocicleta", "Carro", "Caminhão"],
4+
"vehicles": [
5+
"Motocicleta",
6+
"Carro",
7+
"Caminhão"
8+
],
59
"kmTraveled": 10000,
610
"from": "2009-01-01",
711
"to": "2020-11-26"
12+
},
13+
{
14+
"id": "2",
15+
"vehicles": [
16+
"aviao"
17+
],
18+
"kmTraveled": "2000",
19+
"from": "2022-02-02",
20+
"to": "2022-06-06"
821
}
9-
]
22+
]

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import database from "./../database.json" assert { type: "json" };
22
import Person from "./persons.js";
3+
import { save } from "./repository.js";
34
import TerminalController from "./terminal.controller.js";
45

56
const DEFAULT_LANG = "pt-BR";

src/repository.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import { writeFile, readFile } from "fs/promises";
22

33
export const save = async (data) => {
4-
const { pathname: databaseFile } = new URL(
5-
"./../database.json",
6-
import.meta.url
7-
);
8-
const currentData = JSON.parse(await readFile(databaseFile));
4+
const currentData = JSON.parse(await readFile("./database.json"));
95
currentData.push(data);
106

11-
await writeFile(databaseFile, JSON.stringify(currentData, null, 2));
7+
await writeFile("./database.json", JSON.stringify(currentData, null, 2));
128
};

0 commit comments

Comments
 (0)