Update TypeScript configuration for stricter type checks and modify environment variable access. Exclude additional directories from compilation, enhance error handling in resolvers, and improve random element selection in mock data generation. Refactor locale handling in middleware and update GraphQL client to use bracket notation for environment variables.
This commit is contained in:
@@ -36,7 +36,12 @@ const descriptions = [
|
||||
];
|
||||
|
||||
function getRandomElement<T>(array: T[]): T {
|
||||
return array[Math.floor(Math.random() * array.length)];
|
||||
const index = Math.floor(Math.random() * array.length);
|
||||
const element = array[index];
|
||||
if (element === undefined) {
|
||||
throw new Error("Array is empty");
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
function getRandomPrice(): number {
|
||||
@@ -57,9 +62,14 @@ function generateProduct(id: string): Product {
|
||||
const promotionType = Math.random();
|
||||
if (promotionType < 0.33) {
|
||||
// Sale mit Rabatt
|
||||
const discountPercent = [10, 20, 30, 40, 50][
|
||||
Math.floor(Math.random() * 5)
|
||||
];
|
||||
const discountPercentArray = [10, 20, 30, 40, 50];
|
||||
const discountPercent =
|
||||
discountPercentArray[
|
||||
Math.floor(Math.random() * discountPercentArray.length)
|
||||
];
|
||||
if (discountPercent === undefined) {
|
||||
throw new Error("Discount percent array is empty");
|
||||
}
|
||||
originalPrice = basePrice;
|
||||
price = Math.round(basePrice * (1 - discountPercent / 100) * 100) / 100;
|
||||
promotion = {
|
||||
|
||||
@@ -6,7 +6,7 @@ import type { DataAdapter } from "./interface";
|
||||
* Bestimmt welcher Adapter basierend auf Environment-Variablen verwendet wird
|
||||
*/
|
||||
export function createAdapter(): DataAdapter {
|
||||
const adapterType = process.env.DATA_ADAPTER || "mock";
|
||||
const adapterType = process.env["DATA_ADAPTER"] || "mock";
|
||||
|
||||
switch (adapterType) {
|
||||
case "mock":
|
||||
|
||||
Reference in New Issue
Block a user