Skip to content
This repository has been archived by the owner on Jun 21, 2019. It is now read-only.

Feature/#31 cms profile page #43

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open

Conversation

ghost
Copy link

@ghost ghost commented Apr 23, 2018

No description provided.

@ghost ghost requested a review from jmaicaaan April 23, 2018 08:30
Copy link
Member

@jmaicaaan jmaicaaan left a comment

Choose a reason for hiding this comment

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

Hi @cedrickmandocdoc , please see my comments. Thank you 😄

public profileForm: FormGroup;

constructor(
private formBuilder: FormBuilder,
Copy link
Member

Choose a reason for hiding this comment

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

Let's practice declaring constructor params as readonly. It doesn't need to be changed dynamically and it doesn't make sense too.
private readonly formBuilder: FormBuilder

Copy link
Author

Choose a reason for hiding this comment

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

Alright

}

private loadProfile() {
this.userService.currentUser$.subscribe((user: User) => {
Copy link
Member

Choose a reason for hiding this comment

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

Break the line in the .subscribe.

@@ -105,4 +105,20 @@ describe('UserController', () => {
.expect(200);
});
});

describe.only('updateProfileById', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Please remove .only here

@@ -30,4 +30,14 @@ export class UserController {
public getUsers() {
return this.userService.getUsers();
}

@Put('profile')
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't the proper http resource url for put methods must contain an id?

I believe this should be something PUT http://localhost:300/api/users/${userId}. Since it is one of the main resource of api/users endpoint.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see you are getting it to the CurrentUser decorator. But this limits the endpoint to the "currentUser". What if the a special role like admin would like to update a specific account? We will be needing to create another endpoint on that one which is not good. What do you think?

Copy link
Author

Choose a reason for hiding this comment

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

hmm you are right. Do you have any idea on how to update user profile and at the same time can edit by the admin?

Copy link
Author

Choose a reason for hiding this comment

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

maybe a different endpoint?

Copy link
Member

Choose a reason for hiding this comment

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

Why not have a generic endpoint for updating an account? Like the resource url above mentioned as it just needed an accessToken to allow or disallow certain roles. I think having the currentUser and an admin decorator will satisfy the permissions.

});
}

public updateUserById(id: number, data: User): Promise<void> {
delete data.created;
Copy link
Member

Choose a reason for hiding this comment

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

Why delete the created property? Don't you think we need to update it instead?

email: user.email,
roles: user.roles
});
const token = this.jwtService.sign(classToPlain(user));
Copy link
Member

Choose a reason for hiding this comment

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

Hahaha this is good haven't thought about this 👌 but I have a question, don't you think that this will always be unique to each other? Or do you think we should update the passed user before transforming it to object?
For example, updating the created to new Date.now() which will provide a more unique item.

Copy link
Author

Choose a reason for hiding this comment

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

I think jwt returns unique token even the data is always the same

@@ -39,4 +36,9 @@ export class UserService {
public async getUsers() {
return this.userRepository.getUsers({});
}

public updateProfileById(id: number, data: User) {
delete data.password;
Copy link
Member

Choose a reason for hiding this comment

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

Wait, we cannot update without password? 😱 😱 😱 Why delete? Can we not use the token?

Copy link
Author

Choose a reason for hiding this comment

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

Actually I want to separate the endpoint of changing password. I don't want to update the password always for just updating the profile. I can't see any real application that does that. I think it is better to break down all properties that needs to be updated

imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class ProfileRoutingModule { }
Copy link
Member

Choose a reason for hiding this comment

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

Sorry but ProfileRoutingModule is not a good class name hahaha why not name files like this as routes.ts?

So when I look at the files inside the folder I could see the ff:

  • *.module.ts
  • *.routes.ts
  • *.component.ts
  • *.component.scss
  • *.component.html

Copy link
Author

Choose a reason for hiding this comment

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

Ahh I believe I posted before that we will johnpapa's style guide in client and in server side the nest-js style guide extension in vscode

Copy link
Member

Choose a reason for hiding this comment

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

Does john papa's style do that naming?

Sign up for free to 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.

2 participants