How to use the type-graphql.ArgumentValidationError function in type-graphql

To help you get started, weโ€™ve selected a few type-graphql 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 goldcaddy77 / warthog / src / core / BaseService.ts View on Github external
async update(data: DeepPartial, where: W, userId: string): Promise {
    (data as any).updatedById = userId; // TODO: fix any

    // const whereOptions = this.pullParamsFromClass(where);
    const found = await this.findOne(where);
    const idData = ({ id: found.id } as any) as DeepPartial;
    const merged = this.repository.merge(new this.entityClass(), data, idData);

    // skipMissingProperties -> partial validation of only supplied props
    const errors = await validate(merged, { skipMissingProperties: true });
    if (errors.length) {
      throw new ArgumentValidationError(errors);
    }

    // TODO: Fix `any`
    const result = await this.repository.save(merged as any);
    return this.repository.findOneOrFail({ where: { id: result.id } });
  }
github goldcaddy77 / warthog / src / core / BaseService.ts View on Github external
async create(data: DeepPartial, userId: string): Promise {
    (data as any).createdById = userId; // TODO: fix any

    const results = this.repository.create([data]);
    const obj = results[0];

    // Validate against the the data model
    // Without `skipMissingProperties`, some of the class-validator validations (like MinLength)
    // will fail if you don't specify the property
    const errors = await validate(obj, { skipMissingProperties: true });
    if (errors.length) {
      // TODO: create our own error format that matches Mike B's format
      throw new ArgumentValidationError(errors);
    }

    // TODO: remove any when this is fixed: https://github.com/Microsoft/TypeScript/issues/21592
    // TODO: Fix `any`
    return this.repository.save(obj as any, { reload: true });
  }
github goldcaddy77 / warthog / src / core / BaseService.ts View on Github external
async createMany(data: DeepPartial[], userId: string): Promise {
    data = data.map(item => {
      return { ...item, createdById: userId };
    });

    const results = this.repository.create(data);

    // Validate against the the data model
    // Without `skipMissingProperties`, some of the class-validator validations (like MinLength)
    // will fail if you don't specify the property
    for (const obj of results) {
      const errors = await validate(obj, { skipMissingProperties: true });
      if (errors.length) {
        // TODO: create our own error format that matches Mike B's format
        throw new ArgumentValidationError(errors);
      }
    }

    // TODO: remove any when this is fixed: https://github.com/Microsoft/TypeScript/issues/21592
    // TODO: Fix `any`
    return this.repository.save(results as any, { reload: true });
  }