@nestjs/common#applyDecorators TypeScript Examples
The following examples show how to use
@nestjs/common#applyDecorators.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: api-properties.ts From aqualink-app with MIT License | 9 votes |
ApiFileUpload = () => {
const maxFileSizeMB = process.env.STORAGE_MAX_FILE_SIZE_MB
? parseInt(process.env.STORAGE_MAX_FILE_SIZE_MB, 10)
: 1;
return applyDecorators(
ApiConsumes('multipart/form-data'),
ApiBody({
schema: {
type: 'object',
properties: {
file: {
description: `The image to upload (image/jpeg, image/png, image/tiff). Max size: ${maxFileSizeMB}MB`,
type: 'string',
format: 'binary',
},
},
},
}),
);
}
Example #2
Source File: api-pagination.response.ts From nest-js-quiz-manager with MIT License | 6 votes |
ApiPaginatedResponse = <TModel extends Type<any>>(
options: IPaginatedDecoratorApiResponse,
) => {
return applyDecorators(
ApiExtraModels(PaginatedDto),
ApiOkResponse({
description: options.description || 'Successfully received model list',
schema: {
allOf: [
{ $ref: getSchemaPath(PaginatedDto) },
{
properties: {
items: {
type: 'array',
items: { $ref: getSchemaPath(options.model) },
},
meta: {
type: 'any',
default: {
totalItems: 2,
itemCount: 2,
itemsPerPage: 2,
totalPages: 1,
currentPage: 1,
},
},
},
},
],
},
}),
);
}
Example #3
Source File: api-nested-query.decorator.ts From amplication with Apache License 2.0 | 6 votes |
// eslint-disable-next-line @typescript-eslint/ban-types,@typescript-eslint/explicit-module-boundary-types,@typescript-eslint/naming-convention
export function ApiNestedQuery(query: Function) {
const constructor = query.prototype;
const properties = Reflect.getMetadata(
"swagger/apiModelPropertiesArray",
constructor
).map((prop: any) => prop.slice(1));
const decorators = properties
.map((property: any) => {
const { required, isArray } = Reflect.getMetadata(
"swagger/apiModelProperties",
constructor,
property
);
const propertyType = Reflect.getMetadata(
"design:type",
constructor,
property
);
const typedQuery = generateApiQueryObject(
property,
propertyType,
required,
isArray
);
return [ApiExtraModels(propertyType), ApiQuery(typedQuery)];
})
.flat();
return applyDecorators(...decorators);
}
Example #4
Source File: api-properties.ts From aqualink-app with MIT License | 6 votes |
ApiUpdateSiteApplicationBody = () => {
return applyDecorators(
ApiBody({
schema: {
type: 'object',
properties: {
site: {
$ref: getSchemaPath(UpdateSiteWithApplicationDto),
},
siteApplication: {
$ref: getSchemaPath(UpdateSiteApplicationDto),
},
},
},
}),
);
}
Example #5
Source File: api-properties.ts From aqualink-app with MIT License | 6 votes |
ApiCreateSiteBody = () => {
return applyDecorators(
ApiBody({
schema: {
type: 'object',
properties: {
site: {
$ref: getSchemaPath(CreateSiteDto),
},
siteApplication: {
$ref: getSchemaPath(CreateSiteApplicationDto),
},
},
},
}),
);
}
Example #6
Source File: HttpAuth.ts From typescript-clean-architecture with MIT License | 5 votes |
HttpAuth = (...roles: UserRole[]): (...args: any) => void => {
return applyDecorators(
SetMetadata('roles', roles),
UseGuards(HttpJwtAuthGuard, HttpRoleAuthGuard)
);
}
Example #7
Source File: auth.decorator.ts From nest-js-boilerplate with MIT License | 5 votes |
export default function Auth(...roles: RolesEnum[]) {
return applyDecorators(
SetMetadata('roles', roles),
UseGuards(JwtAccessGuard, RolesGuard),
);
}
Example #8
Source File: public.decorator.ts From nest-keycloak-connect with MIT License | 5 votes |
Public = (skipAuth = true) =>
applyDecorators(
SetMetadata(META_UNPROTECTED, true),
SetMetadata(META_SKIP_AUTH, skipAuth),
)
Example #9
Source File: public.decorator.ts From nest-keycloak-connect with MIT License | 5 votes |
Unprotected = (skipAuth = true) =>
applyDecorators(
SetMetadata(META_UNPROTECTED, true),
SetMetadata(META_SKIP_AUTH, skipAuth),
)
Example #10
Source File: except-tracing.decorator.ts From nestjs-jaeger-tracing with MIT License | 5 votes |
export function ExceptTracing(): MethodDecorator {
return applyDecorators(SetMetadata(EXCEPT_TRACING, true));
}
Example #11
Source File: is-files.validator.ts From nestjs-form-data with MIT License | 5 votes |
export function IsFiles(validationOptions?: ValidationOptions): PropertyDecorator {
return applyDecorators(
IsArray(validationOptions),
IsFile(Object.assign(validationOptions || {}, { each: true })),
);
}
Example #12
Source File: form-data.ts From nestjs-form-data with MIT License | 5 votes |
export function FormDataRequest(config?: FormDataInterceptorConfig) {
return applyDecorators(
SetMetadata(FORM_DATA_REQUEST_METADATA_KEY, config),
UseInterceptors(FormDataInterceptor),
);
}
Example #13
Source File: recaptcha.ts From google-recaptcha with MIT License | 5 votes |
export function Recaptcha(options?: VerifyResponseDecoratorOptions): MethodDecorator & ClassDecorator {
return applyDecorators(
SetRecaptchaOptions(options),
UseGuards(GoogleRecaptchaGuard),
);
}
Example #14
Source File: api-time-series-response.ts From aqualink-app with MIT License | 5 votes |
ApiTimeSeriesRangeResponse = () => {
const sources = Object.values(SourceType)
.map((source) => {
const metrics = Object.values(Metric)
.map((metric): Record<string, SchemaObject> => {
return {
[metric]: {
type: 'array',
items: {
type: 'object',
properties: {
maxDate: {
type: 'string',
format: 'date-time',
},
minDate: {
type: 'string',
format: 'date-time',
},
},
},
},
};
})
.reduce(reduceArrayToObject, {});
return {
[source]: {
type: 'object',
properties: metrics,
},
};
})
.reduce(reduceArrayToObject, {});
return applyDecorators(
ApiOkResponse({
schema: {
type: 'object',
properties: sources,
},
}),
);
}
Example #15
Source File: api-time-series-response.ts From aqualink-app with MIT License | 5 votes |
ApiTimeSeriesResponse = () => {
const sources = Object.values(SourceType)
.map((source) => {
const metrics = Object.values(Metric)
.map((metric): Record<string, SchemaObject> => {
return {
[metric]: {
type: 'array',
items: {
type: 'object',
properties: {
timestamp: {
type: 'string',
format: 'date-time',
},
value: {
type: 'number',
example: '12.32',
},
},
},
},
};
})
.reduce(reduceArrayToObject, {});
return {
[source]: {
type: 'object',
properties: metrics,
},
};
})
.reduce(reduceArrayToObject, {});
return applyDecorators(
ApiOkResponse({
schema: {
type: 'object',
properties: sources,
},
}),
);
}
Example #16
Source File: api-response.ts From aqualink-app with MIT License | 5 votes |
ApiNestUnauthorizedResponse = (description: string) => {
return applyDecorators(
ApiUnauthorizedResponse({
schema: errorSchema(HttpStatus.UNAUTHORIZED),
description,
}),
);
}
Example #17
Source File: api-response.ts From aqualink-app with MIT License | 5 votes |
ApiNestBadRequestResponse = (description: string) => {
return applyDecorators(
ApiBadRequestResponse({
schema: errorSchema(HttpStatus.BAD_REQUEST),
description,
}),
);
}
Example #18
Source File: api-response.ts From aqualink-app with MIT License | 5 votes |
ApiNestNotFoundResponse = (description: string) => {
return applyDecorators(
ApiNotFoundResponse({
schema: errorSchema(HttpStatus.NOT_FOUND),
description,
}),
);
}
Example #19
Source File: api-properties.ts From aqualink-app with MIT License | 5 votes |
ApiPointProperty = () => {
return applyDecorators(ApiProperty(PointSchema));
}
Example #20
Source File: public.decorator.ts From aqualink-app with MIT License | 5 votes |
Public = () => {
return applyDecorators(SetMetadata('isPublic', true));
}
Example #21
Source File: override-level-access.decorator.ts From aqualink-app with MIT License | 5 votes |
OverrideLevelAccess = (...levels: AdminLevel[]) => {
return applyDecorators(SetMetadata('levels', levels));
}
Example #22
Source File: auth.decorator.ts From aqualink-app with MIT License | 5 votes |
Auth = (...levels: AdminLevel[]) => {
return applyDecorators(
SetMetadata('levels', levels),
UseGuards(FirebaseAuthGuard, LevelsGuard),
);
}
Example #23
Source File: public.decorator.ts From amplication with Apache License 2.0 | 5 votes |
Public = () =>
applyDecorators(PublicAuthMiddleware, PublicAuthSwagger)