How to use the @loopback/repository.property function in @loopback/repository

To help you get started, we’ve selected a few @loopback/repository 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 strongloop / loopback-next / packages / repository-tests / src / crud / replace-by-id.suite.ts View on Github external
export function createSuiteForReplaceById(
  dataSourceOptions: DataSourceOptions,
  repositoryClass: CrudRepositoryCtor,
  features: CrudFeatures,
) {
  @model()
  class Product extends Entity {
    @property({
      type: features.idType,
      id: true,
      generated: true,
      description: 'The unique identifier for a product',
    })
    id: MixedIdType;

    // cloudant needs this property to do replacement method
    // see cloudant README file for more details
    @property({type: 'string', required: false})
    _rev: string;

    @property({type: 'string', required: true})
    name: string;

    @property({type: 'string', required: false})
github strongloop / loopback-next / packages / repository-tests / src / crud / retrieve-including-relations.suite.ts View on Github external
items?: Item[];
  }

  @model()
  class Item extends Entity {
    @property({
      type: features.idType,
      id: true,
      generated: true,
    })
    id: number | string;

    @property({type: 'string', required: true})
    name: string;

    @property({
      type: features.idType,
      required: true,
      // hacky workaround, we need a more generic solution that will allow
      // any connector to contribute additional metadata for foreign keys
      // ideally, we should use database-agnostic "references" field
      // as proposed in https://github.com/strongloop/loopback-next/issues/2766
      mongodb: {
        dataType: 'ObjectID',
      },
    })
    categoryId: number | string;

    constructor(data?: Partial) {
      super(data);
    }
  }
github strongloop / loopback-next / packages / repository-tests / src / crud / create-retrieve.suite.ts View on Github external
export function createRetrieveSuite(
  dataSourceOptions: DataSourceOptions,
  repositoryClass: CrudRepositoryCtor,
  features: CrudFeatures,
) {
  @model()
  class Product extends Entity {
    @property({
      type: features.idType,
      id: true,
      generated: true,
      description: 'The unique identifier for a product',
    })
    id: MixedIdType;

    @property({type: 'string', required: true})
    name: string;

    @property()
    categoryId?: number;

    constructor(data?: Partial) {
      super(data);
    }
  }

  describe('create-retrieve', () => {
    before(deleteAllModelsInDefaultDataSource);

    let repo: EntityCrudRepository;
    before(
      withCrudCtx(async function setupRepository(ctx: CrudTestContext) {