Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

hotfix update route, add morgan and error logging line #84

Merged
merged 5 commits into from Aug 15, 2017
Merged

Conversation

paolobueno
Copy link
Contributor

Motivation

Client expected to send update requests to PUT /{entity}/:id while server code only supported it on the root of the entity path, we can support both uses.

Description

  • Add support for PUT /:id
  • Add some logging

@@ -95,6 +95,12 @@ export class ApiController<T> {
return Bluebird.reject(error);
}

req.body.id = req.body.id || req.params.id;
if (!req.body) {
Copy link
Member

Choose a reason for hiding this comment

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

Do you mean if (!req.body.id) {?

@@ -95,6 +95,12 @@ export class ApiController<T> {
return Bluebird.reject(error);
}

req.body.id = req.body.id || req.params.id;
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure we should be flexible here. Which way do we prefer?
Documentation states that api for put is PUT /. If we want to expose id as param let's update this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's have PUT /:id, it's the regular way to go since it's a request to modify the resource at the endpoint to a specific entity.

see section 9.6 here

export class MongoDbRepository<T extends { id: string }> implements PagingDataRepository<T> {
export class MongoDbRepository<T extends {
id: string,
_id?: string | ObjectID
Copy link
Member

Choose a reason for hiding this comment

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

[Question] Why we need that? It looks strange.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When this repository is grabbing the data from mongo it comes with _id: ObjectID('...'), but it's serialized to a string when we try to save it again and mongo complains that it won't change it.

We can either delete data._id like I did or try to wrap it again in an ObjectID constructor and try to update it back to the same value. I had some trouble trying out the second option.

Copy link
Member

@wtrocki wtrocki Aug 15, 2017

Choose a reason for hiding this comment

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

I think we have two options. Move all queries to use _id. or remove _id completely from every query. Second option seems better to me and align with the was sync work.
I think I also used wrong syntax for update https://stackoverflow.com/questions/22356110/update-field-inside-document-by-id-in-mongodb

Another thing will be to grab that obj into interface. This looks really strange .

Copy link
Member

@wtrocki wtrocki left a comment

Choose a reason for hiding this comment

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

Create standardized api for PUT. Adjust documentation.
Let's avoid overcomplicated generics.

wtrocki
wtrocki previously approved these changes Aug 15, 2017
wtrocki
wtrocki previously approved these changes Aug 15, 2017
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 6127654 on fix-update into ** on master**.

@wtrocki wtrocki merged commit 5eb80fe into master Aug 15, 2017
@wtrocki wtrocki deleted the fix-update branch August 15, 2017 14:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants