Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- [submission PR 1](https://github.com/wolfes-401-advanced-javascript/notes/pull/1)
- [submission PR 2](https://github.com/wolfes-401-advanced-javascript/notes/pull/2)
- [submission PR 3](https://github.com/wolfes-401-advanced-javascript/notes/pull/3)
- [ci/cd](http://xyz.com) (GitHub Actions)
- [back-end server url](http://xyz.com) (when applicable)
- [front-end application](http://xyz.com) (when applicable)
Expand All @@ -23,7 +24,7 @@ i.e.

#### How to initialize/run your application (where applicable)

- e.g. `npm start`
- `node index.js -a 'Hello world'`

#### How to use your library (where applicable)

Expand Down
19 changes: 19 additions & 0 deletions __tests__/input.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

jest.mock('minimist');
const minimist = require('minimist');
minimist.mockImplementation( () => {
return {
a: 'hello world',
};
});

const Input = require('../lib/input');

describe('Testing the input.js module to verify user input is successfully being received', () => {
it('should return an action and a payload', () => {
let test = new Input();
expect(test.payload).toBe('hello world');

});
});
23 changes: 21 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
'use strict';

console.log('App EXISTS');
require('dotenv').config();

const Input = require('./lib/input.js');
const Notes = require('./lib/notes.js');
const mongoose = require('mongoose');

mongoose.connect(process.env.MONGODB_ATLAS_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});

//let notes = new Notes(parsed);
const db = mongoose.connection;
db.on('open', () => {
});


const input = new Input;
// console.log(input);

if (input.validate(input) === true) {
let addNotes = new Notes(input);
addNotes.execute(input);
addNotes.add(input);

} else {
console.error('Houston, we have a problem!');
}
34 changes: 27 additions & 7 deletions lib/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,36 @@
const minimist = require('minimist');

const args = minimist(process.argv.slice(2));
console.log(args);
let action = (Object.keys(args).slice(1).toString());
console.log(action);
// console.log(args);
let action = (Object.keys(args).slice(1));

let message = (Object.values(args).slice(1));


class Input {
constructor(args, action) {
this.action = action;
this.payload = args.a;
constructor() {
this.action = action[0];
this.payload = message[0];
this.category = action[1];
this.catName = message[1];
}
validate() {
const ops = ['a', 'add'];
let validOp = false;
let validString = false;
const emptyString = '';

if (ops.includes(this.action)) validOp = true;
if (ops.includes(this.category)) validOp = true;
if (this.payload !== emptyString) validString = true;
if (this.catName !== emptyString) validString = true;

return validOp && validString;
}

}

console.log(new Input(args, action));


//console.log(new Input(args, action));
module.exports = Input;
10 changes: 10 additions & 0 deletions lib/model/notes-schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

const mongoose = require('mongoose');

const requestSchema = new mongoose.Schema({
category: {type: String, required: true},
note: {type: String, required: true},
});

module.exports = mongoose.model('request', requestSchema);
53 changes: 39 additions & 14 deletions lib/notes.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,54 @@
'use strict';

const mongoose = require('mongoose');
const Request = require('../lib/model/notes-schema.js');

mongoose.connect(process.env.MONGODB_ATLAS_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});

const newRequest = new Request({ url: 'http//localhost:3000', method: 'POST' });

class Notes {
constructor(action, payload) {
this.action = action;
this.payload = payload;
this.id = Math.floor(Math.random()*1000);
}
constructor(input) {
this.action = input.action;
this.payload = input.payload;
this.category = input.category;
this.catName = input.catName;
}

execute() {
const action = ['add', 'a'];
switch(action.includes(this.action)) {
case 'add' || 'a':
Notes.add;
break;

const action = ['add', 'a', 'list', 'l', 'delete', 'd'];
console.log(this.action);
switch (action.includes(this.action)) {
case 'add' || 'a':
Notes.add;
break;
case 'list' || 'l':
Notes.list;
break;
case 'delete' || 'd':
Notes.delete;
break;
default:
console.log('Uh Oh! We have a problem!');
break;
}
}

add() {
let note = new Notes(this.action, this.payload);
return note;
let note = new Notes(this.action, this.payload, this.category, this.catName);
// console.log(new Notes('add', 'testing'));
console.log('Adding note: ' + this.payload);

newRequest.save()
.then(results => console.log('saving: ', results))
.catch(err => console.log('ERROR'));
}
}


console.log(new Notes('add', 'testing'));


module.exports = Notes;
Loading