Skip to content

General Improvements#390

Merged
ajayyy merged 9 commits into
ajayyy:masterfrom
whizzzkid:fix/general-fixes
Nov 17, 2021
Merged

General Improvements#390
ajayyy merged 9 commits into
ajayyy:masterfrom
whizzzkid:fix/general-fixes

Conversation

@whizzzkid
Copy link
Copy Markdown
Contributor

@whizzzkid whizzzkid commented Oct 22, 2021

Namaste Team 🙏🏽

First of all I'd like to thank you for the time this project has helped me saved while digesting YT content! As a payback I wanted to contribute to the project.

I just started understanding the basic structure and how things are being done in this project. I spotted some inefficiencies along the way and thought of creating a PR. In the future I plan on taking up active issues, but for now I just started dipping my toes 👣 and would like to understand the expectations from the owners.

In this PR, I introduced:

  • Destructuring
  • Valid Interfaces
  • Optimal call execution

Thanks for your time!

const entries = dbEntries.filter(
({ category }: DBEntry) => categories === null || categories.indexOf(category) !== -1);

await Promise.all(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can run requests in parallel.


return res.sendStatus(200);
} No newline at end of file
return res.sendStatus(500);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The default status should not be 200, that should only happen when call succeeds.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think 500 should not be the default, use BadRequest 400 instead. 500 is better in the catch error. It also checks for the BadRequest so I think the current logic is fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it's not actually default.

200 is only returned if try succeeds. Otherwise it's always 500 because we are not checking or limiting ourselves to a particular error type. That line can never be reached. I personally dislike returning from catch so it's just the existing logic, but structured differently.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see. Unlike you, I often return in catch.

Comment thread src/utils/getService.ts
import { Service } from "../types/segments.model";

export function getService<T extends string>(...value: T[]): Service {
const serviceByName = Object.values(Service).reduce((acc, serviceName) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

By doing this we can achieve the same effect in O(n) instead of O(n^2)

@mchangrh
Copy link
Copy Markdown
Contributor

Nice work!

Comment on lines +20 to +27
const {
body: {
videoID,
userID,
categories,
service
}
} = req;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

very cool

Comment thread src/routes/deleteLockCategories.ts Outdated
@whizzzkid whizzzkid mentioned this pull request Oct 28, 2021
@ajayyy ajayyy merged commit 0478491 into ajayyy:master Nov 17, 2021
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.

4 participants