-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
116 lines (116 loc) · 3.82 KB
/
Copy pathmain.js
File metadata and controls
116 lines (116 loc) · 3.82 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
#! /usr/bin/env node
import chalk from "chalk";
import inquirer from "inquirer";
console.log(chalk.bold.blueBright(`****Welcome to Student Management System App Created by Assad Sid****`));
let recordMain = [];
async function smsApp() {
let smsOperator = await inquirer.prompt({
name: "operator",
type: "list",
choices: ["Insert-Record", "Update-Record", "Delete-Record", "All-Record", "Exit"],
message: chalk.bold.yellowBright("Please Select your desired operator")
});
if (smsOperator.operator === "Insert-Record") {
insertRecord();
}
else if (smsOperator.operator === "All-Record") {
console.clear();
allRecordMain();
// console.log(recordMain)
}
else if (smsOperator.operator === "Update-Record") {
updateRecord();
}
else if (smsOperator.operator === "Delete-Record") {
deleteRecord();
}
else if (smsOperator.operator === "Exit") {
console.log(chalk.bold.blueBright(`****Thank you for using CLI based Student Management System****`));
}
}
;
async function insertRecord() {
let insertApp = await inquirer.prompt([{
name: "insertOp1",
type: "input",
message: "Please Enter Student ID:"
},
{
name: "insertOp2",
type: "input",
message: "Please Enter Student Name:"
},
{
name: "insertOp3",
type: "list",
choices: ["Science", "Commerce", "Arts"],
message: "Please Select Your Course"
}
]);
recordMain.push(`Student ID: ${insertApp.insertOp1}\nStudent Name: ${insertApp.insertOp2}\nCourses: ${insertApp.insertOp3}`);
console.clear();
console.log(chalk.bold.greenBright("***Your Information Recorded Successfully!***"));
smsApp();
}
async function allRecordMain() {
console.log(chalk.bold.yellowBright("****All Student Management Data Record****"));
recordMain.map((record1) => {
let recordIndex = recordMain.indexOf(record1) + 1;
console.log(chalk.bold.underline.greenBright(`\nStudent Data no.${recordIndex}`));
console.log(record1);
});
smsApp();
}
async function updateRecord() {
const editData = await inquirer.prompt([{
name: "editNum",
type: "number",
message: "Please Enter the Student Data No. you want to Change:"
},
{
name: "insertOp1",
type: "input",
message: "Please Enter New Student ID:"
},
{
name: "insertOp2",
type: "input",
message: "Please Enter New Student Name:"
},
{
name: "insertOp3",
type: "list",
choices: ["Science", "Commerce", "Arts"],
message: "Please Select the New Course:"
}
]);
let indexNum = editData.editNum;
let newIndex = (`Student ID: ${editData.insertOp1}\nStudent Name: ${editData.insertOp2}\nCourses: ${editData.insertOp3}`);
if (recordMain.length > 0) {
recordMain.splice(indexNum - 1, 1, newIndex);
}
else {
console.log(chalk.bold.redBright("***No Data Found***"));
}
console.clear();
console.log(chalk.bold.greenBright("****Information has been Updated into the Record****"));
smsApp();
}
async function deleteRecord() {
const delRecord = await inquirer.prompt({
name: "delRecs",
type: "input",
message: "Please Enter the Student Data No. you want to Delete:"
});
let dataNum = delRecord.delRecs;
if (recordMain.length > 0) {
recordMain.splice(dataNum - 1, 1);
}
else {
console.log(chalk.bold.redBright("***No Record Found***"));
}
console.clear();
console.log(chalk.bold.greenBright("***The Requested Student Data has been Deleted!***"));
smsApp();
}
smsApp();