-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
73 lines (70 loc) · 1.96 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const { writeJSONFile, readJSONFile } = require("./helpers");
const chalk = require("chalk");
const {
create,
destroy,
update,
index,
show,
filterByPlatform,
addCart,
cancelCart,
} = require("./src/game-controller");
const inform = console.log;
function run() {
const action = process.argv[2];
const game = process.argv[3];
let games = readJSONFile("./data/", "games.json");
let cart = readJSONFile("./data", "cart.json");
let updatingGameInventory = false;
let sendToCart = false;
let updatedGameList = [];
let iMediaCart = [];
switch (action) {
case "index":
const quickView = index(games);
inform(quickView);
break;
case "create":
inform(chalk.green("Game added to the collection."));
updatedGameList = create(games, game);
updatingGameInventory = true;
break;
case "show":
const immersiveView = show(games, game);
inform(immersiveView);
break;
case "update":
updatedGameList = update(games, game, process.argv[4]);
updatingGameInventory = true;
inform(updatedGameList);
break;
case "destroy":
updatedGameList = destroy(games, game);
updatingGameInventory = true;
break;
case "filterPlatform":
const platformResults = filterByPlatform(games, game)
inform(platformResults);
break;
case "addCart":
iMediaCart = addCart(games, cart, process.argv[4]);
sendToCart = true;
inform(chalk.greenBright("Game added to cart."));
break;
case "cancelCart":
iMediaCart = cancelCart(games, cart, process.argv[4]);
sendToCart = true;
inform(chalk.redBright("Game removed from cart."));
break;
default:
inform(chalk.bgRed.underline.blackBright("There was an error."));
if (updatingGameInventory) {
writeJSONFile("./data", "games.json", updatedGameList);
}
if (sendToCart) {
writeJSONFile("./data", "cart.json", iMediaCart);
}
}
}
run();