Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel committed Feb 13, 2024
1 parent 4f5f92a commit ec206f1
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 34 deletions.
2 changes: 1 addition & 1 deletion apps/authz/src/app/evaluation-request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class EvaluationRequestDto {
@IsOptional()
@ValidateNested()
@ApiProperty({
type: () => RequestSignatureDto,
type: RequestSignatureDto,
isArray: true
})
approvals?: RequestSignatureDto[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ export class BaseAdminRequestPayloadDto {
@IsDefined()
@ValidateNested()
@Type(() => RequestSignatureDto)
@ApiProperty({ type: () => RequestSignatureDto })
@ApiProperty({ type: RequestSignatureDto })
authentication: RequestSignatureDto

@ArrayNotEmpty()
@ValidateNested({ each: true })
@Type(() => RequestSignatureDto)
@ApiProperty({
type: () => RequestSignatureDto,
type: RequestSignatureDto,
isArray: true
})
approvals: RequestSignatureDto[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,26 @@ class CreateOrganizationDataDto {
@IsDefined()
@ValidateNested()
@Type(() => AuthCredentialDto)
@ApiProperty({ type: String })
@ApiProperty({ type: AuthCredentialDto })
credential: AuthCredentialDto
}

class CreateOrganizationActionDto extends BaseActionDto {
@IsString()
@IsNotEmpty()
@Matches(Action.CREATE_ORGANIZATION)
@ApiProperty({ default: Action.CREATE_ORGANIZATION })
action: typeof Action.CREATE_ORGANIZATION

@IsDefined()
@ValidateNested()
@Type(() => CreateOrganizationDataDto)
@ApiProperty({ type: () => CreateOrganizationDataDto })
@ApiProperty({ type: CreateOrganizationDataDto })
organization: CreateOrganizationDataDto
}

export class CreateOrganizationRequestDto extends BaseAdminRequestPayloadDto {
@IsDefined()
@ValidateNested()
@Type(() => CreateOrganizationActionDto)
@ApiProperty({ type: () => CreateOrganizationActionDto })
@ApiProperty({ type: CreateOrganizationActionDto })
request: CreateOrganizationActionDto
}
34 changes: 15 additions & 19 deletions apps/authz/src/app/http/rest/dto/create-user-request.dto.ts
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
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { Action } from '@narval/authz-shared'
import { ApiProperty } from '@nestjs/swagger'
import { Type } from 'class-transformer'
import { ArrayNotEmpty, IsDefined, IsNotEmpty, IsString, Matches, ValidateNested } from 'class-validator'
import { ArrayNotEmpty, IsDefined, Matches, ValidateNested } from 'class-validator'
import { Policy } from '../../../../../shared/types/policy.type'
import { BaseActionDto } from '../base-action.dto'
import { BaseAdminRequestPayloadDto } from '../base-admin-request-payload.dto'

export class SetPolicyRulesDto extends BaseActionDto {
@IsString()
@IsNotEmpty()
@Matches(Action.SET_POLICY_RULES)
@ApiProperty({ default: Action.SET_POLICY_RULES })
action: typeof Action.SET_POLICY_RULES
Expand All @@ -24,6 +22,6 @@ export class SetPolicyRulesRequestDto extends BaseAdminRequestPayloadDto {
@IsDefined()
@ValidateNested()
@Type(() => SetPolicyRulesDto)
@ApiProperty({ type: () => SetPolicyRulesDto })
@ApiProperty({ type: SetPolicyRulesDto })
request: SetPolicyRulesDto
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class SetPolicyRulesResponseDto {
@IsDefined()
@Type(() => Policy)
@ValidateNested()
@ApiProperty({ type: () => Policy, isArray: true })
@ApiProperty({ type: Policy, isArray: true })
policies: Policy[]

constructor(partial: Partial<SetPolicyRulesResponseDto>) {
Expand Down
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 }))
}

0 comments on commit ec206f1

Please sign in to comment.