Loopback框架内的create function问题

问题描述 投票:0回答:1

我有这个模型

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未在新的禁用时定义(eval at createModelClassCtor(../LBIssue/lbissue/node_modules/loopback-datasource-juggler/lib/model-builder.js:678:21),:10:27)

简单地产生这个错误,创建空的loopback 4项目然后把优惠券模型=与我提供的代码

node.js crud loopback v4l2loopback
1个回答
0
投票

模型定义中存在错误。

看到这个

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

类型无法禁用。它应该是

@property({
        type: 'boolean',
        required: true,
      })
      disabled: boolean;
© www.soinside.com 2019 - 2024. All rights reserved.