Skip to content

Commit ee38abb

Browse files
committed
revision 1
1 parent 42b8909 commit ee38abb

11 files changed

+3777
-125
lines changed

commands-bkup.js

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env node
2+
const program = require('commander');
3+
const { prompt } = require('inquirer');
4+
const {
5+
getList,
6+
} = require('./index');
7+
8+
// Customer Questions
9+
const questions = [
10+
{
11+
type: 'input',
12+
name: 'firstname',
13+
message: 'Customer First Name'
14+
},
15+
{
16+
type: 'input',
17+
name: 'lastname',
18+
message: 'Customer Last Name'
19+
},
20+
{
21+
type: 'input',
22+
name: 'phone',
23+
message: 'Customer Phone Number'
24+
},
25+
{
26+
type: 'input',
27+
name: 'email',
28+
message: 'Customer Email Address'
29+
}
30+
];
31+
32+
program
33+
.version('1.0.0')
34+
.description('Client Management System')
35+
36+
// program
37+
// .command('add <firstname> <lastname> <phone> <email>')
38+
// .alias('a')
39+
// .description('Add a customer')
40+
// .action((firstname, lastname, phone, email) => {
41+
// addCustomer({firstname, lastname, phone, email});
42+
// });
43+
44+
// Add Command
45+
program
46+
.command('add')
47+
.alias('a')
48+
.description('Add a customer')
49+
.action(() => {
50+
prompt(questions).then(answers => addCustomer(answers));
51+
});
52+
53+
// Find Command
54+
program
55+
.command('find <name>')
56+
.alias('f')
57+
.description('Find a customer')
58+
.action(name => findCustomer(name));
59+
60+
// Update Command
61+
program
62+
.command('update <_id>')
63+
.alias('u')
64+
.description('Update a customer')
65+
.action(_id => {
66+
prompt(questions).then(answers => updateCustomer(_id, answers));
67+
});
68+
69+
// Remove Command
70+
program
71+
.command('remove <_id>')
72+
.alias('r')
73+
.description('Remove a customer')
74+
.action(_id => removeCustomer(_id));
75+
76+
// List Command
77+
program
78+
.command('list')
79+
.alias('l')
80+
.description('List all customers')
81+
.action(() => getList());
82+
83+
program.parse(process.argv);

commands.js

100644100755
+22-47
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env node
2+
23
const program = require('commander');
34
const { prompt } = require('inquirer');
5+
46
const {
5-
addCustomer,
6-
findCustomer,
7-
updateCustomer,
8-
removeCustomer,
9-
listCustomers
10-
} = require('./index');
7+
pwd,
8+
} = require('./vessel');
9+
10+
const docker = require('./docker');
1111

1212
// Customer Questions
1313
const questions = [
@@ -34,54 +34,29 @@ const questions = [
3434
];
3535

3636
program
37-
.version('1.0.0')
37+
.version('1.0.0', '-v, --version')
3838
.description('Client Management System')
3939

40-
// program
41-
// .command('add <firstname> <lastname> <phone> <email>')
42-
// .alias('a')
43-
// .description('Add a customer')
44-
// .action((firstname, lastname, phone, email) => {
45-
// addCustomer({firstname, lastname, phone, email});
46-
// });
47-
48-
// Add Command
49-
program
50-
.command('add')
51-
.alias('a')
52-
.description('Add a customer')
53-
.action(() => {
54-
prompt(questions).then(answers => addCustomer(answers));
55-
});
56-
57-
// Find Command
40+
// List Command
5841
program
59-
.command('find <name>')
60-
.alias('f')
61-
.description('Find a customer')
62-
.action(name => findCustomer(name));
42+
.command('list')
43+
.alias('l')
44+
.description('List all customers')
45+
.action(() => getList());
6346

64-
// Update Command
6547
program
66-
.command('update <_id>')
67-
.alias('u')
68-
.description('Update a customer')
69-
.action(_id => {
70-
prompt(questions).then(answers => updateCustomer(_id, answers));
71-
});
48+
.command('pwd').alias('p')
49+
.description('print working directory')
50+
.action(() => pwd());
7251

73-
// Remove Command
7452
program
75-
.command('remove <_id>')
76-
.alias('r')
77-
.description('Remove a customer')
78-
.action(_id => removeCustomer(_id));
53+
.command('start').alias('sta')
54+
.description('start docker')
55+
.action(() => docker.start());
7956

80-
// List Command
8157
program
82-
.command('list')
83-
.alias('l')
84-
.description('List all customers')
85-
.action(() => listCustomers());
58+
.command('stop').alias('sto')
59+
.description('stop docker')
60+
.action(() => docker.stop());
8661

87-
program.parse(process.argv);
62+
program.parse(process.argv);

db/sqlite.db

Whitespace-only changes.

db/test.db

864 KB
Binary file not shown.

docker.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const sh = require('shelljs')
2+
let _compose = 'docker-compose '
3+
4+
const start = () => sh.exec(_compose + 'up -d')
5+
const stop = () => sh.exec(_compose + 'down')
6+
7+
module.exports = { start, stop }

index.js

+19-63
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,24 @@
1-
const mongoose = require('mongoose');
2-
3-
// Map global promise - get rid of warning
4-
mongoose.Promise = global.Promise;
5-
// Connect to db
6-
const db = mongoose.connect('mongodb://localhost:27017/customercli', {
7-
useMongoClient: true
1+
const sqlite3 = require('sqlite3').verbose();
2+
3+
// open database in memory
4+
let db = new sqlite3.Database('./db/test.db', (err) => {
5+
if (err) {
6+
return console.error(err.message);
7+
}
8+
console.log('Connected to the SQlite database.');
89
});
910

10-
// Import model
11-
const Customer = require('./models/customer');
12-
13-
// Add Customer
14-
const addCustomer = (customer) => {
15-
Customer.create(customer).then(customer => {
16-
console.info('New Customer Added');
17-
db.close();
18-
});
19-
}
20-
21-
// Find Customer
22-
const findCustomer = (name) => {
23-
// Make case insensitive
24-
const search = new RegExp(name, 'i');
25-
Customer.find({$or: [{firstname: search}, {lastname: search}]})
26-
.then(customer => {
27-
console.info(customer);
28-
console.info(`${customer.length} matches`);
29-
db.close();
30-
});
31-
}
32-
33-
// Update Customer
34-
const updateCustomer = (_id, customer) => {
35-
Customer.update({ _id }, customer)
36-
.then(customer => {
37-
console.info('Customer Updated');
38-
db.close();
11+
12+
const getList = () => {
13+
let sql = 'SELECT DISTINCT Name name FROM playlists ORDER BY name';
14+
db.all(sql, [], (err, rows) => {
15+
if (err) {
16+
throw err;
17+
}
18+
rows.forEach((row) => {
19+
console.log(row.name);
20+
});
3921
});
4022
}
4123

42-
// Remove Customer
43-
const removeCustomer = (_id) => {
44-
Customer.remove({ _id })
45-
.then(customer => {
46-
console.info('Customer Removed');
47-
db.close();
48-
});
49-
}
50-
51-
// List Customers
52-
const listCustomers = () => {
53-
Customer.find()
54-
.then(customers => {
55-
console.info(customers);
56-
console.info(`${customers.length} customers`);
57-
db.close();
58-
});
59-
}
60-
61-
// Export All Methods
62-
module.exports = {
63-
addCustomer,
64-
findCustomer,
65-
updateCustomer,
66-
removeCustomer,
67-
listCustomers
68-
}
24+
module.exports = { getList }

models/customer.js

-12
This file was deleted.

0 commit comments

Comments
 (0)