Skip to content

Commit

Permalink
Revert "fix DTOs"
Browse files Browse the repository at this point in the history
This reverts commit 4f5f92a.
  • Loading branch information
samuel committed Feb 13, 2024
1 parent 48e549d commit 5018b0d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
19 changes: 10 additions & 9 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 { IsEnum, IsNotEmpty, IsString } from 'class-validator'
import { IsDefined, IsIn, IsString } from 'class-validator'

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

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

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

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

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

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

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

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

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

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

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

0 comments on commit 5018b0d

Please sign in to comment.