Skip to content

Commit

Permalink
Merge branch 'main' into EW-1083
Browse files Browse the repository at this point in the history
  • Loading branch information
mkreuzkam-cap authored Jan 21, 2025
2 parents 22fc71c + 9719201 commit a18f5a3
Show file tree
Hide file tree
Showing 39 changed files with 230 additions and 189 deletions.
15 changes: 9 additions & 6 deletions apps/server/src/modules/account/api/account.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class AccountController {
@ApiResponse({ status: 200, type: AccountSearchListResponse, description: 'Returns a paged list of accounts.' })
@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(
public async searchAccounts(
@CurrentUser() currentUser: ICurrentUser,
@Query() query: AccountSearchQueryParams
): Promise<AccountSearchListResponse> {
Expand All @@ -48,7 +48,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.' })
@ApiResponse({ status: 404, type: EntityNotFoundError, description: 'Account not found.' })
async findAccountById(
public async findAccountById(
@CurrentUser() currentUser: ICurrentUser,
@Param() params: AccountByIdParams
): Promise<AccountResponse> {
Expand All @@ -65,7 +65,10 @@ 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: ICurrentUser, @Body() params: PatchMyAccountParams): Promise<void> {
public updateMyAccount(
@CurrentUser() currentUser: ICurrentUser,
@Body() params: PatchMyAccountParams
): Promise<void> {
const updateData = new UpdateMyAccountDto(params);
return this.accountUc.updateMyAccount(currentUser.userId, updateData);
}
Expand All @@ -76,7 +79,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.' })
@ApiResponse({ status: 404, type: EntityNotFoundError, description: 'Account not found.' })
async updateAccountById(
public async updateAccountById(
@CurrentUser() currentUser: ICurrentUser,
@Param() params: AccountByIdParams,
@Body() body: AccountByIdBodyParams
Expand All @@ -93,7 +96,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.' })
@ApiResponse({ status: 404, type: EntityNotFoundError, description: 'Account not found.' })
async deleteAccountById(
public async deleteAccountById(
@CurrentUser() currentUser: ICurrentUser,
@Param() params: AccountByIdParams
): Promise<AccountResponse> {
Expand All @@ -107,7 +110,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 or user not found.' })
async replaceMyPassword(
public replaceMyPassword(
@CurrentUser() currentUser: ICurrentUser,
@Body() params: PatchMyPasswordParams
): Promise<void> {
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/modules/account/api/account.uc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class AccountUc {
* @param currentUserId the current user
* @param updateMyAccountDto account details
*/
public async updateMyAccount(currentUserId: EntityId, updateMyAccountDto: UpdateMyAccountDto) {
public async updateMyAccount(currentUserId: EntityId, updateMyAccountDto: UpdateMyAccountDto): Promise<void> {
const user = await this.authorizationService.getUserWithPermissions(currentUserId);
if (
(updateMyAccountDto.firstName && user.firstName !== updateMyAccountDto.firstName) ||
Expand Down Expand Up @@ -205,7 +205,7 @@ export class AccountUc {
currentUser: User,
targetUser: User,
action: 'READ' | 'UPDATE' | 'DELETE' | 'CREATE'
) {
): boolean {
if (this.hasRole(currentUser, RoleName.SUPERHERO)) {
return true;
}
Expand Down Expand Up @@ -267,7 +267,7 @@ export class AccountUc {
);
}

private hasRole(user: User, roleName: string) {
private hasRole(user: User, roleName: string): boolean {
return user.roles.getItems().some((role) => role.name === roleName);
}

Expand Down
8 changes: 4 additions & 4 deletions apps/server/src/modules/account/api/dto/account-search.dto.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { AccountSearchType } from '../../domain/type/account-search-type';

export class AccountSearchDto {
type!: AccountSearchType;
public type!: AccountSearchType;

value!: string;
public value!: string;

skip?: number = 0;
public skip?: number = 0;

limit?: number = 10;
public limit?: number = 10;

constructor(search: AccountSearchDto) {
this.type = search.type;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiPropertyOptional } from '@nestjs/swagger';
import { PrivacyProtect, SanitizeHtml } from '@shared/controller';
import { IsBoolean, IsString, IsOptional, Matches, IsEmail } from 'class-validator';
import { passwordPattern } from '../password-pattern';
import { passwordPattern } from '../../../domain/password-pattern';

export class AccountByIdBodyParams {
@IsOptional()
@IsString()
@SanitizeHtml()
@IsEmail()
@ApiProperty({
@ApiPropertyOptional({
description: 'The new user name for the user.',
required: false,
nullable: true,
})
username?: string;
public username?: string;

@PrivacyProtect()
@IsOptional()
@IsString()
@Matches(passwordPattern)
@ApiProperty({
@ApiPropertyOptional({
description: 'The new password for the user.',
required: false,
nullable: true,
})
password?: string;
public password?: string;

@IsOptional()
@IsBoolean()
@ApiProperty({
@ApiPropertyOptional({
description: 'The new activation state of the user.',
required: false,
nullable: true,
})
activated?: boolean;
public activated?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export class AccountByIdParams {
required: true,
nullable: false,
})
id!: string;
public id!: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class AccountSearchQueryParams extends PaginationParams {
required: true,
nullable: false,
})
type!: AccountSearchType;
public type!: AccountSearchType;

@IsString()
@SanitizeHtml()
Expand All @@ -20,5 +20,5 @@ export class AccountSearchQueryParams extends PaginationParams {
required: true,
nullable: false,
})
value!: string;
public value!: string;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { PrivacyProtect, SanitizeHtml } from '@shared/controller';
import { IsEmail, IsOptional, IsString, Matches } from 'class-validator';
import { passwordPattern } from '../password-pattern';
import { passwordPattern } from '../../../domain/password-pattern';

export class PatchMyAccountParams {
@IsString()
Expand All @@ -10,48 +10,40 @@ export class PatchMyAccountParams {
required: true,
nullable: false,
})
passwordOld!: string;
public passwordOld!: string;

@PrivacyProtect()
@IsString()
@IsOptional()
@Matches(passwordPattern)
@ApiProperty({
@ApiPropertyOptional({
description: 'The new password for the current user.',
required: false,
nullable: true,
})
passwordNew?: string;
public passwordNew?: string;

@IsEmail()
@SanitizeHtml()
@IsOptional()
@ApiProperty({
@ApiPropertyOptional({
description: 'The new email address for the current user.',
required: false,
nullable: true,
})
email?: string;
public email?: string;

@IsString()
@SanitizeHtml()
@IsOptional()
@SanitizeHtml()
@ApiProperty({
@ApiPropertyOptional({
description: 'The new first name for the current user.',
required: false,
nullable: true,
})
firstName?: string;
public firstName?: string;

@IsString()
@SanitizeHtml()
@IsOptional()
@SanitizeHtml()
@ApiProperty({
@ApiPropertyOptional({
description: 'The new last name for the current user.',
required: false,
nullable: true,
})
lastName?: string;
public lastName?: string;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiProperty } from '@nestjs/swagger';
import { PrivacyProtect } from '@shared/controller';
import { IsString, Matches } from 'class-validator';
import { passwordPattern } from '../password-pattern';
import { passwordPattern } from '../../../domain/password-pattern';

export class PatchMyPasswordParams {
@PrivacyProtect()
Expand All @@ -12,7 +12,7 @@ export class PatchMyPasswordParams {
required: true,
nullable: false,
})
password!: string;
public password!: string;

@PrivacyProtect()
@IsString()
Expand All @@ -22,5 +22,5 @@ export class PatchMyPasswordParams {
required: true,
nullable: false,
})
confirmPassword!: string;
public confirmPassword!: string;
}
70 changes: 36 additions & 34 deletions apps/server/src/modules/account/api/dto/resolved-account.dto.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,66 @@
import { EntityId } from '@shared/domain/types';
import { IsBoolean, IsDate, IsMongoId, IsNotEmpty, IsOptional, IsString, Matches } from 'class-validator';
/* eslint-disable max-classes-per-file */
import { ApiPropertyOptional } from '@nestjs/swagger';
import { PrivacyProtect } from '@shared/controller';
import { passwordPattern } from './password-pattern';
import { EntityId } from '@shared/domain/types';
import { IsBoolean, IsDate, IsMongoId, IsNotEmpty, IsString, Matches } from 'class-validator';
import { passwordPattern } from '../../domain/password-pattern';

export class ResolvedAccountDto {
@IsOptional()
@ApiPropertyOptional()
@IsMongoId()
readonly id: EntityId;
public readonly id: EntityId;

@IsOptional()
@ApiPropertyOptional()
@IsDate()
readonly createdAt?: Date;
public readonly createdAt?: Date;

@IsOptional()
@ApiPropertyOptional()
@IsDate()
readonly updatedAt?: Date;
public readonly updatedAt?: Date;

@IsString()
@IsNotEmpty()
username: string;
public username: string;

@PrivacyProtect()
@IsOptional()
@ApiPropertyOptional()
@Matches(passwordPattern)
password?: string;
public password?: string;

@IsOptional()
@ApiPropertyOptional()
@IsString()
token?: string;
public token?: string;

@IsOptional()
@ApiPropertyOptional()
@IsString()
credentialHash?: string;
public credentialHash?: string;

@IsOptional()
@ApiPropertyOptional()
@IsMongoId()
userId?: EntityId;
public userId?: EntityId;

@IsOptional()
@ApiPropertyOptional()
@IsMongoId()
systemId?: EntityId;
public systemId?: EntityId;

@IsOptional()
@ApiPropertyOptional()
@IsDate()
lasttriedFailedLogin?: Date;
public lasttriedFailedLogin?: Date;

@IsOptional()
@ApiPropertyOptional()
@IsDate()
expiresAt?: Date;
public expiresAt?: Date;

@IsOptional()
@ApiPropertyOptional()
@IsBoolean()
activated?: boolean;
public activated?: boolean;

@IsOptional()
idmReferenceId?: string;
@ApiPropertyOptional()
public idmReferenceId?: string;

@IsOptional()
@ApiPropertyOptional()
@IsDate()
deactivatedAt?: Date;
public deactivatedAt?: Date;

constructor(account: ResolvedAccountDto) {
this.id = account.id;
Expand All @@ -79,13 +81,13 @@ export class ResolvedAccountDto {
}

export class ResolvedSearchListAccountDto {
data: ResolvedAccountDto[];
public data: ResolvedAccountDto[];

total: number;
public total: number;

skip?: number;
public skip?: number;

limit?: number;
public limit?: number;

constructor(data: ResolvedAccountDto[], total: number, skip?: number, limit?: number) {
this.data = data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export class AccountSearchListResponse extends PaginationResponse<AccountRespons
}

@ApiProperty({ type: [AccountResponse] })
data: AccountResponse[];
public data: AccountResponse[];
}
Loading

0 comments on commit a18f5a3

Please sign in to comment.