-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #403 from hpi-dhc/issue/258-validate-dtos
Validate DTOs
- Loading branch information
Showing
16 changed files
with
112 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class InstantiableDto<T> { | ||
constructor(dto: T) { | ||
Object.entries(dto).forEach(([key, value]) => { | ||
this[key] = value; | ||
}); | ||
} | ||
} |
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,4 +1,30 @@ | ||
import { BaseEntity } from '../entities/base.entity'; | ||
import { ParseArrayOptions, ParseArrayPipe } from '@nestjs/common'; | ||
import { | ||
IntersectionType, | ||
OmitType, | ||
PartialType, | ||
PickType, | ||
} from '@nestjs/mapped-types'; | ||
|
||
export type PatchBodyDto<T extends BaseEntity> = (Pick<T, 'id'> & | ||
Partial<Omit<T, 'id'>>)[]; | ||
import { Guideline } from '../../guidelines/entities/guideline.entity'; | ||
import { Medication } from '../../medications/medication.entity'; | ||
|
||
export class PatchMedicationDto extends IntersectionType( | ||
PickType(Medication, ['id'] as const), | ||
PartialType(Medication), | ||
) {} | ||
|
||
export class PatchGuidelineDto extends IntersectionType( | ||
PickType(Guideline, ['id'] as const), | ||
OmitType(PartialType(Guideline), ['id'] as const), | ||
) {} | ||
|
||
export function getPatchArrayPipe( | ||
items: ParseArrayOptions['items'], | ||
): ParseArrayPipe { | ||
return new ParseArrayPipe({ | ||
items, | ||
whitelist: true, | ||
forbidNonWhitelisted: true, | ||
}); | ||
} |
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,6 +1,8 @@ | ||
import { IsNumber } from 'class-validator'; | ||
import { PrimaryGeneratedColumn } from 'typeorm'; | ||
|
||
export abstract class BaseEntity { | ||
@PrimaryGeneratedColumn() | ||
@IsNumber() | ||
id: number; | ||
} |
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: 3 additions & 1 deletion
4
annotation-server/src/guidelines/dtos/cpic-recommendation.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
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
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
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
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