-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinquirer.js
More file actions
164 lines (128 loc) · 3.38 KB
/
inquirer.js
File metadata and controls
164 lines (128 loc) · 3.38 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
global.__basepath = process.cwd();
global.app = new require("express")();
require("./lib/helpers");
let logger=require("./app/helpers/Logger");
/* Configurations */
app.loadConfig();
let inquirer = require('inquirer');
let PushNotification = require("./app/services/PushNotification");
const initialQuestions = [
{
type: 'rawlist',
name: 'choices',
message: "What do you want ?",
choices: [
{
name: 'Send push on iPhone',
value: 1
},
{
name: 'Send push on Android',
value: 2
},
new inquirer.Separator(),
{
name: 'Add payment',
value: 3
},
{
name: 'Add Lang',
value: 4
}
]
}
/*,
{
type: 'input',
name: 'last_name',
message: "What's your last name",
default: function() {
return 'Doe';
}
},
{
type: 'input',
name: 'phone',
message: "What's your phone number",
validate: function(value) {
let pass = value.match(
/^([01]{1})?[-.\s]?\(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?){1}(?:\d+)?)?$/i
);
if (pass) {
return true;
}
return 'Please enter a valid phone number';
}
}*/
];
function initial(){
inquirer.prompt(initialQuestions).then(answers => {
const choices = answers.choices;
logger.info("answers : "+answers);
// logger.info(choices);
switch (choices) {
case 1 :
askPushIOS();
break;
case 2 :
askPushAndroid();
break;
case 3 :
addpayment();
break;
default :
initial();
break;
}
});
}
const pushiOSQuestions = [
{
type: 'input',
name: 'data',
message: "Please Write your iPhone token",
validate: function(value) {
if (value.length>3) {
return true;
}
return 'Please enter a valid iPhone token';
}
}
];
function askPushIOS(){
inquirer.prompt(pushiOSQuestions).then(answers => {
const push = answers.data;
logger.info("answers : "+push);
PushNotification.sendios(push,"Hey","Testing 123");
initial();
});
}
function askPushAndroid(){
inquirer.prompt(pushiOSQuestions).then(answers => {
const push = answers.data;
logger.info("answers : "+push);
PushNotification.sendandroid( push,"Hey","from","full name","msgid","Testing 123");
initial();
});
}
const paymentQuestions = [
{
type: 'input',
name: 'data',
message: "Please Write your credit for payment"
}
];
function addpayment(){
inquirer.prompt(paymentQuestions).then(answers => {
const data = answers.data;
logger.info("answers : "+data);
let p = new Payment();
p.teacher = "5c29333c8f46ee10af7c70dc";
p.language = "5c29333c8f46ee10af7c70dc";
p.student = "5c29333c8f46ee10af7c70dc";
p.credit = data;
p.save();
initial();
});
}
initial();