Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eric Whitcomb #481

Open
wants to merge 27 commits into
base: master
Choose a base branch
from

Conversation

ericwhitcomb
Copy link

@ericwhitcomb
Copy link
Author

@ericwhitcomb ericwhitcomb changed the title Forked, cloned, and set up Trello board Eric Whitcomb Feb 14, 2019
@ericwhitcomb
Copy link
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
Copy link
Author

ericwhitcomb commented Feb 19, 2019

Should be done with MVP and on to stretch goals


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

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();

if (note.length) {
return note[0];
} else {
const e = new Error("id does not exist");

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");

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

const insert = async (note) => {

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

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?

}

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

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?

}

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

@KingAtoki KingAtoki Feb 22, 2019

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

}

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

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

}

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

Choose a reason for hiding this comment

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

Same thing here

}

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

@KingAtoki KingAtoki Feb 22, 2019

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) {

return n;
};

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

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

throw e;
}

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

@KingAtoki KingAtoki Feb 22, 2019

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);

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);

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);

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);

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);

Copy link

@KingAtoki KingAtoki left a comment

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