How to use the @tsed/core.getClass function in @tsed/core

To help you get started, we’ve selected a few @tsed/core 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 TypedProject / ts-express-decorators / packages / common / src / converters / services / ConverterService.ts View on Github external
// if (options.type && !isPrimitiveOrPrimitiveClass(options.type)) {
      //  return this.serializeClass(obj, options);
      // }

      if (typeof obj.toJSON === "function" && !obj.toJSON.$ignore) {
        // deserialize from serialize method
        return obj.toJSON();
      }

      // Default converter
      if (!isPrimitiveOrPrimitiveClass(obj)) {
        return this.serializeClass(obj, options);
      }
    } catch (err) {
      /* istanbul ignore next */
      throw err.name === "BAD_REQUEST" ? err : new ConverterSerializationError(getClass(obj), err);
    }

    /* istanbul ignore next */
    return obj;
  }
github TypedProject / ts-express-decorators / test / units / core / utils / ObjectUtils.spec.ts View on Github external
it("should return the class when prototype is given", () => {
      expect(getClass(Test.prototype)).to.eq(Test);
    });
  });
github TypedProject / ts-express-decorators / test / units / core / utils / ObjectUtils.spec.ts View on Github external
it("should return the class when class is given", () => {
      expect(getClass(Test)).to.eq(Test);
    });
github TypedProject / ts-express-decorators / packages / di / src / services / InjectorService.ts View on Github external
public bindInterceptor(instance: any, {propertyKey, useType, options}: IInjectablePropertyService) {
    const target = getClass(instance);
    const originalMethod = instance[propertyKey];

    instance[propertyKey] = (...args: any[]) => {
      const next = (err?: Error) => {
        if (!err) {
          return originalMethod.apply(instance, args);
        }

        throw err;
      };

      const context: IInterceptorContext = {
        target,
        method: propertyKey,
        propertyKey,
        args,
github TypedProject / ts-express-decorators / packages / di / src / services / InjectorService.ts View on Github external
public bindMethod(instance: any, {propertyKey}: IInjectablePropertyService) {
    const target = getClass(instance);
    const originalMethod = instance[propertyKey];
    const deps = Metadata.getParamTypes(prototypeOf(target), propertyKey);

    instance[propertyKey] = () => {
      const services = deps.map((dependency: any) => this.get(dependency));

      return originalMethod.call(instance, ...services);
    };
  }
github TypedProject / ts-express-decorators / packages / common / src / converters / services / ConverterService.ts View on Github external
private checkStrictModelValidation(instance: any, propertyKey: string | symbol, propertyMetadata: PropertyMetadata | undefined) {
    if (this.isStrictModelValidation(getClass(instance)) && propertyMetadata === undefined) {
      throw new UnknownPropertyError(getClass(instance), propertyKey);
    }
  }
github TypedProject / ts-express-decorators / src / mongoose / utils / createModel.ts View on Github external
target.prototype.serialize = function(options: IConverterOptions, converterService: ConverterService) {
    const {checkRequiredValue, ignoreCallback} = options;

    return converterService.serializeClass(this, {
      type: getClass(target),
      checkRequiredValue,
      ignoreCallback
    });
  };