How to use the class-transformer.plainToClass function in class-transformer

To help you get started, we’ve selected a few class-transformer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rucken / cli / entity / src / apps / demo / migrations / 1533634559618-AddDemoTable.ts View on Github external
.getRepository(ContentType)
      .save(
        plainToClass(ContentType, { name: 'demo', title: 'Demo' })
      );
    const ctUser = await queryRunner.manager
      .getRepository(ContentType)
      .findOneOrFail({
        where: {
          name: 'user'
        }
      });
    // create permissions
    const readPermissions = await queryRunner.manager
      .getRepository(Permission)
      .save(
        plainToClass(Permission, [
          {
            title: 'Can read demo',
            name: 'read_demo',
            contentType: ctNewEntity
          },
          {
            title: 'Can read demos frame',
            name: 'read_demos-frame',
            contentType: ctUser
          },
          {
            title: 'Can read demos page',
            name: 'read_demos-page',
            contentType: ctUser
          }
        ])
github rucken / todo-nestjs / libs / rucken / todo-nestjs / src / controllers / tasks.controller.ts View on Github external
async findAll(
    @Req() req,
    @Query('cur_page', new ParseIntWithDefaultPipe(1)) curPage,
    @Query('per_page', new ParseIntWithDefaultPipe(10)) perPage,
    @Query('q') q,
    @Query('sort') sort,
    @Query('project') project,
    @Query('users') usersIds,
    @Query('statuses') statusesNames
  ) {
    try {
      return plainToClass(
        OutTasksDto,
        await this.service.findAll(
          {
            curPage,
            perPage,
            q,
            sort,
            project,
            usersIds: usersIds ? usersIds.split(',').filter(id => !isNaN(+id)).map(id => +id) : [],
            statusesNames: statusesNames ? statusesNames.split(',').map(name => name.trim()) : []
          },
          req.user
        )
      );
    } catch (error) {
      throw error;
github rucken / todo-nestjs / src / libs / core / controllers / users.controller.ts View on Github external
async update(@Param('id', new ParseIntPipe()) id, @Body() dto: InUserDto) {
    try {
      return plainToClass(
        OutUserDto,
        await this.service.update({
          id,
          item: await plainToClass(User, dto).setPassword(dto.password)
        })
      );
    } catch (error) {
      throw error;
    }
  }
  @Roles('isSuperuser')
github weeco / fortnite-client / src / models / news / athenamessage.ts View on Github external
public static FROM_JSON(jsonObject: {}): Athenamessage {
    return plainToClass(Athenamessage, jsonObject);
  }
github rucken / core / libs / rucken / core / src / lib / entities / configs / content-types.config.ts View on Github external
responseData: (data: any, action: ProviderActionEnum) => {
      if (action === ProviderActionEnum.Delete) {
        return true;
      } else {
        if (action === ProviderActionEnum.LoadAll) {
          return plainToClass(ContentType, data.body.contentTypes);
        } else {
          return plainToClass(ContentType, data.body.contentType);
        }
      }
    },
    responsePaginationMeta: (data: any, action: ProviderActionEnum): PaginationMeta => {
github ZhiXiao-Lin / nestify / server / src / common / entities / carousel.entity.ts View on Github external
static create(target: object): Carousel | Carousel[] {
        return plainToClass(Carousel, target);
    }
github EndyKaufman / ngx-dynamic-form-builder / libs / ngx-dynamic-form-builder / src / shared / utils / dynamic-form-group.ts View on Github external
plainToClass(cls: ClassType, plain: Object) {
        return plainToClass(cls, plain, { ignoreDecorators: true });
    }
    private mergeErrors(errors?: IShortValidationErrors, externalErrors?: IShortValidationErrors) {
github weeco / fortnite-client / src / models / login / oauth-exchange.ts View on Github external
public static FROM_JSON(jsonObject: {}): OAuthExchange {
    return plainToClass(OAuthExchange, jsonObject);
  }
github dilame / instagram-private-api / src / feeds / story-tray.feed.ts View on Github external
async get() {
    const { tray } = await new Request(this.session)
      .setMethod('POST')
      .setResource('storyTray')
      .setBodyType('form')
      .setData({})
      .setData({
        _uuid: this.session.uuid,
        _csrftoken: this.session.CSRFToken,
        supported_capabilities_new: JSON.stringify(SUPPORTED_CAPABILITIES),
      })
      .send();
    return plainToClass(StoryTrayResponse, tray);
  }
}
github rucken / todo-nestjs / libs / rucken / todo-nestjs / src / migrations / 1538225369404-FillData.ts View on Github external
description: 'Description of project 1',
        isPublic: true,
        users: [uUser1]
      })
    );
    const pProject1Statuses = await queryRunner.manager
      .getRepository(Status1538225369404)
      .save(
        plainToClass(Status1538225369404, [
          { title: 'status 1 for project 1', name: 'p1s1', project: pProject1 },
          { title: 'status 2 for project 1', name: 'p1s2', project: pProject1 },
          { title: 'status 3 for project 1', name: 'p1s3', project: pProject1 }
        ])
      );
    const pProject1Tasks = await queryRunner.manager.getRepository(Task1538225369404).save(
      plainToClass(Task1538225369404, [
        {
          title: 'Task 1 for project 1',
          description: 'Task 1 of project 1',
          project: pProject1,
          openAt: new Date(),
          status: pProject1Statuses[0]
        },
        {
          title: 'Task 2 for project 1',
          description: 'Task 2 of project 1',
          project: pProject1,
          openAt: new Date(),
          closeAt: new Date(),
          status: pProject1Statuses[1]
        },
        {