-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync-api.js
52 lines (44 loc) · 1.12 KB
/
sync-api.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const {
SyncApi,
SyncPayload,
SYNC_OPERATOR,
RepositoryFactory,
Criteria,
Context,
} = require("../lib");
const { getDemoToken } = require("./helper");
class SyncApiExample {
async execute() {
// Auto add token to global Context
await getDemoToken();
const syncApi = new SyncApi();
const payload = new SyncPayload();
const productRepository = RepositoryFactory.create("product");
const productId = await productRepository
.searchIds(new Criteria(), Context)
.then((resp) => resp.data);
const firstProductId = productId[0];
const secondProductId = productId[1];
payload.setOperator("product", SYNC_OPERATOR.UPSERT, [
{
id: firstProductId,
name: "First update",
stock: 3,
},
]);
payload.setOperator("product", SYNC_OPERATOR.UPSERT, [
{
id: secondProductId,
name: "Second update",
stock: 5,
},
]);
const data = await syncApi.sync(payload);
console.log(data, "Sync success");
}
}
const run = async () => {
const example = new SyncApiExample();
await example.execute();
};
run();