How to use the @tsed/core.Store.fromMethod 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 / multipartfiles / src / decorators / multipartFile.ts View on Github external
return (target: any, propertyKey: string | symbol, index: number): void => {
    const type = getDecoratorType([target, propertyKey, index], true);

    switch (type) {
      default:
        throw new Error("MultipartFile is only supported on parameters");

      case "parameter":
        const store = Store.fromMethod(target, String(propertyKey));
        const multiple = Metadata.getParamTypes(target, propertyKey)[index] === Array;
        const options = typeof name === "object" ? name : undefined;
        const added = store.has("multipartAdded");

        name = (typeof name === "object" ? undefined : name)!;

        // create endpoint metadata
        store.merge("consumes", ["multipart/form-data"]).set("multipartAdded", true);
        store
          .merge("responses", {
            "400": {
              description: `  [fieldName]
                            Example: File too long file1`
            }
          })
          .set("multipartAdded", true);
github TypedProject / ts-express-decorators / test / units / swagger / decorators / returnsArray.spec.ts View on Github external
before(() => {
      ReturnsArray(400, {
        description: "Bad Request"
      })(Test, "test1", descriptorOf(Test, "test1"));
      this.store = Store.fromMethod(Test, "test1");
    });
    it("should set the responses", () => {
github TypedProject / ts-express-decorators / test / units / swagger / decorators / returns.spec.ts View on Github external
before(() => {
      Returns(Test, {
        description: "Success"
      })(Test, "test2", descriptorOf(Test, "test2"));
      this.store = Store.fromMethod(Test, "test2");
    });
    it("should set the responses", () => {
github TypedProject / ts-express-decorators / test / units / swagger / decorators / responses.spec.ts View on Github external
before(() => {
    Responses(400, {
      description: "Bad Request"
    })(Test, "test", descriptorOf(Test, "test"));
    this.store = Store.fromMethod(Test, "test");
  });
  it("should set the responses", () => {
github TypedProject / ts-express-decorators / test / units / swagger / decorators / returns.spec.ts View on Github external
before(() => {
      Returns({
        description: "Success",
        type: Test
      })(Test, "test4", descriptorOf(Test, "test4"));
      this.store = Store.fromMethod(Test, "test4");
    });
    it("should set the responses", () => {
github TypedProject / ts-express-decorators / test / units / swagger / decorators / returnsArray.spec.ts View on Github external
before(() => {
      ReturnsArray(Test)(Test, "test3", descriptorOf(Test, "test3"));
      this.store = Store.fromMethod(Test, "test3");
    });
    it("should set the responses", () => {
github TypedProject / ts-express-decorators / test / units / mvc / decorators / method / authenticated.spec.ts View on Github external
before(() => {
    this.descriptor = {};
    this.options = {options: "options"};

    Authenticated(this.options)(Test, "test", descriptorOf(Test, "test"));
    this.store = Store.fromMethod(Test, "test");
  });
github TypedProject / ts-express-decorators / test / units / multipartfiles / decorators / multerOptions.spec.ts View on Github external
before(() => {
      MulterOptions({dest: "/"})(Test.prototype, "test", descriptorOf(Test.prototype, "test"));
      this.store = Store.fromMethod(Test.prototype, "test");
    });
github TypedProject / ts-express-decorators / packages / swagger / src / class / OpenApiParamsBuilder.ts View on Github external
super(target);
    this.name = `${nameOf(target)}${methodClassName.charAt(0).toUpperCase() + methodClassName.slice(1)}`;

    this.injectedParams = ParamRegistry.getParams(target, methodClassName).filter(param => {
      if (param.paramType === ParamTypes.BODY) {
        this.hasBody = true;
      }

      if (param.paramType === ParamTypes.FORM_DATA) {
        this.hasFormData = true;
      }

      return !param.store.get("hidden");
    });

    const fromMethod = Store.fromMethod(target, methodClassName);
    const operation = fromMethod.get("operation");
    if (operation && operation.consumes && operation.consumes.indexOf("application/x-www-form-urlencoded") > -1) {
      this.hasFormData = true;
    }
  }
github TypedProject / ts-express-decorators / src / multipartfiles / decorators / multerOptions.ts View on Github external
return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
    const type = getDecoratorType([target, propertyKey, descriptor], true);

    switch (type) {
      default:
        throw new Error("MulterOptions is only supported on method");
      case "method":
        Store.fromMethod(target, propertyKey).merge(MultipartFileMiddleware, {
          options
        });

        return descriptor;
    }
  };
}