Skip to content

Commit

Permalink
CurrentUserInterface -> ICurrentUser
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfganggreschus committed Nov 16, 2023
1 parent b4345b6 commit e8460df
Show file tree
Hide file tree
Showing 112 changed files with 452 additions and 527 deletions.
4 changes: 2 additions & 2 deletions apps/server/doc/file-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ The main responsibilities of a controller is to define the REST API interface as
```TypeScript
@Post()
async create(@CurrentUser() currentUser: CurrentUserInterface, @Body() params: CreateNewsParams): Promise<NewsResponse> {
async create(@CurrentUser() currentUser: ICurrentUser, @Body() params: CreateNewsParams): Promise<NewsResponse> {
const news = await this.newsUc.create(
currentUser.userId,
currentUser.schoolId,
Expand All @@ -171,7 +171,7 @@ The main responsibilities of a controller is to define the REST API interface as
#### JWT-Authentication
For **authentication**, use [guards](https://docs.nestjs.com/guards) like JwtAuthGuard. It can be applied to a whole controller or a single controller method only. Then, [CurrentUserInterface](/apps/server/src/modules/authentication/interface/jwt-payload.ts) can be injected using the `@CurrentUser()` decorator.
For **authentication**, use [guards](https://docs.nestjs.com/guards) like JwtAuthGuard. It can be applied to a whole controller or a single controller method only. Then, [ICurrentUser](/apps/server/src/modules/authentication/interface/jwt-payload.ts) can be injected using the `@CurrentUser()` decorator.
#### Validation
Expand Down
17 changes: 7 additions & 10 deletions apps/server/src/modules/account/controller/account.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Body, Controller, Delete, Get, Param, Patch, Query } from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { EntityNotFoundError, ForbiddenOperationError, ValidationError } from '@shared/common';
import { CurrentUserInterface } from '@src/modules/authentication';
import { ICurrentUser } from '@src/modules/authentication';
import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator';
import { AccountUc } from '../uc/account.uc';
import {
Expand Down Expand Up @@ -29,7 +29,7 @@ export class AccountController {
@ApiResponse({ status: 400, type: ValidationError, description: 'Request data has invalid format.' })
@ApiResponse({ status: 403, type: ForbiddenOperationError, description: 'User is not a superhero or administrator.' })
async searchAccounts(
@CurrentUser() currentUser: CurrentUserInterface,
@CurrentUser() currentUser: ICurrentUser,
@Query() query: AccountSearchQueryParams
): Promise<AccountSearchListResponse> {
return this.accountUc.searchAccounts(currentUser, query);
Expand All @@ -42,7 +42,7 @@ export class AccountController {
@ApiResponse({ status: 403, type: ForbiddenOperationError, description: 'User is not a superhero.' })
@ApiResponse({ status: 404, type: EntityNotFoundError, description: 'Account not found.' })
async findAccountById(
@CurrentUser() currentUser: CurrentUserInterface,
@CurrentUser() currentUser: ICurrentUser,
@Param() params: AccountByIdParams
): Promise<AccountResponse> {
return this.accountUc.findAccountById(currentUser, params);
Expand All @@ -57,10 +57,7 @@ export class AccountController {
@ApiResponse({ status: 400, type: ValidationError, description: 'Request data has invalid format.' })
@ApiResponse({ status: 403, type: ForbiddenOperationError, description: 'Invalid password.' })
@ApiResponse({ status: 404, type: EntityNotFoundError, description: 'Account not found.' })
async updateMyAccount(
@CurrentUser() currentUser: CurrentUserInterface,
@Body() params: PatchMyAccountParams
): Promise<void> {
async updateMyAccount(@CurrentUser() currentUser: ICurrentUser, @Body() params: PatchMyAccountParams): Promise<void> {
return this.accountUc.updateMyAccount(currentUser.userId, params);
}

Expand All @@ -71,7 +68,7 @@ export class AccountController {
@ApiResponse({ status: 403, type: ForbiddenOperationError, description: 'User is not a superhero.' })
@ApiResponse({ status: 404, type: EntityNotFoundError, description: 'Account not found.' })
async updateAccountById(
@CurrentUser() currentUser: CurrentUserInterface,
@CurrentUser() currentUser: ICurrentUser,
@Param() params: AccountByIdParams,
@Body() body: AccountByIdBodyParams
): Promise<AccountResponse> {
Expand All @@ -85,7 +82,7 @@ export class AccountController {
@ApiResponse({ status: 403, type: ForbiddenOperationError, description: 'User is not a superhero.' })
@ApiResponse({ status: 404, type: EntityNotFoundError, description: 'Account not found.' })
async deleteAccountById(
@CurrentUser() currentUser: CurrentUserInterface,
@CurrentUser() currentUser: ICurrentUser,
@Param() params: AccountByIdParams
): Promise<AccountResponse> {
return this.accountUc.deleteAccountById(currentUser, params);
Expand All @@ -98,7 +95,7 @@ export class AccountController {
@ApiResponse({ status: 403, type: ForbiddenOperationError, description: 'Invalid password.' })
@ApiResponse({ status: 404, type: EntityNotFoundError, description: 'Account or user not found.' })
async replaceMyPassword(
@CurrentUser() currentUser: CurrentUserInterface,
@CurrentUser() currentUser: ICurrentUser,
@Body() params: PatchMyPasswordParams
): Promise<void> {
return this.accountUc.replaceMyTemporaryPassword(currentUser.userId, params.password, params.confirmPassword);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
PatchMyAccountParams,
PatchMyPasswordParams,
} from '@src/modules/account/controller/dto';
import { CurrentUserInterface } from '@src/modules/authentication';
import { ICurrentUser } from '@src/modules/authentication';
import { JwtAuthGuard } from '@src/modules/authentication/guard/jwt-auth.guard';
import { ServerTestModule } from '@src/modules/server/server.module';
import { Request } from 'express';
Expand All @@ -32,7 +32,7 @@ describe('Account Controller (API)', () => {
let studentUser: User;
let superheroUser: User;

let currentUser: CurrentUserInterface;
let currentUser: ICurrentUser;

const defaultPassword = 'DummyPasswd!1';
const defaultPasswordHash = '$2a$10$/DsztV5o6P5piW2eWJsxw.4nHovmJGBA.QNwiTmuZ/uvUc40b.Uhu';
Expand Down
Loading

0 comments on commit e8460df

Please sign in to comment.