0

我有这个模型

import {Entity, model, property} from '@loopback/repository';

@model()
export class Coupon extends Entity {
  @property({
    id: true,
    type: 'string',
    required: false,
    mongo: {
      columnName: '_id',
      dataType: 'ObjectID',
    },
  })
  id: string;

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

  @property({
    type: 'number',
    required: true,
  })
  maximumUses: number;

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

  @property({
    type: 'number',
    required: true,
  })
  amount: number;

  @property({
    type: 'number',
    required: true,
  })
  maximumUsesPerPerson: number;

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

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

  @property({
    type: 'number',
    required: true,
  })
  currentTotalUses: number;

  @property({
    type: 'array',
    itemType: 'string',
  })
  certainDays?: string[];

  @property({
    type: 'array',
    itemType: 'string',
  })
  certainHours?: string[];

  @property({
    type: 'boolean',
    required: true,
  })
  valid: boolean;

  @property({
    type: 'array',
    itemType: 'string',
  })
  clients?: string[];

  @property({
    type: 'disabled',
    required: true,
  })
  disabled: boolean;

  constructor(data?: Partial<Coupon>) {
    super(data);
  }
}

模型存储库

import {DefaultCrudRepository} from '@loopback/repository';
import {Coupon} from '../models';
import {TestDataSource} from '../datasources';
import {inject} from '@loopback/core';

export class CouponRepository extends DefaultCrudRepository<
  Coupon,
  typeof Coupon.prototype.id
> {
  constructor(
    @inject('datasources.test') dataSource: TestDataSource,
  ) {
    super(Coupon, dataSource);
  }
}

现在以下功能应该可以正常工作

await this.couponsRepo.create({ name: 'string',
    maximumUses: 0,
    maximumUsesPerPerson: 0,
    amount: 0,
    validFrom: 'string',
    validTo: 'string',
    type: 'percentage',
    valid: true,
    currentTotalUses: 0,
    disabled: false });

但它会引发此错误

ReferenceError:g 未在新禁用时定义(在 createModelClassCtor 进行评估(../LBIssue/lbissue/node_modules/loopback-datasource-juggler/lib/model-builder.js:678:21),:10:27)

要简单地产生此错误,请创建空环回 4 项目,然后将优惠券模型 = 与我提供的代码一起放入

4

1 回答 1

0

您的模型定义中有错误。

看到这个

@property({
    type: 'disabled',
    required: true,
  })
  disabled: boolean;

类型不能被禁用。它应该是

@property({
        type: 'boolean',
        required: true,
      })
      disabled: boolean;
于 2019-04-05T07:09:47.370 回答