How to use the class-transformer.classToPlain 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 goparrot / geocoder / src / model / location.ts View on Github external
toObject(options?: ClassTransformOptions): LocationInterface {
        return classToPlain>(this, options) as LocationInterface;
    }
}
github buttplugio / buttplug-js / src / core / Messages.ts View on Github external
public toProtocolFormat(): object {
    const jsonObj = {};
    jsonObj[this.Type] = classToPlain(this);
    return jsonObj;
  }
}
github dilame / instagram-private-api / src / responses / instagram.response.ts View on Github external
get params() {
    return camelKeys(classToPlain(this), { deep: true });
  }
}
github tsmean / tsmean / backend / src / auth / auth.controller.ts View on Github external
const emailValidation = await this.emailValidator.validateEmail(req.email);
    if (!emailValidation.isValid) {
      throw new BadRequestException('Invalid email!');
    }
    const passwordValidation = await this.passwordValidator.validatePassword(req.password);
    if (!emailValidation.isValid) {
      throw new BadRequestException('Invalid password!');
    }

    const user = await this.userService.findOneByEmail(req.email);

    if (!user || !await this.passwordCryptographerService.doCompare(req.password, user.password.hash)) {
      throw new BadRequestException('Incorrect email or password!');
    }

    const token = this.authService.createToken(classToPlain(user));
    return {
      user,
      token
    };
  }
}
github buttplugio / buttplug-js / src / core / messages.ts View on Github external
public toJSON(): string {
    const jsonObj = {};
    const instance: any = this.constructor;
    jsonObj[instance.name] = classToPlain(this);
    return JSON.stringify(jsonObj);
  }
}
github danielwii / asuna-node-server / src / modules / core / storage / storage.minio.engine.ts View on Github external
constructor(configure: () => MinioConfigObject, opts: { defaultBucket?: string } = {}) {
    this.defaultBucket = opts.defaultBucket || 'default';
    this.configObject = configure();
    if (this.configObject.enable !== true) {
      throw new Error(
        `minio must enable when using minio storage engine: ${r({
          configs: classToPlain(this.configObject),
          opts,
        })}`,
      );
    }
    MinioStorage.logger.log(`[constructor] init ${r({ configs: classToPlain(this.configObject), opts })}`);
    /*
    Hermes.setupJobProcessor(AsunaSystemQueue.UPLOAD, (job: Job) => {
      const { bucket, filenameWithPrefix, file } = job.data;
      return this.client
        .fPutObject(bucket, filenameWithPrefix, file.path, {
          'Content-Type': file.mimetype,
        })
        .then(uploaded => {
          MinioStorage.logger.log(`[saveEntity] [${uploaded}] ...`);
          return uploaded;
        })
        .catch(error => {
          MinioStorage.logger.error(
            `[saveEntity] [${filenameWithPrefix}] error: ${error}`,
            error.trace,
          );
github devonfw / my-thai-star / node / src / app / booking / model / dto / booking-page.dto.ts View on Github external
content: bookings.map(booking => {
        return {
          booking:
            booking && classToPlain(booking, { excludeExtraneousValues: true }),
          table: booking.table && classToPlain(booking.table),
          invitedGuests:
            booking.invitedGuests && classToPlain(booking.invitedGuests),
          order: booking.order && classToPlain(booking.order),
          orders:
            booking.order &&
            booking.invitedGuests &&
            booking.invitedGuests.map(element => element.order),
          user: booking.user && classToPlain(booking.user),
        };
      }),
    });
github nestjsx / crud / packages / crud / src / interceptors / crud-response.interceptor.ts View on Github external
protected transform(dto: any, data: any) {
    if (!isObject(data) || isFalse(dto)) {
      return data;
    }

    if (!isFunction(dto)) {
      return data.constructor !== Object ? classToPlain(data) : data;
    }

    return data instanceof dto
      ? classToPlain(data)
      : classToPlain(classToPlainFromExist(data, new dto()));
  }
github weeco / fortnite-client / src / models / lookup / lookup.ts View on Github external
public toJson(): {} {
    return classToPlain(this);
  }
}