Skip to content

Commit 22d97ca

Browse files
author
Maksym Mykhailenko
committed
feat: dummify metadata prices during importing
1 parent 81c204f commit 22d97ca

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

local/seed/seedMetadata.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ if (!process.env.CONNECT_USER_TOKEN) {
77
process.exit(1);
88
}
99

10+
/**
11+
* Iteratively goes through the object and replaces prices with random values.
12+
*
13+
* This method MUTATES object.
14+
*
15+
* @param {Object} o object
16+
*/
17+
function dummifyPrices(o) {
18+
Object.keys(o).forEach(function (k) {
19+
if (o[k] !== null && typeof o[k] === 'object') {
20+
dummifyPrices(o[k]);
21+
return;
22+
}
23+
if (k === 'price' && typeof o[k] === 'number') {
24+
o[k] = 100 + Math.round(Math.random() * 10000);
25+
}
26+
if (k === 'price' && typeof o[k] === 'string') {
27+
o[k] = (100 + Math.round(Math.random() * 10000)).toFixed(0);
28+
}
29+
});
30+
}
31+
1032
// we need to know any logged in Connect user token to retrieve data from DEV
1133
const CONNECT_USER_TOKEN = process.env.CONNECT_USER_TOKEN;
1234

@@ -29,6 +51,7 @@ module.exports = (targetUrl, token) => {
2951
})
3052
.then(async function (response) {
3153
let data = response.data;
54+
dummifyPrices(data)
3255

3356
console.log('Creating metadata objects locally...');
3457

0 commit comments

Comments
 (0)