This commit is contained in:
19
webseite/backend/utils/json-modifier.js
Normal file
19
webseite/backend/utils/json-modifier.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import fs from 'node:fs';
|
||||
import { v4 as id } from 'uuid';
|
||||
|
||||
console.log(id()); // 97412ca6-c7a8-4868-a49b-3cf4c2258dd8
|
||||
|
||||
try {
|
||||
const data = JSON.parse(fs.readFileSync('../data/products.json', 'utf-8'));
|
||||
|
||||
const products = data.map((product, index) => {
|
||||
return { _id: product._id || id(), position: index + 1, ...product };
|
||||
});
|
||||
|
||||
console.log(products);
|
||||
|
||||
fs.writeFileSync('../data/products.json', JSON.stringify(products, null, 2), 'utf-8');
|
||||
console.log('File modified');
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
28
webseite/backend/utils/package-lock.json
generated
Normal file
28
webseite/backend/utils/package-lock.json
generated
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "utils",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "utils",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"uuid": "^14.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/uuid": {
|
||||
"version": "14.0.1",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-14.0.1.tgz",
|
||||
"integrity": "sha512-6ZxzVpzDXDa3bJWaHilVayA+BH/1zmxCJoVgvmqJnid/gPoKHxUrS/aC/T6LGQtNHT+XHG9fXPJB4d+IrU30Ew==",
|
||||
"funding": [
|
||||
"https://github.com/sponsors/broofa",
|
||||
"https://github.com/sponsors/ctavan"
|
||||
],
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"uuid": "dist-node/bin/uuid"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
14
webseite/backend/utils/package.json
Normal file
14
webseite/backend/utils/package.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "utils",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "json-modifier.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"uuid": "^14.0.1"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user