Skip to content
This repository was archived by the owner on Sep 25, 2025. It is now read-only.

Event CRUD API - #299

Merged
vaibhavsingh97 merged 10 commits into
freeCodeCamp:masterfrom
Zeko369:eventCrud_102
Dec 24, 2019
Merged

Event CRUD API#299
vaibhavsingh97 merged 10 commits into
freeCodeCamp:masterfrom
Zeko369:eventCrud_102

Conversation

@Zeko369

Copy link
Copy Markdown
Contributor

Closes#102

Comment threadserver/routes/events.ts Outdated
Comment threadserver/controllers/eventsController.ts Outdated
Comment threadserver/controllers/eventsController.ts Outdated
Comment threadserver/controllers/eventsController.ts Outdated
Comment threadserver/controllers/eventsController.ts
@robertt

Copy link
Copy Markdown
Contributor

#302 just got merged, meaning you can replace all your if(e.code === '23503')s with if(e.code === PostgresErrorCodes.FOREIGN_KEY_VIOLATION)!

@timmyichen

Copy link
Copy Markdown
Contributor

I think the last two commits (updating and rerunning prettier) might be in a separate PR as it dilutes the changes made that are actually relevant to the PR (ideally we can point to this PR as an example of how to do things)

@Zeko369

Copy link
Copy Markdown
ContributorAuthor

@timmyichen I agree, but I can't run prettier on the ts3.7.3 and needed to update prettier, the new prettier automatically added these changes, maybe just ignoring the lint steps?

@AryanJ-NYC

Copy link
Copy Markdown
Contributor

@Zeko369 Just remove the changes to files that are irrelevant to the scope of the Events CRUD API from the branch:

server/models/Chapter.ts
server/models/Event.ts
server/models/EventSponsor.ts
server/models/Location.ts
server/models/Rsvp.ts
server/models/SocialProviderUser.ts
...
etc.

@vaibhavsingh97

Copy link
Copy Markdown
Member

@timmyichen@AryanJ-NYC I agree that the last 2 commits are not related to this PR, but it's just linting, so can we agree and go ahead with this PR?

@AryanJ-NYC

Copy link
Copy Markdown
Contributor

I mean, sure. It's not even necessarily about this one PR. We just want to be sure to not set a precedent of allowing out-of-scope and unrelated changes made.

}
}

res.status(500).json({ error: e });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we should return 400 bad request as response and with the following content?

{
"errors": [
{
"message": "please add your chapter name",
"field": "name"
},
{
"message": "please add your chapter description",
"field": "description"
}
]
}

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah, we should do that instead of using 404, but also keep the 500 error on line 71

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

according to rest API conventions, we should give 500 when there is a server-side error, but here is the fault is from the client-side so I think we should not give 500 as a response code.
Ref: https://restfulapi.net/http-status-codes/

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.

@vaibhavsingh97 What makes you think it is the fault of the client?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Client fault as in, the client didn't send all the details required by API. Here server didn't break, it's the data which is missing

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I changed this to 400 for now, we can open a new issue to discuss what we're going to use. But I think this is fine for now

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, we can fix this in another PR after discussion. Approving

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.

@vkWeb I don't follow your logic. If I think thing A, I have to give an example of thing B? Why the pop quiz?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@AryanJ-NYC I asked that question to make you think of situations when a client-side error may creep.

I checked the models. We aren't allowing NULL values for event name and capacity. So shouldn't we catch NOT_NULL_VIOLATION for them?

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.

Instead of asking questions to try and make me think, wouldn't it be easier to just explicitly say: "Hey, we're missing a catch for the NOT_NULL_VIOLATION?

I'm done arguing this, FWIW.

}
}

res.status(500).json({ error: e });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same as above

@Zeko369

Copy link
Copy Markdown
ContributorAuthor

@Zeko369 Just remove the changes to files that are irrelevant to the scope of the Events CRUD API from the branch:

server/models/Chapter.ts
server/models/Event.ts
server/models/EventSponsor.ts
server/models/Location.ts
server/models/Rsvp.ts
server/models/SocialProviderUser.ts
...
etc.

I tried doing that, but the problem is that if I skip that the CI fails, and if I revert back to the old TS and old prettier I'd have to change ?? to something else

@ankorGH

Copy link
Copy Markdown
Contributor

@Zeko369 can't you create a new pull request for the new prettier/ts config and rebase this branch when its merged ? Or I am missing something

@Zeko369

Copy link
Copy Markdown
ContributorAuthor

@ankorGH OK, I can do this, that seems like a great idea

@Zeko369Zeko369 mentioned this pull request Dec 24, 2019
@vaibhavsingh97

Copy link
Copy Markdown
Member

Merging since we have two approval

@vaibhavsingh97
vaibhavsingh97 merged commit d03bf3a into freeCodeCamp:masterDec 24, 2019
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API: As an organizer I can create events and set their location, tags and capacity.

8 participants

@Zeko369@robertt@timmyichen@AryanJ-NYC@vaibhavsingh97@ankorGH@ScottBrenner@vkWeb