-
Notifications
You must be signed in to change notification settings - Fork 1
/
controller.js
140 lines (99 loc) · 3 KB
/
controller.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import fetch from "node-fetch"
import fs from "fs/promises"
import path from "path"
import inquirer from "inquirer"
import { fetchStats } from "./getStats.js"
import { fetchSprites } from "./getSprites.js"
import { fetchArtwork } from "./getArtwork.js"
console.log('======= Hi, welcome to the Pokemon downloader =======');
const questions = [
{
type: 'input',
name: 'pokemonName',
message: 'Which Pokemon character would you like to know?',
},
{
type: 'checkbox',
message: 'Pokemon info to download',
name: 'infoWanted',
choices: [
new inquirer.Separator(' -- Options --'),
{
name: 'Stats',
},
{
name: 'Sprites',
},
{
name: 'Artwork',
},
],
},
]
const searchAgain = [
{
type: 'list',
name: 'repeatSearch',
message: 'Would you like to search another Pokemon character',
choices: [
{
name: 'Yes'
},
{
name: 'No'
},
]
},
]
// function that will repeat questions if the user wants to search for another pokemon
// functionFirst
const getAnswers = async () => {
const response = await inquirer.prompt(questions)
if(response.infoWanted[0] === 'Stats' && response.infoWanted[0, 1] === 'Sprites' && response.infoWanted[0, 2] === 'Artwork'){
return (fetchStats(response.pokemonName),
fetchSprites(response.pokemonName),
fetchArtwork(response.pokemonName))
} else if(response.infoWanted[0] === 'Stats'){
fetchStats(response.pokemonName)
} else if(response.infoWanted[0] === 'Sprites'){
return (fetchStats(response.pokemonName),
fetchSprites(response.pokemonName))
} else if(response.infoWanted[0] === 'Artwork') {
return (fetchStats(response.pokemonName),
fetchArtwork(response.pokemonName))
}
}
// functionSecond
const repeat = async () => {
const reply = await inquirer.prompt(searchAgain)
if(reply.repeatSearch === 'Yes'){
return getAnswers()
}
}
// function to get everything running
const controller = async () => {
const functionFirst = await getAnswers()
const functionSecond = await repeat()
return (functionFirst, functionSecond)
}
export { controller, getAnswers, repeat }
// function getAnswers() {
// return inquirer.prompt(questions).then((answers) => {
// // if the user wants to search again
// if(answers.repeatSearch === 'Yes' || answers.repeatSearch === 'yes'){
// return getAnswers()
// } else {
// // console.log(answers.pokemonName)
// console.log(answers.pokemonName)
// return fetchStats(answers.pokemonName)
// }
// })
// }
// inquirer.prompt(questions).then((answers) => {
// if(answers.repeat_search === 'Yes'){
// return inquirier.prompt(questions)
// } else {
// console.log(JSON.stringify(answers, null, ' '));
// }
// // console.log('\nOrder receipt:');
// });