Skip to content

Commit

Permalink
fix DTOs
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel committed Feb 13, 2024
1 parent 7251139 commit 4f5f92a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 31 deletions.
19 changes: 9 additions & 10 deletions apps/authz/src/app/http/rest/dto/auth-credential.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Alg } from '@narval/authz-shared'
import { ApiProperty } from '@nestjs/swagger'
import { IsDefined, IsIn, IsString } from 'class-validator'
import { IsEnum, IsNotEmpty, IsString } from 'class-validator'

export class AuthCredentialDto {
constructor(data: AuthCredentialDto) {
Expand All @@ -11,22 +11,21 @@ export class AuthCredentialDto {
}

@IsString()
@IsDefined()
@ApiProperty()
@IsNotEmpty()
@ApiProperty({ type: String })
uid: string

@IsString()
@IsDefined()
@ApiProperty()
@IsNotEmpty()
@ApiProperty({ type: String })
pubKey: string

@IsIn(Object.values(Alg))
@IsDefined()
@ApiProperty({ enum: Object.values(Alg) })
@IsEnum(Alg)
@ApiProperty({ enum: Alg })
alg: Alg

@IsString()
@IsDefined()
@ApiProperty()
@IsNotEmpty()
@ApiProperty({ type: String })
userId: string
}
13 changes: 5 additions & 8 deletions apps/authz/src/app/http/rest/dto/base-action.dto.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { Action } from '@narval/authz-shared'
import { ApiProperty } from '@nestjs/swagger'
import { IsDefined, IsIn, IsString } from 'class-validator'
import { IsEnum, IsNotEmpty, IsString } from 'class-validator'

export class BaseActionDto {
@IsIn(Object.values(Action))
@IsDefined()
@ApiProperty({
enum: Object.values(Action)
})
@IsEnum(Action)
@ApiProperty({ enum: Action })
action: Action

@IsString()
@IsDefined()
@ApiProperty()
@IsNotEmpty()
@ApiProperty({ type: String })
nonce: string
}
27 changes: 14 additions & 13 deletions apps/authz/src/app/http/rest/dto/create-organization-request.dto.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
import { Action } from '@narval/authz-shared'
import { ApiProperty } from '@nestjs/swagger'
import { IsDefined, IsIn, IsString, ValidateNested } from 'class-validator'
import { Type } from 'class-transformer'
import { IsDefined, 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 CreateOrganizationDataDto {
@IsString()
@IsDefined()
@ApiProperty()
@IsNotEmpty()
@ApiProperty({ type: String })
uid: string

@IsString()
@IsDefined()
@ApiProperty()
@ValidateNested()
@Type(() => AuthCredentialDto)
@ApiProperty({ type: String })
credential: AuthCredentialDto
}

class CreateOrganizationActionDto extends BaseActionDto {
@IsIn(Object.values(Action))
@IsDefined()
@ApiProperty({
enum: Object.values(Action),
default: Action.CREATE_ORGANIZATION
})
@IsString()
@IsNotEmpty()
@Matches(Action.CREATE_ORGANIZATION)
@ApiProperty({ default: Action.CREATE_ORGANIZATION })
action: typeof Action.CREATE_ORGANIZATION

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

export class CreateOrganizationRequestDto extends BaseAdminRequestPayloadDto {
@IsDefined()
@ValidateNested()
@ApiProperty()
@Type(() => CreateOrganizationActionDto)
@ApiProperty({ type: () => CreateOrganizationActionDto })
request: CreateOrganizationActionDto
}

0 comments on commit 4f5f92a

Please sign in to comment.