fac26 / week2-database-nkndi

0 stars 0 forks source link

Small refactor #51

Closed ivan-unfolds closed 1 year ago

ivan-unfolds commented 1 year ago

You could refactor the following

https://github.com/fac26/week2-database-nkndi/blob/6ee7693fc6b0f30adca74545df0dde8c19a160f5/routes/addBook.js#L32-L40

To something like

const author_id = getAuthorId(author)?.id || inserteAuthorToDB({ name: author }).id;

Though it's a matter of subjective opinion whether this is better so feel free to ignore. You could argue that your solution is more readable.

ko-karol commented 1 year ago

I agree, using nullish coalescing operator is not only more terse, but also easier to understand than 8 separate lines of code.

nataliarusu commented 1 year ago

Following your advise, done Thank you, Ivan