class-transformer#Transform TypeScript Examples

The following examples show how to use class-transformer#Transform. 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: models.ts    From aws-resource-providers with MIT License 6 votes vote down vote up
@Expose({ name: 'EmailAddress' })
    @Transform(
        (value: any, obj: any) =>
            transformValue(String, 'emailAddress', value, obj, []),
        {
            toClassOnly: true,
        }
    )
    emailAddress?: Optional<string>;
Example #2
Source File: sample-model.ts    From cloudformation-cli-typescript-plugin with Apache License 2.0 6 votes vote down vote up
@Expose({ name: 'ListListAny' })
    @Transform(
        (value, obj) =>
            transformValue(Object, 'listListAny', value, obj, [Array, Array]),
        {
            toClassOnly: true,
        }
    )
    listListAny?: Optional<Array<Array<object>>>;
Example #3
Source File: models.ts    From aws-resource-providers with MIT License 6 votes vote down vote up
@Expose({ name: 'CCEmailAddresses' })
    @Transform(
        (value: any, obj: any) =>
            transformValue(String, 'cCEmailAddresses', value, obj, [Array]),
        {
            toClassOnly: true,
        }
    )
    cCEmailAddresses?: Optional<Array<string>>;
Example #4
Source File: user.ts    From Deep-Lynx with MIT License 6 votes vote down vote up
// because the end user of this class often needs more information about
    // the container for the invite email, we're going to include and load
    // the full container class instead of just doing the ID. The repository
    // should load the relationship on demand
    @ContainerID({message: 'Container must have valid ID'})
    @Expose({name: 'container_id', toClassOnly: true})
    @Transform(
        ({value}) => {
            const container = plainToClass(Container, {});
            container.id = value;
            return container;
        },
        {toClassOnly: true},
    )
    container: Container | undefined;
Example #5
Source File: models.ts    From aws-resource-providers with MIT License 6 votes vote down vote up
@Expose({ name: 'AlternateContactType' })
    @Transform(
        (value: any, obj: any) =>
            transformValue(String, 'alternateContactType', value, obj, []),
        {
            toClassOnly: true,
        }
    )
    alternateContactType?: Optional<string>;
Example #6
Source File: pagination-params.dto.ts    From nestjs-starter-rest-api with MIT License 6 votes vote down vote up
@ApiPropertyOptional({
    description: 'Optional, defaults to 0',
    type: Number,
  })
  @IsNumber()
  @IsOptional()
  @Min(0)
  @Transform(({ value }) => parseInt(value, 10), { toClassOnly: true })
  offset = 0;
Example #7
Source File: models.ts    From aws-resource-providers with MIT License 6 votes vote down vote up
@Expose({ name: 'VPCRegion' })
    @Transform(
        (value: any, obj: any) =>
            transformValue(String, 'vPCRegion', value, obj, []),
        {
            toClassOnly: true,
        }
    )
    vPCRegion?: Optional<string>;
Example #8
Source File: node.ts    From Deep-Lynx with MIT License 6 votes vote down vote up
// we often need the metatype's name, it's keys, or access to other properties
    // when we deal with nodes, so for ease of use we're going to use the whole
    // class, not just the id
    @MetatypeID({message: 'Metatype must have valid ID'})
    @Expose({name: 'metatype_id', toClassOnly: true})
    @Transform(
        ({value}) => {
            const metatype = plainToClass(Metatype, {});
            metatype.id = value;
            return metatype;
        },
        {toClassOnly: true},
    )
    @Type(() => Metatype)
    metatype: Metatype | undefined;
Example #9
Source File: models.ts    From aws-resource-providers with MIT License 6 votes vote down vote up
@Expose({ name: 'Name' })
    @Transform(
        (value: any, obj: any) =>
            transformValue(String, 'name', value, obj, []),
        {
            toClassOnly: true,
        }
    )
    name?: Optional<string>;