Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function createSuiteForReplaceById(
dataSourceOptions: DataSourceOptions,
repositoryClass: CrudRepositoryCtor,
features: CrudFeatures,
) {
@model()
class Product extends Entity {
@property({
type: features.idType,
id: true,
generated: true,
description: 'The unique identifier for a product',
})
id: MixedIdType;
// cloudant needs this property to do replacement method
// see cloudant README file for more details
@property({type: 'string', required: false})
_rev: string;
@property({type: 'string', required: true})
name: string;
@property({type: 'string', required: false})
items?: Item[];
}
@model()
class Item extends Entity {
@property({
type: features.idType,
id: true,
generated: true,
})
id: number | string;
@property({type: 'string', required: true})
name: string;
@property({
type: features.idType,
required: true,
// hacky workaround, we need a more generic solution that will allow
// any connector to contribute additional metadata for foreign keys
// ideally, we should use database-agnostic "references" field
// as proposed in https://github.com/strongloop/loopback-next/issues/2766
mongodb: {
dataType: 'ObjectID',
},
})
categoryId: number | string;
constructor(data?: Partial) {
super(data);
}
}
export function createRetrieveSuite(
dataSourceOptions: DataSourceOptions,
repositoryClass: CrudRepositoryCtor,
features: CrudFeatures,
) {
@model()
class Product extends Entity {
@property({
type: features.idType,
id: true,
generated: true,
description: 'The unique identifier for a product',
})
id: MixedIdType;
@property({type: 'string', required: true})
name: string;
@property()
categoryId?: number;
constructor(data?: Partial) {
super(data);
}
}
describe('create-retrieve', () => {
before(deleteAllModelsInDefaultDataSource);
let repo: EntityCrudRepository;
before(
withCrudCtx(async function setupRepository(ctx: CrudTestContext) {