-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f3d89a
commit 8bb6982
Showing
6 changed files
with
144 additions
and
53 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
2 changes: 1 addition & 1 deletion
2
src/common/pipes/filter-validation.pipe.ts → src/datasets/pipes/filter-validation.pipe.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
File renamed without changes.
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,38 @@ | ||
import { PipeTransform, Injectable } from "@nestjs/common"; | ||
import { BadRequestException } from "@nestjs/common/exceptions"; | ||
import { ConfigService } from "@nestjs/config"; | ||
import { CreateDatasetDto } from "../dto/create-dataset.dto"; | ||
|
||
@Injectable() | ||
export class PidValidationPipe | ||
implements PipeTransform<CreateDatasetDto, CreateDatasetDto> | ||
{ | ||
constructor(private configService: ConfigService) { | ||
this.datasetCreationValidationEnabled = this.configService.get<boolean>( | ||
"datasetCreationValidationEnabled", | ||
); | ||
this.datasetCreationValidationRegex = this.configService.get<string>( | ||
"datasetCreationValidationRegex", | ||
); | ||
} | ||
|
||
private datasetCreationValidationEnabled; | ||
private datasetCreationValidationRegex; | ||
|
||
transform(dataset: CreateDatasetDto): CreateDatasetDto { | ||
if ( | ||
this.datasetCreationValidationEnabled && | ||
this.datasetCreationValidationRegex && | ||
dataset.pid | ||
) { | ||
const re = new RegExp(this.datasetCreationValidationRegex); | ||
if (!re.test(dataset.pid)) { | ||
throw new BadRequestException( | ||
"PID is not following required standards", | ||
); | ||
} | ||
} | ||
|
||
return dataset; | ||
} | ||
} |
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,60 @@ | ||
import { ContentObject } from "@nestjs/swagger/dist/interfaces/open-api-spec.interface"; | ||
|
||
export const getSwaggerDatasetFilterContent = (): ContentObject | undefined => { | ||
/** | ||
* NOTE: This is disabled only for the official sdk package generation as the schema validation complains about the content. | ||
* But we want to have it when we run the application as it improves swagger documentation and usage a lot. | ||
*/ | ||
console.log(process.env.SDK_PACKAGE_SWAGGER_HELPERS_DISABLED); | ||
return process.env.SDK_PACKAGE_SWAGGER_HELPERS_DISABLED | ||
? undefined | ||
: { | ||
"application/json": { | ||
schema: { | ||
type: "object", | ||
properties: { | ||
where: { | ||
type: "object", | ||
}, | ||
include: { | ||
type: "array", | ||
items: { | ||
type: "string", | ||
}, | ||
}, | ||
fields: { | ||
type: "array", | ||
items: { | ||
type: "string", | ||
}, | ||
}, | ||
limits: { | ||
type: "object", | ||
properties: { | ||
limit: { | ||
type: "number", | ||
}, | ||
skip: { | ||
type: "number", | ||
}, | ||
order: { | ||
type: "array", | ||
items: { | ||
type: "object", | ||
properties: { | ||
field: { | ||
type: "string", | ||
}, | ||
direction: { | ||
type: "string", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
}; |