|
| 1 | +import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; |
| 2 | +import { IsInt, IsNotEmpty, IsObject, IsOptional, IsString, MinLength } from 'class-validator'; |
| 3 | + |
| 4 | +class SitenovaAuthBaseDto { |
| 5 | + @ApiProperty({ description: 'Name of the users/auth table in the connected database.' }) |
| 6 | + @IsString() |
| 7 | + @IsNotEmpty() |
| 8 | + tableName: string; |
| 9 | + |
| 10 | + @ApiProperty({ description: 'End-user identifier (matched against the email column).' }) |
| 11 | + @IsString() |
| 12 | + @IsNotEmpty() |
| 13 | + email: string; |
| 14 | + |
| 15 | + @ApiPropertyOptional({ description: 'Override the email column name (default: "email").' }) |
| 16 | + @IsOptional() |
| 17 | + @IsString() |
| 18 | + emailField?: string; |
| 19 | + |
| 20 | + @ApiPropertyOptional({ description: 'Override the password column name (default: "password").' }) |
| 21 | + @IsOptional() |
| 22 | + @IsString() |
| 23 | + passwordField?: string; |
| 24 | +} |
| 25 | + |
| 26 | +export class SitenovaRegisterDto extends SitenovaAuthBaseDto { |
| 27 | + @ApiProperty({ description: 'End-user password (stored hashed; min 6 chars).' }) |
| 28 | + @IsString() |
| 29 | + @MinLength(6) |
| 30 | + password: string; |
| 31 | + |
| 32 | + @ApiPropertyOptional({ type: Object, description: 'Additional columns to set on the new user row.' }) |
| 33 | + @IsOptional() |
| 34 | + @IsObject() |
| 35 | + extra?: Record<string, unknown>; |
| 36 | +} |
| 37 | + |
| 38 | +export class SitenovaLoginDto extends SitenovaAuthBaseDto { |
| 39 | + @ApiProperty({ description: 'End-user password.' }) |
| 40 | + @IsString() |
| 41 | + @IsNotEmpty() |
| 42 | + password: string; |
| 43 | +} |
| 44 | + |
| 45 | +export class SitenovaSiteCreateRowDto { |
| 46 | + @ApiProperty() |
| 47 | + @IsString() |
| 48 | + @IsNotEmpty() |
| 49 | + tableName: string; |
| 50 | + |
| 51 | + @ApiProperty({ type: Object }) |
| 52 | + @IsObject() |
| 53 | + row: Record<string, unknown>; |
| 54 | +} |
| 55 | + |
| 56 | +export class SitenovaSiteGetRowsDto { |
| 57 | + @ApiProperty() |
| 58 | + @IsString() |
| 59 | + @IsNotEmpty() |
| 60 | + tableName: string; |
| 61 | + |
| 62 | + @ApiPropertyOptional() |
| 63 | + @IsOptional() |
| 64 | + @IsInt() |
| 65 | + page?: number; |
| 66 | + |
| 67 | + @ApiPropertyOptional() |
| 68 | + @IsOptional() |
| 69 | + @IsInt() |
| 70 | + perPage?: number; |
| 71 | + |
| 72 | + @ApiPropertyOptional() |
| 73 | + @IsOptional() |
| 74 | + @IsString() |
| 75 | + search?: string; |
| 76 | + |
| 77 | + @ApiPropertyOptional({ type: Object }) |
| 78 | + @IsOptional() |
| 79 | + @IsObject() |
| 80 | + filters?: Record<string, unknown>; |
| 81 | +} |
| 82 | + |
| 83 | +export class SitenovaSiteRowByPrimaryKeyDto { |
| 84 | + @ApiProperty() |
| 85 | + @IsString() |
| 86 | + @IsNotEmpty() |
| 87 | + tableName: string; |
| 88 | + |
| 89 | + @ApiProperty({ type: Object }) |
| 90 | + @IsObject() |
| 91 | + primaryKey: Record<string, unknown>; |
| 92 | +} |
| 93 | + |
| 94 | +export class SitenovaSiteUpdateRowDto extends SitenovaSiteRowByPrimaryKeyDto { |
| 95 | + @ApiProperty({ type: Object }) |
| 96 | + @IsObject() |
| 97 | + row: Record<string, unknown>; |
| 98 | +} |
| 99 | + |
| 100 | +export class SitenovaEndUserAuthResponseDto { |
| 101 | + @ApiProperty({ description: 'End-user JWT to send as Bearer on write requests.' }) |
| 102 | + token: string; |
| 103 | + |
| 104 | + @ApiProperty({ type: Object, description: 'The authenticated user row (password field stripped).' }) |
| 105 | + user: Record<string, unknown>; |
| 106 | +} |
0 commit comments