Loopback 框架内创建函数的问题
Issue with create function inside Loopback framework
我有这个型号
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 is not defined
at new disabled (eval at createModelClassCtor (../LBIssue/lbissue/node_modules/loopback-datasource-juggler/lib/model-builder.js:678:21), :10:27)
为了简单地产生这个错误,创建空环回 4 项目
然后把优惠券模型=和我提供的代码放在一起
您的模型定义有误。
看到这个
@property({
type: 'disabled',
required: true,
})
disabled: boolean;
无法禁用类型。应该是
@property({
type: 'boolean',
required: true,
})
disabled: boolean;
我有这个型号
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 is not defined at new disabled (eval at createModelClassCtor (../LBIssue/lbissue/node_modules/loopback-datasource-juggler/lib/model-builder.js:678:21), :10:27)
为了简单地产生这个错误,创建空环回 4 项目 然后把优惠券模型=和我提供的代码放在一起
您的模型定义有误。
看到这个
@property({
type: 'disabled',
required: true,
})
disabled: boolean;
无法禁用类型。应该是
@property({
type: 'boolean',
required: true,
})
disabled: boolean;