Я новичок в loopback 4, и почти вся документация, которую я нашел, относится к более низким версиям. У меня есть корзина для покупок, но мне нужно избегать ее, чтобы в ней было больше 5 товаров ... как я могу сделать это ограничение?
Это мои модели:
import {Entity, hasMany, model, property} from '@loopback/repository';
import {Item} from './item.model';
@model()
export class Shoppingcar extends Entity {
@property({
type: 'string',
id: true,
generated: true,
})
id?: string;
@property({
type: 'string',
required: true,
})
desc: string;
@property({
type: 'string',
required: true,
}
})
shopper: string;
@hasMany(() => Item)
items: Item[];
constructor(data?: Partial<Gateway>) {
super(data);
}
}
export interface ShoppingcarRelations {
// describe navigational properties here
}
export type ShoppingcarWithRelations = Shoppingcar & ShoppingcarRelations;
и
import {Entity, model, property, belongsTo} from '@loopback/repository';
import {Shoppingcar} from './shoppingcar.model';
@model()
export class Item extends Entity {
@property({
type: 'string',
id: true,
generated: true,
})
id?: string;
@property({
type: 'string',
required: true,
})
name: string;
@property({
type: 'string',
required: true,
})
date: string;
@belongsTo(() => Shoppingcar)
shoppingcarId: string;
constructor(data?: Partial<Item>) {
super(data);
}
}
export interface ItemRelations {
// describe navigational properties here
}
export type ItemWithRelations = Item & ItemRelations;