-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/#31 cms profile page #43
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a different endpoint?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 { } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
No description provided.