Skip to content

Eric Whitcomb#481

Open
ericwhitcomb wants to merge 27 commits into
bloominstituteoftechnology:masterfrom
ericwhitcomb:master
Open

Eric Whitcomb#481
ericwhitcomb wants to merge 27 commits into
bloominstituteoftechnology:masterfrom
ericwhitcomb:master

Conversation

@ericwhitcomb

Copy link
Copy Markdown

@ericwhitcomb

Copy link
Copy Markdown
Author

@ericwhitcomb ericwhitcomb changed the title Forked, cloned, and set up Trello board Eric Whitcomb Feb 14, 2019
@ericwhitcomb

Copy link
Copy Markdown
Author

Link to frontend project pull request-
bloominstituteoftechnology/front-end-project-week#604

Link to frontend deployed on netlify-
https://5c6b95c77eb72fce777d19bb--vibrant-khorana-3f87dc.netlify.com/

Link to backend deployed on heroku-
https://lambda-notes-be-eric-whitcomb.herokuapp.com/

@ericwhitcomb

ericwhitcomb commented Feb 19, 2019

Copy link
Copy Markdown
Author

Should be done with MVP and on to stretch goals

Comment thread data/models/noteModel.js

const get = async (id) => {
if (id) {
const note = await db('notes').where('id', id);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure you can use .first()? instead of having that if statement

Suggested change
const note = await db('notes').where('id', id);
const note = await db('notes').where('id', id).first();

Comment thread data/models/noteModel.js
if (note.length) {
return note[0];
} else {
const e = new Error("id does not exist");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be easiest just to do this all on one line

Suggested change
const e = new Error("id does not exist");
throw new Error("id does not exist");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you won't need the next two lines

Comment thread data/models/noteModel.js
const insert = async (note) => {

// check for missing note object
if (typeof note === 'undefined') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need this check 🤔 is there ever a case where this would happen?

Comment thread data/models/noteModel.js
}

// check if note is object
if (typeof note !== 'object') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this. Would this ever not be an object?

Comment thread data/models/noteModel.js
}

// check for missing title key
if (!note.hasOwnProperty('title')) {

@KingAtoki KingAtoki Feb 22, 2019

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since note isn't inherited, you are fine with just checking !note.title

Suggested change
if (!note.hasOwnProperty('title')) {
if (!note.title) {

Side Note: Now if it something like

const originalNote = { title: 'Here is a title', content: 'Some content' }

const note = originalNote;

console.log(note.hasOwnProperty('title')) // false because it is inherited

note.tag = 'here is a tag'

console.log(note.hasOwnProperty('tag)) // true

Comment thread data/models/noteModel.js
}

// check for title not string
if (typeof note.title !== 'string') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will always be a string. Even if the user types in a number like 1 it will still be a string unless you change it to a number lol

Comment thread data/models/noteModel.js
}

// check for content not string
if (typeof note.content !== 'string') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here

Comment thread data/models/noteModel.js
}

// check for missing content key
if (!note.hasOwnProperty('content')) {

@KingAtoki KingAtoki Feb 22, 2019

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!note.hasOwnProperty('content')) {
if (!note.content) {

Comment thread data/models/noteModel.js
return n;
};

const update = async (id, note) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing as above. Double check to make sure you aren't making unnecessary checks

Comment thread data/models/noteModel.js
throw e;
}

const count = await db('notes').where('id', id).update(note);

@KingAtoki KingAtoki Feb 22, 2019

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good time to have a `try/catch block to organize your code

try {
  await db('notes').where('id', id).update(note); // <-- if this fails it will automatically go to the catch block
  const n = await get(id);
  return n;
} catch (e) {
  throw new Error("id does not exist");
}

test("throws MissingKey when 'title' key not present in note object", async () => {
try {
await noteModel.insert({ content: "Content" });
expect(true).toBe(false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol you don't have to have this here I don't think

Suggested change
expect(true).toBe(false);

test("throws MissingKey when 'content' key not present in note object", async () => {
try {
await noteModel.insert({ title: "Title" });
expect(true).toBe(false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Suggested change
expect(true).toBe(false);

test("throws TypeError when 'title' value is not string", async () => {
try {
await noteModel.insert({ title: 0, content: "Content" });
expect(true).toBe(false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(true).toBe(false);

test("throws TypeError when 'content' value is not string", async () => {
try {
await noteModel.insert({ title: "Title", content: 0 });
expect(true).toBe(false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(true).toBe(false);

@KingAtoki KingAtoki left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very very good work so far! Just a few things to clean up and double check on, but everything is looking great! Keep up the good work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants