How to use the @loopback/repository.model 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-json-schema / src / __tests__ / integration / build-schema.integration.ts View on Github external
it('uses title from model metadata instead of model name', () => {
      @model({title: 'MyCustomer'})
      class Customer {}

      const schema = modelToJsonSchema(Customer, {
        // trigger build of a custom title
        partial: true,
      });

      expect(schema.title).to.equal('MyCustomerPartial');
    });
github strongloop / loopback-next / packages / rest / src / __tests__ / acceptance / validation / validation.acceptance.ts View on Github external
describe('Validation at REST level', () => {
  let app: RestApplication;
  let client: Client;

  @model()
  class Product {
    @property()
    id: number;

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

    // NOTE(rfeng): We have to add `type: 'string'` to `@property` as
    // `string | null` removes TypeScript design:type reflection
    @property({required: false, type: 'string', jsonSchema: {nullable: true}})
    description?: string | null;

    @property({required: true, jsonSchema: {range: [0, 100]}})
    price: number;

    constructor(data: Partial) {
github strongloop / loopback-next / examples / todo-list / src / models / todo-list-image.model.ts View on Github external
// Copyright IBM Corp. 2018,2019. All Rights Reserved.
// Node module: @loopback/example-todo-list
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {belongsTo, Entity, model, property} from '@loopback/repository';
import {TodoList, TodoListWithRelations} from './todo-list.model';

@model()
export class TodoListImage extends Entity {
  @property({
    type: 'number',
    id: true,
  })
  id: number;

  @belongsTo(() => TodoList)
  todoListId: number;

  @property({
    required: true,
  })
  // Ideally we would use Buffer type here, but
  // that is not supported yet.
  // see https://github.com/strongloop/loopback-next/issues/1742
github strongloop / loopback-next / packages / repository-json-schema / src / __tests__ / integration / build-schema.integration.ts View on Github external
it('respects model setting "strict: false"', () => {
        @model({settings: {strict: false}})
        class FreeFormModel {}

        const schema = modelToJsonSchema(FreeFormModel);
        expect(schema).to.containDeep({
          additionalProperties: true,
        });
      });
    });
github strongloop / loopback-next / packages / repository-json-schema / src / __tests__ / integration / build-schema.integration.ts View on Github external
it('properly converts decorated custom array type properties', () => {
          @model()
          class CustomType {
            @property()
            prop: string;
          }

          @model()
          class TestModel {
            @property.array(CustomType)
            cusType: CustomType[];
          }

          const jsonSchema = modelToJsonSchema(TestModel);
          expect(jsonSchema.properties).to.deepEqual({
            cusType: {
              type: 'array',
              items: {$ref: '#/definitions/CustomType'},
github strongloop / loopback-next / packages / repository-json-schema / src / __tests__ / integration / build-schema.integration.ts View on Github external
it('gets cached JSON schema with relation links if one exists', () => {
      @model()
      class Product extends Entity {
        @property({id: true})
        id: number;

        @belongsTo(() => Category)
        categoryId: number;
      }

      @model()
      class Category extends Entity {
        @property({id: true})
        id: number;

        @hasMany(() => Product)
        products?: Product[];
      }

      const cachedSchema: JsonSchema = {
        definitions: {
          ProductWithRelations: {
            title: 'ProductWithRelations',
            properties: {
              id: {type: 'number'},
              categoryId: {type: 'number'},
              category: {$ref: '#/definitions/CategoryWithRelations'},
github strongloop / loopback-next / packages / rest-crud / src / __tests__ / acceptance / default-model-crud-rest.acceptance.ts View on Github external
describe('CrudRestController for a simple Product model', () => {
  @model()
  class Product extends Entity {
    @property({id: true})
    id: number;

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

    @property()
    description?: string;

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

  let app: RestApplication;
github iqbaldjulfri / lb4-jwt-role-based-auth-sample / src / models / role.model.ts View on Github external
import {Entity, model, property} from '@loopback/repository';

@model()
export class Role extends Entity {
  @property({
    type: 'string',
    id: true,
  })
  id?: string;

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

  constructor(data?: Partial) {
    super(data);
  }
github dofapi / dofapi / server / src / models / item.model.ts View on Github external
import { Entity, model, property } from '@loopback/repository';

@model()
export class Item extends Entity {
  @property({
    type: 'number',
    id: true,
    required: true,
  })
  _id: number;

  @property({
    type: 'number',
  })
  ankamaId?: number;

  @property({
    type: 'string',
  })
github strongloop / loopback4-example-shopping / packages / shopping / src / controllers / user.controller.ts View on Github external
import {
  CredentialsRequestBody,
  UserProfileSchema,
} from './specs/user-controller.specs';
import {Credentials} from '../repositories/user.repository';
import {PasswordHasher} from '../services/hash.password.bcryptjs';

import {
  TokenServiceBindings,
  PasswordHasherBindings,
  UserServiceBindings,
} from '../keys';
import _ from 'lodash';
import {OPERATION_SECURITY_SPEC} from '../utils/security-spec';

@model()
export class NewUserRequest extends User {
  @property({
    type: 'string',
    required: true,
  })
  password: string;
}

export class UserController {
  constructor(
    @repository(UserRepository) public userRepository: UserRepository,
    @inject('services.RecommenderService')
    public recommender: RecommenderService,
    @inject(PasswordHasherBindings.PASSWORD_HASHER)
    public passwordHasher: PasswordHasher,
    @inject(TokenServiceBindings.TOKEN_SERVICE)