generated from HugoMendes98/Nx-NestJS-Angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(user): forbid user update for other users
- Loading branch information
1 parent
181e3b7
commit 414c83f
Showing
7 changed files
with
97 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { createParamDecorator, ExecutionContext } from "@nestjs/common"; | ||
|
||
import { UserEntity } from "../user/user.entity"; | ||
|
||
/** | ||
* The authenticated user data on Request | ||
*/ | ||
export type AuthUser = UserEntity; | ||
|
||
/** | ||
* Inject the connected user from the request if exists | ||
*/ | ||
export const AuthUserParam = createParamDecorator<never, ExecutionContext>( | ||
(_, context) => context.switchToHttp().getRequest<Express.Request>().user | ||
); | ||
|
||
declare global { | ||
// eslint-disable-next-line @typescript-eslint/no-namespace -- TODO: set it as a custom global type AND still working for e2e tests | ||
namespace Express { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface -- For declaration merging | ||
interface User extends AuthUser {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { PartialType } from "@nestjs/mapped-types"; | ||
import { OmitType, PartialType } from "@nestjs/mapped-types"; | ||
|
||
import { UserCreateDto } from "./user.create.dto"; | ||
|
||
/** | ||
* DTO used to update [users]{@link UserDto} | ||
* in its {@link UserEndpoint endpoint}. | ||
*/ | ||
export class UserUpdateDto extends PartialType(UserCreateDto) {} | ||
export class UserUpdateDto extends PartialType(OmitType(UserCreateDto, ["email"])) {} |