Skip to content

Commit

Permalink
samples: moved console.log placements in add/remove fulfillment and s…
Browse files Browse the repository at this point in the history
…et inventory. (#215)
  • Loading branch information
Arakel2811 authored Sep 23, 2022
1 parent 73c064b commit 439ee1f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 32 deletions.
16 changes: 8 additions & 8 deletions retail/interactive-tutorials/product/add-fulfillment-places.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,21 @@ async function main(generatedProductId) {
// Create product
const createdProduct = await utils.createProduct(
projectId,
generatedProductId
generatedProductId,
true
);

// Full resource name of Product
const product = createdProduct.name;

// The fulfillment type, including commonly used types (such as
// pickup in store and same day delivery), and custom types.
// pickup in store and same-day delivery), and custom types.
const type = 'same-day-delivery';

// The IDs for this type, such as the store IDs for "pickup-in-store" or the region IDs for
// "same-day-delivery" to be added for this type.
const placeIds = ['store1', 'store2', 'store3'];

// The time when the fulfillment updates are issued, used to prevent
// out-of-order updates on fulfillment information.

//If set to true, and the product is not found, the fulfillment information will still be processed and retained for
// at most 1 day and processed once the product is created
const allowMissing = true;
Expand All @@ -57,16 +55,18 @@ async function main(generatedProductId) {
allowMissing,
};

// To send an out-of-order request assign the invalid addTime here:
// request.addTime = {seconds: Math.round(Date.now() / 1000) - 86400};

console.log('Add fulfillment request:', request);
console.log('Waiting to complete add operation...');

// Run request
const [operation] = await retailClient.addFulfillmentPlaces(request);
await operation.promise();

console.log('Waiting to complete add operation..');
};

// Add fulfillment places with current time
// Add fulfillment places
console.log('Start add fulfillment');
await calladdFulfillmentPlaces();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,13 @@ async function main(generatedProductId) {
const product = createdProduct.name;

// The fulfillment type, including commonly used types (such as
// pickup in store and same day delivery), and custom types.
// pickup in store and same-day delivery), and custom types.
const type = 'same-day-delivery';

// The IDs for this type, such as the store IDs for "pickup-in-store" or the region IDs for
// "same-day-delivery" to be added for this type.
const placeIds = ['store1'];

// The time when the fulfillment updates are issued, used to prevent
// out-of-order updates on fulfillment information.

const callRemoveFulfillmentPlaces = async () => {
// Construct request
const request = {
Expand All @@ -53,15 +50,18 @@ async function main(generatedProductId) {
placeIds,
};

// To send an out-of-order request assign the invalid removeTime here:
// request.removeTime = {seconds: Math.round(Date.now() / 1000) - 86400};

console.log('Remove fulfillment request:', request);
console.log('Waiting to complete remove operation...');

// Run request
const [operation] = await retailClient.removeFulfillmentPlaces(request);
await operation.promise();

console.log('Waiting to complete remove operation..');
};

// Remove fulfillment places with current time
// Remove fulfillment places
console.log('Start remove fulfillment');
await callRemoveFulfillmentPlaces();

Expand Down
26 changes: 9 additions & 17 deletions retail/interactive-tutorials/product/set-inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ async function main(generatedProductId) {
// Create product
const createdProduct = await utils.createProduct(
projectId,
generatedProductId
generatedProductId,
true
);

// The inventory information to update
Expand All @@ -52,9 +53,6 @@ async function main(generatedProductId) {
availability: 'IN_STOCK',
};

// The time when the request is issued, used to prevent
// out-of-order updates on inventory fields with the last update time recorded.

// If set to true, and the product with name is not found, the
// inventory update will still be processed and retained for at most 1 day until the product is created
const allowMissing = true;
Expand All @@ -65,35 +63,29 @@ async function main(generatedProductId) {
inventory: product,
allowMissing,
};

// To send an out-of-order request assign the invalid setTime here:
// request.setTime = {seconds: Math.round(Date.now() / 1000) - 86400};

console.log('Set inventory request:', request);
console.log('Waiting to complete set inventory operation...');

// Run request
const [operation] = await retailClient.setInventory(request);
await operation.promise();
console.log('Waiting to complete set inventory operation..');
};

// Set inventory with current time
// Set inventory
console.log('Start set inventory');
await callSetInventory();

// Get product
let changedProduct = await utils.getProduct(createdProduct.name);
const changedProduct = await utils.getProduct(createdProduct.name);
console.log(
`Updated product ${createdProduct.id} with current time: `,
JSON.stringify(changedProduct[0])
);

// Set inventory with outdated time
product.priceInfo.price = 20.0;
await callSetInventory();

// Get product
changedProduct = await utils.getProduct(createdProduct.name);
console.log(
`Updated product ${createdProduct.id} with outdated time: `,
JSON.stringify(changedProduct[0])
);
console.log('Set inventory finished');

// Delete product
Expand Down

0 comments on commit 439ee1f

Please sign in to comment.