-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload-entity.js
More file actions
34 lines (27 loc) · 874 Bytes
/
load-entity.js
File metadata and controls
34 lines (27 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const { Context, RepositoryFactory, Criteria } = require("../lib");
const { getDemoToken } = require("./helper");
class LoadEntityExample {
productCriteria() {
const criteria = new Criteria();
criteria.addAssociation("options.group");
return criteria;
}
async execute() {
// Auto add token to global Context
await getDemoToken();
const repository = RepositoryFactory.create("product");
const criteria = this.productCriteria();
const products = await repository.search(criteria, Context);
console.log("List", products);
if (products.length > 0) {
const productId = products.first().id;
const product = await repository.get(productId, Context, criteria);
console.log("Detail", product);
}
}
}
const run = async () => {
const example = new LoadEntityExample();
await example.execute();
};
run();