Compare commits

...

2 Commits

Author SHA1 Message Date
Philippe Torrel
17aa46a4bc 2026-08-03 16:00:02 +02:00
Philippe Torrel
7d8daeb14c added website-simple 2026-08-03 15:59:57 +02:00
23 changed files with 6308 additions and 235 deletions

BIN
webseite-gulp-ts.zip Normal file

Binary file not shown.

View File

@@ -1,6 +1,7 @@
<!doctype html> <!doctype html>
<html lang="de"> <html lang="de">
@@include('head.html') @@include('head.html')
<body> <body>
<!-- header.header-main>.content-box>figure>img[alt="Logo"]+figc{The Donkey Coders} --> <!-- header.header-main>.content-box>figure>img[alt="Logo"]+figc{The Donkey Coders} -->
<header class="header-main"> <header class="header-main">

View File

@@ -0,0 +1,31 @@
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Webseite</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="/assets/css/main.css" />
<script src="/assets/js/main.js" defer></script>
</head>
<body>
<nav class="menu-main">
<ul>
<li><a href="/">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="contact.html">Contact</a></li>
<li><a href="imprint.html">Imprint</a></li>
</ul>
</nav>
<main>
<div class="container py-5">
<h1>About</h1>
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Blanditiis ullam obcaecati iure quisquam odio qui
minima aspernatur tenetur praesentium rerum, tempore in veritatis quibusdam eum reprehenderit necessitatibus
corrupti facere dolor!
</p>
</div>
</main>
</body>
</html>

View File

View File

View File

@@ -0,0 +1,31 @@
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Webseite</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="/assets/css/main.css" />
<script src="/assets/js/main.js" defer></script>
</head>
<body>
<nav class="menu-main">
<ul>
<li><a href="/">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="contact.html">Contact</a></li>
<li><a href="imprint.html">Imprint</a></li>
</ul>
</nav>
<main>
<div class="container py-5">
<h1>Home</h1>
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Blanditiis ullam obcaecati iure quisquam odio qui
minima aspernatur tenetur praesentium rerum, tempore in veritatis quibusdam eum reprehenderit necessitatibus
corrupti facere dolor!
</p>
</div>
</main>
</body>
</html>

View File

@@ -0,0 +1,31 @@
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Webseite</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="/assets/css/main.css" />
<script src="/assets/js/main.js" defer></script>
</head>
<body>
<nav class="menu-main">
<ul>
<li><a href="/">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="contact.html">Contact</a></li>
<li><a href="imprint.html">Imprint</a></li>
</ul>
</nav>
<main>
<div class="container py-5">
<h1>Home</h1>
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Blanditiis ullam obcaecati iure quisquam odio qui
minima aspernatur tenetur praesentium rerum, tempore in veritatis quibusdam eum reprehenderit necessitatibus
corrupti facere dolor!
</p>
</div>
</main>
</body>
</html>

View File

@@ -0,0 +1,31 @@
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Webseite</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="/assets/css/main.css" />
<script src="/assets/js/main.js" defer></script>
</head>
<body>
<nav class="menu-main">
<ul>
<li><a href="/">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="contact.html">Contact</a></li>
<li><a href="imprint.html">Imprint</a></li>
</ul>
</nav>
<main>
<div class="container py-5">
<h1>Home</h1>
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Blanditiis ullam obcaecati iure quisquam odio qui
minima aspernatur tenetur praesentium rerum, tempore in veritatis quibusdam eum reprehenderit necessitatibus
corrupti facere dolor!
</p>
</div>
</main>
</body>
</html>

View File

@@ -0,0 +1,933 @@
{
"name": "website-backend",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "website-backend",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"chalk": "^5.6.2",
"cors": "^2.8.6",
"dotenv": "^17.4.2",
"express": "^5.2.1",
"uuid": "^14.0.1"
}
},
"node_modules/accepts": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz",
"integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==",
"license": "MIT",
"dependencies": {
"mime-types": "^3.0.0",
"negotiator": "^1.0.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/body-parser": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.3.0.tgz",
"integrity": "sha512-2cGmJupaNgg+QUwVLAucDuWuoMZ6EX9iHDRswZ5lsNYEmwPaRknMPCLZz07yTzVq/83p4o/wzbDZbBrTvGGTIw==",
"license": "MIT",
"dependencies": {
"bytes": "^3.1.2",
"content-type": "^2.0.0",
"debug": "^4.4.3",
"http-errors": "^2.0.1",
"iconv-lite": "^0.7.2",
"on-finished": "^2.4.1",
"qs": "^6.15.2",
"raw-body": "^3.0.2",
"type-is": "^2.1.0"
},
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/body-parser/node_modules/content-type": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-2.0.0.tgz",
"integrity": "sha512-j/O/d7GcZCyNl7/hwZAb606rzqkyvaDctLmckbxLzHvFBzTJHuGEdodATcP3yIRoDrLHkIATJuvzbFlp/ki2cQ==",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/bytes": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
"integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/call-bind-apply-helpers": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/call-bound": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz",
"integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"get-intrinsic": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/chalk": {
"version": "5.6.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-5.6.2.tgz",
"integrity": "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==",
"license": "MIT",
"engines": {
"node": "^12.17.0 || ^14.13 || >=16.0.0"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/content-disposition": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.1.0.tgz",
"integrity": "sha512-5jRCH9Z/+DRP7rkvY83B+yGIGX96OYdJmzngqnw2SBSxqCFPd0w2km3s5iawpGX8krnwSGmF0FW5Nhr0Hfai3g==",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/content-type": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/cookie": {
"version": "0.7.2",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
"integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/cookie-signature": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz",
"integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==",
"license": "MIT",
"engines": {
"node": ">=6.6.0"
}
},
"node_modules/cors": {
"version": "2.8.6",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz",
"integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==",
"license": "MIT",
"dependencies": {
"object-assign": "^4",
"vary": "^1"
},
"engines": {
"node": ">= 0.10"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/debug": {
"version": "4.4.3",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
"integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
"license": "MIT",
"dependencies": {
"ms": "^2.1.3"
},
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/depd": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/dotenv": {
"version": "17.4.2",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.4.2.tgz",
"integrity": "sha512-nI4U3TottKAcAD9LLud4Cb7b2QztQMUEfHbvhTH09bqXTxnSie8WnjPALV/WMCrJZ6UV/qHJ6L03OqO3LcdYZw==",
"license": "BSD-2-Clause",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.1",
"es-errors": "^1.3.0",
"gopd": "^1.2.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
"license": "MIT"
},
"node_modules/encodeurl": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz",
"integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/es-define-property": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-errors": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-object-atoms": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz",
"integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/escape-html": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
"license": "MIT"
},
"node_modules/etag": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
"integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/express": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz",
"integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==",
"license": "MIT",
"dependencies": {
"accepts": "^2.0.0",
"body-parser": "^2.2.1",
"content-disposition": "^1.0.0",
"content-type": "^1.0.5",
"cookie": "^0.7.1",
"cookie-signature": "^1.2.1",
"debug": "^4.4.0",
"depd": "^2.0.0",
"encodeurl": "^2.0.0",
"escape-html": "^1.0.3",
"etag": "^1.8.1",
"finalhandler": "^2.1.0",
"fresh": "^2.0.0",
"http-errors": "^2.0.0",
"merge-descriptors": "^2.0.0",
"mime-types": "^3.0.0",
"on-finished": "^2.4.1",
"once": "^1.4.0",
"parseurl": "^1.3.3",
"proxy-addr": "^2.0.7",
"qs": "^6.14.0",
"range-parser": "^1.2.1",
"router": "^2.2.0",
"send": "^1.1.0",
"serve-static": "^2.2.0",
"statuses": "^2.0.1",
"type-is": "^2.0.1",
"vary": "^1.1.2"
},
"engines": {
"node": ">= 18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/finalhandler": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz",
"integrity": "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA==",
"license": "MIT",
"dependencies": {
"debug": "^4.4.0",
"encodeurl": "^2.0.0",
"escape-html": "^1.0.3",
"on-finished": "^2.4.1",
"parseurl": "^1.3.3",
"statuses": "^2.0.1"
},
"engines": {
"node": ">= 18.0.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/fresh": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz",
"integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/function-bind": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-intrinsic": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"es-define-property": "^1.0.1",
"es-errors": "^1.3.0",
"es-object-atoms": "^1.1.1",
"function-bind": "^1.1.2",
"get-proto": "^1.0.1",
"gopd": "^1.2.0",
"has-symbols": "^1.1.0",
"hasown": "^2.0.2",
"math-intrinsics": "^1.1.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
"license": "MIT",
"dependencies": {
"dunder-proto": "^1.0.1",
"es-object-atoms": "^1.0.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/gopd": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/has-symbols": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/hasown": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz",
"integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==",
"license": "MIT",
"dependencies": {
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/http-errors": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz",
"integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==",
"license": "MIT",
"dependencies": {
"depd": "~2.0.0",
"inherits": "~2.0.4",
"setprototypeof": "~1.2.0",
"statuses": "~2.0.2",
"toidentifier": "~1.0.1"
},
"engines": {
"node": ">= 0.8"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/iconv-lite": {
"version": "0.7.3",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.3.tgz",
"integrity": "sha512-IKXpvIzjnC9XTAUbVBcMfGS0EPaIXtW6v+zr+RRp+hqULEpo0owZax6wyRwPOJbWbzjYspQwusTsfVr0ifh4uQ==",
"license": "MIT",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3.0.0"
},
"engines": {
"node": ">=0.10.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
"license": "ISC"
},
"node_modules/ipaddr.js": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
"license": "MIT",
"engines": {
"node": ">= 0.10"
}
},
"node_modules/is-promise": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz",
"integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==",
"license": "MIT"
},
"node_modules/math-intrinsics": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/media-typer": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.1.tgz",
"integrity": "sha512-yz3xRaG20c6/BOzvYoDaGtPmGscs7YivItZEEqe6GbwNfHuxu9YNmvnEkMzKldAGY4/80pRcQRZSEnhquk9XuQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/merge-descriptors": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz",
"integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/mime-db": {
"version": "1.54.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz",
"integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz",
"integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==",
"license": "MIT",
"dependencies": {
"mime-db": "^1.54.0"
},
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/ms": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
"license": "MIT"
},
"node_modules/negotiator": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz",
"integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/object-inspect": {
"version": "1.13.4",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
"integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/on-finished": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
"integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
"license": "MIT",
"dependencies": {
"ee-first": "1.1.1"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
"license": "ISC",
"dependencies": {
"wrappy": "1"
}
},
"node_modules/parseurl": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/path-to-regexp": {
"version": "8.4.2",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.4.2.tgz",
"integrity": "sha512-qRcuIdP69NPm4qbACK+aDogI5CBDMi1jKe0ry5rSQJz8JVLsC7jV8XpiJjGRLLol3N+R5ihGYcrPLTno6pAdBA==",
"license": "MIT",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/proxy-addr": {
"version": "2.0.7",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
"integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
"license": "MIT",
"dependencies": {
"forwarded": "0.2.0",
"ipaddr.js": "1.9.1"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/qs": {
"version": "6.15.3",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.15.3.tgz",
"integrity": "sha512-O9gl3zCl5h5blw1KGUzQKhA5oUXSl8rwUIM5o0S3nCXMliSvy5Dzx7/DJcI+SwgICv+IneSZwhBh1oSyEHA71A==",
"license": "BSD-3-Clause",
"dependencies": {
"es-define-property": "^1.0.1",
"side-channel": "^1.1.1"
},
"engines": {
"node": ">=0.6"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/range-parser": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.3.0.tgz",
"integrity": "sha512-hek2mFQpPuI4E1BBKrSto+BU3e3x4xuarsbiwr3+lf7p44juvFMV0XFWQAP3xUyqXA4RrXLIoaSUGbSt056ZMw==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/raw-body": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz",
"integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==",
"license": "MIT",
"dependencies": {
"bytes": "~3.1.2",
"http-errors": "~2.0.1",
"iconv-lite": "~0.7.0",
"unpipe": "~1.0.0"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/router": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz",
"integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==",
"license": "MIT",
"dependencies": {
"debug": "^4.4.0",
"depd": "^2.0.0",
"is-promise": "^4.0.0",
"parseurl": "^1.3.3",
"path-to-regexp": "^8.0.0"
},
"engines": {
"node": ">= 18"
}
},
"node_modules/safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"license": "MIT"
},
"node_modules/send": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz",
"integrity": "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ==",
"license": "MIT",
"dependencies": {
"debug": "^4.4.3",
"encodeurl": "^2.0.0",
"escape-html": "^1.0.3",
"etag": "^1.8.1",
"fresh": "^2.0.0",
"http-errors": "^2.0.1",
"mime-types": "^3.0.2",
"ms": "^2.1.3",
"on-finished": "^2.4.1",
"range-parser": "^1.2.1",
"statuses": "^2.0.2"
},
"engines": {
"node": ">= 18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/serve-static": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.1.tgz",
"integrity": "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw==",
"license": "MIT",
"dependencies": {
"encodeurl": "^2.0.0",
"escape-html": "^1.0.3",
"parseurl": "^1.3.3",
"send": "^1.2.0"
},
"engines": {
"node": ">= 18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/setprototypeof": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
"license": "ISC"
},
"node_modules/side-channel": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.1.tgz",
"integrity": "sha512-6x6dK6zJdpTzF4sQeNYxwtvBzf6Eg4GtlesS94HOvTudUeyK2WXAaIfmDgsyslYrRBeFIlsi54AYsFGUuhmvrQ==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"object-inspect": "^1.13.4",
"side-channel-list": "^1.0.1",
"side-channel-map": "^1.0.1",
"side-channel-weakmap": "^1.0.2"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-list": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz",
"integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"object-inspect": "^1.13.4"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-map": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz",
"integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==",
"license": "MIT",
"dependencies": {
"call-bound": "^1.0.2",
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.5",
"object-inspect": "^1.13.3"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-weakmap": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
"integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
"license": "MIT",
"dependencies": {
"call-bound": "^1.0.2",
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.5",
"object-inspect": "^1.13.3",
"side-channel-map": "^1.0.1"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/statuses": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",
"integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/toidentifier": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
"license": "MIT",
"engines": {
"node": ">=0.6"
}
},
"node_modules/type-is": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-2.1.0.tgz",
"integrity": "sha512-faYHw0anBbc/kWF3zFTEnxSFOAGUX9GFbOBthvDdLsIlEoWOFOtS0zgCiQYwIskL9iGXZL3kAXD8OoZ4GmMATA==",
"license": "MIT",
"dependencies": {
"content-type": "^2.0.0",
"media-typer": "^1.1.0",
"mime-types": "^3.0.0"
},
"engines": {
"node": ">= 18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/type-is/node_modules/content-type": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-2.0.0.tgz",
"integrity": "sha512-j/O/d7GcZCyNl7/hwZAb606rzqkyvaDctLmckbxLzHvFBzTJHuGEdodATcP3yIRoDrLHkIATJuvzbFlp/ki2cQ==",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
"integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"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"
}
},
"node_modules/vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
"license": "ISC"
}
}
}

View File

@@ -1,19 +0,0 @@
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);
}

View File

@@ -0,0 +1,32 @@
import fs from 'node:fs';
import { v4 as id } from 'uuid';
const PRODUCTS_PATH = '../data/products.json';
/** Ein vollständiges Produkt, so wie es in products.json steht. */
interface Product {
_id: string;
position: number;
name: string;
price: number;
}
/** Produkt aus der Datei - _id und position können noch fehlen. */
type ProductInput = Omit<Product, '_id' | 'position'> & Partial<Pick<Product, '_id' | 'position'>>;
console.log(id()); // 97412ca6-c7a8-4868-a49b-3cf4c2258dd8
try {
const data = JSON.parse(fs.readFileSync(PRODUCTS_PATH, 'utf-8')) as ProductInput[];
const products: Product[] = data.map((product, index) => {
return { _id: product._id || id(), position: index + 1, ...product };
});
console.log(products);
fs.writeFileSync(PRODUCTS_PATH, JSON.stringify(products, null, 2), 'utf-8');
console.log('File modified');
} catch (error) {
console.log(error);
}

View File

@@ -9,8 +9,43 @@
"version": "1.0.0", "version": "1.0.0",
"dependencies": { "dependencies": {
"uuid": "^14.0.1" "uuid": "^14.0.1"
},
"devDependencies": {
"@types/node": "^24.10.1",
"typescript": "^5.9.3"
} }
}, },
"node_modules/@types/node": {
"version": "24.13.3",
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.13.3.tgz",
"integrity": "sha512-Dh8vAsV36ig5wa9OX4pXvMc9D3Veibfw2wix0CUwYODLD8nkj9UsLjASr49nPg+2eKzxhBV+v7L8pXvT4e639Q==",
"dev": true,
"license": "MIT",
"dependencies": {
"undici-types": "~7.18.0"
}
},
"node_modules/typescript": {
"version": "5.9.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
"dev": true,
"license": "Apache-2.0",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=14.17"
}
},
"node_modules/undici-types": {
"version": "7.18.2",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.18.2.tgz",
"integrity": "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==",
"dev": true,
"license": "MIT"
},
"node_modules/uuid": { "node_modules/uuid": {
"version": "14.0.1", "version": "14.0.1",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-14.0.1.tgz", "resolved": "https://registry.npmjs.org/uuid/-/uuid-14.0.1.tgz",

View File

@@ -2,13 +2,19 @@
"name": "utils", "name": "utils",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "json-modifier.js", "main": "json-modifier.ts",
"scripts": { "scripts": {
"start": "node json-modifier.ts",
"typecheck": "tsc --noEmit",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"keywords": [], "keywords": [],
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"uuid": "^14.0.1" "uuid": "^14.0.1"
},
"devDependencies": {
"@types/node": "^24.10.1",
"typescript": "^5.9.3"
} }
} }

View File

@@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"lib": ["ES2022"],
/* Node >= 22.18 führt .ts-Dateien direkt aus (type stripping),
tsc wird deshalb nur zum Typprüfen genutzt. */
"noEmit": true,
"allowImportingTsExtensions": true,
"erasableSyntaxOnly": true,
"verbatimModuleSyntax": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true
},
"include": ["**/*.ts"],
"exclude": ["node_modules"]
}

View File

@@ -1,3 +1,4 @@
"use strict";
(() => { (() => {
var __create = Object.create; var __create = Object.create;
var __defProp = Object.defineProperty; var __defProp = Object.defineProperty;
@@ -5499,7 +5500,7 @@
enableDismissTrigger(Toast); enableDismissTrigger(Toast);
defineJQueryPlugin(Toast); defineJQueryPlugin(Toast);
// dev/scripts/modules/Toast.js // dev/scripts/modules/Toast.ts
var import_toastify_js = __toESM(require_toastify(), 1); var import_toastify_js = __toESM(require_toastify(), 1);
var Toast2 = (text = "", variant = "primary") => { var Toast2 = (text = "", variant = "primary") => {
const getColorByName = (variant2 = "") => { const getColorByName = (variant2 = "") => {
@@ -5532,7 +5533,7 @@
break; break;
default: default:
console.warn("variant not found"); console.warn("variant not found");
color: "white"; color = "white";
} }
return color; return color;
}; };
@@ -5558,34 +5559,42 @@
}; };
var Toast_default = Toast2; var Toast_default = Toast2;
// dev/scripts/modules/ProductManager.js // dev/scripts/modules/ProductManager.ts
var ProductManager = (el = null) => { var ProductManager = (el = null) => {
const BASE_URL = "http://127.0.0.1:8000"; const BASE_URL = "http://127.0.0.1:8000";
const module = el || document.querySelector(".product-manager") || console.error("Product Manager not found"); const module = el ?? document.querySelector(".product-manager");
if (!module) return; if (!module) {
console.error("Product Manager not found");
return null;
}
const query2 = (root, selector) => {
const found = root.querySelector(selector);
if (!found) throw new Error(`ProductManager: Element "${selector}" nicht gefunden.`);
return found;
};
const DOM = { const DOM = {
module, module,
table: module.querySelector(".table-products"), table: query2(module, ".table-products"),
tBody: module.querySelector("tbody"), tBody: query2(module, "tbody"),
inputName: module.querySelector(".input-product-name"), inputName: query2(module, ".input-product-name"),
inputPrice: module.querySelector(".input-product-price"), inputPrice: query2(module, ".input-product-price"),
btnAdd: module.querySelector(".button-product-add"), btnAdd: query2(module, ".button-product-add"),
templateRow: module.querySelector(".template-row"), templateRow: query2(module, ".template-row"),
// Nav Actions // Nav Actions
btnSave: module.querySelector(".button-products-save"), btnSave: query2(module, ".button-products-save"),
btnReset: module.querySelector(".button-products-reset"), btnReset: query2(module, ".button-products-reset"),
// Modal Edit // Modal Edit
modalEdit: module.querySelector(".modal-edit"), modalEdit: query2(module, ".modal-edit"),
formEdit: module.querySelector(".form-product-edit"), formEdit: query2(module, ".form-product-edit"),
inputEditName: module.querySelector(".input-edit-name"), inputEditName: query2(module, ".input-edit-name"),
inputEditPrice: module.querySelector(".input-edit-price"), inputEditPrice: query2(module, ".input-edit-price"),
inputEditId: module.querySelector(".input-edit-id"), inputEditId: query2(module, ".input-edit-id"),
inputEditPosition: module.querySelector(".input-edit-position"), inputEditPosition: query2(module, ".input-edit-position"),
btnUpdate: module.querySelector(".button-product-update"), btnUpdate: query2(module, ".button-product-update"),
// Modal Delete // Modal Delete
modalDelete: module.querySelector(".modal-delete"), modalDelete: query2(module, ".modal-delete"),
productName: module.querySelector("strong.product-name"), productName: query2(module, "strong.product-name"),
btnConfirmDelete: module.querySelector(".button-confirm-delete") btnConfirmDelete: query2(module, ".button-confirm-delete")
}; };
console.log(DOM); console.log(DOM);
const bsModalEdit = new Modal(DOM.modalEdit, { const bsModalEdit = new Modal(DOM.modalEdit, {
@@ -5609,11 +5618,10 @@
DOM.formEdit.addEventListener("submit", onSubmitEdit); DOM.formEdit.addEventListener("submit", onSubmitEdit);
window.addEventListener("keyup", onKeyUp); window.addEventListener("keyup", onKeyUp);
}; };
const onKeyUp = (e) => { const onKeyUp = () => {
DOM.btnAdd.disabled = DOM.inputName.value === "" || DOM.inputPrice.value === ""; DOM.btnAdd.disabled = DOM.inputName.value === "" || DOM.inputPrice.value === "";
}; };
const onClickReset = (e) => { const onClickReset = () => {
const btnEl = e.currentTarget;
resetProducts().then((data) => { resetProducts().then((data) => {
if (data.success) { if (data.success) {
Toast_default(data.msg, "success").show(); Toast_default(data.msg, "success").show();
@@ -5623,7 +5631,7 @@
}; };
const onClickSave = (e) => { const onClickSave = (e) => {
const btnEl = e.currentTarget; const btnEl = e.currentTarget;
const icon = btnEl.querySelector("i"); const icon = query2(btnEl, "i");
icon.classList.add("fa-jello"); icon.classList.add("fa-jello");
saveProducts().then((data) => { saveProducts().then((data) => {
if (data.success) { if (data.success) {
@@ -5640,14 +5648,15 @@
name: DOM.inputEditName.value, name: DOM.inputEditName.value,
price: Number(DOM.inputEditPrice.value), price: Number(DOM.inputEditPrice.value),
_id: DOM.inputEditId.value, _id: DOM.inputEditId.value,
position: DOM.inputEditPosition.value position: Number(DOM.inputEditPosition.value)
}; };
DOM.btnUpdate.querySelector("i").classList.add("fa-spin"); const icon = query2(DOM.btnUpdate, "i");
icon.classList.add("fa-spin");
updateProduct(product).then((data) => { updateProduct(product).then((data) => {
console.log(data); console.log(data);
if (data.success) { if (data.success) {
Toast_default(data.msg, "success").show(); Toast_default(data.msg, "success").show();
DOM.btnUpdate.querySelector("i").classList.remove("fa-spin"); icon.classList.remove("fa-spin");
loadProducts(); loadProducts();
resetFields(); resetFields();
bsModalEdit.hide(); bsModalEdit.hide();
@@ -5676,22 +5685,22 @@
const onClickEdit = (e) => { const onClickEdit = (e) => {
const btnEl = e.currentTarget; const btnEl = e.currentTarget;
const currentRow = parents(btnEl, "tr")[0]; const currentRow = parents(btnEl, "tr")[0];
const id = currentRow.dataset.id; const id = currentRow.dataset.id ?? "";
getProduct(id).then((data) => { getProduct(id).then((product) => {
showModalEdit(data); if (product) showModalEdit(product);
}); });
}; };
const onClickRemove = (e) => { const onClickRemove = (e) => {
const btnEl = e.currentTarget; const btnEl = e.currentTarget;
const currentRow = parents(btnEl, "tr")[0]; const currentRow = parents(btnEl, "tr")[0];
const id = currentRow.dataset.id; const id = currentRow.dataset.id ?? "";
const productName = currentRow.querySelector(".td-name").textContent.trim(); const productName = query2(currentRow, ".td-name").textContent?.trim() ?? "";
DOM.btnConfirmDelete.dataset.id = id; DOM.btnConfirmDelete.dataset.id = id;
DOM.productName.textContent = productName; DOM.productName.textContent = productName;
}; };
const onClickConfirmDelete = (e) => { const onClickConfirmDelete = (e) => {
const btnEl = e.currentTarget; const btnEl = e.currentTarget;
const id = btnEl.dataset.id; const id = btnEl.dataset.id ?? "";
deleteProduct(id).then((data) => { deleteProduct(id).then((data) => {
if (data.success) { if (data.success) {
Toast_default(data.msg, "success").show(); Toast_default(data.msg, "success").show();
@@ -5706,14 +5715,14 @@
const onClickMoveUp = (e) => { const onClickMoveUp = (e) => {
const btnEl = e.currentTarget; const btnEl = e.currentTarget;
const currentRowEl = parents(btnEl, "tr")[0]; const currentRowEl = parents(btnEl, "tr")[0];
currentRowEl.previousElementSibling.before(currentRowEl); currentRowEl.previousElementSibling?.before(currentRowEl);
console.log("move up"); console.log("move up");
disableNonFunctionalButtons(); disableNonFunctionalButtons();
}; };
const onClickMoveDown = (e) => { const onClickMoveDown = (e) => {
const btnEl = e.currentTarget; const btnEl = e.currentTarget;
const currentRowEl = parents(btnEl, "tr")[0]; const currentRowEl = parents(btnEl, "tr")[0];
currentRowEl.nextElementSibling.after(currentRowEl); currentRowEl.nextElementSibling?.after(currentRowEl);
console.log("move down"); console.log("move down");
disableNonFunctionalButtons(); disableNonFunctionalButtons();
}; };
@@ -5730,8 +5739,8 @@
const onDragStart = (e) => { const onDragStart = (e) => {
console.log("DragEvent: ", e); console.log("DragEvent: ", e);
const currentRowEl = e.currentTarget; const currentRowEl = e.currentTarget;
const idx = [...currentRowEl.parentNode.children].indexOf(currentRowEl); const idx = indexOfRow(currentRowEl);
e.dataTransfer.setData("text/plain", idx); e.dataTransfer?.setData("text/plain", String(idx));
console.log("tr index:", idx); console.log("tr index:", idx);
}; };
const onDragOver = (e) => { const onDragOver = (e) => {
@@ -5739,13 +5748,14 @@
}; };
const onDrop = (e) => { const onDrop = (e) => {
const currentRowEl = e.currentTarget; const currentRowEl = e.currentTarget;
const targetIdx = [...currentRowEl.parentNode.children].indexOf(currentRowEl); const targetIdx = indexOfRow(currentRowEl);
const sourceIdx = parseInt(e.dataTransfer.getData("text/plain")); const sourceIdx = parseInt(e.dataTransfer?.getData("text/plain") ?? "");
console.log({ targetIdx, sourceIdx }); console.log({ targetIdx, sourceIdx });
if (sourceIdx === targetIdx) { if (Number.isNaN(sourceIdx) || sourceIdx === targetIdx) {
return; return;
} }
const draggedEl = DOM.tBody.querySelector(`tr:nth-child(${sourceIdx + 1})`); const draggedEl = DOM.tBody.querySelector(`tr:nth-child(${sourceIdx + 1})`);
if (!draggedEl) return;
if (sourceIdx > targetIdx) { if (sourceIdx > targetIdx) {
currentRowEl.before(draggedEl); currentRowEl.before(draggedEl);
} else { } else {
@@ -5753,6 +5763,11 @@
} }
disableNonFunctionalButtons(); disableNonFunctionalButtons();
}; };
const toErrorResponse = (error) => ({
msg: error instanceof Error ? error.message : String(error),
status: 0,
success: false
});
const resetProducts = async () => { const resetProducts = async () => {
try { try {
const response = await fetch(`${BASE_URL}/api/products/reset`, { const response = await fetch(`${BASE_URL}/api/products/reset`, {
@@ -5768,9 +5783,10 @@
const data = await response.json(); const data = await response.json();
return data; return data;
} catch (error) { } catch (error) {
Toast_default(error, "error").show(); const result = toErrorResponse(error);
Toast_default(result.msg, "error").show();
console.error(error); console.error(error);
return error; return result;
} }
}; };
const saveProducts = async () => { const saveProducts = async () => {
@@ -5788,9 +5804,10 @@
const data = await response.json(); const data = await response.json();
return data; return data;
} catch (error) { } catch (error) {
Toast_default(error, "error").show(); const result = toErrorResponse(error);
Toast_default(result.msg, "error").show();
console.error(error); console.error(error);
return error; return result;
} }
}; };
const createProduct = async (product) => { const createProduct = async (product) => {
@@ -5808,9 +5825,10 @@
const data = await response.json(); const data = await response.json();
return data; return data;
} catch (error) { } catch (error) {
Toast_default(error, "error").show(); const result = toErrorResponse(error);
Toast_default(result.msg, "error").show();
console.error(error); console.error(error);
return error; return result;
} }
}; };
const getProducts = async () => { const getProducts = async () => {
@@ -5823,7 +5841,7 @@
return data; return data;
} catch (error) { } catch (error) {
console.error(error); console.error(error);
return error; return [];
} }
}; };
const getProduct = async (id) => { const getProduct = async (id) => {
@@ -5836,7 +5854,7 @@
return data; return data;
} catch (error) { } catch (error) {
console.error(error); console.error(error);
return error; return null;
} }
}; };
const updateProduct = async (product) => { const updateProduct = async (product) => {
@@ -5855,7 +5873,7 @@
return data; return data;
} catch (error) { } catch (error) {
console.error(error); console.error(error);
return error; return toErrorResponse(error);
} }
}; };
const deleteProduct = async (id) => { const deleteProduct = async (id) => {
@@ -5873,7 +5891,7 @@
return data; return data;
} catch (error) { } catch (error) {
console.error(error); console.error(error);
return error; return toErrorResponse(error);
} }
}; };
const initProducts = () => { const initProducts = () => {
@@ -5896,16 +5914,18 @@
}; };
const addProduct = (product) => { const addProduct = (product) => {
const { name, price, _id: id, position } = product; const { name, price, _id: id, position } = product;
const trEl = DOM.templateRow.content.firstElementChild.cloneNode(true); const templateEl = DOM.templateRow.content.firstElementChild;
const tdNameEl = trEl.querySelector(".td-name"); if (!templateEl) throw new Error('ProductManager: <template class="template-row"> ist leer.');
const tdPriceEl = trEl.querySelector(".td-price"); const trEl = templateEl.cloneNode(true);
const btnRemoveEl = trEl.querySelector(".button-product-remove"); const tdNameEl = query2(trEl, ".td-name");
const btnMoveUpEl = trEl.querySelector(".button-product-move-up"); const tdPriceEl = query2(trEl, ".td-price");
const btnMoveDownEl = trEl.querySelector(".button-product-move-down"); const btnRemoveEl = query2(trEl, ".button-product-remove");
const btnDragEl = trEl.querySelector(".button-drag"); const btnMoveUpEl = query2(trEl, ".button-product-move-up");
const btnEditEl = trEl.querySelector(".button-product-edit"); const btnMoveDownEl = query2(trEl, ".button-product-move-down");
const btnDragEl = query2(trEl, ".button-drag");
const btnEditEl = query2(trEl, ".button-product-edit");
tdNameEl.textContent = name; tdNameEl.textContent = name;
tdPriceEl.textContent = price; tdPriceEl.textContent = String(price);
btnEditEl.addEventListener("click", onClickEdit); btnEditEl.addEventListener("click", onClickEdit);
btnRemoveEl.addEventListener("click", onClickRemove); btnRemoveEl.addEventListener("click", onClickRemove);
btnMoveUpEl.addEventListener("click", onClickMoveUp); btnMoveUpEl.addEventListener("click", onClickMoveUp);
@@ -5916,15 +5936,15 @@
trEl.addEventListener("dragover", onDragOver); trEl.addEventListener("dragover", onDragOver);
trEl.addEventListener("drop", onDrop); trEl.addEventListener("drop", onDrop);
trEl.dataset.id = id; trEl.dataset.id = id;
trEl.dataset.position = position; trEl.dataset.position = String(position);
DOM.tBody.appendChild(trEl); DOM.tBody.appendChild(trEl);
}; };
const showModalEdit = (product) => { const showModalEdit = (product) => {
const { name = "", price = 0, _id: id, position } = product; const { name = "", price = 0, _id: id, position } = product;
DOM.inputEditName.value = name; DOM.inputEditName.value = name;
DOM.inputEditPrice.value = price; DOM.inputEditPrice.value = String(price);
DOM.inputEditId.value = id; DOM.inputEditId.value = id;
DOM.inputEditPosition.value = position; DOM.inputEditPosition.value = String(position);
}; };
const resetFields = () => { const resetFields = () => {
DOM.btnAdd.disabled = true; DOM.btnAdd.disabled = true;
@@ -5934,18 +5954,26 @@
}; };
const disableNonFunctionalButtons = () => { const disableNonFunctionalButtons = () => {
Array.from(DOM.tBody.querySelectorAll("tr")).forEach((tr) => { Array.from(DOM.tBody.querySelectorAll("tr")).forEach((tr) => {
const btnMoveUp = tr.querySelector(".button-product-move-up"); const btnMoveUp = query2(tr, ".button-product-move-up");
const btnMoveDown = tr.querySelector(".button-product-move-down"); const btnMoveDown = query2(tr, ".button-product-move-down");
btnMoveUp.disabled = !tr.previousElementSibling; btnMoveUp.disabled = !tr.previousElementSibling;
btnMoveDown.disabled = !tr.nextElementSibling; btnMoveDown.disabled = !tr.nextElementSibling;
}); });
}; };
const indexOfRow = (rowEl) => {
const siblings = rowEl.parentElement ? Array.from(rowEl.parentElement.children) : [];
return siblings.indexOf(rowEl);
};
const parents = (el2, selector) => { const parents = (el2, selector) => {
const parents2 = []; const result = [];
while ((el2 = el2.parentNode) && el2 !== document) { let current = el2.parentNode;
if (!selector || el2.matches(selector)) parents2.push(el2); while (current && current !== document) {
if (current instanceof Element && (!selector || current.matches(selector))) {
result.push(current);
} }
return parents2; current = current.parentNode;
}
return result;
}; };
init(); init();
return { return {
@@ -8525,7 +8553,7 @@
Splide.defaults = {}; Splide.defaults = {};
Splide.STATES = STATES; Splide.STATES = STATES;
// dev/scripts/main.js // dev/scripts/main.ts
(() => { (() => {
const DOM = {}; const DOM = {};
const init = () => { const init = () => {
@@ -8537,7 +8565,7 @@
console.log(path); console.log(path);
switch (path) { switch (path) {
case "/": case "/":
case "/index.html": case "/index.html": {
console.log("HOME"); console.log("HOME");
const splider = new Splide(".splide", { const splider = new Splide(".splide", {
type: "loop", type: "loop",
@@ -8546,10 +8574,12 @@
autoHeight: true autoHeight: true
}).mount(); }).mount();
break; break;
case "/projects/product-manager.html": }
case "/projects/product-manager.html": {
console.log("PRODUCT_MANAGER"); console.log("PRODUCT_MANAGER");
const pm = ProductManager_default(); const pm = ProductManager_default();
break; break;
}
default: default:
console.warn("Page not found"); console.warn("Page not found");
} }

File diff suppressed because one or more lines are too long

View File

@@ -8,7 +8,7 @@ import Splide from '@splidejs/splide';
const DOM = {}; const DOM = {};
// === INIT ============= // === INIT =============
const init = () => { const init = (): void => {
console.log('init'); console.log('init');
router(); router();
}; };
@@ -18,14 +18,14 @@ import Splide from '@splidejs/splide';
// === XHR/FETCH ======== // === XHR/FETCH ========
// === FUNCTIONS ======== // === FUNCTIONS ========
const router = () => { const router = (): void => {
const path = window.location.pathname; const path = window.location.pathname;
console.log(path); console.log(path);
switch (path) { switch (path) {
case '/': case '/':
case '/index.html': case '/index.html': {
console.log('HOME'); console.log('HOME');
const splider = new Splide('.splide', { const splider = new Splide('.splide', {
type: 'loop', type: 'loop',
@@ -36,10 +36,12 @@ import Splide from '@splidejs/splide';
// nur Skripte, die für Home relevant ausführen // nur Skripte, die für Home relevant ausführen
break; break;
case '/projects/product-manager.html': }
case '/projects/product-manager.html': {
console.log('PRODUCT_MANAGER'); console.log('PRODUCT_MANAGER');
const pm = ProductManager(); const pm = ProductManager();
break; break;
}
default: default:
console.warn('Page not found'); console.warn('Page not found');
} }

View File

@@ -1,5 +1,6 @@
import { Modal } from 'bootstrap'; // ohne Pfadangabe (Modul auslesen aus node_modules) funktioniert nur mit JS-Bundler (esbuild, rollup & co.) import { Modal } from 'bootstrap'; // ohne Pfadangabe (Modul auslesen aus node_modules) funktioniert nur mit JS-Bundler (esbuild, rollup & co.)
import Toast from './Toast'; import Toast from './Toast';
import type { ApiResponse, Product, ProductDraft } from '../types';
// import * as bootstrap from 'bootstrap'; // import * as bootstrap from 'bootstrap';
// import 'bootstrap'; // import 'bootstrap';
@@ -7,42 +8,58 @@ import Toast from './Toast';
// import 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js'; // würde auch ohne Bundler funktionieren // import 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js'; // würde auch ohne Bundler funktionieren
// import '../../../node_modules/bootstrap/dist/js/bootstrap.esm.js'; // würde auch ohne Bundler funktionieren // import '../../../node_modules/bootstrap/dist/js/bootstrap.esm.js'; // würde auch ohne Bundler funktionieren
export interface ProductManagerApi {
init: () => void;
initProducts: () => void;
resetFields: () => void;
}
// Factory Function // Factory Function
const ProductManager = (el = null) => { const ProductManager = (el: HTMLElement | null = null): ProductManagerApi | null => {
// === DOM & VARS ======= // === DOM & VARS =======
const BASE_URL = 'http://127.0.0.1:8000'; const BASE_URL = 'http://127.0.0.1:8000';
const module = el || document.querySelector('.product-manager') || console.error('Product Manager not found'); const module = el ?? document.querySelector<HTMLElement>('.product-manager');
if (!module) return; if (!module) {
console.error('Product Manager not found');
return null;
}
/** querySelector mit Typ-Angabe: wirft einen Fehler, wenn das Element fehlt. */
const query = <T extends HTMLElement>(root: ParentNode, selector: string): T => {
const found = root.querySelector<T>(selector);
if (!found) throw new Error(`ProductManager: Element "${selector}" nicht gefunden.`);
return found;
};
const DOM = { const DOM = {
module, module,
table: module.querySelector('.table-products'), table: query<HTMLTableElement>(module, '.table-products'),
tBody: module.querySelector('tbody'), tBody: query<HTMLTableSectionElement>(module, 'tbody'),
inputName: module.querySelector('.input-product-name'), inputName: query<HTMLInputElement>(module, '.input-product-name'),
inputPrice: module.querySelector('.input-product-price'), inputPrice: query<HTMLInputElement>(module, '.input-product-price'),
btnAdd: module.querySelector('.button-product-add'), btnAdd: query<HTMLButtonElement>(module, '.button-product-add'),
templateRow: module.querySelector('.template-row'), templateRow: query<HTMLTemplateElement>(module, '.template-row'),
// Nav Actions // Nav Actions
btnSave: module.querySelector('.button-products-save'), btnSave: query<HTMLButtonElement>(module, '.button-products-save'),
btnReset: module.querySelector('.button-products-reset'), btnReset: query<HTMLButtonElement>(module, '.button-products-reset'),
// Modal Edit // Modal Edit
modalEdit: module.querySelector('.modal-edit'), modalEdit: query<HTMLElement>(module, '.modal-edit'),
formEdit: module.querySelector('.form-product-edit'), formEdit: query<HTMLFormElement>(module, '.form-product-edit'),
inputEditName: module.querySelector('.input-edit-name'), inputEditName: query<HTMLInputElement>(module, '.input-edit-name'),
inputEditPrice: module.querySelector('.input-edit-price'), inputEditPrice: query<HTMLInputElement>(module, '.input-edit-price'),
inputEditId: module.querySelector('.input-edit-id'), inputEditId: query<HTMLInputElement>(module, '.input-edit-id'),
inputEditPosition: module.querySelector('.input-edit-position'), inputEditPosition: query<HTMLInputElement>(module, '.input-edit-position'),
btnUpdate: module.querySelector('.button-product-update'), btnUpdate: query<HTMLButtonElement>(module, '.button-product-update'),
// Modal Delete // Modal Delete
modalDelete: module.querySelector('.modal-delete'), modalDelete: query<HTMLElement>(module, '.modal-delete'),
productName: module.querySelector('strong.product-name'), productName: query<HTMLElement>(module, 'strong.product-name'),
btnConfirmDelete: module.querySelector('.button-confirm-delete'), btnConfirmDelete: query<HTMLButtonElement>(module, '.button-confirm-delete'),
}; };
console.log(DOM); console.log(DOM);
@@ -57,7 +74,7 @@ const ProductManager = (el = null) => {
}); });
// === INIT ============= // === INIT =============
const init = () => { const init = (): void => {
console.log('init'); console.log('init');
// Funktionaufrufe zu beginn der Anwendung // Funktionaufrufe zu beginn der Anwendung
initProducts(); initProducts();
@@ -74,7 +91,7 @@ const ProductManager = (el = null) => {
}; };
// === EVENTHANDLER ===== // === EVENTHANDLER =====
const onKeyUp = (e) => { const onKeyUp = (): void => {
// if (DOM.inputName.value === '' && DOM.inputPrice.value === '') { // if (DOM.inputName.value === '' && DOM.inputPrice.value === '') {
// DOM.btnAdd.disabled = true; // DOM.btnAdd.disabled = true;
// } else { // } else {
@@ -83,9 +100,7 @@ const ProductManager = (el = null) => {
DOM.btnAdd.disabled = (DOM.inputName.value === '' || DOM.inputPrice.value === ''); // prettier-ignore DOM.btnAdd.disabled = (DOM.inputName.value === '' || DOM.inputPrice.value === ''); // prettier-ignore
}; };
const onClickReset = (e) => { const onClickReset = (): void => {
const btnEl = e.currentTarget;
// async process // async process
resetProducts().then((data) => { resetProducts().then((data) => {
if (data.success) { if (data.success) {
@@ -95,9 +110,9 @@ const ProductManager = (el = null) => {
}); });
}; };
const onClickSave = (e) => { const onClickSave = (e: MouseEvent): void => {
const btnEl = e.currentTarget; const btnEl = e.currentTarget as HTMLButtonElement;
const icon = btnEl.querySelector('i'); const icon = query<HTMLElement>(btnEl, 'i');
icon.classList.add('fa-jello'); icon.classList.add('fa-jello');
@@ -112,25 +127,26 @@ const ProductManager = (el = null) => {
}); });
}; };
const onSubmitEdit = (e) => { const onSubmitEdit = (e: SubmitEvent): void => {
e.preventDefault(); // Standardverhalten unterbinden (Formular nicht an action versenden) e.preventDefault(); // Standardverhalten unterbinden (Formular nicht an action versenden)
// console.log(Object.entries(new FormData(DOM.formEdit))); // console.log(Object.entries(new FormData(DOM.formEdit)));
const product = { const product: Product = {
name: DOM.inputEditName.value, name: DOM.inputEditName.value,
price: Number(DOM.inputEditPrice.value), price: Number(DOM.inputEditPrice.value),
_id: DOM.inputEditId.value, _id: DOM.inputEditId.value,
position: DOM.inputEditPosition.value, position: Number(DOM.inputEditPosition.value),
}; };
// update async process // update async process
DOM.btnUpdate.querySelector('i').classList.add('fa-spin'); const icon = query<HTMLElement>(DOM.btnUpdate, 'i');
icon.classList.add('fa-spin');
updateProduct(product).then((data) => { updateProduct(product).then((data) => {
console.log(data); console.log(data);
if (data.success) { if (data.success) {
Toast(data.msg, 'success').show(); Toast(data.msg, 'success').show();
DOM.btnUpdate.querySelector('i').classList.remove('fa-spin'); icon.classList.remove('fa-spin');
loadProducts(); // All Produkte auslesen loadProducts(); // All Produkte auslesen
resetFields(); resetFields();
bsModalEdit.hide(); bsModalEdit.hide();
@@ -140,10 +156,10 @@ const ProductManager = (el = null) => {
}); });
}; };
const onClickAdd = (e) => { const onClickAdd = (e: MouseEvent): void => {
console.log('click'); console.log('click');
const product = { const product: ProductDraft = {
name: DOM.inputName.value, name: DOM.inputName.value,
price: Number(DOM.inputPrice.value), price: Number(DOM.inputPrice.value),
}; };
@@ -163,24 +179,24 @@ const ProductManager = (el = null) => {
disableNonFunctionalButtons(); disableNonFunctionalButtons();
}; };
const onClickEdit = (e) => { const onClickEdit = (e: MouseEvent): void => {
const btnEl = e.currentTarget; const btnEl = e.currentTarget as HTMLButtonElement;
const currentRow = parents(btnEl, 'tr')[0]; const currentRow = parents(btnEl, 'tr')[0] as HTMLTableRowElement;
const id = currentRow.dataset.id; const id = currentRow.dataset.id ?? '';
// async fetch // async fetch
getProduct(id).then((data) => { getProduct(id).then((product) => {
// console.log(data); // console.log(product);
showModalEdit(data); if (product) showModalEdit(product);
}); });
}; };
const onClickRemove = (e) => { const onClickRemove = (e: MouseEvent): void => {
const btnEl = e.currentTarget; const btnEl = e.currentTarget as HTMLButtonElement;
const currentRow = parents(btnEl, 'tr')[0]; const currentRow = parents(btnEl, 'tr')[0] as HTMLTableRowElement;
const id = currentRow.dataset.id; const id = currentRow.dataset.id ?? '';
const productName = currentRow.querySelector('.td-name').textContent.trim(); const productName = query<HTMLElement>(currentRow, '.td-name').textContent?.trim() ?? '';
DOM.btnConfirmDelete.dataset.id = id; DOM.btnConfirmDelete.dataset.id = id;
DOM.productName.textContent = productName; DOM.productName.textContent = productName;
@@ -198,9 +214,9 @@ const ProductManager = (el = null) => {
// }); // });
}; };
const onClickConfirmDelete = (e) => { const onClickConfirmDelete = (e: MouseEvent): void => {
const btnEl = e.currentTarget; const btnEl = e.currentTarget as HTMLButtonElement;
const id = btnEl.dataset.id; const id = btnEl.dataset.id ?? '';
// async fetch // async fetch
deleteProduct(id).then((data) => { deleteProduct(id).then((data) => {
@@ -215,79 +231,81 @@ const ProductManager = (el = null) => {
}); });
}; };
const onClickMoveUp = (e) => { const onClickMoveUp = (e: MouseEvent): void => {
const btnEl = e.currentTarget; const btnEl = e.currentTarget as HTMLButtonElement;
// const currentRowEl = btnEl.parentNode.parentNode; // aktuelle Zeile (tr) mit dem Button // const currentRowEl = btnEl.parentNode.parentNode; // aktuelle Zeile (tr) mit dem Button
const currentRowEl = parents(btnEl, 'tr')[0]; const currentRowEl = parents(btnEl, 'tr')[0] as HTMLTableRowElement;
// ParentNode.insertBefore(referenceElement, targetElement) // ParentNode.insertBefore(referenceElement, targetElement)
// DOM.tBody.insertBefore(currentRowEl, currentRowEl.previousElementSibling); // DOM.tBody.insertBefore(currentRowEl, currentRowEl.previousElementSibling);
// targetElement.before(referenceElement) // targetElement.before(referenceElement)
currentRowEl.previousElementSibling.before(currentRowEl); currentRowEl.previousElementSibling?.before(currentRowEl);
console.log('move up'); console.log('move up');
disableNonFunctionalButtons(); disableNonFunctionalButtons();
}; };
const onClickMoveDown = (e) => { const onClickMoveDown = (e: MouseEvent): void => {
const btnEl = e.currentTarget; const btnEl = e.currentTarget as HTMLButtonElement;
// const currentRowEl = btnEl.parentNode.parentNode; // aktuelle Zeile (tr) mit dem Button // const currentRowEl = btnEl.parentNode.parentNode; // aktuelle Zeile (tr) mit dem Button
const currentRowEl = parents(btnEl, 'tr')[0]; const currentRowEl = parents(btnEl, 'tr')[0] as HTMLTableRowElement;
// ParentNode.insertBefore(referenceElement, targetElement) // ParentNode.insertBefore(referenceElement, targetElement)
// DOM.tBody.insertBefore(currentRowEl, currentRowEl.nextElementSibling.nextElementSibling); // DOM.tBody.insertBefore(currentRowEl, currentRowEl.nextElementSibling.nextElementSibling);
// targetElement.after(referenceElement) // targetElement.after(referenceElement)
currentRowEl.nextElementSibling.after(currentRowEl); currentRowEl.nextElementSibling?.after(currentRowEl);
console.log('move down'); console.log('move down');
disableNonFunctionalButtons(); disableNonFunctionalButtons();
}; };
// Drag 'n Drop EventHandler // Drag 'n Drop EventHandler
const onMouseDownDrag = (e) => { const onMouseDownDrag = (e: MouseEvent): void => {
const btnEl = e.currentTarget; const btnEl = e.currentTarget as HTMLButtonElement;
const currentRowEl = parents(btnEl, 'tr')[0]; const currentRowEl = parents(btnEl, 'tr')[0] as HTMLTableRowElement;
currentRowEl.draggable = true; currentRowEl.draggable = true;
}; };
const onMouseUpDrag = (e) => { const onMouseUpDrag = (e: MouseEvent): void => {
const btnEl = e.currentTarget; const btnEl = e.currentTarget as HTMLButtonElement;
const currentRowEl = parents(btnEl, 'tr')[0]; const currentRowEl = parents(btnEl, 'tr')[0] as HTMLTableRowElement;
currentRowEl.draggable = false; currentRowEl.draggable = false;
}; };
const onDragStart = (e) => { const onDragStart = (e: DragEvent): void => {
console.log('DragEvent: ', e); console.log('DragEvent: ', e);
const currentRowEl = e.currentTarget; // tr <- aktuelle Zeie, die bewegt wird const currentRowEl = e.currentTarget as HTMLTableRowElement; // tr <- aktuelle Zeie, die bewegt wird
const idx = [...currentRowEl.parentNode.children].indexOf(currentRowEl); const idx = indexOfRow(currentRowEl);
e.dataTransfer.setData('text/plain', idx); e.dataTransfer?.setData('text/plain', String(idx));
// e.dataTransfer.setData('application/json', JSON.stringify({idx, name: sourceElement})); // e.dataTransfer?.setData('application/json', JSON.stringify({idx, name: sourceElement}));
console.log('tr index:', idx); console.log('tr index:', idx);
}; };
const onDragOver = (e) => { const onDragOver = (e: DragEvent): void => {
e.preventDefault(); // WICHTIG! Sonst funktioniert drop EventHandler nicht. e.preventDefault(); // WICHTIG! Sonst funktioniert drop EventHandler nicht.
}; };
const onDrop = (e) => { const onDrop = (e: DragEvent): void => {
const currentRowEl = e.currentTarget; // tr <- Zielzeile, auf die gedroppt wird. const currentRowEl = e.currentTarget as HTMLTableRowElement; // tr <- Zielzeile, auf die gedroppt wird.
const targetIdx = [...currentRowEl.parentNode.children].indexOf(currentRowEl); const targetIdx = indexOfRow(currentRowEl);
const sourceIdx = parseInt(e.dataTransfer.getData('text/plain')); const sourceIdx = parseInt(e.dataTransfer?.getData('text/plain') ?? '');
// const { sourceIdx } = JSON.parse(e.dataTransfer.getData('application/json')); // const { sourceIdx } = JSON.parse(e.dataTransfer.getData('application/json'));
console.log({ targetIdx, sourceIdx }); console.log({ targetIdx, sourceIdx });
// Guard wenn Element auf sich selbst losgelassen wurde, abbruch // Guard wenn Element auf sich selbst losgelassen wurde, abbruch
if (sourceIdx === targetIdx) { if (Number.isNaN(sourceIdx) || sourceIdx === targetIdx) {
return; return;
} }
const draggedEl = DOM.tBody.querySelector(`tr:nth-child(${sourceIdx + 1})`); const draggedEl = DOM.tBody.querySelector<HTMLTableRowElement>(`tr:nth-child(${sourceIdx + 1})`);
// const draggedEl = DOM.tBody.children[sourceIdx] // const draggedEl = DOM.tBody.children[sourceIdx]
if (!draggedEl) return;
// Verschiebe das Element im DOM // Verschiebe das Element im DOM
if (sourceIdx > targetIdx) { if (sourceIdx > targetIdx) {
currentRowEl.before(draggedEl); currentRowEl.before(draggedEl);
@@ -300,9 +318,16 @@ const ProductManager = (el = null) => {
// === XHR/FETCH ======== // === XHR/FETCH ========
/** Fehler eines fetch-Aufrufs in eine ApiResponse umwandeln. */
const toErrorResponse = <TData = unknown>(error: unknown): ApiResponse<TData> => ({
msg: error instanceof Error ? error.message : String(error),
status: 0,
success: false,
});
// HTTP - Methode - PATCH // HTTP - Methode - PATCH
// reset products // reset products
const resetProducts = async () => { const resetProducts = async (): Promise<ApiResponse> => {
try { try {
const response = await fetch(`${BASE_URL}/api/products/reset`, { const response = await fetch(`${BASE_URL}/api/products/reset`, {
method: 'PATCH', method: 'PATCH',
@@ -314,20 +339,21 @@ const ProductManager = (el = null) => {
if (!response.ok) { if (!response.ok) {
throw new Error('Fetch went wrong.'); throw new Error('Fetch went wrong.');
} }
const data = await response.json(); // HTTP-Response const data: ApiResponse = await response.json(); // HTTP-Response
return data; return data;
} catch (error) { } catch (error) {
Toast(error, 'error').show(); const result = toErrorResponse(error);
Toast(result.msg, 'error').show();
console.error(error); console.error(error);
return error; return result;
} }
}; };
// HTTP - Methode - PATCH // HTTP - Methode - PATCH
// save products // save products
const saveProducts = async () => { const saveProducts = async (): Promise<ApiResponse> => {
try { try {
const response = await fetch(`${BASE_URL}/api/products/save`, { const response = await fetch(`${BASE_URL}/api/products/save`, {
method: 'PATCH', method: 'PATCH',
@@ -339,21 +365,22 @@ const ProductManager = (el = null) => {
if (!response.ok) { if (!response.ok) {
throw new Error('Fetch went wrong.'); throw new Error('Fetch went wrong.');
} }
const data = await response.json(); // HTTP-Response const data: ApiResponse = await response.json(); // HTTP-Response
return data; return data;
} catch (error) { } catch (error) {
Toast(error, 'error').show(); const result = toErrorResponse(error);
Toast(result.msg, 'error').show();
console.error(error); console.error(error);
return error; return result;
} }
}; };
// HTTP - Methode - POST // HTTP - Methode - POST
// (C)RUD - create // (C)RUD - create
// BRE(A)D - add - neues Produkt hinzufügen // BRE(A)D - add - neues Produkt hinzufügen
const createProduct = async (product) => { const createProduct = async (product: ProductDraft): Promise<ApiResponse<Product>> => {
try { try {
const response = await fetch(`${BASE_URL}/api/products`, { const response = await fetch(`${BASE_URL}/api/products`, {
method: 'POST', method: 'POST',
@@ -365,57 +392,58 @@ const ProductManager = (el = null) => {
if (!response.ok) { if (!response.ok) {
throw new Error('Fetch went wrong.'); throw new Error('Fetch went wrong.');
} }
const data = await response.json(); // HTTP-Response const data: ApiResponse<Product> = await response.json(); // HTTP-Response
return data; return data;
} catch (error) { } catch (error) {
Toast(error, 'error').show(); const result = toErrorResponse<Product>(error);
Toast(result.msg, 'error').show();
console.error(error); console.error(error);
return error; return result;
} }
}; };
// HTTP - Methode - GET // HTTP - Methode - GET
// C(R)UD - Read // C(R)UD - Read
// (B)READ - Browse - auslesen aller Produkte // (B)READ - Browse - auslesen aller Produkte
const getProducts = async () => { const getProducts = async (): Promise<Product[]> => {
try { try {
const response = await fetch(`${BASE_URL}/api/products`); // HTTP Request URL const response = await fetch(`${BASE_URL}/api/products`); // HTTP Request URL
if (!response.ok) { if (!response.ok) {
throw new Error('Fetch went wrong.'); throw new Error('Fetch went wrong.');
} }
const data = await response.json(); // HTTP-Response const data: Product[] = await response.json(); // HTTP-Response
return data; return data;
} catch (error) { } catch (error) {
console.error(error); console.error(error);
return error; return [];
} }
}; };
// HTTP - Methode - GET // HTTP - Methode - GET
// C(R)UD - Read // C(R)UD - Read
// B(R)EAD - Read - auslesen eines Produkts // B(R)EAD - Read - auslesen eines Produkts
const getProduct = async (id) => { const getProduct = async (id: string): Promise<Product | null> => {
try { try {
const response = await fetch(`${BASE_URL}/api/products/${id}`); // HTTP Request URL const response = await fetch(`${BASE_URL}/api/products/${id}`); // HTTP Request URL
if (!response.ok) { if (!response.ok) {
throw new Error('Fetch went wrong.'); throw new Error('Fetch went wrong.');
} }
const data = await response.json(); // HTTP-Response const data: Product = await response.json(); // HTTP-Response
return data; return data;
} catch (error) { } catch (error) {
console.error(error); console.error(error);
return error; return null;
} }
}; };
// HTTP - Methode - PUT // HTTP - Methode - PUT
// CR(U)D - update // CR(U)D - update
// BR(E)AD - edit - Produkt aktualisieren // BR(E)AD - edit - Produkt aktualisieren
const updateProduct = async (product) => { const updateProduct = async (product: Product): Promise<ApiResponse<Product>> => {
try { try {
const response = await fetch(`${BASE_URL}/api/products`, { const response = await fetch(`${BASE_URL}/api/products`, {
method: 'PUT', method: 'PUT',
@@ -427,19 +455,19 @@ const ProductManager = (el = null) => {
if (!response.ok) { if (!response.ok) {
throw new Error('Fetch went wrong.'); throw new Error('Fetch went wrong.');
} }
const data = await response.json(); // HTTP-Response const data: ApiResponse<Product> = await response.json(); // HTTP-Response
return data; return data;
} catch (error) { } catch (error) {
console.error(error); console.error(error);
return error; return toErrorResponse(error);
} }
}; };
// HTTP - Methode - DELETE // HTTP - Methode - DELETE
// CRU(D) - delete // CRU(D) - delete
// BREA(D) - delete - Produkt löschen // BREA(D) - delete - Produkt löschen
const deleteProduct = async (id) => { const deleteProduct = async (id: string): Promise<ApiResponse<string>> => {
try { try {
const response = await fetch(`${BASE_URL}/api/products/${id}`, { const response = await fetch(`${BASE_URL}/api/products/${id}`, {
method: 'DELETE', method: 'DELETE',
@@ -451,17 +479,17 @@ const ProductManager = (el = null) => {
throw new Error('Fetch went wrong.'); throw new Error('Fetch went wrong.');
} }
const data = await response.json(); const data: ApiResponse<string> = await response.json();
return data; return data;
} catch (error) { } catch (error) {
console.error(error); console.error(error);
return error; return toErrorResponse(error);
} }
}; };
// === FUNCTIONS ======== // === FUNCTIONS ========
const initProducts = () => { const initProducts = (): void => {
getProducts().then((products) => { getProducts().then((products) => {
products.forEach((product) => { products.forEach((product) => {
addProduct(product); addProduct(product);
@@ -477,7 +505,7 @@ const ProductManager = (el = null) => {
// PRODUCTS.forEach(addProduct); // PRODUCTS.forEach(addProduct);
}; };
const loadProducts = () => { const loadProducts = (): void => {
DOM.tBody.innerHTML = ''; DOM.tBody.innerHTML = '';
getProducts().then((data) => { getProducts().then((data) => {
data.forEach((product) => { data.forEach((product) => {
@@ -487,23 +515,26 @@ const ProductManager = (el = null) => {
}); });
}; };
const addProduct = (product) => { const addProduct = (product: Product): void => {
const { name, price, _id: id, position } = product; const { name, price, _id: id, position } = product;
// https://developer.mozilla.org/de/docs/Web/API/HTMLTemplateElement/content // https://developer.mozilla.org/de/docs/Web/API/HTMLTemplateElement/content
const trEl = DOM.templateRow.content.firstElementChild.cloneNode(true); const templateEl = DOM.templateRow.content.firstElementChild;
if (!templateEl) throw new Error('ProductManager: <template class="template-row"> ist leer.');
const tdNameEl = trEl.querySelector('.td-name'); const trEl = templateEl.cloneNode(true) as HTMLTableRowElement;
const tdPriceEl = trEl.querySelector('.td-price');
const btnRemoveEl = trEl.querySelector('.button-product-remove');
const btnMoveUpEl = trEl.querySelector('.button-product-move-up');
const btnMoveDownEl = trEl.querySelector('.button-product-move-down');
const btnDragEl = trEl.querySelector('.button-drag'); const tdNameEl = query<HTMLTableCellElement>(trEl, '.td-name');
const btnEditEl = trEl.querySelector('.button-product-edit'); const tdPriceEl = query<HTMLTableCellElement>(trEl, '.td-price');
const btnRemoveEl = query<HTMLButtonElement>(trEl, '.button-product-remove');
const btnMoveUpEl = query<HTMLButtonElement>(trEl, '.button-product-move-up');
const btnMoveDownEl = query<HTMLButtonElement>(trEl, '.button-product-move-down');
const btnDragEl = query<HTMLButtonElement>(trEl, '.button-drag');
const btnEditEl = query<HTMLButtonElement>(trEl, '.button-product-edit');
tdNameEl.textContent = name; tdNameEl.textContent = name;
tdPriceEl.textContent = price; tdPriceEl.textContent = String(price);
btnEditEl.addEventListener('click', onClickEdit); btnEditEl.addEventListener('click', onClickEdit);
btnRemoveEl.addEventListener('click', onClickRemove); btnRemoveEl.addEventListener('click', onClickRemove);
@@ -519,22 +550,22 @@ const ProductManager = (el = null) => {
trEl.addEventListener('drop', onDrop); trEl.addEventListener('drop', onDrop);
trEl.dataset.id = id; // <tr data-id="..." >...</tr> trEl.dataset.id = id; // <tr data-id="..." >...</tr>
trEl.dataset.position = position; // <tr data-position="..." >...</tr> trEl.dataset.position = String(position); // <tr data-position="..." >...</tr>
DOM.tBody.appendChild(trEl); // Im DOM hinzufügen DOM.tBody.appendChild(trEl); // Im DOM hinzufügen
}; };
const showModalEdit = (product) => { const showModalEdit = (product: Product): void => {
const { name = '', price = 0, _id: id, position } = product; const { name = '', price = 0, _id: id, position } = product;
DOM.inputEditName.value = name; DOM.inputEditName.value = name;
DOM.inputEditPrice.value = price; DOM.inputEditPrice.value = String(price);
DOM.inputEditId.value = id; DOM.inputEditId.value = id;
DOM.inputEditPosition.value = position; DOM.inputEditPosition.value = String(position);
}; };
const resetFields = () => { const resetFields = (): void => {
DOM.btnAdd.disabled = true; DOM.btnAdd.disabled = true;
DOM.inputPrice.value = ''; DOM.inputPrice.value = '';
DOM.inputName.value = ''; DOM.inputName.value = '';
@@ -542,23 +573,34 @@ const ProductManager = (el = null) => {
DOM.formEdit.reset(); DOM.formEdit.reset();
}; };
const disableNonFunctionalButtons = () => { const disableNonFunctionalButtons = (): void => {
Array.from(DOM.tBody.querySelectorAll('tr')).forEach((tr) => { Array.from(DOM.tBody.querySelectorAll('tr')).forEach((tr) => {
const btnMoveUp = tr.querySelector('.button-product-move-up'); const btnMoveUp = query<HTMLButtonElement>(tr, '.button-product-move-up');
const btnMoveDown = tr.querySelector('.button-product-move-down'); const btnMoveDown = query<HTMLButtonElement>(tr, '.button-product-move-down');
btnMoveUp.disabled = !tr.previousElementSibling; btnMoveUp.disabled = !tr.previousElementSibling;
btnMoveDown.disabled = !tr.nextElementSibling; btnMoveDown.disabled = !tr.nextElementSibling;
}); });
}; };
/** Position einer Zeile innerhalb ihres Elternelements. */
const indexOfRow = (rowEl: HTMLTableRowElement): number => {
const siblings = rowEl.parentElement ? Array.from(rowEl.parentElement.children) : [];
return siblings.indexOf(rowEl);
};
// Helferfunktion aus jQuery (youmightnotjquery) // Helferfunktion aus jQuery (youmightnotjquery)
const parents = (el, selector) => { const parents = (el: Element, selector?: string): Element[] => {
const parents = []; const result: Element[] = [];
while ((el = el.parentNode) && el !== document) { let current: Node | null = el.parentNode;
if (!selector || el.matches(selector)) parents.push(el);
while (current && current !== document) {
if (current instanceof Element && (!selector || current.matches(selector))) {
result.push(current);
} }
return parents; current = current.parentNode;
}
return result;
}; };
init(); init();

View File

@@ -1,8 +1,23 @@
import Toastify from 'toastify-js'; // das Modul wird von node_modules ausgelesen und gebundlet. Funktioniert nur mit JS-Bundler import Toastify from 'toastify-js'; // das Modul wird von node_modules ausgelesen und gebundlet. Funktioniert nur mit JS-Bundler
const Toast = (text = '', variant = 'primary') => { export type ToastVariant =
const getColorByName = (variant = '') => { | 'primary'
let color; | 'secondary'
| 'warning'
| 'success'
| 'info'
| 'error'
| 'danger'
| 'light'
| 'dark';
export interface ToastApi {
show: () => void;
}
const Toast = (text = '', variant: ToastVariant = 'primary'): ToastApi => {
const getColorByName = (variant = ''): string => {
let color: string;
switch (variant.trim().toLowerCase()) { switch (variant.trim().toLowerCase()) {
case 'primary': case 'primary':
color = '#0d6efd'; color = '#0d6efd';
@@ -32,12 +47,12 @@ const Toast = (text = '', variant = 'primary') => {
default: default:
console.warn('variant not found'); console.warn('variant not found');
color: 'white'; color = 'white';
} }
return color; return color;
}; };
const show = () => { const show = (): void => {
Toastify({ Toastify({
text: text, text: text,
duration: 2000, duration: 2000,

View File

@@ -0,0 +1,20 @@
// Gemeinsame Typen für die Anwendung
/** Ein Produkt, so wie es vom Backend geliefert wird. */
export interface Product {
_id: string;
name: string;
price: number;
position: number;
}
/** Ein neues Produkt, das noch keine _id und keine position vom Backend hat. */
export type ProductDraft = Pick<Product, 'name' | 'price'>;
/** Standard-Antwort des Backends bei schreibenden Operationen. */
export interface ApiResponse<TData = unknown> {
msg: string;
status: number;
success: boolean;
data?: TData;
}

File diff suppressed because it is too large Load Diff

View File

@@ -5,10 +5,12 @@
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"start": "run-p server css js", "start": "run-p server css js",
"js": "npx esbuild dev/scripts/main.js --watch --bundle --sourcemap --outfile=assets/js/build.js", "js": "npx esbuild dev/scripts/main.ts --watch --bundle --sourcemap --outfile=assets/js/build.js",
"build:js": "npx esbuild dev/scripts/main.ts --bundle --sourcemap --outfile=assets/js/build.js",
"http-server": "npx http-server -p 3000 -c-1", "http-server": "npx http-server -p 3000 -c-1",
"server": "npx browser-sync start --server --files 'assets/css/*.css, assets/js/*.js, **/*.html, *.html'", "server": "npx browser-sync start --server --files 'assets/css/*.css, assets/js/*.js, **/*.html, *.html'",
"css": "sass dev/scss/main.scss:assets/css/main.css -w -q", "css": "sass dev/scss/main.scss:assets/css/main.css -w -q",
"typecheck": "tsc --noEmit",
"dev": "run-p server css js" "dev": "run-p server css js"
}, },
"keywords": [], "keywords": [],
@@ -16,10 +18,13 @@
"license": "ISC", "license": "ISC",
"type": "module", "type": "module",
"devDependencies": { "devDependencies": {
"@types/bootstrap": "^5.2.10",
"@types/toastify-js": "^1.12.4",
"browser-sync": "^3.0.4", "browser-sync": "^3.0.4",
"esbuild": "^0.28.1", "esbuild": "^0.28.1",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"sass": "^1.101.3" "sass": "^1.101.3",
"typescript": "^5.9.3"
}, },
"dependencies": { "dependencies": {
"@splidejs/splide": "^4.1.4", "@splidejs/splide": "^4.1.4",

View File

@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
/* Bundler (esbuild) kompiliert - tsc wird nur zum Typprüfen genutzt */
"noEmit": true,
"isolatedModules": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
/* Strenge Typprüfung */
"strict": true,
"noImplicitOverride": true,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true
},
"include": ["dev/scripts/**/*.ts"]
}