Artikel DB struktur geändert von CODEX

This commit is contained in:
Marco_205 committed 2026-10-12 14:42:28 +00:00
1 parent 0c0a678eaa
commit 9c18234efe
95 files changed
+3872 -2316

No files matched your search

+83 -80
View File
@@ -1,94 +1,97 @@
'use server'
'use server';
import { revalidatePath } from 'next/cache'
import { Article, ArticleCreate, ArticleUpsert } from "@/apps/frontend/types/catalog";
import { revalidatePath } from 'next/cache';
import {
Article,
ArticleCreate,
ArticleGroup,
ArticleUpsert,
} from '../types/catalog';
import { sites } from '../_config/sites';
import { endpoints } from '../_config/endpoints';
export async function articleCreate(data: ArticleCreate) {
console.log(data);
const result = await fetch('http://192.168.50.205/api/articles', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
const resultData = await result.json();
const api = endpoints.apiServer.url;
if (!result.ok) {
async function mutate(
url: string,
method: string,
data?: unknown,
): Promise<ActionResult> {
try {
const response = await fetch(`${api}${url}`, {
method,
headers: { 'Content-Type': 'application/json' },
body: data === undefined ? undefined : JSON.stringify(data),
});
const result = await response.json();
if (!response.ok) {
return {
success: false,
errors: Array.isArray(result.message)
? result.message
: [result.message ?? 'Speichern fehlgeschlagen'],
};
}
revalidatePath(sites.article.url);
return { success: true, data: result };
} catch {
return {
success: false,
errors: resultData.message, // kommt aus NestJS
errors: [
'Der Artikelserver ist nicht erreichbar. Bitte erneut versuchen.',
],
};
}
revalidatePath(sites.article.new.url)
}
export async function articleUpdate(id: string, data: ArticleUpsert): Promise<ActionResult> {
const result = await fetch(`http://192.168.50.205/api/articles/${id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
const resultData = await result.json();
if (!result.ok) {
return {
success: false,
errors: resultData.message, // kommt aus NestJS
};
}
revalidatePath(sites.article.update.url + '/' + id);
return { success: true };
export async function articleCreate(
data: ArticleCreate,
): Promise<ActionResult> {
return mutate('/articles', 'POST', data);
}
export async function articleUpdate(
id: string,
data: ArticleUpsert,
): Promise<ActionResult> {
const result = await mutate(`/articles/${id}`, 'PATCH', data);
if (result.success) revalidatePath(`${sites.article.update.url}/${id}`);
return result;
}
export async function articleFindAll(): Promise<Article[]> {
const result = await fetch(`http://192.168.50.205/api/articles`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
const data = await result.json() as Article[];
return data;
const response = await fetch(`${api}/articles`, { cache: 'no-store' });
if (!response.ok) throw new Error('Artikel konnten nicht geladen werden');
return response.json();
}
export async function articleFindById(id: string): Promise<Article | null> {
const response = await fetch(`${api}/articles/${id}`, { cache: 'no-store' });
if (response.status === 404) return null;
if (!response.ok) throw new Error('Artikel konnte nicht geladen werden');
return response.json();
}
export async function articleDelete(
id: string,
revalidateUrl?: string,
): Promise<ActionResult> {
const result = await mutate(`/articles/${id}`, 'DELETE');
if (result.success && revalidateUrl) revalidatePath(revalidateUrl);
return result;
}
export async function articleGroupsFindAll(): Promise<ArticleGroup[]> {
const response = await fetch(`${api}/article-groups`, { cache: 'no-store' });
if (!response.ok)
throw new Error('Produktgruppen konnten nicht geladen werden');
return response.json();
}
export async function articleGroupCreate(name: string): Promise<ActionResult> {
return mutate('/article-groups', 'POST', { name });
}
export async function articleFindById(id: string): Promise<any> {
const result = await fetch(`http://192.168.50.205/api/articles/${id}`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
const data = await result.json() as Article
console.log('getArticle', data)
return data;
export async function articleMigrationStatus(): Promise<{
pendingLegacyArticles: number;
}> {
const response = await fetch(`${api}/articles/migration-status`, {
cache: 'no-store',
});
if (!response.ok)
throw new Error('Migrationsstatus konnte nicht geladen werden');
return response.json();
}
export async function articleDelete(id: string,revalidateUrl?:string): Promise<ActionResult> {
const result = await fetch(`http://192.168.50.205/api/articles/${id}`, {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' }
})
const resultData = await result.json();
if (!result.ok) {
return {
success: false,
errors: resultData.message, // kommt aus NestJS
};
}
if(revalidateUrl) revalidatePath(revalidateUrl);
return { success: true };
}
+70 -85
View File
@@ -1,94 +1,79 @@
'use server'
'use server';
import { revalidatePath } from 'next/cache'
import { revalidatePath } from 'next/cache';
import { sites } from '../_config/sites';
import { Stock, StockCreate, StockUpdate } from '../types/inventory/stockContent.types';
import { endpoints } from '../_config/endpoints';
import {
Stock,
StockCreate,
StockUpdate,
} from '../types/inventory/stock.types';
import { StockContent } from '../types/inventory/stockContent.types';
import {
StockMovementIn,
StockMovementOut,
StockMovementTransfer,
} from '../types/inventory/stockMovement.types';
const api = endpoints.apiServer.url;
async function mutate(
path: string,
method: string,
data?: unknown,
): Promise<ActionResult> {
try {
const response = await fetch(`${api}${path}`, {
method,
headers: { 'Content-Type': 'application/json' },
body: data === undefined ? undefined : JSON.stringify(data),
});
const result = await response.json();
if (!response.ok)
return {
success: false,
errors: Array.isArray(result.message)
? result.message
: [result.message ?? 'Buchung fehlgeschlagen'],
};
revalidatePath(sites.stock.new.url);
return { success: true, data: result };
} catch {
return {
success: false,
errors: ['Der Lagerserver ist nicht erreichbar. Bitte erneut versuchen.'],
};
}
}
export async function stockCreate(data: StockCreate) {
const result = await fetch('http://192.168.50.205/api/stock', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
const resultData = await result.json();
if (!result.ok) {
return {
success: false,
errors: resultData.message, // kommt aus NestJS
};
}
revalidatePath(sites.stock.new.url)
return mutate('/stock', 'POST', data);
}
export async function stockUpdate(id: string, data: StockUpdate): Promise<ActionResult> {
const result = await fetch(`http://192.168.50.205/api/stocks/${id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
const resultData = await result.json();
if (!result.ok) {
return {
success: false,
errors: resultData.message, // kommt aus NestJS
};
}
revalidatePath(sites.stock.update.url + '/' + id);
return { success: true };
export async function stockUpdate(id: string, data: StockUpdate) {
return mutate(`/stock/${id}`, 'PATCH', data);
}
export async function stockDelete(id: string) {
return mutate(`/stock/${id}`, 'DELETE');
}
export async function stockFindAll(): Promise<Stock[]> {
const result = await fetch(`http://192.168.50.205/api/stocks`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
const data = await result.json() as Stock[];
return data;
const response = await fetch(`${api}/stock`, { cache: 'no-store' });
if (!response.ok) throw new Error('Lager konnten nicht geladen werden');
return response.json();
}
export async function stockFindById(id: string): Promise<any> {
const result = await fetch(`http://192.168.50.205/api/stocks/${id}`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
const data = await result.json() as Stock
console.log('getArticle', data)
return data;
export async function stockFindById(id: string) {
const response = await fetch(`${api}/stock/${id}`, { cache: 'no-store' });
if (!response.ok) throw new Error('Lager konnte nicht geladen werden');
return response.json();
}
export async function stockContentFindAll(): Promise<StockContent[]> {
const response = await fetch(`${api}/stock-content`, { cache: 'no-store' });
if (!response.ok) throw new Error('Bestände konnten nicht geladen werden');
return response.json();
}
export async function stockMoveIn(data: StockMovementIn) {
return mutate('/stock-movements/in', 'POST', data);
}
export async function stockMoveOut(data: StockMovementOut) {
return mutate('/stock-movements/out', 'POST', data);
}
export async function stockTransfer(data: StockMovementTransfer) {
return mutate('/stock-movements/transfer', 'POST', data);
}
export async function stockDelete(id: string,revalidateUrl?:string): Promise<ActionResult> {
const result = await fetch(`http://192.168.50.205/api/stocks/${id}`, {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' }
})
const resultData = await result.json();
if (!result.ok) {
return {
success: false,
errors: resultData.message, // kommt aus NestJS
};
}
if(revalidateUrl) revalidatePath(revalidateUrl);
return { success: true };
}