-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
samuel
committed
Feb 13, 2024
1 parent
4f5f92a
commit ec206f1
Showing
7 changed files
with
26 additions
and
34 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
34 changes: 15 additions & 19 deletions
34
apps/authz/src/app/http/rest/dto/create-user-request.dto.ts
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,49 +1,45 @@ | ||
import { Action, UserRole } from '@narval/authz-shared' | ||
import { ApiExtraModels, ApiProperty } from '@nestjs/swagger' | ||
import { IsDefined, IsIn, IsOptional, IsString, ValidateNested } from 'class-validator' | ||
import { Type } from 'class-transformer' | ||
import { IsDefined, IsEnum, IsNotEmpty, IsString, Matches, ValidateNested } from 'class-validator' | ||
import { AuthCredentialDto } from './auth-credential.dto' | ||
import { BaseActionDto } from './base-action.dto' | ||
import { BaseAdminRequestPayloadDto } from './base-admin-request-payload.dto' | ||
|
||
class CreateUserDataDto { | ||
@IsString() | ||
@IsDefined() | ||
@ApiProperty() | ||
@IsNotEmpty() | ||
@ApiProperty({ type: String }) | ||
uid: string | ||
|
||
@IsIn(Object.values(UserRole)) | ||
@IsDefined() | ||
@ApiProperty({ | ||
enum: Object.values(UserRole) | ||
}) | ||
@IsEnum(UserRole) | ||
@ApiProperty({ enum: UserRole }) | ||
role: UserRole | ||
|
||
@IsString() | ||
@IsOptional() | ||
@ApiProperty() | ||
@IsDefined() | ||
@ValidateNested() | ||
@Type(() => AuthCredentialDto) | ||
@ApiProperty({ type: AuthCredentialDto }) | ||
credential?: AuthCredentialDto | ||
} | ||
|
||
class CreateUserActionDto extends BaseActionDto { | ||
@IsIn(Object.values(Action)) | ||
@IsDefined() | ||
@ApiProperty({ | ||
enum: Object.values(Action), | ||
default: Action.CREATE_USER | ||
}) | ||
@Matches(Action.CREATE_USER) | ||
@ApiProperty({ default: Action.CREATE_USER }) | ||
action: typeof Action.CREATE_USER | ||
|
||
@IsDefined() | ||
@ValidateNested() | ||
@ApiProperty() | ||
@Type(() => CreateUserDataDto) | ||
@ApiProperty({ type: CreateUserDataDto }) | ||
user: CreateUserDataDto | ||
} | ||
|
||
@ApiExtraModels(CreateUserActionDto, AuthCredentialDto) | ||
export class CreateUserRequestDto extends BaseAdminRequestPayloadDto { | ||
@IsDefined() | ||
@ValidateNested() | ||
@ApiProperty() | ||
@Type(() => CreateUserActionDto) | ||
@ApiProperty({ type: CreateUserActionDto }) | ||
request: CreateUserActionDto | ||
} |
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
4 changes: 2 additions & 2 deletions
4
apps/authz/src/shared/decorators/validate-criterion.decorator.ts
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,8 +1,8 @@ | ||
import { applyDecorators } from '@nestjs/common' | ||
import { ApiProperty } from '@nestjs/swagger' | ||
import { IsDefined, IsString, Matches } from 'class-validator' | ||
import { Matches } from 'class-validator' | ||
import { Criterion } from '../types/policy.type' | ||
|
||
export function ValidateCriterion(name: string) { | ||
return applyDecorators(IsDefined(), IsString(), Matches(name), ApiProperty({ type: () => Criterion, default: name })) | ||
return applyDecorators(Matches(name), ApiProperty({ type: Criterion, default: name })) | ||
} |